diff options
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/Kconfig | 3 | ||||
-rw-r--r-- | drivers/mfd/menelaus.c | 2 | ||||
-rw-r--r-- | drivers/mfd/twl6040-core.c | 67 | ||||
-rw-r--r-- | drivers/mfd/wm831x-core.c | 426 | ||||
-rw-r--r-- | drivers/mfd/wm831x-i2c.c | 68 | ||||
-rw-r--r-- | drivers/mfd/wm831x-spi.c | 196 | ||||
-rw-r--r-- | drivers/mfd/wm8400-core.c | 106 | ||||
-rw-r--r-- | drivers/mfd/wm8994-core.c | 205 |
8 files changed, 551 insertions, 522 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 74d4893a8f21..f1391c21ef26 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -390,6 +390,7 @@ config MFD_WM831X_I2C | |||
390 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C" | 390 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C" |
391 | select MFD_CORE | 391 | select MFD_CORE |
392 | select MFD_WM831X | 392 | select MFD_WM831X |
393 | select REGMAP_I2C | ||
393 | depends on I2C=y && GENERIC_HARDIRQS | 394 | depends on I2C=y && GENERIC_HARDIRQS |
394 | help | 395 | help |
395 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs | 396 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs |
@@ -401,6 +402,7 @@ config MFD_WM831X_SPI | |||
401 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI" | 402 | bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI" |
402 | select MFD_CORE | 403 | select MFD_CORE |
403 | select MFD_WM831X | 404 | select MFD_WM831X |
405 | select REGMAP_SPI | ||
404 | depends on SPI_MASTER && GENERIC_HARDIRQS | 406 | depends on SPI_MASTER && GENERIC_HARDIRQS |
405 | help | 407 | help |
406 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs | 408 | Support for the Wolfson Microelecronics WM831x and WM832x PMICs |
@@ -474,6 +476,7 @@ config MFD_WM8350_I2C | |||
474 | config MFD_WM8994 | 476 | config MFD_WM8994 |
475 | bool "Support Wolfson Microelectronics WM8994" | 477 | bool "Support Wolfson Microelectronics WM8994" |
476 | select MFD_CORE | 478 | select MFD_CORE |
479 | select REGMAP_I2C | ||
477 | depends on I2C=y && GENERIC_HARDIRQS | 480 | depends on I2C=y && GENERIC_HARDIRQS |
478 | help | 481 | help |
479 | The WM8994 is a highly integrated hi-fi CODEC designed for | 482 | The WM8994 is a highly integrated hi-fi CODEC designed for |
diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c index ded870e22155..cb4910ac4d12 100644 --- a/drivers/mfd/menelaus.c +++ b/drivers/mfd/menelaus.c | |||
@@ -44,7 +44,7 @@ | |||
44 | 44 | ||
45 | #include <asm/mach/irq.h> | 45 | #include <asm/mach/irq.h> |
46 | 46 | ||
47 | #include <mach/gpio.h> | 47 | #include <asm/gpio.h> |
48 | #include <plat/menelaus.h> | 48 | #include <plat/menelaus.h> |
49 | 49 | ||
50 | #define DRIVER_NAME "menelaus" | 50 | #define DRIVER_NAME "menelaus" |
diff --git a/drivers/mfd/twl6040-core.c b/drivers/mfd/twl6040-core.c index 24d436c2fe4a..268f80fd0439 100644 --- a/drivers/mfd/twl6040-core.c +++ b/drivers/mfd/twl6040-core.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include <linux/mfd/core.h> | 34 | #include <linux/mfd/core.h> |
35 | #include <linux/mfd/twl6040.h> | 35 | #include <linux/mfd/twl6040.h> |
36 | 36 | ||
37 | static struct platform_device *twl6040_dev; | 37 | #define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1) |
38 | 38 | ||
39 | int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg) | 39 | int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg) |
40 | { | 40 | { |
@@ -42,10 +42,16 @@ int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg) | |||
42 | u8 val = 0; | 42 | u8 val = 0; |
43 | 43 | ||
44 | mutex_lock(&twl6040->io_mutex); | 44 | mutex_lock(&twl6040->io_mutex); |
45 | ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg); | 45 | /* Vibra control registers from cache */ |
46 | if (ret < 0) { | 46 | if (unlikely(reg == TWL6040_REG_VIBCTLL || |
47 | mutex_unlock(&twl6040->io_mutex); | 47 | reg == TWL6040_REG_VIBCTLR)) { |
48 | return ret; | 48 | val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)]; |
49 | } else { | ||
50 | ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg); | ||
51 | if (ret < 0) { | ||
52 | mutex_unlock(&twl6040->io_mutex); | ||
53 | return ret; | ||
54 | } | ||
49 | } | 55 | } |
50 | mutex_unlock(&twl6040->io_mutex); | 56 | mutex_unlock(&twl6040->io_mutex); |
51 | 57 | ||
@@ -59,6 +65,9 @@ int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) | |||
59 | 65 | ||
60 | mutex_lock(&twl6040->io_mutex); | 66 | mutex_lock(&twl6040->io_mutex); |
61 | ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg); | 67 | ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg); |
68 | /* Cache the vibra control registers */ | ||
69 | if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR) | ||
70 | twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val; | ||
62 | mutex_unlock(&twl6040->io_mutex); | 71 | mutex_unlock(&twl6040->io_mutex); |
63 | 72 | ||
64 | return ret; | 73 | return ret; |
@@ -203,11 +212,11 @@ static irqreturn_t twl6040_naudint_handler(int irq, void *data) | |||
203 | if (intid & TWL6040_THINT) { | 212 | if (intid & TWL6040_THINT) { |
204 | status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); | 213 | status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); |
205 | if (status & TWL6040_TSHUTDET) { | 214 | if (status & TWL6040_TSHUTDET) { |
206 | dev_warn(&twl6040_dev->dev, | 215 | dev_warn(twl6040->dev, |
207 | "Thermal shutdown, powering-off"); | 216 | "Thermal shutdown, powering-off"); |
208 | twl6040_power(twl6040, 0); | 217 | twl6040_power(twl6040, 0); |
209 | } else { | 218 | } else { |
210 | dev_warn(&twl6040_dev->dev, | 219 | dev_warn(twl6040->dev, |
211 | "Leaving thermal shutdown, powering-on"); | 220 | "Leaving thermal shutdown, powering-on"); |
212 | twl6040_power(twl6040, 1); | 221 | twl6040_power(twl6040, 1); |
213 | } | 222 | } |
@@ -227,7 +236,7 @@ static int twl6040_power_up_completion(struct twl6040 *twl6040, | |||
227 | if (!time_left) { | 236 | if (!time_left) { |
228 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); | 237 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); |
229 | if (!(intid & TWL6040_READYINT)) { | 238 | if (!(intid & TWL6040_READYINT)) { |
230 | dev_err(&twl6040_dev->dev, | 239 | dev_err(twl6040->dev, |
231 | "timeout waiting for READYINT\n"); | 240 | "timeout waiting for READYINT\n"); |
232 | return -ETIMEDOUT; | 241 | return -ETIMEDOUT; |
233 | } | 242 | } |
@@ -255,7 +264,7 @@ int twl6040_power(struct twl6040 *twl6040, int on) | |||
255 | /* wait for power-up completion */ | 264 | /* wait for power-up completion */ |
256 | ret = twl6040_power_up_completion(twl6040, naudint); | 265 | ret = twl6040_power_up_completion(twl6040, naudint); |
257 | if (ret) { | 266 | if (ret) { |
258 | dev_err(&twl6040_dev->dev, | 267 | dev_err(twl6040->dev, |
259 | "automatic power-down failed\n"); | 268 | "automatic power-down failed\n"); |
260 | twl6040->power_count = 0; | 269 | twl6040->power_count = 0; |
261 | goto out; | 270 | goto out; |
@@ -264,7 +273,7 @@ int twl6040_power(struct twl6040 *twl6040, int on) | |||
264 | /* use manual power-up sequence */ | 273 | /* use manual power-up sequence */ |
265 | ret = twl6040_power_up(twl6040); | 274 | ret = twl6040_power_up(twl6040); |
266 | if (ret) { | 275 | if (ret) { |
267 | dev_err(&twl6040_dev->dev, | 276 | dev_err(twl6040->dev, |
268 | "manual power-up failed\n"); | 277 | "manual power-up failed\n"); |
269 | twl6040->power_count = 0; | 278 | twl6040->power_count = 0; |
270 | goto out; | 279 | goto out; |
@@ -276,7 +285,7 @@ int twl6040_power(struct twl6040 *twl6040, int on) | |||
276 | } else { | 285 | } else { |
277 | /* already powered-down */ | 286 | /* already powered-down */ |
278 | if (!twl6040->power_count) { | 287 | if (!twl6040->power_count) { |
279 | dev_err(&twl6040_dev->dev, | 288 | dev_err(twl6040->dev, |
280 | "device is already powered-off\n"); | 289 | "device is already powered-off\n"); |
281 | ret = -EPERM; | 290 | ret = -EPERM; |
282 | goto out; | 291 | goto out; |
@@ -326,7 +335,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, | |||
326 | lppllctl &= ~TWL6040_LPLLFIN; | 335 | lppllctl &= ~TWL6040_LPLLFIN; |
327 | break; | 336 | break; |
328 | default: | 337 | default: |
329 | dev_err(&twl6040_dev->dev, | 338 | dev_err(twl6040->dev, |
330 | "freq_out %d not supported\n", freq_out); | 339 | "freq_out %d not supported\n", freq_out); |
331 | ret = -EINVAL; | 340 | ret = -EINVAL; |
332 | goto pll_out; | 341 | goto pll_out; |
@@ -347,7 +356,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, | |||
347 | hppllctl); | 356 | hppllctl); |
348 | break; | 357 | break; |
349 | default: | 358 | default: |
350 | dev_err(&twl6040_dev->dev, | 359 | dev_err(twl6040->dev, |
351 | "freq_in %d not supported\n", freq_in); | 360 | "freq_in %d not supported\n", freq_in); |
352 | ret = -EINVAL; | 361 | ret = -EINVAL; |
353 | goto pll_out; | 362 | goto pll_out; |
@@ -356,7 +365,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, | |||
356 | case TWL6040_SYSCLK_SEL_HPPLL: | 365 | case TWL6040_SYSCLK_SEL_HPPLL: |
357 | /* high-performance PLL can provide only 19.2 MHz */ | 366 | /* high-performance PLL can provide only 19.2 MHz */ |
358 | if (freq_out != 19200000) { | 367 | if (freq_out != 19200000) { |
359 | dev_err(&twl6040_dev->dev, | 368 | dev_err(twl6040->dev, |
360 | "freq_out %d not supported\n", freq_out); | 369 | "freq_out %d not supported\n", freq_out); |
361 | ret = -EINVAL; | 370 | ret = -EINVAL; |
362 | goto pll_out; | 371 | goto pll_out; |
@@ -389,7 +398,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, | |||
389 | TWL6040_HPLLENA; | 398 | TWL6040_HPLLENA; |
390 | break; | 399 | break; |
391 | default: | 400 | default: |
392 | dev_err(&twl6040_dev->dev, | 401 | dev_err(twl6040->dev, |
393 | "freq_in %d not supported\n", freq_in); | 402 | "freq_in %d not supported\n", freq_in); |
394 | ret = -EINVAL; | 403 | ret = -EINVAL; |
395 | goto pll_out; | 404 | goto pll_out; |
@@ -406,7 +415,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, | |||
406 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); | 415 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); |
407 | break; | 416 | break; |
408 | default: | 417 | default: |
409 | dev_err(&twl6040_dev->dev, "unknown pll id %d\n", pll_id); | 418 | dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); |
410 | ret = -EINVAL; | 419 | ret = -EINVAL; |
411 | goto pll_out; | 420 | goto pll_out; |
412 | } | 421 | } |
@@ -435,6 +444,18 @@ unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) | |||
435 | } | 444 | } |
436 | EXPORT_SYMBOL(twl6040_get_sysclk); | 445 | EXPORT_SYMBOL(twl6040_get_sysclk); |
437 | 446 | ||
447 | /* Get the combined status of the vibra control register */ | ||
448 | int twl6040_get_vibralr_status(struct twl6040 *twl6040) | ||
449 | { | ||
450 | u8 status; | ||
451 | |||
452 | status = twl6040->vibra_ctrl_cache[0] | twl6040->vibra_ctrl_cache[1]; | ||
453 | status &= (TWL6040_VIBENA | TWL6040_VIBSEL); | ||
454 | |||
455 | return status; | ||
456 | } | ||
457 | EXPORT_SYMBOL(twl6040_get_vibralr_status); | ||
458 | |||
438 | static struct resource twl6040_vibra_rsrc[] = { | 459 | static struct resource twl6040_vibra_rsrc[] = { |
439 | { | 460 | { |
440 | .flags = IORESOURCE_IRQ, | 461 | .flags = IORESOURCE_IRQ, |
@@ -471,9 +492,7 @@ static int __devinit twl6040_probe(struct platform_device *pdev) | |||
471 | 492 | ||
472 | platform_set_drvdata(pdev, twl6040); | 493 | platform_set_drvdata(pdev, twl6040); |
473 | 494 | ||
474 | twl6040_dev = pdev; | ||
475 | twl6040->dev = &pdev->dev; | 495 | twl6040->dev = &pdev->dev; |
476 | twl6040->audpwron = pdata->audpwron_gpio; | ||
477 | twl6040->irq = pdata->naudint_irq; | 496 | twl6040->irq = pdata->naudint_irq; |
478 | twl6040->irq_base = pdata->irq_base; | 497 | twl6040->irq_base = pdata->irq_base; |
479 | 498 | ||
@@ -483,6 +502,12 @@ static int __devinit twl6040_probe(struct platform_device *pdev) | |||
483 | 502 | ||
484 | twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); | 503 | twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); |
485 | 504 | ||
505 | /* ERRATA: Automatic power-up is not possible in ES1.0 */ | ||
506 | if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) | ||
507 | twl6040->audpwron = pdata->audpwron_gpio; | ||
508 | else | ||
509 | twl6040->audpwron = -EINVAL; | ||
510 | |||
486 | if (gpio_is_valid(twl6040->audpwron)) { | 511 | if (gpio_is_valid(twl6040->audpwron)) { |
487 | ret = gpio_request(twl6040->audpwron, "audpwron"); | 512 | ret = gpio_request(twl6040->audpwron, "audpwron"); |
488 | if (ret) | 513 | if (ret) |
@@ -493,10 +518,6 @@ static int __devinit twl6040_probe(struct platform_device *pdev) | |||
493 | goto gpio2_err; | 518 | goto gpio2_err; |
494 | } | 519 | } |
495 | 520 | ||
496 | /* ERRATA: Automatic power-up is not possible in ES1.0 */ | ||
497 | if (twl6040->rev == TWL6040_REV_ES1_0) | ||
498 | twl6040->audpwron = -EINVAL; | ||
499 | |||
500 | /* codec interrupt */ | 521 | /* codec interrupt */ |
501 | ret = twl6040_irq_init(twl6040); | 522 | ret = twl6040_irq_init(twl6040); |
502 | if (ret) | 523 | if (ret) |
@@ -566,7 +587,6 @@ gpio2_err: | |||
566 | gpio1_err: | 587 | gpio1_err: |
567 | platform_set_drvdata(pdev, NULL); | 588 | platform_set_drvdata(pdev, NULL); |
568 | kfree(twl6040); | 589 | kfree(twl6040); |
569 | twl6040_dev = NULL; | ||
570 | return ret; | 590 | return ret; |
571 | } | 591 | } |
572 | 592 | ||
@@ -586,7 +606,6 @@ static int __devexit twl6040_remove(struct platform_device *pdev) | |||
586 | mfd_remove_devices(&pdev->dev); | 606 | mfd_remove_devices(&pdev->dev); |
587 | platform_set_drvdata(pdev, NULL); | 607 | platform_set_drvdata(pdev, NULL); |
588 | kfree(twl6040); | 608 | kfree(twl6040); |
589 | twl6040_dev = NULL; | ||
590 | 609 | ||
591 | return 0; | 610 | return 0; |
592 | } | 611 | } |
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index 099b6104d150..0a2b8d41a702 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/err.h> | ||
21 | 22 | ||
22 | #include <linux/mfd/wm831x/core.h> | 23 | #include <linux/mfd/wm831x/core.h> |
23 | #include <linux/mfd/wm831x/pdata.h> | 24 | #include <linux/mfd/wm831x/pdata.h> |
@@ -161,27 +162,350 @@ int wm831x_reg_unlock(struct wm831x *wm831x) | |||
161 | } | 162 | } |
162 | EXPORT_SYMBOL_GPL(wm831x_reg_unlock); | 163 | EXPORT_SYMBOL_GPL(wm831x_reg_unlock); |
163 | 164 | ||
164 | static int wm831x_read(struct wm831x *wm831x, unsigned short reg, | 165 | static bool wm831x_reg_readable(struct device *dev, unsigned int reg) |
165 | int bytes, void *dest) | ||
166 | { | 166 | { |
167 | int ret, i; | 167 | switch (reg) { |
168 | u16 *buf = dest; | 168 | case WM831X_RESET_ID: |
169 | 169 | case WM831X_REVISION: | |
170 | BUG_ON(bytes % 2); | 170 | case WM831X_PARENT_ID: |
171 | BUG_ON(bytes <= 0); | 171 | case WM831X_SYSVDD_CONTROL: |
172 | case WM831X_THERMAL_MONITORING: | ||
173 | case WM831X_POWER_STATE: | ||
174 | case WM831X_WATCHDOG: | ||
175 | case WM831X_ON_PIN_CONTROL: | ||
176 | case WM831X_RESET_CONTROL: | ||
177 | case WM831X_CONTROL_INTERFACE: | ||
178 | case WM831X_SECURITY_KEY: | ||
179 | case WM831X_SOFTWARE_SCRATCH: | ||
180 | case WM831X_OTP_CONTROL: | ||
181 | case WM831X_GPIO_LEVEL: | ||
182 | case WM831X_SYSTEM_STATUS: | ||
183 | case WM831X_ON_SOURCE: | ||
184 | case WM831X_OFF_SOURCE: | ||
185 | case WM831X_SYSTEM_INTERRUPTS: | ||
186 | case WM831X_INTERRUPT_STATUS_1: | ||
187 | case WM831X_INTERRUPT_STATUS_2: | ||
188 | case WM831X_INTERRUPT_STATUS_3: | ||
189 | case WM831X_INTERRUPT_STATUS_4: | ||
190 | case WM831X_INTERRUPT_STATUS_5: | ||
191 | case WM831X_IRQ_CONFIG: | ||
192 | case WM831X_SYSTEM_INTERRUPTS_MASK: | ||
193 | case WM831X_INTERRUPT_STATUS_1_MASK: | ||
194 | case WM831X_INTERRUPT_STATUS_2_MASK: | ||
195 | case WM831X_INTERRUPT_STATUS_3_MASK: | ||
196 | case WM831X_INTERRUPT_STATUS_4_MASK: | ||
197 | case WM831X_INTERRUPT_STATUS_5_MASK: | ||
198 | case WM831X_RTC_WRITE_COUNTER: | ||
199 | case WM831X_RTC_TIME_1: | ||
200 | case WM831X_RTC_TIME_2: | ||
201 | case WM831X_RTC_ALARM_1: | ||
202 | case WM831X_RTC_ALARM_2: | ||
203 | case WM831X_RTC_CONTROL: | ||
204 | case WM831X_RTC_TRIM: | ||
205 | case WM831X_TOUCH_CONTROL_1: | ||
206 | case WM831X_TOUCH_CONTROL_2: | ||
207 | case WM831X_TOUCH_DATA_X: | ||
208 | case WM831X_TOUCH_DATA_Y: | ||
209 | case WM831X_TOUCH_DATA_Z: | ||
210 | case WM831X_AUXADC_DATA: | ||
211 | case WM831X_AUXADC_CONTROL: | ||
212 | case WM831X_AUXADC_SOURCE: | ||
213 | case WM831X_COMPARATOR_CONTROL: | ||
214 | case WM831X_COMPARATOR_1: | ||
215 | case WM831X_COMPARATOR_2: | ||
216 | case WM831X_COMPARATOR_3: | ||
217 | case WM831X_COMPARATOR_4: | ||
218 | case WM831X_GPIO1_CONTROL: | ||
219 | case WM831X_GPIO2_CONTROL: | ||
220 | case WM831X_GPIO3_CONTROL: | ||
221 | case WM831X_GPIO4_CONTROL: | ||
222 | case WM831X_GPIO5_CONTROL: | ||
223 | case WM831X_GPIO6_CONTROL: | ||
224 | case WM831X_GPIO7_CONTROL: | ||
225 | case WM831X_GPIO8_CONTROL: | ||
226 | case WM831X_GPIO9_CONTROL: | ||
227 | case WM831X_GPIO10_CONTROL: | ||
228 | case WM831X_GPIO11_CONTROL: | ||
229 | case WM831X_GPIO12_CONTROL: | ||
230 | case WM831X_GPIO13_CONTROL: | ||
231 | case WM831X_GPIO14_CONTROL: | ||
232 | case WM831X_GPIO15_CONTROL: | ||
233 | case WM831X_GPIO16_CONTROL: | ||
234 | case WM831X_CHARGER_CONTROL_1: | ||
235 | case WM831X_CHARGER_CONTROL_2: | ||
236 | case WM831X_CHARGER_STATUS: | ||
237 | case WM831X_BACKUP_CHARGER_CONTROL: | ||
238 | case WM831X_STATUS_LED_1: | ||
239 | case WM831X_STATUS_LED_2: | ||
240 | case WM831X_CURRENT_SINK_1: | ||
241 | case WM831X_CURRENT_SINK_2: | ||
242 | case WM831X_DCDC_ENABLE: | ||
243 | case WM831X_LDO_ENABLE: | ||
244 | case WM831X_DCDC_STATUS: | ||
245 | case WM831X_LDO_STATUS: | ||
246 | case WM831X_DCDC_UV_STATUS: | ||
247 | case WM831X_LDO_UV_STATUS: | ||
248 | case WM831X_DC1_CONTROL_1: | ||
249 | case WM831X_DC1_CONTROL_2: | ||
250 | case WM831X_DC1_ON_CONFIG: | ||
251 | case WM831X_DC1_SLEEP_CONTROL: | ||
252 | case WM831X_DC1_DVS_CONTROL: | ||
253 | case WM831X_DC2_CONTROL_1: | ||
254 | case WM831X_DC2_CONTROL_2: | ||
255 | case WM831X_DC2_ON_CONFIG: | ||
256 | case WM831X_DC2_SLEEP_CONTROL: | ||
257 | case WM831X_DC2_DVS_CONTROL: | ||
258 | case WM831X_DC3_CONTROL_1: | ||
259 | case WM831X_DC3_CONTROL_2: | ||
260 | case WM831X_DC3_ON_CONFIG: | ||
261 | case WM831X_DC3_SLEEP_CONTROL: | ||
262 | case WM831X_DC4_CONTROL: | ||
263 | case WM831X_DC4_SLEEP_CONTROL: | ||
264 | case WM831X_EPE1_CONTROL: | ||
265 | case WM831X_EPE2_CONTROL: | ||
266 | case WM831X_LDO1_CONTROL: | ||
267 | case WM831X_LDO1_ON_CONTROL: | ||
268 | case WM831X_LDO1_SLEEP_CONTROL: | ||
269 | case WM831X_LDO2_CONTROL: | ||
270 | case WM831X_LDO2_ON_CONTROL: | ||
271 | case WM831X_LDO2_SLEEP_CONTROL: | ||
272 | case WM831X_LDO3_CONTROL: | ||
273 | case WM831X_LDO3_ON_CONTROL: | ||
274 | case WM831X_LDO3_SLEEP_CONTROL: | ||
275 | case WM831X_LDO4_CONTROL: | ||
276 | case WM831X_LDO4_ON_CONTROL: | ||
277 | case WM831X_LDO4_SLEEP_CONTROL: | ||
278 | case WM831X_LDO5_CONTROL: | ||
279 | case WM831X_LDO5_ON_CONTROL: | ||
280 | case WM831X_LDO5_SLEEP_CONTROL: | ||
281 | case WM831X_LDO6_CONTROL: | ||
282 | case WM831X_LDO6_ON_CONTROL: | ||
283 | case WM831X_LDO6_SLEEP_CONTROL: | ||
284 | case WM831X_LDO7_CONTROL: | ||
285 | case WM831X_LDO7_ON_CONTROL: | ||
286 | case WM831X_LDO7_SLEEP_CONTROL: | ||
287 | case WM831X_LDO8_CONTROL: | ||
288 | case WM831X_LDO8_ON_CONTROL: | ||
289 | case WM831X_LDO8_SLEEP_CONTROL: | ||
290 | case WM831X_LDO9_CONTROL: | ||
291 | case WM831X_LDO9_ON_CONTROL: | ||
292 | case WM831X_LDO9_SLEEP_CONTROL: | ||
293 | case WM831X_LDO10_CONTROL: | ||
294 | case WM831X_LDO10_ON_CONTROL: | ||
295 | case WM831X_LDO10_SLEEP_CONTROL: | ||
296 | case WM831X_LDO11_ON_CONTROL: | ||
297 | case WM831X_LDO11_SLEEP_CONTROL: | ||
298 | case WM831X_POWER_GOOD_SOURCE_1: | ||
299 | case WM831X_POWER_GOOD_SOURCE_2: | ||
300 | case WM831X_CLOCK_CONTROL_1: | ||
301 | case WM831X_CLOCK_CONTROL_2: | ||
302 | case WM831X_FLL_CONTROL_1: | ||
303 | case WM831X_FLL_CONTROL_2: | ||
304 | case WM831X_FLL_CONTROL_3: | ||
305 | case WM831X_FLL_CONTROL_4: | ||
306 | case WM831X_FLL_CONTROL_5: | ||
307 | case WM831X_UNIQUE_ID_1: | ||
308 | case WM831X_UNIQUE_ID_2: | ||
309 | case WM831X_UNIQUE_ID_3: | ||
310 | case WM831X_UNIQUE_ID_4: | ||
311 | case WM831X_UNIQUE_ID_5: | ||
312 | case WM831X_UNIQUE_ID_6: | ||
313 | case WM831X_UNIQUE_ID_7: | ||
314 | case WM831X_UNIQUE_ID_8: | ||
315 | case WM831X_FACTORY_OTP_ID: | ||
316 | case WM831X_FACTORY_OTP_1: | ||
317 | case WM831X_FACTORY_OTP_2: | ||
318 | case WM831X_FACTORY_OTP_3: | ||
319 | case WM831X_FACTORY_OTP_4: | ||
320 | case WM831X_FACTORY_OTP_5: | ||
321 | case WM831X_CUSTOMER_OTP_ID: | ||
322 | case WM831X_DC1_OTP_CONTROL: | ||
323 | case WM831X_DC2_OTP_CONTROL: | ||
324 | case WM831X_DC3_OTP_CONTROL: | ||
325 | case WM831X_LDO1_2_OTP_CONTROL: | ||
326 | case WM831X_LDO3_4_OTP_CONTROL: | ||
327 | case WM831X_LDO5_6_OTP_CONTROL: | ||
328 | case WM831X_LDO7_8_OTP_CONTROL: | ||
329 | case WM831X_LDO9_10_OTP_CONTROL: | ||
330 | case WM831X_LDO11_EPE_CONTROL: | ||
331 | case WM831X_GPIO1_OTP_CONTROL: | ||
332 | case WM831X_GPIO2_OTP_CONTROL: | ||
333 | case WM831X_GPIO3_OTP_CONTROL: | ||
334 | case WM831X_GPIO4_OTP_CONTROL: | ||
335 | case WM831X_GPIO5_OTP_CONTROL: | ||
336 | case WM831X_GPIO6_OTP_CONTROL: | ||
337 | case WM831X_DBE_CHECK_DATA: | ||
338 | return true; | ||
339 | default: | ||
340 | return false; | ||
341 | } | ||
342 | } | ||
172 | 343 | ||
173 | ret = wm831x->read_dev(wm831x, reg, bytes, dest); | 344 | static bool wm831x_reg_writeable(struct device *dev, unsigned int reg) |
174 | if (ret < 0) | 345 | { |
175 | return ret; | 346 | struct wm831x *wm831x = dev_get_drvdata(dev); |
176 | 347 | ||
177 | for (i = 0; i < bytes / 2; i++) { | 348 | if (wm831x_reg_locked(wm831x, reg)) |
178 | buf[i] = be16_to_cpu(buf[i]); | 349 | return false; |
179 | 350 | ||
180 | dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n", | 351 | switch (reg) { |
181 | buf[i], reg + i, reg + i); | 352 | case WM831X_SYSVDD_CONTROL: |
353 | case WM831X_THERMAL_MONITORING: | ||
354 | case WM831X_POWER_STATE: | ||
355 | case WM831X_WATCHDOG: | ||
356 | case WM831X_ON_PIN_CONTROL: | ||
357 | case WM831X_RESET_CONTROL: | ||
358 | case WM831X_CONTROL_INTERFACE: | ||
359 | case WM831X_SECURITY_KEY: | ||
360 | case WM831X_SOFTWARE_SCRATCH: | ||
361 | case WM831X_OTP_CONTROL: | ||
362 | case WM831X_GPIO_LEVEL: | ||
363 | case WM831X_INTERRUPT_STATUS_1: | ||
364 | case WM831X_INTERRUPT_STATUS_2: | ||
365 | case WM831X_INTERRUPT_STATUS_3: | ||
366 | case WM831X_INTERRUPT_STATUS_4: | ||
367 | case WM831X_INTERRUPT_STATUS_5: | ||
368 | case WM831X_IRQ_CONFIG: | ||
369 | case WM831X_SYSTEM_INTERRUPTS_MASK: | ||
370 | case WM831X_INTERRUPT_STATUS_1_MASK: | ||
371 | case WM831X_INTERRUPT_STATUS_2_MASK: | ||
372 | case WM831X_INTERRUPT_STATUS_3_MASK: | ||
373 | case WM831X_INTERRUPT_STATUS_4_MASK: | ||
374 | case WM831X_INTERRUPT_STATUS_5_MASK: | ||
375 | case WM831X_RTC_TIME_1: | ||
376 | case WM831X_RTC_TIME_2: | ||
377 | case WM831X_RTC_ALARM_1: | ||
378 | case WM831X_RTC_ALARM_2: | ||
379 | case WM831X_RTC_CONTROL: | ||
380 | case WM831X_RTC_TRIM: | ||
381 | case WM831X_TOUCH_CONTROL_1: | ||
382 | case WM831X_TOUCH_CONTROL_2: | ||
383 | case WM831X_AUXADC_CONTROL: | ||
384 | case WM831X_AUXADC_SOURCE: | ||
385 | case WM831X_COMPARATOR_CONTROL: | ||
386 | case WM831X_COMPARATOR_1: | ||
387 | case WM831X_COMPARATOR_2: | ||
388 | case WM831X_COMPARATOR_3: | ||
389 | case WM831X_COMPARATOR_4: | ||
390 | case WM831X_GPIO1_CONTROL: | ||
391 | case WM831X_GPIO2_CONTROL: | ||
392 | case WM831X_GPIO3_CONTROL: | ||
393 | case WM831X_GPIO4_CONTROL: | ||
394 | case WM831X_GPIO5_CONTROL: | ||
395 | case WM831X_GPIO6_CONTROL: | ||
396 | case WM831X_GPIO7_CONTROL: | ||
397 | case WM831X_GPIO8_CONTROL: | ||
398 | case WM831X_GPIO9_CONTROL: | ||
399 | case WM831X_GPIO10_CONTROL: | ||
400 | case WM831X_GPIO11_CONTROL: | ||
401 | case WM831X_GPIO12_CONTROL: | ||
402 | case WM831X_GPIO13_CONTROL: | ||
403 | case WM831X_GPIO14_CONTROL: | ||
404 | case WM831X_GPIO15_CONTROL: | ||
405 | case WM831X_GPIO16_CONTROL: | ||
406 | case WM831X_CHARGER_CONTROL_1: | ||
407 | case WM831X_CHARGER_CONTROL_2: | ||
408 | case WM831X_CHARGER_STATUS: | ||
409 | case WM831X_BACKUP_CHARGER_CONTROL: | ||
410 | case WM831X_STATUS_LED_1: | ||
411 | case WM831X_STATUS_LED_2: | ||
412 | case WM831X_CURRENT_SINK_1: | ||
413 | case WM831X_CURRENT_SINK_2: | ||
414 | case WM831X_DCDC_ENABLE: | ||
415 | case WM831X_LDO_ENABLE: | ||
416 | case WM831X_DC1_CONTROL_1: | ||
417 | case WM831X_DC1_CONTROL_2: | ||
418 | case WM831X_DC1_ON_CONFIG: | ||
419 | case WM831X_DC1_SLEEP_CONTROL: | ||
420 | case WM831X_DC1_DVS_CONTROL: | ||
421 | case WM831X_DC2_CONTROL_1: | ||
422 | case WM831X_DC2_CONTROL_2: | ||
423 | case WM831X_DC2_ON_CONFIG: | ||
424 | case WM831X_DC2_SLEEP_CONTROL: | ||
425 | case WM831X_DC2_DVS_CONTROL: | ||
426 | case WM831X_DC3_CONTROL_1: | ||
427 | case WM831X_DC3_CONTROL_2: | ||
428 | case WM831X_DC3_ON_CONFIG: | ||
429 | case WM831X_DC3_SLEEP_CONTROL: | ||
430 | case WM831X_DC4_CONTROL: | ||
431 | case WM831X_DC4_SLEEP_CONTROL: | ||
432 | case WM831X_EPE1_CONTROL: | ||
433 | case WM831X_EPE2_CONTROL: | ||
434 | case WM831X_LDO1_CONTROL: | ||
435 | case WM831X_LDO1_ON_CONTROL: | ||
436 | case WM831X_LDO1_SLEEP_CONTROL: | ||
437 | case WM831X_LDO2_CONTROL: | ||
438 | case WM831X_LDO2_ON_CONTROL: | ||
439 | case WM831X_LDO2_SLEEP_CONTROL: | ||
440 | case WM831X_LDO3_CONTROL: | ||
441 | case WM831X_LDO3_ON_CONTROL: | ||
442 | case WM831X_LDO3_SLEEP_CONTROL: | ||
443 | case WM831X_LDO4_CONTROL: | ||
444 | case WM831X_LDO4_ON_CONTROL: | ||
445 | case WM831X_LDO4_SLEEP_CONTROL: | ||
446 | case WM831X_LDO5_CONTROL: | ||
447 | case WM831X_LDO5_ON_CONTROL: | ||
448 | case WM831X_LDO5_SLEEP_CONTROL: | ||
449 | case WM831X_LDO6_CONTROL: | ||
450 | case WM831X_LDO6_ON_CONTROL: | ||
451 | case WM831X_LDO6_SLEEP_CONTROL: | ||
452 | case WM831X_LDO7_CONTROL: | ||
453 | case WM831X_LDO7_ON_CONTROL: | ||
454 | case WM831X_LDO7_SLEEP_CONTROL: | ||
455 | case WM831X_LDO8_CONTROL: | ||
456 | case WM831X_LDO8_ON_CONTROL: | ||
457 | case WM831X_LDO8_SLEEP_CONTROL: | ||
458 | case WM831X_LDO9_CONTROL: | ||
459 | case WM831X_LDO9_ON_CONTROL: | ||
460 | case WM831X_LDO9_SLEEP_CONTROL: | ||
461 | case WM831X_LDO10_CONTROL: | ||
462 | case WM831X_LDO10_ON_CONTROL: | ||
463 | case WM831X_LDO10_SLEEP_CONTROL: | ||
464 | case WM831X_LDO11_ON_CONTROL: | ||
465 | case WM831X_LDO11_SLEEP_CONTROL: | ||
466 | case WM831X_POWER_GOOD_SOURCE_1: | ||
467 | case WM831X_POWER_GOOD_SOURCE_2: | ||
468 | case WM831X_CLOCK_CONTROL_1: | ||
469 | case WM831X_CLOCK_CONTROL_2: | ||
470 | case WM831X_FLL_CONTROL_1: | ||
471 | case WM831X_FLL_CONTROL_2: | ||
472 | case WM831X_FLL_CONTROL_3: | ||
473 | case WM831X_FLL_CONTROL_4: | ||
474 | case WM831X_FLL_CONTROL_5: | ||
475 | return true; | ||
476 | default: | ||
477 | return false; | ||
182 | } | 478 | } |
479 | } | ||
183 | 480 | ||
184 | return 0; | 481 | static bool wm831x_reg_volatile(struct device *dev, unsigned int reg) |
482 | { | ||
483 | switch (reg) { | ||
484 | case WM831X_SYSTEM_STATUS: | ||
485 | case WM831X_ON_SOURCE: | ||
486 | case WM831X_OFF_SOURCE: | ||
487 | case WM831X_GPIO_LEVEL: | ||
488 | case WM831X_SYSTEM_INTERRUPTS: | ||
489 | case WM831X_INTERRUPT_STATUS_1: | ||
490 | case WM831X_INTERRUPT_STATUS_2: | ||
491 | case WM831X_INTERRUPT_STATUS_3: | ||
492 | case WM831X_INTERRUPT_STATUS_4: | ||
493 | case WM831X_INTERRUPT_STATUS_5: | ||
494 | case WM831X_RTC_TIME_1: | ||
495 | case WM831X_RTC_TIME_2: | ||
496 | case WM831X_TOUCH_DATA_X: | ||
497 | case WM831X_TOUCH_DATA_Y: | ||
498 | case WM831X_TOUCH_DATA_Z: | ||
499 | case WM831X_AUXADC_DATA: | ||
500 | case WM831X_CHARGER_STATUS: | ||
501 | case WM831X_DCDC_STATUS: | ||
502 | case WM831X_LDO_STATUS: | ||
503 | case WM831X_DCDC_UV_STATUS: | ||
504 | case WM831X_LDO_UV_STATUS: | ||
505 | return true; | ||
506 | default: | ||
507 | return false; | ||
508 | } | ||
185 | } | 509 | } |
186 | 510 | ||
187 | /** | 511 | /** |
@@ -192,14 +516,10 @@ static int wm831x_read(struct wm831x *wm831x, unsigned short reg, | |||
192 | */ | 516 | */ |
193 | int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) | 517 | int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) |
194 | { | 518 | { |
195 | unsigned short val; | 519 | unsigned int val; |
196 | int ret; | 520 | int ret; |
197 | 521 | ||
198 | mutex_lock(&wm831x->io_lock); | 522 | ret = regmap_read(wm831x->regmap, reg, &val); |
199 | |||
200 | ret = wm831x_read(wm831x, reg, 2, &val); | ||
201 | |||
202 | mutex_unlock(&wm831x->io_lock); | ||
203 | 523 | ||
204 | if (ret < 0) | 524 | if (ret < 0) |
205 | return ret; | 525 | return ret; |
@@ -219,15 +539,7 @@ EXPORT_SYMBOL_GPL(wm831x_reg_read); | |||
219 | int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, | 539 | int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, |
220 | int count, u16 *buf) | 540 | int count, u16 *buf) |
221 | { | 541 | { |
222 | int ret; | 542 | return regmap_bulk_read(wm831x->regmap, reg, buf, count); |
223 | |||
224 | mutex_lock(&wm831x->io_lock); | ||
225 | |||
226 | ret = wm831x_read(wm831x, reg, count * 2, buf); | ||
227 | |||
228 | mutex_unlock(&wm831x->io_lock); | ||
229 | |||
230 | return ret; | ||
231 | } | 543 | } |
232 | EXPORT_SYMBOL_GPL(wm831x_bulk_read); | 544 | EXPORT_SYMBOL_GPL(wm831x_bulk_read); |
233 | 545 | ||
@@ -235,7 +547,7 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg, | |||
235 | int bytes, void *src) | 547 | int bytes, void *src) |
236 | { | 548 | { |
237 | u16 *buf = src; | 549 | u16 *buf = src; |
238 | int i; | 550 | int i, ret; |
239 | 551 | ||
240 | BUG_ON(bytes % 2); | 552 | BUG_ON(bytes % 2); |
241 | BUG_ON(bytes <= 0); | 553 | BUG_ON(bytes <= 0); |
@@ -246,11 +558,10 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg, | |||
246 | 558 | ||
247 | dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", | 559 | dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", |
248 | buf[i], reg + i, reg + i); | 560 | buf[i], reg + i, reg + i); |
249 | 561 | ret = regmap_write(wm831x->regmap, reg + i, buf[i]); | |
250 | buf[i] = cpu_to_be16(buf[i]); | ||
251 | } | 562 | } |
252 | 563 | ||
253 | return wm831x->write_dev(wm831x, reg, bytes, src); | 564 | return 0; |
254 | } | 565 | } |
255 | 566 | ||
256 | /** | 567 | /** |
@@ -287,20 +598,14 @@ int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg, | |||
287 | unsigned short mask, unsigned short val) | 598 | unsigned short mask, unsigned short val) |
288 | { | 599 | { |
289 | int ret; | 600 | int ret; |
290 | u16 r; | ||
291 | 601 | ||
292 | mutex_lock(&wm831x->io_lock); | 602 | mutex_lock(&wm831x->io_lock); |
293 | 603 | ||
294 | ret = wm831x_read(wm831x, reg, 2, &r); | 604 | if (!wm831x_reg_locked(wm831x, reg)) |
295 | if (ret < 0) | 605 | ret = regmap_update_bits(wm831x->regmap, reg, mask, val); |
296 | goto out; | 606 | else |
297 | 607 | ret = -EPERM; | |
298 | r &= ~mask; | ||
299 | r |= val & mask; | ||
300 | |||
301 | ret = wm831x_write(wm831x, reg, 2, &r); | ||
302 | 608 | ||
303 | out: | ||
304 | mutex_unlock(&wm831x->io_lock); | 609 | mutex_unlock(&wm831x->io_lock); |
305 | 610 | ||
306 | return ret; | 611 | return ret; |
@@ -1293,6 +1598,19 @@ static struct mfd_cell backlight_devs[] = { | |||
1293 | }, | 1598 | }, |
1294 | }; | 1599 | }; |
1295 | 1600 | ||
1601 | struct regmap_config wm831x_regmap_config = { | ||
1602 | .reg_bits = 16, | ||
1603 | .val_bits = 16, | ||
1604 | |||
1605 | .cache_type = REGCACHE_RBTREE, | ||
1606 | |||
1607 | .max_register = WM831X_DBE_CHECK_DATA, | ||
1608 | .readable_reg = wm831x_reg_readable, | ||
1609 | .writeable_reg = wm831x_reg_writeable, | ||
1610 | .volatile_reg = wm831x_reg_volatile, | ||
1611 | }; | ||
1612 | EXPORT_SYMBOL_GPL(wm831x_regmap_config); | ||
1613 | |||
1296 | /* | 1614 | /* |
1297 | * Instantiate the generic non-control parts of the device. | 1615 | * Instantiate the generic non-control parts of the device. |
1298 | */ | 1616 | */ |
@@ -1311,7 +1629,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1311 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); | 1629 | ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); |
1312 | if (ret < 0) { | 1630 | if (ret < 0) { |
1313 | dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); | 1631 | dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); |
1314 | goto err; | 1632 | goto err_regmap; |
1315 | } | 1633 | } |
1316 | switch (ret) { | 1634 | switch (ret) { |
1317 | case 0x6204: | 1635 | case 0x6204: |
@@ -1320,20 +1638,20 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1320 | default: | 1638 | default: |
1321 | dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); | 1639 | dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); |
1322 | ret = -EINVAL; | 1640 | ret = -EINVAL; |
1323 | goto err; | 1641 | goto err_regmap; |
1324 | } | 1642 | } |
1325 | 1643 | ||
1326 | ret = wm831x_reg_read(wm831x, WM831X_REVISION); | 1644 | ret = wm831x_reg_read(wm831x, WM831X_REVISION); |
1327 | if (ret < 0) { | 1645 | if (ret < 0) { |
1328 | dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); | 1646 | dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); |
1329 | goto err; | 1647 | goto err_regmap; |
1330 | } | 1648 | } |
1331 | rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; | 1649 | rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; |
1332 | 1650 | ||
1333 | ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); | 1651 | ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); |
1334 | if (ret < 0) { | 1652 | if (ret < 0) { |
1335 | dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); | 1653 | dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); |
1336 | goto err; | 1654 | goto err_regmap; |
1337 | } | 1655 | } |
1338 | 1656 | ||
1339 | /* Some engineering samples do not have the ID set, rely on | 1657 | /* Some engineering samples do not have the ID set, rely on |
@@ -1408,7 +1726,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1408 | default: | 1726 | default: |
1409 | dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); | 1727 | dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); |
1410 | ret = -EINVAL; | 1728 | ret = -EINVAL; |
1411 | goto err; | 1729 | goto err_regmap; |
1412 | } | 1730 | } |
1413 | 1731 | ||
1414 | /* This will need revisiting in future but is OK for all | 1732 | /* This will need revisiting in future but is OK for all |
@@ -1422,7 +1740,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1422 | ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); | 1740 | ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); |
1423 | if (ret < 0) { | 1741 | if (ret < 0) { |
1424 | dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); | 1742 | dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); |
1425 | goto err; | 1743 | goto err_regmap; |
1426 | } | 1744 | } |
1427 | if (ret != 0) { | 1745 | if (ret != 0) { |
1428 | dev_warn(wm831x->dev, "Security key had non-zero value %x\n", | 1746 | dev_warn(wm831x->dev, "Security key had non-zero value %x\n", |
@@ -1435,7 +1753,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1435 | ret = pdata->pre_init(wm831x); | 1753 | ret = pdata->pre_init(wm831x); |
1436 | if (ret != 0) { | 1754 | if (ret != 0) { |
1437 | dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); | 1755 | dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); |
1438 | goto err; | 1756 | goto err_regmap; |
1439 | } | 1757 | } |
1440 | } | 1758 | } |
1441 | 1759 | ||
@@ -1458,7 +1776,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1458 | 1776 | ||
1459 | ret = wm831x_irq_init(wm831x, irq); | 1777 | ret = wm831x_irq_init(wm831x, irq); |
1460 | if (ret != 0) | 1778 | if (ret != 0) |
1461 | goto err; | 1779 | goto err_regmap; |
1462 | 1780 | ||
1463 | wm831x_auxadc_init(wm831x); | 1781 | wm831x_auxadc_init(wm831x); |
1464 | 1782 | ||
@@ -1554,8 +1872,9 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1554 | 1872 | ||
1555 | err_irq: | 1873 | err_irq: |
1556 | wm831x_irq_exit(wm831x); | 1874 | wm831x_irq_exit(wm831x); |
1557 | err: | 1875 | err_regmap: |
1558 | mfd_remove_devices(wm831x->dev); | 1876 | mfd_remove_devices(wm831x->dev); |
1877 | regmap_exit(wm831x->regmap); | ||
1559 | kfree(wm831x); | 1878 | kfree(wm831x); |
1560 | return ret; | 1879 | return ret; |
1561 | } | 1880 | } |
@@ -1567,6 +1886,7 @@ void wm831x_device_exit(struct wm831x *wm831x) | |||
1567 | if (wm831x->irq_base) | 1886 | if (wm831x->irq_base) |
1568 | free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); | 1887 | free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); |
1569 | wm831x_irq_exit(wm831x); | 1888 | wm831x_irq_exit(wm831x); |
1889 | regmap_exit(wm831x->regmap); | ||
1570 | kfree(wm831x); | 1890 | kfree(wm831x); |
1571 | } | 1891 | } |
1572 | 1892 | ||
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c index 3ff8c13db2a8..ac8da1d439da 100644 --- a/drivers/mfd/wm831x-i2c.c +++ b/drivers/mfd/wm831x-i2c.c | |||
@@ -18,67 +18,17 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/err.h> | ||
22 | #include <linux/regmap.h> | ||
21 | 23 | ||
22 | #include <linux/mfd/wm831x/core.h> | 24 | #include <linux/mfd/wm831x/core.h> |
23 | #include <linux/mfd/wm831x/pdata.h> | 25 | #include <linux/mfd/wm831x/pdata.h> |
24 | 26 | ||
25 | static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, | ||
26 | int bytes, void *dest) | ||
27 | { | ||
28 | struct i2c_client *i2c = wm831x->control_data; | ||
29 | int ret; | ||
30 | u16 r = cpu_to_be16(reg); | ||
31 | |||
32 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
33 | if (ret < 0) | ||
34 | return ret; | ||
35 | if (ret != 2) | ||
36 | return -EIO; | ||
37 | |||
38 | ret = i2c_master_recv(i2c, dest, bytes); | ||
39 | if (ret < 0) | ||
40 | return ret; | ||
41 | if (ret != bytes) | ||
42 | return -EIO; | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | /* Currently we allocate the write buffer on the stack; this is OK for | ||
47 | * small writes - if we need to do large writes this will need to be | ||
48 | * revised. | ||
49 | */ | ||
50 | static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg, | ||
51 | int bytes, void *src) | ||
52 | { | ||
53 | struct i2c_client *i2c = wm831x->control_data; | ||
54 | struct i2c_msg xfer[2]; | ||
55 | int ret; | ||
56 | |||
57 | reg = cpu_to_be16(reg); | ||
58 | |||
59 | xfer[0].addr = i2c->addr; | ||
60 | xfer[0].flags = 0; | ||
61 | xfer[0].len = 2; | ||
62 | xfer[0].buf = (char *)® | ||
63 | |||
64 | xfer[1].addr = i2c->addr; | ||
65 | xfer[1].flags = I2C_M_NOSTART; | ||
66 | xfer[1].len = bytes; | ||
67 | xfer[1].buf = (char *)src; | ||
68 | |||
69 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
70 | if (ret < 0) | ||
71 | return ret; | ||
72 | if (ret != 2) | ||
73 | return -EIO; | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int wm831x_i2c_probe(struct i2c_client *i2c, | 27 | static int wm831x_i2c_probe(struct i2c_client *i2c, |
79 | const struct i2c_device_id *id) | 28 | const struct i2c_device_id *id) |
80 | { | 29 | { |
81 | struct wm831x *wm831x; | 30 | struct wm831x *wm831x; |
31 | int ret; | ||
82 | 32 | ||
83 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | 33 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); |
84 | if (wm831x == NULL) | 34 | if (wm831x == NULL) |
@@ -86,9 +36,15 @@ static int wm831x_i2c_probe(struct i2c_client *i2c, | |||
86 | 36 | ||
87 | i2c_set_clientdata(i2c, wm831x); | 37 | i2c_set_clientdata(i2c, wm831x); |
88 | wm831x->dev = &i2c->dev; | 38 | wm831x->dev = &i2c->dev; |
89 | wm831x->control_data = i2c; | 39 | |
90 | wm831x->read_dev = wm831x_i2c_read_device; | 40 | wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config); |
91 | wm831x->write_dev = wm831x_i2c_write_device; | 41 | if (IS_ERR(wm831x->regmap)) { |
42 | ret = PTR_ERR(wm831x->regmap); | ||
43 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", | ||
44 | ret); | ||
45 | kfree(wm831x); | ||
46 | return ret; | ||
47 | } | ||
92 | 48 | ||
93 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); | 49 | return wm831x_device_init(wm831x, id->driver_data, i2c->irq); |
94 | } | 50 | } |
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c index 8e8138ba0267..8d6a9a969dbc 100644 --- a/drivers/mfd/wm831x-spi.c +++ b/drivers/mfd/wm831x-spi.c | |||
@@ -16,78 +16,19 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/pm.h> | 17 | #include <linux/pm.h> |
18 | #include <linux/spi/spi.h> | 18 | #include <linux/spi/spi.h> |
19 | #include <linux/regmap.h> | ||
20 | #include <linux/err.h> | ||
19 | 21 | ||
20 | #include <linux/mfd/wm831x/core.h> | 22 | #include <linux/mfd/wm831x/core.h> |
21 | 23 | ||
22 | static int wm831x_spi_read_device(struct wm831x *wm831x, unsigned short reg, | ||
23 | int bytes, void *dest) | ||
24 | { | ||
25 | u16 tx_val; | ||
26 | u16 *d = dest; | ||
27 | int r, ret; | ||
28 | |||
29 | /* Go register at a time */ | ||
30 | for (r = reg; r < reg + (bytes / 2); r++) { | ||
31 | tx_val = r | 0x8000; | ||
32 | |||
33 | ret = spi_write_then_read(wm831x->control_data, | ||
34 | (u8 *)&tx_val, 2, (u8 *)d, 2); | ||
35 | if (ret != 0) | ||
36 | return ret; | ||
37 | |||
38 | *d = be16_to_cpu(*d); | ||
39 | |||
40 | d++; | ||
41 | } | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static int wm831x_spi_write_device(struct wm831x *wm831x, unsigned short reg, | ||
47 | int bytes, void *src) | ||
48 | { | ||
49 | struct spi_device *spi = wm831x->control_data; | ||
50 | u16 *s = src; | ||
51 | u16 data[2]; | ||
52 | int ret, r; | ||
53 | |||
54 | /* Go register at a time */ | ||
55 | for (r = reg; r < reg + (bytes / 2); r++) { | ||
56 | data[0] = r; | ||
57 | data[1] = *s++; | ||
58 | |||
59 | ret = spi_write(spi, (char *)&data, sizeof(data)); | ||
60 | if (ret != 0) | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | static int __devinit wm831x_spi_probe(struct spi_device *spi) | 24 | static int __devinit wm831x_spi_probe(struct spi_device *spi) |
68 | { | 25 | { |
26 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
69 | struct wm831x *wm831x; | 27 | struct wm831x *wm831x; |
70 | enum wm831x_parent type; | 28 | enum wm831x_parent type; |
29 | int ret; | ||
71 | 30 | ||
72 | /* Currently SPI support for ID tables is unmerged, we're faking it */ | 31 | type = (enum wm831x_parent)id->driver_data; |
73 | if (strcmp(spi->modalias, "wm8310") == 0) | ||
74 | type = WM8310; | ||
75 | else if (strcmp(spi->modalias, "wm8311") == 0) | ||
76 | type = WM8311; | ||
77 | else if (strcmp(spi->modalias, "wm8312") == 0) | ||
78 | type = WM8312; | ||
79 | else if (strcmp(spi->modalias, "wm8320") == 0) | ||
80 | type = WM8320; | ||
81 | else if (strcmp(spi->modalias, "wm8321") == 0) | ||
82 | type = WM8321; | ||
83 | else if (strcmp(spi->modalias, "wm8325") == 0) | ||
84 | type = WM8325; | ||
85 | else if (strcmp(spi->modalias, "wm8326") == 0) | ||
86 | type = WM8326; | ||
87 | else { | ||
88 | dev_err(&spi->dev, "Unknown device type\n"); | ||
89 | return -EINVAL; | ||
90 | } | ||
91 | 32 | ||
92 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | 33 | wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); |
93 | if (wm831x == NULL) | 34 | if (wm831x == NULL) |
@@ -98,9 +39,15 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi) | |||
98 | 39 | ||
99 | dev_set_drvdata(&spi->dev, wm831x); | 40 | dev_set_drvdata(&spi->dev, wm831x); |
100 | wm831x->dev = &spi->dev; | 41 | wm831x->dev = &spi->dev; |
101 | wm831x->control_data = spi; | 42 | |
102 | wm831x->read_dev = wm831x_spi_read_device; | 43 | wm831x->regmap = regmap_init_spi(spi, &wm831x_regmap_config); |
103 | wm831x->write_dev = wm831x_spi_write_device; | 44 | if (IS_ERR(wm831x->regmap)) { |
45 | ret = PTR_ERR(wm831x->regmap); | ||
46 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", | ||
47 | ret); | ||
48 | kfree(wm831x); | ||
49 | return ret; | ||
50 | } | ||
104 | 51 | ||
105 | return wm831x_device_init(wm831x, type, spi->irq); | 52 | return wm831x_device_init(wm831x, type, spi->irq); |
106 | } | 53 | } |
@@ -133,115 +80,38 @@ static const struct dev_pm_ops wm831x_spi_pm = { | |||
133 | .suspend = wm831x_spi_suspend, | 80 | .suspend = wm831x_spi_suspend, |
134 | }; | 81 | }; |
135 | 82 | ||
136 | static struct spi_driver wm8310_spi_driver = { | 83 | static const struct spi_device_id wm831x_spi_ids[] = { |
137 | .driver = { | 84 | { "wm8310", WM8310 }, |
138 | .name = "wm8310", | 85 | { "wm8311", WM8311 }, |
139 | .bus = &spi_bus_type, | 86 | { "wm8312", WM8312 }, |
140 | .owner = THIS_MODULE, | 87 | { "wm8320", WM8320 }, |
141 | .pm = &wm831x_spi_pm, | 88 | { "wm8321", WM8321 }, |
142 | }, | 89 | { "wm8325", WM8325 }, |
143 | .probe = wm831x_spi_probe, | 90 | { "wm8326", WM8326 }, |
144 | .remove = __devexit_p(wm831x_spi_remove), | 91 | { }, |
145 | }; | 92 | }; |
93 | MODULE_DEVICE_TABLE(spi, wm831x_spi_id); | ||
146 | 94 | ||
147 | static struct spi_driver wm8311_spi_driver = { | 95 | static struct spi_driver wm831x_spi_driver = { |
148 | .driver = { | 96 | .driver = { |
149 | .name = "wm8311", | 97 | .name = "wm831x", |
150 | .bus = &spi_bus_type, | 98 | .bus = &spi_bus_type, |
151 | .owner = THIS_MODULE, | 99 | .owner = THIS_MODULE, |
152 | .pm = &wm831x_spi_pm, | 100 | .pm = &wm831x_spi_pm, |
153 | }, | 101 | }, |
102 | .id_table = wm831x_spi_ids, | ||
154 | .probe = wm831x_spi_probe, | 103 | .probe = wm831x_spi_probe, |
155 | .remove = __devexit_p(wm831x_spi_remove), | 104 | .remove = __devexit_p(wm831x_spi_remove), |
156 | .shutdown = wm831x_spi_shutdown, | 105 | .shutdown = wm831x_spi_shutdown, |
157 | }; | 106 | }; |
158 | 107 | ||
159 | static struct spi_driver wm8312_spi_driver = { | ||
160 | .driver = { | ||
161 | .name = "wm8312", | ||
162 | .bus = &spi_bus_type, | ||
163 | .owner = THIS_MODULE, | ||
164 | .pm = &wm831x_spi_pm, | ||
165 | }, | ||
166 | .probe = wm831x_spi_probe, | ||
167 | .remove = __devexit_p(wm831x_spi_remove), | ||
168 | }; | ||
169 | |||
170 | static struct spi_driver wm8320_spi_driver = { | ||
171 | .driver = { | ||
172 | .name = "wm8320", | ||
173 | .bus = &spi_bus_type, | ||
174 | .owner = THIS_MODULE, | ||
175 | .pm = &wm831x_spi_pm, | ||
176 | }, | ||
177 | .probe = wm831x_spi_probe, | ||
178 | .remove = __devexit_p(wm831x_spi_remove), | ||
179 | }; | ||
180 | |||
181 | static struct spi_driver wm8321_spi_driver = { | ||
182 | .driver = { | ||
183 | .name = "wm8321", | ||
184 | .bus = &spi_bus_type, | ||
185 | .owner = THIS_MODULE, | ||
186 | .pm = &wm831x_spi_pm, | ||
187 | }, | ||
188 | .probe = wm831x_spi_probe, | ||
189 | .remove = __devexit_p(wm831x_spi_remove), | ||
190 | }; | ||
191 | |||
192 | static struct spi_driver wm8325_spi_driver = { | ||
193 | .driver = { | ||
194 | .name = "wm8325", | ||
195 | .bus = &spi_bus_type, | ||
196 | .owner = THIS_MODULE, | ||
197 | .pm = &wm831x_spi_pm, | ||
198 | }, | ||
199 | .probe = wm831x_spi_probe, | ||
200 | .remove = __devexit_p(wm831x_spi_remove), | ||
201 | }; | ||
202 | |||
203 | static struct spi_driver wm8326_spi_driver = { | ||
204 | .driver = { | ||
205 | .name = "wm8326", | ||
206 | .bus = &spi_bus_type, | ||
207 | .owner = THIS_MODULE, | ||
208 | .pm = &wm831x_spi_pm, | ||
209 | }, | ||
210 | .probe = wm831x_spi_probe, | ||
211 | .remove = __devexit_p(wm831x_spi_remove), | ||
212 | }; | ||
213 | |||
214 | static int __init wm831x_spi_init(void) | 108 | static int __init wm831x_spi_init(void) |
215 | { | 109 | { |
216 | int ret; | 110 | int ret; |
217 | 111 | ||
218 | ret = spi_register_driver(&wm8310_spi_driver); | 112 | ret = spi_register_driver(&wm831x_spi_driver); |
219 | if (ret != 0) | ||
220 | pr_err("Failed to register WM8310 SPI driver: %d\n", ret); | ||
221 | |||
222 | ret = spi_register_driver(&wm8311_spi_driver); | ||
223 | if (ret != 0) | ||
224 | pr_err("Failed to register WM8311 SPI driver: %d\n", ret); | ||
225 | |||
226 | ret = spi_register_driver(&wm8312_spi_driver); | ||
227 | if (ret != 0) | ||
228 | pr_err("Failed to register WM8312 SPI driver: %d\n", ret); | ||
229 | |||
230 | ret = spi_register_driver(&wm8320_spi_driver); | ||
231 | if (ret != 0) | ||
232 | pr_err("Failed to register WM8320 SPI driver: %d\n", ret); | ||
233 | |||
234 | ret = spi_register_driver(&wm8321_spi_driver); | ||
235 | if (ret != 0) | ||
236 | pr_err("Failed to register WM8321 SPI driver: %d\n", ret); | ||
237 | |||
238 | ret = spi_register_driver(&wm8325_spi_driver); | ||
239 | if (ret != 0) | ||
240 | pr_err("Failed to register WM8325 SPI driver: %d\n", ret); | ||
241 | |||
242 | ret = spi_register_driver(&wm8326_spi_driver); | ||
243 | if (ret != 0) | 113 | if (ret != 0) |
244 | pr_err("Failed to register WM8326 SPI driver: %d\n", ret); | 114 | pr_err("Failed to register WM831x SPI driver: %d\n", ret); |
245 | 115 | ||
246 | return 0; | 116 | return 0; |
247 | } | 117 | } |
@@ -249,13 +119,7 @@ subsys_initcall(wm831x_spi_init); | |||
249 | 119 | ||
250 | static void __exit wm831x_spi_exit(void) | 120 | static void __exit wm831x_spi_exit(void) |
251 | { | 121 | { |
252 | spi_unregister_driver(&wm8326_spi_driver); | 122 | spi_unregister_driver(&wm831x_spi_driver); |
253 | spi_unregister_driver(&wm8325_spi_driver); | ||
254 | spi_unregister_driver(&wm8321_spi_driver); | ||
255 | spi_unregister_driver(&wm8320_spi_driver); | ||
256 | spi_unregister_driver(&wm8312_spi_driver); | ||
257 | spi_unregister_driver(&wm8311_spi_driver); | ||
258 | spi_unregister_driver(&wm8310_spi_driver); | ||
259 | } | 123 | } |
260 | module_exit(wm831x_spi_exit); | 124 | module_exit(wm831x_spi_exit); |
261 | 125 | ||
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c index 597f82edacaa..e06ba9440cdb 100644 --- a/drivers/mfd/wm8400-core.c +++ b/drivers/mfd/wm8400-core.c | |||
@@ -13,11 +13,13 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/bug.h> | 15 | #include <linux/bug.h> |
16 | #include <linux/err.h> | ||
16 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
18 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
19 | #include <linux/mfd/wm8400-private.h> | 20 | #include <linux/mfd/wm8400-private.h> |
20 | #include <linux/mfd/wm8400-audio.h> | 21 | #include <linux/mfd/wm8400-audio.h> |
22 | #include <linux/regmap.h> | ||
21 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
22 | 24 | ||
23 | static struct { | 25 | static struct { |
@@ -123,14 +125,9 @@ static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest) | |||
123 | /* If there are any volatile reads then read back the entire block */ | 125 | /* If there are any volatile reads then read back the entire block */ |
124 | for (i = reg; i < reg + num_regs; i++) | 126 | for (i = reg; i < reg + num_regs; i++) |
125 | if (reg_data[i].vol) { | 127 | if (reg_data[i].vol) { |
126 | ret = wm8400->read_dev(wm8400->io_data, reg, | 128 | ret = regmap_bulk_read(wm8400->regmap, reg, dest, |
127 | num_regs, dest); | 129 | num_regs); |
128 | if (ret != 0) | 130 | return ret; |
129 | return ret; | ||
130 | for (i = 0; i < num_regs; i++) | ||
131 | dest[i] = be16_to_cpu(dest[i]); | ||
132 | |||
133 | return 0; | ||
134 | } | 131 | } |
135 | 132 | ||
136 | /* Otherwise use the cache */ | 133 | /* Otherwise use the cache */ |
@@ -149,14 +146,11 @@ static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs, | |||
149 | for (i = 0; i < num_regs; i++) { | 146 | for (i = 0; i < num_regs; i++) { |
150 | BUG_ON(!reg_data[reg + i].writable); | 147 | BUG_ON(!reg_data[reg + i].writable); |
151 | wm8400->reg_cache[reg + i] = src[i]; | 148 | wm8400->reg_cache[reg + i] = src[i]; |
152 | src[i] = cpu_to_be16(src[i]); | 149 | ret = regmap_write(wm8400->regmap, reg, src[i]); |
150 | if (ret != 0) | ||
151 | return ret; | ||
153 | } | 152 | } |
154 | 153 | ||
155 | /* Do the actual I/O */ | ||
156 | ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src); | ||
157 | if (ret != 0) | ||
158 | return -EIO; | ||
159 | |||
160 | return 0; | 154 | return 0; |
161 | } | 155 | } |
162 | 156 | ||
@@ -270,14 +264,14 @@ static int wm8400_init(struct wm8400 *wm8400, | |||
270 | dev_set_drvdata(wm8400->dev, wm8400); | 264 | dev_set_drvdata(wm8400->dev, wm8400); |
271 | 265 | ||
272 | /* Check that this is actually a WM8400 */ | 266 | /* Check that this is actually a WM8400 */ |
273 | ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, ®); | 267 | ret = regmap_read(wm8400->regmap, WM8400_RESET_ID, &i); |
274 | if (ret != 0) { | 268 | if (ret != 0) { |
275 | dev_err(wm8400->dev, "Chip ID register read failed\n"); | 269 | dev_err(wm8400->dev, "Chip ID register read failed\n"); |
276 | return -EIO; | 270 | return -EIO; |
277 | } | 271 | } |
278 | if (be16_to_cpu(reg) != reg_data[WM8400_RESET_ID].default_val) { | 272 | if (i != reg_data[WM8400_RESET_ID].default_val) { |
279 | dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", | 273 | dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", |
280 | be16_to_cpu(reg)); | 274 | reg); |
281 | return -ENODEV; | 275 | return -ENODEV; |
282 | } | 276 | } |
283 | 277 | ||
@@ -285,9 +279,8 @@ static int wm8400_init(struct wm8400 *wm8400, | |||
285 | * is a PMIC we can't reset it safely so initialise the register | 279 | * is a PMIC we can't reset it safely so initialise the register |
286 | * cache from the hardware. | 280 | * cache from the hardware. |
287 | */ | 281 | */ |
288 | ret = wm8400->read_dev(wm8400->io_data, 0, | 282 | ret = regmap_raw_read(wm8400->regmap, 0, wm8400->reg_cache, |
289 | ARRAY_SIZE(wm8400->reg_cache), | 283 | ARRAY_SIZE(wm8400->reg_cache)); |
290 | wm8400->reg_cache); | ||
291 | if (ret != 0) { | 284 | if (ret != 0) { |
292 | dev_err(wm8400->dev, "Register cache read failed\n"); | 285 | dev_err(wm8400->dev, "Register cache read failed\n"); |
293 | return -EIO; | 286 | return -EIO; |
@@ -337,60 +330,13 @@ static void wm8400_release(struct wm8400 *wm8400) | |||
337 | mfd_remove_devices(wm8400->dev); | 330 | mfd_remove_devices(wm8400->dev); |
338 | } | 331 | } |
339 | 332 | ||
340 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 333 | static const struct regmap_config wm8400_regmap_config = { |
341 | static int wm8400_i2c_read(void *io_data, char reg, int count, u16 *dest) | 334 | .reg_bits = 8, |
342 | { | 335 | .val_bits = 16, |
343 | struct i2c_client *i2c = io_data; | 336 | .max_register = WM8400_REGISTER_COUNT - 1, |
344 | struct i2c_msg xfer[2]; | 337 | }; |
345 | int ret; | ||
346 | |||
347 | /* Write register */ | ||
348 | xfer[0].addr = i2c->addr; | ||
349 | xfer[0].flags = 0; | ||
350 | xfer[0].len = 1; | ||
351 | xfer[0].buf = ® | ||
352 | |||
353 | /* Read data */ | ||
354 | xfer[1].addr = i2c->addr; | ||
355 | xfer[1].flags = I2C_M_RD; | ||
356 | xfer[1].len = count * sizeof(u16); | ||
357 | xfer[1].buf = (u8 *)dest; | ||
358 | |||
359 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
360 | if (ret == 2) | ||
361 | ret = 0; | ||
362 | else if (ret >= 0) | ||
363 | ret = -EIO; | ||
364 | |||
365 | return ret; | ||
366 | } | ||
367 | |||
368 | static int wm8400_i2c_write(void *io_data, char reg, int count, const u16 *src) | ||
369 | { | ||
370 | struct i2c_client *i2c = io_data; | ||
371 | u8 *msg; | ||
372 | int ret; | ||
373 | |||
374 | /* We add 1 byte for device register - ideally I2C would gather. */ | ||
375 | msg = kmalloc((count * sizeof(u16)) + 1, GFP_KERNEL); | ||
376 | if (msg == NULL) | ||
377 | return -ENOMEM; | ||
378 | |||
379 | msg[0] = reg; | ||
380 | memcpy(&msg[1], src, count * sizeof(u16)); | ||
381 | |||
382 | ret = i2c_master_send(i2c, msg, (count * sizeof(u16)) + 1); | ||
383 | |||
384 | if (ret == (count * 2) + 1) | ||
385 | ret = 0; | ||
386 | else if (ret >= 0) | ||
387 | ret = -EIO; | ||
388 | |||
389 | kfree(msg); | ||
390 | |||
391 | return ret; | ||
392 | } | ||
393 | 338 | ||
339 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
394 | static int wm8400_i2c_probe(struct i2c_client *i2c, | 340 | static int wm8400_i2c_probe(struct i2c_client *i2c, |
395 | const struct i2c_device_id *id) | 341 | const struct i2c_device_id *id) |
396 | { | 342 | { |
@@ -403,18 +349,23 @@ static int wm8400_i2c_probe(struct i2c_client *i2c, | |||
403 | goto err; | 349 | goto err; |
404 | } | 350 | } |
405 | 351 | ||
406 | wm8400->io_data = i2c; | 352 | wm8400->regmap = regmap_init_i2c(i2c, &wm8400_regmap_config); |
407 | wm8400->read_dev = wm8400_i2c_read; | 353 | if (IS_ERR(wm8400->regmap)) { |
408 | wm8400->write_dev = wm8400_i2c_write; | 354 | ret = PTR_ERR(wm8400->regmap); |
355 | goto struct_err; | ||
356 | } | ||
357 | |||
409 | wm8400->dev = &i2c->dev; | 358 | wm8400->dev = &i2c->dev; |
410 | i2c_set_clientdata(i2c, wm8400); | 359 | i2c_set_clientdata(i2c, wm8400); |
411 | 360 | ||
412 | ret = wm8400_init(wm8400, i2c->dev.platform_data); | 361 | ret = wm8400_init(wm8400, i2c->dev.platform_data); |
413 | if (ret != 0) | 362 | if (ret != 0) |
414 | goto struct_err; | 363 | goto map_err; |
415 | 364 | ||
416 | return 0; | 365 | return 0; |
417 | 366 | ||
367 | map_err: | ||
368 | regmap_exit(wm8400->regmap); | ||
418 | struct_err: | 369 | struct_err: |
419 | kfree(wm8400); | 370 | kfree(wm8400); |
420 | err: | 371 | err: |
@@ -426,6 +377,7 @@ static int wm8400_i2c_remove(struct i2c_client *i2c) | |||
426 | struct wm8400 *wm8400 = i2c_get_clientdata(i2c); | 377 | struct wm8400 *wm8400 = i2c_get_clientdata(i2c); |
427 | 378 | ||
428 | wm8400_release(wm8400); | 379 | wm8400_release(wm8400); |
380 | regmap_exit(wm8400->regmap); | ||
429 | kfree(wm8400); | 381 | kfree(wm8400); |
430 | 382 | ||
431 | return 0; | 383 | return 0; |
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c index 9b01a22c3e70..5d6ba132837e 100644 --- a/drivers/mfd/wm8994-core.c +++ b/drivers/mfd/wm8994-core.c | |||
@@ -16,9 +16,11 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
19 | #include <linux/err.h> | ||
19 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
20 | #include <linux/mfd/core.h> | 21 | #include <linux/mfd/core.h> |
21 | #include <linux/pm_runtime.h> | 22 | #include <linux/pm_runtime.h> |
23 | #include <linux/regmap.h> | ||
22 | #include <linux/regulator/consumer.h> | 24 | #include <linux/regulator/consumer.h> |
23 | #include <linux/regulator/machine.h> | 25 | #include <linux/regulator/machine.h> |
24 | 26 | ||
@@ -29,22 +31,7 @@ | |||
29 | static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, | 31 | static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, |
30 | int bytes, void *dest) | 32 | int bytes, void *dest) |
31 | { | 33 | { |
32 | int ret, i; | 34 | return regmap_raw_read(wm8994->regmap, reg, dest, bytes); |
33 | u16 *buf = dest; | ||
34 | |||
35 | BUG_ON(bytes % 2); | ||
36 | BUG_ON(bytes <= 0); | ||
37 | |||
38 | ret = wm8994->read_dev(wm8994, reg, bytes, dest); | ||
39 | if (ret < 0) | ||
40 | return ret; | ||
41 | |||
42 | for (i = 0; i < bytes / 2; i++) { | ||
43 | dev_vdbg(wm8994->dev, "Read %04x from R%d(0x%x)\n", | ||
44 | be16_to_cpu(buf[i]), reg + i, reg + i); | ||
45 | } | ||
46 | |||
47 | return 0; | ||
48 | } | 35 | } |
49 | 36 | ||
50 | /** | 37 | /** |
@@ -55,19 +42,15 @@ static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, | |||
55 | */ | 42 | */ |
56 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) | 43 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) |
57 | { | 44 | { |
58 | unsigned short val; | 45 | unsigned int val; |
59 | int ret; | 46 | int ret; |
60 | 47 | ||
61 | mutex_lock(&wm8994->io_lock); | 48 | ret = regmap_read(wm8994->regmap, reg, &val); |
62 | |||
63 | ret = wm8994_read(wm8994, reg, 2, &val); | ||
64 | |||
65 | mutex_unlock(&wm8994->io_lock); | ||
66 | 49 | ||
67 | if (ret < 0) | 50 | if (ret < 0) |
68 | return ret; | 51 | return ret; |
69 | else | 52 | else |
70 | return be16_to_cpu(val); | 53 | return val; |
71 | } | 54 | } |
72 | EXPORT_SYMBOL_GPL(wm8994_reg_read); | 55 | EXPORT_SYMBOL_GPL(wm8994_reg_read); |
73 | 56 | ||
@@ -82,33 +65,13 @@ EXPORT_SYMBOL_GPL(wm8994_reg_read); | |||
82 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, | 65 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, |
83 | int count, u16 *buf) | 66 | int count, u16 *buf) |
84 | { | 67 | { |
85 | int ret; | 68 | return regmap_bulk_read(wm8994->regmap, reg, buf, count); |
86 | |||
87 | mutex_lock(&wm8994->io_lock); | ||
88 | |||
89 | ret = wm8994_read(wm8994, reg, count * 2, buf); | ||
90 | |||
91 | mutex_unlock(&wm8994->io_lock); | ||
92 | |||
93 | return ret; | ||
94 | } | 69 | } |
95 | EXPORT_SYMBOL_GPL(wm8994_bulk_read); | ||
96 | 70 | ||
97 | static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, | 71 | static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, |
98 | int bytes, const void *src) | 72 | int bytes, const void *src) |
99 | { | 73 | { |
100 | const u16 *buf = src; | 74 | return regmap_raw_write(wm8994->regmap, reg, src, bytes); |
101 | int i; | ||
102 | |||
103 | BUG_ON(bytes % 2); | ||
104 | BUG_ON(bytes <= 0); | ||
105 | |||
106 | for (i = 0; i < bytes / 2; i++) { | ||
107 | dev_vdbg(wm8994->dev, "Write %04x to R%d(0x%x)\n", | ||
108 | be16_to_cpu(buf[i]), reg + i, reg + i); | ||
109 | } | ||
110 | |||
111 | return wm8994->write_dev(wm8994, reg, bytes, src); | ||
112 | } | 75 | } |
113 | 76 | ||
114 | /** | 77 | /** |
@@ -121,17 +84,7 @@ static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, | |||
121 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, | 84 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, |
122 | unsigned short val) | 85 | unsigned short val) |
123 | { | 86 | { |
124 | int ret; | 87 | return regmap_write(wm8994->regmap, reg, val); |
125 | |||
126 | val = cpu_to_be16(val); | ||
127 | |||
128 | mutex_lock(&wm8994->io_lock); | ||
129 | |||
130 | ret = wm8994_write(wm8994, reg, 2, &val); | ||
131 | |||
132 | mutex_unlock(&wm8994->io_lock); | ||
133 | |||
134 | return ret; | ||
135 | } | 88 | } |
136 | EXPORT_SYMBOL_GPL(wm8994_reg_write); | 89 | EXPORT_SYMBOL_GPL(wm8994_reg_write); |
137 | 90 | ||
@@ -146,15 +99,7 @@ EXPORT_SYMBOL_GPL(wm8994_reg_write); | |||
146 | int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, | 99 | int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, |
147 | int count, const u16 *buf) | 100 | int count, const u16 *buf) |
148 | { | 101 | { |
149 | int ret; | 102 | return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16)); |
150 | |||
151 | mutex_lock(&wm8994->io_lock); | ||
152 | |||
153 | ret = wm8994_write(wm8994, reg, count * 2, buf); | ||
154 | |||
155 | mutex_unlock(&wm8994->io_lock); | ||
156 | |||
157 | return ret; | ||
158 | } | 103 | } |
159 | EXPORT_SYMBOL_GPL(wm8994_bulk_write); | 104 | EXPORT_SYMBOL_GPL(wm8994_bulk_write); |
160 | 105 | ||
@@ -169,28 +114,7 @@ EXPORT_SYMBOL_GPL(wm8994_bulk_write); | |||
169 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, | 114 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, |
170 | unsigned short mask, unsigned short val) | 115 | unsigned short mask, unsigned short val) |
171 | { | 116 | { |
172 | int ret; | 117 | return regmap_update_bits(wm8994->regmap, reg, mask, val); |
173 | u16 r; | ||
174 | |||
175 | mutex_lock(&wm8994->io_lock); | ||
176 | |||
177 | ret = wm8994_read(wm8994, reg, 2, &r); | ||
178 | if (ret < 0) | ||
179 | goto out; | ||
180 | |||
181 | r = be16_to_cpu(r); | ||
182 | |||
183 | r &= ~mask; | ||
184 | r |= val; | ||
185 | |||
186 | r = cpu_to_be16(r); | ||
187 | |||
188 | ret = wm8994_write(wm8994, reg, 2, &r); | ||
189 | |||
190 | out: | ||
191 | mutex_unlock(&wm8994->io_lock); | ||
192 | |||
193 | return ret; | ||
194 | } | 118 | } |
195 | EXPORT_SYMBOL_GPL(wm8994_set_bits); | 119 | EXPORT_SYMBOL_GPL(wm8994_set_bits); |
196 | 120 | ||
@@ -243,6 +167,18 @@ static struct mfd_cell wm8994_devs[] = { | |||
243 | * and should be handled via the standard regulator API supply | 167 | * and should be handled via the standard regulator API supply |
244 | * management. | 168 | * management. |
245 | */ | 169 | */ |
170 | static const char *wm1811_main_supplies[] = { | ||
171 | "DBVDD1", | ||
172 | "DBVDD2", | ||
173 | "DBVDD3", | ||
174 | "DCVDD", | ||
175 | "AVDD1", | ||
176 | "AVDD2", | ||
177 | "CPVDD", | ||
178 | "SPKVDD1", | ||
179 | "SPKVDD2", | ||
180 | }; | ||
181 | |||
246 | static const char *wm8994_main_supplies[] = { | 182 | static const char *wm8994_main_supplies[] = { |
247 | "DBVDD", | 183 | "DBVDD", |
248 | "DCVDD", | 184 | "DCVDD", |
@@ -424,6 +360,11 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) | |||
424 | } | 360 | } |
425 | #endif | 361 | #endif |
426 | 362 | ||
363 | static struct regmap_config wm8994_regmap_config = { | ||
364 | .reg_bits = 16, | ||
365 | .val_bits = 16, | ||
366 | }; | ||
367 | |||
427 | /* | 368 | /* |
428 | * Instantiate the generic non-control parts of the device. | 369 | * Instantiate the generic non-control parts of the device. |
429 | */ | 370 | */ |
@@ -433,7 +374,6 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
433 | const char *devname; | 374 | const char *devname; |
434 | int ret, i; | 375 | int ret, i; |
435 | 376 | ||
436 | mutex_init(&wm8994->io_lock); | ||
437 | dev_set_drvdata(wm8994->dev, wm8994); | 377 | dev_set_drvdata(wm8994->dev, wm8994); |
438 | 378 | ||
439 | /* Add the on-chip regulators first for bootstrapping */ | 379 | /* Add the on-chip regulators first for bootstrapping */ |
@@ -443,10 +383,13 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
443 | NULL, 0); | 383 | NULL, 0); |
444 | if (ret != 0) { | 384 | if (ret != 0) { |
445 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); | 385 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
446 | goto err; | 386 | goto err_regmap; |
447 | } | 387 | } |
448 | 388 | ||
449 | switch (wm8994->type) { | 389 | switch (wm8994->type) { |
390 | case WM1811: | ||
391 | wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); | ||
392 | break; | ||
450 | case WM8994: | 393 | case WM8994: |
451 | wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); | 394 | wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); |
452 | break; | 395 | break; |
@@ -455,7 +398,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
455 | break; | 398 | break; |
456 | default: | 399 | default: |
457 | BUG(); | 400 | BUG(); |
458 | goto err; | 401 | goto err_regmap; |
459 | } | 402 | } |
460 | 403 | ||
461 | wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * | 404 | wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * |
@@ -463,10 +406,14 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
463 | GFP_KERNEL); | 406 | GFP_KERNEL); |
464 | if (!wm8994->supplies) { | 407 | if (!wm8994->supplies) { |
465 | ret = -ENOMEM; | 408 | ret = -ENOMEM; |
466 | goto err; | 409 | goto err_regmap; |
467 | } | 410 | } |
468 | 411 | ||
469 | switch (wm8994->type) { | 412 | switch (wm8994->type) { |
413 | case WM1811: | ||
414 | for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++) | ||
415 | wm8994->supplies[i].supply = wm1811_main_supplies[i]; | ||
416 | break; | ||
470 | case WM8994: | 417 | case WM8994: |
471 | for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) | 418 | for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) |
472 | wm8994->supplies[i].supply = wm8994_main_supplies[i]; | 419 | wm8994->supplies[i].supply = wm8994_main_supplies[i]; |
@@ -477,7 +424,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
477 | break; | 424 | break; |
478 | default: | 425 | default: |
479 | BUG(); | 426 | BUG(); |
480 | goto err; | 427 | goto err_regmap; |
481 | } | 428 | } |
482 | 429 | ||
483 | ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, | 430 | ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, |
@@ -500,6 +447,13 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) | |||
500 | goto err_enable; | 447 | goto err_enable; |
501 | } | 448 | } |
502 | switch (ret) { | 449 | switch (ret) { |
450 | case 0x1811: | ||
451 | devname = "WM1811"; | ||
452 | if (wm8994->type != WM1811) | ||
453 | dev_warn(wm8994->dev, "Device registered as type %d\n", | ||
454 | wm8994->type); | ||
455 | wm8994->type = WM1811; | ||
456 | break; | ||
503 | case 0x8994: | 457 | case 0x8994: |
504 | devname = "WM8994"; | 458 | devname = "WM8994"; |
505 | if (wm8994->type != WM8994) | 459 | if (wm8994->type != WM8994) |
@@ -607,7 +561,8 @@ err_get: | |||
607 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); | 561 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); |
608 | err_supplies: | 562 | err_supplies: |
609 | kfree(wm8994->supplies); | 563 | kfree(wm8994->supplies); |
610 | err: | 564 | err_regmap: |
565 | regmap_exit(wm8994->regmap); | ||
611 | mfd_remove_devices(wm8994->dev); | 566 | mfd_remove_devices(wm8994->dev); |
612 | kfree(wm8994); | 567 | kfree(wm8994); |
613 | return ret; | 568 | return ret; |
@@ -622,62 +577,15 @@ static void wm8994_device_exit(struct wm8994 *wm8994) | |||
622 | wm8994->supplies); | 577 | wm8994->supplies); |
623 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); | 578 | regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); |
624 | kfree(wm8994->supplies); | 579 | kfree(wm8994->supplies); |
580 | regmap_exit(wm8994->regmap); | ||
625 | kfree(wm8994); | 581 | kfree(wm8994); |
626 | } | 582 | } |
627 | 583 | ||
628 | static int wm8994_i2c_read_device(struct wm8994 *wm8994, unsigned short reg, | ||
629 | int bytes, void *dest) | ||
630 | { | ||
631 | struct i2c_client *i2c = wm8994->control_data; | ||
632 | int ret; | ||
633 | u16 r = cpu_to_be16(reg); | ||
634 | |||
635 | ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
636 | if (ret < 0) | ||
637 | return ret; | ||
638 | if (ret != 2) | ||
639 | return -EIO; | ||
640 | |||
641 | ret = i2c_master_recv(i2c, dest, bytes); | ||
642 | if (ret < 0) | ||
643 | return ret; | ||
644 | if (ret != bytes) | ||
645 | return -EIO; | ||
646 | return 0; | ||
647 | } | ||
648 | |||
649 | static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, | ||
650 | int bytes, const void *src) | ||
651 | { | ||
652 | struct i2c_client *i2c = wm8994->control_data; | ||
653 | struct i2c_msg xfer[2]; | ||
654 | int ret; | ||
655 | |||
656 | reg = cpu_to_be16(reg); | ||
657 | |||
658 | xfer[0].addr = i2c->addr; | ||
659 | xfer[0].flags = 0; | ||
660 | xfer[0].len = 2; | ||
661 | xfer[0].buf = (char *)® | ||
662 | |||
663 | xfer[1].addr = i2c->addr; | ||
664 | xfer[1].flags = I2C_M_NOSTART; | ||
665 | xfer[1].len = bytes; | ||
666 | xfer[1].buf = (char *)src; | ||
667 | |||
668 | ret = i2c_transfer(i2c->adapter, xfer, 2); | ||
669 | if (ret < 0) | ||
670 | return ret; | ||
671 | if (ret != 2) | ||
672 | return -EIO; | ||
673 | |||
674 | return 0; | ||
675 | } | ||
676 | |||
677 | static int wm8994_i2c_probe(struct i2c_client *i2c, | 584 | static int wm8994_i2c_probe(struct i2c_client *i2c, |
678 | const struct i2c_device_id *id) | 585 | const struct i2c_device_id *id) |
679 | { | 586 | { |
680 | struct wm8994 *wm8994; | 587 | struct wm8994 *wm8994; |
588 | int ret; | ||
681 | 589 | ||
682 | wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); | 590 | wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); |
683 | if (wm8994 == NULL) | 591 | if (wm8994 == NULL) |
@@ -685,12 +593,18 @@ static int wm8994_i2c_probe(struct i2c_client *i2c, | |||
685 | 593 | ||
686 | i2c_set_clientdata(i2c, wm8994); | 594 | i2c_set_clientdata(i2c, wm8994); |
687 | wm8994->dev = &i2c->dev; | 595 | wm8994->dev = &i2c->dev; |
688 | wm8994->control_data = i2c; | ||
689 | wm8994->read_dev = wm8994_i2c_read_device; | ||
690 | wm8994->write_dev = wm8994_i2c_write_device; | ||
691 | wm8994->irq = i2c->irq; | 596 | wm8994->irq = i2c->irq; |
692 | wm8994->type = id->driver_data; | 597 | wm8994->type = id->driver_data; |
693 | 598 | ||
599 | wm8994->regmap = regmap_init_i2c(i2c, &wm8994_regmap_config); | ||
600 | if (IS_ERR(wm8994->regmap)) { | ||
601 | ret = PTR_ERR(wm8994->regmap); | ||
602 | dev_err(wm8994->dev, "Failed to allocate register map: %d\n", | ||
603 | ret); | ||
604 | kfree(wm8994); | ||
605 | return ret; | ||
606 | } | ||
607 | |||
694 | return wm8994_device_init(wm8994, i2c->irq); | 608 | return wm8994_device_init(wm8994, i2c->irq); |
695 | } | 609 | } |
696 | 610 | ||
@@ -704,6 +618,7 @@ static int wm8994_i2c_remove(struct i2c_client *i2c) | |||
704 | } | 618 | } |
705 | 619 | ||
706 | static const struct i2c_device_id wm8994_i2c_id[] = { | 620 | static const struct i2c_device_id wm8994_i2c_id[] = { |
621 | { "wm1811", WM1811 }, | ||
707 | { "wm8994", WM8994 }, | 622 | { "wm8994", WM8994 }, |
708 | { "wm8958", WM8958 }, | 623 | { "wm8958", WM8958 }, |
709 | { } | 624 | { } |