1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Backlight Driver for Dialog DA9052 PMICs
5 * Copyright(c) 2012 Dialog Semiconductor Ltd.
7 * Author: David Dajun Chen <dchen@diasemi.com>
10 #include <linux/backlight.h>
11 #include <linux/delay.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <linux/mfd/da9052/da9052.h>
17 #include <linux/mfd/da9052/reg.h>
19 #define DA9052_MAX_BRIGHTNESS 0xFF
32 static const unsigned char wled_bank
[] = {
39 struct da9052
*da9052
;
45 static int da9052_adjust_wled_brightness(struct da9052_bl
*wleds
)
47 unsigned char boost_en
;
53 if (wleds
->state
== DA9052_WLEDS_OFF
) {
58 ret
= da9052_reg_write(wleds
->da9052
, DA9052_BOOST_REG
, boost_en
);
62 ret
= da9052_reg_write(wleds
->da9052
, DA9052_LED_CONT_REG
, i_sink
);
66 ret
= da9052_reg_write(wleds
->da9052
, wled_bank
[wleds
->led_reg
], 0x0);
70 usleep_range(10000, 11000);
72 if (wleds
->brightness
) {
73 ret
= da9052_reg_write(wleds
->da9052
, wled_bank
[wleds
->led_reg
],
82 static int da9052_backlight_update_status(struct backlight_device
*bl
)
84 int brightness
= bl
->props
.brightness
;
85 struct da9052_bl
*wleds
= bl_get_data(bl
);
87 wleds
->brightness
= brightness
;
88 wleds
->state
= DA9052_WLEDS_ON
;
90 return da9052_adjust_wled_brightness(wleds
);
93 static int da9052_backlight_get_brightness(struct backlight_device
*bl
)
95 struct da9052_bl
*wleds
= bl_get_data(bl
);
97 return wleds
->brightness
;
100 static const struct backlight_ops da9052_backlight_ops
= {
101 .update_status
= da9052_backlight_update_status
,
102 .get_brightness
= da9052_backlight_get_brightness
,
105 static int da9052_backlight_probe(struct platform_device
*pdev
)
107 struct backlight_device
*bl
;
108 struct backlight_properties props
;
109 struct da9052_bl
*wleds
;
111 wleds
= devm_kzalloc(&pdev
->dev
, sizeof(struct da9052_bl
), GFP_KERNEL
);
115 wleds
->da9052
= dev_get_drvdata(pdev
->dev
.parent
);
116 wleds
->brightness
= 0;
117 wleds
->led_reg
= platform_get_device_id(pdev
)->driver_data
;
118 wleds
->state
= DA9052_WLEDS_OFF
;
120 props
.type
= BACKLIGHT_RAW
;
121 props
.max_brightness
= DA9052_MAX_BRIGHTNESS
;
123 bl
= devm_backlight_device_register(&pdev
->dev
, pdev
->name
,
124 wleds
->da9052
->dev
, wleds
,
125 &da9052_backlight_ops
, &props
);
127 dev_err(&pdev
->dev
, "Failed to register backlight\n");
131 bl
->props
.max_brightness
= DA9052_MAX_BRIGHTNESS
;
132 bl
->props
.brightness
= 0;
133 platform_set_drvdata(pdev
, bl
);
135 return da9052_adjust_wled_brightness(wleds
);
138 static int da9052_backlight_remove(struct platform_device
*pdev
)
140 struct backlight_device
*bl
= platform_get_drvdata(pdev
);
141 struct da9052_bl
*wleds
= bl_get_data(bl
);
143 wleds
->brightness
= 0;
144 wleds
->state
= DA9052_WLEDS_OFF
;
145 da9052_adjust_wled_brightness(wleds
);
150 static const struct platform_device_id da9052_wled_ids
[] = {
152 .name
= "da9052-wled1",
153 .driver_data
= DA9052_TYPE_WLED1
,
156 .name
= "da9052-wled2",
157 .driver_data
= DA9052_TYPE_WLED2
,
160 .name
= "da9052-wled3",
161 .driver_data
= DA9052_TYPE_WLED3
,
165 MODULE_DEVICE_TABLE(platform
, da9052_wled_ids
);
167 static struct platform_driver da9052_wled_driver
= {
168 .probe
= da9052_backlight_probe
,
169 .remove
= da9052_backlight_remove
,
170 .id_table
= da9052_wled_ids
,
172 .name
= "da9052-wled",
176 module_platform_driver(da9052_wled_driver
);
178 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
179 MODULE_DESCRIPTION("Backlight driver for DA9052 PMIC");
180 MODULE_LICENSE("GPL");