diff options
Diffstat (limited to 'drivers/video/backlight/adp5520_bl.c')
-rw-r--r-- | drivers/video/backlight/adp5520_bl.c | 137 |
1 files changed, 78 insertions, 59 deletions
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c index ad05da5ba3c7..9f436e014f85 100644 --- a/drivers/video/backlight/adp5520_bl.c +++ b/drivers/video/backlight/adp5520_bl.c | |||
@@ -12,10 +12,11 @@ | |||
12 | #include <linux/fb.h> | 12 | #include <linux/fb.h> |
13 | #include <linux/backlight.h> | 13 | #include <linux/backlight.h> |
14 | #include <linux/mfd/adp5520.h> | 14 | #include <linux/mfd/adp5520.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | struct adp5520_bl { | 17 | struct adp5520_bl { |
17 | struct device *master; | 18 | struct device *master; |
18 | struct adp5520_backlight_platfrom_data *pdata; | 19 | struct adp5520_backlight_platform_data *pdata; |
19 | struct mutex lock; | 20 | struct mutex lock; |
20 | unsigned long cached_daylight_max; | 21 | unsigned long cached_daylight_max; |
21 | int id; | 22 | int id; |
@@ -31,29 +32,30 @@ static int adp5520_bl_set(struct backlight_device *bl, int brightness) | |||
31 | if (data->pdata->en_ambl_sens) { | 32 | if (data->pdata->en_ambl_sens) { |
32 | if ((brightness > 0) && (brightness < ADP5020_MAX_BRIGHTNESS)) { | 33 | if ((brightness > 0) && (brightness < ADP5020_MAX_BRIGHTNESS)) { |
33 | /* Disable Ambient Light auto adjust */ | 34 | /* Disable Ambient Light auto adjust */ |
34 | ret |= adp5520_clr_bits(master, BL_CONTROL, | 35 | ret |= adp5520_clr_bits(master, ADP5520_BL_CONTROL, |
35 | BL_AUTO_ADJ); | 36 | ADP5520_BL_AUTO_ADJ); |
36 | ret |= adp5520_write(master, DAYLIGHT_MAX, brightness); | 37 | ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX, |
38 | brightness); | ||
37 | } else { | 39 | } else { |
38 | /* | 40 | /* |
39 | * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust | 41 | * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust |
40 | * restore daylight l3 sysfs brightness | 42 | * restore daylight l3 sysfs brightness |
41 | */ | 43 | */ |
42 | ret |= adp5520_write(master, DAYLIGHT_MAX, | 44 | ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX, |
43 | data->cached_daylight_max); | 45 | data->cached_daylight_max); |
44 | ret |= adp5520_set_bits(master, BL_CONTROL, | 46 | ret |= adp5520_set_bits(master, ADP5520_BL_CONTROL, |
45 | BL_AUTO_ADJ); | 47 | ADP5520_BL_AUTO_ADJ); |
46 | } | 48 | } |
47 | } else { | 49 | } else { |
48 | ret |= adp5520_write(master, DAYLIGHT_MAX, brightness); | 50 | ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX, brightness); |
49 | } | 51 | } |
50 | 52 | ||
51 | if (data->current_brightness && brightness == 0) | 53 | if (data->current_brightness && brightness == 0) |
52 | ret |= adp5520_set_bits(master, | 54 | ret |= adp5520_set_bits(master, |
53 | MODE_STATUS, DIM_EN); | 55 | ADP5520_MODE_STATUS, ADP5520_DIM_EN); |
54 | else if (data->current_brightness == 0 && brightness) | 56 | else if (data->current_brightness == 0 && brightness) |
55 | ret |= adp5520_clr_bits(master, | 57 | ret |= adp5520_clr_bits(master, |
56 | MODE_STATUS, DIM_EN); | 58 | ADP5520_MODE_STATUS, ADP5520_DIM_EN); |
57 | 59 | ||
58 | if (!ret) | 60 | if (!ret) |
59 | data->current_brightness = brightness; | 61 | data->current_brightness = brightness; |
@@ -79,12 +81,12 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl) | |||
79 | int error; | 81 | int error; |
80 | uint8_t reg_val; | 82 | uint8_t reg_val; |
81 | 83 | ||
82 | error = adp5520_read(data->master, BL_VALUE, ®_val); | 84 | error = adp5520_read(data->master, ADP5520_BL_VALUE, ®_val); |
83 | 85 | ||
84 | return error ? data->current_brightness : reg_val; | 86 | return error ? data->current_brightness : reg_val; |
85 | } | 87 | } |
86 | 88 | ||
87 | static struct backlight_ops adp5520_bl_ops = { | 89 | static const struct backlight_ops adp5520_bl_ops = { |
88 | .update_status = adp5520_bl_update_status, | 90 | .update_status = adp5520_bl_update_status, |
89 | .get_brightness = adp5520_bl_get_brightness, | 91 | .get_brightness = adp5520_bl_get_brightness, |
90 | }; | 92 | }; |
@@ -93,33 +95,46 @@ static int adp5520_bl_setup(struct backlight_device *bl) | |||
93 | { | 95 | { |
94 | struct adp5520_bl *data = bl_get_data(bl); | 96 | struct adp5520_bl *data = bl_get_data(bl); |
95 | struct device *master = data->master; | 97 | struct device *master = data->master; |
96 | struct adp5520_backlight_platfrom_data *pdata = data->pdata; | 98 | struct adp5520_backlight_platform_data *pdata = data->pdata; |
97 | int ret = 0; | 99 | int ret = 0; |
98 | 100 | ||
99 | ret |= adp5520_write(master, DAYLIGHT_MAX, pdata->l1_daylight_max); | 101 | ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX, |
100 | ret |= adp5520_write(master, DAYLIGHT_DIM, pdata->l1_daylight_dim); | 102 | pdata->l1_daylight_max); |
103 | ret |= adp5520_write(master, ADP5520_DAYLIGHT_DIM, | ||
104 | pdata->l1_daylight_dim); | ||
101 | 105 | ||
102 | if (pdata->en_ambl_sens) { | 106 | if (pdata->en_ambl_sens) { |
103 | data->cached_daylight_max = pdata->l1_daylight_max; | 107 | data->cached_daylight_max = pdata->l1_daylight_max; |
104 | ret |= adp5520_write(master, OFFICE_MAX, pdata->l2_office_max); | 108 | ret |= adp5520_write(master, ADP5520_OFFICE_MAX, |
105 | ret |= adp5520_write(master, OFFICE_DIM, pdata->l2_office_dim); | 109 | pdata->l2_office_max); |
106 | ret |= adp5520_write(master, DARK_MAX, pdata->l3_dark_max); | 110 | ret |= adp5520_write(master, ADP5520_OFFICE_DIM, |
107 | ret |= adp5520_write(master, DARK_DIM, pdata->l3_dark_dim); | 111 | pdata->l2_office_dim); |
108 | ret |= adp5520_write(master, L2_TRIP, pdata->l2_trip); | 112 | ret |= adp5520_write(master, ADP5520_DARK_MAX, |
109 | ret |= adp5520_write(master, L2_HYS, pdata->l2_hyst); | 113 | pdata->l3_dark_max); |
110 | ret |= adp5520_write(master, L3_TRIP, pdata->l3_trip); | 114 | ret |= adp5520_write(master, ADP5520_DARK_DIM, |
111 | ret |= adp5520_write(master, L3_HYS, pdata->l3_hyst); | 115 | pdata->l3_dark_dim); |
112 | ret |= adp5520_write(master, ALS_CMPR_CFG, | 116 | ret |= adp5520_write(master, ADP5520_L2_TRIP, |
113 | ALS_CMPR_CFG_VAL(pdata->abml_filt, L3_EN)); | 117 | pdata->l2_trip); |
118 | ret |= adp5520_write(master, ADP5520_L2_HYS, | ||
119 | pdata->l2_hyst); | ||
120 | ret |= adp5520_write(master, ADP5520_L3_TRIP, | ||
121 | pdata->l3_trip); | ||
122 | ret |= adp5520_write(master, ADP5520_L3_HYS, | ||
123 | pdata->l3_hyst); | ||
124 | ret |= adp5520_write(master, ADP5520_ALS_CMPR_CFG, | ||
125 | ALS_CMPR_CFG_VAL(pdata->abml_filt, | ||
126 | ADP5520_L3_EN)); | ||
114 | } | 127 | } |
115 | 128 | ||
116 | ret |= adp5520_write(master, BL_CONTROL, | 129 | ret |= adp5520_write(master, ADP5520_BL_CONTROL, |
117 | BL_CTRL_VAL(pdata->fade_led_law, pdata->en_ambl_sens)); | 130 | BL_CTRL_VAL(pdata->fade_led_law, |
131 | pdata->en_ambl_sens)); | ||
118 | 132 | ||
119 | ret |= adp5520_write(master, BL_FADE, FADE_VAL(pdata->fade_in, | 133 | ret |= adp5520_write(master, ADP5520_BL_FADE, FADE_VAL(pdata->fade_in, |
120 | pdata->fade_out)); | 134 | pdata->fade_out)); |
121 | 135 | ||
122 | ret |= adp5520_set_bits(master, MODE_STATUS, BL_EN | DIM_EN); | 136 | ret |= adp5520_set_bits(master, ADP5520_MODE_STATUS, |
137 | ADP5520_BL_EN | ADP5520_DIM_EN); | ||
123 | 138 | ||
124 | return ret; | 139 | return ret; |
125 | } | 140 | } |
@@ -156,29 +171,31 @@ static ssize_t adp5520_store(struct device *dev, const char *buf, | |||
156 | } | 171 | } |
157 | 172 | ||
158 | static ssize_t adp5520_bl_dark_max_show(struct device *dev, | 173 | static ssize_t adp5520_bl_dark_max_show(struct device *dev, |
159 | struct device_attribute *attr, char *buf) | 174 | struct device_attribute *attr, char *buf) |
160 | { | 175 | { |
161 | return adp5520_show(dev, buf, DARK_MAX); | 176 | return adp5520_show(dev, buf, ADP5520_DARK_MAX); |
162 | } | 177 | } |
163 | 178 | ||
164 | static ssize_t adp5520_bl_dark_max_store(struct device *dev, | 179 | static ssize_t adp5520_bl_dark_max_store(struct device *dev, |
165 | struct device_attribute *attr, const char *buf, size_t count) | 180 | struct device_attribute *attr, |
181 | const char *buf, size_t count) | ||
166 | { | 182 | { |
167 | return adp5520_store(dev, buf, count, DARK_MAX); | 183 | return adp5520_store(dev, buf, count, ADP5520_DARK_MAX); |
168 | } | 184 | } |
169 | static DEVICE_ATTR(dark_max, 0664, adp5520_bl_dark_max_show, | 185 | static DEVICE_ATTR(dark_max, 0664, adp5520_bl_dark_max_show, |
170 | adp5520_bl_dark_max_store); | 186 | adp5520_bl_dark_max_store); |
171 | 187 | ||
172 | static ssize_t adp5520_bl_office_max_show(struct device *dev, | 188 | static ssize_t adp5520_bl_office_max_show(struct device *dev, |
173 | struct device_attribute *attr, char *buf) | 189 | struct device_attribute *attr, char *buf) |
174 | { | 190 | { |
175 | return adp5520_show(dev, buf, OFFICE_MAX); | 191 | return adp5520_show(dev, buf, ADP5520_OFFICE_MAX); |
176 | } | 192 | } |
177 | 193 | ||
178 | static ssize_t adp5520_bl_office_max_store(struct device *dev, | 194 | static ssize_t adp5520_bl_office_max_store(struct device *dev, |
179 | struct device_attribute *attr, const char *buf, size_t count) | 195 | struct device_attribute *attr, |
196 | const char *buf, size_t count) | ||
180 | { | 197 | { |
181 | return adp5520_store(dev, buf, count, OFFICE_MAX); | 198 | return adp5520_store(dev, buf, count, ADP5520_OFFICE_MAX); |
182 | } | 199 | } |
183 | static DEVICE_ATTR(office_max, 0664, adp5520_bl_office_max_show, | 200 | static DEVICE_ATTR(office_max, 0664, adp5520_bl_office_max_show, |
184 | adp5520_bl_office_max_store); | 201 | adp5520_bl_office_max_store); |
@@ -186,16 +203,17 @@ static DEVICE_ATTR(office_max, 0664, adp5520_bl_office_max_show, | |||
186 | static ssize_t adp5520_bl_daylight_max_show(struct device *dev, | 203 | static ssize_t adp5520_bl_daylight_max_show(struct device *dev, |
187 | struct device_attribute *attr, char *buf) | 204 | struct device_attribute *attr, char *buf) |
188 | { | 205 | { |
189 | return adp5520_show(dev, buf, DAYLIGHT_MAX); | 206 | return adp5520_show(dev, buf, ADP5520_DAYLIGHT_MAX); |
190 | } | 207 | } |
191 | 208 | ||
192 | static ssize_t adp5520_bl_daylight_max_store(struct device *dev, | 209 | static ssize_t adp5520_bl_daylight_max_store(struct device *dev, |
193 | struct device_attribute *attr, const char *buf, size_t count) | 210 | struct device_attribute *attr, |
211 | const char *buf, size_t count) | ||
194 | { | 212 | { |
195 | struct adp5520_bl *data = dev_get_drvdata(dev); | 213 | struct adp5520_bl *data = dev_get_drvdata(dev); |
196 | 214 | ||
197 | strict_strtoul(buf, 10, &data->cached_daylight_max); | 215 | strict_strtoul(buf, 10, &data->cached_daylight_max); |
198 | return adp5520_store(dev, buf, count, DAYLIGHT_MAX); | 216 | return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX); |
199 | } | 217 | } |
200 | static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show, | 218 | static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show, |
201 | adp5520_bl_daylight_max_store); | 219 | adp5520_bl_daylight_max_store); |
@@ -203,14 +221,14 @@ static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show, | |||
203 | static ssize_t adp5520_bl_dark_dim_show(struct device *dev, | 221 | static ssize_t adp5520_bl_dark_dim_show(struct device *dev, |
204 | struct device_attribute *attr, char *buf) | 222 | struct device_attribute *attr, char *buf) |
205 | { | 223 | { |
206 | return adp5520_show(dev, buf, DARK_DIM); | 224 | return adp5520_show(dev, buf, ADP5520_DARK_DIM); |
207 | } | 225 | } |
208 | 226 | ||
209 | static ssize_t adp5520_bl_dark_dim_store(struct device *dev, | 227 | static ssize_t adp5520_bl_dark_dim_store(struct device *dev, |
210 | struct device_attribute *attr, | 228 | struct device_attribute *attr, |
211 | const char *buf, size_t count) | 229 | const char *buf, size_t count) |
212 | { | 230 | { |
213 | return adp5520_store(dev, buf, count, DARK_DIM); | 231 | return adp5520_store(dev, buf, count, ADP5520_DARK_DIM); |
214 | } | 232 | } |
215 | static DEVICE_ATTR(dark_dim, 0664, adp5520_bl_dark_dim_show, | 233 | static DEVICE_ATTR(dark_dim, 0664, adp5520_bl_dark_dim_show, |
216 | adp5520_bl_dark_dim_store); | 234 | adp5520_bl_dark_dim_store); |
@@ -218,29 +236,29 @@ static DEVICE_ATTR(dark_dim, 0664, adp5520_bl_dark_dim_show, | |||
218 | static ssize_t adp5520_bl_office_dim_show(struct device *dev, | 236 | static ssize_t adp5520_bl_office_dim_show(struct device *dev, |
219 | struct device_attribute *attr, char *buf) | 237 | struct device_attribute *attr, char *buf) |
220 | { | 238 | { |
221 | return adp5520_show(dev, buf, OFFICE_DIM); | 239 | return adp5520_show(dev, buf, ADP5520_OFFICE_DIM); |
222 | } | 240 | } |
223 | 241 | ||
224 | static ssize_t adp5520_bl_office_dim_store(struct device *dev, | 242 | static ssize_t adp5520_bl_office_dim_store(struct device *dev, |
225 | struct device_attribute *attr, | 243 | struct device_attribute *attr, |
226 | const char *buf, size_t count) | 244 | const char *buf, size_t count) |
227 | { | 245 | { |
228 | return adp5520_store(dev, buf, count, OFFICE_DIM); | 246 | return adp5520_store(dev, buf, count, ADP5520_OFFICE_DIM); |
229 | } | 247 | } |
230 | static DEVICE_ATTR(office_dim, 0664, adp5520_bl_office_dim_show, | 248 | static DEVICE_ATTR(office_dim, 0664, adp5520_bl_office_dim_show, |
231 | adp5520_bl_office_dim_store); | 249 | adp5520_bl_office_dim_store); |
232 | 250 | ||
233 | static ssize_t adp5520_bl_daylight_dim_show(struct device *dev, | 251 | static ssize_t adp5520_bl_daylight_dim_show(struct device *dev, |
234 | struct device_attribute *attr, char *buf) | 252 | struct device_attribute *attr, char *buf) |
235 | { | 253 | { |
236 | return adp5520_show(dev, buf, DAYLIGHT_DIM); | 254 | return adp5520_show(dev, buf, ADP5520_DAYLIGHT_DIM); |
237 | } | 255 | } |
238 | 256 | ||
239 | static ssize_t adp5520_bl_daylight_dim_store(struct device *dev, | 257 | static ssize_t adp5520_bl_daylight_dim_store(struct device *dev, |
240 | struct device_attribute *attr, | 258 | struct device_attribute *attr, |
241 | const char *buf, size_t count) | 259 | const char *buf, size_t count) |
242 | { | 260 | { |
243 | return adp5520_store(dev, buf, count, DAYLIGHT_DIM); | 261 | return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_DIM); |
244 | } | 262 | } |
245 | static DEVICE_ATTR(daylight_dim, 0664, adp5520_bl_daylight_dim_show, | 263 | static DEVICE_ATTR(daylight_dim, 0664, adp5520_bl_daylight_dim_show, |
246 | adp5520_bl_daylight_dim_store); | 264 | adp5520_bl_daylight_dim_store); |
@@ -261,6 +279,7 @@ static const struct attribute_group adp5520_bl_attr_group = { | |||
261 | 279 | ||
262 | static int __devinit adp5520_bl_probe(struct platform_device *pdev) | 280 | static int __devinit adp5520_bl_probe(struct platform_device *pdev) |
263 | { | 281 | { |
282 | struct backlight_properties props; | ||
264 | struct backlight_device *bl; | 283 | struct backlight_device *bl; |
265 | struct adp5520_bl *data; | 284 | struct adp5520_bl *data; |
266 | int ret = 0; | 285 | int ret = 0; |
@@ -283,17 +302,17 @@ static int __devinit adp5520_bl_probe(struct platform_device *pdev) | |||
283 | 302 | ||
284 | mutex_init(&data->lock); | 303 | mutex_init(&data->lock); |
285 | 304 | ||
286 | bl = backlight_device_register(pdev->name, data->master, | 305 | memset(&props, 0, sizeof(struct backlight_properties)); |
287 | data, &adp5520_bl_ops); | 306 | props.max_brightness = ADP5020_MAX_BRIGHTNESS; |
307 | bl = backlight_device_register(pdev->name, data->master, data, | ||
308 | &adp5520_bl_ops, &props); | ||
288 | if (IS_ERR(bl)) { | 309 | if (IS_ERR(bl)) { |
289 | dev_err(&pdev->dev, "failed to register backlight\n"); | 310 | dev_err(&pdev->dev, "failed to register backlight\n"); |
290 | kfree(data); | 311 | kfree(data); |
291 | return PTR_ERR(bl); | 312 | return PTR_ERR(bl); |
292 | } | 313 | } |
293 | 314 | ||
294 | bl->props.max_brightness = | 315 | bl->props.brightness = ADP5020_MAX_BRIGHTNESS; |
295 | bl->props.brightness = ADP5020_MAX_BRIGHTNESS; | ||
296 | |||
297 | if (data->pdata->en_ambl_sens) | 316 | if (data->pdata->en_ambl_sens) |
298 | ret = sysfs_create_group(&bl->dev.kobj, | 317 | ret = sysfs_create_group(&bl->dev.kobj, |
299 | &adp5520_bl_attr_group); | 318 | &adp5520_bl_attr_group); |
@@ -316,7 +335,7 @@ static int __devexit adp5520_bl_remove(struct platform_device *pdev) | |||
316 | struct backlight_device *bl = platform_get_drvdata(pdev); | 335 | struct backlight_device *bl = platform_get_drvdata(pdev); |
317 | struct adp5520_bl *data = bl_get_data(bl); | 336 | struct adp5520_bl *data = bl_get_data(bl); |
318 | 337 | ||
319 | adp5520_clr_bits(data->master, MODE_STATUS, BL_EN); | 338 | adp5520_clr_bits(data->master, ADP5520_MODE_STATUS, ADP5520_BL_EN); |
320 | 339 | ||
321 | if (data->pdata->en_ambl_sens) | 340 | if (data->pdata->en_ambl_sens) |
322 | sysfs_remove_group(&bl->dev.kobj, | 341 | sysfs_remove_group(&bl->dev.kobj, |