Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: Add regmap cache support for wm8350

Use the most simple possible transformation on the existing code so keep
the table sitting around, further patches in this series will delete the
existing cache code - the main purpose of this patch is to ensure that
we always have a cache for bisection.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Mark Brown and committed by
Samuel Ortiz
52b461b8 b0ab907d

+80 -17
+18 -11
drivers/mfd/wm8350-core.c
··· 32 32 #include <linux/mfd/wm8350/supply.h> 33 33 #include <linux/mfd/wm8350/wdt.h> 34 34 35 - #define WM8350_UNLOCK_KEY 0x0013 36 - #define WM8350_LOCK_KEY 0x0000 37 - 38 35 #define WM8350_CLOCK_CONTROL_1 0x28 39 36 #define WM8350_AIF_TEST 0x74 40 37 ··· 292 295 */ 293 296 int wm8350_reg_lock(struct wm8350 *wm8350) 294 297 { 295 - u16 key = WM8350_LOCK_KEY; 296 298 int ret; 297 299 300 + mutex_lock(&reg_lock_mutex); 301 + 298 302 ldbg(__func__); 299 - mutex_lock(&io_mutex); 300 - ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key); 303 + 304 + ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_LOCK_KEY); 301 305 if (ret) 302 306 dev_err(wm8350->dev, "lock failed\n"); 303 - mutex_unlock(&io_mutex); 307 + 308 + wm8350->unlocked = false; 309 + 310 + mutex_unlock(&reg_lock_mutex); 311 + 304 312 return ret; 305 313 } 306 314 EXPORT_SYMBOL_GPL(wm8350_reg_lock); ··· 321 319 */ 322 320 int wm8350_reg_unlock(struct wm8350 *wm8350) 323 321 { 324 - u16 key = WM8350_UNLOCK_KEY; 325 322 int ret; 326 323 324 + mutex_lock(&reg_lock_mutex); 325 + 327 326 ldbg(__func__); 328 - mutex_lock(&io_mutex); 329 - ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key); 327 + 328 + ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_UNLOCK_KEY); 330 329 if (ret) 331 330 dev_err(wm8350->dev, "unlock failed\n"); 332 - mutex_unlock(&io_mutex); 331 + 332 + wm8350->unlocked = true; 333 + 334 + mutex_unlock(&reg_lock_mutex); 335 + 333 336 return ret; 334 337 } 335 338 EXPORT_SYMBOL_GPL(wm8350_reg_unlock);
-5
drivers/mfd/wm8350-i2c.c
··· 23 23 #include <linux/regmap.h> 24 24 #include <linux/slab.h> 25 25 26 - static const struct regmap_config wm8350_regmap = { 27 - .reg_bits = 8, 28 - .val_bits = 16, 29 - }; 30 - 31 26 static int wm8350_i2c_probe(struct i2c_client *i2c, 32 27 const struct i2c_device_id *id) 33 28 {
+56
drivers/mfd/wm8350-regmap.c
··· 3433 3433 { 0x0000, 0x0000, 0x0000 }, /* R254 */ 3434 3434 { 0x0000, 0x0000, 0x0000 }, /* R255 */ 3435 3435 }; 3436 + 3437 + static bool wm8350_readable(struct device *dev, unsigned int reg) 3438 + { 3439 + return wm8350_reg_io_map[reg].readable; 3440 + } 3441 + 3442 + static bool wm8350_writeable(struct device *dev, unsigned int reg) 3443 + { 3444 + struct wm8350 *wm8350 = dev_get_drvdata(dev); 3445 + 3446 + if (!wm8350->unlocked) { 3447 + if ((reg >= WM8350_GPIO_FUNCTION_SELECT_1 && 3448 + reg <= WM8350_GPIO_FUNCTION_SELECT_4) || 3449 + (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 && 3450 + reg <= WM8350_BATTERY_CHARGER_CONTROL_3)) 3451 + return false; 3452 + } 3453 + 3454 + return wm8350_reg_io_map[reg].writable; 3455 + } 3456 + 3457 + static bool wm8350_volatile(struct device *dev, unsigned int reg) 3458 + { 3459 + return wm8350_reg_io_map[reg].vol; 3460 + } 3461 + 3462 + static bool wm8350_precious(struct device *dev, unsigned int reg) 3463 + { 3464 + switch (reg) { 3465 + case WM8350_SYSTEM_INTERRUPTS: 3466 + case WM8350_INT_STATUS_1: 3467 + case WM8350_INT_STATUS_2: 3468 + case WM8350_POWER_UP_INT_STATUS: 3469 + case WM8350_UNDER_VOLTAGE_INT_STATUS: 3470 + case WM8350_OVER_CURRENT_INT_STATUS: 3471 + case WM8350_GPIO_INT_STATUS: 3472 + case WM8350_COMPARATOR_INT_STATUS: 3473 + return true; 3474 + 3475 + default: 3476 + return false; 3477 + } 3478 + } 3479 + 3480 + const struct regmap_config wm8350_regmap = { 3481 + .reg_bits = 8, 3482 + .val_bits = 16, 3483 + 3484 + .cache_type = REGCACHE_RBTREE, 3485 + 3486 + .max_register = WM8350_MAX_REGISTER, 3487 + .readable_reg = wm8350_readable, 3488 + .writeable_reg = wm8350_writeable, 3489 + .volatile_reg = wm8350_volatile, 3490 + .precious_reg = wm8350_precious, 3491 + };
+6 -1
include/linux/mfd/wm8350/core.h
··· 17 17 #include <linux/mutex.h> 18 18 #include <linux/interrupt.h> 19 19 #include <linux/completion.h> 20 + #include <linux/regmap.h> 20 21 21 22 #include <linux/mfd/wm8350/audio.h> 22 23 #include <linux/mfd/wm8350/gpio.h> ··· 66 65 #define WM8350_STATE_MACHINE_STATUS 0xE9 67 66 68 67 #define WM8350_MAX_REGISTER 0xFF 68 + 69 + #define WM8350_UNLOCK_KEY 0x0013 70 + #define WM8350_LOCK_KEY 0x0000 69 71 70 72 /* 71 73 * Field Definitions. ··· 586 582 587 583 #define WM8350_NUM_IRQ_REGS 7 588 584 585 + extern const struct regmap_config wm8350_regmap; 589 586 struct wm8350_reg_access { 590 587 u16 readable; /* Mask of readable bits */ 591 588 u16 writable; /* Mask of writable bits */ ··· 607 602 extern const u16 wm8352_mode3_defaults[]; 608 603 609 604 struct wm8350; 610 - struct regmap; 611 605 612 606 struct wm8350_hwmon { 613 607 struct platform_device *pdev; ··· 619 615 /* device IO */ 620 616 struct regmap *regmap; 621 617 u16 *reg_cache; 618 + bool unlocked; 622 619 623 620 struct mutex auxadc_mutex; 624 621 struct completion auxadc_done;