1 // SPDX-License-Identifier: GPL-2.0-only
3 * Backlight driver for Dialog Semiconductor DA9030/DA9034
5 * Copyright (C) 2008 Compulab, Ltd.
6 * Mike Rapoport <mike@compulab.co.il>
8 * Copyright (C) 2006-2008 Marvell International Ltd.
9 * Eric Miao <eric.miao@marvell.com>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
16 #include <linux/backlight.h>
17 #include <linux/mfd/da903x.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
21 #define DA9030_WLED_CONTROL 0x25
22 #define DA9030_WLED_CP_EN (1 << 6)
23 #define DA9030_WLED_TRIM(x) ((x) & 0x7)
25 #define DA9034_WLED_CONTROL1 0x3C
26 #define DA9034_WLED_CONTROL2 0x3D
27 #define DA9034_WLED_ISET(x) ((x) & 0x1f)
29 #define DA9034_WLED_BOOST_EN (1 << 5)
31 #define DA9030_MAX_BRIGHTNESS 7
32 #define DA9034_MAX_BRIGHTNESS 0x7f
34 struct da903x_backlight_data
{
35 struct device
*da903x_dev
;
37 int current_brightness
;
40 static int da903x_backlight_set(struct backlight_device
*bl
, int brightness
)
42 struct da903x_backlight_data
*data
= bl_get_data(bl
);
43 struct device
*dev
= data
->da903x_dev
;
49 ret
= da903x_update(dev
, DA9034_WLED_CONTROL1
,
54 if (data
->current_brightness
&& brightness
== 0)
55 ret
= da903x_clr_bits(dev
,
57 DA9034_WLED_BOOST_EN
);
59 if (data
->current_brightness
== 0 && brightness
)
60 ret
= da903x_set_bits(dev
,
62 DA9034_WLED_BOOST_EN
);
65 val
= DA9030_WLED_TRIM(brightness
);
66 val
|= brightness
? DA9030_WLED_CP_EN
: 0;
67 ret
= da903x_write(dev
, DA9030_WLED_CONTROL
, val
);
74 data
->current_brightness
= brightness
;
78 static int da903x_backlight_update_status(struct backlight_device
*bl
)
80 return da903x_backlight_set(bl
, backlight_get_brightness(bl
));
83 static int da903x_backlight_get_brightness(struct backlight_device
*bl
)
85 struct da903x_backlight_data
*data
= bl_get_data(bl
);
87 return data
->current_brightness
;
90 static const struct backlight_ops da903x_backlight_ops
= {
91 .options
= BL_CORE_SUSPENDRESUME
,
92 .update_status
= da903x_backlight_update_status
,
93 .get_brightness
= da903x_backlight_get_brightness
,
96 static int da903x_backlight_probe(struct platform_device
*pdev
)
98 struct da9034_backlight_pdata
*pdata
= dev_get_platdata(&pdev
->dev
);
99 struct da903x_backlight_data
*data
;
100 struct backlight_device
*bl
;
101 struct backlight_properties props
;
104 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
110 max_brightness
= DA9030_MAX_BRIGHTNESS
;
113 max_brightness
= DA9034_MAX_BRIGHTNESS
;
116 dev_err(&pdev
->dev
, "invalid backlight device ID(%d)\n",
122 data
->da903x_dev
= pdev
->dev
.parent
;
123 data
->current_brightness
= 0;
125 /* adjust the WLED output current */
127 da903x_write(data
->da903x_dev
, DA9034_WLED_CONTROL2
,
128 DA9034_WLED_ISET(pdata
->output_current
));
130 memset(&props
, 0, sizeof(props
));
131 props
.type
= BACKLIGHT_RAW
;
132 props
.max_brightness
= max_brightness
;
133 bl
= devm_backlight_device_register(&pdev
->dev
, pdev
->name
,
134 data
->da903x_dev
, data
,
135 &da903x_backlight_ops
, &props
);
137 dev_err(&pdev
->dev
, "failed to register backlight\n");
141 bl
->props
.brightness
= max_brightness
;
143 platform_set_drvdata(pdev
, bl
);
144 backlight_update_status(bl
);
148 static struct platform_driver da903x_backlight_driver
= {
150 .name
= "da903x-backlight",
152 .probe
= da903x_backlight_probe
,
155 module_platform_driver(da903x_backlight_driver
);
157 MODULE_DESCRIPTION("Backlight Driver for Dialog Semiconductor DA9030/DA9034");
158 MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
159 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
160 MODULE_LICENSE("GPL");
161 MODULE_ALIAS("platform:da903x-backlight");