blob: 35be94e5f0561d610aabacf887336db1e9d07bca [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 * leds-msm-pmic.c - MSM PMIC LEDs driver.
3 *
Duy Truong790f06d2013-02-13 16:38:12 -08004 * Copyright (c) 2009, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005 *
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
24static 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
34static 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
40static 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
53static 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
61static 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
69static 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
80static 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
91static int __init msm_pmic_led_init(void)
92{
93 return platform_driver_register(&msm_pmic_led_driver);
94}
95module_init(msm_pmic_led_init);
96
97static void __exit msm_pmic_led_exit(void)
98{
99 platform_driver_unregister(&msm_pmic_led_driver);
100}
101module_exit(msm_pmic_led_exit);
102
103MODULE_DESCRIPTION("MSM PMIC LEDs driver");
104MODULE_LICENSE("GPL v2");
105MODULE_ALIAS("platform:pmic-leds");