From patchwork Mon Mar 22 14:01:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1715 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id A7E0C3F067 for ; Mon, 22 Mar 2021 15:02:33 +0100 (CET) Received: by mail-pg1-f198.google.com with SMTP id r1sf8003619pgg.12 for ; Mon, 22 Mar 2021 07:02:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1616421752; cv=pass; d=google.com; s=arc-20160816; b=Z8JAqUIi/edTshcihwmLQ8SxNloG47b2hLwRcqTbEqW1qbN6wYw2aK/VHptVAEepMb vdzmloE/hnKEZEEBCvRADK4+XoTKEeDcyrTmbJjKKnUjrPfwN9rZyapaBr506B3O6YMH 4+jm1aMWNbNsJe72Fm6Wgg8IPj2zlfKvlGHaiCtLEJ+xuSRS6irNSLNBGbKVHDWt77zA uZIPaA0vk9mKvgS+XN7SL5VgqMYoDeyrhA7oltesPe+Zf9KzgBwXpyTWStrGDbeOXDfD N1t79CBM+hRMGNt2/8h1TLjpudq8CVgibuspIwKaAAhe+lWDEpB6BgI2nyZSlv5Rn1ta kprw== 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=vr84lLZglwM2lrImL6wJ76L5Hc9QzGaz1pSUMzHisWs=; b=aADvdNWeW7enh3URTTaCmh78tMcq+x2Gzlw5LTIKAlzzBc3eL8l+adlp/PPgKnFgYc hkByDJVA/vt00p+UhkCdRf31TrLPAuiTTaCx/8EfNbrag4GzRD4L/pNYhVBdrl3J77Yd Hw+7Mh28hpHudvpFgq/7tN5nm1AtKFN17UsItXhRhir3IIM01TtkaHOZcTiD/Gi+hftL lqM7H1DOLr8AgP5pjDXdVaaNRApObvDwKkdg40Gcy7mqM8gCI52dcU93aPuo8UZHJ2Zz j0yU17izSkIRrRH3hRFm2OTh9PX/z5FnmehaBDA14M5/IKBdXl2a8IoieNeXx+kyhGgc pvhg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="poA302j/"; 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=vr84lLZglwM2lrImL6wJ76L5Hc9QzGaz1pSUMzHisWs=; b=cGwwbhB//+Y8aDFqzKgpsFc8iI5cFyehdLzTzghIen20eEoKmc5j6WZWSrSFVkD6PB UiLDScueVY6PYR+iLgB0E+nWAg1qpvVVoQjbMBQ6WOfIit3tJamMyLKBt7bI7wh4k9yr VwFdQXhROtMKhsWTtNGezI5Ga7fneJptOmGB8= 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=vr84lLZglwM2lrImL6wJ76L5Hc9QzGaz1pSUMzHisWs=; b=YtIdcnK0kLmew3grkAukUKLKRaKB8QzbQYkci3jSiumBHQMnfWy1tOtkEElE2EdYUp 2cA+MjdEO97sg+m7IESbXSdS9MN9+qicGL4vDg8jOiYGB7kKqSUfphGhrSepK+X3TxI1 bDVOFTsCbL6ORhEuhZqN/KFRVh+4OqL3jif2LqPAvHsor1FIDbH5lI66TUilHXDMekGV yoplaCy6JQCyc1O1voSrpqVtbZPL27CAeAC+tjpMr7Jk1zyVQPosXSNlh1lSFrxL3mL2 yocWxGv7/We5E9fjg72cEL7PSfZibwj4L7eAGDs/hqrRr54jboeWaQxSEWbUBrLd34Tw 8P/Q== X-Gm-Message-State: AOAM531cCVX/G9o1+q1VyHfVdN+lap4CDV+ral+S3XwEGfwrUY+ZmCEE V/aLvS31hSXGYMUG3KapXV/bLNWF X-Google-Smtp-Source: ABdhPJwr9A5o8pWKHh9vqL0ZpQ3HqsspJGuy5zye0jlssJgVERKl7PqlSDnUpa5cPExwAVH4zJ3Elw== X-Received: by 2002:a17:902:59c9:b029:e6:5cdd:f709 with SMTP id d9-20020a17090259c9b02900e65cddf709mr27033574plj.20.1616421752260; Mon, 22 Mar 2021 07:02:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:9106:: with SMTP id k6ls7735129pjo.0.canary-gmail; Mon, 22 Mar 2021 07:02:31 -0700 (PDT) X-Received: by 2002:a17:902:8d86:b029:e6:45a0:b16e with SMTP id v6-20020a1709028d86b02900e645a0b16emr26550989plo.34.1616421751421; Mon, 22 Mar 2021 07:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616421751; cv=none; d=google.com; s=arc-20160816; b=VGHLSxeupzD6+Zm02ekESCsT697wI8qmtuwzVTQa2HQFNr+LdHz1JH/whQM/hhq+g+ mlBQ/4z4FaM+c+ae1/FccLG0KKKhOGXiLSQM1WnPmUmEuTDIsgeT9d8m1Sw+4LB/jYsG iFgjVI6OZVMr0wifbbgrkZQu/ksTCPkta+f+TXE2PFCEk+YZeiV8xZv50rlXlGm4jjrF 1d98DAMrr6kiJhfPcpL78lIWHx1Sz9jLSA3z4iuUEwmrDP2Xwykt0YfAS8Tt8yOIps7t N11Ekxs0G65SG955REHuFZvxr3LoW8i+0S5/OvLquPqMSHNAjr7vDoAl4nRh9GWZNjee vxFg== 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=ei9A5zbhvayRjVi6Vomvlir4u8ShWE4723QjD9pmyj8=; b=llMhiAa1ME8tQfG5RWgu/EsTbGDDo1p0Xo9hQpO7I8+PHqZ0pS0ISSwlL+PXCjmTSs 7BA1L1NctBv4+1799d/1NyfVGUtPTKou+3yLnLoiE1QMjQT2ZsVl9TMAvIk5yYySc+9c GsLqF4yK40324Lzc278JGymYbVPfojhMOWq3BpUTNq2vxUjlD+2nO6UhuDyR/T6CqULZ ovUAMJqCaGY02QYUG/DUkq2ICcZVIR3HIezscHe+jEEsELA/e+3JBzvQ8yPR9vONr+Q9 X1BrUTDts5PKKuZuSCnulBe1xOYmmTAX0C1CjMkWNsAj+yF9k9BXeEf8t/AImH7XxKDG /4Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="poA302j/"; 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 s6sor7174933pju.2.2021.03.22.07.02.31 for (Google Transport Security); Mon, 22 Mar 2021 07:02:31 -0700 (PDT) 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:f40f:: with SMTP id ch15mr13900475pjb.128.1616421751168; Mon, 22 Mar 2021 07:02:31 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c00a:a884:15c1:9a30:414f:d84b]) by smtp.gmail.com with ESMTPSA id gg22sm14112997pjb.20.2021.03.22.07.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 07:02:30 -0700 (PDT) From: Jagan Teki To: Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Laurent Pinchart , Samuel Holland Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-amarula@amarulasolutions.com, linux-sunxi@googlegroups.com, Jagan Teki Subject: [PATCH v4 3/4] drm: sun4i: dsi: Convert to bridge driver Date: Mon, 22 Mar 2021 19:31:51 +0530 Message-Id: <20210322140152.101709-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322140152.101709-1-jagan@amarulasolutions.com> References: <20210322140152.101709-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="poA302j/"; 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 v4: - none 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);