sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / video / backlight / da9052_bl.c
blobfd2be417aa64d5a247756a7ebacdf6c3472fc012
1 /*
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>
17 #include <linux/fb.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
26 enum {
27 DA9052_WLEDS_OFF,
28 DA9052_WLEDS_ON,
31 enum {
32 DA9052_TYPE_WLED1,
33 DA9052_TYPE_WLED2,
34 DA9052_TYPE_WLED3,
37 static const unsigned char wled_bank[] = {
38 DA9052_LED1_CONF_REG,
39 DA9052_LED2_CONF_REG,
40 DA9052_LED3_CONF_REG,
43 struct da9052_bl {
44 struct da9052 *da9052;
45 uint brightness;
46 uint state;
47 uint led_reg;
50 static int da9052_adjust_wled_brightness(struct da9052_bl *wleds)
52 unsigned char boost_en;
53 unsigned char i_sink;
54 int ret;
56 boost_en = 0x3F;
57 i_sink = 0xFF;
58 if (wleds->state == DA9052_WLEDS_OFF) {
59 boost_en = 0x00;
60 i_sink = 0x00;
63 ret = da9052_reg_write(wleds->da9052, DA9052_BOOST_REG, boost_en);
64 if (ret < 0)
65 return ret;
67 ret = da9052_reg_write(wleds->da9052, DA9052_LED_CONT_REG, i_sink);
68 if (ret < 0)
69 return ret;
71 ret = da9052_reg_write(wleds->da9052, wled_bank[wleds->led_reg], 0x0);
72 if (ret < 0)
73 return ret;
75 usleep_range(10000, 11000);
77 if (wleds->brightness) {
78 ret = da9052_reg_write(wleds->da9052, wled_bank[wleds->led_reg],
79 wleds->brightness);
80 if (ret < 0)
81 return ret;
84 return 0;
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);
117 if (!wleds)
118 return -ENOMEM;
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);
131 if (IS_ERR(bl)) {
132 dev_err(&pdev->dev, "Failed to register backlight\n");
133 return PTR_ERR(bl);
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);
152 return 0;
155 static const 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,
168 { },
171 static struct platform_driver da9052_wled_driver = {
172 .probe = da9052_backlight_probe,
173 .remove = da9052_backlight_remove,
174 .id_table = da9052_wled_ids,
175 .driver = {
176 .name = "da9052-wled",
180 module_platform_driver(da9052_wled_driver);
182 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
183 MODULE_DESCRIPTION("Backlight driver for DA9052 PMIC");
184 MODULE_LICENSE("GPL");
185 MODULE_ALIAS("platform:da9052-backlight");