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"); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 101 | if (val & ARIZONA_AIF2_UNDERCLOCKED_STS) |
Charles Keepax | 3ebef34 | 2012-11-20 13:46:20 +0900 | [diff] [blame] | 102 | dev_err(arizona->dev, "AIF2 underclocked\n"); |
| 103 | if (val & ARIZONA_AIF1_UNDERCLOCKED_STS) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 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); |
Mark Brown | cfe775c | 2012-07-05 20:35:30 +0100 | [diff] [blame] | 200 | continue; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 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 | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 226 | dev_dbg(arizona->dev, "Leaving AoD mode\n"); |
| 227 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 228 | ret = regulator_enable(arizona->dcvdd); |
| 229 | if (ret != 0) { |
| 230 | dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret); |
| 231 | return ret; |
| 232 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 233 | |
| 234 | regcache_cache_only(arizona->regmap, false); |
| 235 | |
| 236 | ret = arizona_wait_for_boot(arizona); |
Mark Brown | 5879f57 | 2012-07-05 20:35:29 +0100 | [diff] [blame] | 237 | if (ret != 0) { |
| 238 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 239 | return ret; |
Mark Brown | 5879f57 | 2012-07-05 20:35:29 +0100 | [diff] [blame] | 240 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 241 | |
| 242 | regcache_sync(arizona->regmap); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static int arizona_runtime_suspend(struct device *dev) |
| 248 | { |
| 249 | struct arizona *arizona = dev_get_drvdata(dev); |
| 250 | |
Mark Brown | 508c829 | 2012-07-20 17:09:12 +0100 | [diff] [blame] | 251 | dev_dbg(arizona->dev, "Entering AoD mode\n"); |
| 252 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 253 | regulator_disable(arizona->dcvdd); |
| 254 | regcache_cache_only(arizona->regmap, true); |
| 255 | regcache_mark_dirty(arizona->regmap); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | #endif |
| 260 | |
| 261 | const struct dev_pm_ops arizona_pm_ops = { |
| 262 | SET_RUNTIME_PM_OPS(arizona_runtime_suspend, |
| 263 | arizona_runtime_resume, |
| 264 | NULL) |
| 265 | }; |
| 266 | EXPORT_SYMBOL_GPL(arizona_pm_ops); |
| 267 | |
| 268 | static struct mfd_cell early_devs[] = { |
| 269 | { .name = "arizona-ldo1" }, |
| 270 | }; |
| 271 | |
| 272 | static struct mfd_cell wm5102_devs[] = { |
| 273 | { .name = "arizona-extcon" }, |
| 274 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 275 | { .name = "arizona-haptics" }, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 276 | { .name = "arizona-micsupp" }, |
| 277 | { .name = "arizona-pwm" }, |
| 278 | { .name = "wm5102-codec" }, |
| 279 | }; |
| 280 | |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 281 | static struct mfd_cell wm5110_devs[] = { |
| 282 | { .name = "arizona-extcon" }, |
| 283 | { .name = "arizona-gpio" }, |
Mark Brown | 503b1ca | 2012-11-27 17:36:38 +0000 | [diff] [blame] | 284 | { .name = "arizona-haptics" }, |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 285 | { .name = "arizona-micsupp" }, |
| 286 | { .name = "arizona-pwm" }, |
| 287 | { .name = "wm5110-codec" }, |
| 288 | }; |
| 289 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 290 | int arizona_dev_init(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 291 | { |
| 292 | struct device *dev = arizona->dev; |
| 293 | const char *type_name; |
| 294 | unsigned int reg, val; |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 295 | int (*apply_patch)(struct arizona *) = NULL; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 296 | int ret, i; |
| 297 | |
| 298 | dev_set_drvdata(arizona->dev, arizona); |
| 299 | mutex_init(&arizona->clk_lock); |
| 300 | |
| 301 | if (dev_get_platdata(arizona->dev)) |
| 302 | memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), |
| 303 | sizeof(arizona->pdata)); |
| 304 | |
| 305 | regcache_cache_only(arizona->regmap, true); |
| 306 | |
| 307 | switch (arizona->type) { |
| 308 | case WM5102: |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 309 | case WM5110: |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 310 | for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) |
| 311 | arizona->core_supplies[i].supply |
| 312 | = wm5102_core_supplies[i]; |
| 313 | arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); |
| 314 | break; |
| 315 | default: |
| 316 | dev_err(arizona->dev, "Unknown device type %d\n", |
| 317 | arizona->type); |
| 318 | return -EINVAL; |
| 319 | } |
| 320 | |
| 321 | ret = mfd_add_devices(arizona->dev, -1, early_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 322 | ARRAY_SIZE(early_devs), NULL, 0, NULL); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 323 | if (ret != 0) { |
| 324 | dev_err(dev, "Failed to add early children: %d\n", ret); |
| 325 | return ret; |
| 326 | } |
| 327 | |
| 328 | ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, |
| 329 | arizona->core_supplies); |
| 330 | if (ret != 0) { |
| 331 | dev_err(dev, "Failed to request core supplies: %d\n", |
| 332 | ret); |
| 333 | goto err_early; |
| 334 | } |
| 335 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 336 | arizona->dcvdd = devm_regulator_get(arizona->dev, "DCVDD"); |
| 337 | if (IS_ERR(arizona->dcvdd)) { |
| 338 | ret = PTR_ERR(arizona->dcvdd); |
| 339 | dev_err(dev, "Failed to request DCVDD: %d\n", ret); |
| 340 | goto err_early; |
| 341 | } |
| 342 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 343 | ret = regulator_bulk_enable(arizona->num_core_supplies, |
| 344 | arizona->core_supplies); |
| 345 | if (ret != 0) { |
| 346 | dev_err(dev, "Failed to enable core supplies: %d\n", |
| 347 | ret); |
| 348 | goto err_early; |
| 349 | } |
| 350 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 351 | ret = regulator_enable(arizona->dcvdd); |
| 352 | if (ret != 0) { |
| 353 | dev_err(dev, "Failed to enable DCVDD: %d\n", ret); |
| 354 | goto err_enable; |
| 355 | } |
| 356 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 357 | if (arizona->pdata.reset) { |
| 358 | /* Start out with /RESET low to put the chip into reset */ |
| 359 | ret = gpio_request_one(arizona->pdata.reset, |
| 360 | GPIOF_DIR_OUT | GPIOF_INIT_LOW, |
| 361 | "arizona /RESET"); |
| 362 | if (ret != 0) { |
| 363 | dev_err(dev, "Failed to request /RESET: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 364 | goto err_dcvdd; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
| 368 | } |
| 369 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 370 | regcache_cache_only(arizona->regmap, false); |
| 371 | |
| 372 | ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); |
| 373 | if (ret != 0) { |
| 374 | dev_err(dev, "Failed to read ID register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 375 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, |
| 379 | &arizona->rev); |
| 380 | if (ret != 0) { |
| 381 | dev_err(dev, "Failed to read revision register: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 382 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 383 | } |
| 384 | arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; |
| 385 | |
| 386 | switch (reg) { |
Mark Brown | 863df8d | 2012-07-05 20:35:31 +0100 | [diff] [blame] | 387 | #ifdef CONFIG_MFD_WM5102 |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 388 | case 0x5102: |
| 389 | type_name = "WM5102"; |
| 390 | if (arizona->type != WM5102) { |
| 391 | dev_err(arizona->dev, "WM5102 registered as %d\n", |
| 392 | arizona->type); |
| 393 | arizona->type = WM5102; |
| 394 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 395 | apply_patch = wm5102_patch; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 396 | break; |
Mark Brown | 863df8d | 2012-07-05 20:35:31 +0100 | [diff] [blame] | 397 | #endif |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 398 | #ifdef CONFIG_MFD_WM5110 |
| 399 | case 0x5110: |
| 400 | type_name = "WM5110"; |
| 401 | if (arizona->type != WM5110) { |
| 402 | dev_err(arizona->dev, "WM5110 registered as %d\n", |
| 403 | arizona->type); |
| 404 | arizona->type = WM5110; |
| 405 | } |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 406 | apply_patch = wm5110_patch; |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 407 | break; |
| 408 | #endif |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 409 | default: |
| 410 | dev_err(arizona->dev, "Unknown device ID %x\n", reg); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 411 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); |
| 415 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 416 | /* If we have a /RESET GPIO we'll already be reset */ |
| 417 | if (!arizona->pdata.reset) { |
Charles Keepax | 46b9d13 | 2012-11-20 14:49:10 +0900 | [diff] [blame] | 418 | regcache_mark_dirty(arizona->regmap); |
| 419 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 420 | ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); |
| 421 | if (ret != 0) { |
| 422 | dev_err(dev, "Failed to reset device: %d\n", ret); |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 423 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 424 | } |
Charles Keepax | 46b9d13 | 2012-11-20 14:49:10 +0900 | [diff] [blame] | 425 | |
| 426 | ret = regcache_sync(arizona->regmap); |
| 427 | if (ret != 0) { |
| 428 | dev_err(dev, "Failed to sync device: %d\n", ret); |
| 429 | goto err_reset; |
| 430 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Mark Brown | af65a36 | 2012-07-09 11:56:43 +0100 | [diff] [blame] | 433 | ret = arizona_wait_for_boot(arizona); |
| 434 | if (ret != 0) { |
| 435 | dev_err(arizona->dev, "Device failed initial boot: %d\n", ret); |
| 436 | goto err_reset; |
| 437 | } |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 438 | |
Mark Brown | 62d62b5 | 2012-12-02 11:41:46 +0900 | [diff] [blame] | 439 | if (apply_patch) { |
| 440 | ret = apply_patch(arizona); |
| 441 | if (ret != 0) { |
| 442 | dev_err(arizona->dev, "Failed to apply patch: %d\n", |
| 443 | ret); |
| 444 | goto err_reset; |
| 445 | } |
| 446 | } |
| 447 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 448 | for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { |
| 449 | if (!arizona->pdata.gpio_defaults[i]) |
| 450 | continue; |
| 451 | |
| 452 | regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, |
| 453 | arizona->pdata.gpio_defaults[i]); |
| 454 | } |
| 455 | |
| 456 | pm_runtime_set_autosuspend_delay(arizona->dev, 100); |
| 457 | pm_runtime_use_autosuspend(arizona->dev); |
| 458 | pm_runtime_enable(arizona->dev); |
| 459 | |
| 460 | /* Chip default */ |
| 461 | if (!arizona->pdata.clk32k_src) |
| 462 | arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; |
| 463 | |
| 464 | switch (arizona->pdata.clk32k_src) { |
| 465 | case ARIZONA_32KZ_MCLK1: |
| 466 | case ARIZONA_32KZ_MCLK2: |
| 467 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 468 | ARIZONA_CLK_32K_SRC_MASK, |
| 469 | arizona->pdata.clk32k_src - 1); |
| 470 | break; |
| 471 | case ARIZONA_32KZ_NONE: |
| 472 | regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, |
| 473 | ARIZONA_CLK_32K_SRC_MASK, 2); |
| 474 | break; |
| 475 | default: |
| 476 | dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", |
| 477 | arizona->pdata.clk32k_src); |
| 478 | ret = -EINVAL; |
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 | |
| 482 | for (i = 0; i < ARIZONA_MAX_INPUT; i++) { |
| 483 | /* Default for both is 0 so noop with defaults */ |
| 484 | val = arizona->pdata.dmic_ref[i] |
| 485 | << ARIZONA_IN1_DMIC_SUP_SHIFT; |
| 486 | val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT; |
| 487 | |
| 488 | regmap_update_bits(arizona->regmap, |
| 489 | ARIZONA_IN1L_CONTROL + (i * 8), |
| 490 | ARIZONA_IN1_DMIC_SUP_MASK | |
| 491 | ARIZONA_IN1_MODE_MASK, val); |
| 492 | } |
| 493 | |
| 494 | for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { |
| 495 | /* Default is 0 so noop with defaults */ |
| 496 | if (arizona->pdata.out_mono[i]) |
| 497 | val = ARIZONA_OUT1_MONO; |
| 498 | else |
| 499 | val = 0; |
| 500 | |
| 501 | regmap_update_bits(arizona->regmap, |
| 502 | ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), |
| 503 | ARIZONA_OUT1_MONO, val); |
| 504 | } |
| 505 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 506 | for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { |
| 507 | if (arizona->pdata.spk_mute[i]) |
| 508 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 509 | ARIZONA_PDM_SPK1_CTRL_1 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 510 | ARIZONA_SPK1_MUTE_ENDIAN_MASK | |
| 511 | ARIZONA_SPK1_MUTE_SEQ1_MASK, |
| 512 | arizona->pdata.spk_mute[i]); |
| 513 | |
| 514 | if (arizona->pdata.spk_fmt[i]) |
| 515 | regmap_update_bits(arizona->regmap, |
Mark Brown | 2a51da0 | 2012-07-09 19:33:14 +0100 | [diff] [blame] | 516 | ARIZONA_PDM_SPK1_CTRL_2 + (i * 2), |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 517 | ARIZONA_SPK1_FMT_MASK, |
| 518 | arizona->pdata.spk_fmt[i]); |
| 519 | } |
| 520 | |
| 521 | /* Set up for interrupts */ |
| 522 | ret = arizona_irq_init(arizona); |
| 523 | if (ret != 0) |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 524 | goto err_reset; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 525 | |
| 526 | arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", |
| 527 | arizona_clkgen_err, arizona); |
| 528 | arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", |
| 529 | arizona_overclocked, arizona); |
| 530 | arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", |
| 531 | arizona_underclocked, arizona); |
| 532 | |
| 533 | switch (arizona->type) { |
| 534 | case WM5102: |
| 535 | ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 536 | ARRAY_SIZE(wm5102_devs), NULL, 0, NULL); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 537 | break; |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 538 | case WM5110: |
| 539 | ret = mfd_add_devices(arizona->dev, -1, wm5110_devs, |
Charles Keepax | 78566af | 2012-11-20 13:46:19 +0900 | [diff] [blame] | 540 | ARRAY_SIZE(wm5110_devs), NULL, 0, NULL); |
Mark Brown | e102bef | 2012-07-10 12:37:58 +0100 | [diff] [blame] | 541 | break; |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if (ret != 0) { |
| 545 | dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); |
| 546 | goto err_irq; |
| 547 | } |
| 548 | |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 549 | #ifdef CONFIG_PM_RUNTIME |
| 550 | regulator_disable(arizona->dcvdd); |
| 551 | #endif |
| 552 | |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 553 | return 0; |
| 554 | |
| 555 | err_irq: |
| 556 | arizona_irq_exit(arizona); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 557 | err_reset: |
| 558 | if (arizona->pdata.reset) { |
| 559 | gpio_set_value_cansleep(arizona->pdata.reset, 1); |
| 560 | gpio_free(arizona->pdata.reset); |
| 561 | } |
Mark Brown | 59db969 | 2012-07-09 00:31:36 +0200 | [diff] [blame] | 562 | err_dcvdd: |
| 563 | regulator_disable(arizona->dcvdd); |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 564 | err_enable: |
Mark Brown | 3a36a0db | 2012-07-09 00:45:53 +0200 | [diff] [blame] | 565 | regulator_bulk_disable(arizona->num_core_supplies, |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 566 | arizona->core_supplies); |
| 567 | err_early: |
| 568 | mfd_remove_devices(dev); |
| 569 | return ret; |
| 570 | } |
| 571 | EXPORT_SYMBOL_GPL(arizona_dev_init); |
| 572 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 573 | int arizona_dev_exit(struct arizona *arizona) |
Mark Brown | 3cc7298 | 2012-06-19 16:31:53 +0100 | [diff] [blame] | 574 | { |
| 575 | mfd_remove_devices(arizona->dev); |
| 576 | arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona); |
| 577 | arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona); |
| 578 | arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona); |
| 579 | pm_runtime_disable(arizona->dev); |
| 580 | arizona_irq_exit(arizona); |
| 581 | return 0; |
| 582 | } |
| 583 | EXPORT_SYMBOL_GPL(arizona_dev_exit); |