2 * Backlight Driver for Dialog DA9052 PMICs
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
6 * Author: David Dajun Chen <dchen@diasemi.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
15 #include <linux/backlight.h>
16 #include <linux/delay.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
21 #include <linux/mfd/da9052/da9052.h>
22 #include <linux/mfd/da9052/reg.h>
24 #define DA9052_MAX_BRIGHTNESS 0xFF
37 static const unsigned char wled_bank
[] = {
44 struct da9052
*da9052
;
50 static int da9052_adjust_wled_brightness(struct da9052_bl
*wleds
)
52 unsigned char boost_en
;
58 if (wleds
->state
== DA9052_WLEDS_OFF
) {
63 ret
= da9052_reg_write(wleds
->da9052
, DA9052_BOOST_REG
, boost_en
);
67 ret
= da9052_reg_write(wleds
->da9052
, DA9052_LED_CONT_REG
, i_sink
);
71 ret
= da9052_reg_write(wleds
->da9052
, wled_bank
[wleds
->led_reg
], 0x0);
75 usleep_range(10000, 11000);
77 if (wleds
->brightness
) {
78 ret
= da9052_reg_write(wleds
->da9052
, wled_bank
[wleds
->led_reg
],
87 static int da9052_backlight_update_status(struct backlight_device
*bl
)
89 int brightness
= bl
->props
.brightness
;
90 struct da9052_bl
*wleds
= bl_get_data(bl
);
92 wleds
->brightness
= brightness
;
93 wleds
->state
= DA9052_WLEDS_ON
;
95 return da9052_adjust_wled_brightness(wleds
);
98 static int da9052_backlight_get_brightness(struct backlight_device
*bl
)
100 struct da9052_bl
*wleds
= bl_get_data(bl
);
102 return wleds
->brightness
;
105 static const struct backlight_ops da9052_backlight_ops
= {
106 .update_status
= da9052_backlight_update_status
,
107 .get_brightness
= da9052_backlight_get_brightness
,
110 static int da9052_backlight_probe(struct platform_device
*pdev
)
112 struct backlight_device
*bl
;
113 struct backlight_properties props
;
114 struct da9052_bl
*wleds
;
116 wleds
= devm_kzalloc(&pdev
->dev
, sizeof(struct da9052_bl
), GFP_KERNEL
);
120 wleds
->da9052
= dev_get_drvdata(pdev
->dev
.parent
);
121 wleds
->brightness
= 0;
122 wleds
->led_reg
= platform_get_device_id(pdev
)->driver_data
;
123 wleds
->state
= DA9052_WLEDS_OFF
;
125 props
.type
= BACKLIGHT_RAW
;
126 props
.max_brightness
= DA9052_MAX_BRIGHTNESS
;
128 bl
= devm_backlight_device_register(&pdev
->dev
, pdev
->name
,
129 wleds
->da9052
->dev
, wleds
,
130 &da9052_backlight_ops
, &props
);
132 dev_err(&pdev
->dev
, "Failed to register backlight\n");
136 bl
->props
.max_brightness
= DA9052_MAX_BRIGHTNESS
;
137 bl
->props
.brightness
= 0;
138 platform_set_drvdata(pdev
, bl
);
140 return da9052_adjust_wled_brightness(wleds
);
143 static int da9052_backlight_remove(struct platform_device
*pdev
)
145 struct backlight_device
*bl
= platform_get_drvdata(pdev
);
146 struct da9052_bl
*wleds
= bl_get_data(bl
);
148 wleds
->brightness
= 0;
149 wleds
->state
= DA9052_WLEDS_OFF
;
150 da9052_adjust_wled_brightness(wleds
);
155 static struct platform_device_id da9052_wled_ids
[] = {
157 .name
= "da9052-wled1",
158 .driver_data
= DA9052_TYPE_WLED1
,
161 .name
= "da9052-wled2",
162 .driver_data
= DA9052_TYPE_WLED2
,
165 .name
= "da9052-wled3",
166 .driver_data
= DA9052_TYPE_WLED3
,
170 static struct platform_driver da9052_wled_driver
= {
171 .probe
= da9052_backlight_probe
,
172 .remove
= da9052_backlight_remove
,
173 .id_table
= da9052_wled_ids
,
175 .name
= "da9052-wled",
179 module_platform_driver(da9052_wled_driver
);
181 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
182 MODULE_DESCRIPTION("Backlight driver for DA9052 PMIC");
183 MODULE_LICENSE("GPL");
184 MODULE_ALIAS("platform:da9052-backlight");