2013-04-11 18:36:37

by Andrew Bresticker

[permalink] [raw]
Subject: [PATCH] backlight: platform_lcd: introduce probe callback

Platform LCD devices may need to do some device-specific
initialization before they can be used (regulator or GPIO setup,
for example), but currently the driver does not support any way of
doing this. This patch adds a probe() callback to plat_lcd_data
which platform LCD devices can set to indicate that device-specific
initialization is needed.

Signed-off-by: Andrew Bresticker <[email protected]>
---
drivers/video/backlight/platform_lcd.c | 8 ++++++++
include/video/platform_lcd.h | 1 +
2 files changed, 9 insertions(+)

diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
index 54d94de..2fb24a1 100644
--- a/drivers/video/backlight/platform_lcd.c
+++ b/drivers/video/backlight/platform_lcd.c
@@ -86,6 +86,14 @@ static int platform_lcd_probe(struct platform_device *pdev)
return -EINVAL;
}

+ if (pdata->probe) {
+ err = pdata->probe(pdata);
+ if (err) {
+ dev_err(dev, "platform probe failed: %d\n", err);
+ return err;
+ }
+ }
+
plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
GFP_KERNEL);
if (!plcd) {
diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
index ad3bdfe..23864b2 100644
--- a/include/video/platform_lcd.h
+++ b/include/video/platform_lcd.h
@@ -15,6 +15,7 @@ struct plat_lcd_data;
struct fb_info;

struct plat_lcd_data {
+ int (*probe)(struct plat_lcd_data *);
void (*set_power)(struct plat_lcd_data *, unsigned int power);
int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
};
--
1.8.1.3


2013-04-11 19:14:44

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH] backlight: platform_lcd: introduce probe callback

Andrew,

On Thu, Apr 11, 2013 at 11:36 AM, Andrew Bresticker
<[email protected]> wrote:
> + if (pdata->probe) {
> + err = pdata->probe(pdata);
> + if (err) {
> + dev_err(dev, "platform probe failed: %d\n", err);

It would probably be good not to print in the case of -EPROBE_DEFER?

Otherwise this looks good to me.

-Doug

2013-04-11 20:17:58

by Andrew Bresticker

[permalink] [raw]
Subject: Re: [PATCH] backlight: platform_lcd: introduce probe callback

> It would probably be good not to print in the case of -EPROBE_DEFER?

Actually, I think I'll just kill the print all together since the
caller will print something anyways.

-Andrew

2013-04-11 20:24:54

by Andrew Bresticker

[permalink] [raw]
Subject: [PATCH v2] backlight: platform_lcd: introduce probe callback

Platform LCD devices may need to do some device-specific
initialization before they can be used (regulator or GPIO setup,
for example), but currently the driver does not support any way of
doing this. This patch adds a probe() callback to plat_lcd_data
which platform LCD devices can set to indicate that device-specific
initialization is needed.

Signed-off-by: Andrew Bresticker <[email protected]>
---
drivers/video/backlight/platform_lcd.c | 6 ++++++
include/video/platform_lcd.h | 1 +
2 files changed, 7 insertions(+)

diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
index 17a6b83..f46180e 100644
--- a/drivers/video/backlight/platform_lcd.c
+++ b/drivers/video/backlight/platform_lcd.c
@@ -86,6 +86,12 @@ static int platform_lcd_probe(struct platform_device *pdev)
return -EINVAL;
}

+ if (pdata->probe) {
+ err = pdata->probe(pdata);
+ if (err)
+ return err;
+ }
+
plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
GFP_KERNEL);
if (!plcd) {
diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
index ad3bdfe..23864b2 100644
--- a/include/video/platform_lcd.h
+++ b/include/video/platform_lcd.h
@@ -15,6 +15,7 @@ struct plat_lcd_data;
struct fb_info;

struct plat_lcd_data {
+ int (*probe)(struct plat_lcd_data *);
void (*set_power)(struct plat_lcd_data *, unsigned int power);
int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
};
--
1.8.1.3

2013-04-11 20:30:57

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v2] backlight: platform_lcd: introduce probe callback

Andrew,

On Thu, Apr 11, 2013 at 1:24 PM, Andrew Bresticker
<[email protected]> wrote:
> Platform LCD devices may need to do some device-specific
> initialization before they can be used (regulator or GPIO setup,
> for example), but currently the driver does not support any way of
> doing this. This patch adds a probe() callback to plat_lcd_data
> which platform LCD devices can set to indicate that device-specific
> initialization is needed.
>
> Signed-off-by: Andrew Bresticker <[email protected]>
> ---
> drivers/video/backlight/platform_lcd.c | 6 ++++++
> include/video/platform_lcd.h | 1 +
> 2 files changed, 7 insertions(+)

Reviewed-by: Doug Anderson <[email protected]>

2013-04-15 01:47:21

by Jingoo Han

[permalink] [raw]
Subject: Re: [PATCH v2] backlight: platform_lcd: introduce probe callback

On Friday, April 12, 2013 5:25 AM, Andrew Bresticker wrote:
>
> Platform LCD devices may need to do some device-specific
> initialization before they can be used (regulator or GPIO setup,
> for example), but currently the driver does not support any way of
> doing this. This patch adds a probe() callback to plat_lcd_data
> which platform LCD devices can set to indicate that device-specific
> initialization is needed.
>
> Signed-off-by: Andrew Bresticker <[email protected]>

CC'ed Andrew Morton,

It looks good.
Acked-by: Jingoo Han <[email protected]>

Best regards,
Jingoo Han


> ---
> drivers/video/backlight/platform_lcd.c | 6 ++++++
> include/video/platform_lcd.h | 1 +
> 2 files changed, 7 insertions(+)
>
> diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
> index 17a6b83..f46180e 100644
> --- a/drivers/video/backlight/platform_lcd.c
> +++ b/drivers/video/backlight/platform_lcd.c
> @@ -86,6 +86,12 @@ static int platform_lcd_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> + if (pdata->probe) {
> + err = pdata->probe(pdata);
> + if (err)
> + return err;
> + }
> +
> plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
> GFP_KERNEL);
> if (!plcd) {
> diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
> index ad3bdfe..23864b2 100644
> --- a/include/video/platform_lcd.h
> +++ b/include/video/platform_lcd.h
> @@ -15,6 +15,7 @@ struct plat_lcd_data;
> struct fb_info;
>
> struct plat_lcd_data {
> + int (*probe)(struct plat_lcd_data *);
> void (*set_power)(struct plat_lcd_data *, unsigned int power);
> int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
> };
> --
> 1.8.1.3
>

2013-04-15 23:06:37

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH v2] backlight: platform_lcd: introduce probe callback

On Thu, 11 Apr 2013 13:24:50 -0700 Andrew Bresticker <[email protected]> wrote:

> Platform LCD devices may need to do some device-specific
> initialization before they can be used (regulator or GPIO setup,
> for example), but currently the driver does not support any way of
> doing this. This patch adds a probe() callback to plat_lcd_data
> which platform LCD devices can set to indicate that device-specific
> initialization is needed.
>
> index 17a6b83..f46180e 100644
> --- a/drivers/video/backlight/platform_lcd.c
> +++ b/drivers/video/backlight/platform_lcd.c
> @@ -86,6 +86,12 @@ static int platform_lcd_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> + if (pdata->probe) {
> + err = pdata->probe(pdata);
> + if (err)
> + return err;
> + }
> +
> plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
> GFP_KERNEL);
> if (!plcd) {
> diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
> index ad3bdfe..23864b2 100644
> --- a/include/video/platform_lcd.h
> +++ b/include/video/platform_lcd.h
> @@ -15,6 +15,7 @@ struct plat_lcd_data;
> struct fb_info;
>
> struct plat_lcd_data {
> + int (*probe)(struct plat_lcd_data *);
> void (*set_power)(struct plat_lcd_data *, unsigned int power);
> int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
> };

Sigh. I see that this entire interface has been lovingly undocumented.
It's an invitation for us to grow bugs, incompatibilities, leaks, etc.

Possible example: what happens if pdata->probe does some resource
allocation or device initialisation which should be backed out if, say,
platform_lcd_probe() later fails?

2013-04-16 00:53:16

by Jingoo Han

[permalink] [raw]
Subject: Re: [PATCH v2] backlight: platform_lcd: introduce probe callback

On Tuesday, April 16, 2013 8:07 AM, Andrew Morton wrote:
>
> On Thu, 11 Apr 2013 13:24:50 -0700 Andrew Bresticker <[email protected]> wrote:
>
> > Platform LCD devices may need to do some device-specific
> > initialization before they can be used (regulator or GPIO setup,
> > for example), but currently the driver does not support any way of
> > doing this. This patch adds a probe() callback to plat_lcd_data
> > which platform LCD devices can set to indicate that device-specific
> > initialization is needed.
> >
> > index 17a6b83..f46180e 100644
> > --- a/drivers/video/backlight/platform_lcd.c
> > +++ b/drivers/video/backlight/platform_lcd.c
> > @@ -86,6 +86,12 @@ static int platform_lcd_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> >
> > + if (pdata->probe) {
> > + err = pdata->probe(pdata);
> > + if (err)
> > + return err;
> > + }
> > +
> > plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
> > GFP_KERNEL);
> > if (!plcd) {
> > diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
> > index ad3bdfe..23864b2 100644
> > --- a/include/video/platform_lcd.h
> > +++ b/include/video/platform_lcd.h
> > @@ -15,6 +15,7 @@ struct plat_lcd_data;
> > struct fb_info;
> >
> > struct plat_lcd_data {
> > + int (*probe)(struct plat_lcd_data *);
> > void (*set_power)(struct plat_lcd_data *, unsigned int power);
> > int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
> > };
>
> Sigh. I see that this entire interface has been lovingly undocumented.
> It's an invitation for us to grow bugs, incompatibilities, leaks, etc.
>
> Possible example: what happens if pdata->probe does some resource
> allocation or device initialisation which should be backed out if, say,
> platform_lcd_probe() later fails?

Hi Andrew,

I agree with you.
Indeed, the documentation is necessary.

Andrew Bresticker,
Would you make the document?
It would be very helpful.

Best regards,
Jingoo Han