From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F25EC4338F for ; Wed, 28 Jul 2021 13:33:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3995660FED for ; Wed, 28 Jul 2021 13:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236615AbhG1NdD (ORCPT ); Wed, 28 Jul 2021 09:33:03 -0400 Received: from new3-smtp.messagingengine.com ([66.111.4.229]:58891 "EHLO new3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236583AbhG1Nc5 (ORCPT ); Wed, 28 Jul 2021 09:32:57 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id C99FE580B89; Wed, 28 Jul 2021 09:32:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 28 Jul 2021 09:32:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=rpqGJA8BzP498 VRthL+GNLGbJX6smf0yyUoSj3bk7lg=; b=T7QPu9DZcrvJ9+DUbEM2WWuxIgvsA aITQ042/uKsM3KruhSU0AE4u17DCinRfDhHJ411KfCKTqHJMfErqcrmOmbHZbQou pv7o1qhZAAv5m4su4JKIy/cHbAjT1r2sg3zRwsFnfnuJQeM81j2gweCQTRmXPpEp +Dejvo9qy+ujNYiXxaaEwGFRCWLfLyKMRPUt7cWWfqjEcHCPnyMCDpITJ/M7zHeL 0yFUePKHq6p2k98yssDPwzK8WbyQS/FTmCdtlwTK6OgqAfWGsY6S/4gToqmt1X5b bjFqBV7hJ6deK29Il+b44wVaTNdwwfSPI6fqdcKPbeyxewjKzae9qtUdQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=rpqGJA8BzP498VRthL+GNLGbJX6smf0yyUoSj3bk7lg=; b=mzkBpZBj MFoDsZ2rHfeXCJsmwG+9bmw+xSYn9Ok8xtbCoysdJw9h80OmmUOnOpBMheKFRB5Q ulD2Gr2Y7q7hFTikZhL0KIHLaaYU9Ab2AKOxeR1yM9OYJ2t2vW5cew0sEt52Hvmn EvoNcZhBfKhQTH+x6HJXRdvl25gfpIx1BfiXInkhhjuahf8IsCejx8j4kCjxU5Dl XE9q3UaESs0v4y7uEXXMeWpr3iyXIB0UTZSYpfG5l3orGYAFZXl1X7aPP+ukD5jM H4ryNloUl1HMBMYVTAfOGeAcIaQmR0HltX0A35x7U5fSf22tmDEPGxVfhG37s0QG NKaLa+m/1OT1yg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrgeelgdeifecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpedvkeelveefffekjefhffeuleetleefudeifeehuddugffghffhffehveevheeh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrg igihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Jul 2021 09:32:53 -0400 (EDT) From: Maxime Ripard To: Sam Ravnborg , Daniel Vetter , David Airlie , Thierry Reding , Laurent Pinchart , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , Jernej Skrabec , Neil Armstrong , Andrzej Hajda , Jonas Karlman , Robert Foss Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/8] drm/panel: raspberrypi-touchscreen: Use the attach hook Date: Wed, 28 Jul 2021 15:32:28 +0200 Message-Id: <20210728133229.2247965-8-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728133229.2247965-1-maxime@cerno.tech> References: <20210728133229.2247965-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have an attach hook available for panels as well, let's use it for the RaspberryPi 7" DSI panel. This now mimics what all the other bridges in a similar situation are doing, and we avoid our probe order issue entirely. Signed-off-by: Maxime Ripard --- .../drm/panel/panel-raspberrypi-touchscreen.c | 135 ++++++++++-------- 1 file changed, 77 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c index 462faae0f446..995c5cafb970 100644 --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c @@ -346,7 +346,83 @@ static int rpi_touchscreen_get_modes(struct drm_panel *panel, return num; } +static int rpi_touchscreen_attach(struct drm_panel *panel) +{ + struct rpi_touchscreen *ts = panel_to_ts(panel); + struct device *dev = &ts->i2c->dev; + struct device_node *endpoint, *dsi_host_node; + struct mipi_dsi_device *dsi; + struct mipi_dsi_host *host; + int ret; + + struct mipi_dsi_device_info info = { + .type = RPI_DSI_DRIVER_NAME, + .channel = 0, + .node = NULL, + }; + + /* Look up the DSI host. It needs to probe before we do. */ + endpoint = of_graph_get_next_endpoint(dev->of_node, NULL); + if (!endpoint) + return -ENODEV; + + dsi_host_node = of_graph_get_remote_port_parent(endpoint); + if (!dsi_host_node) { + of_node_put(endpoint); + return -ENODEV; + } + + host = of_find_mipi_dsi_host_by_node(dsi_host_node); + of_node_put(dsi_host_node); + if (!host) { + of_node_put(endpoint); + return -EPROBE_DEFER; + } + + info.node = of_graph_get_remote_port(endpoint); + if (!info.node) { + of_node_put(endpoint); + return -ENODEV; + } + + of_node_put(endpoint); + + dsi = mipi_dsi_device_register_full(host, &info); + if (IS_ERR(dsi)) { + dev_err(dev, "DSI device registration failed: %ld\n", + PTR_ERR(dsi)); + return PTR_ERR(dsi); + } + + ts->dsi = dsi; + + dsi->mode_flags = (MIPI_DSI_MODE_VIDEO | + MIPI_DSI_MODE_VIDEO_SYNC_PULSE | + MIPI_DSI_MODE_LPM); + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->lanes = 1; + + ret = mipi_dsi_attach(dsi); + if (ret) { + dev_err(&dsi->dev, "failed to attach dsi to host: %d\n", ret); + return ret; + } + + return 0; +} + +static void rpi_touchscreen_detach(struct drm_panel *panel) +{ + struct rpi_touchscreen *ts = panel_to_ts(panel); + + mipi_dsi_detach(ts->dsi); + mipi_dsi_device_unregister(ts->dsi); +} + static const struct drm_panel_funcs rpi_touchscreen_funcs = { + .attach = rpi_touchscreen_attach, + .detach = rpi_touchscreen_detach, + .disable = rpi_touchscreen_disable, .unprepare = rpi_touchscreen_noop, .prepare = rpi_touchscreen_noop, @@ -359,14 +435,7 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, { struct device *dev = &i2c->dev; struct rpi_touchscreen *ts; - struct device_node *endpoint, *dsi_host_node; - struct mipi_dsi_host *host; int ver; - struct mipi_dsi_device_info info = { - .type = RPI_DSI_DRIVER_NAME, - .channel = 0, - .node = NULL, - }; ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); if (!ts) @@ -394,35 +463,6 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, /* /\* Turn off at boot, so we can cleanly sequence powering on. *\/ */ /* rpi_touchscreen_i2c_write(ts, REG_POWERON, 0); */ - /* Look up the DSI host. It needs to probe before we do. */ - endpoint = of_graph_get_next_endpoint(dev->of_node, NULL); - if (!endpoint) - return -ENODEV; - - dsi_host_node = of_graph_get_remote_port_parent(endpoint); - if (!dsi_host_node) - goto error; - - host = of_find_mipi_dsi_host_by_node(dsi_host_node); - of_node_put(dsi_host_node); - if (!host) { - of_node_put(endpoint); - return -EPROBE_DEFER; - } - - info.node = of_graph_get_remote_port(endpoint); - if (!info.node) - goto error; - - of_node_put(endpoint); - - ts->dsi = mipi_dsi_device_register_full(host, &info); - if (IS_ERR(ts->dsi)) { - dev_err(dev, "DSI device registration failed: %ld\n", - PTR_ERR(ts->dsi)); - return PTR_ERR(ts->dsi); - } - drm_panel_init(&ts->base, dev, &rpi_touchscreen_funcs, DRM_MODE_CONNECTOR_DSI); @@ -432,41 +472,20 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, drm_panel_add(&ts->base); return 0; - -error: - of_node_put(endpoint); - return -ENODEV; } static int rpi_touchscreen_remove(struct i2c_client *i2c) { struct rpi_touchscreen *ts = i2c_get_clientdata(i2c); - mipi_dsi_detach(ts->dsi); - drm_panel_remove(&ts->base); - mipi_dsi_device_unregister(ts->dsi); - return 0; } static int rpi_touchscreen_dsi_probe(struct mipi_dsi_device *dsi) { - int ret; - - dsi->mode_flags = (MIPI_DSI_MODE_VIDEO | - MIPI_DSI_MODE_VIDEO_SYNC_PULSE | - MIPI_DSI_MODE_LPM); - dsi->format = MIPI_DSI_FMT_RGB888; - dsi->lanes = 1; - - ret = mipi_dsi_attach(dsi); - - if (ret) - dev_err(&dsi->dev, "failed to attach dsi to host: %d\n", ret); - - return ret; + return 0; } static struct mipi_dsi_driver rpi_touchscreen_dsi_driver = { -- 2.31.1