From patchwork Fri Dec 17 13:51:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12696661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBE76C433F5 for ; Fri, 17 Dec 2021 13:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vr6GoH+pI2xq3Gctrs+Ccu720ADGbhPFBzRyP3mruxE=; b=5AgC8WXVCiip5B N+oOwnfjGpMlC8tPSWc7zXPF5isiRpSIFwac9JgPsBF0T0tVfnQ+eMsrDRRnGSxV00TcLvL/mcF++ HS3LB5Cx8Jc97FuPy0UHAPzDwM4i0dhwFUDeLOpax9gsJJMN3PA/wmewegvIN9NZ3Hb/XAvBplu+7 AQZ8kJS6rNPP0gfHExY1C6Tsq40InUh+57102OB8RKuh3skbHUV1YU5JvSkOrL1Q+NlM7Mv3elz/E HZETWnhou3XyLBeEo6yQL5onu5shskhbwflnR33/6KndHWjRK4Bwa5F973zxBAFCMpTsVuZmAPGLb PGE1UKLrAYgLt7lPOHOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myDfU-00ATub-1G; Fri, 17 Dec 2021 13:53:04 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myDe0-00ATCU-JY for linux-arm-kernel@lists.infradead.org; Fri, 17 Dec 2021 13:51:34 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id E949C5C0178; Fri, 17 Dec 2021 08:51:31 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 17 Dec 2021 08:51:31 -0500 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=fm1; bh=aH1pAYV+tXJ5x oBSTjz2hscIrtUupVA0V4HuuGPNrPA=; b=LJPQK6m1mIXxl0h5ObR+8A4C8RZ8Q +fvIv5BYCqj7YX9qt3PYT3zZXxkSoR9Xv8PZEwY+qnyOid4Y8Zko9xtHlctjq8nG qEtMeUoAWaXxQ0k+tr1LGnxk5vd7zI4TZyPP4cm3jmKO/c7TvIv3RicSkDYi8ZGr niHqgGO6Re+ScOdinXadEYTw7N1gUgOIxZtKBXxmj7zkXZyG2yGI6RJMzxehAgRV s2HoFjqeUOePmDXswpW/abtQOICoPTEkWd+jqtfZVakIfrswpzV0wIykGNBw8oXj PeW0SzW7ievQB/9KcYDQN6ZV1vNM3NMXDE1KSKsRW054llYfmO8AANgmA== 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= fm1; bh=aH1pAYV+tXJ5xoBSTjz2hscIrtUupVA0V4HuuGPNrPA=; b=nnTF8YBQ AtGGJy/lKacV3rpudcLgG4HhzGRUTqngZmJS4HzGO7MMKLhRaRifBtlg/qkaQFAV DYBDEzOZuyEUAPxmlfSkNkrEcqsIEEioEcZG91rlt9dRXCBFNOaG7K/9sVWH6/Wj UIsFO45YfWrQ/9XvIh52ngoBf0CZ5mvUD3t7l8d1JPCnCmxUPTrgKkhaeDlLJVpQ ID5DjBjaBiFLg7GOanGbuiedNgu7uZHVMXU3QHkeODOlB1Q0pFMS7MlzFKDrjMOU RmPMWmbIo3ZmwjTEt907NM99bx75CQkIaRCflDxOPKtWHx1VBdXLAE400N6tr8dg mWySCtDAcAfj8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrleeigdehkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpedvkeelveefffekjefhffeuleetleefudeifeehuddugffghffhffehveevheeh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrg igihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 Dec 2021 08:51:31 -0500 (EST) From: Maxime Ripard To: Daniel Vetter , David Airlie , Rob Herring , Frank Rowand , Laurent Pinchart , Chen-Yu Tsai , Maxime Ripard , =?utf-8?q?Jernej_=C5=A0krabec?= Cc: linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org Subject: [PATCH v6 4/7] drm/sun4i: tcon: Refactor the LVDS and panel probing Date: Fri, 17 Dec 2021 14:51:16 +0100 Message-Id: <20211217135119.316781-5-maxime@cerno.tech> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211217135119.316781-1-maxime@cerno.tech> References: <20211217135119.316781-1-maxime@cerno.tech> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_055132_763407_F26A16B5 X-CRM114-Status: GOOD ( 19.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The current code to parse the DT, deal with the older device trees, and register either the RGB or LVDS output has so far grown organically into the bind function and has become quite hard to extend properly. Let's move it into a single function that grabs all the resources it needs and registers the proper panel output. Reviewed-by: Chen-Yu Tsai Reviewed-by: Laurent Pinchart Signed-off-by: Maxime Ripard --- drivers/gpu/drm/sun4i/sun4i_tcon.c | 127 +++++++++++++---------------- 1 file changed, 58 insertions(+), 69 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index 88db2d2a9336..4e01807ecf41 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -866,6 +866,63 @@ static int sun4i_tcon_init_regmap(struct device *dev, return 0; } +static int sun4i_tcon_register_panel(struct drm_device *drm, + struct sun4i_tcon *tcon) +{ + struct device_node *companion; + struct device_node *remote; + struct device *dev = tcon->dev; + int ret; + + /* + * If we have an LVDS panel connected to the TCON, we should + * just probe the LVDS connector. Otherwise, let's just register + * an RGB panel. + */ + remote = of_graph_get_remote_node(dev->of_node, 1, 0); + if (!tcon->quirks->supports_lvds || + !of_device_is_compatible(remote, "panel-lvds")) + return sun4i_rgb_init(drm, tcon); + + /* + * This can only be made optional since we've had DT + * nodes without the LVDS reset properties. + * + * If the property is missing, just disable LVDS, and + * print a warning. + */ + tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds"); + if (IS_ERR(tcon->lvds_rst)) { + dev_err(dev, "Couldn't get our reset line\n"); + return PTR_ERR(tcon->lvds_rst); + } else if (!tcon->lvds_rst) { + dev_warn(dev, "Missing LVDS reset property, please upgrade your DT\n"); + return -ENODEV; + } + + reset_control_reset(tcon->lvds_rst); + + /* + * This can only be made optional since we've had DT + * nodes without the LVDS clocks properties. + * + * If the property is missing, just disable LVDS, and + * print a warning. + */ + if (tcon->quirks->has_lvds_alt) { + tcon->lvds_pll = devm_clk_get_optional(dev, "lvds-alt"); + if (IS_ERR(tcon->lvds_pll)) { + dev_err(dev, "Couldn't get the LVDS PLL\n"); + return PTR_ERR(tcon->lvds_pll); + } else if (!tcon->lvds_pll) { + dev_warn(dev, "Missing LVDS PLL clock, please upgrade your DT\n"); + return -ENODEV; + } + } + + return sun4i_lvds_init(drm, tcon); +} + /* * On SoCs with the old display pipeline design (Display Engine 1.0), * the TCON is always tied to just one backend. Hence we can traverse @@ -1113,10 +1170,8 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, struct drm_device *drm = data; struct sun4i_drv *drv = drm->dev_private; struct sunxi_engine *engine; - struct device_node *remote; struct sun4i_tcon *tcon; struct reset_control *edp_rstc; - bool has_lvds_rst, has_lvds_alt, can_lvds; int ret; engine = sun4i_tcon_find_engine(drv, dev->of_node); @@ -1161,58 +1216,6 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, return ret; } - if (tcon->quirks->supports_lvds) { - /* - * This can only be made optional since we've had DT - * nodes without the LVDS reset properties. - * - * If the property is missing, just disable LVDS, and - * print a warning. - */ - tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds"); - if (IS_ERR(tcon->lvds_rst)) { - dev_err(dev, "Couldn't get our reset line\n"); - return PTR_ERR(tcon->lvds_rst); - } else if (tcon->lvds_rst) { - has_lvds_rst = true; - reset_control_reset(tcon->lvds_rst); - } else { - has_lvds_rst = false; - } - - /* - * This can only be made optional since we've had DT - * nodes without the LVDS reset properties. - * - * If the property is missing, just disable LVDS, and - * print a warning. - */ - if (tcon->quirks->has_lvds_alt) { - tcon->lvds_pll = devm_clk_get(dev, "lvds-alt"); - if (IS_ERR(tcon->lvds_pll)) { - if (PTR_ERR(tcon->lvds_pll) == -ENOENT) { - has_lvds_alt = false; - } else { - dev_err(dev, "Couldn't get the LVDS PLL\n"); - return PTR_ERR(tcon->lvds_pll); - } - } else { - has_lvds_alt = true; - } - } - - if (!has_lvds_rst || - (tcon->quirks->has_lvds_alt && !has_lvds_alt)) { - dev_warn(dev, "Missing LVDS properties, Please upgrade your DT\n"); - dev_warn(dev, "LVDS output disabled\n"); - can_lvds = false; - } else { - can_lvds = true; - } - } else { - can_lvds = false; - } - ret = sun4i_tcon_init_clocks(dev, tcon); if (ret) { dev_err(dev, "Couldn't init our TCON clocks\n"); @@ -1247,21 +1250,7 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, } if (tcon->quirks->has_channel_0) { - /* - * If we have an LVDS panel connected to the TCON, we should - * just probe the LVDS connector. Otherwise, just probe RGB as - * we used to. - */ - remote = of_graph_get_remote_node(dev->of_node, 1, 0); - if (of_device_is_compatible(remote, "panel-lvds")) - if (can_lvds) - ret = sun4i_lvds_init(drm, tcon); - else - ret = -EINVAL; - else - ret = sun4i_rgb_init(drm, tcon); - of_node_put(remote); - + ret = sun4i_tcon_register_panel(drm, tcon); if (ret < 0) goto err_free_dotclock; }