devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, Pawel Moll <pawel.moll@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	David Airlie <airlied@linux.ie>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Kumar Gala <galak@codeaurora.org>
Subject: Re: [PATCH v2 6/6] drm/panel: rpi-touchscreen: Set status to "fail" when ->probe() fails
Date: Fri, 4 May 2018 10:06:53 +0200	[thread overview]
Message-ID: <20180504100653.6ee70802@bbrezillon> (raw)
In-Reply-To: <CAL_JsqJMarPW6sdcF1ZFCEr6wGyPgi2yhYMCxgypUYYwN7ayfQ@mail.gmail.com>

Hi Rob,

On Thu, 3 May 2018 12:12:39 -0500
Rob Herring <robh+dt@kernel.org> wrote:

> On Thu, May 3, 2018 at 11:40 AM, Boris Brezillon
> <boris.brezillon@bootlin.com> wrote:
> > The device might be described in the device tree but not connected to
> > the I2C bus. Update the status property so that the DRM panel logic
> > returns -ENODEV when someone tries to get the panel attached to this
> > DT node.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
> > ---
> >  .../gpu/drm/panel/panel-raspberrypi-touchscreen.c  | 35 ++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> > index 2c9c9722734f..b8fcb1acef75 100644
> > --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> > +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> > @@ -358,6 +358,39 @@ static const struct drm_panel_funcs rpi_touchscreen_funcs = {
> >         .get_modes = rpi_touchscreen_get_modes,
> >  };
> >
> > +static void rpi_touchscreen_set_status_fail(struct i2c_client *i2c)
> > +{
> > +       struct property *newprop;
> > +
> > +       newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
> > +       if (!newprop)
> > +               return;
> > +
> > +       newprop->name = kstrdup("status", GFP_KERNEL);
> > +       if (!newprop->name)
> > +               goto err;
> > +
> > +       newprop->value = kstrdup("fail", GFP_KERNEL);
> > +       if (!newprop->value)
> > +               goto err;
> > +
> > +       newprop->length = sizeof("fail");
> > +
> > +       if (of_update_property(i2c->dev.of_node, newprop))
> > +               goto err;
> > +  
> 
> As I mentioned on irc, can you make this a common DT function.

Yep, will move that to drivers/of/base.c and make it generic.

> 
> I'm not sure if it matters that we set status to fail vs. disabled. I
> somewhat prefer the latter as we already have other cases and I'd
> rather the api not pass a string in. I can't think of any reason to
> distinguish the difference between fail and disabled.

Well, I just read the ePAPR doc pointed by Thierry [1] (section 2.3.4),
and "fail" seemed like a good match for what we are trying to express
here: "we failed to communicate with the device in the probe function
and want to mark it unusable", which is a bit different from "the
device was explicitly disabled by the user".

Anyway, if you think "disabled" is more appropriate, I'll use that.

> 
> > +       /* We intentionally leak the memory we allocate here, because the new
> > +        * OF property might live longer than the underlying dev, so no way
> > +        * we can use devm_kzalloc() here.
> > +        */
> > +       return;
> > +
> > +err:
> > +       kfree(newprop->value);
> > +       kfree(newprop->name);
> > +       kfree(newprop);
> > +}
> > +
> >  static int rpi_touchscreen_probe(struct i2c_client *i2c,
> >                                  const struct i2c_device_id *id)
> >  {
> > @@ -382,6 +415,7 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
> >
> >         ver = rpi_touchscreen_i2c_read(ts, REG_ID);
> >         if (ver < 0) {
> > +               rpi_touchscreen_set_status_fail(i2c);  
> 
> I've thought some more about this and I still think this should be
> handled in the driver core or i2c core.
> 
> The reason is simple. I think the state of the system should be the
> same after this as if you booted with 'status = "disabled"' for this
> node. And that means the device should be removed completely because
> we don't create struct device's for disabled nodes.

That was my feeling to when first discussing the issue with Daniel and
Thierry on IRC, but after digging a bit in the code I'm no longer sure
this is a good idea. At least, I don't think basing the decision to
disable the device (or mark it unusable) based on the return value of
the probe function is a good idea. What I can do is:

1/ provide a function to change the status prop in of.h
2/ let each driver call this function if they want to
3/ let the I2C core test the status prop again after the probe function
   has returned an error to determine whether the device (I mean struct
   i2c_client/device object) should be removed

Would that work for you?

Regards,

Boris

[1]https://elinux.org/images/c/cf/Power_ePAPR_APPROVED_v1.1.pdf
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2018-05-04  8:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 16:40 [PATCH v2 0/6] drm/panel: Handle the "panel is missing" case properly Boris Brezillon
2018-05-03 16:40 ` [PATCH v2 1/6] drm/tegra: Fix a device_node leak when the DRM panel is not found Boris Brezillon
2018-05-04  9:50   ` Thierry Reding
2018-05-04  9:53     ` Thierry Reding
2018-05-04  9:54     ` Boris Brezillon
2018-05-03 16:40 ` [PATCH v2 2/6] drm/panel: Make of_drm_find_panel() return an ERR_PTR() instead of NULL Boris Brezillon
2018-05-04 10:18   ` Thierry Reding
2018-05-04 11:58     ` Boris Brezillon
2018-05-04 12:11       ` Thierry Reding
2018-05-03 16:40 ` [PATCH v2 3/6] drm/panel: Let of_drm_find_panel() return -ENODEV when the panel is disabled Boris Brezillon
2018-05-04 10:20   ` Thierry Reding
2018-05-03 16:40 ` [PATCH v2 4/6] drm/of: Make drm_of_find_panel_or_bridge() fail when the device " Boris Brezillon
2018-05-04 10:20   ` Thierry Reding
2018-05-03 16:40 ` [PATCH v2 5/6] drm/vc4: Support the case where the DSI " Boris Brezillon
2018-05-04 10:28   ` Thierry Reding
2018-05-04 12:05     ` Boris Brezillon
2018-05-04 13:29       ` Thierry Reding
2018-05-04 13:49         ` Boris Brezillon
2018-05-04 13:56           ` Thierry Reding
2018-05-04 10:30   ` Thierry Reding
2018-05-04 12:00     ` Boris Brezillon
2018-05-03 16:40 ` [PATCH v2 6/6] drm/panel: rpi-touchscreen: Set status to "fail" when ->probe() fails Boris Brezillon
2018-05-03 17:12   ` Rob Herring
2018-05-04  8:06     ` Boris Brezillon [this message]
2018-05-04  9:47       ` Thierry Reding
2018-05-04 12:17         ` Boris Brezillon
2018-05-04 14:20           ` Daniel Vetter
2018-05-04 14:24             ` Boris Brezillon
2018-05-04 15:01               ` Boris Brezillon
2018-05-04 19:29             ` Rob Herring
2018-05-07 11:14               ` Boris Brezillon

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=20180504100653.6ee70802@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=airlied@linux.ie \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).