blob: e32d0d30e9cda0f1b513b669db635ef64bedc5df [file] [log] [blame]
Mark Brown3cc72982012-06-19 16:31:53 +01001/*
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 Brown59db9692012-07-09 00:31:36 +020014#include <linux/err.h>
Mark Brown3cc72982012-06-19 16:31:53 +010015#include <linux/gpio.h>
16#include <linux/interrupt.h>
17#include <linux/mfd/core.h>
18#include <linux/module.h>
Mark Brownd7810092013-03-25 00:11:27 +000019#include <linux/of.h>
20#include <linux/of_device.h>
21#include <linux/of_gpio.h>
Mark Brown3cc72982012-06-19 16:31:53 +010022#include <linux/pm_runtime.h>
23#include <linux/regmap.h>
24#include <linux/regulator/consumer.h>
Mark Brown59274672013-04-23 19:44:16 +010025#include <linux/regulator/machine.h>
Mark Brown3cc72982012-06-19 16:31:53 +010026#include <linux/slab.h>
27
28#include <linux/mfd/arizona/core.h>
29#include <linux/mfd/arizona/registers.h>
30
31#include "arizona.h"
32
Charles Keepax3762aed2015-08-11 09:34:31 +010033static const char * const wm5102_core_supplies[] = {
Mark Brown3cc72982012-06-19 16:31:53 +010034 "AVDD",
35 "DBVDD1",
Mark Brown3cc72982012-06-19 16:31:53 +010036};
37
38int arizona_clk32k_enable(struct arizona *arizona)
39{
40 int ret = 0;
41
42 mutex_lock(&arizona->clk_lock);
43
44 arizona->clk32k_ref++;
45
Mark Brown247fa192013-03-19 14:47:47 +010046 if (arizona->clk32k_ref == 1) {
47 switch (arizona->pdata.clk32k_src) {
48 case ARIZONA_32KZ_MCLK1:
49 ret = pm_runtime_get_sync(arizona->dev);
50 if (ret != 0)
51 goto out;
52 break;
53 }
54
Mark Brown3cc72982012-06-19 16:31:53 +010055 ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
56 ARIZONA_CLK_32K_ENA,
57 ARIZONA_CLK_32K_ENA);
Mark Brown247fa192013-03-19 14:47:47 +010058 }
Mark Brown3cc72982012-06-19 16:31:53 +010059
Mark Brown247fa192013-03-19 14:47:47 +010060out:
Mark Brown3cc72982012-06-19 16:31:53 +010061 if (ret != 0)
62 arizona->clk32k_ref--;
63
64 mutex_unlock(&arizona->clk_lock);
65
66 return ret;
67}
68EXPORT_SYMBOL_GPL(arizona_clk32k_enable);
69
70int arizona_clk32k_disable(struct arizona *arizona)
71{
Mark Brown3cc72982012-06-19 16:31:53 +010072 mutex_lock(&arizona->clk_lock);
73
74 BUG_ON(arizona->clk32k_ref <= 0);
75
76 arizona->clk32k_ref--;
77
Mark Brown247fa192013-03-19 14:47:47 +010078 if (arizona->clk32k_ref == 0) {
Mark Brown3cc72982012-06-19 16:31:53 +010079 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
80 ARIZONA_CLK_32K_ENA, 0);
81
Mark Brown247fa192013-03-19 14:47:47 +010082 switch (arizona->pdata.clk32k_src) {
83 case ARIZONA_32KZ_MCLK1:
84 pm_runtime_put_sync(arizona->dev);
85 break;
86 }
87 }
88
Mark Brown3cc72982012-06-19 16:31:53 +010089 mutex_unlock(&arizona->clk_lock);
90
Javier Martinez Canillasa260fba2015-09-29 13:26:02 +020091 return 0;
Mark Brown3cc72982012-06-19 16:31:53 +010092}
93EXPORT_SYMBOL_GPL(arizona_clk32k_disable);
94
95static irqreturn_t arizona_clkgen_err(int irq, void *data)
96{
97 struct arizona *arizona = data;
98
99 dev_err(arizona->dev, "CLKGEN error\n");
100
101 return IRQ_HANDLED;
102}
103
104static irqreturn_t arizona_underclocked(int irq, void *data)
105{
106 struct arizona *arizona = data;
107 unsigned int val;
108 int ret;
109
110 ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8,
111 &val);
112 if (ret != 0) {
113 dev_err(arizona->dev, "Failed to read underclock status: %d\n",
114 ret);
115 return IRQ_NONE;
116 }
117
118 if (val & ARIZONA_AIF3_UNDERCLOCKED_STS)
119 dev_err(arizona->dev, "AIF3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100120 if (val & ARIZONA_AIF2_UNDERCLOCKED_STS)
Charles Keepax3ebef342012-11-20 13:46:20 +0900121 dev_err(arizona->dev, "AIF2 underclocked\n");
122 if (val & ARIZONA_AIF1_UNDERCLOCKED_STS)
Mark Brown3cc72982012-06-19 16:31:53 +0100123 dev_err(arizona->dev, "AIF1 underclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100124 if (val & ARIZONA_ISRC3_UNDERCLOCKED_STS)
125 dev_err(arizona->dev, "ISRC3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100126 if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS)
127 dev_err(arizona->dev, "ISRC2 underclocked\n");
128 if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS)
129 dev_err(arizona->dev, "ISRC1 underclocked\n");
130 if (val & ARIZONA_FX_UNDERCLOCKED_STS)
131 dev_err(arizona->dev, "FX underclocked\n");
132 if (val & ARIZONA_ASRC_UNDERCLOCKED_STS)
133 dev_err(arizona->dev, "ASRC underclocked\n");
134 if (val & ARIZONA_DAC_UNDERCLOCKED_STS)
135 dev_err(arizona->dev, "DAC underclocked\n");
136 if (val & ARIZONA_ADC_UNDERCLOCKED_STS)
137 dev_err(arizona->dev, "ADC underclocked\n");
138 if (val & ARIZONA_MIXER_UNDERCLOCKED_STS)
Mark Brown648a9882013-01-28 00:32:53 +0800139 dev_err(arizona->dev, "Mixer dropped sample\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100140
141 return IRQ_HANDLED;
142}
143
144static irqreturn_t arizona_overclocked(int irq, void *data)
145{
146 struct arizona *arizona = data;
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100147 unsigned int val[3];
Mark Brown3cc72982012-06-19 16:31:53 +0100148 int ret;
Charles Keepax3762aed2015-08-11 09:34:31 +0100149
Mark Brown3cc72982012-06-19 16:31:53 +0100150 ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6,
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100151 &val[0], 3);
Mark Brown3cc72982012-06-19 16:31:53 +0100152 if (ret != 0) {
153 dev_err(arizona->dev, "Failed to read overclock status: %d\n",
154 ret);
155 return IRQ_NONE;
156 }
157
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100158 switch (arizona->type) {
159 case WM8998:
160 case WM1814:
161 /* Some bits are shifted on WM8998,
162 * rearrange to match the standard bit layout
163 */
164 val[0] = ((val[0] & 0x60e0) >> 1) |
165 ((val[0] & 0x1e00) >> 2) |
166 (val[0] & 0x000f);
167 break;
168 default:
169 break;
170 }
171
Mark Brown3cc72982012-06-19 16:31:53 +0100172 if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS)
173 dev_err(arizona->dev, "PWM overclocked\n");
174 if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS)
175 dev_err(arizona->dev, "FX core overclocked\n");
176 if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS)
177 dev_err(arizona->dev, "DAC SYS overclocked\n");
178 if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS)
179 dev_err(arizona->dev, "DAC WARP overclocked\n");
180 if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS)
181 dev_err(arizona->dev, "ADC overclocked\n");
182 if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS)
183 dev_err(arizona->dev, "Mixer overclocked\n");
184 if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS)
185 dev_err(arizona->dev, "AIF3 overclocked\n");
186 if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS)
187 dev_err(arizona->dev, "AIF2 overclocked\n");
188 if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS)
189 dev_err(arizona->dev, "AIF1 overclocked\n");
190 if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS)
191 dev_err(arizona->dev, "Pad control overclocked\n");
192
193 if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS)
194 dev_err(arizona->dev, "Slimbus subsystem overclocked\n");
195 if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS)
196 dev_err(arizona->dev, "Slimbus async overclocked\n");
197 if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS)
198 dev_err(arizona->dev, "Slimbus sync overclocked\n");
199 if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS)
200 dev_err(arizona->dev, "ASRC async system overclocked\n");
201 if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS)
202 dev_err(arizona->dev, "ASRC async WARP overclocked\n");
203 if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS)
204 dev_err(arizona->dev, "ASRC sync system overclocked\n");
205 if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS)
206 dev_err(arizona->dev, "ASRC sync WARP overclocked\n");
207 if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS)
208 dev_err(arizona->dev, "DSP1 overclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100209 if (val[1] & ARIZONA_ISRC3_OVERCLOCKED_STS)
210 dev_err(arizona->dev, "ISRC3 overclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100211 if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS)
212 dev_err(arizona->dev, "ISRC2 overclocked\n");
213 if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS)
214 dev_err(arizona->dev, "ISRC1 overclocked\n");
215
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100216 if (val[2] & ARIZONA_SPDIF_OVERCLOCKED_STS)
217 dev_err(arizona->dev, "SPDIF overclocked\n");
218
Mark Brown3cc72982012-06-19 16:31:53 +0100219 return IRQ_HANDLED;
220}
221
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000222static int arizona_poll_reg(struct arizona *arizona,
223 int timeout, unsigned int reg,
224 unsigned int mask, unsigned int target)
225{
226 unsigned int val = 0;
227 int ret, i;
228
229 for (i = 0; i < timeout; i++) {
230 ret = regmap_read(arizona->regmap, reg, &val);
231 if (ret != 0) {
232 dev_err(arizona->dev, "Failed to read reg %u: %d\n",
233 reg, ret);
234 continue;
235 }
236
237 if ((val & mask) == target)
238 return 0;
239
240 msleep(1);
241 }
242
243 dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val);
244 return -ETIMEDOUT;
245}
246
Mark Brown3cc72982012-06-19 16:31:53 +0100247static int arizona_wait_for_boot(struct arizona *arizona)
248{
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000249 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100250
251 /*
252 * We can't use an interrupt as we need to runtime resume to do so,
253 * we won't race with the interrupt handler as it'll be blocked on
254 * runtime resume.
255 */
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000256 ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5,
257 ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100258
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000259 if (!ret)
Mark Brown3cc72982012-06-19 16:31:53 +0100260 regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
261 ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100262
263 pm_runtime_mark_last_busy(arizona->dev);
264
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000265 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100266}
267
Charles Keepax22298752015-05-11 13:58:02 +0100268static inline void arizona_enable_reset(struct arizona *arizona)
269{
270 if (arizona->pdata.reset)
271 gpio_set_value_cansleep(arizona->pdata.reset, 0);
272}
273
274static void arizona_disable_reset(struct arizona *arizona)
275{
276 if (arizona->pdata.reset) {
Charles Keepax121c0752015-05-11 13:58:10 +0100277 switch (arizona->type) {
278 case WM5110:
279 case WM8280:
280 /* Meet requirements for minimum reset duration */
281 msleep(5);
282 break;
283 default:
284 break;
285 }
286
Charles Keepax22298752015-05-11 13:58:02 +0100287 gpio_set_value_cansleep(arizona->pdata.reset, 1);
288 msleep(1);
289 }
290}
291
Charles Keepax3850e3e2015-05-11 13:58:05 +0100292struct arizona_sysclk_state {
293 unsigned int fll;
294 unsigned int sysclk;
295};
296
297static int arizona_enable_freerun_sysclk(struct arizona *arizona,
298 struct arizona_sysclk_state *state)
Charles Keepaxe80436b2013-03-26 18:46:15 +0000299{
Charles Keepaxe80436b2013-03-26 18:46:15 +0000300 int ret, err;
301
Charles Keepaxe80436b2013-03-26 18:46:15 +0000302 /* Cache existing FLL and SYSCLK settings */
Charles Keepax3850e3e2015-05-11 13:58:05 +0100303 ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll);
Charles Keepax0be068a2015-05-11 13:58:04 +0100304 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000305 dev_err(arizona->dev, "Failed to cache FLL settings: %d\n",
306 ret);
307 return ret;
308 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100309 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
310 &state->sysclk);
Charles Keepax0be068a2015-05-11 13:58:04 +0100311 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000312 dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
313 ret);
314 return ret;
315 }
316
317 /* Start up SYSCLK using the FLL in free running mode */
318 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1,
319 ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN);
Charles Keepax0be068a2015-05-11 13:58:04 +0100320 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000321 dev_err(arizona->dev,
322 "Failed to start FLL in freerunning mode: %d\n",
323 ret);
324 return ret;
325 }
326 ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
327 ARIZONA_FLL1_CLOCK_OK_STS,
328 ARIZONA_FLL1_CLOCK_OK_STS);
Charles Keepax0be068a2015-05-11 13:58:04 +0100329 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000330 ret = -ETIMEDOUT;
331 goto err_fll;
332 }
333
334 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
Charles Keepax0be068a2015-05-11 13:58:04 +0100335 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000336 dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
337 goto err_fll;
338 }
339
Charles Keepax3850e3e2015-05-11 13:58:05 +0100340 return 0;
341
342err_fll:
343 err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
344 if (err)
345 dev_err(arizona->dev,
346 "Failed to re-apply old FLL settings: %d\n", err);
347
348 return ret;
349}
350
351static int arizona_disable_freerun_sysclk(struct arizona *arizona,
352 struct arizona_sysclk_state *state)
353{
354 int ret;
355
356 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
357 state->sysclk);
358 if (ret) {
359 dev_err(arizona->dev,
360 "Failed to re-apply old SYSCLK settings: %d\n", ret);
361 return ret;
362 }
363
364 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
365 if (ret) {
366 dev_err(arizona->dev,
367 "Failed to re-apply old FLL settings: %d\n", ret);
368 return ret;
369 }
370
371 return 0;
372}
373
374static int wm5102_apply_hardware_patch(struct arizona *arizona)
375{
376 struct arizona_sysclk_state state;
377 int err, ret;
378
379 ret = arizona_enable_freerun_sysclk(arizona, &state);
380 if (ret)
381 return ret;
382
Charles Keepaxe80436b2013-03-26 18:46:15 +0000383 /* Start the write sequencer and wait for it to finish */
384 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100385 ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160);
386 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000387 dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
388 ret);
Charles Keepax3850e3e2015-05-11 13:58:05 +0100389 goto err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000390 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100391
Charles Keepaxe80436b2013-03-26 18:46:15 +0000392 ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
393 ARIZONA_WSEQ_BUSY, 0);
Charles Keepax0be068a2015-05-11 13:58:04 +0100394 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000395 regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100396 ARIZONA_WSEQ_ABORT);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000397 ret = -ETIMEDOUT;
398 }
399
Charles Keepax3850e3e2015-05-11 13:58:05 +0100400err:
401 err = arizona_disable_freerun_sysclk(arizona, &state);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000402
Charles Keepax0be068a2015-05-11 13:58:04 +0100403 return ret ?: err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000404}
405
Charles Keepax882bc462015-05-11 13:58:06 +0100406/*
407 * Register patch to some of the CODECs internal write sequences
408 * to ensure a clean exit from the low power sleep state.
409 */
Nariman Poushin8019ff62015-07-16 16:36:21 +0100410static const struct reg_sequence wm5110_sleep_patch[] = {
Charles Keepax882bc462015-05-11 13:58:06 +0100411 { 0x337A, 0xC100 },
412 { 0x337B, 0x0041 },
413 { 0x3300, 0xA210 },
414 { 0x3301, 0x050C },
415};
416
417static int wm5110_apply_sleep_patch(struct arizona *arizona)
418{
419 struct arizona_sysclk_state state;
420 int err, ret;
421
422 ret = arizona_enable_freerun_sysclk(arizona, &state);
423 if (ret)
424 return ret;
425
426 ret = regmap_multi_reg_write_bypassed(arizona->regmap,
427 wm5110_sleep_patch,
428 ARRAY_SIZE(wm5110_sleep_patch));
429
430 err = arizona_disable_freerun_sysclk(arizona, &state);
431
432 return ret ?: err;
433}
434
Charles Keepax1c1c6bb2015-05-11 13:58:03 +0100435static int wm5102_clear_write_sequencer(struct arizona *arizona)
436{
437 int ret;
438
439 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_3,
440 0x0);
441 if (ret) {
442 dev_err(arizona->dev,
443 "Failed to clear write sequencer state: %d\n", ret);
444 return ret;
445 }
446
447 arizona_enable_reset(arizona);
448 regulator_disable(arizona->dcvdd);
449
450 msleep(20);
451
452 ret = regulator_enable(arizona->dcvdd);
453 if (ret) {
454 dev_err(arizona->dev, "Failed to re-enable DCVDD: %d\n", ret);
455 return ret;
456 }
457 arizona_disable_reset(arizona);
458
459 return 0;
460}
461
Rafael J. Wysocki48bb9fe2014-12-05 03:04:12 +0100462#ifdef CONFIG_PM
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100463static int arizona_isolate_dcvdd(struct arizona *arizona)
464{
465 int ret;
466
467 ret = regmap_update_bits(arizona->regmap,
468 ARIZONA_ISOLATION_CONTROL,
469 ARIZONA_ISOLATE_DCVDD1,
470 ARIZONA_ISOLATE_DCVDD1);
471 if (ret != 0)
472 dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n", ret);
473
474 return ret;
475}
476
477static int arizona_connect_dcvdd(struct arizona *arizona)
478{
479 int ret;
480
481 ret = regmap_update_bits(arizona->regmap,
482 ARIZONA_ISOLATION_CONTROL,
483 ARIZONA_ISOLATE_DCVDD1, 0);
484 if (ret != 0)
485 dev_err(arizona->dev, "Failed to connect DCVDD: %d\n", ret);
486
487 return ret;
488}
489
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100490static int arizona_is_jack_det_active(struct arizona *arizona)
491{
492 unsigned int val;
493 int ret;
494
495 ret = regmap_read(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, &val);
496 if (ret) {
497 dev_err(arizona->dev,
498 "Failed to check jack det status: %d\n", ret);
499 return ret;
500 } else if (val & ARIZONA_JD1_ENA) {
501 return 1;
502 } else {
503 return 0;
504 }
505}
506
Mark Brown3cc72982012-06-19 16:31:53 +0100507static int arizona_runtime_resume(struct device *dev)
508{
509 struct arizona *arizona = dev_get_drvdata(dev);
510 int ret;
511
Mark Brown508c8292012-07-20 17:09:12 +0100512 dev_dbg(arizona->dev, "Leaving AoD mode\n");
513
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100514 if (arizona->has_fully_powered_off) {
515 dev_dbg(arizona->dev, "Re-enabling core supplies\n");
516
517 ret = regulator_bulk_enable(arizona->num_core_supplies,
518 arizona->core_supplies);
519 if (ret) {
520 dev_err(dev, "Failed to enable core supplies: %d\n",
521 ret);
522 return ret;
523 }
524 }
525
Mark Brown59db9692012-07-09 00:31:36 +0200526 ret = regulator_enable(arizona->dcvdd);
527 if (ret != 0) {
528 dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100529 if (arizona->has_fully_powered_off)
530 regulator_bulk_disable(arizona->num_core_supplies,
531 arizona->core_supplies);
Mark Brown59db9692012-07-09 00:31:36 +0200532 return ret;
533 }
Mark Brown3cc72982012-06-19 16:31:53 +0100534
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100535 if (arizona->has_fully_powered_off) {
536 arizona_disable_reset(arizona);
537 enable_irq(arizona->irq);
538 arizona->has_fully_powered_off = false;
539 }
540
Mark Brown3cc72982012-06-19 16:31:53 +0100541 regcache_cache_only(arizona->regmap, false);
542
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000543 switch (arizona->type) {
544 case WM5102:
Mark Brown59274672013-04-23 19:44:16 +0100545 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100546 ret = arizona_connect_dcvdd(arizona);
547 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100548 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100549 }
550
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000551 ret = wm5102_patch(arizona);
552 if (ret != 0) {
553 dev_err(arizona->dev, "Failed to apply patch: %d\n",
554 ret);
555 goto err;
556 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000557
Charles Keepax0be068a2015-05-11 13:58:04 +0100558 ret = wm5102_apply_hardware_patch(arizona);
559 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000560 dev_err(arizona->dev,
561 "Failed to apply hardware patch: %d\n",
562 ret);
563 goto err;
564 }
565 break;
Charles Keepax96129a02015-05-11 13:58:08 +0100566 case WM5110:
567 case WM8280:
568 ret = arizona_wait_for_boot(arizona);
569 if (ret)
570 goto err;
571
572 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100573 ret = arizona_connect_dcvdd(arizona);
574 if (ret != 0)
Charles Keepax96129a02015-05-11 13:58:08 +0100575 goto err;
Charles Keepax96129a02015-05-11 13:58:08 +0100576 } else {
577 /*
578 * As this is only called for the internal regulator
579 * (where we know voltage ranges available) it is ok
580 * to request an exact range.
581 */
582 ret = regulator_set_voltage(arizona->dcvdd,
583 1200000, 1200000);
584 if (ret < 0) {
585 dev_err(arizona->dev,
586 "Failed to set resume voltage: %d\n",
587 ret);
588 goto err;
589 }
590 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100591
592 ret = wm5110_apply_sleep_patch(arizona);
593 if (ret) {
594 dev_err(arizona->dev,
595 "Failed to re-apply sleep patch: %d\n",
596 ret);
597 goto err;
598 }
Charles Keepax96129a02015-05-11 13:58:08 +0100599 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000600 default:
Charles Keepax12bb68e2013-03-27 09:49:40 +0000601 ret = arizona_wait_for_boot(arizona);
Charles Keepax3762aed2015-08-11 09:34:31 +0100602 if (ret != 0)
Charles Keepax12bb68e2013-03-27 09:49:40 +0000603 goto err;
Charles Keepax12bb68e2013-03-27 09:49:40 +0000604
Mark Brown59274672013-04-23 19:44:16 +0100605 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100606 ret = arizona_connect_dcvdd(arizona);
607 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100608 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100609 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000610 break;
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000611 }
612
Mark Brown9270bdf2013-01-04 17:16:12 +0000613 ret = regcache_sync(arizona->regmap);
614 if (ret != 0) {
615 dev_err(arizona->dev, "Failed to restore register cache\n");
Mark Brown4816bd12013-01-14 15:50:38 +0900616 goto err;
Mark Brown9270bdf2013-01-04 17:16:12 +0000617 }
Mark Brown3cc72982012-06-19 16:31:53 +0100618
619 return 0;
Mark Brown4816bd12013-01-14 15:50:38 +0900620
621err:
622 regcache_cache_only(arizona->regmap, true);
623 regulator_disable(arizona->dcvdd);
624 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100625}
626
627static int arizona_runtime_suspend(struct device *dev)
628{
629 struct arizona *arizona = dev_get_drvdata(dev);
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100630 unsigned int jd_active = 0;
Mark Brown59274672013-04-23 19:44:16 +0100631 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100632
Mark Brown508c8292012-07-20 17:09:12 +0100633 dev_dbg(arizona->dev, "Entering AoD mode\n");
634
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100635 switch (arizona->type) {
636 case WM5110:
637 case WM8280:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100638 jd_active = arizona_is_jack_det_active(arizona);
639 if (jd_active < 0)
640 return jd_active;
641
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100642 if (arizona->external_dcvdd) {
643 ret = arizona_isolate_dcvdd(arizona);
644 if (ret != 0)
645 return ret;
646 } else {
647 /*
648 * As this is only called for the internal regulator
649 * (where we know voltage ranges available) it is ok
650 * to request an exact range.
651 */
652 ret = regulator_set_voltage(arizona->dcvdd,
653 1175000, 1175000);
654 if (ret < 0) {
655 dev_err(arizona->dev,
656 "Failed to set suspend voltage: %d\n",
657 ret);
658 return ret;
659 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100660 }
661 break;
662 case WM5102:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100663 jd_active = arizona_is_jack_det_active(arizona);
664 if (jd_active < 0)
665 return jd_active;
666
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100667 if (arizona->external_dcvdd) {
668 ret = arizona_isolate_dcvdd(arizona);
669 if (ret != 0)
670 return ret;
671 }
672
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100673 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100674 ret = regmap_write(arizona->regmap,
675 ARIZONA_WRITE_SEQUENCER_CTRL_3, 0x0);
676 if (ret) {
Charles Keepax96129a02015-05-11 13:58:08 +0100677 dev_err(arizona->dev,
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100678 "Failed to clear write sequencer: %d\n",
Charles Keepax96129a02015-05-11 13:58:08 +0100679 ret);
680 return ret;
681 }
Charles Keepax96129a02015-05-11 13:58:08 +0100682 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100683 break;
684 default:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100685 jd_active = arizona_is_jack_det_active(arizona);
686 if (jd_active < 0)
687 return jd_active;
688
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100689 if (arizona->external_dcvdd) {
690 ret = arizona_isolate_dcvdd(arizona);
691 if (ret != 0)
692 return ret;
693 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100694 break;
Mark Brown59274672013-04-23 19:44:16 +0100695 }
696
Mark Brown59db9692012-07-09 00:31:36 +0200697 regcache_cache_only(arizona->regmap, true);
698 regcache_mark_dirty(arizona->regmap);
Charles Keepaxe293e84722013-08-06 17:18:35 +0100699 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +0100700
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100701 /* Allow us to completely power down if no jack detection */
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100702 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100703 dev_dbg(arizona->dev, "Fully powering off\n");
704
705 arizona->has_fully_powered_off = true;
706
Charles Keepax11150922015-06-14 15:41:49 +0100707 disable_irq_nosync(arizona->irq);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100708 arizona_enable_reset(arizona);
709 regulator_bulk_disable(arizona->num_core_supplies,
710 arizona->core_supplies);
711 }
712
Mark Brown3cc72982012-06-19 16:31:53 +0100713 return 0;
714}
715#endif
716
Mark Browndc781d02013-01-27 12:07:32 +0800717#ifdef CONFIG_PM_SLEEP
Mark Brown67c99292013-04-10 12:40:26 +0100718static int arizona_suspend(struct device *dev)
719{
720 struct arizona *arizona = dev_get_drvdata(dev);
721
722 dev_dbg(arizona->dev, "Suspend, disabling IRQ\n");
723 disable_irq(arizona->irq);
724
725 return 0;
726}
727
728static int arizona_suspend_late(struct device *dev)
729{
730 struct arizona *arizona = dev_get_drvdata(dev);
731
732 dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n");
733 enable_irq(arizona->irq);
734
735 return 0;
736}
737
Mark Browndc781d02013-01-27 12:07:32 +0800738static int arizona_resume_noirq(struct device *dev)
739{
740 struct arizona *arizona = dev_get_drvdata(dev);
741
742 dev_dbg(arizona->dev, "Early resume, disabling IRQ\n");
743 disable_irq(arizona->irq);
744
745 return 0;
746}
747
748static int arizona_resume(struct device *dev)
749{
750 struct arizona *arizona = dev_get_drvdata(dev);
751
752 dev_dbg(arizona->dev, "Late resume, reenabling IRQ\n");
753 enable_irq(arizona->irq);
754
755 return 0;
756}
757#endif
758
Mark Brown3cc72982012-06-19 16:31:53 +0100759const struct dev_pm_ops arizona_pm_ops = {
760 SET_RUNTIME_PM_OPS(arizona_runtime_suspend,
761 arizona_runtime_resume,
762 NULL)
Mark Brown67c99292013-04-10 12:40:26 +0100763 SET_SYSTEM_SLEEP_PM_OPS(arizona_suspend, arizona_resume)
Mark Browndc781d02013-01-27 12:07:32 +0800764#ifdef CONFIG_PM_SLEEP
Mark Brown67c99292013-04-10 12:40:26 +0100765 .suspend_late = arizona_suspend_late,
Mark Browndc781d02013-01-27 12:07:32 +0800766 .resume_noirq = arizona_resume_noirq,
767#endif
Mark Brown3cc72982012-06-19 16:31:53 +0100768};
769EXPORT_SYMBOL_GPL(arizona_pm_ops);
770
Mark Brownd7810092013-03-25 00:11:27 +0000771#ifdef CONFIG_OF
Lee Jones942786e2014-07-02 14:28:46 +0100772unsigned long arizona_of_get_type(struct device *dev)
Mark Brownd7810092013-03-25 00:11:27 +0000773{
774 const struct of_device_id *id = of_match_device(arizona_of_match, dev);
775
776 if (id)
Lee Jones942786e2014-07-02 14:28:46 +0100777 return (unsigned long)id->data;
Mark Brownd7810092013-03-25 00:11:27 +0000778 else
779 return 0;
780}
781EXPORT_SYMBOL_GPL(arizona_of_get_type);
782
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100783int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop,
784 bool mandatory)
785{
786 int gpio;
787
788 gpio = of_get_named_gpio(arizona->dev->of_node, prop, 0);
789 if (gpio < 0) {
790 if (mandatory)
791 dev_err(arizona->dev,
792 "Mandatory DT gpio %s missing/malformed: %d\n",
793 prop, gpio);
794
795 gpio = 0;
796 }
797
798 return gpio;
799}
800EXPORT_SYMBOL_GPL(arizona_of_get_named_gpio);
801
Mark Brownd7810092013-03-25 00:11:27 +0000802static int arizona_of_get_core_pdata(struct arizona *arizona)
803{
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100804 struct arizona_pdata *pdata = &arizona->pdata;
Inha Songcc47aed2014-08-30 11:27:18 +0900805 struct property *prop;
806 const __be32 *cur;
807 u32 val;
Mark Brownd7810092013-03-25 00:11:27 +0000808 int ret, i;
Inha Songcc47aed2014-08-30 11:27:18 +0900809 int count = 0;
Mark Brownd7810092013-03-25 00:11:27 +0000810
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100811 pdata->reset = arizona_of_get_named_gpio(arizona, "wlf,reset", true);
Mark Brownd7810092013-03-25 00:11:27 +0000812
813 ret = of_property_read_u32_array(arizona->dev->of_node,
814 "wlf,gpio-defaults",
Charles Keepax3762aed2015-08-11 09:34:31 +0100815 pdata->gpio_defaults,
816 ARRAY_SIZE(pdata->gpio_defaults));
Mark Brownd7810092013-03-25 00:11:27 +0000817 if (ret >= 0) {
818 /*
819 * All values are literal except out of range values
820 * which are chip default, translate into platform
821 * data which uses 0 as chip default and out of range
822 * as zero.
823 */
Charles Keepax3762aed2015-08-11 09:34:31 +0100824 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
825 if (pdata->gpio_defaults[i] > 0xffff)
826 pdata->gpio_defaults[i] = 0;
827 else if (pdata->gpio_defaults[i] == 0)
828 pdata->gpio_defaults[i] = 0x10000;
Mark Brownd7810092013-03-25 00:11:27 +0000829 }
830 } else {
831 dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n",
832 ret);
833 }
834
Inha Songcc47aed2014-08-30 11:27:18 +0900835 of_property_for_each_u32(arizona->dev->of_node, "wlf,inmode", prop,
836 cur, val) {
Charles Keepax3762aed2015-08-11 09:34:31 +0100837 if (count == ARRAY_SIZE(pdata->inmode))
Inha Songcc47aed2014-08-30 11:27:18 +0900838 break;
839
Charles Keepax3762aed2015-08-11 09:34:31 +0100840 pdata->inmode[count] = val;
Inha Songcc47aed2014-08-30 11:27:18 +0900841 count++;
842 }
843
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000844 count = 0;
845 of_property_for_each_u32(arizona->dev->of_node, "wlf,dmic-ref", prop,
846 cur, val) {
Charles Keepax3762aed2015-08-11 09:34:31 +0100847 if (count == ARRAY_SIZE(pdata->dmic_ref))
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000848 break;
849
Charles Keepax3762aed2015-08-11 09:34:31 +0100850 pdata->dmic_ref[count] = val;
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000851 count++;
852 }
853
Mark Brownd7810092013-03-25 00:11:27 +0000854 return 0;
855}
856
857const struct of_device_id arizona_of_match[] = {
858 { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
859 { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000860 { .compatible = "wlf,wm8280", .data = (void *)WM8280 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100861 { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100862 { .compatible = "wlf,wm8998", .data = (void *)WM8998 },
863 { .compatible = "wlf,wm1814", .data = (void *)WM1814 },
Mark Brownd7810092013-03-25 00:11:27 +0000864 {},
865};
866EXPORT_SYMBOL_GPL(arizona_of_match);
867#else
868static inline int arizona_of_get_core_pdata(struct arizona *arizona)
869{
870 return 0;
871}
872#endif
873
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100874static const struct mfd_cell early_devs[] = {
Mark Brown3cc72982012-06-19 16:31:53 +0100875 { .name = "arizona-ldo1" },
876};
877
Charles Keepax3762aed2015-08-11 09:34:31 +0100878static const char * const wm5102_supplies[] = {
Charles Keepax5fc6c392014-07-25 16:24:44 +0100879 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100880 "DBVDD2",
881 "DBVDD3",
882 "CPVDD",
883 "SPKVDDL",
884 "SPKVDDR",
885};
886
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100887static const struct mfd_cell wm5102_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000888 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100889 {
890 .name = "arizona-extcon",
891 .parent_supplies = wm5102_supplies,
892 .num_parent_supplies = 1, /* We only need MICVDD */
893 },
Mark Brown3cc72982012-06-19 16:31:53 +0100894 { .name = "arizona-gpio" },
Mark Brown503b1ca2012-11-27 17:36:38 +0000895 { .name = "arizona-haptics" },
Mark Brown3cc72982012-06-19 16:31:53 +0100896 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100897 {
898 .name = "wm5102-codec",
899 .parent_supplies = wm5102_supplies,
900 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
901 },
Mark Brown3cc72982012-06-19 16:31:53 +0100902};
903
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100904static const struct mfd_cell wm5110_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000905 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100906 {
907 .name = "arizona-extcon",
908 .parent_supplies = wm5102_supplies,
909 .num_parent_supplies = 1, /* We only need MICVDD */
910 },
Mark Browne102bef2012-07-10 12:37:58 +0100911 { .name = "arizona-gpio" },
Mark Brown503b1ca2012-11-27 17:36:38 +0000912 { .name = "arizona-haptics" },
Mark Browne102bef2012-07-10 12:37:58 +0100913 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100914 {
915 .name = "wm5110-codec",
916 .parent_supplies = wm5102_supplies,
917 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
918 },
919};
920
Charles Keepax3762aed2015-08-11 09:34:31 +0100921static const char * const wm8997_supplies[] = {
Charles Keepax996c2d42014-07-25 16:24:43 +0100922 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100923 "DBVDD2",
924 "CPVDD",
925 "SPKVDD",
Mark Browne102bef2012-07-10 12:37:58 +0100926};
927
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100928static const struct mfd_cell wm8997_devs[] = {
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100929 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100930 {
931 .name = "arizona-extcon",
932 .parent_supplies = wm8997_supplies,
933 .num_parent_supplies = 1, /* We only need MICVDD */
934 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100935 { .name = "arizona-gpio" },
936 { .name = "arizona-haptics" },
937 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100938 {
939 .name = "wm8997-codec",
940 .parent_supplies = wm8997_supplies,
941 .num_parent_supplies = ARRAY_SIZE(wm8997_supplies),
942 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100943};
944
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100945static const struct mfd_cell wm8998_devs[] = {
946 {
947 .name = "arizona-extcon",
948 .parent_supplies = wm5102_supplies,
949 .num_parent_supplies = 1, /* We only need MICVDD */
950 },
951 { .name = "arizona-gpio" },
952 { .name = "arizona-haptics" },
953 { .name = "arizona-pwm" },
954 {
955 .name = "wm8998-codec",
956 .parent_supplies = wm5102_supplies,
957 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
958 },
959 { .name = "arizona-micsupp" },
960};
961
Bill Pembertonf791be42012-11-19 13:23:04 -0500962int arizona_dev_init(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +0100963{
964 struct device *dev = arizona->dev;
965 const char *type_name;
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100966 unsigned int reg, val, mask;
Mark Brown62d62b52012-12-02 11:41:46 +0900967 int (*apply_patch)(struct arizona *) = NULL;
Mark Brown3cc72982012-06-19 16:31:53 +0100968 int ret, i;
969
970 dev_set_drvdata(arizona->dev, arizona);
971 mutex_init(&arizona->clk_lock);
972
973 if (dev_get_platdata(arizona->dev))
974 memcpy(&arizona->pdata, dev_get_platdata(arizona->dev),
975 sizeof(arizona->pdata));
Lee Jones22d7dc82013-09-27 14:25:55 +0100976 else
977 arizona_of_get_core_pdata(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +0100978
979 regcache_cache_only(arizona->regmap, true);
980
981 switch (arizona->type) {
982 case WM5102:
Mark Browne102bef2012-07-10 12:37:58 +0100983 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000984 case WM8280:
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100985 case WM8997:
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100986 case WM8998:
987 case WM1814:
Mark Brown3cc72982012-06-19 16:31:53 +0100988 for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++)
989 arizona->core_supplies[i].supply
990 = wm5102_core_supplies[i];
991 arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies);
992 break;
993 default:
994 dev_err(arizona->dev, "Unknown device type %d\n",
995 arizona->type);
996 return -EINVAL;
997 }
998
Charles Keepax4a8c4752014-04-16 10:01:38 +0100999 /* Mark DCVDD as external, LDO1 driver will clear if internal */
1000 arizona->external_dcvdd = true;
1001
Mark Brown3cc72982012-06-19 16:31:53 +01001002 ret = mfd_add_devices(arizona->dev, -1, early_devs,
Mark Brown0848c942012-09-11 15:16:36 +08001003 ARRAY_SIZE(early_devs), NULL, 0, NULL);
Mark Brown3cc72982012-06-19 16:31:53 +01001004 if (ret != 0) {
1005 dev_err(dev, "Failed to add early children: %d\n", ret);
1006 return ret;
1007 }
1008
1009 ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies,
1010 arizona->core_supplies);
1011 if (ret != 0) {
1012 dev_err(dev, "Failed to request core supplies: %d\n",
1013 ret);
1014 goto err_early;
1015 }
1016
Charles Keepax0c2d0ff2014-06-19 16:04:23 +01001017 /**
1018 * Don't use devres here because the only device we have to get
1019 * against is the MFD device and DCVDD will likely be supplied by
1020 * one of its children. Meaning that the regulator will be
1021 * destroyed by the time devres calls regulator put.
1022 */
Charles Keepaxe6021512014-06-02 09:50:41 +01001023 arizona->dcvdd = regulator_get(arizona->dev, "DCVDD");
Mark Brown59db9692012-07-09 00:31:36 +02001024 if (IS_ERR(arizona->dcvdd)) {
1025 ret = PTR_ERR(arizona->dcvdd);
1026 dev_err(dev, "Failed to request DCVDD: %d\n", ret);
1027 goto err_early;
1028 }
1029
Mark Brown87d3af42013-03-26 12:15:26 +00001030 if (arizona->pdata.reset) {
1031 /* Start out with /RESET low to put the chip into reset */
Charles Keepax5f056bf2015-05-11 13:58:01 +01001032 ret = devm_gpio_request_one(arizona->dev, arizona->pdata.reset,
1033 GPIOF_DIR_OUT | GPIOF_INIT_LOW,
1034 "arizona /RESET");
Mark Brown87d3af42013-03-26 12:15:26 +00001035 if (ret != 0) {
1036 dev_err(dev, "Failed to request /RESET: %d\n", ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001037 goto err_dcvdd;
Mark Brown87d3af42013-03-26 12:15:26 +00001038 }
1039 }
1040
Mark Brown3cc72982012-06-19 16:31:53 +01001041 ret = regulator_bulk_enable(arizona->num_core_supplies,
1042 arizona->core_supplies);
1043 if (ret != 0) {
1044 dev_err(dev, "Failed to enable core supplies: %d\n",
1045 ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001046 goto err_dcvdd;
Mark Brown3cc72982012-06-19 16:31:53 +01001047 }
1048
Mark Brown59db9692012-07-09 00:31:36 +02001049 ret = regulator_enable(arizona->dcvdd);
1050 if (ret != 0) {
1051 dev_err(dev, "Failed to enable DCVDD: %d\n", ret);
1052 goto err_enable;
1053 }
1054
Charles Keepax22298752015-05-11 13:58:02 +01001055 arizona_disable_reset(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001056
Mark Brown3cc72982012-06-19 16:31:53 +01001057 regcache_cache_only(arizona->regmap, false);
1058
Mark Brownca76ceb2013-04-09 16:04:35 +01001059 /* Verify that this is a chip we know about */
1060 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1061 if (ret != 0) {
1062 dev_err(dev, "Failed to read ID register: %d\n", ret);
1063 goto err_reset;
1064 }
1065
1066 switch (reg) {
1067 case 0x5102:
1068 case 0x5110:
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001069 case 0x6349:
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001070 case 0x8997:
Mark Brownca76ceb2013-04-09 16:04:35 +01001071 break;
1072 default:
1073 dev_err(arizona->dev, "Unknown device ID: %x\n", reg);
1074 goto err_reset;
1075 }
1076
1077 /* If we have a /RESET GPIO we'll already be reset */
1078 if (!arizona->pdata.reset) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001079 ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0);
1080 if (ret != 0) {
1081 dev_err(dev, "Failed to reset device: %d\n", ret);
1082 goto err_reset;
1083 }
1084
1085 msleep(1);
Mark Brownca76ceb2013-04-09 16:04:35 +01001086 }
1087
1088 /* Ensure device startup is complete */
1089 switch (arizona->type) {
1090 case WM5102:
Mark Brown48018942014-08-13 11:42:46 +01001091 ret = regmap_read(arizona->regmap,
1092 ARIZONA_WRITE_SEQUENCER_CTRL_3, &val);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001093 if (ret) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001094 dev_err(dev,
1095 "Failed to check write sequencer state: %d\n",
1096 ret);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001097 } else if (val & 0x01) {
1098 ret = wm5102_clear_write_sequencer(arizona);
1099 if (ret)
1100 return ret;
Mark Brownca76ceb2013-04-09 16:04:35 +01001101 }
1102 break;
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001103 default:
1104 break;
1105 }
1106
1107 ret = arizona_wait_for_boot(arizona);
1108 if (ret) {
1109 dev_err(arizona->dev, "Device failed initial boot: %d\n", ret);
1110 goto err_reset;
Mark Brownca76ceb2013-04-09 16:04:35 +01001111 }
1112
1113 /* Read the device ID information & do device specific stuff */
Mark Brown3cc72982012-06-19 16:31:53 +01001114 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1115 if (ret != 0) {
1116 dev_err(dev, "Failed to read ID register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001117 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001118 }
1119
1120 ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION,
1121 &arizona->rev);
1122 if (ret != 0) {
1123 dev_err(dev, "Failed to read revision register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001124 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001125 }
1126 arizona->rev &= ARIZONA_DEVICE_REVISION_MASK;
1127
1128 switch (reg) {
Mark Brown863df8d2012-07-05 20:35:31 +01001129#ifdef CONFIG_MFD_WM5102
Mark Brown3cc72982012-06-19 16:31:53 +01001130 case 0x5102:
1131 type_name = "WM5102";
1132 if (arizona->type != WM5102) {
1133 dev_err(arizona->dev, "WM5102 registered as %d\n",
1134 arizona->type);
1135 arizona->type = WM5102;
1136 }
Mark Brown62d62b52012-12-02 11:41:46 +09001137 apply_patch = wm5102_patch;
Mark Brownc6d6bfb2013-03-26 11:14:52 +00001138 arizona->rev &= 0x7;
Mark Brown3cc72982012-06-19 16:31:53 +01001139 break;
Mark Brown863df8d2012-07-05 20:35:31 +01001140#endif
Mark Browne102bef2012-07-10 12:37:58 +01001141#ifdef CONFIG_MFD_WM5110
1142 case 0x5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +00001143 switch (arizona->type) {
1144 case WM5110:
1145 type_name = "WM5110";
1146 break;
1147 case WM8280:
1148 type_name = "WM8280";
1149 break;
1150 default:
1151 type_name = "WM5110";
Mark Browne102bef2012-07-10 12:37:58 +01001152 dev_err(arizona->dev, "WM5110 registered as %d\n",
1153 arizona->type);
1154 arizona->type = WM5110;
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +00001155 break;
Mark Browne102bef2012-07-10 12:37:58 +01001156 }
Mark Brown62d62b52012-12-02 11:41:46 +09001157 apply_patch = wm5110_patch;
Mark Browne102bef2012-07-10 12:37:58 +01001158 break;
1159#endif
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001160#ifdef CONFIG_MFD_WM8997
1161 case 0x8997:
1162 type_name = "WM8997";
1163 if (arizona->type != WM8997) {
1164 dev_err(arizona->dev, "WM8997 registered as %d\n",
1165 arizona->type);
1166 arizona->type = WM8997;
1167 }
1168 apply_patch = wm8997_patch;
1169 break;
1170#endif
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001171#ifdef CONFIG_MFD_WM8998
1172 case 0x6349:
1173 switch (arizona->type) {
1174 case WM8998:
1175 type_name = "WM8998";
1176 break;
1177
1178 case WM1814:
1179 type_name = "WM1814";
1180 break;
1181
1182 default:
1183 type_name = "WM8998";
1184 dev_err(arizona->dev, "WM8998 registered as %d\n",
1185 arizona->type);
1186 arizona->type = WM8998;
1187 }
1188
1189 apply_patch = wm8998_patch;
1190 break;
1191#endif
Mark Brown3cc72982012-06-19 16:31:53 +01001192 default:
1193 dev_err(arizona->dev, "Unknown device ID %x\n", reg);
Mark Brown59db9692012-07-09 00:31:36 +02001194 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001195 }
1196
1197 dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A');
1198
Mark Brown62d62b52012-12-02 11:41:46 +09001199 if (apply_patch) {
1200 ret = apply_patch(arizona);
1201 if (ret != 0) {
1202 dev_err(arizona->dev, "Failed to apply patch: %d\n",
1203 ret);
1204 goto err_reset;
1205 }
Charles Keepaxe80436b2013-03-26 18:46:15 +00001206
1207 switch (arizona->type) {
1208 case WM5102:
Charles Keepax0be068a2015-05-11 13:58:04 +01001209 ret = wm5102_apply_hardware_patch(arizona);
1210 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +00001211 dev_err(arizona->dev,
1212 "Failed to apply hardware patch: %d\n",
1213 ret);
1214 goto err_reset;
1215 }
1216 break;
Charles Keepax882bc462015-05-11 13:58:06 +01001217 case WM5110:
1218 case WM8280:
1219 ret = wm5110_apply_sleep_patch(arizona);
1220 if (ret) {
1221 dev_err(arizona->dev,
1222 "Failed to apply sleep patch: %d\n",
1223 ret);
1224 goto err_reset;
1225 }
1226 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +00001227 default:
1228 break;
1229 }
Mark Brown62d62b52012-12-02 11:41:46 +09001230 }
1231
Mark Brown3cc72982012-06-19 16:31:53 +01001232 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
1233 if (!arizona->pdata.gpio_defaults[i])
1234 continue;
1235
1236 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i,
1237 arizona->pdata.gpio_defaults[i]);
1238 }
1239
Mark Brown3cc72982012-06-19 16:31:53 +01001240 /* Chip default */
1241 if (!arizona->pdata.clk32k_src)
1242 arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2;
1243
1244 switch (arizona->pdata.clk32k_src) {
1245 case ARIZONA_32KZ_MCLK1:
1246 case ARIZONA_32KZ_MCLK2:
1247 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1248 ARIZONA_CLK_32K_SRC_MASK,
1249 arizona->pdata.clk32k_src - 1);
Mark Brown767c6dc2013-03-19 19:04:46 +01001250 arizona_clk32k_enable(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001251 break;
1252 case ARIZONA_32KZ_NONE:
1253 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1254 ARIZONA_CLK_32K_SRC_MASK, 2);
1255 break;
1256 default:
1257 dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n",
1258 arizona->pdata.clk32k_src);
1259 ret = -EINVAL;
Mark Brown59db9692012-07-09 00:31:36 +02001260 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001261 }
1262
Mark Brown3d91f822013-01-29 00:47:37 +08001263 for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) {
Mark Brown544c7aa2013-01-29 18:44:41 +08001264 if (!arizona->pdata.micbias[i].mV &&
1265 !arizona->pdata.micbias[i].bypass)
Mark Brown3d91f822013-01-29 00:47:37 +08001266 continue;
1267
Mark Brown544c7aa2013-01-29 18:44:41 +08001268 /* Apply default for bypass mode */
1269 if (!arizona->pdata.micbias[i].mV)
1270 arizona->pdata.micbias[i].mV = 2800;
1271
Mark Brown3d91f822013-01-29 00:47:37 +08001272 val = (arizona->pdata.micbias[i].mV - 1500) / 100;
Mark Brown544c7aa2013-01-29 18:44:41 +08001273
Mark Brown3d91f822013-01-29 00:47:37 +08001274 val <<= ARIZONA_MICB1_LVL_SHIFT;
1275
1276 if (arizona->pdata.micbias[i].ext_cap)
1277 val |= ARIZONA_MICB1_EXT_CAP;
1278
1279 if (arizona->pdata.micbias[i].discharge)
1280 val |= ARIZONA_MICB1_DISCH;
1281
Charles Keepaxf773fc62013-05-21 14:56:58 +01001282 if (arizona->pdata.micbias[i].soft_start)
Mark Brown3d91f822013-01-29 00:47:37 +08001283 val |= ARIZONA_MICB1_RATE;
1284
Mark Brown544c7aa2013-01-29 18:44:41 +08001285 if (arizona->pdata.micbias[i].bypass)
1286 val |= ARIZONA_MICB1_BYPASS;
1287
Mark Brown3d91f822013-01-29 00:47:37 +08001288 regmap_update_bits(arizona->regmap,
1289 ARIZONA_MIC_BIAS_CTRL_1 + i,
1290 ARIZONA_MICB1_LVL_MASK |
Charles Keepax71d134b2014-09-24 10:37:11 +01001291 ARIZONA_MICB1_EXT_CAP |
Mark Brown3d91f822013-01-29 00:47:37 +08001292 ARIZONA_MICB1_DISCH |
Mark Brown544c7aa2013-01-29 18:44:41 +08001293 ARIZONA_MICB1_BYPASS |
Mark Brown3d91f822013-01-29 00:47:37 +08001294 ARIZONA_MICB1_RATE, val);
1295 }
1296
Mark Brown3cc72982012-06-19 16:31:53 +01001297 for (i = 0; i < ARIZONA_MAX_INPUT; i++) {
1298 /* Default for both is 0 so noop with defaults */
1299 val = arizona->pdata.dmic_ref[i]
1300 << ARIZONA_IN1_DMIC_SUP_SHIFT;
Richard Fitzgeraldfc027d12015-05-01 16:15:12 +01001301 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_DMIC)
1302 val |= 1 << ARIZONA_IN1_MODE_SHIFT;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001303
1304 switch (arizona->type) {
1305 case WM8998:
1306 case WM1814:
1307 regmap_update_bits(arizona->regmap,
1308 ARIZONA_ADC_DIGITAL_VOLUME_1L + (i * 8),
1309 ARIZONA_IN1L_SRC_SE_MASK,
1310 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1311 << ARIZONA_IN1L_SRC_SE_SHIFT);
1312
1313 regmap_update_bits(arizona->regmap,
1314 ARIZONA_ADC_DIGITAL_VOLUME_1R + (i * 8),
1315 ARIZONA_IN1R_SRC_SE_MASK,
1316 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1317 << ARIZONA_IN1R_SRC_SE_SHIFT);
1318
1319 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1320 ARIZONA_IN1_MODE_MASK;
1321 break;
1322 default:
1323 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1324 val |= 1 << ARIZONA_IN1_SINGLE_ENDED_SHIFT;
1325
1326 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1327 ARIZONA_IN1_MODE_MASK |
1328 ARIZONA_IN1_SINGLE_ENDED_MASK;
1329 break;
1330 }
Mark Brown3cc72982012-06-19 16:31:53 +01001331
1332 regmap_update_bits(arizona->regmap,
1333 ARIZONA_IN1L_CONTROL + (i * 8),
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001334 mask, val);
Mark Brown3cc72982012-06-19 16:31:53 +01001335 }
1336
1337 for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) {
1338 /* Default is 0 so noop with defaults */
1339 if (arizona->pdata.out_mono[i])
1340 val = ARIZONA_OUT1_MONO;
1341 else
1342 val = 0;
1343
1344 regmap_update_bits(arizona->regmap,
1345 ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8),
1346 ARIZONA_OUT1_MONO, val);
1347 }
1348
Mark Brown3cc72982012-06-19 16:31:53 +01001349 for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) {
1350 if (arizona->pdata.spk_mute[i])
1351 regmap_update_bits(arizona->regmap,
Mark Brown2a51da02012-07-09 19:33:14 +01001352 ARIZONA_PDM_SPK1_CTRL_1 + (i * 2),
Mark Brown3cc72982012-06-19 16:31:53 +01001353 ARIZONA_SPK1_MUTE_ENDIAN_MASK |
1354 ARIZONA_SPK1_MUTE_SEQ1_MASK,
1355 arizona->pdata.spk_mute[i]);
1356
1357 if (arizona->pdata.spk_fmt[i])
1358 regmap_update_bits(arizona->regmap,
Mark Brown2a51da02012-07-09 19:33:14 +01001359 ARIZONA_PDM_SPK1_CTRL_2 + (i * 2),
Mark Brown3cc72982012-06-19 16:31:53 +01001360 ARIZONA_SPK1_FMT_MASK,
1361 arizona->pdata.spk_fmt[i]);
1362 }
1363
Charles Keepax72e43162015-06-14 15:41:50 +01001364 pm_runtime_set_active(arizona->dev);
1365 pm_runtime_enable(arizona->dev);
1366
Mark Brown3cc72982012-06-19 16:31:53 +01001367 /* Set up for interrupts */
1368 ret = arizona_irq_init(arizona);
1369 if (ret != 0)
Mark Brown59db9692012-07-09 00:31:36 +02001370 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001371
Charles Keepax72e43162015-06-14 15:41:50 +01001372 pm_runtime_set_autosuspend_delay(arizona->dev, 100);
1373 pm_runtime_use_autosuspend(arizona->dev);
1374
Mark Brown3cc72982012-06-19 16:31:53 +01001375 arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error",
1376 arizona_clkgen_err, arizona);
1377 arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked",
1378 arizona_overclocked, arizona);
1379 arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked",
1380 arizona_underclocked, arizona);
1381
1382 switch (arizona->type) {
1383 case WM5102:
1384 ret = mfd_add_devices(arizona->dev, -1, wm5102_devs,
Mark Brown0848c942012-09-11 15:16:36 +08001385 ARRAY_SIZE(wm5102_devs), NULL, 0, NULL);
Mark Brown3cc72982012-06-19 16:31:53 +01001386 break;
Mark Browne102bef2012-07-10 12:37:58 +01001387 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +00001388 case WM8280:
Mark Browne102bef2012-07-10 12:37:58 +01001389 ret = mfd_add_devices(arizona->dev, -1, wm5110_devs,
Charles Keepax78566af2012-11-20 13:46:19 +09001390 ARRAY_SIZE(wm5110_devs), NULL, 0, NULL);
Mark Browne102bef2012-07-10 12:37:58 +01001391 break;
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001392 case WM8997:
1393 ret = mfd_add_devices(arizona->dev, -1, wm8997_devs,
1394 ARRAY_SIZE(wm8997_devs), NULL, 0, NULL);
1395 break;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001396 case WM8998:
1397 case WM1814:
1398 ret = mfd_add_devices(arizona->dev, -1, wm8998_devs,
1399 ARRAY_SIZE(wm8998_devs), NULL, 0, NULL);
1400 break;
Mark Brown3cc72982012-06-19 16:31:53 +01001401 }
1402
1403 if (ret != 0) {
1404 dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret);
1405 goto err_irq;
1406 }
1407
1408 return 0;
1409
1410err_irq:
1411 arizona_irq_exit(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001412err_reset:
Charles Keepax22298752015-05-11 13:58:02 +01001413 arizona_enable_reset(arizona);
Mark Brown59db9692012-07-09 00:31:36 +02001414 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001415err_enable:
Mark Brown3a36a0db2012-07-09 00:45:53 +02001416 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown3cc72982012-06-19 16:31:53 +01001417 arizona->core_supplies);
Charles Keepaxe6021512014-06-02 09:50:41 +01001418err_dcvdd:
1419 regulator_put(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001420err_early:
1421 mfd_remove_devices(dev);
1422 return ret;
1423}
1424EXPORT_SYMBOL_GPL(arizona_dev_init);
1425
Bill Pemberton4740f732012-11-19 13:26:01 -05001426int arizona_dev_exit(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +01001427{
Charles Keepaxb8040202014-06-02 09:50:39 +01001428 pm_runtime_disable(arizona->dev);
1429
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001430 regulator_disable(arizona->dcvdd);
Charles Keepaxe6021512014-06-02 09:50:41 +01001431 regulator_put(arizona->dcvdd);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001432
Mark Brown3cc72982012-06-19 16:31:53 +01001433 mfd_remove_devices(arizona->dev);
1434 arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona);
1435 arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona);
1436 arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001437 arizona_irq_exit(arizona);
Charles Keepax22298752015-05-11 13:58:02 +01001438 arizona_enable_reset(arizona);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001439
Charles Keepax44202862014-06-02 09:50:42 +01001440 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown1d017b62013-03-26 12:16:26 +00001441 arizona->core_supplies);
Mark Brown3cc72982012-06-19 16:31:53 +01001442 return 0;
1443}
1444EXPORT_SYMBOL_GPL(arizona_dev_exit);