aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 07:57:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 07:57:45 -0400
commit4e7e2a2008f5d8c49791c412849d5b0232d39bb3 (patch)
tree32c3fa2d5cefb388689cb795225022769bf7b413 /drivers/mfd
parent8a9ea3237e7eb5c25f09e429ad242ae5a3d5ea22 (diff)
parent7cccbdc84487616c3dbe493b04bfa1f362f4bc56 (diff)
Merge branch 'for-linus' of git://opensource.wolfsonmicro.com/regmap
* 'for-linus' of git://opensource.wolfsonmicro.com/regmap: (62 commits) mfd: Enable rbtree cache for wm831x devices regmap: Support some block operations on cached devices regmap: Allow caches for devices with no defaults regmap: Ensure rbtree syncs registers set to zero properly regmap: Allow rbtree to cache zero default values regmap: Warn on raw I/O as well as bulk reads that bypass cache regmap: Return a sensible error code if we fail to read the cache regmap: Use bsearch() to search the register defaults regmap: Fix doc comment regmap: Optimize the lookup path to use binary search regmap: Ensure we scream if we enable cache bypass/only at the same time regmap: Implement regcache_cache_bypass helper function regmap: Save/restore the bypass state upon syncing regmap: Lock the sync path, ensure we use the lockless _regmap_write() regmap: Fix apostrophe usage regmap: Make _regmap_write() global regmap: Fix lock used for regcache_cache_only() regmap: Grab the lock in regcache_cache_only() regmap: Modify map->cache_bypass directly regmap: Fix regcache_sync generic implementation ...
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/Kconfig3
-rw-r--r--drivers/mfd/wm831x-core.c437
-rw-r--r--drivers/mfd/wm831x-i2c.c76
-rw-r--r--drivers/mfd/wm831x-spi.c204
-rw-r--r--drivers/mfd/wm8400-core.c106
-rw-r--r--drivers/mfd/wm8994-core.c178
6 files changed, 507 insertions, 497 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 21574bdf485f..a67adcbd0fa1 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -404,6 +404,7 @@ config MFD_WM831X_I2C
404 bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C" 404 bool "Support Wolfson Microelectronics WM831x/2x PMICs with I2C"
405 select MFD_CORE 405 select MFD_CORE
406 select MFD_WM831X 406 select MFD_WM831X
407 select REGMAP_I2C
407 depends on I2C=y && GENERIC_HARDIRQS 408 depends on I2C=y && GENERIC_HARDIRQS
408 help 409 help
409 Support for the Wolfson Microelecronics WM831x and WM832x PMICs 410 Support for the Wolfson Microelecronics WM831x and WM832x PMICs
@@ -415,6 +416,7 @@ config MFD_WM831X_SPI
415 bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI" 416 bool "Support Wolfson Microelectronics WM831x/2x PMICs with SPI"
416 select MFD_CORE 417 select MFD_CORE
417 select MFD_WM831X 418 select MFD_WM831X
419 select REGMAP_SPI
418 depends on SPI_MASTER && GENERIC_HARDIRQS 420 depends on SPI_MASTER && GENERIC_HARDIRQS
419 help 421 help
420 Support for the Wolfson Microelecronics WM831x and WM832x PMICs 422 Support for the Wolfson Microelecronics WM831x and WM832x PMICs
@@ -488,6 +490,7 @@ config MFD_WM8350_I2C
488config MFD_WM8994 490config MFD_WM8994
489 bool "Support Wolfson Microelectronics WM8994" 491 bool "Support Wolfson Microelectronics WM8994"
490 select MFD_CORE 492 select MFD_CORE
493 select REGMAP_I2C
491 depends on I2C=y && GENERIC_HARDIRQS 494 depends on I2C=y && GENERIC_HARDIRQS
492 help 495 help
493 The WM8994 is a highly integrated hi-fi CODEC designed for 496 The WM8994 is a highly integrated hi-fi CODEC designed for
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index 282e76ab678f..0a2b8d41a702 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -18,12 +18,14 @@
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>
24#include <linux/mfd/wm831x/irq.h> 25#include <linux/mfd/wm831x/irq.h>
25#include <linux/mfd/wm831x/auxadc.h> 26#include <linux/mfd/wm831x/auxadc.h>
26#include <linux/mfd/wm831x/otp.h> 27#include <linux/mfd/wm831x/otp.h>
28#include <linux/mfd/wm831x/pmu.h>
27#include <linux/mfd/wm831x/regulator.h> 29#include <linux/mfd/wm831x/regulator.h>
28 30
29/* Current settings - values are 2*2^(reg_val/4) microamps. These are 31/* Current settings - values are 2*2^(reg_val/4) microamps. These are
@@ -160,27 +162,350 @@ int wm831x_reg_unlock(struct wm831x *wm831x)
160} 162}
161EXPORT_SYMBOL_GPL(wm831x_reg_unlock); 163EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
162 164
163static int wm831x_read(struct wm831x *wm831x, unsigned short reg, 165static bool wm831x_reg_readable(struct device *dev, unsigned int reg)
164 int bytes, void *dest)
165{ 166{
166 int ret, i; 167 switch (reg) {
167 u16 *buf = dest; 168 case WM831X_RESET_ID:
168 169 case WM831X_REVISION:
169 BUG_ON(bytes % 2); 170 case WM831X_PARENT_ID:
170 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}
171 343
172 ret = wm831x->read_dev(wm831x, reg, bytes, dest); 344static bool wm831x_reg_writeable(struct device *dev, unsigned int reg)
173 if (ret < 0) 345{
174 return ret; 346 struct wm831x *wm831x = dev_get_drvdata(dev);
175 347
176 for (i = 0; i < bytes / 2; i++) { 348 if (wm831x_reg_locked(wm831x, reg))
177 buf[i] = be16_to_cpu(buf[i]); 349 return false;
178 350
179 dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n", 351 switch (reg) {
180 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;
181 } 478 }
479}
182 480
183 return 0; 481static 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 }
184} 509}
185 510
186/** 511/**
@@ -191,14 +516,10 @@ static int wm831x_read(struct wm831x *wm831x, unsigned short reg,
191 */ 516 */
192int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) 517int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
193{ 518{
194 unsigned short val; 519 unsigned int val;
195 int ret; 520 int ret;
196 521
197 mutex_lock(&wm831x->io_lock); 522 ret = regmap_read(wm831x->regmap, reg, &val);
198
199 ret = wm831x_read(wm831x, reg, 2, &val);
200
201 mutex_unlock(&wm831x->io_lock);
202 523
203 if (ret < 0) 524 if (ret < 0)
204 return ret; 525 return ret;
@@ -218,15 +539,7 @@ EXPORT_SYMBOL_GPL(wm831x_reg_read);
218int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, 539int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
219 int count, u16 *buf) 540 int count, u16 *buf)
220{ 541{
221 int ret; 542 return regmap_bulk_read(wm831x->regmap, reg, buf, count);
222
223 mutex_lock(&wm831x->io_lock);
224
225 ret = wm831x_read(wm831x, reg, count * 2, buf);
226
227 mutex_unlock(&wm831x->io_lock);
228
229 return ret;
230} 543}
231EXPORT_SYMBOL_GPL(wm831x_bulk_read); 544EXPORT_SYMBOL_GPL(wm831x_bulk_read);
232 545
@@ -234,7 +547,7 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
234 int bytes, void *src) 547 int bytes, void *src)
235{ 548{
236 u16 *buf = src; 549 u16 *buf = src;
237 int i; 550 int i, ret;
238 551
239 BUG_ON(bytes % 2); 552 BUG_ON(bytes % 2);
240 BUG_ON(bytes <= 0); 553 BUG_ON(bytes <= 0);
@@ -245,11 +558,10 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
245 558
246 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",
247 buf[i], reg + i, reg + i); 560 buf[i], reg + i, reg + i);
248 561 ret = regmap_write(wm831x->regmap, reg + i, buf[i]);
249 buf[i] = cpu_to_be16(buf[i]);
250 } 562 }
251 563
252 return wm831x->write_dev(wm831x, reg, bytes, src); 564 return 0;
253} 565}
254 566
255/** 567/**
@@ -286,20 +598,14 @@ int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
286 unsigned short mask, unsigned short val) 598 unsigned short mask, unsigned short val)
287{ 599{
288 int ret; 600 int ret;
289 u16 r;
290 601
291 mutex_lock(&wm831x->io_lock); 602 mutex_lock(&wm831x->io_lock);
292 603
293 ret = wm831x_read(wm831x, reg, 2, &r); 604 if (!wm831x_reg_locked(wm831x, reg))
294 if (ret < 0) 605 ret = regmap_update_bits(wm831x->regmap, reg, mask, val);
295 goto out; 606 else
296 607 ret = -EPERM;
297 r &= ~mask;
298 r |= val & mask;
299
300 ret = wm831x_write(wm831x, reg, 2, &r);
301 608
302out:
303 mutex_unlock(&wm831x->io_lock); 609 mutex_unlock(&wm831x->io_lock);
304 610
305 return ret; 611 return ret;
@@ -1292,6 +1598,19 @@ static struct mfd_cell backlight_devs[] = {
1292 }, 1598 },
1293}; 1599};
1294 1600
1601struct 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};
1612EXPORT_SYMBOL_GPL(wm831x_regmap_config);
1613
1295/* 1614/*
1296 * Instantiate the generic non-control parts of the device. 1615 * Instantiate the generic non-control parts of the device.
1297 */ 1616 */
@@ -1305,11 +1624,12 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1305 mutex_init(&wm831x->io_lock); 1624 mutex_init(&wm831x->io_lock);
1306 mutex_init(&wm831x->key_lock); 1625 mutex_init(&wm831x->key_lock);
1307 dev_set_drvdata(wm831x->dev, wm831x); 1626 dev_set_drvdata(wm831x->dev, wm831x);
1627 wm831x->soft_shutdown = pdata->soft_shutdown;
1308 1628
1309 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); 1629 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1310 if (ret < 0) { 1630 if (ret < 0) {
1311 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);
1312 goto err; 1632 goto err_regmap;
1313 } 1633 }
1314 switch (ret) { 1634 switch (ret) {
1315 case 0x6204: 1635 case 0x6204:
@@ -1318,20 +1638,20 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1318 default: 1638 default:
1319 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);
1320 ret = -EINVAL; 1640 ret = -EINVAL;
1321 goto err; 1641 goto err_regmap;
1322 } 1642 }
1323 1643
1324 ret = wm831x_reg_read(wm831x, WM831X_REVISION); 1644 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1325 if (ret < 0) { 1645 if (ret < 0) {
1326 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); 1646 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1327 goto err; 1647 goto err_regmap;
1328 } 1648 }
1329 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; 1649 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1330 1650
1331 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); 1651 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1332 if (ret < 0) { 1652 if (ret < 0) {
1333 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);
1334 goto err; 1654 goto err_regmap;
1335 } 1655 }
1336 1656
1337 /* Some engineering samples do not have the ID set, rely on 1657 /* Some engineering samples do not have the ID set, rely on
@@ -1406,7 +1726,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1406 default: 1726 default:
1407 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); 1727 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1408 ret = -EINVAL; 1728 ret = -EINVAL;
1409 goto err; 1729 goto err_regmap;
1410 } 1730 }
1411 1731
1412 /* This will need revisiting in future but is OK for all 1732 /* This will need revisiting in future but is OK for all
@@ -1420,7 +1740,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1420 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); 1740 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1421 if (ret < 0) { 1741 if (ret < 0) {
1422 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);
1423 goto err; 1743 goto err_regmap;
1424 } 1744 }
1425 if (ret != 0) { 1745 if (ret != 0) {
1426 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",
@@ -1433,7 +1753,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1433 ret = pdata->pre_init(wm831x); 1753 ret = pdata->pre_init(wm831x);
1434 if (ret != 0) { 1754 if (ret != 0) {
1435 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); 1755 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
1436 goto err; 1756 goto err_regmap;
1437 } 1757 }
1438 } 1758 }
1439 1759
@@ -1456,7 +1776,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1456 1776
1457 ret = wm831x_irq_init(wm831x, irq); 1777 ret = wm831x_irq_init(wm831x, irq);
1458 if (ret != 0) 1778 if (ret != 0)
1459 goto err; 1779 goto err_regmap;
1460 1780
1461 wm831x_auxadc_init(wm831x); 1781 wm831x_auxadc_init(wm831x);
1462 1782
@@ -1552,8 +1872,9 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1552 1872
1553err_irq: 1873err_irq:
1554 wm831x_irq_exit(wm831x); 1874 wm831x_irq_exit(wm831x);
1555err: 1875err_regmap:
1556 mfd_remove_devices(wm831x->dev); 1876 mfd_remove_devices(wm831x->dev);
1877 regmap_exit(wm831x->regmap);
1557 kfree(wm831x); 1878 kfree(wm831x);
1558 return ret; 1879 return ret;
1559} 1880}
@@ -1565,6 +1886,7 @@ void wm831x_device_exit(struct wm831x *wm831x)
1565 if (wm831x->irq_base) 1886 if (wm831x->irq_base)
1566 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); 1887 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
1567 wm831x_irq_exit(wm831x); 1888 wm831x_irq_exit(wm831x);
1889 regmap_exit(wm831x->regmap);
1568 kfree(wm831x); 1890 kfree(wm831x);
1569} 1891}
1570 1892
@@ -1604,6 +1926,15 @@ int wm831x_device_suspend(struct wm831x *wm831x)
1604 return 0; 1926 return 0;
1605} 1927}
1606 1928
1929void wm831x_device_shutdown(struct wm831x *wm831x)
1930{
1931 if (wm831x->soft_shutdown) {
1932 dev_info(wm831x->dev, "Initiating shutdown...\n");
1933 wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0);
1934 }
1935}
1936EXPORT_SYMBOL_GPL(wm831x_device_shutdown);
1937
1607MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC"); 1938MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
1608MODULE_LICENSE("GPL"); 1939MODULE_LICENSE("GPL");
1609MODULE_AUTHOR("Mark Brown"); 1940MODULE_AUTHOR("Mark Brown");
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c
index a06cbc739716..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
25static 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 */
50static 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 *)&reg;
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
78static int wm831x_i2c_probe(struct i2c_client *i2c, 27static 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}
@@ -109,6 +65,13 @@ static int wm831x_i2c_suspend(struct device *dev)
109 return wm831x_device_suspend(wm831x); 65 return wm831x_device_suspend(wm831x);
110} 66}
111 67
68static void wm831x_i2c_shutdown(struct i2c_client *i2c)
69{
70 struct wm831x *wm831x = i2c_get_clientdata(i2c);
71
72 wm831x_device_shutdown(wm831x);
73}
74
112static const struct i2c_device_id wm831x_i2c_id[] = { 75static const struct i2c_device_id wm831x_i2c_id[] = {
113 { "wm8310", WM8310 }, 76 { "wm8310", WM8310 },
114 { "wm8311", WM8311 }, 77 { "wm8311", WM8311 },
@@ -133,6 +96,7 @@ static struct i2c_driver wm831x_i2c_driver = {
133 }, 96 },
134 .probe = wm831x_i2c_probe, 97 .probe = wm831x_i2c_probe,
135 .remove = wm831x_i2c_remove, 98 .remove = wm831x_i2c_remove,
99 .shutdown = wm831x_i2c_shutdown,
136 .id_table = wm831x_i2c_id, 100 .id_table = wm831x_i2c_id,
137}; 101};
138 102
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index eed8e4f7a5a1..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
22static 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
46static 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
67static int __devinit wm831x_spi_probe(struct spi_device *spi) 24static 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}
@@ -121,119 +68,50 @@ static int wm831x_spi_suspend(struct device *dev)
121 return wm831x_device_suspend(wm831x); 68 return wm831x_device_suspend(wm831x);
122} 69}
123 70
71static void wm831x_spi_shutdown(struct spi_device *spi)
72{
73 struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
74
75 wm831x_device_shutdown(wm831x);
76}
77
124static const struct dev_pm_ops wm831x_spi_pm = { 78static const struct dev_pm_ops wm831x_spi_pm = {
125 .freeze = wm831x_spi_suspend, 79 .freeze = wm831x_spi_suspend,
126 .suspend = wm831x_spi_suspend, 80 .suspend = wm831x_spi_suspend,
127}; 81};
128 82
129static struct spi_driver wm8310_spi_driver = { 83static const struct spi_device_id wm831x_spi_ids[] = {
130 .driver = { 84 { "wm8310", WM8310 },
131 .name = "wm8310", 85 { "wm8311", WM8311 },
132 .bus = &spi_bus_type, 86 { "wm8312", WM8312 },
133 .owner = THIS_MODULE, 87 { "wm8320", WM8320 },
134 .pm = &wm831x_spi_pm, 88 { "wm8321", WM8321 },
135 }, 89 { "wm8325", WM8325 },
136 .probe = wm831x_spi_probe, 90 { "wm8326", WM8326 },
137 .remove = __devexit_p(wm831x_spi_remove), 91 { },
138}; 92};
93MODULE_DEVICE_TABLE(spi, wm831x_spi_id);
139 94
140static struct spi_driver wm8311_spi_driver = { 95static struct spi_driver wm831x_spi_driver = {
141 .driver = { 96 .driver = {
142 .name = "wm8311", 97 .name = "wm831x",
143 .bus = &spi_bus_type,
144 .owner = THIS_MODULE,
145 .pm = &wm831x_spi_pm,
146 },
147 .probe = wm831x_spi_probe,
148 .remove = __devexit_p(wm831x_spi_remove),
149};
150
151static struct spi_driver wm8312_spi_driver = {
152 .driver = {
153 .name = "wm8312",
154 .bus = &spi_bus_type,
155 .owner = THIS_MODULE,
156 .pm = &wm831x_spi_pm,
157 },
158 .probe = wm831x_spi_probe,
159 .remove = __devexit_p(wm831x_spi_remove),
160};
161
162static struct spi_driver wm8320_spi_driver = {
163 .driver = {
164 .name = "wm8320",
165 .bus = &spi_bus_type,
166 .owner = THIS_MODULE,
167 .pm = &wm831x_spi_pm,
168 },
169 .probe = wm831x_spi_probe,
170 .remove = __devexit_p(wm831x_spi_remove),
171};
172
173static struct spi_driver wm8321_spi_driver = {
174 .driver = {
175 .name = "wm8321",
176 .bus = &spi_bus_type,
177 .owner = THIS_MODULE,
178 .pm = &wm831x_spi_pm,
179 },
180 .probe = wm831x_spi_probe,
181 .remove = __devexit_p(wm831x_spi_remove),
182};
183
184static struct spi_driver wm8325_spi_driver = {
185 .driver = {
186 .name = "wm8325",
187 .bus = &spi_bus_type,
188 .owner = THIS_MODULE,
189 .pm = &wm831x_spi_pm,
190 },
191 .probe = wm831x_spi_probe,
192 .remove = __devexit_p(wm831x_spi_remove),
193};
194
195static struct spi_driver wm8326_spi_driver = {
196 .driver = {
197 .name = "wm8326",
198 .bus = &spi_bus_type, 98 .bus = &spi_bus_type,
199 .owner = THIS_MODULE, 99 .owner = THIS_MODULE,
200 .pm = &wm831x_spi_pm, 100 .pm = &wm831x_spi_pm,
201 }, 101 },
102 .id_table = wm831x_spi_ids,
202 .probe = wm831x_spi_probe, 103 .probe = wm831x_spi_probe,
203 .remove = __devexit_p(wm831x_spi_remove), 104 .remove = __devexit_p(wm831x_spi_remove),
105 .shutdown = wm831x_spi_shutdown,
204}; 106};
205 107
206static int __init wm831x_spi_init(void) 108static int __init wm831x_spi_init(void)
207{ 109{
208 int ret; 110 int ret;
209 111
210 ret = spi_register_driver(&wm8310_spi_driver); 112 ret = spi_register_driver(&wm831x_spi_driver);
211 if (ret != 0)
212 pr_err("Failed to register WM8310 SPI driver: %d\n", ret);
213
214 ret = spi_register_driver(&wm8311_spi_driver);
215 if (ret != 0)
216 pr_err("Failed to register WM8311 SPI driver: %d\n", ret);
217
218 ret = spi_register_driver(&wm8312_spi_driver);
219 if (ret != 0)
220 pr_err("Failed to register WM8312 SPI driver: %d\n", ret);
221
222 ret = spi_register_driver(&wm8320_spi_driver);
223 if (ret != 0)
224 pr_err("Failed to register WM8320 SPI driver: %d\n", ret);
225
226 ret = spi_register_driver(&wm8321_spi_driver);
227 if (ret != 0)
228 pr_err("Failed to register WM8321 SPI driver: %d\n", ret);
229
230 ret = spi_register_driver(&wm8325_spi_driver);
231 if (ret != 0)
232 pr_err("Failed to register WM8325 SPI driver: %d\n", ret);
233
234 ret = spi_register_driver(&wm8326_spi_driver);
235 if (ret != 0) 113 if (ret != 0)
236 pr_err("Failed to register WM8326 SPI driver: %d\n", ret); 114 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
237 115
238 return 0; 116 return 0;
239} 117}
@@ -241,13 +119,7 @@ subsys_initcall(wm831x_spi_init);
241 119
242static void __exit wm831x_spi_exit(void) 120static void __exit wm831x_spi_exit(void)
243{ 121{
244 spi_unregister_driver(&wm8326_spi_driver); 122 spi_unregister_driver(&wm831x_spi_driver);
245 spi_unregister_driver(&wm8325_spi_driver);
246 spi_unregister_driver(&wm8321_spi_driver);
247 spi_unregister_driver(&wm8320_spi_driver);
248 spi_unregister_driver(&wm8312_spi_driver);
249 spi_unregister_driver(&wm8311_spi_driver);
250 spi_unregister_driver(&wm8310_spi_driver);
251} 123}
252module_exit(wm831x_spi_exit); 124module_exit(wm831x_spi_exit);
253 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
23static struct { 25static 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, &reg); 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) 333static const struct regmap_config wm8400_regmap_config = {
341static 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 = &reg;
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
368static 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)
394static int wm8400_i2c_probe(struct i2c_client *i2c, 340static 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
367map_err:
368 regmap_exit(wm8400->regmap);
418struct_err: 369struct_err:
419 kfree(wm8400); 370 kfree(wm8400);
420err: 371err:
@@ -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 96479c9b1728..bfde4e8ec638 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 @@
29static int wm8994_read(struct wm8994 *wm8994, unsigned short reg, 31static 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 */
56int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) 43int 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}
72EXPORT_SYMBOL_GPL(wm8994_reg_read); 55EXPORT_SYMBOL_GPL(wm8994_reg_read);
73 56
@@ -82,33 +65,13 @@ EXPORT_SYMBOL_GPL(wm8994_reg_read);
82int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, 65int 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}
95EXPORT_SYMBOL_GPL(wm8994_bulk_read);
96 70
97static int wm8994_write(struct wm8994 *wm8994, unsigned short reg, 71static 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,
121int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, 84int 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}
136EXPORT_SYMBOL_GPL(wm8994_reg_write); 89EXPORT_SYMBOL_GPL(wm8994_reg_write);
137 90
@@ -146,15 +99,7 @@ EXPORT_SYMBOL_GPL(wm8994_reg_write);
146int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, 99int 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}
159EXPORT_SYMBOL_GPL(wm8994_bulk_write); 104EXPORT_SYMBOL_GPL(wm8994_bulk_write);
160 105
@@ -169,28 +114,7 @@ EXPORT_SYMBOL_GPL(wm8994_bulk_write);
169int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, 114int 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
190out:
191 mutex_unlock(&wm8994->io_lock);
192
193 return ret;
194} 118}
195EXPORT_SYMBOL_GPL(wm8994_set_bits); 119EXPORT_SYMBOL_GPL(wm8994_set_bits);
196 120
@@ -378,6 +302,11 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
378} 302}
379#endif 303#endif
380 304
305static struct regmap_config wm8994_regmap_config = {
306 .reg_bits = 16,
307 .val_bits = 16,
308};
309
381/* 310/*
382 * Instantiate the generic non-control parts of the device. 311 * Instantiate the generic non-control parts of the device.
383 */ 312 */
@@ -387,7 +316,6 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
387 const char *devname; 316 const char *devname;
388 int ret, i; 317 int ret, i;
389 318
390 mutex_init(&wm8994->io_lock);
391 dev_set_drvdata(wm8994->dev, wm8994); 319 dev_set_drvdata(wm8994->dev, wm8994);
392 320
393 /* Add the on-chip regulators first for bootstrapping */ 321 /* Add the on-chip regulators first for bootstrapping */
@@ -397,7 +325,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
397 NULL, 0); 325 NULL, 0);
398 if (ret != 0) { 326 if (ret != 0) {
399 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 327 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
400 goto err; 328 goto err_regmap;
401 } 329 }
402 330
403 switch (wm8994->type) { 331 switch (wm8994->type) {
@@ -409,7 +337,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
409 break; 337 break;
410 default: 338 default:
411 BUG(); 339 BUG();
412 goto err; 340 goto err_regmap;
413 } 341 }
414 342
415 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * 343 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
@@ -417,7 +345,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
417 GFP_KERNEL); 345 GFP_KERNEL);
418 if (!wm8994->supplies) { 346 if (!wm8994->supplies) {
419 ret = -ENOMEM; 347 ret = -ENOMEM;
420 goto err; 348 goto err_regmap;
421 } 349 }
422 350
423 switch (wm8994->type) { 351 switch (wm8994->type) {
@@ -431,7 +359,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
431 break; 359 break;
432 default: 360 default:
433 BUG(); 361 BUG();
434 goto err; 362 goto err_regmap;
435 } 363 }
436 364
437 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, 365 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
@@ -554,7 +482,8 @@ err_get:
554 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); 482 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
555err_supplies: 483err_supplies:
556 kfree(wm8994->supplies); 484 kfree(wm8994->supplies);
557err: 485err_regmap:
486 regmap_exit(wm8994->regmap);
558 mfd_remove_devices(wm8994->dev); 487 mfd_remove_devices(wm8994->dev);
559 kfree(wm8994); 488 kfree(wm8994);
560 return ret; 489 return ret;
@@ -569,62 +498,15 @@ static void wm8994_device_exit(struct wm8994 *wm8994)
569 wm8994->supplies); 498 wm8994->supplies);
570 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); 499 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
571 kfree(wm8994->supplies); 500 kfree(wm8994->supplies);
501 regmap_exit(wm8994->regmap);
572 kfree(wm8994); 502 kfree(wm8994);
573} 503}
574 504
575static int wm8994_i2c_read_device(struct wm8994 *wm8994, unsigned short reg,
576 int bytes, void *dest)
577{
578 struct i2c_client *i2c = wm8994->control_data;
579 int ret;
580 u16 r = cpu_to_be16(reg);
581
582 ret = i2c_master_send(i2c, (unsigned char *)&r, 2);
583 if (ret < 0)
584 return ret;
585 if (ret != 2)
586 return -EIO;
587
588 ret = i2c_master_recv(i2c, dest, bytes);
589 if (ret < 0)
590 return ret;
591 if (ret != bytes)
592 return -EIO;
593 return 0;
594}
595
596static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg,
597 int bytes, const void *src)
598{
599 struct i2c_client *i2c = wm8994->control_data;
600 struct i2c_msg xfer[2];
601 int ret;
602
603 reg = cpu_to_be16(reg);
604
605 xfer[0].addr = i2c->addr;
606 xfer[0].flags = 0;
607 xfer[0].len = 2;
608 xfer[0].buf = (char *)&reg;
609
610 xfer[1].addr = i2c->addr;
611 xfer[1].flags = I2C_M_NOSTART;
612 xfer[1].len = bytes;
613 xfer[1].buf = (char *)src;
614
615 ret = i2c_transfer(i2c->adapter, xfer, 2);
616 if (ret < 0)
617 return ret;
618 if (ret != 2)
619 return -EIO;
620
621 return 0;
622}
623
624static int wm8994_i2c_probe(struct i2c_client *i2c, 505static int wm8994_i2c_probe(struct i2c_client *i2c,
625 const struct i2c_device_id *id) 506 const struct i2c_device_id *id)
626{ 507{
627 struct wm8994 *wm8994; 508 struct wm8994 *wm8994;
509 int ret;
628 510
629 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); 511 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL);
630 if (wm8994 == NULL) 512 if (wm8994 == NULL)
@@ -632,12 +514,18 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
632 514
633 i2c_set_clientdata(i2c, wm8994); 515 i2c_set_clientdata(i2c, wm8994);
634 wm8994->dev = &i2c->dev; 516 wm8994->dev = &i2c->dev;
635 wm8994->control_data = i2c;
636 wm8994->read_dev = wm8994_i2c_read_device;
637 wm8994->write_dev = wm8994_i2c_write_device;
638 wm8994->irq = i2c->irq; 517 wm8994->irq = i2c->irq;
639 wm8994->type = id->driver_data; 518 wm8994->type = id->driver_data;
640 519
520 wm8994->regmap = regmap_init_i2c(i2c, &wm8994_regmap_config);
521 if (IS_ERR(wm8994->regmap)) {
522 ret = PTR_ERR(wm8994->regmap);
523 dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
524 ret);
525 kfree(wm8994);
526 return ret;
527 }
528
641 return wm8994_device_init(wm8994, i2c->irq); 529 return wm8994_device_init(wm8994, i2c->irq);
642} 530}
643 531