mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / video / backlight / gpio_backlight.c
blob5fa217f9f4457232e15d23d27ab06db24b68710c
1 /*
2 * gpio_backlight.c - Simple GPIO-controlled backlight
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/backlight.h>
10 #include <linux/err.h>
11 #include <linux/fb.h>
12 #include <linux/gpio.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/platform_data/gpio_backlight.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
20 struct gpio_backlight {
21 struct device *dev;
22 struct device *fbdev;
24 int gpio;
25 int active;
28 static int gpio_backlight_update_status(struct backlight_device *bl)
30 struct gpio_backlight *gbl = bl_get_data(bl);
31 int brightness = bl->props.brightness;
33 if (bl->props.power != FB_BLANK_UNBLANK ||
34 bl->props.fb_blank != FB_BLANK_UNBLANK ||
35 bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
36 brightness = 0;
38 gpio_set_value(gbl->gpio, brightness ? gbl->active : !gbl->active);
40 return 0;
43 static int gpio_backlight_get_brightness(struct backlight_device *bl)
45 return bl->props.brightness;
48 static int gpio_backlight_check_fb(struct backlight_device *bl,
49 struct fb_info *info)
51 struct gpio_backlight *gbl = bl_get_data(bl);
53 return gbl->fbdev == NULL || gbl->fbdev == info->dev;
56 static const struct backlight_ops gpio_backlight_ops = {
57 .options = BL_CORE_SUSPENDRESUME,
58 .update_status = gpio_backlight_update_status,
59 .get_brightness = gpio_backlight_get_brightness,
60 .check_fb = gpio_backlight_check_fb,
63 static int gpio_backlight_probe(struct platform_device *pdev)
65 struct gpio_backlight_platform_data *pdata = pdev->dev.platform_data;
66 struct backlight_properties props;
67 struct backlight_device *bl;
68 struct gpio_backlight *gbl;
69 int ret;
71 if (!pdata) {
72 dev_err(&pdev->dev, "failed to find platform data\n");
73 return -ENODEV;
76 gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
77 if (gbl == NULL)
78 return -ENOMEM;
80 gbl->dev = &pdev->dev;
81 gbl->fbdev = pdata->fbdev;
82 gbl->gpio = pdata->gpio;
83 gbl->active = pdata->active_low ? 0 : 1;
85 ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT |
86 (gbl->active ? GPIOF_INIT_LOW
87 : GPIOF_INIT_HIGH),
88 pdata->name);
89 if (ret < 0) {
90 dev_err(&pdev->dev, "unable to request GPIO\n");
91 return ret;
94 memset(&props, 0, sizeof(props));
95 props.type = BACKLIGHT_RAW;
96 props.max_brightness = 1;
97 bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, gbl,
98 &gpio_backlight_ops, &props);
99 if (IS_ERR(bl)) {
100 dev_err(&pdev->dev, "failed to register backlight\n");
101 return PTR_ERR(bl);
104 bl->props.brightness = pdata->def_value;
105 backlight_update_status(bl);
107 platform_set_drvdata(pdev, bl);
108 return 0;
111 static int gpio_backlight_remove(struct platform_device *pdev)
113 struct backlight_device *bl = platform_get_drvdata(pdev);
115 backlight_device_unregister(bl);
116 return 0;
119 static struct platform_driver gpio_backlight_driver = {
120 .driver = {
121 .name = "gpio-backlight",
122 .owner = THIS_MODULE,
124 .probe = gpio_backlight_probe,
125 .remove = gpio_backlight_remove,
128 module_platform_driver(gpio_backlight_driver);
130 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
131 MODULE_DESCRIPTION("GPIO-based Backlight Driver");
132 MODULE_LICENSE("GPL");
133 MODULE_ALIAS("platform:gpio-backlight");