leds: lp8550 driver update.
[firefly-linux-kernel-4.4.55.git] / drivers / leds / leds-auo-panel-backlight.c
1 /*
2  * Copyright (C) 2010 Motorola, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
16  * 02111-1307, USA
17  */
18
19 #include <linux/leds.h>
20 #include <linux/leds-auo-panel-backlight.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23 #include <linux/types.h>
24
25 struct auo_panel_data {
26         struct led_classdev led_dev;
27         struct auo_panel_bl_platform_data *auo_pdata;
28         struct mutex lock;
29         int led_on;
30 };
31
32 static uint32_t auo_panel_debug;
33 module_param_named(auo_bl_debug, auo_panel_debug, uint, 0664);
34
35 static void ld_auo_panel_brightness_set(struct led_classdev *led_cdev,
36                                      enum led_brightness value)
37 {
38         struct auo_panel_data *auo_data =
39             container_of(led_cdev, struct auo_panel_data, led_dev);
40
41         mutex_lock(&auo_data->lock);
42         if (value == LED_OFF) {
43                 if (auo_data->led_on == 1) {
44                         if (auo_data->auo_pdata->bl_disable) {
45                                 auo_data->auo_pdata->bl_disable();
46                                 auo_data->led_on = 0;
47                         }
48                 }
49         } else {
50                 if (auo_data->led_on == 0) {
51                         if (auo_data->auo_pdata->bl_enable) {
52                                 auo_data->auo_pdata->bl_enable();
53                                 auo_data->led_on = 1;
54                         }
55                 }
56         }
57         mutex_unlock(&auo_data->lock);
58 }
59
60 static int __devinit ld_auo_panel_bl_probe(struct platform_device *pdev)
61 {
62         struct auo_panel_data *auo_data;
63         int error = 0;
64
65         if (pdev->dev.platform_data == NULL) {
66                 pr_err("%s: platform data required\n", __func__);
67                 return -ENODEV;
68         }
69         auo_data = kzalloc(sizeof(struct auo_panel_data), GFP_KERNEL);
70         if (auo_data == NULL)
71                 return -ENOMEM;
72
73         auo_data->led_dev.name = LD_AUO_PANEL_BL_LED_DEV;
74         auo_data->led_dev.brightness_set = ld_auo_panel_brightness_set;
75
76         auo_data->auo_pdata = pdev->dev.platform_data;
77
78         error = led_classdev_register(&pdev->dev, &auo_data->led_dev);
79         if (error < 0) {
80                 pr_err("%s: Register led class failed: %d\n", __func__, error);
81                 error = -ENODEV;
82                 kfree(auo_data);
83                 return error;
84         }
85         mutex_init(&auo_data->lock);
86
87         mutex_lock(&auo_data->lock);
88         auo_data->led_on = 1;
89         mutex_unlock(&auo_data->lock);
90
91         platform_set_drvdata(pdev, auo_data);
92
93         return 0;
94 }
95
96 static int __devexit ld_auo_panel_remove(struct platform_device *pdev)
97 {
98         struct auo_panel_data *auo_data = pdev->dev.platform_data;
99         led_classdev_unregister(&auo_data->led_dev);
100         kfree(auo_data);
101         return 0;
102 }
103
104 static struct platform_driver auo_led_driver = {
105         .probe          = ld_auo_panel_bl_probe,
106         .remove         = __devexit_p(ld_auo_panel_remove),
107         .driver         = {
108                 .name   = LD_AUO_PANEL_BL_NAME,
109                 .owner  = THIS_MODULE,
110         },
111 };
112 static int __init ld_auo_panel_init(void)
113 {
114         return platform_driver_register(&auo_led_driver);
115 }
116
117 static void __exit ld_auo_panel_exit(void)
118 {
119         platform_driver_unregister(&auo_led_driver);
120
121 }
122
123 module_init(ld_auo_panel_init);
124 module_exit(ld_auo_panel_exit);
125
126 MODULE_DESCRIPTION("Lighting driver for the AUO display panel");
127 MODULE_AUTHOR("Dan Murphy <wldm10@Motorola.com>");
128 MODULE_LICENSE("GPL");