Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Arizona core driver |
| 3 | * |
| 4 | * Copyright 2012 Wolfson Microelectronics plc |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/delay.h> |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 14 | #include <linux/err.h> |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 15 | #include <linux/gpio.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/mfd/core.h> |
| 18 | #include <linux/module.h> |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 19 | #include <linux/of.h> |
| 20 | #include <linux/of_device.h> |
| 21 | #include <linux/of_gpio.h> |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 22 | #include <linux/pm_runtime.h> |
| 23 | #include <linux/regmap.h> |
| 24 | #include <linux/regulator/consumer.h> |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 25 | #include <linux/regulator/machine.h> |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 26 | #include <linux/slab.h> |
Richard Fitzgerald | ae05ea36 | 2015-10-02 13:29:13 +0100 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 28 | |
| 29 | #include <linux/mfd/arizona/core.h> |
| 30 | #include <linux/mfd/arizona/registers.h> |
| 31 | |
| 32 | #include "arizona.h" |
| 33 | |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 34 | static const char * const wm5102_core_supplies[] = { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 35 | "AVDD", |
| 36 | "DBVDD1", |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | int arizona_clk32k_enable(struct arizona *arizona) |
| 40 | { |
| 41 | int ret = 0; |
| 42 | |
| 43 | mutex_lock(&arizona->clk_lock); |
| 44 | |
| 45 | arizona->clk32k_ref++; |
| 46 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 47 | if (arizona->clk32k_ref == 1) { |
| 48 | switch (arizona->pdata.clk32k_src) { |
| 49 | case ARIZONA_32KZ_MCLK1: |
| 50 | ret = pm_runtime_get_sync(arizona->dev); |
| 51 | if (ret != 0) |
| 52 | goto out; |
| 53 | break; |
| 54 | } |
| 55 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 56 | ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 57 | ARIZONA_CLK_32K_ENA, |
| 58 | ARIZONA_CLK_32K_ENA); |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 59 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 60 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 61 | out: |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 62 | if (ret != 0) |
| 63 | arizona->clk32k_ref--; |
| 64 | |
| 65 | mutex_unlock(&arizona->clk_lock); |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | EXPORT_SYMBOL_GPL(arizona_clk32k_enable); |
| 70 | |
| 71 | int arizona_clk32k_disable(struct arizona *arizona) |
| 72 | { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 73 | mutex_lock(&arizona->clk_lock); |
| 74 | |
| 75 | BUG_ON(arizona->clk32k_ref <= 0); |
| 76 | |
| 77 | arizona->clk32k_ref--; |
| 78 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 79 | if (arizona->clk32k_ref == 0) { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 80 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 81 | ARIZONA_CLK_32K_ENA, 0); |
| 82 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 83 | switch (arizona->pdata.clk32k_src) { |
| 84 | case ARIZONA_32KZ_MCLK1: |
| 85 | pm_runtime_put_sync(arizona->dev); |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 90 | mutex_unlock(&arizona->clk_lock); |
| 91 | |
Javier Martinez Canillas | a260fba | 2015-09-29 13:26:02 +0200 | [diff] [blame] | 92 | return 0; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 93 | } |
| 94 | EXPORT_SYMBOL_GPL(arizona_clk32k_disable); |
| 95 | |
| 96 | static irqreturn_t arizona_clkgen_err(int irq, void *data) |
| 97 | { |
| 98 | struct arizona *arizona = data; |
| 99 | |
| 100 | dev_err(arizona->dev, "CLKGEN error\n"); |
| 101 | |
| 102 | return IRQ_HANDLED; |
| 103 | } |
| 104 | |
| 105 | static irqreturn_t arizona_underclocked(int irq, void *data) |
| 106 | { |
| 107 | struct arizona *arizona = data; |
| 108 | unsigned int val; |
| 109 | int ret; |
| 110 | |
| 111 | ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8, |
| 112 | &val); |
| 113 | if (ret != 0) { |
| 114 | dev_err(arizona->dev, "Failed to read underclock status: %d\n", |
| 115 | ret); |
| 116 | return IRQ_NONE; |
| 117 | } |
| 118 | |
| 119 | if (val & ARIZONA_AIF3_UNDERCLOCKED_STS) |
| 120 | dev_err(arizona->dev, "AIF3 underclocked\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 121 | if (val & ARIZONA_AIF2_UNDERCLOCKED_STS) |
Charles Keepax | 3ebef34 | 2012-11-20 13:46:20 +0900 | [diff] [blame] | 122 | dev_err(arizona->dev, "AIF2 underclocked\n"); |
| 123 | if (val & ARIZONA_AIF1_UNDERCLOCKED_STS) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 124 | dev_err(arizona->dev, "AIF1 underclocked\n"); |
Charles Keepax | 6e440d2 | 2014-07-15 11:21:49 +0100 | [diff] [blame] | 125 | if (val & ARIZONA_ISRC3_UNDERCLOCKED_STS) |
| 126 | dev_err(arizona->dev, "ISRC3 underclocked\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 127 | if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS) |
| 128 | dev_err(arizona->dev, "ISRC2 underclocked\n"); |
| 129 | if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS) |
| 130 | dev_err(arizona->dev, "ISRC1 underclocked\n"); |
| 131 | if (val & ARIZONA_FX_UNDERCLOCKED_STS) |
| 132 | dev_err(arizona->dev, "FX underclocked\n"); |
| 133 | if (val & ARIZONA_ASRC_UNDERCLOCKED_STS) |
| 134 | dev_err(arizona->dev, "ASRC underclocked\n"); |
| 135 | if (val & ARIZONA_DAC_UNDERCLOCKED_STS) |
| 136 | dev_err(arizona->dev, "DAC underclocked\n"); |
| 137 | if (val & ARIZONA_ADC_UNDERCLOCKED_STS) |
| 138 | dev_err(arizona->dev, "ADC underclocked\n"); |
| 139 | if (val & ARIZONA_MIXER_UNDERCLOCKED_STS) |
Mark Brown | 648a988 | 2013-01-28 00:32:53 +0800 | [diff] [blame] | 140 | dev_err(arizona->dev, "Mixer dropped sample\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 141 | |
| 142 | return IRQ_HANDLED; |
| 143 | } |
| 144 | |
| 145 | static irqreturn_t arizona_overclocked(int irq, void *data) |
| 146 | { |
| 147 | struct arizona *arizona = data; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 148 | unsigned int val[3]; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 149 | int ret; |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 150 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 151 | ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6, |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 152 | &val[0], 3); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 153 | if (ret != 0) { |
| 154 | dev_err(arizona->dev, "Failed to read overclock status: %d\n", |
| 155 | ret); |
| 156 | return IRQ_NONE; |
| 157 | } |
| 158 | |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 159 | switch (arizona->type) { |
| 160 | case WM8998: |
| 161 | case WM1814: |
| 162 | /* Some bits are shifted on WM8998, |
| 163 | * rearrange to match the standard bit layout |
| 164 | */ |
| 165 | val[0] = ((val[0] & 0x60e0) >> 1) | |
| 166 | ((val[0] & 0x1e00) >> 2) | |
| 167 | (val[0] & 0x000f); |
| 168 | break; |
| 169 | default: |
| 170 | break; |
| 171 | } |
| 172 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 173 | if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS) |
| 174 | dev_err(arizona->dev, "PWM overclocked\n"); |
| 175 | if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS) |
| 176 | dev_err(arizona->dev, "FX core overclocked\n"); |
| 177 | if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS) |
| 178 | dev_err(arizona->dev, "DAC SYS overclocked\n"); |
| 179 | if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS) |
| 180 | dev_err(arizona->dev, "DAC WARP overclocked\n"); |
| 181 | if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS) |
| 182 | dev_err(arizona->dev, "ADC overclocked\n"); |
| 183 | if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS) |
| 184 | dev_err(arizona->dev, "Mixer overclocked\n"); |
| 185 | if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS) |
| 186 | dev_err(arizona->dev, "AIF3 overclocked\n"); |
| 187 | if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS) |
| 188 | dev_err(arizona->dev, "AIF2 overclocked\n"); |
| 189 | if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS) |
| 190 | dev_err(arizona->dev, "AIF1 overclocked\n"); |
| 191 | if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS) |
| 192 | dev_err(arizona->dev, "Pad control overclocked\n"); |
| 193 | |
| 194 | if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS) |
| 195 | dev_err(arizona->dev, "Slimbus subsystem overclocked\n"); |
| 196 | if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS) |
| 197 | dev_err(arizona->dev, "Slimbus async overclocked\n"); |
| 198 | if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS) |
| 199 | dev_err(arizona->dev, "Slimbus sync overclocked\n"); |
| 200 | if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS) |
| 201 | dev_err(arizona->dev, "ASRC async system overclocked\n"); |
| 202 | if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS) |
| 203 | dev_err(arizona->dev, "ASRC async WARP overclocked\n"); |
| 204 | if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS) |
| 205 | dev_err(arizona->dev, "ASRC sync system overclocked\n"); |
| 206 | if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS) |
| 207 | dev_err(arizona->dev, "ASRC sync WARP overclocked\n"); |
| 208 | if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS) |
| 209 | dev_err(arizona->dev, "DSP1 overclocked\n"); |
Charles Keepax | 6e440d2 | 2014-07-15 11:21:49 +0100 | [diff] [blame] | 210 | if (val[1] & ARIZONA_ISRC3_OVERCLOCKED_STS) |
| 211 | dev_err(arizona->dev, "ISRC3 overclocked\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 212 | if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS) |
| 213 | dev_err(arizona->dev, "ISRC2 overclocked\n"); |
| 214 | if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS) |
| 215 | dev_err(arizona->dev, "ISRC1 overclocked\n"); |
| 216 | |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 217 | if (val[2] & ARIZONA_SPDIF_OVERCLOCKED_STS) |
| 218 | dev_err(arizona->dev, "SPDIF overclocked\n"); |
| 219 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 220 | return IRQ_HANDLED; |
| 221 | } |
| 222 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 223 | static int arizona_poll_reg(struct arizona *arizona, |
| 224 | int timeout, unsigned int reg, |
| 225 | unsigned int mask, unsigned int target) |
| 226 | { |
| 227 | unsigned int val = 0; |
| 228 | int ret, i; |
| 229 | |
| 230 | for (i = 0; i < timeout; i++) { |
| 231 | ret = regmap_read(arizona->regmap, reg, &val); |
| 232 | if (ret != 0) { |
| 233 | dev_err(arizona->dev, "Failed to read reg %u: %d\n", |
| 234 | reg, ret); |
| 235 | continue; |
| 236 | } |
| 237 | |
| 238 | if ((val & mask) == target) |
| 239 | return 0; |
| 240 | |
| 241 | msleep(1); |
| 242 | } |
| 243 | |
| 244 | dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val); |
| 245 | return -ETIMEDOUT; |
| 246 | } |
| 247 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 248 | static int arizona_wait_for_boot(struct arizona *arizona) |
| 249 | { |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 250 | int ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * We can't use an interrupt as we need to runtime resume to do so, |
| 254 | * we won't race with the interrupt handler as it'll be blocked on |
| 255 | * runtime resume. |
| 256 | */ |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 257 | ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5, |
| 258 | ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 259 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 260 | if (!ret) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 261 | regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5, |
| 262 | ARIZONA_BOOT_DONE_STS); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 263 | |
| 264 | pm_runtime_mark_last_busy(arizona->dev); |
| 265 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 266 | return ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Charles Keepax | 2229875 | 2015-05-11 13:58:02 +0100 | [diff] [blame] | 269 | static inline void arizona_enable_reset(struct arizona *arizona) |
| 270 | { |
| 271 | if (arizona->pdata.reset) |
| 272 | gpio_set_value_cansleep(arizona->pdata.reset, 0); |
| 273 | } |
| 274 | |
| 275 | static void arizona_disable_reset(struct arizona *arizona) |
| 276 | { |
| 277 | if (arizona->pdata.reset) { |
Charles Keepax | 121c075 | 2015-05-11 13:58:10 +0100 | [diff] [blame] | 278 | switch (arizona->type) { |
| 279 | case WM5110: |
| 280 | case WM8280: |
| 281 | /* Meet requirements for minimum reset duration */ |
| 282 | msleep(5); |
| 283 | break; |
| 284 | default: |
| 285 | break; |
| 286 | } |
| 287 | |
Charles Keepax | 2229875 | 2015-05-11 13:58:02 +0100 | [diff] [blame] | 288 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
| 289 | msleep(1); |
| 290 | } |
| 291 | } |
| 292 | |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 293 | struct arizona_sysclk_state { |
| 294 | unsigned int fll; |
| 295 | unsigned int sysclk; |
| 296 | }; |
| 297 | |
| 298 | static int arizona_enable_freerun_sysclk(struct arizona *arizona, |
| 299 | struct arizona_sysclk_state *state) |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 300 | { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 301 | int ret, err; |
| 302 | |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 303 | /* Cache existing FLL and SYSCLK settings */ |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 304 | ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 305 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 306 | dev_err(arizona->dev, "Failed to cache FLL settings: %d\n", |
| 307 | ret); |
| 308 | return ret; |
| 309 | } |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 310 | ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, |
| 311 | &state->sysclk); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 312 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 313 | dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n", |
| 314 | ret); |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | /* Start up SYSCLK using the FLL in free running mode */ |
| 319 | ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, |
| 320 | ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 321 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 322 | dev_err(arizona->dev, |
| 323 | "Failed to start FLL in freerunning mode: %d\n", |
| 324 | ret); |
| 325 | return ret; |
| 326 | } |
| 327 | ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5, |
| 328 | ARIZONA_FLL1_CLOCK_OK_STS, |
| 329 | ARIZONA_FLL1_CLOCK_OK_STS); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 330 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 331 | ret = -ETIMEDOUT; |
| 332 | goto err_fll; |
| 333 | } |
| 334 | |
| 335 | ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 336 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 337 | dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret); |
| 338 | goto err_fll; |
| 339 | } |
| 340 | |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 341 | return 0; |
| 342 | |
| 343 | err_fll: |
| 344 | err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll); |
| 345 | if (err) |
| 346 | dev_err(arizona->dev, |
| 347 | "Failed to re-apply old FLL settings: %d\n", err); |
| 348 | |
| 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | static int arizona_disable_freerun_sysclk(struct arizona *arizona, |
| 353 | struct arizona_sysclk_state *state) |
| 354 | { |
| 355 | int ret; |
| 356 | |
| 357 | ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, |
| 358 | state->sysclk); |
| 359 | if (ret) { |
| 360 | dev_err(arizona->dev, |
| 361 | "Failed to re-apply old SYSCLK settings: %d\n", ret); |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll); |
| 366 | if (ret) { |
| 367 | dev_err(arizona->dev, |
| 368 | "Failed to re-apply old FLL settings: %d\n", ret); |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static int wm5102_apply_hardware_patch(struct arizona *arizona) |
| 376 | { |
| 377 | struct arizona_sysclk_state state; |
| 378 | int err, ret; |
| 379 | |
| 380 | ret = arizona_enable_freerun_sysclk(arizona, &state); |
| 381 | if (ret) |
| 382 | return ret; |
| 383 | |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 384 | /* Start the write sequencer and wait for it to finish */ |
| 385 | ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 386 | ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160); |
| 387 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 388 | dev_err(arizona->dev, "Failed to start write sequencer: %d\n", |
| 389 | ret); |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 390 | goto err; |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 391 | } |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 392 | |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 393 | ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1, |
| 394 | ARIZONA_WSEQ_BUSY, 0); |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 395 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 396 | regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 397 | ARIZONA_WSEQ_ABORT); |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 398 | ret = -ETIMEDOUT; |
| 399 | } |
| 400 | |
Charles Keepax | 3850e3e | 2015-05-11 13:58:05 +0100 | [diff] [blame] | 401 | err: |
| 402 | err = arizona_disable_freerun_sysclk(arizona, &state); |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 403 | |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 404 | return ret ?: err; |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Charles Keepax | 882bc46 | 2015-05-11 13:58:06 +0100 | [diff] [blame] | 407 | /* |
| 408 | * Register patch to some of the CODECs internal write sequences |
| 409 | * to ensure a clean exit from the low power sleep state. |
| 410 | */ |
Nariman Poushin | 8019ff6 | 2015-07-16 16:36:21 +0100 | [diff] [blame] | 411 | static const struct reg_sequence wm5110_sleep_patch[] = { |
Charles Keepax | 882bc46 | 2015-05-11 13:58:06 +0100 | [diff] [blame] | 412 | { 0x337A, 0xC100 }, |
| 413 | { 0x337B, 0x0041 }, |
| 414 | { 0x3300, 0xA210 }, |
| 415 | { 0x3301, 0x050C }, |
| 416 | }; |
| 417 | |
| 418 | static int wm5110_apply_sleep_patch(struct arizona *arizona) |
| 419 | { |
| 420 | struct arizona_sysclk_state state; |
| 421 | int err, ret; |
| 422 | |
| 423 | ret = arizona_enable_freerun_sysclk(arizona, &state); |
| 424 | if (ret) |
| 425 | return ret; |
| 426 | |
| 427 | ret = regmap_multi_reg_write_bypassed(arizona->regmap, |
| 428 | wm5110_sleep_patch, |
| 429 | ARRAY_SIZE(wm5110_sleep_patch)); |
| 430 | |
| 431 | err = arizona_disable_freerun_sysclk(arizona, &state); |
| 432 | |
| 433 | return ret ?: err; |
| 434 | } |
| 435 | |
Charles Keepax | 1c1c6bb | 2015-05-11 13:58:03 +0100 | [diff] [blame] | 436 | static int wm5102_clear_write_sequencer(struct arizona *arizona) |
| 437 | { |
| 438 | int ret; |
| 439 | |
| 440 | ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_3, |
| 441 | 0x0); |
| 442 | if (ret) { |
| 443 | dev_err(arizona->dev, |
| 444 | "Failed to clear write sequencer state: %d\n", ret); |
| 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | arizona_enable_reset(arizona); |
| 449 | regulator_disable(arizona->dcvdd); |
| 450 | |
| 451 | msleep(20); |
| 452 | |
| 453 | ret = regulator_enable(arizona->dcvdd); |
| 454 | if (ret) { |
| 455 | dev_err(arizona->dev, "Failed to re-enable DCVDD: %d\n", ret); |
| 456 | return ret; |
| 457 | } |
| 458 | arizona_disable_reset(arizona); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Rafael J. Wysocki | 48bb9fe | 2014-12-05 03:04:12 +0100 | [diff] [blame] | 463 | #ifdef CONFIG_PM |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 464 | static int arizona_isolate_dcvdd(struct arizona *arizona) |
| 465 | { |
| 466 | int ret; |
| 467 | |
| 468 | ret = regmap_update_bits(arizona->regmap, |
| 469 | ARIZONA_ISOLATION_CONTROL, |
| 470 | ARIZONA_ISOLATE_DCVDD1, |
| 471 | ARIZONA_ISOLATE_DCVDD1); |
| 472 | if (ret != 0) |
| 473 | dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n", ret); |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | static int arizona_connect_dcvdd(struct arizona *arizona) |
| 479 | { |
| 480 | int ret; |
| 481 | |
| 482 | ret = regmap_update_bits(arizona->regmap, |
| 483 | ARIZONA_ISOLATION_CONTROL, |
| 484 | ARIZONA_ISOLATE_DCVDD1, 0); |
| 485 | if (ret != 0) |
| 486 | dev_err(arizona->dev, "Failed to connect DCVDD: %d\n", ret); |
| 487 | |
| 488 | return ret; |
| 489 | } |
| 490 | |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 491 | static int arizona_is_jack_det_active(struct arizona *arizona) |
| 492 | { |
| 493 | unsigned int val; |
| 494 | int ret; |
| 495 | |
| 496 | ret = regmap_read(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, &val); |
| 497 | if (ret) { |
| 498 | dev_err(arizona->dev, |
| 499 | "Failed to check jack det status: %d\n", ret); |
| 500 | return ret; |
| 501 | } else if (val & ARIZONA_JD1_ENA) { |
| 502 | return 1; |
| 503 | } else { |
| 504 | return 0; |
| 505 | } |
| 506 | } |
| 507 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 508 | static int arizona_runtime_resume(struct device *dev) |
| 509 | { |
| 510 | struct arizona *arizona = dev_get_drvdata(dev); |
| 511 | int ret; |
| 512 | |
Mark Brown | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 513 | dev_dbg(arizona->dev, "Leaving AoD mode\n"); |
| 514 | |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 515 | if (arizona->has_fully_powered_off) { |
| 516 | dev_dbg(arizona->dev, "Re-enabling core supplies\n"); |
| 517 | |
| 518 | ret = regulator_bulk_enable(arizona->num_core_supplies, |
| 519 | arizona->core_supplies); |
| 520 | if (ret) { |
| 521 | dev_err(dev, "Failed to enable core supplies: %d\n", |
| 522 | ret); |
| 523 | return ret; |
| 524 | } |
| 525 | } |
| 526 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 527 | ret = regulator_enable(arizona->dcvdd); |
| 528 | if (ret != 0) { |
| 529 | dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret); |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 530 | if (arizona->has_fully_powered_off) |
| 531 | regulator_bulk_disable(arizona->num_core_supplies, |
| 532 | arizona->core_supplies); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 533 | return ret; |
| 534 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 535 | |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 536 | if (arizona->has_fully_powered_off) { |
| 537 | arizona_disable_reset(arizona); |
| 538 | enable_irq(arizona->irq); |
| 539 | arizona->has_fully_powered_off = false; |
| 540 | } |
| 541 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 542 | regcache_cache_only(arizona->regmap, false); |
| 543 | |
Charles Keepax | 4c9bb8b | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 544 | switch (arizona->type) { |
| 545 | case WM5102: |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 546 | if (arizona->external_dcvdd) { |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 547 | ret = arizona_connect_dcvdd(arizona); |
| 548 | if (ret != 0) |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 549 | goto err; |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Charles Keepax | 4c9bb8b | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 552 | ret = wm5102_patch(arizona); |
| 553 | if (ret != 0) { |
| 554 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 555 | ret); |
| 556 | goto err; |
| 557 | } |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 558 | |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 559 | ret = wm5102_apply_hardware_patch(arizona); |
| 560 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 561 | dev_err(arizona->dev, |
| 562 | "Failed to apply hardware patch: %d\n", |
| 563 | ret); |
| 564 | goto err; |
| 565 | } |
| 566 | break; |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 567 | case WM5110: |
| 568 | case WM8280: |
| 569 | ret = arizona_wait_for_boot(arizona); |
| 570 | if (ret) |
| 571 | goto err; |
| 572 | |
| 573 | if (arizona->external_dcvdd) { |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 574 | ret = arizona_connect_dcvdd(arizona); |
| 575 | if (ret != 0) |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 576 | goto err; |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 577 | } else { |
| 578 | /* |
| 579 | * As this is only called for the internal regulator |
| 580 | * (where we know voltage ranges available) it is ok |
| 581 | * to request an exact range. |
| 582 | */ |
| 583 | ret = regulator_set_voltage(arizona->dcvdd, |
| 584 | 1200000, 1200000); |
| 585 | if (ret < 0) { |
| 586 | dev_err(arizona->dev, |
| 587 | "Failed to set resume voltage: %d\n", |
| 588 | ret); |
| 589 | goto err; |
| 590 | } |
| 591 | } |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 592 | |
| 593 | ret = wm5110_apply_sleep_patch(arizona); |
| 594 | if (ret) { |
| 595 | dev_err(arizona->dev, |
| 596 | "Failed to re-apply sleep patch: %d\n", |
| 597 | ret); |
| 598 | goto err; |
| 599 | } |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 600 | break; |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 601 | case WM1831: |
| 602 | case CS47L24: |
| 603 | ret = arizona_wait_for_boot(arizona); |
| 604 | if (ret != 0) |
| 605 | goto err; |
| 606 | break; |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 607 | default: |
Charles Keepax | 12bb68e | 2013-03-27 09:49:40 +0000 | [diff] [blame] | 608 | ret = arizona_wait_for_boot(arizona); |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 609 | if (ret != 0) |
Charles Keepax | 12bb68e | 2013-03-27 09:49:40 +0000 | [diff] [blame] | 610 | goto err; |
Charles Keepax | 12bb68e | 2013-03-27 09:49:40 +0000 | [diff] [blame] | 611 | |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 612 | if (arizona->external_dcvdd) { |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 613 | ret = arizona_connect_dcvdd(arizona); |
| 614 | if (ret != 0) |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 615 | goto err; |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 616 | } |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 617 | break; |
Charles Keepax | 4c9bb8b | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Mark Brown | 9270bdf | 2013-01-04 17:16:12 +0000 | [diff] [blame] | 620 | ret = regcache_sync(arizona->regmap); |
| 621 | if (ret != 0) { |
| 622 | dev_err(arizona->dev, "Failed to restore register cache\n"); |
Mark Brown | 4816bd1 | 2013-01-14 15:50:38 +0900 | [diff] [blame] | 623 | goto err; |
Mark Brown | 9270bdf | 2013-01-04 17:16:12 +0000 | [diff] [blame] | 624 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 625 | |
| 626 | return 0; |
Mark Brown | 4816bd1 | 2013-01-14 15:50:38 +0900 | [diff] [blame] | 627 | |
| 628 | err: |
| 629 | regcache_cache_only(arizona->regmap, true); |
| 630 | regulator_disable(arizona->dcvdd); |
| 631 | return ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static int arizona_runtime_suspend(struct device *dev) |
| 635 | { |
| 636 | struct arizona *arizona = dev_get_drvdata(dev); |
Dan Carpenter | a05950a | 2015-10-19 13:18:05 +0300 | [diff] [blame] | 637 | int jd_active = 0; |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 638 | int ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 639 | |
Mark Brown | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 640 | dev_dbg(arizona->dev, "Entering AoD mode\n"); |
| 641 | |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 642 | switch (arizona->type) { |
| 643 | case WM5110: |
| 644 | case WM8280: |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 645 | jd_active = arizona_is_jack_det_active(arizona); |
| 646 | if (jd_active < 0) |
| 647 | return jd_active; |
| 648 | |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 649 | if (arizona->external_dcvdd) { |
| 650 | ret = arizona_isolate_dcvdd(arizona); |
| 651 | if (ret != 0) |
| 652 | return ret; |
| 653 | } else { |
| 654 | /* |
| 655 | * As this is only called for the internal regulator |
| 656 | * (where we know voltage ranges available) it is ok |
| 657 | * to request an exact range. |
| 658 | */ |
| 659 | ret = regulator_set_voltage(arizona->dcvdd, |
| 660 | 1175000, 1175000); |
| 661 | if (ret < 0) { |
| 662 | dev_err(arizona->dev, |
| 663 | "Failed to set suspend voltage: %d\n", |
| 664 | ret); |
| 665 | return ret; |
| 666 | } |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 667 | } |
| 668 | break; |
| 669 | case WM5102: |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 670 | jd_active = arizona_is_jack_det_active(arizona); |
| 671 | if (jd_active < 0) |
| 672 | return jd_active; |
| 673 | |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 674 | if (arizona->external_dcvdd) { |
| 675 | ret = arizona_isolate_dcvdd(arizona); |
| 676 | if (ret != 0) |
| 677 | return ret; |
| 678 | } |
| 679 | |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 680 | if (!jd_active) { |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 681 | ret = regmap_write(arizona->regmap, |
| 682 | ARIZONA_WRITE_SEQUENCER_CTRL_3, 0x0); |
| 683 | if (ret) { |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 684 | dev_err(arizona->dev, |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 685 | "Failed to clear write sequencer: %d\n", |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 686 | ret); |
| 687 | return ret; |
| 688 | } |
Charles Keepax | 96129a0 | 2015-05-11 13:58:08 +0100 | [diff] [blame] | 689 | } |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 690 | break; |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 691 | case WM1831: |
| 692 | case CS47L24: |
| 693 | break; |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 694 | default: |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 695 | jd_active = arizona_is_jack_det_active(arizona); |
| 696 | if (jd_active < 0) |
| 697 | return jd_active; |
| 698 | |
Richard Fitzgerald | e781114 | 2015-10-02 13:29:10 +0100 | [diff] [blame] | 699 | if (arizona->external_dcvdd) { |
| 700 | ret = arizona_isolate_dcvdd(arizona); |
| 701 | if (ret != 0) |
| 702 | return ret; |
| 703 | } |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 704 | break; |
Mark Brown | 5927467 | 2013-04-23 19:44:16 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 707 | regcache_cache_only(arizona->regmap, true); |
| 708 | regcache_mark_dirty(arizona->regmap); |
Charles Keepax | e293e8472 | 2013-08-06 17:18:35 +0100 | [diff] [blame] | 709 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 710 | |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 711 | /* Allow us to completely power down if no jack detection */ |
Richard Fitzgerald | e342427 | 2015-10-02 13:29:11 +0100 | [diff] [blame] | 712 | if (!jd_active) { |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 713 | dev_dbg(arizona->dev, "Fully powering off\n"); |
| 714 | |
| 715 | arizona->has_fully_powered_off = true; |
| 716 | |
Charles Keepax | 1115092 | 2015-06-14 15:41:49 +0100 | [diff] [blame] | 717 | disable_irq_nosync(arizona->irq); |
Charles Keepax | e6cb734 | 2015-05-11 13:58:09 +0100 | [diff] [blame] | 718 | arizona_enable_reset(arizona); |
| 719 | regulator_bulk_disable(arizona->num_core_supplies, |
| 720 | arizona->core_supplies); |
| 721 | } |
| 722 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | #endif |
| 726 | |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 727 | #ifdef CONFIG_PM_SLEEP |
Mark Brown | 67c9929 | 2013-04-10 12:40:26 +0100 | [diff] [blame] | 728 | static int arizona_suspend(struct device *dev) |
| 729 | { |
| 730 | struct arizona *arizona = dev_get_drvdata(dev); |
| 731 | |
| 732 | dev_dbg(arizona->dev, "Suspend, disabling IRQ\n"); |
| 733 | disable_irq(arizona->irq); |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int arizona_suspend_late(struct device *dev) |
| 739 | { |
| 740 | struct arizona *arizona = dev_get_drvdata(dev); |
| 741 | |
| 742 | dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n"); |
| 743 | enable_irq(arizona->irq); |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 748 | static int arizona_resume_noirq(struct device *dev) |
| 749 | { |
| 750 | struct arizona *arizona = dev_get_drvdata(dev); |
| 751 | |
| 752 | dev_dbg(arizona->dev, "Early resume, disabling IRQ\n"); |
| 753 | disable_irq(arizona->irq); |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | static int arizona_resume(struct device *dev) |
| 759 | { |
| 760 | struct arizona *arizona = dev_get_drvdata(dev); |
| 761 | |
| 762 | dev_dbg(arizona->dev, "Late resume, reenabling IRQ\n"); |
| 763 | enable_irq(arizona->irq); |
| 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | #endif |
| 768 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 769 | const struct dev_pm_ops arizona_pm_ops = { |
| 770 | SET_RUNTIME_PM_OPS(arizona_runtime_suspend, |
| 771 | arizona_runtime_resume, |
| 772 | NULL) |
Mark Brown | 67c9929 | 2013-04-10 12:40:26 +0100 | [diff] [blame] | 773 | SET_SYSTEM_SLEEP_PM_OPS(arizona_suspend, arizona_resume) |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 774 | #ifdef CONFIG_PM_SLEEP |
Mark Brown | 67c9929 | 2013-04-10 12:40:26 +0100 | [diff] [blame] | 775 | .suspend_late = arizona_suspend_late, |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 776 | .resume_noirq = arizona_resume_noirq, |
| 777 | #endif |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 778 | }; |
| 779 | EXPORT_SYMBOL_GPL(arizona_pm_ops); |
| 780 | |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 781 | #ifdef CONFIG_OF |
Lee Jones | 942786e | 2014-07-02 14:28:46 +0100 | [diff] [blame] | 782 | unsigned long arizona_of_get_type(struct device *dev) |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 783 | { |
| 784 | const struct of_device_id *id = of_match_device(arizona_of_match, dev); |
| 785 | |
| 786 | if (id) |
Lee Jones | 942786e | 2014-07-02 14:28:46 +0100 | [diff] [blame] | 787 | return (unsigned long)id->data; |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 788 | else |
| 789 | return 0; |
| 790 | } |
| 791 | EXPORT_SYMBOL_GPL(arizona_of_get_type); |
| 792 | |
Charles Keepax | e4fcb1d | 2014-04-16 10:01:37 +0100 | [diff] [blame] | 793 | int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop, |
| 794 | bool mandatory) |
| 795 | { |
| 796 | int gpio; |
| 797 | |
| 798 | gpio = of_get_named_gpio(arizona->dev->of_node, prop, 0); |
| 799 | if (gpio < 0) { |
| 800 | if (mandatory) |
| 801 | dev_err(arizona->dev, |
| 802 | "Mandatory DT gpio %s missing/malformed: %d\n", |
| 803 | prop, gpio); |
| 804 | |
| 805 | gpio = 0; |
| 806 | } |
| 807 | |
| 808 | return gpio; |
| 809 | } |
| 810 | EXPORT_SYMBOL_GPL(arizona_of_get_named_gpio); |
| 811 | |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 812 | static int arizona_of_get_core_pdata(struct arizona *arizona) |
| 813 | { |
Charles Keepax | e4fcb1d | 2014-04-16 10:01:37 +0100 | [diff] [blame] | 814 | struct arizona_pdata *pdata = &arizona->pdata; |
Inha Song | cc47aed | 2014-08-30 11:27:18 +0900 | [diff] [blame] | 815 | struct property *prop; |
| 816 | const __be32 *cur; |
| 817 | u32 val; |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 818 | int ret, i; |
Inha Song | cc47aed | 2014-08-30 11:27:18 +0900 | [diff] [blame] | 819 | int count = 0; |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 820 | |
Charles Keepax | e4fcb1d | 2014-04-16 10:01:37 +0100 | [diff] [blame] | 821 | pdata->reset = arizona_of_get_named_gpio(arizona, "wlf,reset", true); |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 822 | |
| 823 | ret = of_property_read_u32_array(arizona->dev->of_node, |
| 824 | "wlf,gpio-defaults", |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 825 | pdata->gpio_defaults, |
| 826 | ARRAY_SIZE(pdata->gpio_defaults)); |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 827 | if (ret >= 0) { |
| 828 | /* |
| 829 | * All values are literal except out of range values |
| 830 | * which are chip default, translate into platform |
| 831 | * data which uses 0 as chip default and out of range |
| 832 | * as zero. |
| 833 | */ |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 834 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { |
| 835 | if (pdata->gpio_defaults[i] > 0xffff) |
| 836 | pdata->gpio_defaults[i] = 0; |
| 837 | else if (pdata->gpio_defaults[i] == 0) |
| 838 | pdata->gpio_defaults[i] = 0x10000; |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 839 | } |
| 840 | } else { |
| 841 | dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n", |
| 842 | ret); |
| 843 | } |
| 844 | |
Inha Song | cc47aed | 2014-08-30 11:27:18 +0900 | [diff] [blame] | 845 | of_property_for_each_u32(arizona->dev->of_node, "wlf,inmode", prop, |
| 846 | cur, val) { |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 847 | if (count == ARRAY_SIZE(pdata->inmode)) |
Inha Song | cc47aed | 2014-08-30 11:27:18 +0900 | [diff] [blame] | 848 | break; |
| 849 | |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 850 | pdata->inmode[count] = val; |
Inha Song | cc47aed | 2014-08-30 11:27:18 +0900 | [diff] [blame] | 851 | count++; |
| 852 | } |
| 853 | |
Charles Keepax | e7ad27c | 2015-03-03 15:04:53 +0000 | [diff] [blame] | 854 | count = 0; |
| 855 | of_property_for_each_u32(arizona->dev->of_node, "wlf,dmic-ref", prop, |
| 856 | cur, val) { |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 857 | if (count == ARRAY_SIZE(pdata->dmic_ref)) |
Charles Keepax | e7ad27c | 2015-03-03 15:04:53 +0000 | [diff] [blame] | 858 | break; |
| 859 | |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 860 | pdata->dmic_ref[count] = val; |
Charles Keepax | e7ad27c | 2015-03-03 15:04:53 +0000 | [diff] [blame] | 861 | count++; |
| 862 | } |
| 863 | |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | const struct of_device_id arizona_of_match[] = { |
| 868 | { .compatible = "wlf,wm5102", .data = (void *)WM5102 }, |
| 869 | { .compatible = "wlf,wm5110", .data = (void *)WM5110 }, |
Richard Fitzgerald | e5d4ef0 | 2015-01-17 15:21:22 +0000 | [diff] [blame] | 870 | { .compatible = "wlf,wm8280", .data = (void *)WM8280 }, |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 871 | { .compatible = "wlf,wm8997", .data = (void *)WM8997 }, |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 872 | { .compatible = "wlf,wm8998", .data = (void *)WM8998 }, |
| 873 | { .compatible = "wlf,wm1814", .data = (void *)WM1814 }, |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 874 | { .compatible = "wlf,wm1831", .data = (void *)WM1831 }, |
| 875 | { .compatible = "cirrus,cs47l24", .data = (void *)CS47L24 }, |
Mark Brown | d781009 | 2013-03-25 00:11:27 +0000 | [diff] [blame] | 876 | {}, |
| 877 | }; |
| 878 | EXPORT_SYMBOL_GPL(arizona_of_match); |
| 879 | #else |
| 880 | static inline int arizona_of_get_core_pdata(struct arizona *arizona) |
| 881 | { |
| 882 | return 0; |
| 883 | } |
| 884 | #endif |
| 885 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 886 | static const struct mfd_cell early_devs[] = { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 887 | { .name = "arizona-ldo1" }, |
| 888 | }; |
| 889 | |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 890 | static const char * const wm5102_supplies[] = { |
Charles Keepax | 5fc6c39 | 2014-07-25 16:24:44 +0100 | [diff] [blame] | 891 | "MICVDD", |
Charles Keepax | 32dadef | 2013-10-15 20:14:22 +0100 | [diff] [blame] | 892 | "DBVDD2", |
| 893 | "DBVDD3", |
| 894 | "CPVDD", |
| 895 | "SPKVDDL", |
| 896 | "SPKVDDR", |
| 897 | }; |
| 898 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 899 | static const struct mfd_cell wm5102_devs[] = { |
Mark Brown | d776811 | 2012-12-20 15:38:03 +0000 | [diff] [blame] | 900 | { .name = "arizona-micsupp" }, |
Charles Keepax | 5fc6c39 | 2014-07-25 16:24:44 +0100 | [diff] [blame] | 901 | { |
| 902 | .name = "arizona-extcon", |
| 903 | .parent_supplies = wm5102_supplies, |
| 904 | .num_parent_supplies = 1, /* We only need MICVDD */ |
| 905 | }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 906 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 907 | { .name = "arizona-haptics" }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 908 | { .name = "arizona-pwm" }, |
Charles Keepax | 32dadef | 2013-10-15 20:14:22 +0100 | [diff] [blame] | 909 | { |
| 910 | .name = "wm5102-codec", |
| 911 | .parent_supplies = wm5102_supplies, |
| 912 | .num_parent_supplies = ARRAY_SIZE(wm5102_supplies), |
| 913 | }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 914 | }; |
| 915 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 916 | static const struct mfd_cell wm5110_devs[] = { |
Mark Brown | d776811 | 2012-12-20 15:38:03 +0000 | [diff] [blame] | 917 | { .name = "arizona-micsupp" }, |
Charles Keepax | 5fc6c39 | 2014-07-25 16:24:44 +0100 | [diff] [blame] | 918 | { |
| 919 | .name = "arizona-extcon", |
| 920 | .parent_supplies = wm5102_supplies, |
| 921 | .num_parent_supplies = 1, /* We only need MICVDD */ |
| 922 | }, |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 923 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 924 | { .name = "arizona-haptics" }, |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 925 | { .name = "arizona-pwm" }, |
Charles Keepax | 32dadef | 2013-10-15 20:14:22 +0100 | [diff] [blame] | 926 | { |
| 927 | .name = "wm5110-codec", |
| 928 | .parent_supplies = wm5102_supplies, |
| 929 | .num_parent_supplies = ARRAY_SIZE(wm5102_supplies), |
| 930 | }, |
| 931 | }; |
| 932 | |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 933 | static const char * const cs47l24_supplies[] = { |
| 934 | "MICVDD", |
| 935 | "CPVDD", |
| 936 | "SPKVDD", |
| 937 | }; |
| 938 | |
| 939 | static const struct mfd_cell cs47l24_devs[] = { |
| 940 | { .name = "arizona-gpio" }, |
| 941 | { .name = "arizona-haptics" }, |
| 942 | { .name = "arizona-pwm" }, |
| 943 | { |
| 944 | .name = "cs47l24-codec", |
| 945 | .parent_supplies = cs47l24_supplies, |
| 946 | .num_parent_supplies = ARRAY_SIZE(cs47l24_supplies), |
| 947 | }, |
| 948 | }; |
| 949 | |
Charles Keepax | 3762aed | 2015-08-11 09:34:31 +0100 | [diff] [blame] | 950 | static const char * const wm8997_supplies[] = { |
Charles Keepax | 996c2d4 | 2014-07-25 16:24:43 +0100 | [diff] [blame] | 951 | "MICVDD", |
Charles Keepax | 32dadef | 2013-10-15 20:14:22 +0100 | [diff] [blame] | 952 | "DBVDD2", |
| 953 | "CPVDD", |
| 954 | "SPKVDD", |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 955 | }; |
| 956 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 957 | static const struct mfd_cell wm8997_devs[] = { |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 958 | { .name = "arizona-micsupp" }, |
Charles Keepax | 5fc6c39 | 2014-07-25 16:24:44 +0100 | [diff] [blame] | 959 | { |
| 960 | .name = "arizona-extcon", |
| 961 | .parent_supplies = wm8997_supplies, |
| 962 | .num_parent_supplies = 1, /* We only need MICVDD */ |
| 963 | }, |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 964 | { .name = "arizona-gpio" }, |
| 965 | { .name = "arizona-haptics" }, |
| 966 | { .name = "arizona-pwm" }, |
Charles Keepax | 32dadef | 2013-10-15 20:14:22 +0100 | [diff] [blame] | 967 | { |
| 968 | .name = "wm8997-codec", |
| 969 | .parent_supplies = wm8997_supplies, |
| 970 | .num_parent_supplies = ARRAY_SIZE(wm8997_supplies), |
| 971 | }, |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 972 | }; |
| 973 | |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 974 | static const struct mfd_cell wm8998_devs[] = { |
| 975 | { |
| 976 | .name = "arizona-extcon", |
| 977 | .parent_supplies = wm5102_supplies, |
| 978 | .num_parent_supplies = 1, /* We only need MICVDD */ |
| 979 | }, |
| 980 | { .name = "arizona-gpio" }, |
| 981 | { .name = "arizona-haptics" }, |
| 982 | { .name = "arizona-pwm" }, |
| 983 | { |
| 984 | .name = "wm8998-codec", |
| 985 | .parent_supplies = wm5102_supplies, |
| 986 | .num_parent_supplies = ARRAY_SIZE(wm5102_supplies), |
| 987 | }, |
| 988 | { .name = "arizona-micsupp" }, |
| 989 | }; |
| 990 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 991 | int arizona_dev_init(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 992 | { |
| 993 | struct device *dev = arizona->dev; |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 994 | const char *type_name = NULL; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 995 | unsigned int reg, val, mask; |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 996 | int (*apply_patch)(struct arizona *) = NULL; |
Richard Fitzgerald | ae05ea36 | 2015-10-02 13:29:13 +0100 | [diff] [blame] | 997 | const struct mfd_cell *subdevs = NULL; |
| 998 | int n_subdevs, ret, i; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 999 | |
| 1000 | dev_set_drvdata(arizona->dev, arizona); |
| 1001 | mutex_init(&arizona->clk_lock); |
| 1002 | |
| 1003 | if (dev_get_platdata(arizona->dev)) |
| 1004 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), |
| 1005 | sizeof(arizona->pdata)); |
Lee Jones | 22d7dc8 | 2013-09-27 14:25:55 +0100 | [diff] [blame] | 1006 | else |
| 1007 | arizona_of_get_core_pdata(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1008 | |
| 1009 | regcache_cache_only(arizona->regmap, true); |
| 1010 | |
| 1011 | switch (arizona->type) { |
| 1012 | case WM5102: |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 1013 | case WM5110: |
Richard Fitzgerald | e5d4ef0 | 2015-01-17 15:21:22 +0000 | [diff] [blame] | 1014 | case WM8280: |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 1015 | case WM8997: |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1016 | case WM8998: |
| 1017 | case WM1814: |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 1018 | case WM1831: |
| 1019 | case CS47L24: |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1020 | for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) |
| 1021 | arizona->core_supplies[i].supply |
| 1022 | = wm5102_core_supplies[i]; |
| 1023 | arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); |
| 1024 | break; |
| 1025 | default: |
| 1026 | dev_err(arizona->dev, "Unknown device type %d\n", |
| 1027 | arizona->type); |
| 1028 | return -EINVAL; |
| 1029 | } |
| 1030 | |
Charles Keepax | 4a8c475 | 2014-04-16 10:01:38 +0100 | [diff] [blame] | 1031 | /* Mark DCVDD as external, LDO1 driver will clear if internal */ |
| 1032 | arizona->external_dcvdd = true; |
| 1033 | |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 1034 | switch (arizona->type) { |
| 1035 | case WM1831: |
| 1036 | case CS47L24: |
| 1037 | break; /* No LDO1 regulator */ |
| 1038 | default: |
| 1039 | ret = mfd_add_devices(arizona->dev, -1, early_devs, |
| 1040 | ARRAY_SIZE(early_devs), NULL, 0, NULL); |
| 1041 | if (ret != 0) { |
| 1042 | dev_err(dev, "Failed to add early children: %d\n", ret); |
| 1043 | return ret; |
| 1044 | } |
| 1045 | break; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, |
| 1049 | arizona->core_supplies); |
| 1050 | if (ret != 0) { |
| 1051 | dev_err(dev, "Failed to request core supplies: %d\n", |
| 1052 | ret); |
| 1053 | goto err_early; |
| 1054 | } |
| 1055 | |
Charles Keepax | 0c2d0ff | 2014-06-19 16:04:23 +0100 | [diff] [blame] | 1056 | /** |
| 1057 | * Don't use devres here because the only device we have to get |
| 1058 | * against is the MFD device and DCVDD will likely be supplied by |
| 1059 | * one of its children. Meaning that the regulator will be |
| 1060 | * destroyed by the time devres calls regulator put. |
| 1061 | */ |
Charles Keepax | e602151 | 2014-06-02 09:50:41 +0100 | [diff] [blame] | 1062 | arizona->dcvdd = regulator_get(arizona->dev, "DCVDD"); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1063 | if (IS_ERR(arizona->dcvdd)) { |
| 1064 | ret = PTR_ERR(arizona->dcvdd); |
| 1065 | dev_err(dev, "Failed to request DCVDD: %d\n", ret); |
| 1066 | goto err_early; |
| 1067 | } |
| 1068 | |
Mark Brown | 87d3af4 | 2013-03-26 12:15:26 +0000 | [diff] [blame] | 1069 | if (arizona->pdata.reset) { |
| 1070 | /* Start out with /RESET low to put the chip into reset */ |
Charles Keepax | 5f056bf | 2015-05-11 13:58:01 +0100 | [diff] [blame] | 1071 | ret = devm_gpio_request_one(arizona->dev, arizona->pdata.reset, |
| 1072 | GPIOF_DIR_OUT | GPIOF_INIT_LOW, |
| 1073 | "arizona /RESET"); |
Mark Brown | 87d3af4 | 2013-03-26 12:15:26 +0000 | [diff] [blame] | 1074 | if (ret != 0) { |
| 1075 | dev_err(dev, "Failed to request /RESET: %d\n", ret); |
Charles Keepax | e602151 | 2014-06-02 09:50:41 +0100 | [diff] [blame] | 1076 | goto err_dcvdd; |
Mark Brown | 87d3af4 | 2013-03-26 12:15:26 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1080 | ret = regulator_bulk_enable(arizona->num_core_supplies, |
| 1081 | arizona->core_supplies); |
| 1082 | if (ret != 0) { |
| 1083 | dev_err(dev, "Failed to enable core supplies: %d\n", |
| 1084 | ret); |
Charles Keepax | e602151 | 2014-06-02 09:50:41 +0100 | [diff] [blame] | 1085 | goto err_dcvdd; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1088 | ret = regulator_enable(arizona->dcvdd); |
| 1089 | if (ret != 0) { |
| 1090 | dev_err(dev, "Failed to enable DCVDD: %d\n", ret); |
| 1091 | goto err_enable; |
| 1092 | } |
| 1093 | |
Charles Keepax | 2229875 | 2015-05-11 13:58:02 +0100 | [diff] [blame] | 1094 | arizona_disable_reset(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1095 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1096 | regcache_cache_only(arizona->regmap, false); |
| 1097 | |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1098 | /* Verify that this is a chip we know about */ |
| 1099 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 1100 | if (ret != 0) { |
| 1101 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
| 1102 | goto err_reset; |
| 1103 | } |
| 1104 | |
| 1105 | switch (reg) { |
| 1106 | case 0x5102: |
| 1107 | case 0x5110: |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1108 | case 0x6349: |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 1109 | case 0x6363: |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 1110 | case 0x8997: |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1111 | break; |
| 1112 | default: |
| 1113 | dev_err(arizona->dev, "Unknown device ID: %x\n", reg); |
| 1114 | goto err_reset; |
| 1115 | } |
| 1116 | |
| 1117 | /* If we have a /RESET GPIO we'll already be reset */ |
| 1118 | if (!arizona->pdata.reset) { |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1119 | ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); |
| 1120 | if (ret != 0) { |
| 1121 | dev_err(dev, "Failed to reset device: %d\n", ret); |
| 1122 | goto err_reset; |
| 1123 | } |
| 1124 | |
| 1125 | msleep(1); |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /* Ensure device startup is complete */ |
| 1129 | switch (arizona->type) { |
| 1130 | case WM5102: |
Mark Brown | 4801894 | 2014-08-13 11:42:46 +0100 | [diff] [blame] | 1131 | ret = regmap_read(arizona->regmap, |
| 1132 | ARIZONA_WRITE_SEQUENCER_CTRL_3, &val); |
Charles Keepax | 1c1c6bb | 2015-05-11 13:58:03 +0100 | [diff] [blame] | 1133 | if (ret) { |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1134 | dev_err(dev, |
| 1135 | "Failed to check write sequencer state: %d\n", |
| 1136 | ret); |
Charles Keepax | 1c1c6bb | 2015-05-11 13:58:03 +0100 | [diff] [blame] | 1137 | } else if (val & 0x01) { |
| 1138 | ret = wm5102_clear_write_sequencer(arizona); |
| 1139 | if (ret) |
| 1140 | return ret; |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1141 | } |
| 1142 | break; |
Charles Keepax | 1c1c6bb | 2015-05-11 13:58:03 +0100 | [diff] [blame] | 1143 | default: |
| 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | ret = arizona_wait_for_boot(arizona); |
| 1148 | if (ret) { |
| 1149 | dev_err(arizona->dev, "Device failed initial boot: %d\n", ret); |
| 1150 | goto err_reset; |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | /* Read the device ID information & do device specific stuff */ |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1154 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 1155 | if (ret != 0) { |
| 1156 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1157 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, |
| 1161 | &arizona->rev); |
| 1162 | if (ret != 0) { |
| 1163 | dev_err(dev, "Failed to read revision register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1164 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1165 | } |
| 1166 | arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; |
| 1167 | |
| 1168 | switch (reg) { |
| 1169 | case 0x5102: |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1170 | if (IS_ENABLED(CONFIG_MFD_WM5102)) { |
| 1171 | type_name = "WM5102"; |
| 1172 | if (arizona->type != WM5102) { |
| 1173 | dev_warn(arizona->dev, |
| 1174 | "WM5102 registered as %d\n", |
| 1175 | arizona->type); |
| 1176 | arizona->type = WM5102; |
| 1177 | } |
| 1178 | |
| 1179 | apply_patch = wm5102_patch; |
| 1180 | arizona->rev &= 0x7; |
| 1181 | subdevs = wm5102_devs; |
| 1182 | n_subdevs = ARRAY_SIZE(wm5102_devs); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1183 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1184 | break; |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 1185 | case 0x5110: |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1186 | if (IS_ENABLED(CONFIG_MFD_WM5110)) { |
| 1187 | switch (arizona->type) { |
| 1188 | case WM5110: |
| 1189 | type_name = "WM5110"; |
| 1190 | break; |
| 1191 | case WM8280: |
| 1192 | type_name = "WM8280"; |
| 1193 | break; |
| 1194 | default: |
| 1195 | type_name = "WM5110"; |
| 1196 | dev_warn(arizona->dev, |
| 1197 | "WM5110 registered as %d\n", |
| 1198 | arizona->type); |
| 1199 | arizona->type = WM5110; |
| 1200 | break; |
| 1201 | } |
| 1202 | |
| 1203 | apply_patch = wm5110_patch; |
| 1204 | subdevs = wm5110_devs; |
| 1205 | n_subdevs = ARRAY_SIZE(wm5110_devs); |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 1206 | } |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 1207 | break; |
Richard Fitzgerald | ea1f333 | 2015-11-03 15:08:32 +0000 | [diff] [blame^] | 1208 | case 0x6363: |
| 1209 | if (IS_ENABLED(CONFIG_MFD_CS47L24)) { |
| 1210 | switch (arizona->type) { |
| 1211 | case CS47L24: |
| 1212 | type_name = "CS47L24"; |
| 1213 | break; |
| 1214 | |
| 1215 | case WM1831: |
| 1216 | type_name = "WM1831"; |
| 1217 | break; |
| 1218 | |
| 1219 | default: |
| 1220 | dev_warn(arizona->dev, |
| 1221 | "CS47L24 registered as %d\n", |
| 1222 | arizona->type); |
| 1223 | arizona->type = CS47L24; |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | apply_patch = cs47l24_patch; |
| 1228 | subdevs = cs47l24_devs; |
| 1229 | n_subdevs = ARRAY_SIZE(cs47l24_devs); |
| 1230 | } |
| 1231 | break; |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 1232 | case 0x8997: |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1233 | if (IS_ENABLED(CONFIG_MFD_WM8997)) { |
| 1234 | type_name = "WM8997"; |
| 1235 | if (arizona->type != WM8997) { |
| 1236 | dev_warn(arizona->dev, |
| 1237 | "WM8997 registered as %d\n", |
| 1238 | arizona->type); |
| 1239 | arizona->type = WM8997; |
| 1240 | } |
| 1241 | |
| 1242 | apply_patch = wm8997_patch; |
| 1243 | subdevs = wm8997_devs; |
| 1244 | n_subdevs = ARRAY_SIZE(wm8997_devs); |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 1245 | } |
Charles Keepax | dc7d486 | 2013-06-13 09:43:29 +0100 | [diff] [blame] | 1246 | break; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1247 | case 0x6349: |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1248 | if (IS_ENABLED(CONFIG_MFD_WM8998)) { |
| 1249 | switch (arizona->type) { |
| 1250 | case WM8998: |
| 1251 | type_name = "WM8998"; |
| 1252 | break; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1253 | |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1254 | case WM1814: |
| 1255 | type_name = "WM1814"; |
| 1256 | break; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1257 | |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1258 | default: |
| 1259 | type_name = "WM8998"; |
| 1260 | dev_warn(arizona->dev, |
| 1261 | "WM8998 registered as %d\n", |
| 1262 | arizona->type); |
| 1263 | arizona->type = WM8998; |
| 1264 | } |
| 1265 | |
| 1266 | apply_patch = wm8998_patch; |
| 1267 | subdevs = wm8998_devs; |
| 1268 | n_subdevs = ARRAY_SIZE(wm8998_devs); |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1269 | } |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1270 | break; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1271 | default: |
| 1272 | dev_err(arizona->dev, "Unknown device ID %x\n", reg); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1273 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
Richard Fitzgerald | b61c1ec | 2015-10-02 13:29:14 +0100 | [diff] [blame] | 1276 | if (!subdevs) { |
| 1277 | dev_err(arizona->dev, |
| 1278 | "No kernel support for device ID %x\n", reg); |
| 1279 | goto err_reset; |
| 1280 | } |
| 1281 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1282 | dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); |
| 1283 | |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 1284 | if (apply_patch) { |
| 1285 | ret = apply_patch(arizona); |
| 1286 | if (ret != 0) { |
| 1287 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 1288 | ret); |
| 1289 | goto err_reset; |
| 1290 | } |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 1291 | |
| 1292 | switch (arizona->type) { |
| 1293 | case WM5102: |
Charles Keepax | 0be068a | 2015-05-11 13:58:04 +0100 | [diff] [blame] | 1294 | ret = wm5102_apply_hardware_patch(arizona); |
| 1295 | if (ret) { |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 1296 | dev_err(arizona->dev, |
| 1297 | "Failed to apply hardware patch: %d\n", |
| 1298 | ret); |
| 1299 | goto err_reset; |
| 1300 | } |
| 1301 | break; |
Charles Keepax | 882bc46 | 2015-05-11 13:58:06 +0100 | [diff] [blame] | 1302 | case WM5110: |
| 1303 | case WM8280: |
| 1304 | ret = wm5110_apply_sleep_patch(arizona); |
| 1305 | if (ret) { |
| 1306 | dev_err(arizona->dev, |
| 1307 | "Failed to apply sleep patch: %d\n", |
| 1308 | ret); |
| 1309 | goto err_reset; |
| 1310 | } |
| 1311 | break; |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 1312 | default: |
| 1313 | break; |
| 1314 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 1315 | } |
| 1316 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1317 | for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { |
| 1318 | if (!arizona->pdata.gpio_defaults[i]) |
| 1319 | continue; |
| 1320 | |
| 1321 | regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, |
| 1322 | arizona->pdata.gpio_defaults[i]); |
| 1323 | } |
| 1324 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1325 | /* Chip default */ |
| 1326 | if (!arizona->pdata.clk32k_src) |
| 1327 | arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; |
| 1328 | |
| 1329 | switch (arizona->pdata.clk32k_src) { |
| 1330 | case ARIZONA_32KZ_MCLK1: |
| 1331 | case ARIZONA_32KZ_MCLK2: |
| 1332 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 1333 | ARIZONA_CLK_32K_SRC_MASK, |
| 1334 | arizona->pdata.clk32k_src - 1); |
Mark Brown | 767c6dc | 2013-03-19 19:04:46 +0100 | [diff] [blame] | 1335 | arizona_clk32k_enable(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1336 | break; |
| 1337 | case ARIZONA_32KZ_NONE: |
| 1338 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 1339 | ARIZONA_CLK_32K_SRC_MASK, 2); |
| 1340 | break; |
| 1341 | default: |
| 1342 | dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", |
| 1343 | arizona->pdata.clk32k_src); |
| 1344 | ret = -EINVAL; |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1345 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1348 | for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) { |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 1349 | if (!arizona->pdata.micbias[i].mV && |
| 1350 | !arizona->pdata.micbias[i].bypass) |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1351 | continue; |
| 1352 | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 1353 | /* Apply default for bypass mode */ |
| 1354 | if (!arizona->pdata.micbias[i].mV) |
| 1355 | arizona->pdata.micbias[i].mV = 2800; |
| 1356 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1357 | val = (arizona->pdata.micbias[i].mV - 1500) / 100; |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 1358 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1359 | val <<= ARIZONA_MICB1_LVL_SHIFT; |
| 1360 | |
| 1361 | if (arizona->pdata.micbias[i].ext_cap) |
| 1362 | val |= ARIZONA_MICB1_EXT_CAP; |
| 1363 | |
| 1364 | if (arizona->pdata.micbias[i].discharge) |
| 1365 | val |= ARIZONA_MICB1_DISCH; |
| 1366 | |
Charles Keepax | f773fc6 | 2013-05-21 14:56:58 +0100 | [diff] [blame] | 1367 | if (arizona->pdata.micbias[i].soft_start) |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1368 | val |= ARIZONA_MICB1_RATE; |
| 1369 | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 1370 | if (arizona->pdata.micbias[i].bypass) |
| 1371 | val |= ARIZONA_MICB1_BYPASS; |
| 1372 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1373 | regmap_update_bits(arizona->regmap, |
| 1374 | ARIZONA_MIC_BIAS_CTRL_1 + i, |
| 1375 | ARIZONA_MICB1_LVL_MASK | |
Charles Keepax | 71d134b | 2014-09-24 10:37:11 +0100 | [diff] [blame] | 1376 | ARIZONA_MICB1_EXT_CAP | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1377 | ARIZONA_MICB1_DISCH | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 1378 | ARIZONA_MICB1_BYPASS | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 1379 | ARIZONA_MICB1_RATE, val); |
| 1380 | } |
| 1381 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1382 | for (i = 0; i < ARIZONA_MAX_INPUT; i++) { |
| 1383 | /* Default for both is 0 so noop with defaults */ |
| 1384 | val = arizona->pdata.dmic_ref[i] |
| 1385 | << ARIZONA_IN1_DMIC_SUP_SHIFT; |
Richard Fitzgerald | fc027d1 | 2015-05-01 16:15:12 +0100 | [diff] [blame] | 1386 | if (arizona->pdata.inmode[i] & ARIZONA_INMODE_DMIC) |
| 1387 | val |= 1 << ARIZONA_IN1_MODE_SHIFT; |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1388 | |
| 1389 | switch (arizona->type) { |
| 1390 | case WM8998: |
| 1391 | case WM1814: |
| 1392 | regmap_update_bits(arizona->regmap, |
| 1393 | ARIZONA_ADC_DIGITAL_VOLUME_1L + (i * 8), |
| 1394 | ARIZONA_IN1L_SRC_SE_MASK, |
| 1395 | (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE) |
| 1396 | << ARIZONA_IN1L_SRC_SE_SHIFT); |
| 1397 | |
| 1398 | regmap_update_bits(arizona->regmap, |
| 1399 | ARIZONA_ADC_DIGITAL_VOLUME_1R + (i * 8), |
| 1400 | ARIZONA_IN1R_SRC_SE_MASK, |
| 1401 | (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE) |
| 1402 | << ARIZONA_IN1R_SRC_SE_SHIFT); |
| 1403 | |
| 1404 | mask = ARIZONA_IN1_DMIC_SUP_MASK | |
| 1405 | ARIZONA_IN1_MODE_MASK; |
| 1406 | break; |
| 1407 | default: |
| 1408 | if (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE) |
| 1409 | val |= 1 << ARIZONA_IN1_SINGLE_ENDED_SHIFT; |
| 1410 | |
| 1411 | mask = ARIZONA_IN1_DMIC_SUP_MASK | |
| 1412 | ARIZONA_IN1_MODE_MASK | |
| 1413 | ARIZONA_IN1_SINGLE_ENDED_MASK; |
| 1414 | break; |
| 1415 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1416 | |
| 1417 | regmap_update_bits(arizona->regmap, |
| 1418 | ARIZONA_IN1L_CONTROL + (i * 8), |
Richard Fitzgerald | 6887b04 | 2015-07-03 16:16:35 +0100 | [diff] [blame] | 1419 | mask, val); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { |
| 1423 | /* Default is 0 so noop with defaults */ |
| 1424 | if (arizona->pdata.out_mono[i]) |
| 1425 | val = ARIZONA_OUT1_MONO; |
| 1426 | else |
| 1427 | val = 0; |
| 1428 | |
| 1429 | regmap_update_bits(arizona->regmap, |
| 1430 | ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), |
| 1431 | ARIZONA_OUT1_MONO, val); |
| 1432 | } |
| 1433 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1434 | for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { |
| 1435 | if (arizona->pdata.spk_mute[i]) |
| 1436 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 1437 | ARIZONA_PDM_SPK1_CTRL_1 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1438 | ARIZONA_SPK1_MUTE_ENDIAN_MASK | |
| 1439 | ARIZONA_SPK1_MUTE_SEQ1_MASK, |
| 1440 | arizona->pdata.spk_mute[i]); |
| 1441 | |
| 1442 | if (arizona->pdata.spk_fmt[i]) |
| 1443 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 1444 | ARIZONA_PDM_SPK1_CTRL_2 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1445 | ARIZONA_SPK1_FMT_MASK, |
| 1446 | arizona->pdata.spk_fmt[i]); |
| 1447 | } |
| 1448 | |
Charles Keepax | 72e4316 | 2015-06-14 15:41:50 +0100 | [diff] [blame] | 1449 | pm_runtime_set_active(arizona->dev); |
| 1450 | pm_runtime_enable(arizona->dev); |
| 1451 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1452 | /* Set up for interrupts */ |
| 1453 | ret = arizona_irq_init(arizona); |
| 1454 | if (ret != 0) |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1455 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1456 | |
Charles Keepax | 72e4316 | 2015-06-14 15:41:50 +0100 | [diff] [blame] | 1457 | pm_runtime_set_autosuspend_delay(arizona->dev, 100); |
| 1458 | pm_runtime_use_autosuspend(arizona->dev); |
| 1459 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1460 | arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", |
| 1461 | arizona_clkgen_err, arizona); |
| 1462 | arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", |
| 1463 | arizona_overclocked, arizona); |
| 1464 | arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", |
| 1465 | arizona_underclocked, arizona); |
| 1466 | |
Richard Fitzgerald | ae05ea36 | 2015-10-02 13:29:13 +0100 | [diff] [blame] | 1467 | ret = mfd_add_devices(arizona->dev, PLATFORM_DEVID_NONE, |
| 1468 | subdevs, n_subdevs, NULL, 0, NULL); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1469 | |
Richard Fitzgerald | ae05ea36 | 2015-10-02 13:29:13 +0100 | [diff] [blame] | 1470 | if (ret) { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1471 | dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); |
| 1472 | goto err_irq; |
| 1473 | } |
| 1474 | |
| 1475 | return 0; |
| 1476 | |
| 1477 | err_irq: |
| 1478 | arizona_irq_exit(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1479 | err_reset: |
Charles Keepax | 2229875 | 2015-05-11 13:58:02 +0100 | [diff] [blame] | 1480 | arizona_enable_reset(arizona); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 1481 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1482 | err_enable: |
Mark Brown | 3a36a0db | 2012-07-09 00:45:53 +0200 | [diff] [blame] | 1483 | regulator_bulk_disable(arizona->num_core_supplies, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1484 | arizona->core_supplies); |
Charles Keepax | e602151 | 2014-06-02 09:50:41 +0100 | [diff] [blame] | 1485 | err_dcvdd: |
| 1486 | regulator_put(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1487 | err_early: |
| 1488 | mfd_remove_devices(dev); |
| 1489 | return ret; |
| 1490 | } |
| 1491 | EXPORT_SYMBOL_GPL(arizona_dev_init); |
| 1492 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 1493 | int arizona_dev_exit(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1494 | { |
Charles Keepax | b804020 | 2014-06-02 09:50:39 +0100 | [diff] [blame] | 1495 | pm_runtime_disable(arizona->dev); |
| 1496 | |
Charles Keepax | df6b335 | 2014-06-02 09:50:40 +0100 | [diff] [blame] | 1497 | regulator_disable(arizona->dcvdd); |
Charles Keepax | e602151 | 2014-06-02 09:50:41 +0100 | [diff] [blame] | 1498 | regulator_put(arizona->dcvdd); |
Charles Keepax | df6b335 | 2014-06-02 09:50:40 +0100 | [diff] [blame] | 1499 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1500 | mfd_remove_devices(arizona->dev); |
| 1501 | arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona); |
| 1502 | arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona); |
| 1503 | arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1504 | arizona_irq_exit(arizona); |
Charles Keepax | 2229875 | 2015-05-11 13:58:02 +0100 | [diff] [blame] | 1505 | arizona_enable_reset(arizona); |
Charles Keepax | df6b335 | 2014-06-02 09:50:40 +0100 | [diff] [blame] | 1506 | |
Charles Keepax | 4420286 | 2014-06-02 09:50:42 +0100 | [diff] [blame] | 1507 | regulator_bulk_disable(arizona->num_core_supplies, |
Mark Brown | 1d017b6 | 2013-03-26 12:16:26 +0000 | [diff] [blame] | 1508 | arizona->core_supplies); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 1509 | return 0; |
| 1510 | } |
| 1511 | EXPORT_SYMBOL_GPL(arizona_dev_exit); |