blob: 39899bf182311ce5b9e801a8b4a8c3c7758845c4 [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>
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +010027#include <linux/platform_device.h>
Mark Brown3cc72982012-06-19 16:31:53 +010028
29#include <linux/mfd/arizona/core.h>
30#include <linux/mfd/arizona/registers.h>
31
32#include "arizona.h"
33
Charles Keepax3762aed2015-08-11 09:34:31 +010034static const char * const wm5102_core_supplies[] = {
Mark Brown3cc72982012-06-19 16:31:53 +010035 "AVDD",
36 "DBVDD1",
Mark Brown3cc72982012-06-19 16:31:53 +010037};
38
39int arizona_clk32k_enable(struct arizona *arizona)
40{
41 int ret = 0;
42
43 mutex_lock(&arizona->clk_lock);
44
45 arizona->clk32k_ref++;
46
Mark Brown247fa192013-03-19 14:47:47 +010047 if (arizona->clk32k_ref == 1) {
48 switch (arizona->pdata.clk32k_src) {
49 case ARIZONA_32KZ_MCLK1:
50 ret = pm_runtime_get_sync(arizona->dev);
51 if (ret != 0)
52 goto out;
53 break;
54 }
55
Mark Brown3cc72982012-06-19 16:31:53 +010056 ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
57 ARIZONA_CLK_32K_ENA,
58 ARIZONA_CLK_32K_ENA);
Mark Brown247fa192013-03-19 14:47:47 +010059 }
Mark Brown3cc72982012-06-19 16:31:53 +010060
Mark Brown247fa192013-03-19 14:47:47 +010061out:
Mark Brown3cc72982012-06-19 16:31:53 +010062 if (ret != 0)
63 arizona->clk32k_ref--;
64
65 mutex_unlock(&arizona->clk_lock);
66
67 return ret;
68}
69EXPORT_SYMBOL_GPL(arizona_clk32k_enable);
70
71int arizona_clk32k_disable(struct arizona *arizona)
72{
Mark Brown3cc72982012-06-19 16:31:53 +010073 mutex_lock(&arizona->clk_lock);
74
75 BUG_ON(arizona->clk32k_ref <= 0);
76
77 arizona->clk32k_ref--;
78
Mark Brown247fa192013-03-19 14:47:47 +010079 if (arizona->clk32k_ref == 0) {
Mark Brown3cc72982012-06-19 16:31:53 +010080 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
81 ARIZONA_CLK_32K_ENA, 0);
82
Mark Brown247fa192013-03-19 14:47:47 +010083 switch (arizona->pdata.clk32k_src) {
84 case ARIZONA_32KZ_MCLK1:
85 pm_runtime_put_sync(arizona->dev);
86 break;
87 }
88 }
89
Mark Brown3cc72982012-06-19 16:31:53 +010090 mutex_unlock(&arizona->clk_lock);
91
Javier Martinez Canillasa260fba2015-09-29 13:26:02 +020092 return 0;
Mark Brown3cc72982012-06-19 16:31:53 +010093}
94EXPORT_SYMBOL_GPL(arizona_clk32k_disable);
95
96static irqreturn_t arizona_clkgen_err(int irq, void *data)
97{
98 struct arizona *arizona = data;
99
100 dev_err(arizona->dev, "CLKGEN error\n");
101
102 return IRQ_HANDLED;
103}
104
105static irqreturn_t arizona_underclocked(int irq, void *data)
106{
107 struct arizona *arizona = data;
108 unsigned int val;
109 int ret;
110
111 ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8,
112 &val);
113 if (ret != 0) {
114 dev_err(arizona->dev, "Failed to read underclock status: %d\n",
115 ret);
116 return IRQ_NONE;
117 }
118
119 if (val & ARIZONA_AIF3_UNDERCLOCKED_STS)
120 dev_err(arizona->dev, "AIF3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100121 if (val & ARIZONA_AIF2_UNDERCLOCKED_STS)
Charles Keepax3ebef342012-11-20 13:46:20 +0900122 dev_err(arizona->dev, "AIF2 underclocked\n");
123 if (val & ARIZONA_AIF1_UNDERCLOCKED_STS)
Mark Brown3cc72982012-06-19 16:31:53 +0100124 dev_err(arizona->dev, "AIF1 underclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100125 if (val & ARIZONA_ISRC3_UNDERCLOCKED_STS)
126 dev_err(arizona->dev, "ISRC3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100127 if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS)
128 dev_err(arizona->dev, "ISRC2 underclocked\n");
129 if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS)
130 dev_err(arizona->dev, "ISRC1 underclocked\n");
131 if (val & ARIZONA_FX_UNDERCLOCKED_STS)
132 dev_err(arizona->dev, "FX underclocked\n");
133 if (val & ARIZONA_ASRC_UNDERCLOCKED_STS)
134 dev_err(arizona->dev, "ASRC underclocked\n");
135 if (val & ARIZONA_DAC_UNDERCLOCKED_STS)
136 dev_err(arizona->dev, "DAC underclocked\n");
137 if (val & ARIZONA_ADC_UNDERCLOCKED_STS)
138 dev_err(arizona->dev, "ADC underclocked\n");
139 if (val & ARIZONA_MIXER_UNDERCLOCKED_STS)
Mark Brown648a9882013-01-28 00:32:53 +0800140 dev_err(arizona->dev, "Mixer dropped sample\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100141
142 return IRQ_HANDLED;
143}
144
145static irqreturn_t arizona_overclocked(int irq, void *data)
146{
147 struct arizona *arizona = data;
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100148 unsigned int val[3];
Mark Brown3cc72982012-06-19 16:31:53 +0100149 int ret;
Charles Keepax3762aed2015-08-11 09:34:31 +0100150
Mark Brown3cc72982012-06-19 16:31:53 +0100151 ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6,
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100152 &val[0], 3);
Mark Brown3cc72982012-06-19 16:31:53 +0100153 if (ret != 0) {
154 dev_err(arizona->dev, "Failed to read overclock status: %d\n",
155 ret);
156 return IRQ_NONE;
157 }
158
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100159 switch (arizona->type) {
160 case WM8998:
161 case WM1814:
162 /* Some bits are shifted on WM8998,
163 * rearrange to match the standard bit layout
164 */
165 val[0] = ((val[0] & 0x60e0) >> 1) |
166 ((val[0] & 0x1e00) >> 2) |
167 (val[0] & 0x000f);
168 break;
169 default:
170 break;
171 }
172
Mark Brown3cc72982012-06-19 16:31:53 +0100173 if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS)
174 dev_err(arizona->dev, "PWM overclocked\n");
175 if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS)
176 dev_err(arizona->dev, "FX core overclocked\n");
177 if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS)
178 dev_err(arizona->dev, "DAC SYS overclocked\n");
179 if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS)
180 dev_err(arizona->dev, "DAC WARP overclocked\n");
181 if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS)
182 dev_err(arizona->dev, "ADC overclocked\n");
183 if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS)
184 dev_err(arizona->dev, "Mixer overclocked\n");
185 if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS)
186 dev_err(arizona->dev, "AIF3 overclocked\n");
187 if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS)
188 dev_err(arizona->dev, "AIF2 overclocked\n");
189 if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS)
190 dev_err(arizona->dev, "AIF1 overclocked\n");
191 if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS)
192 dev_err(arizona->dev, "Pad control overclocked\n");
193
194 if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS)
195 dev_err(arizona->dev, "Slimbus subsystem overclocked\n");
196 if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS)
197 dev_err(arizona->dev, "Slimbus async overclocked\n");
198 if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS)
199 dev_err(arizona->dev, "Slimbus sync overclocked\n");
200 if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS)
201 dev_err(arizona->dev, "ASRC async system overclocked\n");
202 if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS)
203 dev_err(arizona->dev, "ASRC async WARP overclocked\n");
204 if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS)
205 dev_err(arizona->dev, "ASRC sync system overclocked\n");
206 if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS)
207 dev_err(arizona->dev, "ASRC sync WARP overclocked\n");
208 if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS)
209 dev_err(arizona->dev, "DSP1 overclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100210 if (val[1] & ARIZONA_ISRC3_OVERCLOCKED_STS)
211 dev_err(arizona->dev, "ISRC3 overclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100212 if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS)
213 dev_err(arizona->dev, "ISRC2 overclocked\n");
214 if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS)
215 dev_err(arizona->dev, "ISRC1 overclocked\n");
216
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100217 if (val[2] & ARIZONA_SPDIF_OVERCLOCKED_STS)
218 dev_err(arizona->dev, "SPDIF overclocked\n");
219
Mark Brown3cc72982012-06-19 16:31:53 +0100220 return IRQ_HANDLED;
221}
222
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000223static int arizona_poll_reg(struct arizona *arizona,
224 int timeout, unsigned int reg,
225 unsigned int mask, unsigned int target)
226{
227 unsigned int val = 0;
228 int ret, i;
229
230 for (i = 0; i < timeout; i++) {
231 ret = regmap_read(arizona->regmap, reg, &val);
232 if (ret != 0) {
233 dev_err(arizona->dev, "Failed to read reg %u: %d\n",
234 reg, ret);
235 continue;
236 }
237
238 if ((val & mask) == target)
239 return 0;
240
241 msleep(1);
242 }
243
244 dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val);
245 return -ETIMEDOUT;
246}
247
Mark Brown3cc72982012-06-19 16:31:53 +0100248static int arizona_wait_for_boot(struct arizona *arizona)
249{
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000250 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100251
252 /*
253 * We can't use an interrupt as we need to runtime resume to do so,
254 * we won't race with the interrupt handler as it'll be blocked on
255 * runtime resume.
256 */
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000257 ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5,
258 ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100259
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000260 if (!ret)
Mark Brown3cc72982012-06-19 16:31:53 +0100261 regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
262 ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100263
264 pm_runtime_mark_last_busy(arizona->dev);
265
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000266 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100267}
268
Charles Keepax22298752015-05-11 13:58:02 +0100269static inline void arizona_enable_reset(struct arizona *arizona)
270{
271 if (arizona->pdata.reset)
272 gpio_set_value_cansleep(arizona->pdata.reset, 0);
273}
274
275static void arizona_disable_reset(struct arizona *arizona)
276{
277 if (arizona->pdata.reset) {
Charles Keepax121c0752015-05-11 13:58:10 +0100278 switch (arizona->type) {
279 case WM5110:
280 case WM8280:
281 /* Meet requirements for minimum reset duration */
282 msleep(5);
283 break;
284 default:
285 break;
286 }
287
Charles Keepax22298752015-05-11 13:58:02 +0100288 gpio_set_value_cansleep(arizona->pdata.reset, 1);
289 msleep(1);
290 }
291}
292
Charles Keepax3850e3e2015-05-11 13:58:05 +0100293struct arizona_sysclk_state {
294 unsigned int fll;
295 unsigned int sysclk;
296};
297
298static int arizona_enable_freerun_sysclk(struct arizona *arizona,
299 struct arizona_sysclk_state *state)
Charles Keepaxe80436b2013-03-26 18:46:15 +0000300{
Charles Keepaxe80436b2013-03-26 18:46:15 +0000301 int ret, err;
302
Charles Keepaxe80436b2013-03-26 18:46:15 +0000303 /* Cache existing FLL and SYSCLK settings */
Charles Keepax3850e3e2015-05-11 13:58:05 +0100304 ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll);
Charles Keepax0be068a2015-05-11 13:58:04 +0100305 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000306 dev_err(arizona->dev, "Failed to cache FLL settings: %d\n",
307 ret);
308 return ret;
309 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100310 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
311 &state->sysclk);
Charles Keepax0be068a2015-05-11 13:58:04 +0100312 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000313 dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
314 ret);
315 return ret;
316 }
317
318 /* Start up SYSCLK using the FLL in free running mode */
319 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1,
320 ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN);
Charles Keepax0be068a2015-05-11 13:58:04 +0100321 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000322 dev_err(arizona->dev,
323 "Failed to start FLL in freerunning mode: %d\n",
324 ret);
325 return ret;
326 }
327 ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
328 ARIZONA_FLL1_CLOCK_OK_STS,
329 ARIZONA_FLL1_CLOCK_OK_STS);
Charles Keepax0be068a2015-05-11 13:58:04 +0100330 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000331 ret = -ETIMEDOUT;
332 goto err_fll;
333 }
334
335 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
Charles Keepax0be068a2015-05-11 13:58:04 +0100336 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000337 dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
338 goto err_fll;
339 }
340
Charles Keepax3850e3e2015-05-11 13:58:05 +0100341 return 0;
342
343err_fll:
344 err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
345 if (err)
346 dev_err(arizona->dev,
347 "Failed to re-apply old FLL settings: %d\n", err);
348
349 return ret;
350}
351
352static int arizona_disable_freerun_sysclk(struct arizona *arizona,
353 struct arizona_sysclk_state *state)
354{
355 int ret;
356
357 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
358 state->sysclk);
359 if (ret) {
360 dev_err(arizona->dev,
361 "Failed to re-apply old SYSCLK settings: %d\n", ret);
362 return ret;
363 }
364
365 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
366 if (ret) {
367 dev_err(arizona->dev,
368 "Failed to re-apply old FLL settings: %d\n", ret);
369 return ret;
370 }
371
372 return 0;
373}
374
375static int wm5102_apply_hardware_patch(struct arizona *arizona)
376{
377 struct arizona_sysclk_state state;
378 int err, ret;
379
380 ret = arizona_enable_freerun_sysclk(arizona, &state);
381 if (ret)
382 return ret;
383
Charles Keepaxe80436b2013-03-26 18:46:15 +0000384 /* Start the write sequencer and wait for it to finish */
385 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100386 ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160);
387 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000388 dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
389 ret);
Charles Keepax3850e3e2015-05-11 13:58:05 +0100390 goto err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000391 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100392
Charles Keepaxe80436b2013-03-26 18:46:15 +0000393 ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
394 ARIZONA_WSEQ_BUSY, 0);
Charles Keepax0be068a2015-05-11 13:58:04 +0100395 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000396 regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100397 ARIZONA_WSEQ_ABORT);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000398 ret = -ETIMEDOUT;
399 }
400
Charles Keepax3850e3e2015-05-11 13:58:05 +0100401err:
402 err = arizona_disable_freerun_sysclk(arizona, &state);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000403
Charles Keepax0be068a2015-05-11 13:58:04 +0100404 return ret ?: err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000405}
406
Charles Keepax882bc462015-05-11 13:58:06 +0100407/*
408 * Register patch to some of the CODECs internal write sequences
409 * to ensure a clean exit from the low power sleep state.
410 */
Nariman Poushin8019ff62015-07-16 16:36:21 +0100411static const struct reg_sequence wm5110_sleep_patch[] = {
Charles Keepax882bc462015-05-11 13:58:06 +0100412 { 0x337A, 0xC100 },
413 { 0x337B, 0x0041 },
414 { 0x3300, 0xA210 },
415 { 0x3301, 0x050C },
416};
417
418static int wm5110_apply_sleep_patch(struct arizona *arizona)
419{
420 struct arizona_sysclk_state state;
421 int err, ret;
422
423 ret = arizona_enable_freerun_sysclk(arizona, &state);
424 if (ret)
425 return ret;
426
427 ret = regmap_multi_reg_write_bypassed(arizona->regmap,
428 wm5110_sleep_patch,
429 ARRAY_SIZE(wm5110_sleep_patch));
430
431 err = arizona_disable_freerun_sysclk(arizona, &state);
432
433 return ret ?: err;
434}
435
Charles Keepax1c1c6bb2015-05-11 13:58:03 +0100436static int wm5102_clear_write_sequencer(struct arizona *arizona)
437{
438 int ret;
439
440 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_3,
441 0x0);
442 if (ret) {
443 dev_err(arizona->dev,
444 "Failed to clear write sequencer state: %d\n", ret);
445 return ret;
446 }
447
448 arizona_enable_reset(arizona);
449 regulator_disable(arizona->dcvdd);
450
451 msleep(20);
452
453 ret = regulator_enable(arizona->dcvdd);
454 if (ret) {
455 dev_err(arizona->dev, "Failed to re-enable DCVDD: %d\n", ret);
456 return ret;
457 }
458 arizona_disable_reset(arizona);
459
460 return 0;
461}
462
Rafael J. Wysocki48bb9fe2014-12-05 03:04:12 +0100463#ifdef CONFIG_PM
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100464static int arizona_isolate_dcvdd(struct arizona *arizona)
465{
466 int ret;
467
468 ret = regmap_update_bits(arizona->regmap,
469 ARIZONA_ISOLATION_CONTROL,
470 ARIZONA_ISOLATE_DCVDD1,
471 ARIZONA_ISOLATE_DCVDD1);
472 if (ret != 0)
473 dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n", ret);
474
475 return ret;
476}
477
478static int arizona_connect_dcvdd(struct arizona *arizona)
479{
480 int ret;
481
482 ret = regmap_update_bits(arizona->regmap,
483 ARIZONA_ISOLATION_CONTROL,
484 ARIZONA_ISOLATE_DCVDD1, 0);
485 if (ret != 0)
486 dev_err(arizona->dev, "Failed to connect DCVDD: %d\n", ret);
487
488 return ret;
489}
490
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100491static int arizona_is_jack_det_active(struct arizona *arizona)
492{
493 unsigned int val;
494 int ret;
495
496 ret = regmap_read(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, &val);
497 if (ret) {
498 dev_err(arizona->dev,
499 "Failed to check jack det status: %d\n", ret);
500 return ret;
501 } else if (val & ARIZONA_JD1_ENA) {
502 return 1;
503 } else {
504 return 0;
505 }
506}
507
Mark Brown3cc72982012-06-19 16:31:53 +0100508static int arizona_runtime_resume(struct device *dev)
509{
510 struct arizona *arizona = dev_get_drvdata(dev);
511 int ret;
512
Mark Brown508c8292012-07-20 17:09:12 +0100513 dev_dbg(arizona->dev, "Leaving AoD mode\n");
514
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100515 if (arizona->has_fully_powered_off) {
516 dev_dbg(arizona->dev, "Re-enabling core supplies\n");
517
518 ret = regulator_bulk_enable(arizona->num_core_supplies,
519 arizona->core_supplies);
520 if (ret) {
521 dev_err(dev, "Failed to enable core supplies: %d\n",
522 ret);
523 return ret;
524 }
525 }
526
Mark Brown59db9692012-07-09 00:31:36 +0200527 ret = regulator_enable(arizona->dcvdd);
528 if (ret != 0) {
529 dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100530 if (arizona->has_fully_powered_off)
531 regulator_bulk_disable(arizona->num_core_supplies,
532 arizona->core_supplies);
Mark Brown59db9692012-07-09 00:31:36 +0200533 return ret;
534 }
Mark Brown3cc72982012-06-19 16:31:53 +0100535
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100536 if (arizona->has_fully_powered_off) {
537 arizona_disable_reset(arizona);
538 enable_irq(arizona->irq);
539 arizona->has_fully_powered_off = false;
540 }
541
Mark Brown3cc72982012-06-19 16:31:53 +0100542 regcache_cache_only(arizona->regmap, false);
543
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000544 switch (arizona->type) {
545 case WM5102:
Mark Brown59274672013-04-23 19:44:16 +0100546 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100547 ret = arizona_connect_dcvdd(arizona);
548 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100549 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100550 }
551
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000552 ret = wm5102_patch(arizona);
553 if (ret != 0) {
554 dev_err(arizona->dev, "Failed to apply patch: %d\n",
555 ret);
556 goto err;
557 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000558
Charles Keepax0be068a2015-05-11 13:58:04 +0100559 ret = wm5102_apply_hardware_patch(arizona);
560 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000561 dev_err(arizona->dev,
562 "Failed to apply hardware patch: %d\n",
563 ret);
564 goto err;
565 }
566 break;
Charles Keepax96129a02015-05-11 13:58:08 +0100567 case WM5110:
568 case WM8280:
569 ret = arizona_wait_for_boot(arizona);
570 if (ret)
571 goto err;
572
573 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100574 ret = arizona_connect_dcvdd(arizona);
575 if (ret != 0)
Charles Keepax96129a02015-05-11 13:58:08 +0100576 goto err;
Charles Keepax96129a02015-05-11 13:58:08 +0100577 } else {
578 /*
579 * As this is only called for the internal regulator
580 * (where we know voltage ranges available) it is ok
581 * to request an exact range.
582 */
583 ret = regulator_set_voltage(arizona->dcvdd,
584 1200000, 1200000);
585 if (ret < 0) {
586 dev_err(arizona->dev,
587 "Failed to set resume voltage: %d\n",
588 ret);
589 goto err;
590 }
591 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100592
593 ret = wm5110_apply_sleep_patch(arizona);
594 if (ret) {
595 dev_err(arizona->dev,
596 "Failed to re-apply sleep patch: %d\n",
597 ret);
598 goto err;
599 }
Charles Keepax96129a02015-05-11 13:58:08 +0100600 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000601 default:
Charles Keepax12bb68e2013-03-27 09:49:40 +0000602 ret = arizona_wait_for_boot(arizona);
Charles Keepax3762aed2015-08-11 09:34:31 +0100603 if (ret != 0)
Charles Keepax12bb68e2013-03-27 09:49:40 +0000604 goto err;
Charles Keepax12bb68e2013-03-27 09:49:40 +0000605
Mark Brown59274672013-04-23 19:44:16 +0100606 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100607 ret = arizona_connect_dcvdd(arizona);
608 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100609 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100610 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000611 break;
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000612 }
613
Mark Brown9270bdf2013-01-04 17:16:12 +0000614 ret = regcache_sync(arizona->regmap);
615 if (ret != 0) {
616 dev_err(arizona->dev, "Failed to restore register cache\n");
Mark Brown4816bd12013-01-14 15:50:38 +0900617 goto err;
Mark Brown9270bdf2013-01-04 17:16:12 +0000618 }
Mark Brown3cc72982012-06-19 16:31:53 +0100619
620 return 0;
Mark Brown4816bd12013-01-14 15:50:38 +0900621
622err:
623 regcache_cache_only(arizona->regmap, true);
624 regulator_disable(arizona->dcvdd);
625 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100626}
627
628static int arizona_runtime_suspend(struct device *dev)
629{
630 struct arizona *arizona = dev_get_drvdata(dev);
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100631 unsigned int jd_active = 0;
Mark Brown59274672013-04-23 19:44:16 +0100632 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100633
Mark Brown508c8292012-07-20 17:09:12 +0100634 dev_dbg(arizona->dev, "Entering AoD mode\n");
635
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100636 switch (arizona->type) {
637 case WM5110:
638 case WM8280:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100639 jd_active = arizona_is_jack_det_active(arizona);
640 if (jd_active < 0)
641 return jd_active;
642
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100643 if (arizona->external_dcvdd) {
644 ret = arizona_isolate_dcvdd(arizona);
645 if (ret != 0)
646 return ret;
647 } else {
648 /*
649 * As this is only called for the internal regulator
650 * (where we know voltage ranges available) it is ok
651 * to request an exact range.
652 */
653 ret = regulator_set_voltage(arizona->dcvdd,
654 1175000, 1175000);
655 if (ret < 0) {
656 dev_err(arizona->dev,
657 "Failed to set suspend voltage: %d\n",
658 ret);
659 return ret;
660 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100661 }
662 break;
663 case WM5102:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100664 jd_active = arizona_is_jack_det_active(arizona);
665 if (jd_active < 0)
666 return jd_active;
667
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100668 if (arizona->external_dcvdd) {
669 ret = arizona_isolate_dcvdd(arizona);
670 if (ret != 0)
671 return ret;
672 }
673
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100674 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100675 ret = regmap_write(arizona->regmap,
676 ARIZONA_WRITE_SEQUENCER_CTRL_3, 0x0);
677 if (ret) {
Charles Keepax96129a02015-05-11 13:58:08 +0100678 dev_err(arizona->dev,
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100679 "Failed to clear write sequencer: %d\n",
Charles Keepax96129a02015-05-11 13:58:08 +0100680 ret);
681 return ret;
682 }
Charles Keepax96129a02015-05-11 13:58:08 +0100683 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100684 break;
685 default:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100686 jd_active = arizona_is_jack_det_active(arizona);
687 if (jd_active < 0)
688 return jd_active;
689
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100690 if (arizona->external_dcvdd) {
691 ret = arizona_isolate_dcvdd(arizona);
692 if (ret != 0)
693 return ret;
694 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100695 break;
Mark Brown59274672013-04-23 19:44:16 +0100696 }
697
Mark Brown59db9692012-07-09 00:31:36 +0200698 regcache_cache_only(arizona->regmap, true);
699 regcache_mark_dirty(arizona->regmap);
Charles Keepaxe293e84722013-08-06 17:18:35 +0100700 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +0100701
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100702 /* Allow us to completely power down if no jack detection */
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100703 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100704 dev_dbg(arizona->dev, "Fully powering off\n");
705
706 arizona->has_fully_powered_off = true;
707
Charles Keepax11150922015-06-14 15:41:49 +0100708 disable_irq_nosync(arizona->irq);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100709 arizona_enable_reset(arizona);
710 regulator_bulk_disable(arizona->num_core_supplies,
711 arizona->core_supplies);
712 }
713
Mark Brown3cc72982012-06-19 16:31:53 +0100714 return 0;
715}
716#endif
717
Mark Browndc781d02013-01-27 12:07:32 +0800718#ifdef CONFIG_PM_SLEEP
Mark Brown67c99292013-04-10 12:40:26 +0100719static int arizona_suspend(struct device *dev)
720{
721 struct arizona *arizona = dev_get_drvdata(dev);
722
723 dev_dbg(arizona->dev, "Suspend, disabling IRQ\n");
724 disable_irq(arizona->irq);
725
726 return 0;
727}
728
729static int arizona_suspend_late(struct device *dev)
730{
731 struct arizona *arizona = dev_get_drvdata(dev);
732
733 dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n");
734 enable_irq(arizona->irq);
735
736 return 0;
737}
738
Mark Browndc781d02013-01-27 12:07:32 +0800739static int arizona_resume_noirq(struct device *dev)
740{
741 struct arizona *arizona = dev_get_drvdata(dev);
742
743 dev_dbg(arizona->dev, "Early resume, disabling IRQ\n");
744 disable_irq(arizona->irq);
745
746 return 0;
747}
748
749static int arizona_resume(struct device *dev)
750{
751 struct arizona *arizona = dev_get_drvdata(dev);
752
753 dev_dbg(arizona->dev, "Late resume, reenabling IRQ\n");
754 enable_irq(arizona->irq);
755
756 return 0;
757}
758#endif
759
Mark Brown3cc72982012-06-19 16:31:53 +0100760const struct dev_pm_ops arizona_pm_ops = {
761 SET_RUNTIME_PM_OPS(arizona_runtime_suspend,
762 arizona_runtime_resume,
763 NULL)
Mark Brown67c99292013-04-10 12:40:26 +0100764 SET_SYSTEM_SLEEP_PM_OPS(arizona_suspend, arizona_resume)
Mark Browndc781d02013-01-27 12:07:32 +0800765#ifdef CONFIG_PM_SLEEP
Mark Brown67c99292013-04-10 12:40:26 +0100766 .suspend_late = arizona_suspend_late,
Mark Browndc781d02013-01-27 12:07:32 +0800767 .resume_noirq = arizona_resume_noirq,
768#endif
Mark Brown3cc72982012-06-19 16:31:53 +0100769};
770EXPORT_SYMBOL_GPL(arizona_pm_ops);
771
Mark Brownd7810092013-03-25 00:11:27 +0000772#ifdef CONFIG_OF
Lee Jones942786e2014-07-02 14:28:46 +0100773unsigned long arizona_of_get_type(struct device *dev)
Mark Brownd7810092013-03-25 00:11:27 +0000774{
775 const struct of_device_id *id = of_match_device(arizona_of_match, dev);
776
777 if (id)
Lee Jones942786e2014-07-02 14:28:46 +0100778 return (unsigned long)id->data;
Mark Brownd7810092013-03-25 00:11:27 +0000779 else
780 return 0;
781}
782EXPORT_SYMBOL_GPL(arizona_of_get_type);
783
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100784int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop,
785 bool mandatory)
786{
787 int gpio;
788
789 gpio = of_get_named_gpio(arizona->dev->of_node, prop, 0);
790 if (gpio < 0) {
791 if (mandatory)
792 dev_err(arizona->dev,
793 "Mandatory DT gpio %s missing/malformed: %d\n",
794 prop, gpio);
795
796 gpio = 0;
797 }
798
799 return gpio;
800}
801EXPORT_SYMBOL_GPL(arizona_of_get_named_gpio);
802
Mark Brownd7810092013-03-25 00:11:27 +0000803static int arizona_of_get_core_pdata(struct arizona *arizona)
804{
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100805 struct arizona_pdata *pdata = &arizona->pdata;
Inha Songcc47aed2014-08-30 11:27:18 +0900806 struct property *prop;
807 const __be32 *cur;
808 u32 val;
Mark Brownd7810092013-03-25 00:11:27 +0000809 int ret, i;
Inha Songcc47aed2014-08-30 11:27:18 +0900810 int count = 0;
Mark Brownd7810092013-03-25 00:11:27 +0000811
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100812 pdata->reset = arizona_of_get_named_gpio(arizona, "wlf,reset", true);
Mark Brownd7810092013-03-25 00:11:27 +0000813
814 ret = of_property_read_u32_array(arizona->dev->of_node,
815 "wlf,gpio-defaults",
Charles Keepax3762aed2015-08-11 09:34:31 +0100816 pdata->gpio_defaults,
817 ARRAY_SIZE(pdata->gpio_defaults));
Mark Brownd7810092013-03-25 00:11:27 +0000818 if (ret >= 0) {
819 /*
820 * All values are literal except out of range values
821 * which are chip default, translate into platform
822 * data which uses 0 as chip default and out of range
823 * as zero.
824 */
Charles Keepax3762aed2015-08-11 09:34:31 +0100825 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
826 if (pdata->gpio_defaults[i] > 0xffff)
827 pdata->gpio_defaults[i] = 0;
828 else if (pdata->gpio_defaults[i] == 0)
829 pdata->gpio_defaults[i] = 0x10000;
Mark Brownd7810092013-03-25 00:11:27 +0000830 }
831 } else {
832 dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n",
833 ret);
834 }
835
Inha Songcc47aed2014-08-30 11:27:18 +0900836 of_property_for_each_u32(arizona->dev->of_node, "wlf,inmode", prop,
837 cur, val) {
Charles Keepax3762aed2015-08-11 09:34:31 +0100838 if (count == ARRAY_SIZE(pdata->inmode))
Inha Songcc47aed2014-08-30 11:27:18 +0900839 break;
840
Charles Keepax3762aed2015-08-11 09:34:31 +0100841 pdata->inmode[count] = val;
Inha Songcc47aed2014-08-30 11:27:18 +0900842 count++;
843 }
844
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000845 count = 0;
846 of_property_for_each_u32(arizona->dev->of_node, "wlf,dmic-ref", prop,
847 cur, val) {
Charles Keepax3762aed2015-08-11 09:34:31 +0100848 if (count == ARRAY_SIZE(pdata->dmic_ref))
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000849 break;
850
Charles Keepax3762aed2015-08-11 09:34:31 +0100851 pdata->dmic_ref[count] = val;
Charles Keepaxe7ad27c2015-03-03 15:04:53 +0000852 count++;
853 }
854
Mark Brownd7810092013-03-25 00:11:27 +0000855 return 0;
856}
857
858const struct of_device_id arizona_of_match[] = {
859 { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
860 { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000861 { .compatible = "wlf,wm8280", .data = (void *)WM8280 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100862 { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100863 { .compatible = "wlf,wm8998", .data = (void *)WM8998 },
864 { .compatible = "wlf,wm1814", .data = (void *)WM1814 },
Mark Brownd7810092013-03-25 00:11:27 +0000865 {},
866};
867EXPORT_SYMBOL_GPL(arizona_of_match);
868#else
869static inline int arizona_of_get_core_pdata(struct arizona *arizona)
870{
871 return 0;
872}
873#endif
874
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100875static const struct mfd_cell early_devs[] = {
Mark Brown3cc72982012-06-19 16:31:53 +0100876 { .name = "arizona-ldo1" },
877};
878
Charles Keepax3762aed2015-08-11 09:34:31 +0100879static const char * const wm5102_supplies[] = {
Charles Keepax5fc6c392014-07-25 16:24:44 +0100880 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100881 "DBVDD2",
882 "DBVDD3",
883 "CPVDD",
884 "SPKVDDL",
885 "SPKVDDR",
886};
887
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100888static const struct mfd_cell wm5102_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000889 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100890 {
891 .name = "arizona-extcon",
892 .parent_supplies = wm5102_supplies,
893 .num_parent_supplies = 1, /* We only need MICVDD */
894 },
Mark Brown3cc72982012-06-19 16:31:53 +0100895 { .name = "arizona-gpio" },
Mark Brown503b1ca2012-11-27 17:36:38 +0000896 { .name = "arizona-haptics" },
Mark Brown3cc72982012-06-19 16:31:53 +0100897 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100898 {
899 .name = "wm5102-codec",
900 .parent_supplies = wm5102_supplies,
901 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
902 },
Mark Brown3cc72982012-06-19 16:31:53 +0100903};
904
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100905static const struct mfd_cell wm5110_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000906 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100907 {
908 .name = "arizona-extcon",
909 .parent_supplies = wm5102_supplies,
910 .num_parent_supplies = 1, /* We only need MICVDD */
911 },
Mark Browne102bef2012-07-10 12:37:58 +0100912 { .name = "arizona-gpio" },
Mark Brown503b1ca2012-11-27 17:36:38 +0000913 { .name = "arizona-haptics" },
Mark Browne102bef2012-07-10 12:37:58 +0100914 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100915 {
916 .name = "wm5110-codec",
917 .parent_supplies = wm5102_supplies,
918 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
919 },
920};
921
Charles Keepax3762aed2015-08-11 09:34:31 +0100922static const char * const wm8997_supplies[] = {
Charles Keepax996c2d42014-07-25 16:24:43 +0100923 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100924 "DBVDD2",
925 "CPVDD",
926 "SPKVDD",
Mark Browne102bef2012-07-10 12:37:58 +0100927};
928
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100929static const struct mfd_cell wm8997_devs[] = {
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100930 { .name = "arizona-micsupp" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100931 {
932 .name = "arizona-extcon",
933 .parent_supplies = wm8997_supplies,
934 .num_parent_supplies = 1, /* We only need MICVDD */
935 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100936 { .name = "arizona-gpio" },
937 { .name = "arizona-haptics" },
938 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100939 {
940 .name = "wm8997-codec",
941 .parent_supplies = wm8997_supplies,
942 .num_parent_supplies = ARRAY_SIZE(wm8997_supplies),
943 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100944};
945
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100946static const struct mfd_cell wm8998_devs[] = {
947 {
948 .name = "arizona-extcon",
949 .parent_supplies = wm5102_supplies,
950 .num_parent_supplies = 1, /* We only need MICVDD */
951 },
952 { .name = "arizona-gpio" },
953 { .name = "arizona-haptics" },
954 { .name = "arizona-pwm" },
955 {
956 .name = "wm8998-codec",
957 .parent_supplies = wm5102_supplies,
958 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
959 },
960 { .name = "arizona-micsupp" },
961};
962
Bill Pembertonf791be42012-11-19 13:23:04 -0500963int arizona_dev_init(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +0100964{
965 struct device *dev = arizona->dev;
966 const char *type_name;
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100967 unsigned int reg, val, mask;
Mark Brown62d62b52012-12-02 11:41:46 +0900968 int (*apply_patch)(struct arizona *) = NULL;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +0100969 const struct mfd_cell *subdevs = NULL;
970 int n_subdevs, ret, i;
Mark Brown3cc72982012-06-19 16:31:53 +0100971
972 dev_set_drvdata(arizona->dev, arizona);
973 mutex_init(&arizona->clk_lock);
974
975 if (dev_get_platdata(arizona->dev))
976 memcpy(&arizona->pdata, dev_get_platdata(arizona->dev),
977 sizeof(arizona->pdata));
Lee Jones22d7dc82013-09-27 14:25:55 +0100978 else
979 arizona_of_get_core_pdata(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +0100980
981 regcache_cache_only(arizona->regmap, true);
982
983 switch (arizona->type) {
984 case WM5102:
Mark Browne102bef2012-07-10 12:37:58 +0100985 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000986 case WM8280:
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100987 case WM8997:
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100988 case WM8998:
989 case WM1814:
Mark Brown3cc72982012-06-19 16:31:53 +0100990 for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++)
991 arizona->core_supplies[i].supply
992 = wm5102_core_supplies[i];
993 arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies);
994 break;
995 default:
996 dev_err(arizona->dev, "Unknown device type %d\n",
997 arizona->type);
998 return -EINVAL;
999 }
1000
Charles Keepax4a8c4752014-04-16 10:01:38 +01001001 /* Mark DCVDD as external, LDO1 driver will clear if internal */
1002 arizona->external_dcvdd = true;
1003
Mark Brown3cc72982012-06-19 16:31:53 +01001004 ret = mfd_add_devices(arizona->dev, -1, early_devs,
Mark Brown0848c942012-09-11 15:16:36 +08001005 ARRAY_SIZE(early_devs), NULL, 0, NULL);
Mark Brown3cc72982012-06-19 16:31:53 +01001006 if (ret != 0) {
1007 dev_err(dev, "Failed to add early children: %d\n", ret);
1008 return ret;
1009 }
1010
1011 ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies,
1012 arizona->core_supplies);
1013 if (ret != 0) {
1014 dev_err(dev, "Failed to request core supplies: %d\n",
1015 ret);
1016 goto err_early;
1017 }
1018
Charles Keepax0c2d0ff2014-06-19 16:04:23 +01001019 /**
1020 * Don't use devres here because the only device we have to get
1021 * against is the MFD device and DCVDD will likely be supplied by
1022 * one of its children. Meaning that the regulator will be
1023 * destroyed by the time devres calls regulator put.
1024 */
Charles Keepaxe6021512014-06-02 09:50:41 +01001025 arizona->dcvdd = regulator_get(arizona->dev, "DCVDD");
Mark Brown59db9692012-07-09 00:31:36 +02001026 if (IS_ERR(arizona->dcvdd)) {
1027 ret = PTR_ERR(arizona->dcvdd);
1028 dev_err(dev, "Failed to request DCVDD: %d\n", ret);
1029 goto err_early;
1030 }
1031
Mark Brown87d3af42013-03-26 12:15:26 +00001032 if (arizona->pdata.reset) {
1033 /* Start out with /RESET low to put the chip into reset */
Charles Keepax5f056bf2015-05-11 13:58:01 +01001034 ret = devm_gpio_request_one(arizona->dev, arizona->pdata.reset,
1035 GPIOF_DIR_OUT | GPIOF_INIT_LOW,
1036 "arizona /RESET");
Mark Brown87d3af42013-03-26 12:15:26 +00001037 if (ret != 0) {
1038 dev_err(dev, "Failed to request /RESET: %d\n", ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001039 goto err_dcvdd;
Mark Brown87d3af42013-03-26 12:15:26 +00001040 }
1041 }
1042
Mark Brown3cc72982012-06-19 16:31:53 +01001043 ret = regulator_bulk_enable(arizona->num_core_supplies,
1044 arizona->core_supplies);
1045 if (ret != 0) {
1046 dev_err(dev, "Failed to enable core supplies: %d\n",
1047 ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001048 goto err_dcvdd;
Mark Brown3cc72982012-06-19 16:31:53 +01001049 }
1050
Mark Brown59db9692012-07-09 00:31:36 +02001051 ret = regulator_enable(arizona->dcvdd);
1052 if (ret != 0) {
1053 dev_err(dev, "Failed to enable DCVDD: %d\n", ret);
1054 goto err_enable;
1055 }
1056
Charles Keepax22298752015-05-11 13:58:02 +01001057 arizona_disable_reset(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001058
Mark Brown3cc72982012-06-19 16:31:53 +01001059 regcache_cache_only(arizona->regmap, false);
1060
Mark Brownca76ceb2013-04-09 16:04:35 +01001061 /* Verify that this is a chip we know about */
1062 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1063 if (ret != 0) {
1064 dev_err(dev, "Failed to read ID register: %d\n", ret);
1065 goto err_reset;
1066 }
1067
1068 switch (reg) {
1069 case 0x5102:
1070 case 0x5110:
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001071 case 0x6349:
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001072 case 0x8997:
Mark Brownca76ceb2013-04-09 16:04:35 +01001073 break;
1074 default:
1075 dev_err(arizona->dev, "Unknown device ID: %x\n", reg);
1076 goto err_reset;
1077 }
1078
1079 /* If we have a /RESET GPIO we'll already be reset */
1080 if (!arizona->pdata.reset) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001081 ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0);
1082 if (ret != 0) {
1083 dev_err(dev, "Failed to reset device: %d\n", ret);
1084 goto err_reset;
1085 }
1086
1087 msleep(1);
Mark Brownca76ceb2013-04-09 16:04:35 +01001088 }
1089
1090 /* Ensure device startup is complete */
1091 switch (arizona->type) {
1092 case WM5102:
Mark Brown48018942014-08-13 11:42:46 +01001093 ret = regmap_read(arizona->regmap,
1094 ARIZONA_WRITE_SEQUENCER_CTRL_3, &val);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001095 if (ret) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001096 dev_err(dev,
1097 "Failed to check write sequencer state: %d\n",
1098 ret);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001099 } else if (val & 0x01) {
1100 ret = wm5102_clear_write_sequencer(arizona);
1101 if (ret)
1102 return ret;
Mark Brownca76ceb2013-04-09 16:04:35 +01001103 }
1104 break;
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001105 default:
1106 break;
1107 }
1108
1109 ret = arizona_wait_for_boot(arizona);
1110 if (ret) {
1111 dev_err(arizona->dev, "Device failed initial boot: %d\n", ret);
1112 goto err_reset;
Mark Brownca76ceb2013-04-09 16:04:35 +01001113 }
1114
1115 /* Read the device ID information & do device specific stuff */
Mark Brown3cc72982012-06-19 16:31:53 +01001116 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1117 if (ret != 0) {
1118 dev_err(dev, "Failed to read ID register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001119 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001120 }
1121
1122 ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION,
1123 &arizona->rev);
1124 if (ret != 0) {
1125 dev_err(dev, "Failed to read revision register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001126 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001127 }
1128 arizona->rev &= ARIZONA_DEVICE_REVISION_MASK;
1129
1130 switch (reg) {
Mark Brown863df8d2012-07-05 20:35:31 +01001131#ifdef CONFIG_MFD_WM5102
Mark Brown3cc72982012-06-19 16:31:53 +01001132 case 0x5102:
1133 type_name = "WM5102";
1134 if (arizona->type != WM5102) {
Richard Fitzgerald161ad302015-10-02 13:29:12 +01001135 dev_warn(arizona->dev, "WM5102 registered as %d\n",
1136 arizona->type);
Mark Brown3cc72982012-06-19 16:31:53 +01001137 arizona->type = WM5102;
1138 }
Mark Brown62d62b52012-12-02 11:41:46 +09001139 apply_patch = wm5102_patch;
Mark Brownc6d6bfb2013-03-26 11:14:52 +00001140 arizona->rev &= 0x7;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001141 subdevs = wm5102_devs;
1142 n_subdevs = ARRAY_SIZE(wm5102_devs);
Mark Brown3cc72982012-06-19 16:31:53 +01001143 break;
Mark Brown863df8d2012-07-05 20:35:31 +01001144#endif
Mark Browne102bef2012-07-10 12:37:58 +01001145#ifdef CONFIG_MFD_WM5110
1146 case 0x5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +00001147 switch (arizona->type) {
1148 case WM5110:
1149 type_name = "WM5110";
1150 break;
1151 case WM8280:
1152 type_name = "WM8280";
1153 break;
1154 default:
1155 type_name = "WM5110";
Richard Fitzgerald161ad302015-10-02 13:29:12 +01001156 dev_warn(arizona->dev, "WM5110 registered as %d\n",
1157 arizona->type);
Mark Browne102bef2012-07-10 12:37:58 +01001158 arizona->type = WM5110;
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +00001159 break;
Mark Browne102bef2012-07-10 12:37:58 +01001160 }
Mark Brown62d62b52012-12-02 11:41:46 +09001161 apply_patch = wm5110_patch;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001162 subdevs = wm5110_devs;
1163 n_subdevs = ARRAY_SIZE(wm5110_devs);
Mark Browne102bef2012-07-10 12:37:58 +01001164 break;
1165#endif
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001166#ifdef CONFIG_MFD_WM8997
1167 case 0x8997:
1168 type_name = "WM8997";
1169 if (arizona->type != WM8997) {
Richard Fitzgerald161ad302015-10-02 13:29:12 +01001170 dev_warn(arizona->dev, "WM8997 registered as %d\n",
1171 arizona->type);
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001172 arizona->type = WM8997;
1173 }
1174 apply_patch = wm8997_patch;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001175 subdevs = wm8997_devs;
1176 n_subdevs = ARRAY_SIZE(wm8997_devs);
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001177 break;
1178#endif
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001179#ifdef CONFIG_MFD_WM8998
1180 case 0x6349:
1181 switch (arizona->type) {
1182 case WM8998:
1183 type_name = "WM8998";
1184 break;
1185
1186 case WM1814:
1187 type_name = "WM1814";
1188 break;
1189
1190 default:
1191 type_name = "WM8998";
Richard Fitzgerald161ad302015-10-02 13:29:12 +01001192 dev_warn(arizona->dev, "WM8998 registered as %d\n",
1193 arizona->type);
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001194 arizona->type = WM8998;
1195 }
1196
1197 apply_patch = wm8998_patch;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001198 subdevs = wm8998_devs;
1199 n_subdevs = ARRAY_SIZE(wm8998_devs);
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001200 break;
1201#endif
Mark Brown3cc72982012-06-19 16:31:53 +01001202 default:
1203 dev_err(arizona->dev, "Unknown device ID %x\n", reg);
Mark Brown59db9692012-07-09 00:31:36 +02001204 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001205 }
1206
1207 dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A');
1208
Mark Brown62d62b52012-12-02 11:41:46 +09001209 if (apply_patch) {
1210 ret = apply_patch(arizona);
1211 if (ret != 0) {
1212 dev_err(arizona->dev, "Failed to apply patch: %d\n",
1213 ret);
1214 goto err_reset;
1215 }
Charles Keepaxe80436b2013-03-26 18:46:15 +00001216
1217 switch (arizona->type) {
1218 case WM5102:
Charles Keepax0be068a2015-05-11 13:58:04 +01001219 ret = wm5102_apply_hardware_patch(arizona);
1220 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +00001221 dev_err(arizona->dev,
1222 "Failed to apply hardware patch: %d\n",
1223 ret);
1224 goto err_reset;
1225 }
1226 break;
Charles Keepax882bc462015-05-11 13:58:06 +01001227 case WM5110:
1228 case WM8280:
1229 ret = wm5110_apply_sleep_patch(arizona);
1230 if (ret) {
1231 dev_err(arizona->dev,
1232 "Failed to apply sleep patch: %d\n",
1233 ret);
1234 goto err_reset;
1235 }
1236 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +00001237 default:
1238 break;
1239 }
Mark Brown62d62b52012-12-02 11:41:46 +09001240 }
1241
Mark Brown3cc72982012-06-19 16:31:53 +01001242 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
1243 if (!arizona->pdata.gpio_defaults[i])
1244 continue;
1245
1246 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i,
1247 arizona->pdata.gpio_defaults[i]);
1248 }
1249
Mark Brown3cc72982012-06-19 16:31:53 +01001250 /* Chip default */
1251 if (!arizona->pdata.clk32k_src)
1252 arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2;
1253
1254 switch (arizona->pdata.clk32k_src) {
1255 case ARIZONA_32KZ_MCLK1:
1256 case ARIZONA_32KZ_MCLK2:
1257 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1258 ARIZONA_CLK_32K_SRC_MASK,
1259 arizona->pdata.clk32k_src - 1);
Mark Brown767c6dc2013-03-19 19:04:46 +01001260 arizona_clk32k_enable(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001261 break;
1262 case ARIZONA_32KZ_NONE:
1263 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1264 ARIZONA_CLK_32K_SRC_MASK, 2);
1265 break;
1266 default:
1267 dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n",
1268 arizona->pdata.clk32k_src);
1269 ret = -EINVAL;
Mark Brown59db9692012-07-09 00:31:36 +02001270 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001271 }
1272
Mark Brown3d91f822013-01-29 00:47:37 +08001273 for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) {
Mark Brown544c7aa2013-01-29 18:44:41 +08001274 if (!arizona->pdata.micbias[i].mV &&
1275 !arizona->pdata.micbias[i].bypass)
Mark Brown3d91f822013-01-29 00:47:37 +08001276 continue;
1277
Mark Brown544c7aa2013-01-29 18:44:41 +08001278 /* Apply default for bypass mode */
1279 if (!arizona->pdata.micbias[i].mV)
1280 arizona->pdata.micbias[i].mV = 2800;
1281
Mark Brown3d91f822013-01-29 00:47:37 +08001282 val = (arizona->pdata.micbias[i].mV - 1500) / 100;
Mark Brown544c7aa2013-01-29 18:44:41 +08001283
Mark Brown3d91f822013-01-29 00:47:37 +08001284 val <<= ARIZONA_MICB1_LVL_SHIFT;
1285
1286 if (arizona->pdata.micbias[i].ext_cap)
1287 val |= ARIZONA_MICB1_EXT_CAP;
1288
1289 if (arizona->pdata.micbias[i].discharge)
1290 val |= ARIZONA_MICB1_DISCH;
1291
Charles Keepaxf773fc62013-05-21 14:56:58 +01001292 if (arizona->pdata.micbias[i].soft_start)
Mark Brown3d91f822013-01-29 00:47:37 +08001293 val |= ARIZONA_MICB1_RATE;
1294
Mark Brown544c7aa2013-01-29 18:44:41 +08001295 if (arizona->pdata.micbias[i].bypass)
1296 val |= ARIZONA_MICB1_BYPASS;
1297
Mark Brown3d91f822013-01-29 00:47:37 +08001298 regmap_update_bits(arizona->regmap,
1299 ARIZONA_MIC_BIAS_CTRL_1 + i,
1300 ARIZONA_MICB1_LVL_MASK |
Charles Keepax71d134b2014-09-24 10:37:11 +01001301 ARIZONA_MICB1_EXT_CAP |
Mark Brown3d91f822013-01-29 00:47:37 +08001302 ARIZONA_MICB1_DISCH |
Mark Brown544c7aa2013-01-29 18:44:41 +08001303 ARIZONA_MICB1_BYPASS |
Mark Brown3d91f822013-01-29 00:47:37 +08001304 ARIZONA_MICB1_RATE, val);
1305 }
1306
Mark Brown3cc72982012-06-19 16:31:53 +01001307 for (i = 0; i < ARIZONA_MAX_INPUT; i++) {
1308 /* Default for both is 0 so noop with defaults */
1309 val = arizona->pdata.dmic_ref[i]
1310 << ARIZONA_IN1_DMIC_SUP_SHIFT;
Richard Fitzgeraldfc027d12015-05-01 16:15:12 +01001311 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_DMIC)
1312 val |= 1 << ARIZONA_IN1_MODE_SHIFT;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001313
1314 switch (arizona->type) {
1315 case WM8998:
1316 case WM1814:
1317 regmap_update_bits(arizona->regmap,
1318 ARIZONA_ADC_DIGITAL_VOLUME_1L + (i * 8),
1319 ARIZONA_IN1L_SRC_SE_MASK,
1320 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1321 << ARIZONA_IN1L_SRC_SE_SHIFT);
1322
1323 regmap_update_bits(arizona->regmap,
1324 ARIZONA_ADC_DIGITAL_VOLUME_1R + (i * 8),
1325 ARIZONA_IN1R_SRC_SE_MASK,
1326 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1327 << ARIZONA_IN1R_SRC_SE_SHIFT);
1328
1329 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1330 ARIZONA_IN1_MODE_MASK;
1331 break;
1332 default:
1333 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1334 val |= 1 << ARIZONA_IN1_SINGLE_ENDED_SHIFT;
1335
1336 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1337 ARIZONA_IN1_MODE_MASK |
1338 ARIZONA_IN1_SINGLE_ENDED_MASK;
1339 break;
1340 }
Mark Brown3cc72982012-06-19 16:31:53 +01001341
1342 regmap_update_bits(arizona->regmap,
1343 ARIZONA_IN1L_CONTROL + (i * 8),
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001344 mask, val);
Mark Brown3cc72982012-06-19 16:31:53 +01001345 }
1346
1347 for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) {
1348 /* Default is 0 so noop with defaults */
1349 if (arizona->pdata.out_mono[i])
1350 val = ARIZONA_OUT1_MONO;
1351 else
1352 val = 0;
1353
1354 regmap_update_bits(arizona->regmap,
1355 ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8),
1356 ARIZONA_OUT1_MONO, val);
1357 }
1358
Mark Brown3cc72982012-06-19 16:31:53 +01001359 for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) {
1360 if (arizona->pdata.spk_mute[i])
1361 regmap_update_bits(arizona->regmap,
Mark Brown2a51da02012-07-09 19:33:14 +01001362 ARIZONA_PDM_SPK1_CTRL_1 + (i * 2),
Mark Brown3cc72982012-06-19 16:31:53 +01001363 ARIZONA_SPK1_MUTE_ENDIAN_MASK |
1364 ARIZONA_SPK1_MUTE_SEQ1_MASK,
1365 arizona->pdata.spk_mute[i]);
1366
1367 if (arizona->pdata.spk_fmt[i])
1368 regmap_update_bits(arizona->regmap,
Mark Brown2a51da02012-07-09 19:33:14 +01001369 ARIZONA_PDM_SPK1_CTRL_2 + (i * 2),
Mark Brown3cc72982012-06-19 16:31:53 +01001370 ARIZONA_SPK1_FMT_MASK,
1371 arizona->pdata.spk_fmt[i]);
1372 }
1373
Charles Keepax72e43162015-06-14 15:41:50 +01001374 pm_runtime_set_active(arizona->dev);
1375 pm_runtime_enable(arizona->dev);
1376
Mark Brown3cc72982012-06-19 16:31:53 +01001377 /* Set up for interrupts */
1378 ret = arizona_irq_init(arizona);
1379 if (ret != 0)
Mark Brown59db9692012-07-09 00:31:36 +02001380 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001381
Charles Keepax72e43162015-06-14 15:41:50 +01001382 pm_runtime_set_autosuspend_delay(arizona->dev, 100);
1383 pm_runtime_use_autosuspend(arizona->dev);
1384
Mark Brown3cc72982012-06-19 16:31:53 +01001385 arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error",
1386 arizona_clkgen_err, arizona);
1387 arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked",
1388 arizona_overclocked, arizona);
1389 arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked",
1390 arizona_underclocked, arizona);
1391
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001392 ret = mfd_add_devices(arizona->dev, PLATFORM_DEVID_NONE,
1393 subdevs, n_subdevs, NULL, 0, NULL);
Mark Brown3cc72982012-06-19 16:31:53 +01001394
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001395 if (ret) {
Mark Brown3cc72982012-06-19 16:31:53 +01001396 dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret);
1397 goto err_irq;
1398 }
1399
1400 return 0;
1401
1402err_irq:
1403 arizona_irq_exit(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001404err_reset:
Charles Keepax22298752015-05-11 13:58:02 +01001405 arizona_enable_reset(arizona);
Mark Brown59db9692012-07-09 00:31:36 +02001406 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001407err_enable:
Mark Brown3a36a0db2012-07-09 00:45:53 +02001408 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown3cc72982012-06-19 16:31:53 +01001409 arizona->core_supplies);
Charles Keepaxe6021512014-06-02 09:50:41 +01001410err_dcvdd:
1411 regulator_put(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001412err_early:
1413 mfd_remove_devices(dev);
1414 return ret;
1415}
1416EXPORT_SYMBOL_GPL(arizona_dev_init);
1417
Bill Pemberton4740f732012-11-19 13:26:01 -05001418int arizona_dev_exit(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +01001419{
Charles Keepaxb8040202014-06-02 09:50:39 +01001420 pm_runtime_disable(arizona->dev);
1421
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001422 regulator_disable(arizona->dcvdd);
Charles Keepaxe6021512014-06-02 09:50:41 +01001423 regulator_put(arizona->dcvdd);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001424
Mark Brown3cc72982012-06-19 16:31:53 +01001425 mfd_remove_devices(arizona->dev);
1426 arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona);
1427 arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona);
1428 arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001429 arizona_irq_exit(arizona);
Charles Keepax22298752015-05-11 13:58:02 +01001430 arizona_enable_reset(arizona);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001431
Charles Keepax44202862014-06-02 09:50:42 +01001432 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown1d017b62013-03-26 12:16:26 +00001433 arizona->core_supplies);
Mark Brown3cc72982012-06-19 16:31:53 +01001434 return 0;
1435}
1436EXPORT_SYMBOL_GPL(arizona_dev_exit);