Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * leds-msm-pmic.c - MSM PMIC LEDs driver. |
| 3 | * |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 4 | * Copyright (c) 2009, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 and |
| 8 | * only version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/leds.h> |
| 19 | |
| 20 | #include <mach/pmic.h> |
| 21 | |
| 22 | #define MAX_KEYPAD_BL_LEVEL 16 |
| 23 | |
| 24 | static void msm_keypad_bl_led_set(struct led_classdev *led_cdev, |
| 25 | enum led_brightness value) |
| 26 | { |
| 27 | int ret; |
| 28 | |
| 29 | ret = pmic_set_led_intensity(LED_KEYPAD, value / MAX_KEYPAD_BL_LEVEL); |
| 30 | if (ret) |
| 31 | dev_err(led_cdev->dev, "can't set keypad backlight\n"); |
| 32 | } |
| 33 | |
| 34 | static struct led_classdev msm_kp_bl_led = { |
| 35 | .name = "keyboard-backlight", |
| 36 | .brightness_set = msm_keypad_bl_led_set, |
| 37 | .brightness = LED_OFF, |
| 38 | }; |
| 39 | |
| 40 | static int msm_pmic_led_probe(struct platform_device *pdev) |
| 41 | { |
| 42 | int rc; |
| 43 | |
| 44 | rc = led_classdev_register(&pdev->dev, &msm_kp_bl_led); |
| 45 | if (rc) { |
| 46 | dev_err(&pdev->dev, "unable to register led class driver\n"); |
| 47 | return rc; |
| 48 | } |
| 49 | msm_keypad_bl_led_set(&msm_kp_bl_led, LED_OFF); |
| 50 | return rc; |
| 51 | } |
| 52 | |
| 53 | static int __devexit msm_pmic_led_remove(struct platform_device *pdev) |
| 54 | { |
| 55 | led_classdev_unregister(&msm_kp_bl_led); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_PM |
| 61 | static int msm_pmic_led_suspend(struct platform_device *dev, |
| 62 | pm_message_t state) |
| 63 | { |
| 64 | led_classdev_suspend(&msm_kp_bl_led); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int msm_pmic_led_resume(struct platform_device *dev) |
| 70 | { |
| 71 | led_classdev_resume(&msm_kp_bl_led); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | #else |
| 76 | #define msm_pmic_led_suspend NULL |
| 77 | #define msm_pmic_led_resume NULL |
| 78 | #endif |
| 79 | |
| 80 | static struct platform_driver msm_pmic_led_driver = { |
| 81 | .probe = msm_pmic_led_probe, |
| 82 | .remove = __devexit_p(msm_pmic_led_remove), |
| 83 | .suspend = msm_pmic_led_suspend, |
| 84 | .resume = msm_pmic_led_resume, |
| 85 | .driver = { |
| 86 | .name = "pmic-leds", |
| 87 | .owner = THIS_MODULE, |
| 88 | }, |
| 89 | }; |
| 90 | |
| 91 | static int __init msm_pmic_led_init(void) |
| 92 | { |
| 93 | return platform_driver_register(&msm_pmic_led_driver); |
| 94 | } |
| 95 | module_init(msm_pmic_led_init); |
| 96 | |
| 97 | static void __exit msm_pmic_led_exit(void) |
| 98 | { |
| 99 | platform_driver_unregister(&msm_pmic_led_driver); |
| 100 | } |
| 101 | module_exit(msm_pmic_led_exit); |
| 102 | |
| 103 | MODULE_DESCRIPTION("MSM PMIC LEDs driver"); |
| 104 | MODULE_LICENSE("GPL v2"); |
| 105 | MODULE_ALIAS("platform:pmic-leds"); |