From e83bba876433ae77247d421d1811474af9810fe0 Mon Sep 17 00:00:00 2001 From: Markinus Date: Sat, 16 Oct 2010 13:25:23 +0200 Subject: [PATCH] htcleo: some cleanups in the keypad led driver --- arch/arm/mach-msm/board-htcleo-keypad.c | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-msm/board-htcleo-keypad.c b/arch/arm/mach-msm/board-htcleo-keypad.c index b28ac502..4ba9b443 100644 --- a/arch/arm/mach-msm/board-htcleo-keypad.c +++ b/arch/arm/mach-msm/board-htcleo-keypad.c @@ -26,8 +26,11 @@ #include "board-htcleo.h" +#define HTCLEO_DEFAULT_KEYPAD_BRIGHTNESS 0 +static int htcleo_keypad_brightness = HTCLEO_DEFAULT_KEYPAD_BRIGHTNESS; +static DEFINE_MUTEX(htcleo_keypad_brightness_lock); + struct led_data { - struct led_classdev ldev; struct mutex led_data_mutex; struct work_struct brightness_work; spinlock_t brightness_lock; @@ -169,21 +172,35 @@ static void keypad_led_brightness_set(struct led_classdev *led_cdev, enum led_brightness brightness) { unsigned long flags; + mutex_lock(&htcleo_keypad_brightness_lock); pr_debug("Setting %s brightness current %d new %d\n", led_cdev->name, led_cdev->brightness, brightness); if (brightness > 255) brightness = 255; - led_cdev->brightness = brightness; + htcleo_keypad_brightness = brightness; spin_lock_irqsave(&keypad_led_data.brightness_lock, flags); keypad_led_data.brightness = brightness; spin_unlock_irqrestore(&keypad_led_data.brightness_lock, flags); schedule_work(&keypad_led_data.brightness_work); + mutex_unlock(&htcleo_keypad_brightness_lock); } +static enum led_brightness keypad_led_brightness_get(struct led_classdev *led_cdev) +{ + return htcleo_keypad_brightness; +} + +static struct led_classdev htcleo_backlight_led = +{ + .name = "button-backlight", + .brightness = HTCLEO_DEFAULT_KEYPAD_BRIGHTNESS, + .brightness_set = keypad_led_brightness_set, + .brightness_get = keypad_led_brightness_get, +}; static int __init htcleo_init_keypad(void) { @@ -214,15 +231,12 @@ static int __init htcleo_init_keypad(void) goto err_gpio_kpl; } - keypad_led_data.ldev.name = "button-backlight"; - keypad_led_data.ldev.brightness_set = keypad_led_brightness_set; keypad_led_data.oldval = 0; mutex_init(&keypad_led_data.led_data_mutex); INIT_WORK(&keypad_led_data.brightness_work, keypad_led_brightness_set_work); spin_lock_init(&keypad_led_data.brightness_lock); - ret = led_classdev_register(&htcleo_input_device.dev, &keypad_led_data.ldev); + ret = led_classdev_register(&htcleo_input_device.dev, &htcleo_backlight_led); if (ret) { - keypad_led_data.ldev.name = NULL; goto exit; }