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>
22 #include <linux/module.h>
24 #define DA9030_WLED_CONTROL 0x25
25 #define DA9030_WLED_CP_EN (1 << 6)
26 #define DA9030_WLED_TRIM(x) ((x) & 0x7)
28 #define DA9034_WLED_CONTROL1 0x3C
29 #define DA9034_WLED_CONTROL2 0x3D
30 #define DA9034_WLED_ISET(x) ((x) & 0x1f)
32 #define DA9034_WLED_BOOST_EN (1 << 5)
34 #define DA9030_MAX_BRIGHTNESS 7
35 #define DA9034_MAX_BRIGHTNESS 0x7f
37 struct da903x_backlight_data
{
38 struct device
*da903x_dev
;
40 int current_brightness
;
43 static int da903x_backlight_set(struct backlight_device
*bl
, int brightness
)
45 struct da903x_backlight_data
*data
= bl_get_data(bl
);
46 struct device
*dev
= data
->da903x_dev
;
52 ret
= da903x_update(dev
, DA9034_WLED_CONTROL1
,
57 if (data
->current_brightness
&& brightness
== 0)
58 ret
= da903x_clr_bits(dev
,
60 DA9034_WLED_BOOST_EN
);
62 if (data
->current_brightness
== 0 && brightness
)
63 ret
= da903x_set_bits(dev
,
65 DA9034_WLED_BOOST_EN
);
68 val
= DA9030_WLED_TRIM(brightness
);
69 val
|= brightness
? DA9030_WLED_CP_EN
: 0;
70 ret
= da903x_write(dev
, DA9030_WLED_CONTROL
, val
);
77 data
->current_brightness
= brightness
;
81 static int da903x_backlight_update_status(struct backlight_device
*bl
)
83 int brightness
= bl
->props
.brightness
;
85 if (bl
->props
.power
!= FB_BLANK_UNBLANK
)
88 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
91 if (bl
->props
.state
& BL_CORE_SUSPENDED
)
94 return da903x_backlight_set(bl
, brightness
);
97 static int da903x_backlight_get_brightness(struct backlight_device
*bl
)
99 struct da903x_backlight_data
*data
= bl_get_data(bl
);
101 return data
->current_brightness
;
104 static const struct backlight_ops da903x_backlight_ops
= {
105 .options
= BL_CORE_SUSPENDRESUME
,
106 .update_status
= da903x_backlight_update_status
,
107 .get_brightness
= da903x_backlight_get_brightness
,
110 static int da903x_backlight_probe(struct platform_device
*pdev
)
112 struct da9034_backlight_pdata
*pdata
= dev_get_platdata(&pdev
->dev
);
113 struct da903x_backlight_data
*data
;
114 struct backlight_device
*bl
;
115 struct backlight_properties props
;
118 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
124 max_brightness
= DA9030_MAX_BRIGHTNESS
;
127 max_brightness
= DA9034_MAX_BRIGHTNESS
;
130 dev_err(&pdev
->dev
, "invalid backlight device ID(%d)\n",
136 data
->da903x_dev
= pdev
->dev
.parent
;
137 data
->current_brightness
= 0;
139 /* adjust the WLED output current */
141 da903x_write(data
->da903x_dev
, DA9034_WLED_CONTROL2
,
142 DA9034_WLED_ISET(pdata
->output_current
));
144 memset(&props
, 0, sizeof(props
));
145 props
.type
= BACKLIGHT_RAW
;
146 props
.max_brightness
= max_brightness
;
147 bl
= devm_backlight_device_register(&pdev
->dev
, pdev
->name
,
148 data
->da903x_dev
, data
,
149 &da903x_backlight_ops
, &props
);
151 dev_err(&pdev
->dev
, "failed to register backlight\n");
155 bl
->props
.brightness
= max_brightness
;
157 platform_set_drvdata(pdev
, bl
);
158 backlight_update_status(bl
);
162 static struct platform_driver da903x_backlight_driver
= {
164 .name
= "da903x-backlight",
166 .probe
= da903x_backlight_probe
,
169 module_platform_driver(da903x_backlight_driver
);
171 MODULE_DESCRIPTION("Backlight Driver for Dialog Semiconductor DA9030/DA9034");
172 MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
173 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
174 MODULE_LICENSE("GPL");
175 MODULE_ALIAS("platform:da903x-backlight");