All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: David Airlie <airlied@linux.ie>, Chen-Yu Tsai <wens@csie.org>,
	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
Date: Mon, 11 Mar 2019 16:11:06 +0000	[thread overview]
Message-ID: <yw1xef7d4cit.fsf@mansr.com> (raw)
In-Reply-To: <20190311154702.eslw5ccol44vxcmy@flea> (Maxime Ripard's message of "Mon, 11 Mar 2019 16:47:02 +0100")

Maxime Ripard <maxime.ripard@bootlin.com> 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 <mans@mansr.com>
>> ---
>>  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.

-- 
Måns Rullgård

WARNING: multiple messages have this Message-ID (diff)
From: "Måns Rullgård" <mans@mansr.com>
To: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: David Airlie <airlied@linux.ie>, Chen-Yu Tsai <wens@csie.org>,
	linux-arm-kernel@lists.infradead.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/sun4i: hdmi: add support for ddc-i2c-bus property
Date: Mon, 11 Mar 2019 16:11:06 +0000	[thread overview]
Message-ID: <yw1xef7d4cit.fsf@mansr.com> (raw)
In-Reply-To: <20190311154702.eslw5ccol44vxcmy@flea> (Maxime Ripard's message of "Mon, 11 Mar 2019 16:47:02 +0100")

Maxime Ripard <maxime.ripard@bootlin.com> 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 <mans@mansr.com>
>> ---
>>  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.

-- 
Måns Rullgård

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-03-11 16:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-11 13:47 [PATCH] drm/sun4i: hdmi: add support for ddc-i2c-bus property Mans Rullgard
2019-03-11 13:47 ` Mans Rullgard
2019-03-11 15:47 ` Maxime Ripard
2019-03-11 15:47   ` Maxime Ripard
2019-03-11 15:47   ` Maxime Ripard
2019-03-11 16:11   ` Måns Rullgård [this message]
2019-03-11 16:11     ` Måns Rullgård
2019-03-14 15:41     ` Maxime Ripard
2019-03-14 15:41       ` Maxime Ripard
2019-03-14 16:09       ` Måns Rullgård
2019-03-14 16:09         ` Måns Rullgård
2019-03-18 15:50         ` Maxime Ripard
2019-03-18 15:50           ` Maxime Ripard
2019-03-18 16:23           ` Måns Rullgård
2019-03-18 16:23             ` Måns Rullgård
2019-03-19 12:34             ` Maxime Ripard
2019-03-19 12:34               ` Maxime Ripard
2019-03-19 12:34               ` Maxime Ripard
2019-03-19 12:48               ` Måns Rullgård
2019-03-19 12:48                 ` Måns Rullgård
2019-03-21 15:44                 ` Maxime Ripard
2019-03-21 15:44                   ` Maxime Ripard
2019-03-21 18:00                   ` Måns Rullgård
2019-03-21 18:00                     ` Måns Rullgård
2019-03-26 19:49                     ` Maxime Ripard
2019-03-26 19:49                       ` Maxime Ripard
2019-03-28 13:02                       ` Mans Rullgard
2019-03-28 13:02                         ` Mans Rullgard
2019-04-01 11:58                         ` Maxime Ripard
2019-04-01 11:58                           ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xef7d4cit.fsf@mansr.com \
    --to=mans@mansr.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.