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 | |
| 42 | if (arizona->clk32k_ref == 1) |
| 43 | ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 44 | ARIZONA_CLK_32K_ENA, |
| 45 | ARIZONA_CLK_32K_ENA); |
| 46 | |
| 47 | if (ret != 0) |
| 48 | arizona->clk32k_ref--; |
| 49 | |
| 50 | mutex_unlock(&arizona->clk_lock); |
| 51 | |
| 52 | return ret; |
| 53 | } |
| 54 | EXPORT_SYMBOL_GPL(arizona_clk32k_enable); |
| 55 | |
| 56 | int arizona_clk32k_disable(struct arizona *arizona) |
| 57 | { |
| 58 | int ret = 0; |
| 59 | |
| 60 | mutex_lock(&arizona->clk_lock); |
| 61 | |
| 62 | BUG_ON(arizona->clk32k_ref <= 0); |
| 63 | |
| 64 | arizona->clk32k_ref--; |
| 65 | |
| 66 | if (arizona->clk32k_ref == 0) |
| 67 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 68 | ARIZONA_CLK_32K_ENA, 0); |
| 69 | |
| 70 | mutex_unlock(&arizona->clk_lock); |
| 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | EXPORT_SYMBOL_GPL(arizona_clk32k_disable); |
| 75 | |
| 76 | static irqreturn_t arizona_clkgen_err(int irq, void *data) |
| 77 | { |
| 78 | struct arizona *arizona = data; |
| 79 | |
| 80 | dev_err(arizona->dev, "CLKGEN error\n"); |
| 81 | |
| 82 | return IRQ_HANDLED; |
| 83 | } |
| 84 | |
| 85 | static irqreturn_t arizona_underclocked(int irq, void *data) |
| 86 | { |
| 87 | struct arizona *arizona = data; |
| 88 | unsigned int val; |
| 89 | int ret; |
| 90 | |
| 91 | ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8, |
| 92 | &val); |
| 93 | if (ret != 0) { |
| 94 | dev_err(arizona->dev, "Failed to read underclock status: %d\n", |
| 95 | ret); |
| 96 | return IRQ_NONE; |
| 97 | } |
| 98 | |
| 99 | if (val & ARIZONA_AIF3_UNDERCLOCKED_STS) |
| 100 | dev_err(arizona->dev, "AIF3 underclocked\n"); |
| 101 | if (val & ARIZONA_AIF3_UNDERCLOCKED_STS) |
| 102 | dev_err(arizona->dev, "AIF3 underclocked\n"); |
| 103 | if (val & ARIZONA_AIF2_UNDERCLOCKED_STS) |
| 104 | dev_err(arizona->dev, "AIF1 underclocked\n"); |
| 105 | if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS) |
| 106 | dev_err(arizona->dev, "ISRC2 underclocked\n"); |
| 107 | if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS) |
| 108 | dev_err(arizona->dev, "ISRC1 underclocked\n"); |
| 109 | if (val & ARIZONA_FX_UNDERCLOCKED_STS) |
| 110 | dev_err(arizona->dev, "FX underclocked\n"); |
| 111 | if (val & ARIZONA_ASRC_UNDERCLOCKED_STS) |
| 112 | dev_err(arizona->dev, "ASRC underclocked\n"); |
| 113 | if (val & ARIZONA_DAC_UNDERCLOCKED_STS) |
| 114 | dev_err(arizona->dev, "DAC underclocked\n"); |
| 115 | if (val & ARIZONA_ADC_UNDERCLOCKED_STS) |
| 116 | dev_err(arizona->dev, "ADC underclocked\n"); |
| 117 | if (val & ARIZONA_MIXER_UNDERCLOCKED_STS) |
| 118 | dev_err(arizona->dev, "Mixer underclocked\n"); |
| 119 | |
| 120 | return IRQ_HANDLED; |
| 121 | } |
| 122 | |
| 123 | static irqreturn_t arizona_overclocked(int irq, void *data) |
| 124 | { |
| 125 | struct arizona *arizona = data; |
| 126 | unsigned int val[2]; |
| 127 | int ret; |
| 128 | |
| 129 | ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6, |
| 130 | &val[0], 2); |
| 131 | if (ret != 0) { |
| 132 | dev_err(arizona->dev, "Failed to read overclock status: %d\n", |
| 133 | ret); |
| 134 | return IRQ_NONE; |
| 135 | } |
| 136 | |
| 137 | if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS) |
| 138 | dev_err(arizona->dev, "PWM overclocked\n"); |
| 139 | if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS) |
| 140 | dev_err(arizona->dev, "FX core overclocked\n"); |
| 141 | if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS) |
| 142 | dev_err(arizona->dev, "DAC SYS overclocked\n"); |
| 143 | if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS) |
| 144 | dev_err(arizona->dev, "DAC WARP overclocked\n"); |
| 145 | if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS) |
| 146 | dev_err(arizona->dev, "ADC overclocked\n"); |
| 147 | if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS) |
| 148 | dev_err(arizona->dev, "Mixer overclocked\n"); |
| 149 | if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS) |
| 150 | dev_err(arizona->dev, "AIF3 overclocked\n"); |
| 151 | if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS) |
| 152 | dev_err(arizona->dev, "AIF2 overclocked\n"); |
| 153 | if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS) |
| 154 | dev_err(arizona->dev, "AIF1 overclocked\n"); |
| 155 | if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS) |
| 156 | dev_err(arizona->dev, "Pad control overclocked\n"); |
| 157 | |
| 158 | if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS) |
| 159 | dev_err(arizona->dev, "Slimbus subsystem overclocked\n"); |
| 160 | if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS) |
| 161 | dev_err(arizona->dev, "Slimbus async overclocked\n"); |
| 162 | if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS) |
| 163 | dev_err(arizona->dev, "Slimbus sync overclocked\n"); |
| 164 | if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS) |
| 165 | dev_err(arizona->dev, "ASRC async system overclocked\n"); |
| 166 | if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS) |
| 167 | dev_err(arizona->dev, "ASRC async WARP overclocked\n"); |
| 168 | if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS) |
| 169 | dev_err(arizona->dev, "ASRC sync system overclocked\n"); |
| 170 | if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS) |
| 171 | dev_err(arizona->dev, "ASRC sync WARP overclocked\n"); |
| 172 | if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS) |
| 173 | dev_err(arizona->dev, "DSP1 overclocked\n"); |
| 174 | if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS) |
| 175 | dev_err(arizona->dev, "ISRC2 overclocked\n"); |
| 176 | if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS) |
| 177 | dev_err(arizona->dev, "ISRC1 overclocked\n"); |
| 178 | |
| 179 | return IRQ_HANDLED; |
| 180 | } |
| 181 | |
| 182 | static int arizona_wait_for_boot(struct arizona *arizona) |
| 183 | { |
| 184 | unsigned int reg; |
| 185 | int ret, i; |
| 186 | |
| 187 | /* |
| 188 | * We can't use an interrupt as we need to runtime resume to do so, |
| 189 | * we won't race with the interrupt handler as it'll be blocked on |
| 190 | * runtime resume. |
| 191 | */ |
| 192 | for (i = 0; i < 5; i++) { |
| 193 | msleep(1); |
| 194 | |
| 195 | ret = regmap_read(arizona->regmap, |
| 196 | ARIZONA_INTERRUPT_RAW_STATUS_5, ®); |
| 197 | if (ret != 0) { |
| 198 | dev_err(arizona->dev, "Failed to read boot state: %d\n", |
| 199 | ret); |
| 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | if (reg & ARIZONA_BOOT_DONE_STS) |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | if (reg & ARIZONA_BOOT_DONE_STS) { |
| 208 | regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5, |
| 209 | ARIZONA_BOOT_DONE_STS); |
| 210 | } else { |
| 211 | dev_err(arizona->dev, "Device boot timed out: %x\n", reg); |
| 212 | return -ETIMEDOUT; |
| 213 | } |
| 214 | |
| 215 | pm_runtime_mark_last_busy(arizona->dev); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | #ifdef CONFIG_PM_RUNTIME |
| 221 | static int arizona_runtime_resume(struct device *dev) |
| 222 | { |
| 223 | struct arizona *arizona = dev_get_drvdata(dev); |
| 224 | int ret; |
| 225 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 226 | ret = regulator_enable(arizona->dcvdd); |
| 227 | if (ret != 0) { |
| 228 | dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret); |
| 229 | return ret; |
| 230 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 231 | |
| 232 | regcache_cache_only(arizona->regmap, false); |
| 233 | |
| 234 | ret = arizona_wait_for_boot(arizona); |
Mark Brown | 5879f57 | 2012-07-05 20:35:29 +0100 | [diff] [blame^] | 235 | if (ret != 0) { |
| 236 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 237 | return ret; |
Mark Brown | 5879f57 | 2012-07-05 20:35:29 +0100 | [diff] [blame^] | 238 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 239 | |
| 240 | regcache_sync(arizona->regmap); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int arizona_runtime_suspend(struct device *dev) |
| 246 | { |
| 247 | struct arizona *arizona = dev_get_drvdata(dev); |
| 248 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 249 | regulator_disable(arizona->dcvdd); |
| 250 | regcache_cache_only(arizona->regmap, true); |
| 251 | regcache_mark_dirty(arizona->regmap); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | const struct dev_pm_ops arizona_pm_ops = { |
| 258 | SET_RUNTIME_PM_OPS(arizona_runtime_suspend, |
| 259 | arizona_runtime_resume, |
| 260 | NULL) |
| 261 | }; |
| 262 | EXPORT_SYMBOL_GPL(arizona_pm_ops); |
| 263 | |
| 264 | static struct mfd_cell early_devs[] = { |
| 265 | { .name = "arizona-ldo1" }, |
| 266 | }; |
| 267 | |
| 268 | static struct mfd_cell wm5102_devs[] = { |
| 269 | { .name = "arizona-extcon" }, |
| 270 | { .name = "arizona-gpio" }, |
| 271 | { .name = "arizona-micsupp" }, |
| 272 | { .name = "arizona-pwm" }, |
| 273 | { .name = "wm5102-codec" }, |
| 274 | }; |
| 275 | |
| 276 | int __devinit arizona_dev_init(struct arizona *arizona) |
| 277 | { |
| 278 | struct device *dev = arizona->dev; |
| 279 | const char *type_name; |
| 280 | unsigned int reg, val; |
| 281 | int ret, i; |
| 282 | |
| 283 | dev_set_drvdata(arizona->dev, arizona); |
| 284 | mutex_init(&arizona->clk_lock); |
| 285 | |
| 286 | if (dev_get_platdata(arizona->dev)) |
| 287 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), |
| 288 | sizeof(arizona->pdata)); |
| 289 | |
| 290 | regcache_cache_only(arizona->regmap, true); |
| 291 | |
| 292 | switch (arizona->type) { |
| 293 | case WM5102: |
| 294 | for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) |
| 295 | arizona->core_supplies[i].supply |
| 296 | = wm5102_core_supplies[i]; |
| 297 | arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); |
| 298 | break; |
| 299 | default: |
| 300 | dev_err(arizona->dev, "Unknown device type %d\n", |
| 301 | arizona->type); |
| 302 | return -EINVAL; |
| 303 | } |
| 304 | |
| 305 | ret = mfd_add_devices(arizona->dev, -1, early_devs, |
| 306 | ARRAY_SIZE(early_devs), NULL, 0); |
| 307 | if (ret != 0) { |
| 308 | dev_err(dev, "Failed to add early children: %d\n", ret); |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, |
| 313 | arizona->core_supplies); |
| 314 | if (ret != 0) { |
| 315 | dev_err(dev, "Failed to request core supplies: %d\n", |
| 316 | ret); |
| 317 | goto err_early; |
| 318 | } |
| 319 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 320 | arizona->dcvdd = devm_regulator_get(arizona->dev, "DCVDD"); |
| 321 | if (IS_ERR(arizona->dcvdd)) { |
| 322 | ret = PTR_ERR(arizona->dcvdd); |
| 323 | dev_err(dev, "Failed to request DCVDD: %d\n", ret); |
| 324 | goto err_early; |
| 325 | } |
| 326 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 327 | ret = regulator_bulk_enable(arizona->num_core_supplies, |
| 328 | arizona->core_supplies); |
| 329 | if (ret != 0) { |
| 330 | dev_err(dev, "Failed to enable core supplies: %d\n", |
| 331 | ret); |
| 332 | goto err_early; |
| 333 | } |
| 334 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 335 | ret = regulator_enable(arizona->dcvdd); |
| 336 | if (ret != 0) { |
| 337 | dev_err(dev, "Failed to enable DCVDD: %d\n", ret); |
| 338 | goto err_enable; |
| 339 | } |
| 340 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 341 | if (arizona->pdata.reset) { |
| 342 | /* Start out with /RESET low to put the chip into reset */ |
| 343 | ret = gpio_request_one(arizona->pdata.reset, |
| 344 | GPIOF_DIR_OUT | GPIOF_INIT_LOW, |
| 345 | "arizona /RESET"); |
| 346 | if (ret != 0) { |
| 347 | dev_err(dev, "Failed to request /RESET: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 348 | goto err_dcvdd; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
| 352 | } |
| 353 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 354 | regcache_cache_only(arizona->regmap, false); |
| 355 | |
| 356 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 357 | if (ret != 0) { |
| 358 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 359 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, |
| 363 | &arizona->rev); |
| 364 | if (ret != 0) { |
| 365 | dev_err(dev, "Failed to read revision register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 366 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 367 | } |
| 368 | arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; |
| 369 | |
| 370 | switch (reg) { |
| 371 | case 0x5102: |
| 372 | type_name = "WM5102"; |
| 373 | if (arizona->type != WM5102) { |
| 374 | dev_err(arizona->dev, "WM5102 registered as %d\n", |
| 375 | arizona->type); |
| 376 | arizona->type = WM5102; |
| 377 | } |
| 378 | ret = wm5102_patch(arizona); |
| 379 | break; |
| 380 | |
| 381 | default: |
| 382 | dev_err(arizona->dev, "Unknown device ID %x\n", reg); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 383 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); |
| 387 | |
| 388 | if (ret != 0) |
| 389 | dev_err(arizona->dev, "Failed to apply patch: %d\n", ret); |
| 390 | |
| 391 | /* If we have a /RESET GPIO we'll already be reset */ |
| 392 | if (!arizona->pdata.reset) { |
| 393 | ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); |
| 394 | if (ret != 0) { |
| 395 | dev_err(dev, "Failed to reset device: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 396 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
| 400 | arizona_wait_for_boot(arizona); |
| 401 | |
| 402 | for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { |
| 403 | if (!arizona->pdata.gpio_defaults[i]) |
| 404 | continue; |
| 405 | |
| 406 | regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, |
| 407 | arizona->pdata.gpio_defaults[i]); |
| 408 | } |
| 409 | |
| 410 | pm_runtime_set_autosuspend_delay(arizona->dev, 100); |
| 411 | pm_runtime_use_autosuspend(arizona->dev); |
| 412 | pm_runtime_enable(arizona->dev); |
| 413 | |
| 414 | /* Chip default */ |
| 415 | if (!arizona->pdata.clk32k_src) |
| 416 | arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; |
| 417 | |
| 418 | switch (arizona->pdata.clk32k_src) { |
| 419 | case ARIZONA_32KZ_MCLK1: |
| 420 | case ARIZONA_32KZ_MCLK2: |
| 421 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 422 | ARIZONA_CLK_32K_SRC_MASK, |
| 423 | arizona->pdata.clk32k_src - 1); |
| 424 | break; |
| 425 | case ARIZONA_32KZ_NONE: |
| 426 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 427 | ARIZONA_CLK_32K_SRC_MASK, 2); |
| 428 | break; |
| 429 | default: |
| 430 | dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", |
| 431 | arizona->pdata.clk32k_src); |
| 432 | ret = -EINVAL; |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 433 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | for (i = 0; i < ARIZONA_MAX_INPUT; i++) { |
| 437 | /* Default for both is 0 so noop with defaults */ |
| 438 | val = arizona->pdata.dmic_ref[i] |
| 439 | << ARIZONA_IN1_DMIC_SUP_SHIFT; |
| 440 | val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT; |
| 441 | |
| 442 | regmap_update_bits(arizona->regmap, |
| 443 | ARIZONA_IN1L_CONTROL + (i * 8), |
| 444 | ARIZONA_IN1_DMIC_SUP_MASK | |
| 445 | ARIZONA_IN1_MODE_MASK, val); |
| 446 | } |
| 447 | |
| 448 | for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { |
| 449 | /* Default is 0 so noop with defaults */ |
| 450 | if (arizona->pdata.out_mono[i]) |
| 451 | val = ARIZONA_OUT1_MONO; |
| 452 | else |
| 453 | val = 0; |
| 454 | |
| 455 | regmap_update_bits(arizona->regmap, |
| 456 | ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), |
| 457 | ARIZONA_OUT1_MONO, val); |
| 458 | } |
| 459 | |
| 460 | BUILD_BUG_ON(ARIZONA_MAX_PDM_SPK > 1); |
| 461 | for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { |
| 462 | if (arizona->pdata.spk_mute[i]) |
| 463 | regmap_update_bits(arizona->regmap, |
| 464 | ARIZONA_PDM_SPK1_CTRL_1, |
| 465 | ARIZONA_SPK1_MUTE_ENDIAN_MASK | |
| 466 | ARIZONA_SPK1_MUTE_SEQ1_MASK, |
| 467 | arizona->pdata.spk_mute[i]); |
| 468 | |
| 469 | if (arizona->pdata.spk_fmt[i]) |
| 470 | regmap_update_bits(arizona->regmap, |
| 471 | ARIZONA_PDM_SPK1_CTRL_2, |
| 472 | ARIZONA_SPK1_FMT_MASK, |
| 473 | arizona->pdata.spk_fmt[i]); |
| 474 | } |
| 475 | |
| 476 | /* Set up for interrupts */ |
| 477 | ret = arizona_irq_init(arizona); |
| 478 | if (ret != 0) |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 479 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 480 | |
| 481 | arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", |
| 482 | arizona_clkgen_err, arizona); |
| 483 | arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", |
| 484 | arizona_overclocked, arizona); |
| 485 | arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", |
| 486 | arizona_underclocked, arizona); |
| 487 | |
| 488 | switch (arizona->type) { |
| 489 | case WM5102: |
| 490 | ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, |
| 491 | ARRAY_SIZE(wm5102_devs), NULL, 0); |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | if (ret != 0) { |
| 496 | dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); |
| 497 | goto err_irq; |
| 498 | } |
| 499 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 500 | #ifdef CONFIG_PM_RUNTIME |
| 501 | regulator_disable(arizona->dcvdd); |
| 502 | #endif |
| 503 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 504 | return 0; |
| 505 | |
| 506 | err_irq: |
| 507 | arizona_irq_exit(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 508 | err_reset: |
| 509 | if (arizona->pdata.reset) { |
| 510 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
| 511 | gpio_free(arizona->pdata.reset); |
| 512 | } |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 513 | err_dcvdd: |
| 514 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 515 | err_enable: |
| 516 | regulator_bulk_disable(ARRAY_SIZE(arizona->core_supplies), |
| 517 | arizona->core_supplies); |
| 518 | err_early: |
| 519 | mfd_remove_devices(dev); |
| 520 | return ret; |
| 521 | } |
| 522 | EXPORT_SYMBOL_GPL(arizona_dev_init); |
| 523 | |
| 524 | int __devexit arizona_dev_exit(struct arizona *arizona) |
| 525 | { |
| 526 | mfd_remove_devices(arizona->dev); |
| 527 | arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona); |
| 528 | arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona); |
| 529 | arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona); |
| 530 | pm_runtime_disable(arizona->dev); |
| 531 | arizona_irq_exit(arizona); |
| 532 | return 0; |
| 533 | } |
| 534 | EXPORT_SYMBOL_GPL(arizona_dev_exit); |