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> |
| 19 | #include <linux/pm_runtime.h> |
| 20 | #include <linux/regmap.h> |
| 21 | #include <linux/regulator/consumer.h> |
| 22 | #include <linux/slab.h> |
| 23 | |
| 24 | #include <linux/mfd/arizona/core.h> |
| 25 | #include <linux/mfd/arizona/registers.h> |
| 26 | |
| 27 | #include "arizona.h" |
| 28 | |
| 29 | static const char *wm5102_core_supplies[] = { |
| 30 | "AVDD", |
| 31 | "DBVDD1", |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | int arizona_clk32k_enable(struct arizona *arizona) |
| 35 | { |
| 36 | int ret = 0; |
| 37 | |
| 38 | mutex_lock(&arizona->clk_lock); |
| 39 | |
| 40 | arizona->clk32k_ref++; |
| 41 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 42 | if (arizona->clk32k_ref == 1) { |
| 43 | switch (arizona->pdata.clk32k_src) { |
| 44 | case ARIZONA_32KZ_MCLK1: |
| 45 | ret = pm_runtime_get_sync(arizona->dev); |
| 46 | if (ret != 0) |
| 47 | goto out; |
| 48 | break; |
| 49 | } |
| 50 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 51 | ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 52 | ARIZONA_CLK_32K_ENA, |
| 53 | ARIZONA_CLK_32K_ENA); |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 54 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 55 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 56 | out: |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 57 | if (ret != 0) |
| 58 | arizona->clk32k_ref--; |
| 59 | |
| 60 | mutex_unlock(&arizona->clk_lock); |
| 61 | |
| 62 | return ret; |
| 63 | } |
| 64 | EXPORT_SYMBOL_GPL(arizona_clk32k_enable); |
| 65 | |
| 66 | int arizona_clk32k_disable(struct arizona *arizona) |
| 67 | { |
| 68 | int ret = 0; |
| 69 | |
| 70 | mutex_lock(&arizona->clk_lock); |
| 71 | |
| 72 | BUG_ON(arizona->clk32k_ref <= 0); |
| 73 | |
| 74 | arizona->clk32k_ref--; |
| 75 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 76 | if (arizona->clk32k_ref == 0) { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 77 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 78 | ARIZONA_CLK_32K_ENA, 0); |
| 79 | |
Mark Brown | 247fa19 | 2013-03-19 14:47:47 +0100 | [diff] [blame] | 80 | switch (arizona->pdata.clk32k_src) { |
| 81 | case ARIZONA_32KZ_MCLK1: |
| 82 | pm_runtime_put_sync(arizona->dev); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 87 | mutex_unlock(&arizona->clk_lock); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | EXPORT_SYMBOL_GPL(arizona_clk32k_disable); |
| 92 | |
| 93 | static irqreturn_t arizona_clkgen_err(int irq, void *data) |
| 94 | { |
| 95 | struct arizona *arizona = data; |
| 96 | |
| 97 | dev_err(arizona->dev, "CLKGEN error\n"); |
| 98 | |
| 99 | return IRQ_HANDLED; |
| 100 | } |
| 101 | |
| 102 | static irqreturn_t arizona_underclocked(int irq, void *data) |
| 103 | { |
| 104 | struct arizona *arizona = data; |
| 105 | unsigned int val; |
| 106 | int ret; |
| 107 | |
| 108 | ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8, |
| 109 | &val); |
| 110 | if (ret != 0) { |
| 111 | dev_err(arizona->dev, "Failed to read underclock status: %d\n", |
| 112 | ret); |
| 113 | return IRQ_NONE; |
| 114 | } |
| 115 | |
| 116 | if (val & ARIZONA_AIF3_UNDERCLOCKED_STS) |
| 117 | dev_err(arizona->dev, "AIF3 underclocked\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 118 | if (val & ARIZONA_AIF2_UNDERCLOCKED_STS) |
Charles Keepax | 3ebef34 | 2012-11-20 13:46:20 +0900 | [diff] [blame] | 119 | dev_err(arizona->dev, "AIF2 underclocked\n"); |
| 120 | if (val & ARIZONA_AIF1_UNDERCLOCKED_STS) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 121 | dev_err(arizona->dev, "AIF1 underclocked\n"); |
| 122 | if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS) |
| 123 | dev_err(arizona->dev, "ISRC2 underclocked\n"); |
| 124 | if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS) |
| 125 | dev_err(arizona->dev, "ISRC1 underclocked\n"); |
| 126 | if (val & ARIZONA_FX_UNDERCLOCKED_STS) |
| 127 | dev_err(arizona->dev, "FX underclocked\n"); |
| 128 | if (val & ARIZONA_ASRC_UNDERCLOCKED_STS) |
| 129 | dev_err(arizona->dev, "ASRC underclocked\n"); |
| 130 | if (val & ARIZONA_DAC_UNDERCLOCKED_STS) |
| 131 | dev_err(arizona->dev, "DAC underclocked\n"); |
| 132 | if (val & ARIZONA_ADC_UNDERCLOCKED_STS) |
| 133 | dev_err(arizona->dev, "ADC underclocked\n"); |
| 134 | if (val & ARIZONA_MIXER_UNDERCLOCKED_STS) |
Mark Brown | 648a988 | 2013-01-28 00:32:53 +0800 | [diff] [blame] | 135 | dev_err(arizona->dev, "Mixer dropped sample\n"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 136 | |
| 137 | return IRQ_HANDLED; |
| 138 | } |
| 139 | |
| 140 | static irqreturn_t arizona_overclocked(int irq, void *data) |
| 141 | { |
| 142 | struct arizona *arizona = data; |
| 143 | unsigned int val[2]; |
| 144 | int ret; |
| 145 | |
| 146 | ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6, |
| 147 | &val[0], 2); |
| 148 | if (ret != 0) { |
| 149 | dev_err(arizona->dev, "Failed to read overclock status: %d\n", |
| 150 | ret); |
| 151 | return IRQ_NONE; |
| 152 | } |
| 153 | |
| 154 | if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS) |
| 155 | dev_err(arizona->dev, "PWM overclocked\n"); |
| 156 | if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS) |
| 157 | dev_err(arizona->dev, "FX core overclocked\n"); |
| 158 | if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS) |
| 159 | dev_err(arizona->dev, "DAC SYS overclocked\n"); |
| 160 | if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS) |
| 161 | dev_err(arizona->dev, "DAC WARP overclocked\n"); |
| 162 | if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS) |
| 163 | dev_err(arizona->dev, "ADC overclocked\n"); |
| 164 | if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS) |
| 165 | dev_err(arizona->dev, "Mixer overclocked\n"); |
| 166 | if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS) |
| 167 | dev_err(arizona->dev, "AIF3 overclocked\n"); |
| 168 | if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS) |
| 169 | dev_err(arizona->dev, "AIF2 overclocked\n"); |
| 170 | if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS) |
| 171 | dev_err(arizona->dev, "AIF1 overclocked\n"); |
| 172 | if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS) |
| 173 | dev_err(arizona->dev, "Pad control overclocked\n"); |
| 174 | |
| 175 | if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS) |
| 176 | dev_err(arizona->dev, "Slimbus subsystem overclocked\n"); |
| 177 | if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS) |
| 178 | dev_err(arizona->dev, "Slimbus async overclocked\n"); |
| 179 | if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS) |
| 180 | dev_err(arizona->dev, "Slimbus sync overclocked\n"); |
| 181 | if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS) |
| 182 | dev_err(arizona->dev, "ASRC async system overclocked\n"); |
| 183 | if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS) |
| 184 | dev_err(arizona->dev, "ASRC async WARP overclocked\n"); |
| 185 | if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS) |
| 186 | dev_err(arizona->dev, "ASRC sync system overclocked\n"); |
| 187 | if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS) |
| 188 | dev_err(arizona->dev, "ASRC sync WARP overclocked\n"); |
| 189 | if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS) |
| 190 | dev_err(arizona->dev, "DSP1 overclocked\n"); |
| 191 | if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS) |
| 192 | dev_err(arizona->dev, "ISRC2 overclocked\n"); |
| 193 | if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS) |
| 194 | dev_err(arizona->dev, "ISRC1 overclocked\n"); |
| 195 | |
| 196 | return IRQ_HANDLED; |
| 197 | } |
| 198 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 199 | static int arizona_poll_reg(struct arizona *arizona, |
| 200 | int timeout, unsigned int reg, |
| 201 | unsigned int mask, unsigned int target) |
| 202 | { |
| 203 | unsigned int val = 0; |
| 204 | int ret, i; |
| 205 | |
| 206 | for (i = 0; i < timeout; i++) { |
| 207 | ret = regmap_read(arizona->regmap, reg, &val); |
| 208 | if (ret != 0) { |
| 209 | dev_err(arizona->dev, "Failed to read reg %u: %d\n", |
| 210 | reg, ret); |
| 211 | continue; |
| 212 | } |
| 213 | |
| 214 | if ((val & mask) == target) |
| 215 | return 0; |
| 216 | |
| 217 | msleep(1); |
| 218 | } |
| 219 | |
| 220 | dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val); |
| 221 | return -ETIMEDOUT; |
| 222 | } |
| 223 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 224 | static int arizona_wait_for_boot(struct arizona *arizona) |
| 225 | { |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 226 | int ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * We can't use an interrupt as we need to runtime resume to do so, |
| 230 | * we won't race with the interrupt handler as it'll be blocked on |
| 231 | * runtime resume. |
| 232 | */ |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 233 | ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5, |
| 234 | ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 235 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 236 | if (!ret) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 237 | regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5, |
| 238 | ARIZONA_BOOT_DONE_STS); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 239 | |
| 240 | pm_runtime_mark_last_busy(arizona->dev); |
| 241 | |
Charles Keepax | 9d53dfd | 2013-03-26 17:38:45 +0000 | [diff] [blame] | 242 | return ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 245 | static int arizona_apply_hardware_patch(struct arizona* arizona) |
| 246 | { |
| 247 | unsigned int fll, sysclk; |
| 248 | int ret, err; |
| 249 | |
| 250 | regcache_cache_bypass(arizona->regmap, true); |
| 251 | |
| 252 | /* Cache existing FLL and SYSCLK settings */ |
| 253 | ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &fll); |
| 254 | if (ret != 0) { |
| 255 | dev_err(arizona->dev, "Failed to cache FLL settings: %d\n", |
| 256 | ret); |
| 257 | return ret; |
| 258 | } |
| 259 | ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, &sysclk); |
| 260 | if (ret != 0) { |
| 261 | dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n", |
| 262 | ret); |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | /* Start up SYSCLK using the FLL in free running mode */ |
| 267 | ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, |
| 268 | ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN); |
| 269 | if (ret != 0) { |
| 270 | dev_err(arizona->dev, |
| 271 | "Failed to start FLL in freerunning mode: %d\n", |
| 272 | ret); |
| 273 | return ret; |
| 274 | } |
| 275 | ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5, |
| 276 | ARIZONA_FLL1_CLOCK_OK_STS, |
| 277 | ARIZONA_FLL1_CLOCK_OK_STS); |
| 278 | if (ret != 0) { |
| 279 | ret = -ETIMEDOUT; |
| 280 | goto err_fll; |
| 281 | } |
| 282 | |
| 283 | ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144); |
| 284 | if (ret != 0) { |
| 285 | dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret); |
| 286 | goto err_fll; |
| 287 | } |
| 288 | |
| 289 | /* Start the write sequencer and wait for it to finish */ |
| 290 | ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, |
| 291 | ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160); |
| 292 | if (ret != 0) { |
| 293 | dev_err(arizona->dev, "Failed to start write sequencer: %d\n", |
| 294 | ret); |
| 295 | goto err_sysclk; |
| 296 | } |
| 297 | ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1, |
| 298 | ARIZONA_WSEQ_BUSY, 0); |
| 299 | if (ret != 0) { |
| 300 | regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, |
| 301 | ARIZONA_WSEQ_ABORT); |
| 302 | ret = -ETIMEDOUT; |
| 303 | } |
| 304 | |
| 305 | err_sysclk: |
| 306 | err = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, sysclk); |
| 307 | if (err != 0) { |
| 308 | dev_err(arizona->dev, |
| 309 | "Failed to re-apply old SYSCLK settings: %d\n", |
| 310 | err); |
| 311 | } |
| 312 | |
| 313 | err_fll: |
| 314 | err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, fll); |
| 315 | if (err != 0) { |
| 316 | dev_err(arizona->dev, |
| 317 | "Failed to re-apply old FLL settings: %d\n", |
| 318 | err); |
| 319 | } |
| 320 | |
| 321 | regcache_cache_bypass(arizona->regmap, false); |
| 322 | |
| 323 | if (ret != 0) |
| 324 | return ret; |
| 325 | else |
| 326 | return err; |
| 327 | } |
| 328 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 329 | #ifdef CONFIG_PM_RUNTIME |
| 330 | static int arizona_runtime_resume(struct device *dev) |
| 331 | { |
| 332 | struct arizona *arizona = dev_get_drvdata(dev); |
| 333 | int ret; |
| 334 | |
Mark Brown | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 335 | dev_dbg(arizona->dev, "Leaving AoD mode\n"); |
| 336 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 337 | ret = regulator_enable(arizona->dcvdd); |
| 338 | if (ret != 0) { |
| 339 | dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret); |
| 340 | return ret; |
| 341 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 342 | |
| 343 | regcache_cache_only(arizona->regmap, false); |
| 344 | |
Charles Keepax | 4c9bb8b | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 345 | switch (arizona->type) { |
| 346 | case WM5102: |
| 347 | ret = wm5102_patch(arizona); |
| 348 | if (ret != 0) { |
| 349 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 350 | ret); |
| 351 | goto err; |
| 352 | } |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 353 | |
| 354 | ret = arizona_apply_hardware_patch(arizona); |
| 355 | if (ret != 0) { |
| 356 | dev_err(arizona->dev, |
| 357 | "Failed to apply hardware patch: %d\n", |
| 358 | ret); |
| 359 | goto err; |
| 360 | } |
| 361 | break; |
| 362 | default: |
Charles Keepax | 12bb68e | 2013-03-27 09:49:40 +0000 | [diff] [blame] | 363 | ret = arizona_wait_for_boot(arizona); |
| 364 | if (ret != 0) { |
| 365 | goto err; |
| 366 | } |
| 367 | |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 368 | break; |
Charles Keepax | 4c9bb8b | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Charles Keepax | d9d0349 | 2013-03-26 18:01:49 +0000 | [diff] [blame] | 371 | switch (arizona->type) { |
| 372 | case WM5102: |
| 373 | ret = wm5102_patch(arizona); |
| 374 | if (ret != 0) { |
| 375 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 376 | ret); |
| 377 | goto err; |
| 378 | } |
| 379 | default: |
| 380 | break; |
| 381 | } |
| 382 | |
Mark Brown | 9270bdf | 2013-01-04 17:16:12 +0000 | [diff] [blame] | 383 | ret = regcache_sync(arizona->regmap); |
| 384 | if (ret != 0) { |
| 385 | dev_err(arizona->dev, "Failed to restore register cache\n"); |
Mark Brown | 4816bd1 | 2013-01-14 15:50:38 +0900 | [diff] [blame] | 386 | goto err; |
Mark Brown | 9270bdf | 2013-01-04 17:16:12 +0000 | [diff] [blame] | 387 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 388 | |
| 389 | return 0; |
Mark Brown | 4816bd1 | 2013-01-14 15:50:38 +0900 | [diff] [blame] | 390 | |
| 391 | err: |
| 392 | regcache_cache_only(arizona->regmap, true); |
| 393 | regulator_disable(arizona->dcvdd); |
| 394 | return ret; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static int arizona_runtime_suspend(struct device *dev) |
| 398 | { |
| 399 | struct arizona *arizona = dev_get_drvdata(dev); |
| 400 | |
Mark Brown | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 401 | dev_dbg(arizona->dev, "Entering AoD mode\n"); |
| 402 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 403 | regulator_disable(arizona->dcvdd); |
| 404 | regcache_cache_only(arizona->regmap, true); |
| 405 | regcache_mark_dirty(arizona->regmap); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | #endif |
| 410 | |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 411 | #ifdef CONFIG_PM_SLEEP |
| 412 | static int arizona_resume_noirq(struct device *dev) |
| 413 | { |
| 414 | struct arizona *arizona = dev_get_drvdata(dev); |
| 415 | |
| 416 | dev_dbg(arizona->dev, "Early resume, disabling IRQ\n"); |
| 417 | disable_irq(arizona->irq); |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int arizona_resume(struct device *dev) |
| 423 | { |
| 424 | struct arizona *arizona = dev_get_drvdata(dev); |
| 425 | |
| 426 | dev_dbg(arizona->dev, "Late resume, reenabling IRQ\n"); |
| 427 | enable_irq(arizona->irq); |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | #endif |
| 432 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 433 | const struct dev_pm_ops arizona_pm_ops = { |
| 434 | SET_RUNTIME_PM_OPS(arizona_runtime_suspend, |
| 435 | arizona_runtime_resume, |
| 436 | NULL) |
Mark Brown | dc781d0 | 2013-01-27 12:07:32 +0800 | [diff] [blame] | 437 | SET_SYSTEM_SLEEP_PM_OPS(NULL, arizona_resume) |
| 438 | #ifdef CONFIG_PM_SLEEP |
| 439 | .resume_noirq = arizona_resume_noirq, |
| 440 | #endif |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 441 | }; |
| 442 | EXPORT_SYMBOL_GPL(arizona_pm_ops); |
| 443 | |
| 444 | static struct mfd_cell early_devs[] = { |
| 445 | { .name = "arizona-ldo1" }, |
| 446 | }; |
| 447 | |
| 448 | static struct mfd_cell wm5102_devs[] = { |
Mark Brown | d776811 | 2012-12-20 15:38:03 +0000 | [diff] [blame] | 449 | { .name = "arizona-micsupp" }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 450 | { .name = "arizona-extcon" }, |
| 451 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 452 | { .name = "arizona-haptics" }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 453 | { .name = "arizona-pwm" }, |
| 454 | { .name = "wm5102-codec" }, |
| 455 | }; |
| 456 | |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 457 | static struct mfd_cell wm5110_devs[] = { |
Mark Brown | d776811 | 2012-12-20 15:38:03 +0000 | [diff] [blame] | 458 | { .name = "arizona-micsupp" }, |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 459 | { .name = "arizona-extcon" }, |
| 460 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 461 | { .name = "arizona-haptics" }, |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 462 | { .name = "arizona-pwm" }, |
| 463 | { .name = "wm5110-codec" }, |
| 464 | }; |
| 465 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 466 | int arizona_dev_init(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 467 | { |
| 468 | struct device *dev = arizona->dev; |
| 469 | const char *type_name; |
| 470 | unsigned int reg, val; |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 471 | int (*apply_patch)(struct arizona *) = NULL; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 472 | int ret, i; |
| 473 | |
| 474 | dev_set_drvdata(arizona->dev, arizona); |
| 475 | mutex_init(&arizona->clk_lock); |
| 476 | |
| 477 | if (dev_get_platdata(arizona->dev)) |
| 478 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), |
| 479 | sizeof(arizona->pdata)); |
| 480 | |
| 481 | regcache_cache_only(arizona->regmap, true); |
| 482 | |
| 483 | switch (arizona->type) { |
| 484 | case WM5102: |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 485 | case WM5110: |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 486 | for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) |
| 487 | arizona->core_supplies[i].supply |
| 488 | = wm5102_core_supplies[i]; |
| 489 | arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); |
| 490 | break; |
| 491 | default: |
| 492 | dev_err(arizona->dev, "Unknown device type %d\n", |
| 493 | arizona->type); |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | ret = mfd_add_devices(arizona->dev, -1, early_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 498 | ARRAY_SIZE(early_devs), NULL, 0, NULL); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 499 | if (ret != 0) { |
| 500 | dev_err(dev, "Failed to add early children: %d\n", ret); |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, |
| 505 | arizona->core_supplies); |
| 506 | if (ret != 0) { |
| 507 | dev_err(dev, "Failed to request core supplies: %d\n", |
| 508 | ret); |
| 509 | goto err_early; |
| 510 | } |
| 511 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 512 | arizona->dcvdd = devm_regulator_get(arizona->dev, "DCVDD"); |
| 513 | if (IS_ERR(arizona->dcvdd)) { |
| 514 | ret = PTR_ERR(arizona->dcvdd); |
| 515 | dev_err(dev, "Failed to request DCVDD: %d\n", ret); |
| 516 | goto err_early; |
| 517 | } |
| 518 | |
Mark Brown | 87d3af4 | 2013-03-26 12:15:26 +0000 | [diff] [blame] | 519 | if (arizona->pdata.reset) { |
| 520 | /* Start out with /RESET low to put the chip into reset */ |
| 521 | ret = gpio_request_one(arizona->pdata.reset, |
| 522 | GPIOF_DIR_OUT | GPIOF_INIT_LOW, |
| 523 | "arizona /RESET"); |
| 524 | if (ret != 0) { |
| 525 | dev_err(dev, "Failed to request /RESET: %d\n", ret); |
| 526 | goto err_early; |
| 527 | } |
| 528 | } |
| 529 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 530 | ret = regulator_bulk_enable(arizona->num_core_supplies, |
| 531 | arizona->core_supplies); |
| 532 | if (ret != 0) { |
| 533 | dev_err(dev, "Failed to enable core supplies: %d\n", |
| 534 | ret); |
| 535 | goto err_early; |
| 536 | } |
| 537 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 538 | ret = regulator_enable(arizona->dcvdd); |
| 539 | if (ret != 0) { |
| 540 | dev_err(dev, "Failed to enable DCVDD: %d\n", ret); |
| 541 | goto err_enable; |
| 542 | } |
| 543 | |
Charles Keepax | c25feaa | 2013-04-03 12:53:37 +0100 | [diff] [blame] | 544 | if (arizona->pdata.reset) { |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 545 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
Charles Keepax | c25feaa | 2013-04-03 12:53:37 +0100 | [diff] [blame] | 546 | msleep(1); |
| 547 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 548 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 549 | regcache_cache_only(arizona->regmap, false); |
| 550 | |
Mark Brown | ca76ceb | 2013-04-09 16:04:35 +0100 | [diff] [blame] | 551 | /* Verify that this is a chip we know about */ |
| 552 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 553 | if (ret != 0) { |
| 554 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
| 555 | goto err_reset; |
| 556 | } |
| 557 | |
| 558 | switch (reg) { |
| 559 | case 0x5102: |
| 560 | case 0x5110: |
| 561 | break; |
| 562 | default: |
| 563 | dev_err(arizona->dev, "Unknown device ID: %x\n", reg); |
| 564 | goto err_reset; |
| 565 | } |
| 566 | |
| 567 | /* If we have a /RESET GPIO we'll already be reset */ |
| 568 | if (!arizona->pdata.reset) { |
| 569 | regcache_mark_dirty(arizona->regmap); |
| 570 | |
| 571 | ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); |
| 572 | if (ret != 0) { |
| 573 | dev_err(dev, "Failed to reset device: %d\n", ret); |
| 574 | goto err_reset; |
| 575 | } |
| 576 | |
| 577 | msleep(1); |
| 578 | |
| 579 | ret = regcache_sync(arizona->regmap); |
| 580 | if (ret != 0) { |
| 581 | dev_err(dev, "Failed to sync device: %d\n", ret); |
| 582 | goto err_reset; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /* Ensure device startup is complete */ |
| 587 | switch (arizona->type) { |
| 588 | case WM5102: |
| 589 | ret = regmap_read(arizona->regmap, 0x19, &val); |
| 590 | if (ret != 0) |
| 591 | dev_err(dev, |
| 592 | "Failed to check write sequencer state: %d\n", |
| 593 | ret); |
| 594 | else if (val & 0x01) |
| 595 | break; |
| 596 | /* Fall through */ |
| 597 | default: |
| 598 | ret = arizona_wait_for_boot(arizona); |
| 599 | if (ret != 0) { |
| 600 | dev_err(arizona->dev, |
| 601 | "Device failed initial boot: %d\n", ret); |
| 602 | goto err_reset; |
| 603 | } |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | /* Read the device ID information & do device specific stuff */ |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 608 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 609 | if (ret != 0) { |
| 610 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 611 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, |
| 615 | &arizona->rev); |
| 616 | if (ret != 0) { |
| 617 | dev_err(dev, "Failed to read revision register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 618 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 619 | } |
| 620 | arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; |
| 621 | |
| 622 | switch (reg) { |
Mark Brown | 863df8d | 2012-07-05 20:35:31 +0100 | [diff] [blame] | 623 | #ifdef CONFIG_MFD_WM5102 |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 624 | case 0x5102: |
| 625 | type_name = "WM5102"; |
| 626 | if (arizona->type != WM5102) { |
| 627 | dev_err(arizona->dev, "WM5102 registered as %d\n", |
| 628 | arizona->type); |
| 629 | arizona->type = WM5102; |
| 630 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 631 | apply_patch = wm5102_patch; |
Mark Brown | c6d6bfb | 2013-03-26 11:14:52 +0000 | [diff] [blame] | 632 | arizona->rev &= 0x7; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 633 | break; |
Mark Brown | 863df8d | 2012-07-05 20:35:31 +0100 | [diff] [blame] | 634 | #endif |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 635 | #ifdef CONFIG_MFD_WM5110 |
| 636 | case 0x5110: |
| 637 | type_name = "WM5110"; |
| 638 | if (arizona->type != WM5110) { |
| 639 | dev_err(arizona->dev, "WM5110 registered as %d\n", |
| 640 | arizona->type); |
| 641 | arizona->type = WM5110; |
| 642 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 643 | apply_patch = wm5110_patch; |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 644 | break; |
| 645 | #endif |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 646 | default: |
| 647 | dev_err(arizona->dev, "Unknown device ID %x\n", reg); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 648 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); |
| 652 | |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 653 | if (apply_patch) { |
| 654 | ret = apply_patch(arizona); |
| 655 | if (ret != 0) { |
| 656 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 657 | ret); |
| 658 | goto err_reset; |
| 659 | } |
Charles Keepax | e80436b | 2013-03-26 18:46:15 +0000 | [diff] [blame] | 660 | |
| 661 | switch (arizona->type) { |
| 662 | case WM5102: |
| 663 | ret = arizona_apply_hardware_patch(arizona); |
| 664 | if (ret != 0) { |
| 665 | dev_err(arizona->dev, |
| 666 | "Failed to apply hardware patch: %d\n", |
| 667 | ret); |
| 668 | goto err_reset; |
| 669 | } |
| 670 | break; |
| 671 | default: |
| 672 | break; |
| 673 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 674 | } |
| 675 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 676 | for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { |
| 677 | if (!arizona->pdata.gpio_defaults[i]) |
| 678 | continue; |
| 679 | |
| 680 | regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, |
| 681 | arizona->pdata.gpio_defaults[i]); |
| 682 | } |
| 683 | |
| 684 | pm_runtime_set_autosuspend_delay(arizona->dev, 100); |
| 685 | pm_runtime_use_autosuspend(arizona->dev); |
| 686 | pm_runtime_enable(arizona->dev); |
| 687 | |
| 688 | /* Chip default */ |
| 689 | if (!arizona->pdata.clk32k_src) |
| 690 | arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; |
| 691 | |
| 692 | switch (arizona->pdata.clk32k_src) { |
| 693 | case ARIZONA_32KZ_MCLK1: |
| 694 | case ARIZONA_32KZ_MCLK2: |
| 695 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 696 | ARIZONA_CLK_32K_SRC_MASK, |
| 697 | arizona->pdata.clk32k_src - 1); |
Mark Brown | 767c6dc | 2013-03-19 19:04:46 +0100 | [diff] [blame] | 698 | arizona_clk32k_enable(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 699 | break; |
| 700 | case ARIZONA_32KZ_NONE: |
| 701 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 702 | ARIZONA_CLK_32K_SRC_MASK, 2); |
| 703 | break; |
| 704 | default: |
| 705 | dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", |
| 706 | arizona->pdata.clk32k_src); |
| 707 | ret = -EINVAL; |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 708 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 709 | } |
| 710 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 711 | for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) { |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 712 | if (!arizona->pdata.micbias[i].mV && |
| 713 | !arizona->pdata.micbias[i].bypass) |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 714 | continue; |
| 715 | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 716 | /* Apply default for bypass mode */ |
| 717 | if (!arizona->pdata.micbias[i].mV) |
| 718 | arizona->pdata.micbias[i].mV = 2800; |
| 719 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 720 | val = (arizona->pdata.micbias[i].mV - 1500) / 100; |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 721 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 722 | val <<= ARIZONA_MICB1_LVL_SHIFT; |
| 723 | |
| 724 | if (arizona->pdata.micbias[i].ext_cap) |
| 725 | val |= ARIZONA_MICB1_EXT_CAP; |
| 726 | |
| 727 | if (arizona->pdata.micbias[i].discharge) |
| 728 | val |= ARIZONA_MICB1_DISCH; |
| 729 | |
| 730 | if (arizona->pdata.micbias[i].fast_start) |
| 731 | val |= ARIZONA_MICB1_RATE; |
| 732 | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 733 | if (arizona->pdata.micbias[i].bypass) |
| 734 | val |= ARIZONA_MICB1_BYPASS; |
| 735 | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 736 | regmap_update_bits(arizona->regmap, |
| 737 | ARIZONA_MIC_BIAS_CTRL_1 + i, |
| 738 | ARIZONA_MICB1_LVL_MASK | |
| 739 | ARIZONA_MICB1_DISCH | |
Mark Brown | 544c7aa | 2013-01-29 18:44:41 +0800 | [diff] [blame] | 740 | ARIZONA_MICB1_BYPASS | |
Mark Brown | 3d91f82 | 2013-01-29 00:47:37 +0800 | [diff] [blame] | 741 | ARIZONA_MICB1_RATE, val); |
| 742 | } |
| 743 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 744 | for (i = 0; i < ARIZONA_MAX_INPUT; i++) { |
| 745 | /* Default for both is 0 so noop with defaults */ |
| 746 | val = arizona->pdata.dmic_ref[i] |
| 747 | << ARIZONA_IN1_DMIC_SUP_SHIFT; |
| 748 | val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT; |
| 749 | |
| 750 | regmap_update_bits(arizona->regmap, |
| 751 | ARIZONA_IN1L_CONTROL + (i * 8), |
| 752 | ARIZONA_IN1_DMIC_SUP_MASK | |
| 753 | ARIZONA_IN1_MODE_MASK, val); |
| 754 | } |
| 755 | |
| 756 | for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { |
| 757 | /* Default is 0 so noop with defaults */ |
| 758 | if (arizona->pdata.out_mono[i]) |
| 759 | val = ARIZONA_OUT1_MONO; |
| 760 | else |
| 761 | val = 0; |
| 762 | |
| 763 | regmap_update_bits(arizona->regmap, |
| 764 | ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), |
| 765 | ARIZONA_OUT1_MONO, val); |
| 766 | } |
| 767 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 768 | for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { |
| 769 | if (arizona->pdata.spk_mute[i]) |
| 770 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 771 | ARIZONA_PDM_SPK1_CTRL_1 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 772 | ARIZONA_SPK1_MUTE_ENDIAN_MASK | |
| 773 | ARIZONA_SPK1_MUTE_SEQ1_MASK, |
| 774 | arizona->pdata.spk_mute[i]); |
| 775 | |
| 776 | if (arizona->pdata.spk_fmt[i]) |
| 777 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 778 | ARIZONA_PDM_SPK1_CTRL_2 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 779 | ARIZONA_SPK1_FMT_MASK, |
| 780 | arizona->pdata.spk_fmt[i]); |
| 781 | } |
| 782 | |
| 783 | /* Set up for interrupts */ |
| 784 | ret = arizona_irq_init(arizona); |
| 785 | if (ret != 0) |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 786 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 787 | |
| 788 | arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", |
| 789 | arizona_clkgen_err, arizona); |
| 790 | arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", |
| 791 | arizona_overclocked, arizona); |
| 792 | arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", |
| 793 | arizona_underclocked, arizona); |
| 794 | |
| 795 | switch (arizona->type) { |
| 796 | case WM5102: |
| 797 | ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 798 | ARRAY_SIZE(wm5102_devs), NULL, 0, NULL); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 799 | break; |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 800 | case WM5110: |
| 801 | ret = mfd_add_devices(arizona->dev, -1, wm5110_devs, |
Charles Keepax | 78566af | 2012-11-20 13:46:19 +0900 | [diff] [blame] | 802 | ARRAY_SIZE(wm5110_devs), NULL, 0, NULL); |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 803 | break; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | if (ret != 0) { |
| 807 | dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); |
| 808 | goto err_irq; |
| 809 | } |
| 810 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 811 | #ifdef CONFIG_PM_RUNTIME |
| 812 | regulator_disable(arizona->dcvdd); |
| 813 | #endif |
| 814 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 815 | return 0; |
| 816 | |
| 817 | err_irq: |
| 818 | arizona_irq_exit(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 819 | err_reset: |
| 820 | if (arizona->pdata.reset) { |
Mark Brown | 87d3af4 | 2013-03-26 12:15:26 +0000 | [diff] [blame] | 821 | gpio_set_value_cansleep(arizona->pdata.reset, 0); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 822 | gpio_free(arizona->pdata.reset); |
| 823 | } |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 824 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 825 | err_enable: |
Mark Brown | 3a36a0db | 2012-07-09 00:45:53 +0200 | [diff] [blame] | 826 | regulator_bulk_disable(arizona->num_core_supplies, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 827 | arizona->core_supplies); |
| 828 | err_early: |
| 829 | mfd_remove_devices(dev); |
| 830 | return ret; |
| 831 | } |
| 832 | EXPORT_SYMBOL_GPL(arizona_dev_init); |
| 833 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 834 | int arizona_dev_exit(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 835 | { |
| 836 | mfd_remove_devices(arizona->dev); |
| 837 | arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona); |
| 838 | arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona); |
| 839 | arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona); |
| 840 | pm_runtime_disable(arizona->dev); |
| 841 | arizona_irq_exit(arizona); |
Mark Brown | 1d017b6 | 2013-03-26 12:16:26 +0000 | [diff] [blame^] | 842 | if (arizona->pdata.reset) |
| 843 | gpio_set_value_cansleep(arizona->pdata.reset, 0); |
| 844 | regulator_disable(arizona->dcvdd); |
| 845 | regulator_bulk_disable(ARRAY_SIZE(arizona->core_supplies), |
| 846 | arizona->core_supplies); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | EXPORT_SYMBOL_GPL(arizona_dev_exit); |