Re: [PATCH 1/5] backlight: Add GPIO-based backlight driver

From: Laurent Pinchart
Date: Tue Nov 27 2012 - 06:53:07 EST


Hi Jingoo,

On Tuesday 27 November 2012 01:10:36 Jingoo Han wrote:
> On Saturday, November 24, 2012 1:35 AM, Laurent Pinchart wrote
>
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> > ---
> >
> > drivers/video/backlight/Kconfig | 7 ++
> > drivers/video/backlight/Makefile | 1 +
> > drivers/video/backlight/gpio_backlight.c | 158 +++++++++++++++++++++++++
> > include/video/gpio_backlight.h | 21 ++++
> > 4 files changed, 187 insertions(+), 0 deletions(-)
> > create mode 100644 drivers/video/backlight/gpio_backlight.c
> > create mode 100644 include/video/gpio_backlight.h
>
>
> [...]
>
>
> > +static int __devinit gpio_backlight_probe(struct platform_device *pdev)
> > +{
> > + struct gpio_backlight_platform_data *pdata = pdev->dev.platform_data;
> > + struct backlight_properties props;
> > + struct backlight_device *bl;
> > + struct gpio_backlight *gbl;
> > + int ret;
> > +
> > + gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
> > + if (gbl == NULL)
> > + return -ENOMEM;
> > +
> > + gbl->dev = &pdev->dev;
> > +
> > + if (!pdata) {
> > + dev_err(&pdev->dev, "failed to find platform data\n");
> > + return -ENODEV;
> > + }
> > +
> > + gbl->fbdev = pdata->fbdev;
> > + gbl->gpio = pdata->gpio;
> > + gbl->active = pdata->active_low ? 0 : 1;
> > +
> > + ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT,
> > + pdata->name);
>
>
> Please use GPIOF_INIT flags if you want to turn off GPIO backlight.
> If gbl->active is inverted, GPIOF_INIT_HIGH can be used as below:
>
> ret = devm_gpio_request_one(gbl->dev, gbl->gpio,
> GPIOF_DIR_OUT | (gbl->active ?
> GPIOF_INIT_LOW : GPIOF_INIT_HIGH),
> pdata->name);

Good point, thank you. I'll fix that.

> > + if (ret < 0) {
> > + dev_err(&pdev->dev, "unable to request GPIO\n");
> > + return ret;
> > + }
> > +
> > + memset(&props, 0, sizeof(props));
> > + props.type = BACKLIGHT_RAW;
> > + props.max_brightness = 1;
> > + bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, gbl,
> > + &gpio_backlight_ops, &props);
> > + if (IS_ERR(bl)) {
> > + dev_err(&pdev->dev, "failed to register backlight\n");
> > + return PTR_ERR(bl);
> > + }
> > +
> > + bl->props.brightness = pdata->def_value;
> > + backlight_update_status(bl);
> > +
> > + platform_set_drvdata(pdev, bl);
> > + return 0;
> > +}

--
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/