Commit | Line | Data |
---|---|---|
d2bedfe7 MB |
1 | /* |
2 | * wm831x-core.c -- Device access for Wolfson WM831x PMICs | |
3 | * | |
4 | * Copyright 2009 Wolfson Microelectronics PLC. | |
5 | * | |
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2 of the License, or (at your | |
11 | * option) any later version. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include <linux/kernel.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/i2c.h> | |
7e9f9fd4 MB |
18 | #include <linux/bcd.h> |
19 | #include <linux/delay.h> | |
d2bedfe7 MB |
20 | #include <linux/mfd/core.h> |
21 | ||
22 | #include <linux/mfd/wm831x/core.h> | |
23 | #include <linux/mfd/wm831x/pdata.h> | |
7d4d0a3e | 24 | #include <linux/mfd/wm831x/irq.h> |
7e9f9fd4 | 25 | #include <linux/mfd/wm831x/auxadc.h> |
6704e517 | 26 | #include <linux/mfd/wm831x/otp.h> |
d2bedfe7 MB |
27 | |
28 | enum wm831x_parent { | |
29 | WM8310 = 0, | |
30 | WM8311 = 1, | |
31 | WM8312 = 2, | |
32 | }; | |
33 | ||
34 | static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg) | |
35 | { | |
36 | if (!wm831x->locked) | |
37 | return 0; | |
38 | ||
39 | switch (reg) { | |
40 | case WM831X_WATCHDOG: | |
41 | case WM831X_DC4_CONTROL: | |
42 | case WM831X_ON_PIN_CONTROL: | |
43 | case WM831X_BACKUP_CHARGER_CONTROL: | |
44 | case WM831X_CHARGER_CONTROL_1: | |
45 | case WM831X_CHARGER_CONTROL_2: | |
46 | return 1; | |
47 | ||
48 | default: | |
49 | return 0; | |
50 | } | |
51 | } | |
52 | ||
53 | /** | |
54 | * wm831x_reg_unlock: Unlock user keyed registers | |
55 | * | |
56 | * The WM831x has a user key preventing writes to particularly | |
57 | * critical registers. This function locks those registers, | |
58 | * allowing writes to them. | |
59 | */ | |
60 | void wm831x_reg_lock(struct wm831x *wm831x) | |
61 | { | |
62 | int ret; | |
63 | ||
64 | ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0); | |
65 | if (ret == 0) { | |
66 | dev_vdbg(wm831x->dev, "Registers locked\n"); | |
67 | ||
68 | mutex_lock(&wm831x->io_lock); | |
69 | WARN_ON(wm831x->locked); | |
70 | wm831x->locked = 1; | |
71 | mutex_unlock(&wm831x->io_lock); | |
72 | } else { | |
73 | dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret); | |
74 | } | |
75 | ||
76 | } | |
77 | EXPORT_SYMBOL_GPL(wm831x_reg_lock); | |
78 | ||
79 | /** | |
80 | * wm831x_reg_unlock: Unlock user keyed registers | |
81 | * | |
82 | * The WM831x has a user key preventing writes to particularly | |
83 | * critical registers. This function locks those registers, | |
84 | * preventing spurious writes. | |
85 | */ | |
86 | int wm831x_reg_unlock(struct wm831x *wm831x) | |
87 | { | |
88 | int ret; | |
89 | ||
90 | /* 0x9716 is the value required to unlock the registers */ | |
91 | ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716); | |
92 | if (ret == 0) { | |
93 | dev_vdbg(wm831x->dev, "Registers unlocked\n"); | |
94 | ||
95 | mutex_lock(&wm831x->io_lock); | |
96 | WARN_ON(!wm831x->locked); | |
97 | wm831x->locked = 0; | |
98 | mutex_unlock(&wm831x->io_lock); | |
99 | } | |
100 | ||
101 | return ret; | |
102 | } | |
103 | EXPORT_SYMBOL_GPL(wm831x_reg_unlock); | |
104 | ||
105 | static int wm831x_read(struct wm831x *wm831x, unsigned short reg, | |
106 | int bytes, void *dest) | |
107 | { | |
108 | int ret, i; | |
109 | u16 *buf = dest; | |
110 | ||
111 | BUG_ON(bytes % 2); | |
112 | BUG_ON(bytes <= 0); | |
113 | ||
114 | ret = wm831x->read_dev(wm831x, reg, bytes, dest); | |
115 | if (ret < 0) | |
116 | return ret; | |
117 | ||
118 | for (i = 0; i < bytes / 2; i++) { | |
119 | buf[i] = be16_to_cpu(buf[i]); | |
120 | ||
121 | dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n", | |
122 | buf[i], reg + i, reg + i); | |
123 | } | |
124 | ||
125 | return 0; | |
126 | } | |
127 | ||
128 | /** | |
129 | * wm831x_reg_read: Read a single WM831x register. | |
130 | * | |
131 | * @wm831x: Device to read from. | |
132 | * @reg: Register to read. | |
133 | */ | |
134 | int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) | |
135 | { | |
136 | unsigned short val; | |
137 | int ret; | |
138 | ||
139 | mutex_lock(&wm831x->io_lock); | |
140 | ||
141 | ret = wm831x_read(wm831x, reg, 2, &val); | |
142 | ||
143 | mutex_unlock(&wm831x->io_lock); | |
144 | ||
145 | if (ret < 0) | |
146 | return ret; | |
147 | else | |
148 | return val; | |
149 | } | |
150 | EXPORT_SYMBOL_GPL(wm831x_reg_read); | |
151 | ||
152 | /** | |
153 | * wm831x_bulk_read: Read multiple WM831x registers | |
154 | * | |
155 | * @wm831x: Device to read from | |
156 | * @reg: First register | |
157 | * @count: Number of registers | |
158 | * @buf: Buffer to fill. | |
159 | */ | |
160 | int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, | |
161 | int count, u16 *buf) | |
162 | { | |
163 | int ret; | |
164 | ||
165 | mutex_lock(&wm831x->io_lock); | |
166 | ||
167 | ret = wm831x_read(wm831x, reg, count * 2, buf); | |
168 | ||
169 | mutex_unlock(&wm831x->io_lock); | |
170 | ||
171 | return ret; | |
172 | } | |
173 | EXPORT_SYMBOL_GPL(wm831x_bulk_read); | |
174 | ||
175 | static int wm831x_write(struct wm831x *wm831x, unsigned short reg, | |
176 | int bytes, void *src) | |
177 | { | |
178 | u16 *buf = src; | |
179 | int i; | |
180 | ||
181 | BUG_ON(bytes % 2); | |
182 | BUG_ON(bytes <= 0); | |
183 | ||
184 | for (i = 0; i < bytes / 2; i++) { | |
185 | if (wm831x_reg_locked(wm831x, reg)) | |
186 | return -EPERM; | |
187 | ||
188 | dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", | |
189 | buf[i], reg + i, reg + i); | |
190 | ||
191 | buf[i] = cpu_to_be16(buf[i]); | |
192 | } | |
193 | ||
194 | return wm831x->write_dev(wm831x, reg, bytes, src); | |
195 | } | |
196 | ||
197 | /** | |
198 | * wm831x_reg_write: Write a single WM831x register. | |
199 | * | |
200 | * @wm831x: Device to write to. | |
201 | * @reg: Register to write to. | |
202 | * @val: Value to write. | |
203 | */ | |
204 | int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg, | |
205 | unsigned short val) | |
206 | { | |
207 | int ret; | |
208 | ||
209 | mutex_lock(&wm831x->io_lock); | |
210 | ||
211 | ret = wm831x_write(wm831x, reg, 2, &val); | |
212 | ||
213 | mutex_unlock(&wm831x->io_lock); | |
214 | ||
215 | return ret; | |
216 | } | |
217 | EXPORT_SYMBOL_GPL(wm831x_reg_write); | |
218 | ||
219 | /** | |
220 | * wm831x_set_bits: Set the value of a bitfield in a WM831x register | |
221 | * | |
222 | * @wm831x: Device to write to. | |
223 | * @reg: Register to write to. | |
224 | * @mask: Mask of bits to set. | |
225 | * @val: Value to set (unshifted) | |
226 | */ | |
227 | int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg, | |
228 | unsigned short mask, unsigned short val) | |
229 | { | |
230 | int ret; | |
231 | u16 r; | |
232 | ||
233 | mutex_lock(&wm831x->io_lock); | |
234 | ||
235 | ret = wm831x_read(wm831x, reg, 2, &r); | |
236 | if (ret < 0) | |
237 | goto out; | |
238 | ||
239 | r &= ~mask; | |
240 | r |= val; | |
241 | ||
242 | ret = wm831x_write(wm831x, reg, 2, &r); | |
243 | ||
244 | out: | |
245 | mutex_unlock(&wm831x->io_lock); | |
246 | ||
247 | return ret; | |
248 | } | |
249 | EXPORT_SYMBOL_GPL(wm831x_set_bits); | |
250 | ||
7e9f9fd4 MB |
251 | /** |
252 | * wm831x_auxadc_read: Read a value from the WM831x AUXADC | |
253 | * | |
254 | * @wm831x: Device to read from. | |
255 | * @input: AUXADC input to read. | |
256 | */ | |
257 | int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) | |
258 | { | |
259 | int tries = 10; | |
260 | int ret, src; | |
261 | ||
262 | mutex_lock(&wm831x->auxadc_lock); | |
263 | ||
264 | ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, | |
265 | WM831X_AUX_ENA, WM831X_AUX_ENA); | |
266 | if (ret < 0) { | |
267 | dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n", ret); | |
268 | goto out; | |
269 | } | |
270 | ||
271 | /* We force a single source at present */ | |
272 | src = input; | |
273 | ret = wm831x_reg_write(wm831x, WM831X_AUXADC_SOURCE, | |
274 | 1 << src); | |
275 | if (ret < 0) { | |
276 | dev_err(wm831x->dev, "Failed to set AUXADC source: %d\n", ret); | |
277 | goto out; | |
278 | } | |
279 | ||
280 | ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, | |
281 | WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA); | |
282 | if (ret < 0) { | |
283 | dev_err(wm831x->dev, "Failed to start AUXADC: %d\n", ret); | |
284 | goto disable; | |
285 | } | |
286 | ||
287 | do { | |
288 | msleep(1); | |
289 | ||
290 | ret = wm831x_reg_read(wm831x, WM831X_AUXADC_CONTROL); | |
291 | if (ret < 0) | |
292 | ret = WM831X_AUX_CVT_ENA; | |
293 | } while ((ret & WM831X_AUX_CVT_ENA) && --tries); | |
294 | ||
295 | if (ret & WM831X_AUX_CVT_ENA) { | |
296 | dev_err(wm831x->dev, "Timed out reading AUXADC\n"); | |
297 | ret = -EBUSY; | |
298 | goto disable; | |
299 | } | |
300 | ||
301 | ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA); | |
302 | if (ret < 0) { | |
303 | dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret); | |
304 | } else { | |
305 | src = ((ret & WM831X_AUX_DATA_SRC_MASK) | |
306 | >> WM831X_AUX_DATA_SRC_SHIFT) - 1; | |
307 | ||
308 | if (src == 14) | |
309 | src = WM831X_AUX_CAL; | |
310 | ||
311 | if (src != input) { | |
312 | dev_err(wm831x->dev, "Data from source %d not %d\n", | |
313 | src, input); | |
314 | ret = -EINVAL; | |
315 | } else { | |
316 | ret &= WM831X_AUX_DATA_MASK; | |
317 | } | |
318 | } | |
319 | ||
320 | disable: | |
321 | wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, WM831X_AUX_ENA, 0); | |
322 | out: | |
323 | mutex_unlock(&wm831x->auxadc_lock); | |
324 | return ret; | |
325 | } | |
326 | EXPORT_SYMBOL_GPL(wm831x_auxadc_read); | |
327 | ||
328 | /** | |
329 | * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC | |
330 | * | |
331 | * @wm831x: Device to read from. | |
332 | * @input: AUXADC input to read. | |
333 | */ | |
334 | int wm831x_auxadc_read_uv(struct wm831x *wm831x, enum wm831x_auxadc input) | |
335 | { | |
336 | int ret; | |
337 | ||
338 | ret = wm831x_auxadc_read(wm831x, input); | |
339 | if (ret < 0) | |
340 | return ret; | |
341 | ||
342 | ret *= 1465; | |
343 | ||
344 | return ret; | |
345 | } | |
346 | EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv); | |
347 | ||
d2bedfe7 MB |
348 | static struct resource wm831x_dcdc1_resources[] = { |
349 | { | |
350 | .start = WM831X_DC1_CONTROL_1, | |
351 | .end = WM831X_DC1_DVS_CONTROL, | |
352 | .flags = IORESOURCE_IO, | |
353 | }, | |
354 | { | |
355 | .name = "UV", | |
356 | .start = WM831X_IRQ_UV_DC1, | |
357 | .end = WM831X_IRQ_UV_DC1, | |
358 | .flags = IORESOURCE_IRQ, | |
359 | }, | |
360 | { | |
361 | .name = "HC", | |
362 | .start = WM831X_IRQ_HC_DC1, | |
363 | .end = WM831X_IRQ_HC_DC1, | |
364 | .flags = IORESOURCE_IRQ, | |
365 | }, | |
366 | }; | |
367 | ||
368 | ||
369 | static struct resource wm831x_dcdc2_resources[] = { | |
370 | { | |
371 | .start = WM831X_DC2_CONTROL_1, | |
372 | .end = WM831X_DC2_DVS_CONTROL, | |
373 | .flags = IORESOURCE_IO, | |
374 | }, | |
375 | { | |
376 | .name = "UV", | |
377 | .start = WM831X_IRQ_UV_DC2, | |
378 | .end = WM831X_IRQ_UV_DC2, | |
379 | .flags = IORESOURCE_IRQ, | |
380 | }, | |
381 | { | |
382 | .name = "HC", | |
383 | .start = WM831X_IRQ_HC_DC2, | |
384 | .end = WM831X_IRQ_HC_DC2, | |
385 | .flags = IORESOURCE_IRQ, | |
386 | }, | |
387 | }; | |
388 | ||
389 | static struct resource wm831x_dcdc3_resources[] = { | |
390 | { | |
391 | .start = WM831X_DC3_CONTROL_1, | |
392 | .end = WM831X_DC3_SLEEP_CONTROL, | |
393 | .flags = IORESOURCE_IO, | |
394 | }, | |
395 | { | |
396 | .name = "UV", | |
397 | .start = WM831X_IRQ_UV_DC3, | |
398 | .end = WM831X_IRQ_UV_DC3, | |
399 | .flags = IORESOURCE_IRQ, | |
400 | }, | |
401 | }; | |
402 | ||
403 | static struct resource wm831x_dcdc4_resources[] = { | |
404 | { | |
405 | .start = WM831X_DC4_CONTROL, | |
406 | .end = WM831X_DC4_SLEEP_CONTROL, | |
407 | .flags = IORESOURCE_IO, | |
408 | }, | |
409 | { | |
410 | .name = "UV", | |
411 | .start = WM831X_IRQ_UV_DC4, | |
412 | .end = WM831X_IRQ_UV_DC4, | |
413 | .flags = IORESOURCE_IRQ, | |
414 | }, | |
415 | }; | |
416 | ||
417 | static struct resource wm831x_gpio_resources[] = { | |
418 | { | |
419 | .start = WM831X_IRQ_GPIO_1, | |
420 | .end = WM831X_IRQ_GPIO_16, | |
421 | .flags = IORESOURCE_IRQ, | |
422 | }, | |
423 | }; | |
424 | ||
425 | static struct resource wm831x_isink1_resources[] = { | |
426 | { | |
427 | .start = WM831X_CURRENT_SINK_1, | |
428 | .end = WM831X_CURRENT_SINK_1, | |
429 | .flags = IORESOURCE_IO, | |
430 | }, | |
431 | { | |
432 | .start = WM831X_IRQ_CS1, | |
433 | .end = WM831X_IRQ_CS1, | |
434 | .flags = IORESOURCE_IRQ, | |
435 | }, | |
436 | }; | |
437 | ||
438 | static struct resource wm831x_isink2_resources[] = { | |
439 | { | |
440 | .start = WM831X_CURRENT_SINK_2, | |
441 | .end = WM831X_CURRENT_SINK_2, | |
442 | .flags = IORESOURCE_IO, | |
443 | }, | |
444 | { | |
445 | .start = WM831X_IRQ_CS2, | |
446 | .end = WM831X_IRQ_CS2, | |
447 | .flags = IORESOURCE_IRQ, | |
448 | }, | |
449 | }; | |
450 | ||
451 | static struct resource wm831x_ldo1_resources[] = { | |
452 | { | |
453 | .start = WM831X_LDO1_CONTROL, | |
454 | .end = WM831X_LDO1_SLEEP_CONTROL, | |
455 | .flags = IORESOURCE_IO, | |
456 | }, | |
457 | { | |
458 | .name = "UV", | |
459 | .start = WM831X_IRQ_UV_LDO1, | |
460 | .end = WM831X_IRQ_UV_LDO1, | |
461 | .flags = IORESOURCE_IRQ, | |
462 | }, | |
463 | }; | |
464 | ||
465 | static struct resource wm831x_ldo2_resources[] = { | |
466 | { | |
467 | .start = WM831X_LDO2_CONTROL, | |
468 | .end = WM831X_LDO2_SLEEP_CONTROL, | |
469 | .flags = IORESOURCE_IO, | |
470 | }, | |
471 | { | |
472 | .name = "UV", | |
473 | .start = WM831X_IRQ_UV_LDO2, | |
474 | .end = WM831X_IRQ_UV_LDO2, | |
475 | .flags = IORESOURCE_IRQ, | |
476 | }, | |
477 | }; | |
478 | ||
479 | static struct resource wm831x_ldo3_resources[] = { | |
480 | { | |
481 | .start = WM831X_LDO3_CONTROL, | |
482 | .end = WM831X_LDO3_SLEEP_CONTROL, | |
483 | .flags = IORESOURCE_IO, | |
484 | }, | |
485 | { | |
486 | .name = "UV", | |
487 | .start = WM831X_IRQ_UV_LDO3, | |
488 | .end = WM831X_IRQ_UV_LDO3, | |
489 | .flags = IORESOURCE_IRQ, | |
490 | }, | |
491 | }; | |
492 | ||
493 | static struct resource wm831x_ldo4_resources[] = { | |
494 | { | |
495 | .start = WM831X_LDO4_CONTROL, | |
496 | .end = WM831X_LDO4_SLEEP_CONTROL, | |
497 | .flags = IORESOURCE_IO, | |
498 | }, | |
499 | { | |
500 | .name = "UV", | |
501 | .start = WM831X_IRQ_UV_LDO4, | |
502 | .end = WM831X_IRQ_UV_LDO4, | |
503 | .flags = IORESOURCE_IRQ, | |
504 | }, | |
505 | }; | |
506 | ||
507 | static struct resource wm831x_ldo5_resources[] = { | |
508 | { | |
509 | .start = WM831X_LDO5_CONTROL, | |
510 | .end = WM831X_LDO5_SLEEP_CONTROL, | |
511 | .flags = IORESOURCE_IO, | |
512 | }, | |
513 | { | |
514 | .name = "UV", | |
515 | .start = WM831X_IRQ_UV_LDO5, | |
516 | .end = WM831X_IRQ_UV_LDO5, | |
517 | .flags = IORESOURCE_IRQ, | |
518 | }, | |
519 | }; | |
520 | ||
521 | static struct resource wm831x_ldo6_resources[] = { | |
522 | { | |
523 | .start = WM831X_LDO6_CONTROL, | |
524 | .end = WM831X_LDO6_SLEEP_CONTROL, | |
525 | .flags = IORESOURCE_IO, | |
526 | }, | |
527 | { | |
528 | .name = "UV", | |
529 | .start = WM831X_IRQ_UV_LDO6, | |
530 | .end = WM831X_IRQ_UV_LDO6, | |
531 | .flags = IORESOURCE_IRQ, | |
532 | }, | |
533 | }; | |
534 | ||
535 | static struct resource wm831x_ldo7_resources[] = { | |
536 | { | |
537 | .start = WM831X_LDO7_CONTROL, | |
538 | .end = WM831X_LDO7_SLEEP_CONTROL, | |
539 | .flags = IORESOURCE_IO, | |
540 | }, | |
541 | { | |
542 | .name = "UV", | |
543 | .start = WM831X_IRQ_UV_LDO7, | |
544 | .end = WM831X_IRQ_UV_LDO7, | |
545 | .flags = IORESOURCE_IRQ, | |
546 | }, | |
547 | }; | |
548 | ||
549 | static struct resource wm831x_ldo8_resources[] = { | |
550 | { | |
551 | .start = WM831X_LDO8_CONTROL, | |
552 | .end = WM831X_LDO8_SLEEP_CONTROL, | |
553 | .flags = IORESOURCE_IO, | |
554 | }, | |
555 | { | |
556 | .name = "UV", | |
557 | .start = WM831X_IRQ_UV_LDO8, | |
558 | .end = WM831X_IRQ_UV_LDO8, | |
559 | .flags = IORESOURCE_IRQ, | |
560 | }, | |
561 | }; | |
562 | ||
563 | static struct resource wm831x_ldo9_resources[] = { | |
564 | { | |
565 | .start = WM831X_LDO9_CONTROL, | |
566 | .end = WM831X_LDO9_SLEEP_CONTROL, | |
567 | .flags = IORESOURCE_IO, | |
568 | }, | |
569 | { | |
570 | .name = "UV", | |
571 | .start = WM831X_IRQ_UV_LDO9, | |
572 | .end = WM831X_IRQ_UV_LDO9, | |
573 | .flags = IORESOURCE_IRQ, | |
574 | }, | |
575 | }; | |
576 | ||
577 | static struct resource wm831x_ldo10_resources[] = { | |
578 | { | |
579 | .start = WM831X_LDO10_CONTROL, | |
580 | .end = WM831X_LDO10_SLEEP_CONTROL, | |
581 | .flags = IORESOURCE_IO, | |
582 | }, | |
583 | { | |
584 | .name = "UV", | |
585 | .start = WM831X_IRQ_UV_LDO10, | |
586 | .end = WM831X_IRQ_UV_LDO10, | |
587 | .flags = IORESOURCE_IRQ, | |
588 | }, | |
589 | }; | |
590 | ||
591 | static struct resource wm831x_ldo11_resources[] = { | |
592 | { | |
593 | .start = WM831X_LDO11_ON_CONTROL, | |
594 | .end = WM831X_LDO11_SLEEP_CONTROL, | |
595 | .flags = IORESOURCE_IO, | |
596 | }, | |
597 | }; | |
598 | ||
599 | static struct resource wm831x_on_resources[] = { | |
600 | { | |
601 | .start = WM831X_IRQ_ON, | |
602 | .end = WM831X_IRQ_ON, | |
603 | .flags = IORESOURCE_IRQ, | |
604 | }, | |
605 | }; | |
606 | ||
607 | ||
608 | static struct resource wm831x_power_resources[] = { | |
609 | { | |
610 | .name = "SYSLO", | |
611 | .start = WM831X_IRQ_PPM_SYSLO, | |
612 | .end = WM831X_IRQ_PPM_SYSLO, | |
613 | .flags = IORESOURCE_IRQ, | |
614 | }, | |
615 | { | |
616 | .name = "PWR SRC", | |
617 | .start = WM831X_IRQ_PPM_PWR_SRC, | |
618 | .end = WM831X_IRQ_PPM_PWR_SRC, | |
619 | .flags = IORESOURCE_IRQ, | |
620 | }, | |
621 | { | |
622 | .name = "USB CURR", | |
623 | .start = WM831X_IRQ_PPM_USB_CURR, | |
624 | .end = WM831X_IRQ_PPM_USB_CURR, | |
625 | .flags = IORESOURCE_IRQ, | |
626 | }, | |
627 | { | |
628 | .name = "BATT HOT", | |
629 | .start = WM831X_IRQ_CHG_BATT_HOT, | |
630 | .end = WM831X_IRQ_CHG_BATT_HOT, | |
631 | .flags = IORESOURCE_IRQ, | |
632 | }, | |
633 | { | |
634 | .name = "BATT COLD", | |
635 | .start = WM831X_IRQ_CHG_BATT_COLD, | |
636 | .end = WM831X_IRQ_CHG_BATT_COLD, | |
637 | .flags = IORESOURCE_IRQ, | |
638 | }, | |
639 | { | |
640 | .name = "BATT FAIL", | |
641 | .start = WM831X_IRQ_CHG_BATT_FAIL, | |
642 | .end = WM831X_IRQ_CHG_BATT_FAIL, | |
643 | .flags = IORESOURCE_IRQ, | |
644 | }, | |
645 | { | |
646 | .name = "OV", | |
647 | .start = WM831X_IRQ_CHG_OV, | |
648 | .end = WM831X_IRQ_CHG_OV, | |
649 | .flags = IORESOURCE_IRQ, | |
650 | }, | |
651 | { | |
652 | .name = "END", | |
653 | .start = WM831X_IRQ_CHG_END, | |
654 | .end = WM831X_IRQ_CHG_END, | |
655 | .flags = IORESOURCE_IRQ, | |
656 | }, | |
657 | { | |
658 | .name = "TO", | |
659 | .start = WM831X_IRQ_CHG_TO, | |
660 | .end = WM831X_IRQ_CHG_TO, | |
661 | .flags = IORESOURCE_IRQ, | |
662 | }, | |
663 | { | |
664 | .name = "MODE", | |
665 | .start = WM831X_IRQ_CHG_MODE, | |
666 | .end = WM831X_IRQ_CHG_MODE, | |
667 | .flags = IORESOURCE_IRQ, | |
668 | }, | |
669 | { | |
670 | .name = "START", | |
671 | .start = WM831X_IRQ_CHG_START, | |
672 | .end = WM831X_IRQ_CHG_START, | |
673 | .flags = IORESOURCE_IRQ, | |
674 | }, | |
675 | }; | |
676 | ||
677 | static struct resource wm831x_rtc_resources[] = { | |
678 | { | |
679 | .name = "PER", | |
680 | .start = WM831X_IRQ_RTC_PER, | |
681 | .end = WM831X_IRQ_RTC_PER, | |
682 | .flags = IORESOURCE_IRQ, | |
683 | }, | |
684 | { | |
685 | .name = "ALM", | |
686 | .start = WM831X_IRQ_RTC_ALM, | |
687 | .end = WM831X_IRQ_RTC_ALM, | |
688 | .flags = IORESOURCE_IRQ, | |
689 | }, | |
690 | }; | |
691 | ||
692 | static struct resource wm831x_status1_resources[] = { | |
693 | { | |
694 | .start = WM831X_STATUS_LED_1, | |
695 | .end = WM831X_STATUS_LED_1, | |
696 | .flags = IORESOURCE_IO, | |
697 | }, | |
698 | }; | |
699 | ||
700 | static struct resource wm831x_status2_resources[] = { | |
701 | { | |
702 | .start = WM831X_STATUS_LED_2, | |
703 | .end = WM831X_STATUS_LED_2, | |
704 | .flags = IORESOURCE_IO, | |
705 | }, | |
706 | }; | |
707 | ||
708 | static struct resource wm831x_touch_resources[] = { | |
709 | { | |
710 | .name = "TCHPD", | |
711 | .start = WM831X_IRQ_TCHPD, | |
712 | .end = WM831X_IRQ_TCHPD, | |
713 | .flags = IORESOURCE_IRQ, | |
714 | }, | |
715 | { | |
716 | .name = "TCHDATA", | |
717 | .start = WM831X_IRQ_TCHDATA, | |
718 | .end = WM831X_IRQ_TCHDATA, | |
719 | .flags = IORESOURCE_IRQ, | |
720 | }, | |
721 | }; | |
722 | ||
723 | static struct resource wm831x_wdt_resources[] = { | |
724 | { | |
725 | .start = WM831X_IRQ_WDOG_TO, | |
726 | .end = WM831X_IRQ_WDOG_TO, | |
727 | .flags = IORESOURCE_IRQ, | |
728 | }, | |
729 | }; | |
730 | ||
731 | static struct mfd_cell wm8310_devs[] = { | |
732 | { | |
733 | .name = "wm831x-buckv", | |
734 | .id = 1, | |
735 | .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), | |
736 | .resources = wm831x_dcdc1_resources, | |
737 | }, | |
738 | { | |
739 | .name = "wm831x-buckv", | |
740 | .id = 2, | |
741 | .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), | |
742 | .resources = wm831x_dcdc2_resources, | |
743 | }, | |
744 | { | |
745 | .name = "wm831x-buckp", | |
746 | .id = 3, | |
747 | .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), | |
748 | .resources = wm831x_dcdc3_resources, | |
749 | }, | |
750 | { | |
751 | .name = "wm831x-boostp", | |
752 | .id = 4, | |
753 | .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), | |
754 | .resources = wm831x_dcdc4_resources, | |
755 | }, | |
756 | { | |
757 | .name = "wm831x-epe", | |
758 | .id = 1, | |
759 | }, | |
760 | { | |
761 | .name = "wm831x-epe", | |
762 | .id = 2, | |
763 | }, | |
764 | { | |
765 | .name = "wm831x-gpio", | |
766 | .num_resources = ARRAY_SIZE(wm831x_gpio_resources), | |
767 | .resources = wm831x_gpio_resources, | |
768 | }, | |
769 | { | |
770 | .name = "wm831x-hwmon", | |
771 | }, | |
772 | { | |
773 | .name = "wm831x-isink", | |
774 | .id = 1, | |
775 | .num_resources = ARRAY_SIZE(wm831x_isink1_resources), | |
776 | .resources = wm831x_isink1_resources, | |
777 | }, | |
778 | { | |
779 | .name = "wm831x-isink", | |
780 | .id = 2, | |
781 | .num_resources = ARRAY_SIZE(wm831x_isink2_resources), | |
782 | .resources = wm831x_isink2_resources, | |
783 | }, | |
784 | { | |
785 | .name = "wm831x-ldo", | |
786 | .id = 1, | |
787 | .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), | |
788 | .resources = wm831x_ldo1_resources, | |
789 | }, | |
790 | { | |
791 | .name = "wm831x-ldo", | |
792 | .id = 2, | |
793 | .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), | |
794 | .resources = wm831x_ldo2_resources, | |
795 | }, | |
796 | { | |
797 | .name = "wm831x-ldo", | |
798 | .id = 3, | |
799 | .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), | |
800 | .resources = wm831x_ldo3_resources, | |
801 | }, | |
802 | { | |
803 | .name = "wm831x-ldo", | |
804 | .id = 4, | |
805 | .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), | |
806 | .resources = wm831x_ldo4_resources, | |
807 | }, | |
808 | { | |
809 | .name = "wm831x-ldo", | |
810 | .id = 5, | |
811 | .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), | |
812 | .resources = wm831x_ldo5_resources, | |
813 | }, | |
814 | { | |
815 | .name = "wm831x-ldo", | |
816 | .id = 6, | |
817 | .num_resources = ARRAY_SIZE(wm831x_ldo6_resources), | |
818 | .resources = wm831x_ldo6_resources, | |
819 | }, | |
820 | { | |
821 | .name = "wm831x-aldo", | |
822 | .id = 7, | |
823 | .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), | |
824 | .resources = wm831x_ldo7_resources, | |
825 | }, | |
826 | { | |
827 | .name = "wm831x-aldo", | |
828 | .id = 8, | |
829 | .num_resources = ARRAY_SIZE(wm831x_ldo8_resources), | |
830 | .resources = wm831x_ldo8_resources, | |
831 | }, | |
832 | { | |
833 | .name = "wm831x-aldo", | |
834 | .id = 9, | |
835 | .num_resources = ARRAY_SIZE(wm831x_ldo9_resources), | |
836 | .resources = wm831x_ldo9_resources, | |
837 | }, | |
838 | { | |
839 | .name = "wm831x-aldo", | |
840 | .id = 10, | |
841 | .num_resources = ARRAY_SIZE(wm831x_ldo10_resources), | |
842 | .resources = wm831x_ldo10_resources, | |
843 | }, | |
844 | { | |
845 | .name = "wm831x-alive-ldo", | |
846 | .id = 11, | |
847 | .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), | |
848 | .resources = wm831x_ldo11_resources, | |
849 | }, | |
850 | { | |
851 | .name = "wm831x-on", | |
852 | .num_resources = ARRAY_SIZE(wm831x_on_resources), | |
853 | .resources = wm831x_on_resources, | |
854 | }, | |
855 | { | |
856 | .name = "wm831x-power", | |
857 | .num_resources = ARRAY_SIZE(wm831x_power_resources), | |
858 | .resources = wm831x_power_resources, | |
859 | }, | |
860 | { | |
861 | .name = "wm831x-rtc", | |
862 | .num_resources = ARRAY_SIZE(wm831x_rtc_resources), | |
863 | .resources = wm831x_rtc_resources, | |
864 | }, | |
865 | { | |
866 | .name = "wm831x-status", | |
867 | .id = 1, | |
868 | .num_resources = ARRAY_SIZE(wm831x_status1_resources), | |
869 | .resources = wm831x_status1_resources, | |
870 | }, | |
871 | { | |
872 | .name = "wm831x-status", | |
873 | .id = 2, | |
874 | .num_resources = ARRAY_SIZE(wm831x_status2_resources), | |
875 | .resources = wm831x_status2_resources, | |
876 | }, | |
877 | { | |
878 | .name = "wm831x-watchdog", | |
879 | .num_resources = ARRAY_SIZE(wm831x_wdt_resources), | |
880 | .resources = wm831x_wdt_resources, | |
881 | }, | |
882 | }; | |
883 | ||
884 | static struct mfd_cell wm8311_devs[] = { | |
885 | { | |
886 | .name = "wm831x-buckv", | |
887 | .id = 1, | |
888 | .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), | |
889 | .resources = wm831x_dcdc1_resources, | |
890 | }, | |
891 | { | |
892 | .name = "wm831x-buckv", | |
893 | .id = 2, | |
894 | .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), | |
895 | .resources = wm831x_dcdc2_resources, | |
896 | }, | |
897 | { | |
898 | .name = "wm831x-buckp", | |
899 | .id = 3, | |
900 | .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), | |
901 | .resources = wm831x_dcdc3_resources, | |
902 | }, | |
903 | { | |
904 | .name = "wm831x-boostp", | |
905 | .id = 4, | |
906 | .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), | |
907 | .resources = wm831x_dcdc4_resources, | |
908 | }, | |
909 | { | |
910 | .name = "wm831x-epe", | |
911 | .id = 1, | |
912 | }, | |
913 | { | |
914 | .name = "wm831x-epe", | |
915 | .id = 2, | |
916 | }, | |
917 | { | |
918 | .name = "wm831x-gpio", | |
919 | .num_resources = ARRAY_SIZE(wm831x_gpio_resources), | |
920 | .resources = wm831x_gpio_resources, | |
921 | }, | |
922 | { | |
923 | .name = "wm831x-hwmon", | |
924 | }, | |
925 | { | |
926 | .name = "wm831x-isink", | |
927 | .id = 1, | |
928 | .num_resources = ARRAY_SIZE(wm831x_isink1_resources), | |
929 | .resources = wm831x_isink1_resources, | |
930 | }, | |
931 | { | |
932 | .name = "wm831x-isink", | |
933 | .id = 2, | |
934 | .num_resources = ARRAY_SIZE(wm831x_isink2_resources), | |
935 | .resources = wm831x_isink2_resources, | |
936 | }, | |
937 | { | |
938 | .name = "wm831x-ldo", | |
939 | .id = 1, | |
940 | .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), | |
941 | .resources = wm831x_ldo1_resources, | |
942 | }, | |
943 | { | |
944 | .name = "wm831x-ldo", | |
945 | .id = 2, | |
946 | .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), | |
947 | .resources = wm831x_ldo2_resources, | |
948 | }, | |
949 | { | |
950 | .name = "wm831x-ldo", | |
951 | .id = 3, | |
952 | .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), | |
953 | .resources = wm831x_ldo3_resources, | |
954 | }, | |
955 | { | |
956 | .name = "wm831x-ldo", | |
957 | .id = 4, | |
958 | .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), | |
959 | .resources = wm831x_ldo4_resources, | |
960 | }, | |
961 | { | |
962 | .name = "wm831x-ldo", | |
963 | .id = 5, | |
964 | .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), | |
965 | .resources = wm831x_ldo5_resources, | |
966 | }, | |
967 | { | |
968 | .name = "wm831x-aldo", | |
969 | .id = 7, | |
970 | .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), | |
971 | .resources = wm831x_ldo7_resources, | |
972 | }, | |
973 | { | |
974 | .name = "wm831x-alive-ldo", | |
975 | .id = 11, | |
976 | .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), | |
977 | .resources = wm831x_ldo11_resources, | |
978 | }, | |
979 | { | |
980 | .name = "wm831x-on", | |
981 | .num_resources = ARRAY_SIZE(wm831x_on_resources), | |
982 | .resources = wm831x_on_resources, | |
983 | }, | |
984 | { | |
985 | .name = "wm831x-power", | |
986 | .num_resources = ARRAY_SIZE(wm831x_power_resources), | |
987 | .resources = wm831x_power_resources, | |
988 | }, | |
989 | { | |
990 | .name = "wm831x-rtc", | |
991 | .num_resources = ARRAY_SIZE(wm831x_rtc_resources), | |
992 | .resources = wm831x_rtc_resources, | |
993 | }, | |
994 | { | |
995 | .name = "wm831x-status", | |
996 | .id = 1, | |
997 | .num_resources = ARRAY_SIZE(wm831x_status1_resources), | |
998 | .resources = wm831x_status1_resources, | |
999 | }, | |
1000 | { | |
1001 | .name = "wm831x-status", | |
1002 | .id = 2, | |
1003 | .num_resources = ARRAY_SIZE(wm831x_status2_resources), | |
1004 | .resources = wm831x_status2_resources, | |
1005 | }, | |
1006 | { | |
1007 | .name = "wm831x-touch", | |
1008 | .num_resources = ARRAY_SIZE(wm831x_touch_resources), | |
1009 | .resources = wm831x_touch_resources, | |
1010 | }, | |
1011 | { | |
1012 | .name = "wm831x-watchdog", | |
1013 | .num_resources = ARRAY_SIZE(wm831x_wdt_resources), | |
1014 | .resources = wm831x_wdt_resources, | |
1015 | }, | |
1016 | }; | |
1017 | ||
1018 | static struct mfd_cell wm8312_devs[] = { | |
1019 | { | |
1020 | .name = "wm831x-buckv", | |
1021 | .id = 1, | |
1022 | .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), | |
1023 | .resources = wm831x_dcdc1_resources, | |
1024 | }, | |
1025 | { | |
1026 | .name = "wm831x-buckv", | |
1027 | .id = 2, | |
1028 | .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), | |
1029 | .resources = wm831x_dcdc2_resources, | |
1030 | }, | |
1031 | { | |
1032 | .name = "wm831x-buckp", | |
1033 | .id = 3, | |
1034 | .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), | |
1035 | .resources = wm831x_dcdc3_resources, | |
1036 | }, | |
1037 | { | |
1038 | .name = "wm831x-boostp", | |
1039 | .id = 4, | |
1040 | .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), | |
1041 | .resources = wm831x_dcdc4_resources, | |
1042 | }, | |
1043 | { | |
1044 | .name = "wm831x-epe", | |
1045 | .id = 1, | |
1046 | }, | |
1047 | { | |
1048 | .name = "wm831x-epe", | |
1049 | .id = 2, | |
1050 | }, | |
1051 | { | |
1052 | .name = "wm831x-gpio", | |
1053 | .num_resources = ARRAY_SIZE(wm831x_gpio_resources), | |
1054 | .resources = wm831x_gpio_resources, | |
1055 | }, | |
1056 | { | |
1057 | .name = "wm831x-hwmon", | |
1058 | }, | |
1059 | { | |
1060 | .name = "wm831x-isink", | |
1061 | .id = 1, | |
1062 | .num_resources = ARRAY_SIZE(wm831x_isink1_resources), | |
1063 | .resources = wm831x_isink1_resources, | |
1064 | }, | |
1065 | { | |
1066 | .name = "wm831x-isink", | |
1067 | .id = 2, | |
1068 | .num_resources = ARRAY_SIZE(wm831x_isink2_resources), | |
1069 | .resources = wm831x_isink2_resources, | |
1070 | }, | |
1071 | { | |
1072 | .name = "wm831x-ldo", | |
1073 | .id = 1, | |
1074 | .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), | |
1075 | .resources = wm831x_ldo1_resources, | |
1076 | }, | |
1077 | { | |
1078 | .name = "wm831x-ldo", | |
1079 | .id = 2, | |
1080 | .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), | |
1081 | .resources = wm831x_ldo2_resources, | |
1082 | }, | |
1083 | { | |
1084 | .name = "wm831x-ldo", | |
1085 | .id = 3, | |
1086 | .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), | |
1087 | .resources = wm831x_ldo3_resources, | |
1088 | }, | |
1089 | { | |
1090 | .name = "wm831x-ldo", | |
1091 | .id = 4, | |
1092 | .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), | |
1093 | .resources = wm831x_ldo4_resources, | |
1094 | }, | |
1095 | { | |
1096 | .name = "wm831x-ldo", | |
1097 | .id = 5, | |
1098 | .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), | |
1099 | .resources = wm831x_ldo5_resources, | |
1100 | }, | |
1101 | { | |
1102 | .name = "wm831x-ldo", | |
1103 | .id = 6, | |
1104 | .num_resources = ARRAY_SIZE(wm831x_ldo6_resources), | |
1105 | .resources = wm831x_ldo6_resources, | |
1106 | }, | |
1107 | { | |
1108 | .name = "wm831x-aldo", | |
1109 | .id = 7, | |
1110 | .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), | |
1111 | .resources = wm831x_ldo7_resources, | |
1112 | }, | |
1113 | { | |
1114 | .name = "wm831x-aldo", | |
1115 | .id = 8, | |
1116 | .num_resources = ARRAY_SIZE(wm831x_ldo8_resources), | |
1117 | .resources = wm831x_ldo8_resources, | |
1118 | }, | |
1119 | { | |
1120 | .name = "wm831x-aldo", | |
1121 | .id = 9, | |
1122 | .num_resources = ARRAY_SIZE(wm831x_ldo9_resources), | |
1123 | .resources = wm831x_ldo9_resources, | |
1124 | }, | |
1125 | { | |
1126 | .name = "wm831x-aldo", | |
1127 | .id = 10, | |
1128 | .num_resources = ARRAY_SIZE(wm831x_ldo10_resources), | |
1129 | .resources = wm831x_ldo10_resources, | |
1130 | }, | |
1131 | { | |
1132 | .name = "wm831x-alive-ldo", | |
1133 | .id = 11, | |
1134 | .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), | |
1135 | .resources = wm831x_ldo11_resources, | |
1136 | }, | |
1137 | { | |
1138 | .name = "wm831x-on", | |
1139 | .num_resources = ARRAY_SIZE(wm831x_on_resources), | |
1140 | .resources = wm831x_on_resources, | |
1141 | }, | |
1142 | { | |
1143 | .name = "wm831x-power", | |
1144 | .num_resources = ARRAY_SIZE(wm831x_power_resources), | |
1145 | .resources = wm831x_power_resources, | |
1146 | }, | |
1147 | { | |
1148 | .name = "wm831x-rtc", | |
1149 | .num_resources = ARRAY_SIZE(wm831x_rtc_resources), | |
1150 | .resources = wm831x_rtc_resources, | |
1151 | }, | |
1152 | { | |
1153 | .name = "wm831x-status", | |
1154 | .id = 1, | |
1155 | .num_resources = ARRAY_SIZE(wm831x_status1_resources), | |
1156 | .resources = wm831x_status1_resources, | |
1157 | }, | |
1158 | { | |
1159 | .name = "wm831x-status", | |
1160 | .id = 2, | |
1161 | .num_resources = ARRAY_SIZE(wm831x_status2_resources), | |
1162 | .resources = wm831x_status2_resources, | |
1163 | }, | |
1164 | { | |
1165 | .name = "wm831x-touch", | |
1166 | .num_resources = ARRAY_SIZE(wm831x_touch_resources), | |
1167 | .resources = wm831x_touch_resources, | |
1168 | }, | |
1169 | { | |
1170 | .name = "wm831x-watchdog", | |
1171 | .num_resources = ARRAY_SIZE(wm831x_wdt_resources), | |
1172 | .resources = wm831x_wdt_resources, | |
1173 | }, | |
1174 | }; | |
1175 | ||
63aed85e MB |
1176 | static struct mfd_cell backlight_devs[] = { |
1177 | { | |
1178 | .name = "wm831x-backlight", | |
1179 | }, | |
1180 | }; | |
1181 | ||
d2bedfe7 MB |
1182 | /* |
1183 | * Instantiate the generic non-control parts of the device. | |
1184 | */ | |
1185 | static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |
1186 | { | |
1187 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | |
1188 | int rev; | |
1189 | enum wm831x_parent parent; | |
1190 | int ret; | |
1191 | ||
1192 | mutex_init(&wm831x->io_lock); | |
1193 | mutex_init(&wm831x->key_lock); | |
7e9f9fd4 | 1194 | mutex_init(&wm831x->auxadc_lock); |
d2bedfe7 MB |
1195 | dev_set_drvdata(wm831x->dev, wm831x); |
1196 | ||
1197 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); | |
1198 | if (ret < 0) { | |
1199 | dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); | |
1200 | goto err; | |
1201 | } | |
1202 | if (ret != 0x6204) { | |
1203 | dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); | |
1204 | ret = -EINVAL; | |
1205 | goto err; | |
1206 | } | |
1207 | ||
1208 | ret = wm831x_reg_read(wm831x, WM831X_REVISION); | |
1209 | if (ret < 0) { | |
1210 | dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); | |
1211 | goto err; | |
1212 | } | |
1213 | rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; | |
1214 | ||
1215 | ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); | |
1216 | if (ret < 0) { | |
1217 | dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); | |
1218 | goto err; | |
1219 | } | |
1220 | ||
1221 | switch (ret) { | |
1222 | case 0x8310: | |
1223 | parent = WM8310; | |
1224 | switch (rev) { | |
1225 | case 0: | |
1226 | dev_info(wm831x->dev, "WM8310 revision %c\n", | |
1227 | 'A' + rev); | |
1228 | break; | |
1229 | } | |
1230 | break; | |
1231 | ||
1232 | case 0x8311: | |
1233 | parent = WM8311; | |
1234 | switch (rev) { | |
1235 | case 0: | |
1236 | dev_info(wm831x->dev, "WM8311 revision %c\n", | |
1237 | 'A' + rev); | |
1238 | break; | |
1239 | } | |
1240 | break; | |
1241 | ||
1242 | case 0x8312: | |
1243 | parent = WM8312; | |
1244 | switch (rev) { | |
1245 | case 0: | |
1246 | dev_info(wm831x->dev, "WM8312 revision %c\n", | |
1247 | 'A' + rev); | |
1248 | break; | |
1249 | } | |
1250 | break; | |
1251 | ||
1252 | case 0: | |
1253 | /* Some engineering samples do not have the ID set, | |
1254 | * rely on the device being registered correctly. | |
1255 | * This will need revisiting for future devices with | |
1256 | * multiple dies. | |
1257 | */ | |
1258 | parent = id; | |
1259 | switch (rev) { | |
1260 | case 0: | |
1261 | dev_info(wm831x->dev, "WM831%d ES revision %c\n", | |
1262 | parent, 'A' + rev); | |
1263 | break; | |
1264 | } | |
1265 | break; | |
1266 | ||
1267 | default: | |
1268 | dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); | |
1269 | ret = -EINVAL; | |
1270 | goto err; | |
1271 | } | |
1272 | ||
1273 | /* This will need revisiting in future but is OK for all | |
1274 | * current parts. | |
1275 | */ | |
1276 | if (parent != id) | |
1277 | dev_warn(wm831x->dev, "Device was registered as a WM831%lu\n", | |
1278 | id); | |
1279 | ||
1280 | /* Bootstrap the user key */ | |
1281 | ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); | |
1282 | if (ret < 0) { | |
1283 | dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); | |
1284 | goto err; | |
1285 | } | |
1286 | if (ret != 0) { | |
1287 | dev_warn(wm831x->dev, "Security key had non-zero value %x\n", | |
1288 | ret); | |
1289 | wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0); | |
1290 | } | |
1291 | wm831x->locked = 1; | |
1292 | ||
1293 | if (pdata && pdata->pre_init) { | |
1294 | ret = pdata->pre_init(wm831x); | |
1295 | if (ret != 0) { | |
1296 | dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); | |
1297 | goto err; | |
1298 | } | |
1299 | } | |
1300 | ||
7d4d0a3e MB |
1301 | ret = wm831x_irq_init(wm831x, irq); |
1302 | if (ret != 0) | |
1303 | goto err; | |
1304 | ||
d2bedfe7 MB |
1305 | /* The core device is up, instantiate the subdevices. */ |
1306 | switch (parent) { | |
1307 | case WM8310: | |
1308 | ret = mfd_add_devices(wm831x->dev, -1, | |
1309 | wm8310_devs, ARRAY_SIZE(wm8310_devs), | |
1310 | NULL, 0); | |
1311 | break; | |
1312 | ||
1313 | case WM8311: | |
1314 | ret = mfd_add_devices(wm831x->dev, -1, | |
1315 | wm8311_devs, ARRAY_SIZE(wm8311_devs), | |
1316 | NULL, 0); | |
1317 | break; | |
1318 | ||
1319 | case WM8312: | |
1320 | ret = mfd_add_devices(wm831x->dev, -1, | |
1321 | wm8312_devs, ARRAY_SIZE(wm8312_devs), | |
1322 | NULL, 0); | |
1323 | break; | |
1324 | ||
1325 | default: | |
1326 | /* If this happens the bus probe function is buggy */ | |
1327 | BUG(); | |
1328 | } | |
1329 | ||
1330 | if (ret != 0) { | |
1331 | dev_err(wm831x->dev, "Failed to add children\n"); | |
7d4d0a3e | 1332 | goto err_irq; |
d2bedfe7 MB |
1333 | } |
1334 | ||
63aed85e MB |
1335 | if (pdata && pdata->backlight) { |
1336 | /* Treat errors as non-critical */ | |
1337 | ret = mfd_add_devices(wm831x->dev, -1, backlight_devs, | |
1338 | ARRAY_SIZE(backlight_devs), NULL, 0); | |
1339 | if (ret < 0) | |
1340 | dev_err(wm831x->dev, "Failed to add backlight: %d\n", | |
1341 | ret); | |
1342 | } | |
1343 | ||
6704e517 MB |
1344 | wm831x_otp_init(wm831x); |
1345 | ||
d2bedfe7 MB |
1346 | if (pdata && pdata->post_init) { |
1347 | ret = pdata->post_init(wm831x); | |
1348 | if (ret != 0) { | |
1349 | dev_err(wm831x->dev, "post_init() failed: %d\n", ret); | |
7d4d0a3e | 1350 | goto err_irq; |
d2bedfe7 MB |
1351 | } |
1352 | } | |
1353 | ||
1354 | return 0; | |
1355 | ||
7d4d0a3e MB |
1356 | err_irq: |
1357 | wm831x_irq_exit(wm831x); | |
d2bedfe7 MB |
1358 | err: |
1359 | mfd_remove_devices(wm831x->dev); | |
1360 | kfree(wm831x); | |
1361 | return ret; | |
1362 | } | |
1363 | ||
1364 | static void wm831x_device_exit(struct wm831x *wm831x) | |
1365 | { | |
6704e517 | 1366 | wm831x_otp_exit(wm831x); |
d2bedfe7 | 1367 | mfd_remove_devices(wm831x->dev); |
7d4d0a3e | 1368 | wm831x_irq_exit(wm831x); |
d2bedfe7 MB |
1369 | kfree(wm831x); |
1370 | } | |
1371 | ||
1372 | static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, | |
1373 | int bytes, void *dest) | |
1374 | { | |
1375 | struct i2c_client *i2c = wm831x->control_data; | |
1376 | int ret; | |
1377 | u16 r = cpu_to_be16(reg); | |
1378 | ||
1379 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | |
1380 | if (ret < 0) | |
1381 | return ret; | |
1382 | if (ret != 2) | |
1383 | return -EIO; | |
1384 | ||
1385 | ret = i2c_master_recv(i2c, dest, bytes); | |
1386 | if (ret < 0) | |
1387 | return ret; | |
1388 | if (ret != bytes) | |
1389 | return -EIO; | |
1390 | return 0; | |
1391 | } | |
1392 | ||
1393 | /* Currently we allocate the write buffer on the stack; this is OK for | |
1394 | * small writes - if we need to do large writes this will need to be | |
1395 | * revised. | |
1396 | */ | |
1397 | static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg, | |
1398 | int bytes, void *src) | |
1399 | { | |
1400 | struct i2c_client *i2c = wm831x->control_data; | |
1401 | unsigned char msg[bytes + 2]; | |
1402 | int ret; | |
1403 | ||
1404 | reg = cpu_to_be16(reg); | |
1405 | memcpy(&msg[0], ®, 2); | |
1406 | memcpy(&msg[2], src, bytes); | |
1407 | ||
1408 | ret = i2c_master_send(i2c, msg, bytes + 2); | |
1409 | if (ret < 0) | |
1410 | return ret; | |
1411 | if (ret < bytes + 2) | |
1412 | return -EIO; | |
1413 | ||
1414 | return 0; | |
1415 | } | |
1416 | ||
1417 | static int wm831x_i2c_probe(struct i2c_client *i2c, | |
1418 | const struct i2c_device_id *id) | |
1419 | { | |
1420 | struct wm831x *wm831x; | |
1421 | ||
1422 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | |
1423 | if (wm831x == NULL) { | |
1424 | kfree(i2c); | |
1425 | return -ENOMEM; | |
1426 | } | |
1427 | ||
1428 | i2c_set_clientdata(i2c, wm831x); | |
1429 | wm831x->dev = &i2c->dev; | |
1430 | wm831x->control_data = i2c; | |
1431 | wm831x->read_dev = wm831x_i2c_read_device; | |
1432 | wm831x->write_dev = wm831x_i2c_write_device; | |
1433 | ||
1434 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); | |
1435 | } | |
1436 | ||
1437 | static int wm831x_i2c_remove(struct i2c_client *i2c) | |
1438 | { | |
1439 | struct wm831x *wm831x = i2c_get_clientdata(i2c); | |
1440 | ||
1441 | wm831x_device_exit(wm831x); | |
1442 | ||
1443 | return 0; | |
1444 | } | |
1445 | ||
1446 | static const struct i2c_device_id wm831x_i2c_id[] = { | |
1447 | { "wm8310", WM8310 }, | |
1448 | { "wm8311", WM8311 }, | |
1449 | { "wm8312", WM8312 }, | |
1450 | { } | |
1451 | }; | |
1452 | MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); | |
1453 | ||
1454 | ||
1455 | static struct i2c_driver wm831x_i2c_driver = { | |
1456 | .driver = { | |
1457 | .name = "wm831x", | |
1458 | .owner = THIS_MODULE, | |
1459 | }, | |
1460 | .probe = wm831x_i2c_probe, | |
1461 | .remove = wm831x_i2c_remove, | |
1462 | .id_table = wm831x_i2c_id, | |
1463 | }; | |
1464 | ||
1465 | static int __init wm831x_i2c_init(void) | |
1466 | { | |
1467 | int ret; | |
1468 | ||
1469 | ret = i2c_add_driver(&wm831x_i2c_driver); | |
1470 | if (ret != 0) | |
1471 | pr_err("Failed to register wm831x I2C driver: %d\n", ret); | |
1472 | ||
1473 | return ret; | |
1474 | } | |
1475 | subsys_initcall(wm831x_i2c_init); | |
1476 | ||
1477 | static void __exit wm831x_i2c_exit(void) | |
1478 | { | |
1479 | i2c_del_driver(&wm831x_i2c_driver); | |
1480 | } | |
1481 | module_exit(wm831x_i2c_exit); | |
1482 | ||
1483 | MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC"); | |
1484 | MODULE_LICENSE("GPL"); | |
1485 | MODULE_AUTHOR("Mark Brown"); |