2 * LEDs driver for Dialog Semiconductor DA9030/DA9034
4 * Copyright (C) 2008 Compulab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
7 * Copyright (C) 2006-2008 Marvell International Ltd.
8 * Eric Miao <eric.miao@marvell.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/leds.h>
20 #include <linux/workqueue.h>
21 #include <linux/mfd/da903x.h>
22 #include <linux/slab.h>
24 #define DA9030_LED1_CONTROL 0x20
25 #define DA9030_LED2_CONTROL 0x21
26 #define DA9030_LED3_CONTROL 0x22
27 #define DA9030_LED4_CONTROL 0x23
28 #define DA9030_LEDPC_CONTROL 0x24
29 #define DA9030_MISC_CONTROL_A 0x26 /* Vibrator Control */
31 #define DA9034_LED1_CONTROL 0x35
32 #define DA9034_LED2_CONTROL 0x36
33 #define DA9034_VIBRA 0x40
36 struct led_classdev cdev
;
37 struct work_struct work
;
38 struct device
*master
;
39 enum led_brightness new_brightness
;
44 #define DA9030_LED_OFFSET(id) ((id) - DA9030_ID_LED_1)
45 #define DA9034_LED_OFFSET(id) ((id) - DA9034_ID_LED_1)
47 static void da903x_led_work(struct work_struct
*work
)
49 struct da903x_led
*led
= container_of(work
, struct da903x_led
, work
);
58 case DA9030_ID_LED_PC
:
59 offset
= DA9030_LED_OFFSET(led
->id
);
60 val
= led
->flags
& ~0x87;
61 val
|= (led
->new_brightness
) ? 0x80 : 0; /* EN bit */
62 val
|= (0x7 - (led
->new_brightness
>> 5)) & 0x7; /* PWM<2:0> */
63 da903x_write(led
->master
, DA9030_LED1_CONTROL
+ offset
, val
);
66 val
= led
->flags
& ~0x80;
67 val
|= (led
->new_brightness
) ? 0x80 : 0; /* EN bit */
68 da903x_write(led
->master
, DA9030_MISC_CONTROL_A
, val
);
72 offset
= DA9034_LED_OFFSET(led
->id
);
73 val
= (led
->new_brightness
* 0x5f / LED_FULL
) & 0x7f;
74 val
|= (led
->flags
& DA9034_LED_RAMP
) ? 0x80 : 0;
75 da903x_write(led
->master
, DA9034_LED1_CONTROL
+ offset
, val
);
78 val
= led
->new_brightness
& 0xfe;
79 da903x_write(led
->master
, DA9034_VIBRA
, val
);
84 static void da903x_led_set(struct led_classdev
*led_cdev
,
85 enum led_brightness value
)
87 struct da903x_led
*led
;
89 led
= container_of(led_cdev
, struct da903x_led
, cdev
);
90 led
->new_brightness
= value
;
91 schedule_work(&led
->work
);
94 static int __devinit
da903x_led_probe(struct platform_device
*pdev
)
96 struct led_info
*pdata
= pdev
->dev
.platform_data
;
97 struct da903x_led
*led
;
105 if (!((id
>= DA9030_ID_LED_1
&& id
<= DA9030_ID_VIBRA
) ||
106 (id
>= DA9034_ID_LED_1
&& id
<= DA9034_ID_VIBRA
))) {
107 dev_err(&pdev
->dev
, "invalid LED ID (%d) specified\n", id
);
111 led
= kzalloc(sizeof(struct da903x_led
), GFP_KERNEL
);
113 dev_err(&pdev
->dev
, "failed to alloc memory for LED%d\n", id
);
117 led
->cdev
.name
= pdata
->name
;
118 led
->cdev
.default_trigger
= pdata
->default_trigger
;
119 led
->cdev
.brightness_set
= da903x_led_set
;
120 led
->cdev
.brightness
= LED_OFF
;
123 led
->flags
= pdata
->flags
;
124 led
->master
= pdev
->dev
.parent
;
125 led
->new_brightness
= LED_OFF
;
127 INIT_WORK(&led
->work
, da903x_led_work
);
129 ret
= led_classdev_register(led
->master
, &led
->cdev
);
131 dev_err(&pdev
->dev
, "failed to register LED %d\n", id
);
135 platform_set_drvdata(pdev
, led
);
143 static int __devexit
da903x_led_remove(struct platform_device
*pdev
)
145 struct da903x_led
*led
= platform_get_drvdata(pdev
);
147 led_classdev_unregister(&led
->cdev
);
152 static struct platform_driver da903x_led_driver
= {
154 .name
= "da903x-led",
155 .owner
= THIS_MODULE
,
157 .probe
= da903x_led_probe
,
158 .remove
= __devexit_p(da903x_led_remove
),
161 module_platform_driver(da903x_led_driver
);
163 MODULE_DESCRIPTION("LEDs driver for Dialog Semiconductor DA9030/DA9034");
164 MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
165 "Mike Rapoport <mike@compulab.co.il>");
166 MODULE_LICENSE("GPL");
167 MODULE_ALIAS("platform:da903x-led");