Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp547618img; Mon, 18 Mar 2019 08:52:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqydep2bk+hel0fG5cWmWU9WwDyR/kAivvWJBMd10H7rMDzmDLKXm2X+o6arYsjKXqEKar80 X-Received: by 2002:a65:47cb:: with SMTP id f11mr18365135pgs.18.1552924353392; Mon, 18 Mar 2019 08:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552924353; cv=none; d=google.com; s=arc-20160816; b=R35K9kamYdn843xsHJw5YtIeOXGG0GmGZpB0LN6Uty+EkrrR2qoJdxiBMOQjZSJ4E8 3MgB1bdIvPkNohm53JnYE8y54Rm5dZRADl9dti8Yv0oYMiL13pQhf1l3Hdf/IPqW4yw7 0NPSGiRtpwtIuyWPipGDgWgxmmIvYfpI8bQC5BP7+TQlo1n45N/zFi9IhQEyP33Fiyoy 6U2nYthxz2UKXyPQl4wZVDf+cdaaKVUqNg23dyoqfP7yGHJaki7QVqxVH/yw7jZpsk2z mDJUoxmd+QhkKtyjuMJlG3eZ8aB4LxJoIazODFKkTHJNBGzlxmLXQ40IEW2W/ClhDA6p 5YoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=QfeDgBOuQ5tpF5LLXDIXD7uji54rfpNSl2U8OU3CXmQ=; b=xST7cbj0KU0fzqXyadCWQInh4dMTve1iObHceJMXKu6ldjcJqEF8rhT6AW/T0+YB2w comNWwWdDX/nptjX8MlyFSvkBg7YJid3FdqAEL4To/HWDdmDCYX0UfJrlpMnpIIvuf4H F+xOP+NwN6QhADyJEfVzTOSJE1sFpBEDOA3Z2K2q6hm6Qdu4um1r5JmxFbtHejOg5Mu9 qD0QbM+5rctB4Di5OC1AdsYjTCxK0qz5fQhkBLPc61mV8hRjzwUPOOEGuQyozfUd4PSe AE7Fdqln15t8UCNOQZQlBQ6B7KVWBIRwVbGCbaGegmaDzaz7GJS9/A0XBeCOt97Z8DJG AVBQ== 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 cc11si2065125plb.346.2019.03.18.08.52.18; Mon, 18 Mar 2019 08:52:33 -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 S1727606AbfCRPuR (ORCPT + 99 others); Mon, 18 Mar 2019 11:50:17 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:59255 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbfCRPuR (ORCPT ); Mon, 18 Mar 2019 11:50:17 -0400 X-Originating-IP: 90.88.22.102 Received: from localhost (aaubervilliers-681-1-80-102.w90-88.abo.wanadoo.fr [90.88.22.102]) (Authenticated sender: maxime.ripard@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 5918320005; Mon, 18 Mar 2019 15:50:14 +0000 (UTC) Date: Mon, 18 Mar 2019 16:50:13 +0100 From: Maxime Ripard To: =?utf-8?B?TcOlbnMgUnVsbGfDpXJk?= 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 Message-ID: <20190318155013.lge2x2cp5hvyz52f@flea> References: <20190311134713.25876-1-mans@mansr.com> <20190311154702.eslw5ccol44vxcmy@flea> <20190314154105.o6r7hzeuiyajxh7v@flea> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zgta55aho4vg3yl5" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --zgta55aho4vg3yl5 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Mar 14, 2019 at 04:09:13PM +0000, M=E5ns Rullg=E5rd wrote: > Maxime Ripard writes: > > > On Mon, Mar 11, 2019 at 04:11:06PM +0000, M=E5ns Rullg=E5rd 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/s= un4i/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/d= rm/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_conn= ector *connector) > >> >> struct edid *edid; > >> >> int ret; > >> >> > >> >> - edid =3D drm_get_edid(connector, hdmi->i2c); > >> >> + edid =3D 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_con= nector *connector) > >> >> return ret; > >> >> } > >> >> > >> >> +static struct i2c_adapter *sun4i_hdmi_get_ddc(struct device *dev) > >> >> +{ > >> >> + struct device_node *phandle, *remote; > >> >> + struct i2c_adapter *ddc; > >> >> + > >> >> + remote =3D of_graph_get_remote_node(dev->of_node, 1, -1); > >> >> + if (!remote) > >> >> + return ERR_PTR(-EINVAL); > >> >> + > >> >> + phandle =3D of_parse_phandle(remote, "ddc-i2c-bus", 0); > >> >> + of_node_put(remote); > >> >> + if (!phandle) > >> >> + return NULL; > >> >> + > >> >> + ddc =3D 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 pointe= r. > >> > > >> >> +} > >> >> + > >> >> static const struct drm_connector_helper_funcs sun4i_hdmi_connecto= r_helper_funcs =3D { > >> >> .get_modes =3D 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 =3D 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. Maxime -- Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com --zgta55aho4vg3yl5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCXI++NQAKCRDj7w1vZxhR xU/fAPwKyH3UipugIw6d2GTBm58n3be3hj7Du3v4gb67f87YNAD/bcJ7Ga6d2liD a9a7pHBzi9jALRrCU+KSGfr5NY/T4AQ= =xMyn -----END PGP SIGNATURE----- --zgta55aho4vg3yl5--