2 * Backlight 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/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
19 #include <linux/backlight.h>
20 #include <linux/mfd/da903x.h>
21 #include <linux/slab.h>
23 #define DA9030_WLED_CONTROL 0x25
24 #define DA9030_WLED_CP_EN (1 << 6)
25 #define DA9030_WLED_TRIM(x) ((x) & 0x7)
27 #define DA9034_WLED_CONTROL1 0x3C
28 #define DA9034_WLED_CONTROL2 0x3D
29 #define DA9034_WLED_ISET(x) ((x) & 0x1f)
31 #define DA9034_WLED_BOOST_EN (1 << 5)
33 #define DA9030_MAX_BRIGHTNESS 7
34 #define DA9034_MAX_BRIGHTNESS 0x7f
36 struct da903x_backlight_data
{
37 struct device
*da903x_dev
;
39 int current_brightness
;
42 static int da903x_backlight_set(struct backlight_device
*bl
, int brightness
)
44 struct da903x_backlight_data
*data
= bl_get_data(bl
);
45 struct device
*dev
= data
->da903x_dev
;
51 ret
= da903x_update(dev
, DA9034_WLED_CONTROL1
,
56 if (data
->current_brightness
&& brightness
== 0)
57 ret
= da903x_clr_bits(dev
,
59 DA9034_WLED_BOOST_EN
);
61 if (data
->current_brightness
== 0 && brightness
)
62 ret
= da903x_set_bits(dev
,
64 DA9034_WLED_BOOST_EN
);
67 val
= DA9030_WLED_TRIM(brightness
);
68 val
|= brightness
? DA9030_WLED_CP_EN
: 0;
69 ret
= da903x_write(dev
, DA9030_WLED_CONTROL
, val
);
76 data
->current_brightness
= brightness
;
80 static int da903x_backlight_update_status(struct backlight_device
*bl
)
82 int brightness
= bl
->props
.brightness
;
84 if (bl
->props
.power
!= FB_BLANK_UNBLANK
)
87 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
90 return da903x_backlight_set(bl
, brightness
);
93 static int da903x_backlight_get_brightness(struct backlight_device
*bl
)
95 struct da903x_backlight_data
*data
= bl_get_data(bl
);
96 return data
->current_brightness
;
99 static const struct backlight_ops da903x_backlight_ops
= {
100 .update_status
= da903x_backlight_update_status
,
101 .get_brightness
= da903x_backlight_get_brightness
,
104 static int da903x_backlight_probe(struct platform_device
*pdev
)
106 struct da9034_backlight_pdata
*pdata
= pdev
->dev
.platform_data
;
107 struct da903x_backlight_data
*data
;
108 struct backlight_device
*bl
;
109 struct backlight_properties props
;
112 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
118 max_brightness
= DA9030_MAX_BRIGHTNESS
;
121 max_brightness
= DA9034_MAX_BRIGHTNESS
;
124 dev_err(&pdev
->dev
, "invalid backlight device ID(%d)\n",
131 data
->da903x_dev
= pdev
->dev
.parent
;
132 data
->current_brightness
= 0;
134 /* adjust the WLED output current */
136 da903x_write(data
->da903x_dev
, DA9034_WLED_CONTROL2
,
137 DA9034_WLED_ISET(pdata
->output_current
));
139 props
.type
= BACKLIGHT_RAW
;
140 props
.max_brightness
= max_brightness
;
141 bl
= backlight_device_register(pdev
->name
, data
->da903x_dev
, data
,
142 &da903x_backlight_ops
, &props
);
144 dev_err(&pdev
->dev
, "failed to register backlight\n");
149 bl
->props
.brightness
= max_brightness
;
151 platform_set_drvdata(pdev
, bl
);
152 backlight_update_status(bl
);
156 static int da903x_backlight_remove(struct platform_device
*pdev
)
158 struct backlight_device
*bl
= platform_get_drvdata(pdev
);
159 struct da903x_backlight_data
*data
= bl_get_data(bl
);
161 backlight_device_unregister(bl
);
167 static int da903x_backlight_suspend(struct device
*dev
)
169 struct platform_device
*pdev
= to_platform_device(dev
);
170 struct backlight_device
*bl
= platform_get_drvdata(pdev
);
171 return da903x_backlight_set(bl
, 0);
174 static int da903x_backlight_resume(struct device
*dev
)
176 struct platform_device
*pdev
= to_platform_device(dev
);
177 struct backlight_device
*bl
= platform_get_drvdata(pdev
);
179 backlight_update_status(bl
);
183 static const struct dev_pm_ops da903x_backlight_pm_ops
= {
184 .suspend
= da903x_backlight_suspend
,
185 .resume
= da903x_backlight_resume
,
189 static struct platform_driver da903x_backlight_driver
= {
191 .name
= "da903x-backlight",
192 .owner
= THIS_MODULE
,
194 .pm
= &da903x_backlight_pm_ops
,
197 .probe
= da903x_backlight_probe
,
198 .remove
= da903x_backlight_remove
,
201 static int __init
da903x_backlight_init(void)
203 return platform_driver_register(&da903x_backlight_driver
);
205 module_init(da903x_backlight_init
);
207 static void __exit
da903x_backlight_exit(void)
209 platform_driver_unregister(&da903x_backlight_driver
);
211 module_exit(da903x_backlight_exit
);
213 MODULE_DESCRIPTION("Backlight Driver for Dialog Semiconductor DA9030/DA9034");
214 MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
215 "Mike Rapoport <mike@compulab.co.il>");
216 MODULE_LICENSE("GPL");
217 MODULE_ALIAS("platform:da903x-backlight");