From patchwork Sun Feb 14 19:40:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1633 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1CFDC3F158 for ; Sun, 14 Feb 2021 20:41:33 +0100 (CET) Received: by mail-pf1-f199.google.com with SMTP id j7sf5665873pfa.14 for ; Sun, 14 Feb 2021 11:41:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1613331692; cv=pass; d=google.com; s=arc-20160816; b=w2/buBxgFS3+6Ptw7I7Uby1Xdg7b/IMtlmFKQdyYetDc4pKDhrdw88TqTsrUr0B1aG X+fQgzCIDQACk9AZjT7URk/MihpwG2IjIhLTCiRfjA+2RNg1zzdFz/7lyqhrHOBvNm52 xbj7TffxCv9ChgSczXyQIWPU5zY5uw2BGQ4q6xGB5qgi0AlSLqt4V6baKQCPO5Bsp718 GvzDlxrZjq8apctCxxkvyVb1bQjkGmNvek91w8J18sBy9rmHmaahvlL6YcIVhKM5cbPJ uFOVnb+oD48CmzchM0IXYFnkjjw5bFz2wXoNWLUJwusOcxGhRXoxi6fyL1GP6EEwkQjC VKlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=uJVB17KIITDIB/TZlj0/HUhMKR8a9QDSgbIzbxYCHDY=; b=dDuahCnlTJw+Q8U2r0Yp5Ke1eVV9STT1czFSyx3lpH/CUB09TWCdmCq1deMTAXxhVJ hWZedLTVdbsqtNF6npK1vIEwv5uwWMT7JxU7/Sc3QQbA9kEnV4NUJOf3eehFdWX7FY+j Rq3pTzjlI7aHCCQu9RU0hLG4s1ajccsCf0GcEMjYhXIJmZv4h+cb/7wWkRgFX3ZMVyVV Gkt6VUxQj+5hLBj3BlxNFqcDFNfOduyfABYIywEik0OH/lxiNROJ6n+v0egMTweORuy5 7+KsTc3rYRXojwwdNncBTqyVh97qiug+hx+2bCumX/1gJR1ycHV9Q629D4zz6ZUQOANq 9gmg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EgPf4vqR; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=uJVB17KIITDIB/TZlj0/HUhMKR8a9QDSgbIzbxYCHDY=; b=CmYCBFUwbTVILTpkIBxxEBFqTp2et/WSS8K5EP+ckysQ4eByAkkJ7G6VEX+8lpH8+P cNOIn+xiQWJNoDazzlbxW9/gWS49ecWPvSS0zoqtwuhOn6l1c555WIfxKnp3k5qX4bfm tu8hT5uyJdNiSI8+qDtNNdySVg0wgF4H7K+3o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=uJVB17KIITDIB/TZlj0/HUhMKR8a9QDSgbIzbxYCHDY=; b=WJERWkP/NMV4pvFtrdfQHR0FcyBYu3pxFBWwxSu03N02MabBibUP4AFfxiPjWAwRjf LEHgmtfCqeGuqiQvnbF2ud19uY/TuUz2Kltz32PiW/9iZvoJGMTNWI0CENjLUdPUVjsM Wd5Qj/ll1u51urBVgPclWcmcGt/Vb8XsHf2+l1Y7fnkdMrHJlk//Mg7DWLq4DPiK/8Ao ent5bJiMKpxPonNczo7zhD4uUAWTdmTom273DQeFi4yM/iyF1wB82Xb+usVDrYhQY8q6 WnlTBu0QyHlp+xrJUmkYqhOIG74j6BxWQdutVlgMcP4fGzYw6pTfAkxuj4xLiQDH4V27 F/0A== X-Gm-Message-State: AOAM533LDd1A3BNEBHJzyHwta0iPSajZFdgO3t/J+LnGttbgAqw4TWnK xNM6W0Ki6UNDdahrnXjQU1gmVyzy X-Google-Smtp-Source: ABdhPJy1rj00f6gnP4ESEDr0oyyqF4zJhQ9Pxdz3jp99lfFpFJqqnW08KFI/mo3BgizH8ybnZ2N9hw== X-Received: by 2002:a63:2259:: with SMTP id t25mr12274365pgm.395.1613331691958; Sun, 14 Feb 2021 11:41:31 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:7487:: with SMTP id h7ls1405945pll.4.gmail; Sun, 14 Feb 2021 11:41:31 -0800 (PST) X-Received: by 2002:a17:90a:fb87:: with SMTP id cp7mr12726695pjb.121.1613331691353; Sun, 14 Feb 2021 11:41:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613331691; cv=none; d=google.com; s=arc-20160816; b=hbTy7eRrOS8kzrLRx9XwPHNjiK2xTqBG0NhKYuuRW4ey3ykN0J/rdFr5q2B3JF5gqV 9OhWyXWmqNeDvfJffJ6lHIhd7CDynLjCgkRtwQi+Y3iaff+lcBaMKZ/xDkhdCbkz9y2v yyKSlzjj14NsMH1DSPiQCvWBI0xhRbr582y6ALjPMw78PgcX29sX5r4Dx3RxBPjkBx1Q fCe5WNzTf8GIavmp/ziMxFwzI9Bbu1LDmTEjjWpavkMySl2Jj83XtF7MDiiozltmmMfY PXNHNfFmfm8n7IwrrYRpF/nqAknhAPNkNdSnSYaIhTZQSwgwETsvAqNu2sRgX4XHS5uZ 9cPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=bf5bVF/V5mY1BZUCCppx1dZ4tCXtGjp23rohASbcBPw=; b=LxweadjuJFBEFZF273y5N9v6Grj4ATHqFzTX/OlRNDDxgJ1nKV2mt8rTDF39qiNzd/ CLyed+M3itbeY6nrLUUYunc7eFUeywhcifDp011n3aRiKRy5O+vyXkIbLm5vQ5j8Rv9Z SJ/ymWJtIfSULuem06WIHUZ6uSyLsFPY3AkAhnXZbHRPVkmR9EaPwKO46adTeDiZWNwE Y8f5z9aS/NcQJas2IlBRzseeKSldxSprG7uBaoUM4OIa+CoYT51uHbEsBpR7KbEoW0HA OdTFJ3LWUG735mHOpDZHBpmWCqLXdrAk/iUPzy1/IhbIXQTMizouuec1lvz6ExkOkpQw ymZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EgPf4vqR; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id lx5sor6874912pjb.21.2021.02.14.11.41.31 for (Google Transport Security); Sun, 14 Feb 2021 11:41:31 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:90a:1b6c:: with SMTP id q99mr12487478pjq.137.1613331691135; Sun, 14 Feb 2021 11:41:31 -0800 (PST) Received: from ub-XPS-13-9350.domain.name ([45.249.78.214]) by smtp.gmail.com with ESMTPSA id 125sm15129247pfu.7.2021.02.14.11.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 11:41:30 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Laurent Pinchart Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 3/7] drm: sun4i: dsi: Convert to bridge driver Date: Mon, 15 Feb 2021 01:10:58 +0530 Message-Id: <20210214194102.126146-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210214194102.126146-1-jagan@amarulasolutions.com> References: <20210214194102.126146-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EgPf4vqR; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , DRM bridge drivers have build-in handling of treating all display pipeline components as bridges. So, convert the existing to a drm bridge driver with a built-in encoder support for compatibility with existing component drivers. Signed-off-by: Jagan Teki --- Changes for v3: - new patch drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 75 ++++++++++++++++---------- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h | 6 +++ 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c index 39321299dc27..6f3c5330a468 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -714,10 +714,10 @@ static int sun6i_dsi_start(struct sun6i_dsi *dsi, return 0; } -static void sun6i_dsi_encoder_enable(struct drm_encoder *encoder) +static void sun6i_dsi_bridge_enable(struct drm_bridge *bridge) { - struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; - struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); + struct drm_display_mode *mode = &bridge->encoder->crtc->state->adjusted_mode; + struct sun6i_dsi *dsi = bridge_to_sun6i_dsi(bridge); struct mipi_dsi_device *device = dsi->device; union phy_configure_opts opts = { }; struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; @@ -801,9 +801,9 @@ static void sun6i_dsi_encoder_enable(struct drm_encoder *encoder) sun6i_dsi_start(dsi, DSI_START_HSD); } -static void sun6i_dsi_encoder_disable(struct drm_encoder *encoder) +static void sun6i_dsi_bridge_disable(struct drm_bridge *bridge) { - struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); + struct sun6i_dsi *dsi = bridge_to_sun6i_dsi(bridge); DRM_DEBUG_DRIVER("Disabling DSI output\n"); @@ -852,9 +852,40 @@ static const struct drm_connector_funcs sun6i_dsi_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static const struct drm_encoder_helper_funcs sun6i_dsi_enc_helper_funcs = { - .disable = sun6i_dsi_encoder_disable, - .enable = sun6i_dsi_encoder_enable, +static int sun6i_dsi_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct sun6i_dsi *dsi = bridge_to_sun6i_dsi(bridge); + int ret; + + if (dsi->panel_bridge) + return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, NULL, 0); + + if (dsi->panel) { + drm_connector_helper_add(&dsi->connector, + &sun6i_dsi_connector_helper_funcs); + ret = drm_connector_init(bridge->dev, &dsi->connector, + &sun6i_dsi_connector_funcs, + DRM_MODE_CONNECTOR_DSI); + if (ret) { + dev_err(dsi->dev, "Couldn't initialise the DSI connector\n"); + goto err_cleanup_connector; + } + + drm_connector_attach_encoder(&dsi->connector, &dsi->encoder); + } + + return 0; + +err_cleanup_connector: + drm_encoder_cleanup(&dsi->encoder); + return ret; +} + +static const struct drm_bridge_funcs sun6i_dsi_bridge_funcs = { + .enable = sun6i_dsi_bridge_enable, + .disable = sun6i_dsi_bridge_disable, + .attach = sun6i_dsi_bridge_attach, }; static u32 sun6i_dsi_dcs_build_pkt_hdr(struct sun6i_dsi *dsi, @@ -1063,8 +1094,6 @@ static int sun6i_dsi_bind(struct device *dev, struct device *master, struct sun6i_dsi *dsi = dev_get_drvdata(dev); int ret; - drm_encoder_helper_add(&dsi->encoder, - &sun6i_dsi_enc_helper_funcs); ret = drm_simple_encoder_init(drm, &dsi->encoder, DRM_MODE_ENCODER_DSI); if (ret) { @@ -1073,27 +1102,12 @@ static int sun6i_dsi_bind(struct device *dev, struct device *master, } dsi->encoder.possible_crtcs = BIT(0); - drm_connector_helper_add(&dsi->connector, - &sun6i_dsi_connector_helper_funcs); - ret = drm_connector_init(drm, &dsi->connector, - &sun6i_dsi_connector_funcs, - DRM_MODE_CONNECTOR_DSI); + ret = drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL, 0); if (ret) { - dev_err(dsi->dev, - "Couldn't initialise the DSI connector\n"); + dev_err(dsi->dev, "Couldn't attach drm bridge\n"); goto err_cleanup_connector; } - drm_connector_attach_encoder(&dsi->connector, &dsi->encoder); - - if (dsi->panel_bridge) { - ret = drm_bridge_attach(&dsi->encoder, dsi->panel_bridge, NULL, 0); - if (ret) { - dev_err(dsi->dev, "Couldn't attach drm bridge\n"); - goto err_cleanup_connector; - } - } - return 0; err_cleanup_connector: @@ -1199,6 +1213,12 @@ static int sun6i_dsi_probe(struct platform_device *pdev) goto err_unprotect_clk; } + dsi->bridge.funcs = &sun6i_dsi_bridge_funcs; + dsi->bridge.of_node = dev->of_node; + dsi->bridge.type = DRM_MODE_CONNECTOR_DSI; + + drm_bridge_add(&dsi->bridge); + ret = component_add(&pdev->dev, &sun6i_dsi_ops); if (ret) { dev_err(dev, "Couldn't register our component\n"); @@ -1222,6 +1242,7 @@ static int sun6i_dsi_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; struct sun6i_dsi *dsi = dev_get_drvdata(dev); + drm_bridge_remove(&dsi->bridge); component_del(&pdev->dev, &sun6i_dsi_ops); mipi_dsi_host_unregister(&dsi->host); clk_rate_exclusive_put(dsi->mod_clk); diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h index 370ecb356a63..5e70666089ad 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h @@ -16,6 +16,7 @@ #define SUN6I_DSI_TCON_DIV 4 struct sun6i_dsi { + struct drm_bridge bridge; struct drm_connector connector; struct drm_encoder encoder; struct mipi_dsi_host host; @@ -38,6 +39,11 @@ static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host) return container_of(host, struct sun6i_dsi, host); }; +static inline struct sun6i_dsi *bridge_to_sun6i_dsi(struct drm_bridge *bridge) +{ + return container_of(bridge, struct sun6i_dsi, bridge); +} + static inline struct sun6i_dsi *connector_to_sun6i_dsi(struct drm_connector *connector) { return container_of(connector, struct sun6i_dsi, connector);