diff options
| author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-06-03 08:37:24 -0400 |
|---|---|---|
| committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-07-08 18:16:10 -0400 |
| commit | 19d57ed5a308472a02e773f33c03ad4cb2ec6a9d (patch) | |
| tree | 31b3ec5f0716703f194136eb8ff7097bd09571cd | |
| parent | 7fdb5d32614f7784fc7c2b8e883eb4da26358a94 (diff) | |
mfd: Remove custom wm8350 cache implementation
Since none of the users now reference the cache directly we can happily
remove the custom cache code and rely on the regmap cache.
For simplicity we don't bother with the register defaults tables but
instead read the defaults from the device - regmap is capable of doing
this, unlike our old cache infrastructure. This saves a lot of code and
allows us to cache the device revision information too.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
| -rw-r--r-- | drivers/mfd/wm8350-core.c | 325 | ||||
| -rw-r--r-- | drivers/mfd/wm8350-regmap.c | 3166 | ||||
| -rw-r--r-- | include/linux/mfd/wm8350/core.h | 19 |
3 files changed, 18 insertions, 3492 deletions
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c index fadcbbe9e2ba..7c1ae24605d9 100644 --- a/drivers/mfd/wm8350-core.c +++ b/drivers/mfd/wm8350-core.c | |||
| @@ -60,181 +60,32 @@ | |||
| 60 | /* | 60 | /* |
| 61 | * WM8350 Device IO | 61 | * WM8350 Device IO |
| 62 | */ | 62 | */ |
| 63 | static DEFINE_MUTEX(io_mutex); | ||
| 64 | static DEFINE_MUTEX(reg_lock_mutex); | 63 | static DEFINE_MUTEX(reg_lock_mutex); |
| 65 | 64 | ||
| 66 | /* Perform a physical read from the device. | ||
| 67 | */ | ||
| 68 | static int wm8350_phys_read(struct wm8350 *wm8350, u8 reg, int num_regs, | ||
| 69 | u16 *dest) | ||
| 70 | { | ||
| 71 | int i, ret; | ||
| 72 | int bytes = num_regs * 2; | ||
| 73 | |||
| 74 | dev_dbg(wm8350->dev, "volatile read\n"); | ||
| 75 | ret = regmap_raw_read(wm8350->regmap, reg, dest, bytes); | ||
| 76 | |||
| 77 | for (i = reg; i < reg + num_regs; i++) { | ||
| 78 | /* Cache is CPU endian */ | ||
| 79 | dest[i - reg] = be16_to_cpu(dest[i - reg]); | ||
| 80 | |||
| 81 | /* Mask out non-readable bits */ | ||
| 82 | dest[i - reg] &= wm8350_reg_io_map[i].readable; | ||
| 83 | } | ||
| 84 | |||
| 85 | dump(num_regs, dest); | ||
| 86 | |||
| 87 | return ret; | ||
| 88 | } | ||
| 89 | |||
| 90 | static int wm8350_read(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *dest) | ||
| 91 | { | ||
| 92 | int i; | ||
| 93 | int end = reg + num_regs; | ||
| 94 | int ret = 0; | ||
| 95 | int bytes = num_regs * 2; | ||
| 96 | |||
| 97 | if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) { | ||
| 98 | dev_err(wm8350->dev, "invalid reg %x\n", | ||
| 99 | reg + num_regs - 1); | ||
| 100 | return -EINVAL; | ||
| 101 | } | ||
| 102 | |||
| 103 | dev_dbg(wm8350->dev, | ||
| 104 | "%s R%d(0x%2.2x) %d regs\n", __func__, reg, reg, num_regs); | ||
| 105 | |||
| 106 | #if WM8350_BUS_DEBUG | ||
| 107 | /* we can _safely_ read any register, but warn if read not supported */ | ||
| 108 | for (i = reg; i < end; i++) { | ||
| 109 | if (!wm8350_reg_io_map[i].readable) | ||
| 110 | dev_warn(wm8350->dev, | ||
| 111 | "reg R%d is not readable\n", i); | ||
| 112 | } | ||
| 113 | #endif | ||
| 114 | |||
| 115 | /* if any volatile registers are required, then read back all */ | ||
| 116 | for (i = reg; i < end; i++) | ||
| 117 | if (wm8350_reg_io_map[i].vol) | ||
| 118 | return wm8350_phys_read(wm8350, reg, num_regs, dest); | ||
| 119 | |||
| 120 | /* no volatiles, then cache is good */ | ||
| 121 | dev_dbg(wm8350->dev, "cache read\n"); | ||
| 122 | memcpy(dest, &wm8350->reg_cache[reg], bytes); | ||
| 123 | dump(num_regs, dest); | ||
| 124 | return ret; | ||
| 125 | } | ||
| 126 | |||
| 127 | static inline int is_reg_locked(struct wm8350 *wm8350, u8 reg) | ||
| 128 | { | ||
| 129 | if (reg == WM8350_SECURITY || | ||
| 130 | wm8350->reg_cache[WM8350_SECURITY] == WM8350_UNLOCK_KEY) | ||
| 131 | return 0; | ||
| 132 | |||
| 133 | if ((reg >= WM8350_GPIO_FUNCTION_SELECT_1 && | ||
| 134 | reg <= WM8350_GPIO_FUNCTION_SELECT_4) || | ||
| 135 | (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 && | ||
| 136 | reg <= WM8350_BATTERY_CHARGER_CONTROL_3)) | ||
| 137 | return 1; | ||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | |||
| 141 | static int wm8350_write(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *src) | ||
| 142 | { | ||
| 143 | int i; | ||
| 144 | int end = reg + num_regs; | ||
| 145 | int bytes = num_regs * 2; | ||
| 146 | |||
| 147 | if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) { | ||
| 148 | dev_err(wm8350->dev, "invalid reg %x\n", | ||
| 149 | reg + num_regs - 1); | ||
| 150 | return -EINVAL; | ||
| 151 | } | ||
| 152 | |||
| 153 | /* it's generally not a good idea to write to RO or locked registers */ | ||
| 154 | for (i = reg; i < end; i++) { | ||
| 155 | if (!wm8350_reg_io_map[i].writable) { | ||
| 156 | dev_err(wm8350->dev, | ||
| 157 | "attempted write to read only reg R%d\n", i); | ||
| 158 | return -EINVAL; | ||
| 159 | } | ||
| 160 | |||
| 161 | if (is_reg_locked(wm8350, i)) { | ||
| 162 | dev_err(wm8350->dev, | ||
| 163 | "attempted write to locked reg R%d\n", i); | ||
| 164 | return -EINVAL; | ||
| 165 | } | ||
| 166 | |||
| 167 | src[i - reg] &= wm8350_reg_io_map[i].writable; | ||
| 168 | |||
| 169 | wm8350->reg_cache[i] = | ||
| 170 | (wm8350->reg_cache[i] & ~wm8350_reg_io_map[i].writable) | ||
| 171 | | src[i - reg]; | ||
| 172 | |||
| 173 | src[i - reg] = cpu_to_be16(src[i - reg]); | ||
| 174 | } | ||
| 175 | |||
| 176 | /* Actually write it out */ | ||
| 177 | return regmap_raw_write(wm8350->regmap, reg, src, bytes); | ||
| 178 | } | ||
| 179 | |||
| 180 | /* | 65 | /* |
| 181 | * Safe read, modify, write methods | 66 | * Safe read, modify, write methods |
| 182 | */ | 67 | */ |
| 183 | int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask) | 68 | int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask) |
| 184 | { | 69 | { |
| 185 | u16 data; | 70 | return regmap_update_bits(wm8350->regmap, reg, mask, 0); |
| 186 | int err; | ||
| 187 | |||
| 188 | mutex_lock(&io_mutex); | ||
| 189 | err = wm8350_read(wm8350, reg, 1, &data); | ||
| 190 | if (err) { | ||
| 191 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | ||
| 192 | goto out; | ||
| 193 | } | ||
| 194 | |||
| 195 | data &= ~mask; | ||
| 196 | err = wm8350_write(wm8350, reg, 1, &data); | ||
| 197 | if (err) | ||
| 198 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); | ||
| 199 | out: | ||
| 200 | mutex_unlock(&io_mutex); | ||
| 201 | return err; | ||
| 202 | } | 71 | } |
| 203 | EXPORT_SYMBOL_GPL(wm8350_clear_bits); | 72 | EXPORT_SYMBOL_GPL(wm8350_clear_bits); |
| 204 | 73 | ||
| 205 | int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask) | 74 | int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask) |
| 206 | { | 75 | { |
| 207 | u16 data; | 76 | return regmap_update_bits(wm8350->regmap, reg, mask, mask); |
| 208 | int err; | ||
| 209 | |||
| 210 | mutex_lock(&io_mutex); | ||
| 211 | err = wm8350_read(wm8350, reg, 1, &data); | ||
| 212 | if (err) { | ||
| 213 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | ||
| 214 | goto out; | ||
| 215 | } | ||
| 216 | |||
| 217 | data |= mask; | ||
| 218 | err = wm8350_write(wm8350, reg, 1, &data); | ||
| 219 | if (err) | ||
| 220 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); | ||
| 221 | out: | ||
| 222 | mutex_unlock(&io_mutex); | ||
| 223 | return err; | ||
| 224 | } | 77 | } |
| 225 | EXPORT_SYMBOL_GPL(wm8350_set_bits); | 78 | EXPORT_SYMBOL_GPL(wm8350_set_bits); |
| 226 | 79 | ||
| 227 | u16 wm8350_reg_read(struct wm8350 *wm8350, int reg) | 80 | u16 wm8350_reg_read(struct wm8350 *wm8350, int reg) |
| 228 | { | 81 | { |
| 229 | u16 data; | 82 | unsigned int data; |
| 230 | int err; | 83 | int err; |
| 231 | 84 | ||
| 232 | mutex_lock(&io_mutex); | 85 | err = regmap_read(wm8350->regmap, reg, &data); |
| 233 | err = wm8350_read(wm8350, reg, 1, &data); | ||
| 234 | if (err) | 86 | if (err) |
| 235 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); | 87 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); |
| 236 | 88 | ||
| 237 | mutex_unlock(&io_mutex); | ||
| 238 | return data; | ||
