From patchwork Mon Nov 22 06:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1783 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2703A3F15A for ; Mon, 22 Nov 2021 07:53:36 +0100 (CET) Received: by mail-pj1-f72.google.com with SMTP id x1-20020a17090a294100b001a6e7ba6b4esf8444741pjf.9 for ; Sun, 21 Nov 2021 22:53:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637564015; cv=pass; d=google.com; s=arc-20160816; b=nT0MgMpl7O3aMdk5BuaBg6ql8quxL6/8ERMp4yo/CX0Igs56m/OkQATIn7GTbAgcNj u8CvUxXfpSf6Yb62bvKc1/5EcsWR8ky90o+UFqtT0Gih+hevDtfxjw35tsthEMoxRl+b 5XeUTu0dQjF7lc/t/i3SzUQspd/ACMBl4PYiCxzPRI04qIk8aWyPnR1pdMoqcknYcFxG u5k0/2lc0svQI3FY3aT9vJKyXGc+wJ4k5Jc3nNN0eVWnqol0l1CtvLKNX5gjorWfeOS0 hO2Ct7eWtWQthmdHa39NEf6zj84IEkAiodpd8uZG1TABYsDWtEBEn1qekUavKRjm2sMM MWjg== 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=RDUaCivmG7VEGVtAWqfsSQ9AlriwBNm+z4f2tWkiqtk=; b=0VXI3uuVWY9/JCSVT4+nP+960I4W8U3hgY/9bgtx0fY4/WPlTx7Wa8hkt84MwWGMaK SLvLz+VOIYfKXHs5k9VkIVVFpN6E3ngbzI3GpFgM46pfXmc6zr2Y/lCu2TAZhqiIdNDz XuyL/OGx1wJ6jxZLKFbWgVaSynybucrgaLnroLlZZESU8uhUGudX8xODFvlwIZwzs9Qr nuuOCfCyAl6mOXacedBagb+hkNv+NCOCN5RPQ11WLjEgAy4D874owuTEFyfmLWgj8GYG Nt9K6BpOKwk8RFSd4qDe/nOS++Br7xdGLeeZ1tm4aDfmdcMn3NGnCdsXnVnbheSuJ58g hbsQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=h7ZUfJH9; 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=RDUaCivmG7VEGVtAWqfsSQ9AlriwBNm+z4f2tWkiqtk=; b=oir+v2sHh8nMeMphhBBQ1d9FkGAb0+p18ezJ70mngqqtGHY26C2XyW52MqosmSa96F q42ls1s0n2pDFwg8Ha8OQmHsNFnCyuT753ednNqXUFIVdhMDhnN31DnON5iSDhDXUEWH W79QOFw5Cz4QxEG8axG4mbE6tVW7UXP/3AEKE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=RDUaCivmG7VEGVtAWqfsSQ9AlriwBNm+z4f2tWkiqtk=; b=BmlCyVFwWVSi+nytDXDD/ebxRxQfw4mU1CXMyBDx76BIEWkWQh6zLbGP6lVdizmKzm oPIMu/cZ4Vc8QypueYPonPh9AtcstfHvlVFRDR0LO+Fm6NrstQPR2x49nf3xq17Jr/Tw e2182QK6QVcfVmuY4z5+mg1Bpy301gclVSds6mAlVcrdJMvez5FH5iWXEw4oA+c7NVve 5CBKVrlE9lmWQ7o06Q5icNfNK8034B43T9x68oFDU5Gy9XMXRclmEz0OucVDZ32/1V53 Jpgks7eMXyXTbln17Xk1dhizmJ8eb6dAIz3CeLrIEjsAMND/yxcW4skbZPbvOo+LQmqD ZqPg== X-Gm-Message-State: AOAM533QX1O1ypGoO+l6kjZoHd6qB/TjmDc21HyDXI+Ji8Ixh+FYoAus pSKLFlNsnpWwiKFUmB5F3laYNbDA X-Google-Smtp-Source: ABdhPJyJ57W6b7JUiCkXfskiz0PPFBAKbQDV+wPMzbnk5nOFwm8uvge8hnNksVkjKfHLF7dnbF8fPA== X-Received: by 2002:a17:90a:d70a:: with SMTP id y10mr28906150pju.36.1637564014950; Sun, 21 Nov 2021 22:53:34 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:1a8a:: with SMTP id ng10ls9802684pjb.1.canary-gmail; Sun, 21 Nov 2021 22:53:34 -0800 (PST) X-Received: by 2002:a17:90b:314e:: with SMTP id ip14mr29798701pjb.130.1637564014285; Sun, 21 Nov 2021 22:53:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637564014; cv=none; d=google.com; s=arc-20160816; b=cu+CUqXvHN86eWcVJ6YY908gKF4pay5lo1wmZhYTfAee1nYLeysgNa0z8sexREXCJc 40tcZuCogvWvGLrIQMCSObRdqqsMgfLhJN8iGUFAGiVxCdx2J+PFs1mo8aSjZZcGSey6 8453OOKm28PbJjh6rR5/XZUUWlqFu4JrvHZmjcPImfFhP92stD4vrDklLP3+6NPXmFuG QAoRjg7XZjhrcWB3hPSff3UIoNvg//2ux4NEAAdYH8Uxl5qgalCXo7cLjGoACc/9MqkN v4H013xPmbeHsP5ZAhEqnOEv2RyZm43t00nYifRoMsEFdPLBvFyTACLbtQxYXSoPKNE4 0KAA== 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=Bn7OMxc+0lRaKOfEDxXP5eAln8VQKH/m4PmaTGfkaqk=; b=aIMuSPQogT37sFI8VFSX4/T7P5FiVnsQKUaRbZlIL+2WsUL87byUqq7co9gYQlh+Gg febJPWeT+/BO9k1ZSQFz5gh0gaAVE2YI0uvKnDsXsrOV+6XE8vvnvxKIuZJptcYVEn6F AEvuWc64tb7Kr4tQcjSJf4A/9Ol0Fw9L6RyhBFivxFwvs3Y+IlayqQAThiJQ9cuChw/h dAlWMaV6jAqMAfaruf7c3f7rqcyf4iNiBeq/C8oFjw0JK9459h1lnkXRee5INc3zvgLQ ap6juD8ruwtgpAstt7zEuS/bnkaQX9v7DJGcd6u9KBshw/pxLfMmvJ7P1J2T91RWLYGT wtIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=h7ZUfJH9; 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 na2sor12331441pjb.43.2021.11.21.22.53.34 for (Google Transport Security); Sun, 21 Nov 2021 22:53:34 -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:90b:350c:: with SMTP id ls12mr28224649pjb.197.1637564013943; Sun, 21 Nov 2021 22:53:33 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a0a9:eed6:c913:819a:3850]) by smtp.gmail.com with ESMTPSA id a8sm7935904pfv.176.2021.11.21.22.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Nov 2021 22:53:33 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Chen-Yu Tsai , Laurent Pinchart , Neil Armstrong , Robert Foss , Sam Ravnborg Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@googlegroups.com, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v5 3/7] drm: sun4i: dsi: Convert to bridge driver Date: Mon, 22 Nov 2021 12:22:19 +0530 Message-Id: <20211122065223.88059-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211122065223.88059-1-jagan@amarulasolutions.com> References: <20211122065223.88059-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=h7ZUfJH9; 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: , Some display panels would come up with a non-DSI output, those can have an option to connect the DSI host by means of interface bridge converter. This DSI to non-DSI interface bridge converter would requires DSI Host to handle drm bridge functionalities in order to DSI Host to Interface bridge. This patch 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 v5: - add atomic APIs - find host and device variant DSI devices. Changes for v4, v3: - none drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 112 ++++++++++++++++++++----- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h | 7 ++ 2 files changed, 96 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c index 43d9c9e5198d..a6a272b55f77 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -713,10 +714,11 @@ 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_atomic_enable(struct drm_bridge *bridge, + struct drm_bridge_state *old_bridge_state) { - struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; - struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder); + struct sun6i_dsi *dsi = bridge_to_sun6i_dsi(bridge); + struct drm_display_mode *mode = &bridge->encoder->crtc->state->adjusted_mode; struct mipi_dsi_device *device = dsi->device; union phy_configure_opts opts = { }; struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; @@ -772,6 +774,9 @@ static void sun6i_dsi_encoder_enable(struct drm_encoder *encoder) if (dsi->panel) drm_panel_prepare(dsi->panel); + if (dsi->next_bridge) + dsi->next_bridge->funcs->atomic_pre_enable(dsi->next_bridge, old_bridge_state); + /* * FIXME: This should be moved after the switch to HS mode. * @@ -787,6 +792,9 @@ static void sun6i_dsi_encoder_enable(struct drm_encoder *encoder) if (dsi->panel) drm_panel_enable(dsi->panel); + if (dsi->next_bridge) + dsi->next_bridge->funcs->atomic_enable(dsi->next_bridge, old_bridge_state); + sun6i_dsi_start(dsi, DSI_START_HSC); udelay(1000); @@ -794,15 +802,19 @@ 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_atomic_disable(struct drm_bridge *bridge, + struct drm_bridge_state *old_bridge_state) { - 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"); if (dsi->panel) { drm_panel_disable(dsi->panel); drm_panel_unprepare(dsi->panel); + } else if (dsi->next_bridge) { + dsi->next_bridge->funcs->atomic_disable(dsi->next_bridge, old_bridge_state); + dsi->next_bridge->funcs->atomic_post_disable(dsi->next_bridge, old_bridge_state); } phy_power_off(dsi->dphy); @@ -842,9 +854,25 @@ 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); + + if (dsi->next_bridge) + return drm_bridge_attach(bridge->encoder, dsi->next_bridge, + NULL, 0); + + return 0; +} + +static const struct drm_bridge_funcs sun6i_dsi_bridge_funcs = { + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, + .atomic_reset = drm_atomic_helper_bridge_reset, + .atomic_enable = sun6i_dsi_bridge_atomic_enable, + .atomic_disable = sun6i_dsi_bridge_atomic_disable, + .attach = sun6i_dsi_bridge_attach, }; static u32 sun6i_dsi_dcs_build_pkt_hdr(struct sun6i_dsi *dsi, @@ -966,8 +994,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) { @@ -976,18 +1002,26 @@ 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) { + 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); + 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; @@ -1013,16 +1047,46 @@ static int sun6i_dsi_attach(struct mipi_dsi_host *host, struct mipi_dsi_device *device) { struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); - struct drm_panel *panel = of_drm_find_panel(device->dev.of_node); + struct device_node *remote = device->dev.of_node; int ret; - if (IS_ERR(panel)) - return PTR_ERR(panel); + if (!of_device_is_available(remote)) { + /** + * I2C interfaced DSI bridges will register DSI host on the + * bridge drivers instead of conventional device. + * + * Those are probed via host of_node instead of device of_node. + */ + remote = of_graph_get_remote_node(host->dev->of_node, 0, 0); + if (!remote) + return -ENODEV; + } + + dsi->panel = of_drm_find_panel(remote); + if (IS_ERR(dsi->panel)) { + dsi->panel = NULL; + + dsi->next_bridge = of_drm_find_bridge(remote); + if (IS_ERR(dsi->next_bridge)) { + dev_err(dsi->dev, "failed to find bridge\n"); + return PTR_ERR(dsi->next_bridge); + } + } else { + dsi->next_bridge = NULL; + } + + of_node_put(remote); - dsi->panel = panel; dsi->device = device; - dev_info(host->dev, "Attached device %s\n", device->name); + dev_info(host->dev, "Attached %s %s\n", + device->name, dsi->panel ? "panel" : "bridge"); + + dsi->bridge.funcs = &sun6i_dsi_bridge_funcs; + dsi->bridge.of_node = dsi->dev->of_node; + dsi->bridge.type = DRM_MODE_CONNECTOR_DSI; + + drm_bridge_add(&dsi->bridge); ret = component_add(dsi->dev, &sun6i_dsi_ops); if (ret) { @@ -1040,9 +1104,11 @@ static int sun6i_dsi_detach(struct mipi_dsi_host *host, struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); dsi->panel = NULL; + dsi->next_bridge = NULL; dsi->device = NULL; component_del(dsi->dev, &sun6i_dsi_ops); + drm_bridge_remove(&dsi->bridge); return 0; } diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h index 61e88ea6044d..d269304691c9 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; @@ -30,6 +31,7 @@ struct sun6i_dsi { struct device *dev; struct mipi_dsi_device *device; struct drm_panel *panel; + struct drm_bridge *next_bridge; }; static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host) @@ -37,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);