From 99cb4ecf10de349c8afe15a149b9878aae3cec62 Mon Sep 17 00:00:00 2001 From: lyx Date: Thu, 2 Jun 2011 20:29:37 -0700 Subject: [PATCH] a22: add button light driver --- arch/arm/configs/rk29_a22_defconfig | 1 + arch/arm/mach-rk29/board-rk29-a22.c | 17 +++ arch/arm/mach-rk29/include/mach/board.h | 7 ++ drivers/video/backlight/Kconfig | 10 +- drivers/video/backlight/Makefile | 2 + drivers/video/backlight/rk29_buttonlight.c | 135 +++++++++++++++++++++ 6 files changed, 171 insertions(+), 1 deletion(-) mode change 100644 => 100755 arch/arm/configs/rk29_a22_defconfig create mode 100755 drivers/video/backlight/rk29_buttonlight.c diff --git a/arch/arm/configs/rk29_a22_defconfig b/arch/arm/configs/rk29_a22_defconfig old mode 100644 new mode 100755 index ff32ea6ae43b..f255623f9390 --- a/arch/arm/configs/rk29_a22_defconfig +++ b/arch/arm/configs/rk29_a22_defconfig @@ -1225,6 +1225,7 @@ CONFIG_BACKLIGHT_CLASS_DEVICE=y # CONFIG_BACKLIGHT_RK29_BL is not set # CONFIG_FIH_TOUCHKEY_LED is not set CONFIG_BACKLIGHT_AW9364=y +CONFIG_BUTTON_LIGHT=y # # Display device support diff --git a/arch/arm/mach-rk29/board-rk29-a22.c b/arch/arm/mach-rk29/board-rk29-a22.c index dea8ae984452..ef4c024c3edc 100755 --- a/arch/arm/mach-rk29/board-rk29-a22.c +++ b/arch/arm/mach-rk29/board-rk29-a22.c @@ -1984,6 +1984,20 @@ struct platform_device aw9364_device_backlight = { #endif +#ifdef CONFIG_BUTTON_LIGHT +struct rk29_button_light_info rk29_button_light_info = { + .led_on_pin = RK29_PIN6_PB4, + .led_on_level = GPIO_HIGH, +}; + +struct platform_device rk29_device_button_light = { + .name = "rk29_button_light", + .id = -1, + .dev = { + .platform_data = &rk29_button_light_info, + } +}; +#endif /***************************************************************************************** * pwm voltage regulator devices @@ -2493,6 +2507,9 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_BACKLIGHT_AW9364 &aw9364_device_backlight, #endif +#ifdef CONFIG_BUTTON_LIGHT + &rk29_device_button_light, +#endif #ifdef CONFIG_RK29_VMAC &rk29_device_vmac, #endif diff --git a/arch/arm/mach-rk29/include/mach/board.h b/arch/arm/mach-rk29/include/mach/board.h index b9e59e90ee59..3a0e7c23e0a9 100755 --- a/arch/arm/mach-rk29/include/mach/board.h +++ b/arch/arm/mach-rk29/include/mach/board.h @@ -22,6 +22,13 @@ #include #include +struct rk29_button_light_info{ + u32 led_on_pin; + u32 led_on_level; + int (*io_init)(void); + int (*io_deinit)(void); +}; + /*spi*/ struct spi_cs_gpio { const char *name; diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 07f29590de62..8ecc980c7faa 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -286,4 +286,12 @@ config BACKLIGHT_AW9364 bool "aw9364 backlight driver" depends on BACKLIGHT_CLASS_DEVICE && ARCH_RK29 help - aw9364 backlight support. + aw9364 backlight support. + +config BUTTON_LIGHT + bool "rk29 button light driver" + depends on BACKLIGHT_CLASS_DEVICE + default n + help + rk29 button light support. + diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index d38ca546f89d..54235006d719 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -32,3 +32,5 @@ obj-$(CONFIG_BACKLIGHT_RK2818_BL) += rk2818_backlight.o obj-$(CONFIG_BACKLIGHT_RK29_BL) += rk29_backlight.o obj-$(CONFIG_BACKLIGHT_AW9364) += aw9364_bl.o obj-$(CONFIG_FIH_TOUCHKEY_LED) += fih_touchkey_led.o +obj-$(CONFIG_BUTTON_LIGHT) += rk29_buttonlight.o + diff --git a/drivers/video/backlight/rk29_buttonlight.c b/drivers/video/backlight/rk29_buttonlight.c new file mode 100755 index 000000000000..bb72a6643411 --- /dev/null +++ b/drivers/video/backlight/rk29_buttonlight.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2009 Rockchip Corporation. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +/* + * Debug + */ +#if 0 +#define DBG(x...) printk(x) +#else +#define DBG(x...) +#endif + +static int rk29_button_light_value = 0; +struct backlight_device * rk29_button_light_device; + +static s32 rk29_set_button_light(struct backlight_device *bl) +{ + struct rk29_button_light_info *button_light_info = bl->dev.parent->platform_data; + + DBG(">>>>>>> rk29_set_button_light\n"); + if(bl->props.brightness) + { + gpio_set_value(button_light_info->led_on_pin, button_light_info->led_on_level); + rk29_button_light_value = 255; + } + else + { + gpio_set_value(button_light_info->led_on_pin, button_light_info->led_on_level?0:1); + rk29_button_light_value = 0; + } + return 0; +} + +static s32 rk29_get_button_light(struct backlight_device *bl) +{ + DBG(">>>>>>> rk29_get_button_light\n"); + return rk29_button_light_value; +} + +static struct backlight_ops rk29_button_light_ops = { + .update_status = rk29_set_button_light, + .get_brightness = rk29_get_button_light, +}; + +static int rk29_button_light_probe(struct platform_device *pdev) +{ + struct rk29_button_light_info *button_light_info = pdev->dev.platform_data; + + rk29_button_light_device = backlight_device_register("rk29_button_light", &pdev->dev, NULL, &rk29_button_light_ops); + if (!rk29_button_light_device) { + DBG("rk29_button_light_probe error\n"); + return -ENODEV; + } + + rk29_button_light_device->props.power = FB_BLANK_UNBLANK; + rk29_button_light_device->props.fb_blank = FB_BLANK_UNBLANK; + rk29_button_light_device->props.max_brightness = 255; + rk29_button_light_device->props.brightness = 255; + + gpio_request(button_light_info->led_on_pin, NULL); + gpio_direction_output(button_light_info->led_on_pin, button_light_info->led_on_level?0:1); + + if (button_light_info && button_light_info->io_init) + button_light_info->io_init(); + + return 0; +} + +static int rk29_button_light_remove(struct platform_device *pdev) +{ + + if (rk29_button_light_device) { + backlight_device_unregister(rk29_button_light_device); + return 0; + } else { + DBG("rk29_button_light_remove error\n"); + return -ENODEV; + } +} + +static struct platform_driver rk29_button_light_driver = { + .probe = rk29_button_light_probe, + .remove = rk29_button_light_remove, + .driver = { + .name = "rk29_button_light", + .owner = THIS_MODULE, + }, +}; + + +static int __init rk29_button_light_init(void) +{ + platform_driver_register(&rk29_button_light_driver); + return 0; +} + +static int __init rk29_button_light_exit(void) +{ + platform_driver_unregister(&rk29_button_light_driver); + return 0; +} + +late_initcall(rk29_button_light_init); +module_exit(rk29_button_light_exit); + -- 2.34.1