From b65bd1539feaec73ccca49dced755a14c554c5b8 Mon Sep 17 00:00:00 2001 From: Dan Murphy Date: Tue, 18 May 2010 13:20:22 -0500 Subject: [PATCH] leds: Simple GPIO driver to control the AUO backlight This is a simple driver that controls the AUO backlight and registers to the LED class driver. This code is not long term code. Once new displays are available this code can be disabled and removed. Change-Id: I91f4fdfe25060440643597f5419f67a87ef72a96 Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 6 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-auo-panel-backlight.c | 128 +++++++++++++++++++++++ include/linux/leds-auo-panel-backlight.h | 40 +++++++ 4 files changed, 175 insertions(+) create mode 100755 drivers/leds/leds-auo-panel-backlight.c create mode 100755 include/linux/leds-auo-panel-backlight.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 3845131ee555..8e37852364f8 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -138,6 +138,12 @@ config LEDS_PCA9532 LED controller. It is generally only useful as a platform driver +config LEDS_AUO_PANEL + tristate "Support for AUO display backlight driver" + depends on LEDS_CLASS + help + This option enables support for AUO display backlight driver + config LEDS_GPIO tristate "LED Support for GPIO connected LEDs" depends on GENERIC_GPIO diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 5fe6885c77a3..19b63453d0d7 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o obj-$(CONFIG_LEDS_NS2) += leds-ns2.o +obj-$(CONFIG_LEDS_AUO_PANEL) += leds-auo-panel-backlight.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-auo-panel-backlight.c b/drivers/leds/leds-auo-panel-backlight.c new file mode 100755 index 000000000000..e95131a7c71a --- /dev/null +++ b/drivers/leds/leds-auo-panel-backlight.c @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2010 Motorola, Inc. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +struct auo_panel_data { + struct led_classdev led_dev; + struct auo_panel_bl_platform_data *auo_pdata; + struct mutex lock; + int led_on; +}; + +static uint32_t auo_panel_debug; +module_param_named(auo_bl_debug, auo_panel_debug, uint, 0664); + +static void ld_auo_panel_brightness_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct auo_panel_data *auo_data = + container_of(led_cdev, struct auo_panel_data, led_dev); + + mutex_lock(&auo_data->lock); + if (value == LED_OFF) { + if (auo_data->led_on == 1) { + if (auo_data->auo_pdata->bl_disable) { + auo_data->auo_pdata->bl_disable(); + auo_data->led_on = 0; + } + } + } else { + if (auo_data->led_on == 0) { + if (auo_data->auo_pdata->bl_enable) { + auo_data->auo_pdata->bl_enable(); + auo_data->led_on = 1; + } + } + } + mutex_unlock(&auo_data->lock); +} + +static int __devinit ld_auo_panel_bl_probe(struct platform_device *pdev) +{ + struct auo_panel_data *auo_data; + int error = 0; + + if (pdev->dev.platform_data == NULL) { + pr_err("%s: platform data required\n", __func__); + return -ENODEV; + } + auo_data = kzalloc(sizeof(struct auo_panel_data), GFP_KERNEL); + if (auo_data == NULL) + return -ENOMEM; + + auo_data->led_dev.name = LD_AUO_PANEL_BL_LED_DEV; + auo_data->led_dev.brightness_set = ld_auo_panel_brightness_set; + + auo_data->auo_pdata = pdev->dev.platform_data; + + error = led_classdev_register(&pdev->dev, &auo_data->led_dev); + if (error < 0) { + pr_err("%s: Register led class failed: %d\n", __func__, error); + error = -ENODEV; + kfree(auo_data); + return error; + } + mutex_init(&auo_data->lock); + + mutex_lock(&auo_data->lock); + auo_data->led_on = 1; + mutex_unlock(&auo_data->lock); + + platform_set_drvdata(pdev, auo_data); + + return 0; +} + +static int __devexit ld_auo_panel_remove(struct platform_device *pdev) +{ + struct auo_panel_data *auo_data = pdev->dev.platform_data; + led_classdev_unregister(&auo_data->led_dev); + kfree(auo_data); + return 0; +} + +static struct platform_driver auo_led_driver = { + .probe = ld_auo_panel_bl_probe, + .remove = __devexit_p(ld_auo_panel_remove), + .driver = { + .name = LD_AUO_PANEL_BL_NAME, + .owner = THIS_MODULE, + }, +}; +static int __init ld_auo_panel_init(void) +{ + return platform_driver_register(&auo_led_driver); +} + +static void __exit ld_auo_panel_exit(void) +{ + platform_driver_unregister(&auo_led_driver); + +} + +module_init(ld_auo_panel_init); +module_exit(ld_auo_panel_exit); + +MODULE_DESCRIPTION("Lighting driver for the AUO display panel"); +MODULE_AUTHOR("Dan Murphy "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/leds-auo-panel-backlight.h b/include/linux/leds-auo-panel-backlight.h new file mode 100755 index 000000000000..8d053a10c594 --- /dev/null +++ b/include/linux/leds-auo-panel-backlight.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 Motorola, Inc. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307, USA + */ + +#ifndef _LINUX_LED_LD_AUO_PANEL_BL_H__ +#define _LINUX_LED_LD_AUO_PANEL_BL_H__ + +#define MANUAL 0 +#define AUTOMATIC 1 +#define MANUAL_SENSOR 2 + + +#define LD_AUO_PANEL_BL_LED_DEV "lcd-backlight" + +#define LD_AUO_PANEL_BL_NAME "auo_panel_bl_led" + +#ifdef __KERNEL__ +struct auo_panel_bl_platform_data { + void (*bl_enable) (void); + void (*bl_disable) (void); + void (*pwm_enable) (void); + void (*pwm_disable) (void); +}; + +#endif /* __KERNEL__ */ +#endif /* _LINUX_LED_LD_AUO_PANEL_BL_H__ */ -- 2.34.1