Add GPIO backlight driver
authorGrazvydas Ignotas <notasas@gmail.com>
Sat, 6 Dec 2008 23:17:38 +0000 (01:17 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 6 Dec 2008 23:24:34 +0000 (01:24 +0200)
drivers/video/backlight/Kconfig
drivers/video/backlight/Makefile
drivers/video/backlight/gpio_bl.c [new file with mode: 0644]

index 452b770..2746bbc 100644 (file)
@@ -156,6 +156,12 @@ config BACKLIGHT_PWM
          If you have a LCD backlight adjustable by PWM, say Y to enable
          this driver.
 
+config BACKLIGHT_GPIO
+       tristate "GPIO based Backlight Driver"
+       depends on BACKLIGHT_CLASS_DEVICE
+       help
+         If you have a GPIO controlled backlight, say Y to enable this driver.
+
 config BACKLIGHT_MBP_NVIDIA
        tristate "MacBook Pro Nvidia Backlight Driver"
        depends on BACKLIGHT_CLASS_DEVICE && X86
index b405aac..d122dbe 100644 (file)
@@ -15,5 +15,6 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o
 obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
 obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
 obj-$(CONFIG_BACKLIGHT_PWM)    += pwm_bl.o
+obj-$(CONFIG_BACKLIGHT_GPIO)   += gpio_bl.o
 obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
 
diff --git a/drivers/video/backlight/gpio_bl.c b/drivers/video/backlight/gpio_bl.c
new file mode 100644 (file)
index 0000000..555d227
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * A driver for GPIO controlled backlights.
+ * Based on pwm_bl.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/fb.h>
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+
+static int gpio_backlight_update_status(struct backlight_device *bl)
+{
+       int gpio = (int)dev_get_drvdata(&bl->dev);
+       int brightness = bl->props.brightness;
+
+       if (bl->props.power != FB_BLANK_UNBLANK)
+               brightness = 0;
+
+       /* ignore fb blank for now
+       if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+               brightness = 0;
+       */
+
+       gpio_set_value(gpio, brightness);
+
+       return 0;
+}
+
+static int gpio_backlight_get_brightness(struct backlight_device *bl)
+{
+       return bl->props.brightness;
+}
+
+static struct backlight_ops gpio_backlight_ops = {
+       .update_status  = gpio_backlight_update_status,
+       .get_brightness = gpio_backlight_get_brightness,
+};
+
+static int gpio_backlight_probe(struct platform_device *pdev)
+{
+       struct backlight_device *bl;
+       int gpio, ret;
+
+       gpio = (int)pdev->dev.platform_data;
+
+       bl = backlight_device_register(pdev->name, &pdev->dev,
+                       (void *)gpio, &gpio_backlight_ops);
+       if (IS_ERR(bl)) {
+               dev_err(&pdev->dev, "failed to register backlight\n");
+               return PTR_ERR(bl);
+       }
+
+       ret = gpio_request(gpio, "backlight");
+       if (ret < 0) {
+               dev_err(&pdev->dev, "Failed to request GPIO %d\n", gpio);
+               goto err_bl;
+       }
+
+       ret = gpio_direction_output(gpio, 1);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "Failed to set GPIO %d direction\n", gpio);
+               goto err_gpio;
+       }
+
+       bl->props.max_brightness = 1;
+       bl->props.brightness = 1;
+       backlight_update_status(bl);
+
+       return 0;
+
+err_gpio:
+       gpio_free(gpio);
+err_bl:
+       backlight_device_unregister(bl);
+       return ret;
+}
+
+static int gpio_backlight_remove(struct platform_device *pdev)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+       int gpio = (int)dev_get_drvdata(&bl->dev);
+
+       gpio_free(gpio);
+       backlight_device_unregister(bl);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int gpio_backlight_suspend(struct platform_device *pdev,
+                                pm_message_t state)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+       int gpio = (int)dev_get_drvdata(&bl->dev);
+
+       gpio_set_value(gpio, 0);
+       return 0;
+}
+
+static int gpio_backlight_resume(struct platform_device *pdev)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+
+       backlight_update_status(bl);
+       return 0;
+}
+#else
+#define gpio_backlight_suspend NULL
+#define gpio_backlight_resume  NULL
+#endif
+
+static struct platform_driver gpio_backlight_driver = {
+       .driver         = {
+               .name   = "gpio-backlight",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = gpio_backlight_probe,
+       .remove         = gpio_backlight_remove,
+       .suspend        = gpio_backlight_suspend,
+       .resume         = gpio_backlight_resume,
+};
+
+static int __init gpio_backlight_init(void)
+{
+       return platform_driver_register(&gpio_backlight_driver);
+}
+module_init(gpio_backlight_init);
+
+static void __exit gpio_backlight_exit(void)
+{
+       platform_driver_unregister(&gpio_backlight_driver);
+}
+module_exit(gpio_backlight_exit);
+
+MODULE_DESCRIPTION("GPIO based Backlight Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:gpio-backlight");
+