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/platform_device.h>
18 #include <linux/leds.h>
19 #include <linux/mfd/da903x.h>
20 #include <linux/slab.h>
22 #define DA9030_LED1_CONTROL 0x20
23 #define DA9030_LED2_CONTROL 0x21
24 #define DA9030_LED3_CONTROL 0x22
25 #define DA9030_LED4_CONTROL 0x23
26 #define DA9030_LEDPC_CONTROL 0x24
27 #define DA9030_MISC_CONTROL_A 0x26 /* Vibrator Control */
29 #define DA9034_LED1_CONTROL 0x35
30 #define DA9034_LED2_CONTROL 0x36
31 #define DA9034_VIBRA 0x40
34 struct led_classdev cdev;
35 struct device *master;
40 #define DA9030_LED_OFFSET(id) ((id) - DA9030_ID_LED_1)
41 #define DA9034_LED_OFFSET(id) ((id) - DA9034_ID_LED_1)
43 static int da903x_led_set(struct led_classdev *led_cdev,
44 enum led_brightness value)
46 struct da903x_led *led =
47 container_of(led_cdev, struct da903x_led, cdev);
49 int offset, ret = -EINVAL;
56 case DA9030_ID_LED_PC:
57 offset = DA9030_LED_OFFSET(led->id);
58 val = led->flags & ~0x87;
59 val |= value ? 0x80 : 0; /* EN bit */
60 val |= (0x7 - (value >> 5)) & 0x7; /* PWM<2:0> */
61 ret = da903x_write(led->master, DA9030_LED1_CONTROL + offset,
65 val = led->flags & ~0x80;
66 val |= value ? 0x80 : 0; /* EN bit */
67 ret = da903x_write(led->master, DA9030_MISC_CONTROL_A, val);
71 offset = DA9034_LED_OFFSET(led->id);
72 val = (value * 0x5f / LED_FULL) & 0x7f;
73 val |= (led->flags & DA9034_LED_RAMP) ? 0x80 : 0;
74 ret = da903x_write(led->master, DA9034_LED1_CONTROL + offset,
79 ret = da903x_write(led->master, DA9034_VIBRA, val);
86 static int da903x_led_probe(struct platform_device *pdev)
88 struct led_info *pdata = dev_get_platdata(&pdev->dev);
89 struct da903x_led *led;
97 if (!((id >= DA9030_ID_LED_1 && id <= DA9030_ID_VIBRA) ||
98 (id >= DA9034_ID_LED_1 && id <= DA9034_ID_VIBRA))) {
99 dev_err(&pdev->dev, "invalid LED ID (%d) specified\n", id);
103 led = devm_kzalloc(&pdev->dev, sizeof(struct da903x_led), GFP_KERNEL);
107 led->cdev.name = pdata->name;
108 led->cdev.default_trigger = pdata->default_trigger;
109 led->cdev.brightness_set_blocking = da903x_led_set;
110 led->cdev.brightness = LED_OFF;
113 led->flags = pdata->flags;
114 led->master = pdev->dev.parent;
116 ret = devm_led_classdev_register(led->master, &led->cdev);
118 dev_err(&pdev->dev, "failed to register LED %d\n", id);
125 static struct platform_driver da903x_led_driver = {
127 .name = "da903x-led",
129 .probe = da903x_led_probe,
132 module_platform_driver(da903x_led_driver);
134 MODULE_DESCRIPTION("LEDs driver for Dialog Semiconductor DA9030/DA9034");
135 MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
136 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
137 MODULE_LICENSE("GPL");
138 MODULE_ALIAS("platform:da903x-led");