Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp573817img; Mon, 18 Mar 2019 09:25:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwhmzJwTTOB2M0m3EMRUsGzJ2K0Z20RMz1w0EjXX2auN3/4XIBpC8OaKlepqQesunlRBdW X-Received: by 2002:aa7:90d3:: with SMTP id k19mr12581146pfk.41.1552926301193; Mon, 18 Mar 2019 09:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552926301; cv=none; d=google.com; s=arc-20160816; b=JISD6raavA/Q7M2dXjvJiSOe18UQtpHCtj2kJ0SxeebyVFtr4wpbK9PsUDQOMWmSEi k73bwYT5lM+XXALWwkR5vnEKW51bYgEIxSO3tJZ1bP60ZbVoIV26XRufeighi9U7pGMz GUdFJQedcMDSVHIb+FigwPxz84GLF7dtXHLh9Oqe5nbenf3ZrRn8ad7jeZIUj1h4m0B4 LbonQdsAX5W2UZejWC5wz6pYdCyAP1P3TZymUcmdue6rDsK1mQtI/MMg9s5i5AWGybUO hCUgHv6soBtZskV40/BozzvwF+28tj/AbeJCni13FMIIQpJNXM3y8nj5jFM4ZFRbQiet fRKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from; bh=JYPvvfNjTX5bKvd+G8WfQ3TEnpE7zQW7E/iagxfgsm0=; b=s9NzCXnurJiOFHOpsb+g2NflQBL9q/9LqchNG35n02gqmk9yEpJuR1lYVn4MqOfvZ4 FjVd5eGGmaSCx0GB1g3gAiN1xvqlNJ89NwjoVPVVR1juFTI9PP5geYhMzjHHKXbAZP4V g3ZvXlD34alzcaiHELOX2uZRgRR9kwPBLt5NHFJjxeV0VCCeRJ0L4Sldq9k23Spn0auF LeoGq9SXkVFei7prJ/lUmfZJUmeoOHieGe2UxfRf/IeSYGJCmu5hLM2z9VlKoBWsmV6x CoD5n0Y4IOYCxtFSNiykWaEzPb+si0JT+EDLg1APFuFk4wSl5vjYRr1vQlJsHaxjrJ8/ Wlzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si8977958pgv.70.2019.03.18.09.24.45; Mon, 18 Mar 2019 09:25:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbfCRQX6 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 18 Mar 2019 12:23:58 -0400 Received: from unicorn.mansr.com ([81.2.72.234]:57406 "EHLO unicorn.mansr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfCRQX6 (ORCPT ); Mon, 18 Mar 2019 12:23:58 -0400 Received: by unicorn.mansr.com (Postfix, from userid 51770) id 405CA1562F; Mon, 18 Mar 2019 16:23:56 +0000 (GMT) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Maxime Ripard Cc: David Airlie , Chen-Yu Tsai , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/sun4i: hdmi: add support for ddc-i2c-bus property References: <20190311134713.25876-1-mans@mansr.com> <20190311154702.eslw5ccol44vxcmy@flea> <20190314154105.o6r7hzeuiyajxh7v@flea> <20190318155013.lge2x2cp5hvyz52f@flea> Date: Mon, 18 Mar 2019 16:23:56 +0000 In-Reply-To: <20190318155013.lge2x2cp5hvyz52f@flea> (Maxime Ripard's message of "Mon, 18 Mar 2019 16:50:13 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Maxime Ripard writes: > On Thu, Mar 14, 2019 at 04:09:13PM +0000, M?ns Rullg?rd wrote: >> Maxime Ripard writes: >> >> > On Mon, Mar 11, 2019 at 04:11:06PM +0000, M?ns Rullg?rd wrote: >> >> Maxime Ripard writes: >> >> >> >> > Hi! >> >> > >> >> > On Mon, Mar 11, 2019 at 01:47:13PM +0000, Mans Rullgard wrote: >> >> >> Sometimes it is desirabled to use a separate i2c controller for ddc >> >> >> access. This adds support for the ddc-i2c-bus property of the >> >> >> hdmi-connector node, using the specified controller if provided. >> >> >> >> >> >> Signed-off-by: Mans Rullgard >> >> >> --- >> >> >> drivers/gpu/drm/sun4i/sun4i_hdmi.h | 1 + >> >> >> drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 37 +++++++++++++++++++++++--- >> >> >> 2 files changed, 35 insertions(+), 3 deletions(-) >> >> >> >> >> >> diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi.h b/drivers/gpu/drm/sun4i/sun4i_hdmi.h >> >> >> index b685ee11623d..b08c4453d47c 100644 >> >> >> --- a/drivers/gpu/drm/sun4i/sun4i_hdmi.h >> >> >> +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi.h >> >> >> @@ -269,6 +269,7 @@ struct sun4i_hdmi { >> >> >> struct clk *tmds_clk; >> >> >> >> >> >> struct i2c_adapter *i2c; >> >> >> + struct i2c_adapter *ddc_i2c; >> >> >> >> >> >> /* Regmap fields for I2C adapter */ >> >> >> struct regmap_field *field_ddc_en; >> >> >> diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c >> >> >> index 061d2e0d9011..5b2fac79f5d6 100644 >> >> >> --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c >> >> >> +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c >> >> >> @@ -212,7 +212,7 @@ static int sun4i_hdmi_get_modes(struct drm_connector *connector) >> >> >> struct edid *edid; >> >> >> int ret; >> >> >> >> >> >> - edid = drm_get_edid(connector, hdmi->i2c); >> >> >> + edid = drm_get_edid(connector, hdmi->ddc_i2c ?: hdmi->i2c); >> >> > >> >> > You can't test whether ddc_i2c is NULL or not... >> >> > >> >> >> if (!edid) >> >> >> return 0; >> >> >> >> >> >> @@ -228,6 +228,28 @@ static int sun4i_hdmi_get_modes(struct drm_connector *connector) >> >> >> return ret; >> >> >> } >> >> >> >> >> >> +static struct i2c_adapter *sun4i_hdmi_get_ddc(struct device *dev) >> >> >> +{ >> >> >> + struct device_node *phandle, *remote; >> >> >> + struct i2c_adapter *ddc; >> >> >> + >> >> >> + remote = of_graph_get_remote_node(dev->of_node, 1, -1); >> >> >> + if (!remote) >> >> >> + return ERR_PTR(-EINVAL); >> >> >> + >> >> >> + phandle = of_parse_phandle(remote, "ddc-i2c-bus", 0); >> >> >> + of_node_put(remote); >> >> >> + if (!phandle) >> >> >> + return NULL; >> >> >> + >> >> >> + ddc = of_get_i2c_adapter_by_node(phandle); >> >> >> + of_node_put(phandle); >> >> >> + if (!ddc) >> >> >> + return ERR_PTR(-EPROBE_DEFER); >> >> >> + >> >> >> + return ddc; >> >> > >> >> > ... Since even in (most) error cases you're returning a !NULL pointer. >> >> > >> >> >> +} >> >> >> + >> >> >> static const struct drm_connector_helper_funcs sun4i_hdmi_connector_helper_funcs = { >> >> >> .get_modes = sun4i_hdmi_get_modes, >> >> >> }; >> >> >> @@ -575,6 +597,12 @@ static int sun4i_hdmi_bind(struct device *dev, struct device *master, >> >> >> goto err_disable_mod_clk; >> >> >> } >> >> >> >> >> >> + hdmi->ddc_i2c = sun4i_hdmi_get_ddc(dev); >> >> >> + if (IS_ERR(hdmi->ddc_i2c)) { >> >> >> >> ... which is checked here. >> >> >> >> The property is optional, so the idea was to return null in that case >> >> and use the built-in controller. If the property exists but some error >> >> occurs, we want to abort rather than proceed with the fallback which >> >> almost certainly won't work. >> >> >> >> Maybe I got something wrong in that logic. >> > >> > Indeed, I just got confused. I guess returning ENODEV in such a case, >> > and testing for that, would make things more obvious. >> >> There's also a case I hadn't thought of: property exists but isn't a >> valid phandle. What do you think is the correct action in that case? > > I think we would have that one covered. of_parse_phandle will return > !NULL, but then of_get_i2c_adapter_by_node will return NULL since we > wouldn't have an associated i2c adapter to the bogus phandle, and you > are checking for that already. of_parse_phandle() doesn't differentiate between a missing property and an existing non-phandle value. The following cases are possible with this patch: - ddc-i2c-bus points to valid i2c controller node: use this for ddc - no ddc-i2c-bus property: return NULL, use internal i2c - ddc-i2c-bus exists but isn't a phandle: likewise - ddc-i2c-bus points to a non-i2c-controller node: EPROBE_DEFER The last two cases obviously mean the devicetree is invalid, so perhaps it doesn't matter much what happens then. I don't think it's possible to distinguish between a well-formed phandle pointing to some bogus node and a good one where the i2c driver hasn't been probed yet. -- M?ns Rullg?rd