Skip to content

Commit 52b461b

Browse files
broonieSamuel Ortiz
authored andcommitted
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>
1 parent b0ab907 commit 52b461b

4 files changed

Lines changed: 80 additions & 17 deletions

File tree

‎drivers/mfd/wm8350-core.c‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
#include <linux/mfd/wm8350/supply.h>
3333
#include <linux/mfd/wm8350/wdt.h>
3434

35-
#define WM8350_UNLOCK_KEY 0x0013
36-
#define WM8350_LOCK_KEY 0x0000
37-
3835
#define WM8350_CLOCK_CONTROL_1 0x28
3936
#define WM8350_AIF_TEST 0x74
4037

@@ -295,15 +292,20 @@ EXPORT_SYMBOL_GPL(wm8350_block_write);
295292
*/
296293
int wm8350_reg_lock(struct wm8350 *wm8350)
297294
{
298-
u16 key = WM8350_LOCK_KEY;
299295
int ret;
300296

297+
mutex_lock(&reg_lock_mutex);
298+
301299
ldbg(__func__);
302-
mutex_lock(&io_mutex);
303-
ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
300+
301+
ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_LOCK_KEY);
304302
if (ret)
305303
dev_err(wm8350->dev, "lock failed\n");
306-
mutex_unlock(&io_mutex);
304+
305+
wm8350->unlocked = false;
306+
307+
mutex_unlock(&reg_lock_mutex);
308+
307309
return ret;
308310
}
309311
EXPORT_SYMBOL_GPL(wm8350_reg_lock);
@@ -319,15 +321,20 @@ EXPORT_SYMBOL_GPL(wm8350_reg_lock);
319321
*/
320322
int wm8350_reg_unlock(struct wm8350 *wm8350)
321323
{
322-
u16 key = WM8350_UNLOCK_KEY;
323324
int ret;
324325

326+
mutex_lock(&reg_lock_mutex);
327+
325328
ldbg(__func__);
326-
mutex_lock(&io_mutex);
327-
ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
329+
330+
ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_UNLOCK_KEY);
328331
if (ret)
329332
dev_err(wm8350->dev, "unlock failed\n");
330-
mutex_unlock(&io_mutex);
333+
334+
wm8350->unlocked = true;
335+
336+
mutex_unlock(&reg_lock_mutex);
337+
331338
return ret;
332339
}
333340
EXPORT_SYMBOL_GPL(wm8350_reg_unlock);

‎drivers/mfd/wm8350-i2c.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
#include <linux/regmap.h>
2424
#include <linux/slab.h>
2525

26-
static const struct regmap_config wm8350_regmap = {
27-
.reg_bits = 8,
28-
.val_bits = 16,
29-
};
30-
3126
static int wm8350_i2c_probe(struct i2c_client *i2c,
3227
const struct i2c_device_id *id)
3328
{

‎drivers/mfd/wm8350-regmap.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,3 +3433,59 @@ const struct wm8350_reg_access wm8350_reg_io_map[] = {
34333433
{ 0x0000, 0x0000, 0x0000 }, /* R254 */
34343434
{ 0x0000, 0x0000, 0x0000 }, /* R255 */
34353435
};
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+
};

‎include/linux/mfd/wm8350/core.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/mutex.h>
1818
#include <linux/interrupt.h>
1919
#include <linux/completion.h>
20+
#include <linux/regmap.h>
2021

2122
#include <linux/mfd/wm8350/audio.h>
2223
#include <linux/mfd/wm8350/gpio.h>
@@ -66,6 +67,9 @@
6667

6768
#define WM8350_MAX_REGISTER 0xFF
6869

70+
#define WM8350_UNLOCK_KEY 0x0013
71+
#define WM8350_LOCK_KEY 0x0000
72+
6973
/*
7074
* Field Definitions.
7175
*/
@@ -582,6 +586,7 @@
582586

583587
#define WM8350_NUM_IRQ_REGS 7
584588

589+
extern const struct regmap_config wm8350_regmap;
585590
struct wm8350_reg_access {
586591
u16 readable; /* Mask of readable bits */
587592
u16 writable; /* Mask of writable bits */
@@ -602,7 +607,6 @@ extern const u16 wm8352_mode2_defaults[];
602607
extern const u16 wm8352_mode3_defaults[];
603608

604609
struct wm8350;
605-
struct regmap;
606610

607611
struct wm8350_hwmon {
608612
struct platform_device *pdev;
@@ -615,6 +619,7 @@ struct wm8350 {
615619
/* device IO */
616620
struct regmap *regmap;
617621
u16 *reg_cache;
622+
bool unlocked;
618623

619624
struct mutex auxadc_mutex;
620625
struct completion auxadc_done;

0 commit comments

Comments
 (0)