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