From patchwork Wed Sep 29 08:42:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12524919 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51418C433F5 for ; Wed, 29 Sep 2021 08:46:06 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 22CE36128E for ; Wed, 29 Sep 2021 08:46:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 22CE36128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cerno.tech Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=krZzD73lgcGcJFRAvOspFP5lb0nS1YCxK8JMNPByQSQ=; b=n8/MUFi2XZn06J eXENXteXyQh+2u2LMP+07jHdz/QMd5iFvX3WxMt32YvBIcPdHym9v9ET7eU2tXskeSaFPer06g7T/ r9pTud9nJJGDl4HDhUH150GrvA+bKwNmiiIsQruD1If+wjWDXihWsL53DB7vJqcNqUyeWrWFkqZeq DOsFDeLwgnUkGwXbCAnRhdKezCCeQY8PcJ6nPqAxeS95J/88fnN3S520/fBdHWI4F4QpOJLgro6kp l8WLAjR1pvntQlLDoQP3CTyJrLofroMNH6C/3UULPSQxUy7NDE7iAAiOcVGxkTSHHyj3CKxpi5J/O cS3e/8oAJIvKbfIM+5pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVVBq-00ATfA-AM; Wed, 29 Sep 2021 08:43:46 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVVB1-00ATPg-2p for linux-arm-kernel@lists.infradead.org; Wed, 29 Sep 2021 08:42:57 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 03B9C3200F9F; Wed, 29 Sep 2021 04:42:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 29 Sep 2021 04:42:54 -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=fm1; bh=m7erXvXAgiomR 18EaZboPnGxQzKM2J1BreGTXbt+er0=; b=fJK16vRqXpt34z6Xpz7OAJEcgjRrr xvmeiq2Ja1I5r1UCYdYM2beU6X9J+GlMDrgRfbPb7rNRzHNvNc43KlTXDJ8EnqhH gNzVvlKT+6Ct8Jlw0b7+saJvSjDM8b3skPhi3otNNaRIHgmqhBcOZVWz/TjTA3YL 9WYwkO0UOLIs7YE7vCtPz1eY4CsxCa790/IPxk3uLKqT1uDoEi7tKgT787DK5/Ip P7ApbiIctzJ7piLMDWhlQhc+ZNEYdznEZ9avkDYEKWvkCs/cxI9ICbuK+Mco0oOL Cg8EntG7DLYK1pCPL2UFGCrLsS3BM2SZHwJBd7TQ/pos+MmOIwxHH6J9Q== 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=m7erXvXAgiomR18EaZboPnGxQzKM2J1BreGTXbt+er0=; b=PBNmC6Da gRktST4wvpvXixTlSOkUZV9qv8/gh6hBB/YvNlmBy11fsyx11T0kDeSskbKIzim0 v4Hs/JSito7YQrifmcoRzwSS7p37CxeWdYO6kVJ6JT7ypDZigYLk0xAdtT9k84Cc H4feoan6vFo7HYei1X2MPJCC3rrgbufB9fR5R4lU5RI12Nw9EoSbe8UzCxMPB0je 4Agr/+d/YFzpiWe05oPgErfAeCj4UmHKZroZ4jdKCtls7xqSBy6SIxq+9oNJSE6X BVLvroKfRNM4gd/Botcaqr0dRlia07I/adSCAYIZxdvs9y+FPop+EHs2Q0dT/VKF h/edju+GM6KZ0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudekvddgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepmh grgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Sep 2021 04:42:53 -0400 (EDT) From: Maxime Ripard To: Rob Herring , Frank Rowand , Chen-Yu Tsai , Maxime Ripard , =?utf-8?q?Jernej_=C5=A0krabec?= , Daniel Vetter , David Airlie , Laurent Pinchart Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 4/7] drm/sun4i: tcon: Refactor the LVDS and panel probing Date: Wed, 29 Sep 2021 10:42:31 +0200 Message-Id: <20210929084234.1271915-5-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210929084234.1271915-1-maxime@cerno.tech> References: <20210929084234.1271915-1-maxime@cerno.tech> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_014255_228608_58865043 X-CRM114-Status: GOOD ( 20.89 ) 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 9f06dec0fc61..e38e60faafd2 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -868,6 +868,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 @@ -1115,10 +1172,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); @@ -1163,58 +1218,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"); @@ -1249,21 +1252,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; }