blob: 77875250abe590bb73ba2b52ba3c38c444552579 [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
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +010013#include <linux/clk.h>
Mark Brown3cc72982012-06-19 16:31:53 +010014#include <linux/delay.h>
Mark Brown59db9692012-07-09 00:31:36 +020015#include <linux/err.h>
Mark Brown3cc72982012-06-19 16:31:53 +010016#include <linux/gpio.h>
17#include <linux/interrupt.h>
18#include <linux/mfd/core.h>
19#include <linux/module.h>
Mark Brownd7810092013-03-25 00:11:27 +000020#include <linux/of.h>
21#include <linux/of_device.h>
22#include <linux/of_gpio.h>
Mark Brown3cc72982012-06-19 16:31:53 +010023#include <linux/pm_runtime.h>
24#include <linux/regmap.h>
25#include <linux/regulator/consumer.h>
Mark Brown59274672013-04-23 19:44:16 +010026#include <linux/regulator/machine.h>
Mark Brown3cc72982012-06-19 16:31:53 +010027#include <linux/slab.h>
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +010028#include <linux/platform_device.h>
Mark Brown3cc72982012-06-19 16:31:53 +010029
30#include <linux/mfd/arizona/core.h>
31#include <linux/mfd/arizona/registers.h>
32
33#include "arizona.h"
34
Charles Keepax3762aed2015-08-11 09:34:31 +010035static const char * const wm5102_core_supplies[] = {
Mark Brown3cc72982012-06-19 16:31:53 +010036 "AVDD",
37 "DBVDD1",
Mark Brown3cc72982012-06-19 16:31:53 +010038};
39
40int arizona_clk32k_enable(struct arizona *arizona)
41{
42 int ret = 0;
43
44 mutex_lock(&arizona->clk_lock);
45
46 arizona->clk32k_ref++;
47
Mark Brown247fa192013-03-19 14:47:47 +010048 if (arizona->clk32k_ref == 1) {
49 switch (arizona->pdata.clk32k_src) {
50 case ARIZONA_32KZ_MCLK1:
51 ret = pm_runtime_get_sync(arizona->dev);
52 if (ret != 0)
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +010053 goto err_ref;
54 ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK1]);
55 if (ret != 0)
56 goto err_pm;
57 break;
58 case ARIZONA_32KZ_MCLK2:
59 ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK2]);
60 if (ret != 0)
61 goto err_ref;
Mark Brown247fa192013-03-19 14:47:47 +010062 break;
63 }
64
Mark Brown3cc72982012-06-19 16:31:53 +010065 ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
66 ARIZONA_CLK_32K_ENA,
67 ARIZONA_CLK_32K_ENA);
Mark Brown247fa192013-03-19 14:47:47 +010068 }
Mark Brown3cc72982012-06-19 16:31:53 +010069
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +010070err_pm:
71 pm_runtime_put_sync(arizona->dev);
72err_ref:
Mark Brown3cc72982012-06-19 16:31:53 +010073 if (ret != 0)
74 arizona->clk32k_ref--;
75
76 mutex_unlock(&arizona->clk_lock);
77
78 return ret;
79}
80EXPORT_SYMBOL_GPL(arizona_clk32k_enable);
81
82int arizona_clk32k_disable(struct arizona *arizona)
83{
Mark Brown3cc72982012-06-19 16:31:53 +010084 mutex_lock(&arizona->clk_lock);
85
86 BUG_ON(arizona->clk32k_ref <= 0);
87
88 arizona->clk32k_ref--;
89
Mark Brown247fa192013-03-19 14:47:47 +010090 if (arizona->clk32k_ref == 0) {
Mark Brown3cc72982012-06-19 16:31:53 +010091 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
92 ARIZONA_CLK_32K_ENA, 0);
93
Mark Brown247fa192013-03-19 14:47:47 +010094 switch (arizona->pdata.clk32k_src) {
95 case ARIZONA_32KZ_MCLK1:
96 pm_runtime_put_sync(arizona->dev);
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +010097 clk_disable_unprepare(arizona->mclk[ARIZONA_MCLK1]);
98 break;
99 case ARIZONA_32KZ_MCLK2:
100 clk_disable_unprepare(arizona->mclk[ARIZONA_MCLK2]);
Mark Brown247fa192013-03-19 14:47:47 +0100101 break;
102 }
103 }
104
Mark Brown3cc72982012-06-19 16:31:53 +0100105 mutex_unlock(&arizona->clk_lock);
106
Javier Martinez Canillasa260fba2015-09-29 13:26:02 +0200107 return 0;
Mark Brown3cc72982012-06-19 16:31:53 +0100108}
109EXPORT_SYMBOL_GPL(arizona_clk32k_disable);
110
111static irqreturn_t arizona_clkgen_err(int irq, void *data)
112{
113 struct arizona *arizona = data;
114
115 dev_err(arizona->dev, "CLKGEN error\n");
116
117 return IRQ_HANDLED;
118}
119
120static irqreturn_t arizona_underclocked(int irq, void *data)
121{
122 struct arizona *arizona = data;
123 unsigned int val;
124 int ret;
125
126 ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8,
127 &val);
128 if (ret != 0) {
129 dev_err(arizona->dev, "Failed to read underclock status: %d\n",
130 ret);
131 return IRQ_NONE;
132 }
133
134 if (val & ARIZONA_AIF3_UNDERCLOCKED_STS)
135 dev_err(arizona->dev, "AIF3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100136 if (val & ARIZONA_AIF2_UNDERCLOCKED_STS)
Charles Keepax3ebef342012-11-20 13:46:20 +0900137 dev_err(arizona->dev, "AIF2 underclocked\n");
138 if (val & ARIZONA_AIF1_UNDERCLOCKED_STS)
Mark Brown3cc72982012-06-19 16:31:53 +0100139 dev_err(arizona->dev, "AIF1 underclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100140 if (val & ARIZONA_ISRC3_UNDERCLOCKED_STS)
141 dev_err(arizona->dev, "ISRC3 underclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100142 if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS)
143 dev_err(arizona->dev, "ISRC2 underclocked\n");
144 if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS)
145 dev_err(arizona->dev, "ISRC1 underclocked\n");
146 if (val & ARIZONA_FX_UNDERCLOCKED_STS)
147 dev_err(arizona->dev, "FX underclocked\n");
148 if (val & ARIZONA_ASRC_UNDERCLOCKED_STS)
149 dev_err(arizona->dev, "ASRC underclocked\n");
150 if (val & ARIZONA_DAC_UNDERCLOCKED_STS)
151 dev_err(arizona->dev, "DAC underclocked\n");
152 if (val & ARIZONA_ADC_UNDERCLOCKED_STS)
153 dev_err(arizona->dev, "ADC underclocked\n");
154 if (val & ARIZONA_MIXER_UNDERCLOCKED_STS)
Mark Brown648a9882013-01-28 00:32:53 +0800155 dev_err(arizona->dev, "Mixer dropped sample\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100156
157 return IRQ_HANDLED;
158}
159
160static irqreturn_t arizona_overclocked(int irq, void *data)
161{
162 struct arizona *arizona = data;
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100163 unsigned int val[3];
Mark Brown3cc72982012-06-19 16:31:53 +0100164 int ret;
Charles Keepax3762aed2015-08-11 09:34:31 +0100165
Mark Brown3cc72982012-06-19 16:31:53 +0100166 ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6,
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100167 &val[0], 3);
Mark Brown3cc72982012-06-19 16:31:53 +0100168 if (ret != 0) {
169 dev_err(arizona->dev, "Failed to read overclock status: %d\n",
170 ret);
171 return IRQ_NONE;
172 }
173
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100174 switch (arizona->type) {
175 case WM8998:
176 case WM1814:
177 /* Some bits are shifted on WM8998,
178 * rearrange to match the standard bit layout
179 */
180 val[0] = ((val[0] & 0x60e0) >> 1) |
181 ((val[0] & 0x1e00) >> 2) |
182 (val[0] & 0x000f);
183 break;
184 default:
185 break;
186 }
187
Mark Brown3cc72982012-06-19 16:31:53 +0100188 if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS)
189 dev_err(arizona->dev, "PWM overclocked\n");
190 if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS)
191 dev_err(arizona->dev, "FX core overclocked\n");
192 if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS)
193 dev_err(arizona->dev, "DAC SYS overclocked\n");
194 if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS)
195 dev_err(arizona->dev, "DAC WARP overclocked\n");
196 if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS)
197 dev_err(arizona->dev, "ADC overclocked\n");
198 if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS)
199 dev_err(arizona->dev, "Mixer overclocked\n");
200 if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS)
201 dev_err(arizona->dev, "AIF3 overclocked\n");
202 if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS)
203 dev_err(arizona->dev, "AIF2 overclocked\n");
204 if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS)
205 dev_err(arizona->dev, "AIF1 overclocked\n");
206 if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS)
207 dev_err(arizona->dev, "Pad control overclocked\n");
208
209 if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS)
210 dev_err(arizona->dev, "Slimbus subsystem overclocked\n");
211 if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS)
212 dev_err(arizona->dev, "Slimbus async overclocked\n");
213 if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS)
214 dev_err(arizona->dev, "Slimbus sync overclocked\n");
215 if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS)
216 dev_err(arizona->dev, "ASRC async system overclocked\n");
217 if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS)
218 dev_err(arizona->dev, "ASRC async WARP overclocked\n");
219 if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS)
220 dev_err(arizona->dev, "ASRC sync system overclocked\n");
221 if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS)
222 dev_err(arizona->dev, "ASRC sync WARP overclocked\n");
223 if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS)
224 dev_err(arizona->dev, "DSP1 overclocked\n");
Charles Keepax6e440d22014-07-15 11:21:49 +0100225 if (val[1] & ARIZONA_ISRC3_OVERCLOCKED_STS)
226 dev_err(arizona->dev, "ISRC3 overclocked\n");
Mark Brown3cc72982012-06-19 16:31:53 +0100227 if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS)
228 dev_err(arizona->dev, "ISRC2 overclocked\n");
229 if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS)
230 dev_err(arizona->dev, "ISRC1 overclocked\n");
231
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100232 if (val[2] & ARIZONA_SPDIF_OVERCLOCKED_STS)
233 dev_err(arizona->dev, "SPDIF overclocked\n");
234
Mark Brown3cc72982012-06-19 16:31:53 +0100235 return IRQ_HANDLED;
236}
237
Charles Keepaxef84f882017-03-15 14:58:38 +0000238#define ARIZONA_REG_POLL_DELAY_US 7500
239
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000240static int arizona_poll_reg(struct arizona *arizona,
Charles Keepaxef84f882017-03-15 14:58:38 +0000241 int timeout_ms, unsigned int reg,
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000242 unsigned int mask, unsigned int target)
243{
244 unsigned int val = 0;
Charles Keepaxef84f882017-03-15 14:58:38 +0000245 int ret;
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000246
Charles Keepaxef84f882017-03-15 14:58:38 +0000247 ret = regmap_read_poll_timeout(arizona->regmap,
Charles Keepax27fef9f2017-06-06 09:46:33 +0100248 reg, val, ((val & mask) == target),
Charles Keepaxef84f882017-03-15 14:58:38 +0000249 ARIZONA_REG_POLL_DELAY_US,
250 timeout_ms * 1000);
251 if (ret)
252 dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n",
253 reg, val);
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000254
Charles Keepaxef84f882017-03-15 14:58:38 +0000255 return ret;
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000256}
257
Mark Brown3cc72982012-06-19 16:31:53 +0100258static int arizona_wait_for_boot(struct arizona *arizona)
259{
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000260 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100261
262 /*
263 * We can't use an interrupt as we need to runtime resume to do so,
264 * we won't race with the interrupt handler as it'll be blocked on
265 * runtime resume.
266 */
Charles Keepaxef84f882017-03-15 14:58:38 +0000267 ret = arizona_poll_reg(arizona, 30, ARIZONA_INTERRUPT_RAW_STATUS_5,
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000268 ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100269
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000270 if (!ret)
Mark Brown3cc72982012-06-19 16:31:53 +0100271 regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
272 ARIZONA_BOOT_DONE_STS);
Mark Brown3cc72982012-06-19 16:31:53 +0100273
274 pm_runtime_mark_last_busy(arizona->dev);
275
Charles Keepax9d53dfd2013-03-26 17:38:45 +0000276 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100277}
278
Charles Keepax22298752015-05-11 13:58:02 +0100279static inline void arizona_enable_reset(struct arizona *arizona)
280{
281 if (arizona->pdata.reset)
282 gpio_set_value_cansleep(arizona->pdata.reset, 0);
283}
284
285static void arizona_disable_reset(struct arizona *arizona)
286{
287 if (arizona->pdata.reset) {
Charles Keepax121c0752015-05-11 13:58:10 +0100288 switch (arizona->type) {
289 case WM5110:
290 case WM8280:
291 /* Meet requirements for minimum reset duration */
Lee Jonesb79a9802015-10-28 12:42:30 +0000292 usleep_range(5000, 10000);
Charles Keepax121c0752015-05-11 13:58:10 +0100293 break;
294 default:
295 break;
296 }
297
Charles Keepax22298752015-05-11 13:58:02 +0100298 gpio_set_value_cansleep(arizona->pdata.reset, 1);
Lee Jonesb79a9802015-10-28 12:42:30 +0000299 usleep_range(1000, 5000);
Charles Keepax22298752015-05-11 13:58:02 +0100300 }
301}
302
Charles Keepax3850e3e2015-05-11 13:58:05 +0100303struct arizona_sysclk_state {
304 unsigned int fll;
305 unsigned int sysclk;
306};
307
308static int arizona_enable_freerun_sysclk(struct arizona *arizona,
309 struct arizona_sysclk_state *state)
Charles Keepaxe80436b2013-03-26 18:46:15 +0000310{
Charles Keepaxe80436b2013-03-26 18:46:15 +0000311 int ret, err;
312
Charles Keepaxe80436b2013-03-26 18:46:15 +0000313 /* Cache existing FLL and SYSCLK settings */
Charles Keepax3850e3e2015-05-11 13:58:05 +0100314 ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll);
Charles Keepax0be068a2015-05-11 13:58:04 +0100315 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000316 dev_err(arizona->dev, "Failed to cache FLL settings: %d\n",
317 ret);
318 return ret;
319 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100320 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
321 &state->sysclk);
Charles Keepax0be068a2015-05-11 13:58:04 +0100322 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000323 dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
324 ret);
325 return ret;
326 }
327
328 /* Start up SYSCLK using the FLL in free running mode */
329 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1,
330 ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN);
Charles Keepax0be068a2015-05-11 13:58:04 +0100331 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000332 dev_err(arizona->dev,
333 "Failed to start FLL in freerunning mode: %d\n",
334 ret);
335 return ret;
336 }
Charles Keepaxef84f882017-03-15 14:58:38 +0000337 ret = arizona_poll_reg(arizona, 180, ARIZONA_INTERRUPT_RAW_STATUS_5,
Charles Keepaxe80436b2013-03-26 18:46:15 +0000338 ARIZONA_FLL1_CLOCK_OK_STS,
339 ARIZONA_FLL1_CLOCK_OK_STS);
Charles Keepaxde4ea102017-03-15 14:58:36 +0000340 if (ret)
Charles Keepaxe80436b2013-03-26 18:46:15 +0000341 goto err_fll;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000342
343 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
Charles Keepax0be068a2015-05-11 13:58:04 +0100344 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000345 dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
346 goto err_fll;
347 }
348
Charles Keepax3850e3e2015-05-11 13:58:05 +0100349 return 0;
350
351err_fll:
352 err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
353 if (err)
354 dev_err(arizona->dev,
355 "Failed to re-apply old FLL settings: %d\n", err);
356
357 return ret;
358}
359
360static int arizona_disable_freerun_sysclk(struct arizona *arizona,
361 struct arizona_sysclk_state *state)
362{
363 int ret;
364
365 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
366 state->sysclk);
367 if (ret) {
368 dev_err(arizona->dev,
369 "Failed to re-apply old SYSCLK settings: %d\n", ret);
370 return ret;
371 }
372
373 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
374 if (ret) {
375 dev_err(arizona->dev,
376 "Failed to re-apply old FLL settings: %d\n", ret);
377 return ret;
378 }
379
380 return 0;
381}
382
383static int wm5102_apply_hardware_patch(struct arizona *arizona)
384{
385 struct arizona_sysclk_state state;
386 int err, ret;
387
388 ret = arizona_enable_freerun_sysclk(arizona, &state);
389 if (ret)
390 return ret;
391
Charles Keepaxe80436b2013-03-26 18:46:15 +0000392 /* Start the write sequencer and wait for it to finish */
393 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100394 ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160);
395 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000396 dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
397 ret);
Charles Keepax3850e3e2015-05-11 13:58:05 +0100398 goto err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000399 }
Charles Keepax3850e3e2015-05-11 13:58:05 +0100400
Charles Keepaxef84f882017-03-15 14:58:38 +0000401 ret = arizona_poll_reg(arizona, 30, ARIZONA_WRITE_SEQUENCER_CTRL_1,
Charles Keepaxe80436b2013-03-26 18:46:15 +0000402 ARIZONA_WSEQ_BUSY, 0);
Charles Keepaxde4ea102017-03-15 14:58:36 +0000403 if (ret)
Charles Keepaxe80436b2013-03-26 18:46:15 +0000404 regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
Charles Keepax0be068a2015-05-11 13:58:04 +0100405 ARIZONA_WSEQ_ABORT);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000406
Charles Keepax3850e3e2015-05-11 13:58:05 +0100407err:
408 err = arizona_disable_freerun_sysclk(arizona, &state);
Charles Keepaxe80436b2013-03-26 18:46:15 +0000409
Charles Keepax0be068a2015-05-11 13:58:04 +0100410 return ret ?: err;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000411}
412
Charles Keepax882bc462015-05-11 13:58:06 +0100413/*
414 * Register patch to some of the CODECs internal write sequences
415 * to ensure a clean exit from the low power sleep state.
416 */
Nariman Poushin8019ff62015-07-16 16:36:21 +0100417static const struct reg_sequence wm5110_sleep_patch[] = {
Charles Keepax882bc462015-05-11 13:58:06 +0100418 { 0x337A, 0xC100 },
419 { 0x337B, 0x0041 },
420 { 0x3300, 0xA210 },
421 { 0x3301, 0x050C },
422};
423
424static int wm5110_apply_sleep_patch(struct arizona *arizona)
425{
426 struct arizona_sysclk_state state;
427 int err, ret;
428
429 ret = arizona_enable_freerun_sysclk(arizona, &state);
430 if (ret)
431 return ret;
432
433 ret = regmap_multi_reg_write_bypassed(arizona->regmap,
434 wm5110_sleep_patch,
435 ARRAY_SIZE(wm5110_sleep_patch));
436
437 err = arizona_disable_freerun_sysclk(arizona, &state);
438
439 return ret ?: err;
440}
441
Charles Keepax1c1c6bb2015-05-11 13:58:03 +0100442static int wm5102_clear_write_sequencer(struct arizona *arizona)
443{
444 int ret;
445
446 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_3,
447 0x0);
448 if (ret) {
449 dev_err(arizona->dev,
450 "Failed to clear write sequencer state: %d\n", ret);
451 return ret;
452 }
453
454 arizona_enable_reset(arizona);
455 regulator_disable(arizona->dcvdd);
456
457 msleep(20);
458
459 ret = regulator_enable(arizona->dcvdd);
460 if (ret) {
461 dev_err(arizona->dev, "Failed to re-enable DCVDD: %d\n", ret);
462 return ret;
463 }
464 arizona_disable_reset(arizona);
465
466 return 0;
467}
468
Rafael J. Wysocki48bb9fe2014-12-05 03:04:12 +0100469#ifdef CONFIG_PM
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100470static int arizona_isolate_dcvdd(struct arizona *arizona)
471{
472 int ret;
473
474 ret = regmap_update_bits(arizona->regmap,
475 ARIZONA_ISOLATION_CONTROL,
476 ARIZONA_ISOLATE_DCVDD1,
477 ARIZONA_ISOLATE_DCVDD1);
478 if (ret != 0)
479 dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n", ret);
480
481 return ret;
482}
483
484static int arizona_connect_dcvdd(struct arizona *arizona)
485{
486 int ret;
487
488 ret = regmap_update_bits(arizona->regmap,
489 ARIZONA_ISOLATION_CONTROL,
490 ARIZONA_ISOLATE_DCVDD1, 0);
491 if (ret != 0)
492 dev_err(arizona->dev, "Failed to connect DCVDD: %d\n", ret);
493
494 return ret;
495}
496
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100497static int arizona_is_jack_det_active(struct arizona *arizona)
498{
499 unsigned int val;
500 int ret;
501
502 ret = regmap_read(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, &val);
503 if (ret) {
504 dev_err(arizona->dev,
505 "Failed to check jack det status: %d\n", ret);
506 return ret;
507 } else if (val & ARIZONA_JD1_ENA) {
508 return 1;
509 } else {
510 return 0;
511 }
512}
513
Mark Brown3cc72982012-06-19 16:31:53 +0100514static int arizona_runtime_resume(struct device *dev)
515{
516 struct arizona *arizona = dev_get_drvdata(dev);
517 int ret;
518
Mark Brown508c8292012-07-20 17:09:12 +0100519 dev_dbg(arizona->dev, "Leaving AoD mode\n");
520
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100521 if (arizona->has_fully_powered_off) {
522 dev_dbg(arizona->dev, "Re-enabling core supplies\n");
523
524 ret = regulator_bulk_enable(arizona->num_core_supplies,
525 arizona->core_supplies);
526 if (ret) {
527 dev_err(dev, "Failed to enable core supplies: %d\n",
528 ret);
529 return ret;
530 }
531 }
532
Mark Brown59db9692012-07-09 00:31:36 +0200533 ret = regulator_enable(arizona->dcvdd);
534 if (ret != 0) {
535 dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100536 if (arizona->has_fully_powered_off)
537 regulator_bulk_disable(arizona->num_core_supplies,
538 arizona->core_supplies);
Mark Brown59db9692012-07-09 00:31:36 +0200539 return ret;
540 }
Mark Brown3cc72982012-06-19 16:31:53 +0100541
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100542 if (arizona->has_fully_powered_off) {
543 arizona_disable_reset(arizona);
544 enable_irq(arizona->irq);
545 arizona->has_fully_powered_off = false;
546 }
547
Mark Brown3cc72982012-06-19 16:31:53 +0100548 regcache_cache_only(arizona->regmap, false);
549
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000550 switch (arizona->type) {
551 case WM5102:
Mark Brown59274672013-04-23 19:44:16 +0100552 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100553 ret = arizona_connect_dcvdd(arizona);
554 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100555 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100556 }
557
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000558 ret = wm5102_patch(arizona);
559 if (ret != 0) {
560 dev_err(arizona->dev, "Failed to apply patch: %d\n",
561 ret);
562 goto err;
563 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000564
Charles Keepax0be068a2015-05-11 13:58:04 +0100565 ret = wm5102_apply_hardware_patch(arizona);
566 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +0000567 dev_err(arizona->dev,
568 "Failed to apply hardware patch: %d\n",
569 ret);
570 goto err;
571 }
572 break;
Charles Keepax96129a02015-05-11 13:58:08 +0100573 case WM5110:
574 case WM8280:
575 ret = arizona_wait_for_boot(arizona);
576 if (ret)
577 goto err;
578
579 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100580 ret = arizona_connect_dcvdd(arizona);
581 if (ret != 0)
Charles Keepax96129a02015-05-11 13:58:08 +0100582 goto err;
Charles Keepax96129a02015-05-11 13:58:08 +0100583 } else {
584 /*
585 * As this is only called for the internal regulator
586 * (where we know voltage ranges available) it is ok
587 * to request an exact range.
588 */
589 ret = regulator_set_voltage(arizona->dcvdd,
590 1200000, 1200000);
591 if (ret < 0) {
592 dev_err(arizona->dev,
593 "Failed to set resume voltage: %d\n",
594 ret);
595 goto err;
596 }
597 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100598
599 ret = wm5110_apply_sleep_patch(arizona);
600 if (ret) {
601 dev_err(arizona->dev,
602 "Failed to re-apply sleep patch: %d\n",
603 ret);
604 goto err;
605 }
Charles Keepax96129a02015-05-11 13:58:08 +0100606 break;
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +0000607 case WM1831:
608 case CS47L24:
609 ret = arizona_wait_for_boot(arizona);
610 if (ret != 0)
611 goto err;
612 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +0000613 default:
Charles Keepax12bb68e2013-03-27 09:49:40 +0000614 ret = arizona_wait_for_boot(arizona);
Charles Keepax3762aed2015-08-11 09:34:31 +0100615 if (ret != 0)
Charles Keepax12bb68e2013-03-27 09:49:40 +0000616 goto err;
Charles Keepax12bb68e2013-03-27 09:49:40 +0000617
Mark Brown59274672013-04-23 19:44:16 +0100618 if (arizona->external_dcvdd) {
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100619 ret = arizona_connect_dcvdd(arizona);
620 if (ret != 0)
Mark Brown59274672013-04-23 19:44:16 +0100621 goto err;
Mark Brown59274672013-04-23 19:44:16 +0100622 }
Charles Keepaxe80436b2013-03-26 18:46:15 +0000623 break;
Charles Keepax4c9bb8b2013-03-26 18:01:49 +0000624 }
625
Mark Brown9270bdf2013-01-04 17:16:12 +0000626 ret = regcache_sync(arizona->regmap);
627 if (ret != 0) {
628 dev_err(arizona->dev, "Failed to restore register cache\n");
Mark Brown4816bd12013-01-14 15:50:38 +0900629 goto err;
Mark Brown9270bdf2013-01-04 17:16:12 +0000630 }
Mark Brown3cc72982012-06-19 16:31:53 +0100631
632 return 0;
Mark Brown4816bd12013-01-14 15:50:38 +0900633
634err:
635 regcache_cache_only(arizona->regmap, true);
636 regulator_disable(arizona->dcvdd);
637 return ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100638}
639
640static int arizona_runtime_suspend(struct device *dev)
641{
642 struct arizona *arizona = dev_get_drvdata(dev);
Dan Carpentera05950a2015-10-19 13:18:05 +0300643 int jd_active = 0;
Mark Brown59274672013-04-23 19:44:16 +0100644 int ret;
Mark Brown3cc72982012-06-19 16:31:53 +0100645
Mark Brown508c8292012-07-20 17:09:12 +0100646 dev_dbg(arizona->dev, "Entering AoD mode\n");
647
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100648 switch (arizona->type) {
649 case WM5110:
650 case WM8280:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100651 jd_active = arizona_is_jack_det_active(arizona);
652 if (jd_active < 0)
653 return jd_active;
654
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100655 if (arizona->external_dcvdd) {
656 ret = arizona_isolate_dcvdd(arizona);
657 if (ret != 0)
658 return ret;
659 } else {
660 /*
661 * As this is only called for the internal regulator
662 * (where we know voltage ranges available) it is ok
663 * to request an exact range.
664 */
665 ret = regulator_set_voltage(arizona->dcvdd,
666 1175000, 1175000);
667 if (ret < 0) {
668 dev_err(arizona->dev,
669 "Failed to set suspend voltage: %d\n",
670 ret);
671 return ret;
672 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100673 }
674 break;
675 case WM5102:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100676 jd_active = arizona_is_jack_det_active(arizona);
677 if (jd_active < 0)
678 return jd_active;
679
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100680 if (arizona->external_dcvdd) {
681 ret = arizona_isolate_dcvdd(arizona);
682 if (ret != 0)
683 return ret;
684 }
685
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100686 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100687 ret = regmap_write(arizona->regmap,
688 ARIZONA_WRITE_SEQUENCER_CTRL_3, 0x0);
689 if (ret) {
Charles Keepax96129a02015-05-11 13:58:08 +0100690 dev_err(arizona->dev,
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100691 "Failed to clear write sequencer: %d\n",
Charles Keepax96129a02015-05-11 13:58:08 +0100692 ret);
693 return ret;
694 }
Charles Keepax96129a02015-05-11 13:58:08 +0100695 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100696 break;
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +0000697 case WM1831:
698 case CS47L24:
699 break;
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100700 default:
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100701 jd_active = arizona_is_jack_det_active(arizona);
702 if (jd_active < 0)
703 return jd_active;
704
Richard Fitzgeralde7811142015-10-02 13:29:10 +0100705 if (arizona->external_dcvdd) {
706 ret = arizona_isolate_dcvdd(arizona);
707 if (ret != 0)
708 return ret;
709 }
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100710 break;
Mark Brown59274672013-04-23 19:44:16 +0100711 }
712
Mark Brown59db9692012-07-09 00:31:36 +0200713 regcache_cache_only(arizona->regmap, true);
714 regcache_mark_dirty(arizona->regmap);
Charles Keepaxe293e84722013-08-06 17:18:35 +0100715 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +0100716
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100717 /* Allow us to completely power down if no jack detection */
Richard Fitzgeralde3424272015-10-02 13:29:11 +0100718 if (!jd_active) {
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100719 dev_dbg(arizona->dev, "Fully powering off\n");
720
721 arizona->has_fully_powered_off = true;
722
Charles Keepax11150922015-06-14 15:41:49 +0100723 disable_irq_nosync(arizona->irq);
Charles Keepaxe6cb7342015-05-11 13:58:09 +0100724 arizona_enable_reset(arizona);
725 regulator_bulk_disable(arizona->num_core_supplies,
726 arizona->core_supplies);
727 }
728
Mark Brown3cc72982012-06-19 16:31:53 +0100729 return 0;
730}
731#endif
732
Mark Browndc781d02013-01-27 12:07:32 +0800733#ifdef CONFIG_PM_SLEEP
Mark Brown67c99292013-04-10 12:40:26 +0100734static int arizona_suspend(struct device *dev)
735{
736 struct arizona *arizona = dev_get_drvdata(dev);
737
738 dev_dbg(arizona->dev, "Suspend, disabling IRQ\n");
739 disable_irq(arizona->irq);
740
741 return 0;
742}
743
Charles Keepax3612b272016-08-30 10:33:10 +0100744static int arizona_suspend_noirq(struct device *dev)
Mark Brown67c99292013-04-10 12:40:26 +0100745{
746 struct arizona *arizona = dev_get_drvdata(dev);
747
748 dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n");
749 enable_irq(arizona->irq);
750
751 return 0;
752}
753
Mark Browndc781d02013-01-27 12:07:32 +0800754static int arizona_resume_noirq(struct device *dev)
755{
756 struct arizona *arizona = dev_get_drvdata(dev);
757
758 dev_dbg(arizona->dev, "Early resume, disabling IRQ\n");
759 disable_irq(arizona->irq);
760
761 return 0;
762}
763
764static int arizona_resume(struct device *dev)
765{
766 struct arizona *arizona = dev_get_drvdata(dev);
767
Charles Keepax3612b272016-08-30 10:33:10 +0100768 dev_dbg(arizona->dev, "Resume, reenabling IRQ\n");
Mark Browndc781d02013-01-27 12:07:32 +0800769 enable_irq(arizona->irq);
770
771 return 0;
772}
773#endif
774
Mark Brown3cc72982012-06-19 16:31:53 +0100775const struct dev_pm_ops arizona_pm_ops = {
776 SET_RUNTIME_PM_OPS(arizona_runtime_suspend,
777 arizona_runtime_resume,
778 NULL)
Mark Brown67c99292013-04-10 12:40:26 +0100779 SET_SYSTEM_SLEEP_PM_OPS(arizona_suspend, arizona_resume)
Charles Keepax3612b272016-08-30 10:33:10 +0100780 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(arizona_suspend_noirq,
781 arizona_resume_noirq)
Mark Brown3cc72982012-06-19 16:31:53 +0100782};
783EXPORT_SYMBOL_GPL(arizona_pm_ops);
784
Mark Brownd7810092013-03-25 00:11:27 +0000785#ifdef CONFIG_OF
Lee Jones942786e2014-07-02 14:28:46 +0100786unsigned long arizona_of_get_type(struct device *dev)
Mark Brownd7810092013-03-25 00:11:27 +0000787{
788 const struct of_device_id *id = of_match_device(arizona_of_match, dev);
789
790 if (id)
Lee Jones942786e2014-07-02 14:28:46 +0100791 return (unsigned long)id->data;
Mark Brownd7810092013-03-25 00:11:27 +0000792 else
793 return 0;
794}
795EXPORT_SYMBOL_GPL(arizona_of_get_type);
796
797static int arizona_of_get_core_pdata(struct arizona *arizona)
798{
Charles Keepaxe4fcb1d2014-04-16 10:01:37 +0100799 struct arizona_pdata *pdata = &arizona->pdata;
Mark Brownd7810092013-03-25 00:11:27 +0000800 int ret, i;
801
Charles Keepax1961531d2016-09-20 16:30:13 +0100802 pdata->reset = of_get_named_gpio(arizona->dev->of_node, "wlf,reset", 0);
Charles Keepaxb8d336e2016-09-20 16:30:14 +0100803 if (pdata->reset == -EPROBE_DEFER) {
804 return pdata->reset;
805 } else if (pdata->reset < 0) {
Charles Keepax1961531d2016-09-20 16:30:13 +0100806 dev_err(arizona->dev, "Reset GPIO missing/malformed: %d\n",
807 pdata->reset);
808
809 pdata->reset = 0;
810 }
Mark Brownd7810092013-03-25 00:11:27 +0000811
812 ret = of_property_read_u32_array(arizona->dev->of_node,
813 "wlf,gpio-defaults",
Charles Keepax3762aed2015-08-11 09:34:31 +0100814 pdata->gpio_defaults,
815 ARRAY_SIZE(pdata->gpio_defaults));
Mark Brownd7810092013-03-25 00:11:27 +0000816 if (ret >= 0) {
817 /*
818 * All values are literal except out of range values
819 * which are chip default, translate into platform
820 * data which uses 0 as chip default and out of range
821 * as zero.
822 */
Charles Keepax3762aed2015-08-11 09:34:31 +0100823 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
824 if (pdata->gpio_defaults[i] > 0xffff)
825 pdata->gpio_defaults[i] = 0;
826 else if (pdata->gpio_defaults[i] == 0)
827 pdata->gpio_defaults[i] = 0x10000;
Mark Brownd7810092013-03-25 00:11:27 +0000828 }
829 } else {
830 dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n",
831 ret);
832 }
833
834 return 0;
835}
836
837const struct of_device_id arizona_of_match[] = {
838 { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
839 { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000840 { .compatible = "wlf,wm8280", .data = (void *)WM8280 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100841 { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100842 { .compatible = "wlf,wm8998", .data = (void *)WM8998 },
843 { .compatible = "wlf,wm1814", .data = (void *)WM1814 },
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +0000844 { .compatible = "wlf,wm1831", .data = (void *)WM1831 },
845 { .compatible = "cirrus,cs47l24", .data = (void *)CS47L24 },
Mark Brownd7810092013-03-25 00:11:27 +0000846 {},
847};
848EXPORT_SYMBOL_GPL(arizona_of_match);
849#else
850static inline int arizona_of_get_core_pdata(struct arizona *arizona)
851{
852 return 0;
853}
854#endif
855
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100856static const struct mfd_cell early_devs[] = {
Mark Brown3cc72982012-06-19 16:31:53 +0100857 { .name = "arizona-ldo1" },
858};
859
Charles Keepax3762aed2015-08-11 09:34:31 +0100860static const char * const wm5102_supplies[] = {
Charles Keepax5fc6c392014-07-25 16:24:44 +0100861 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100862 "DBVDD2",
863 "DBVDD3",
864 "CPVDD",
865 "SPKVDDL",
866 "SPKVDDR",
867};
868
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100869static const struct mfd_cell wm5102_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000870 { .name = "arizona-micsupp" },
Charles Keepaxf83c2182016-04-15 13:18:47 +0100871 { .name = "arizona-gpio" },
Charles Keepax5fc6c392014-07-25 16:24:44 +0100872 {
873 .name = "arizona-extcon",
874 .parent_supplies = wm5102_supplies,
875 .num_parent_supplies = 1, /* We only need MICVDD */
876 },
Mark Brown503b1ca2012-11-27 17:36:38 +0000877 { .name = "arizona-haptics" },
Mark Brown3cc72982012-06-19 16:31:53 +0100878 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100879 {
880 .name = "wm5102-codec",
881 .parent_supplies = wm5102_supplies,
882 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
883 },
Mark Brown3cc72982012-06-19 16:31:53 +0100884};
885
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100886static const struct mfd_cell wm5110_devs[] = {
Mark Brownd7768112012-12-20 15:38:03 +0000887 { .name = "arizona-micsupp" },
Charles Keepaxf83c2182016-04-15 13:18:47 +0100888 { .name = "arizona-gpio" },
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 Brown503b1ca2012-11-27 17:36:38 +0000894 { .name = "arizona-haptics" },
Mark Browne102bef2012-07-10 12:37:58 +0100895 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100896 {
897 .name = "wm5110-codec",
898 .parent_supplies = wm5102_supplies,
899 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
900 },
901};
902
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +0000903static const char * const cs47l24_supplies[] = {
904 "MICVDD",
905 "CPVDD",
906 "SPKVDD",
907};
908
909static const struct mfd_cell cs47l24_devs[] = {
910 { .name = "arizona-gpio" },
911 { .name = "arizona-haptics" },
912 { .name = "arizona-pwm" },
913 {
914 .name = "cs47l24-codec",
915 .parent_supplies = cs47l24_supplies,
916 .num_parent_supplies = ARRAY_SIZE(cs47l24_supplies),
917 },
918};
919
Charles Keepax3762aed2015-08-11 09:34:31 +0100920static const char * const wm8997_supplies[] = {
Charles Keepax996c2d42014-07-25 16:24:43 +0100921 "MICVDD",
Charles Keepax32dadef2013-10-15 20:14:22 +0100922 "DBVDD2",
923 "CPVDD",
924 "SPKVDD",
Mark Browne102bef2012-07-10 12:37:58 +0100925};
926
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +0100927static const struct mfd_cell wm8997_devs[] = {
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100928 { .name = "arizona-micsupp" },
Charles Keepaxf83c2182016-04-15 13:18:47 +0100929 { .name = "arizona-gpio" },
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-haptics" },
936 { .name = "arizona-pwm" },
Charles Keepax32dadef2013-10-15 20:14:22 +0100937 {
938 .name = "wm8997-codec",
939 .parent_supplies = wm8997_supplies,
940 .num_parent_supplies = ARRAY_SIZE(wm8997_supplies),
941 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100942};
943
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100944static const struct mfd_cell wm8998_devs[] = {
Charles Keepaxf83c2182016-04-15 13:18:47 +0100945 { .name = "arizona-micsupp" },
946 { .name = "arizona-gpio" },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100947 {
948 .name = "arizona-extcon",
949 .parent_supplies = wm5102_supplies,
950 .num_parent_supplies = 1, /* We only need MICVDD */
951 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100952 { .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 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100959};
960
Bill Pembertonf791be42012-11-19 13:23:04 -0500961int arizona_dev_init(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +0100962{
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +0100963 const char * const mclk_name[] = { "mclk1", "mclk2" };
Mark Brown3cc72982012-06-19 16:31:53 +0100964 struct device *dev = arizona->dev;
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +0000965 const char *type_name = NULL;
Charles Keepax6000c992017-09-04 16:41:51 +0100966 unsigned int reg, val;
Mark Brown62d62b52012-12-02 11:41:46 +0900967 int (*apply_patch)(struct arizona *) = NULL;
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +0100968 const struct mfd_cell *subdevs = NULL;
969 int n_subdevs, ret, i;
Mark Brown3cc72982012-06-19 16:31:53 +0100970
971 dev_set_drvdata(arizona->dev, arizona);
972 mutex_init(&arizona->clk_lock);
973
Charles Keepaxb8d336e2016-09-20 16:30:14 +0100974 if (dev_get_platdata(arizona->dev)) {
Mark Brown3cc72982012-06-19 16:31:53 +0100975 memcpy(&arizona->pdata, dev_get_platdata(arizona->dev),
976 sizeof(arizona->pdata));
Charles Keepaxb8d336e2016-09-20 16:30:14 +0100977 } else {
978 ret = arizona_of_get_core_pdata(arizona);
979 if (ret < 0)
980 return ret;
981 }
Mark Brown3cc72982012-06-19 16:31:53 +0100982
Sylwester Nawrockicdd8da82016-09-02 16:52:46 +0100983 BUILD_BUG_ON(ARRAY_SIZE(arizona->mclk) != ARRAY_SIZE(mclk_name));
984 for (i = 0; i < ARRAY_SIZE(arizona->mclk); i++) {
985 arizona->mclk[i] = devm_clk_get(arizona->dev, mclk_name[i]);
986 if (IS_ERR(arizona->mclk[i])) {
987 dev_info(arizona->dev, "Failed to get %s: %ld\n",
988 mclk_name[i], PTR_ERR(arizona->mclk[i]));
989 arizona->mclk[i] = NULL;
990 }
991 }
992
Mark Brown3cc72982012-06-19 16:31:53 +0100993 regcache_cache_only(arizona->regmap, true);
994
995 switch (arizona->type) {
996 case WM5102:
Mark Browne102bef2012-07-10 12:37:58 +0100997 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000998 case WM8280:
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100999 case WM8997:
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001000 case WM8998:
1001 case WM1814:
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +00001002 case WM1831:
1003 case CS47L24:
Mark Brown3cc72982012-06-19 16:31:53 +01001004 for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++)
1005 arizona->core_supplies[i].supply
1006 = wm5102_core_supplies[i];
1007 arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies);
1008 break;
1009 default:
1010 dev_err(arizona->dev, "Unknown device type %d\n",
1011 arizona->type);
Charles Keepax75d8a2b2016-08-31 10:41:30 +01001012 return -ENODEV;
Mark Brown3cc72982012-06-19 16:31:53 +01001013 }
1014
Charles Keepax4a8c4752014-04-16 10:01:38 +01001015 /* Mark DCVDD as external, LDO1 driver will clear if internal */
1016 arizona->external_dcvdd = true;
1017
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +00001018 switch (arizona->type) {
1019 case WM1831:
1020 case CS47L24:
1021 break; /* No LDO1 regulator */
1022 default:
1023 ret = mfd_add_devices(arizona->dev, -1, early_devs,
1024 ARRAY_SIZE(early_devs), NULL, 0, NULL);
1025 if (ret != 0) {
1026 dev_err(dev, "Failed to add early children: %d\n", ret);
1027 return ret;
1028 }
1029 break;
Mark Brown3cc72982012-06-19 16:31:53 +01001030 }
1031
1032 ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies,
1033 arizona->core_supplies);
1034 if (ret != 0) {
1035 dev_err(dev, "Failed to request core supplies: %d\n",
1036 ret);
1037 goto err_early;
1038 }
1039
Charles Keepax0c2d0ff2014-06-19 16:04:23 +01001040 /**
1041 * Don't use devres here because the only device we have to get
1042 * against is the MFD device and DCVDD will likely be supplied by
1043 * one of its children. Meaning that the regulator will be
1044 * destroyed by the time devres calls regulator put.
1045 */
Charles Keepaxe6021512014-06-02 09:50:41 +01001046 arizona->dcvdd = regulator_get(arizona->dev, "DCVDD");
Mark Brown59db9692012-07-09 00:31:36 +02001047 if (IS_ERR(arizona->dcvdd)) {
1048 ret = PTR_ERR(arizona->dcvdd);
1049 dev_err(dev, "Failed to request DCVDD: %d\n", ret);
1050 goto err_early;
1051 }
1052
Mark Brown87d3af42013-03-26 12:15:26 +00001053 if (arizona->pdata.reset) {
1054 /* Start out with /RESET low to put the chip into reset */
Charles Keepax5f056bf2015-05-11 13:58:01 +01001055 ret = devm_gpio_request_one(arizona->dev, arizona->pdata.reset,
1056 GPIOF_DIR_OUT | GPIOF_INIT_LOW,
1057 "arizona /RESET");
Mark Brown87d3af42013-03-26 12:15:26 +00001058 if (ret != 0) {
1059 dev_err(dev, "Failed to request /RESET: %d\n", ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001060 goto err_dcvdd;
Mark Brown87d3af42013-03-26 12:15:26 +00001061 }
1062 }
1063
Mark Brown3cc72982012-06-19 16:31:53 +01001064 ret = regulator_bulk_enable(arizona->num_core_supplies,
1065 arizona->core_supplies);
1066 if (ret != 0) {
1067 dev_err(dev, "Failed to enable core supplies: %d\n",
1068 ret);
Charles Keepaxe6021512014-06-02 09:50:41 +01001069 goto err_dcvdd;
Mark Brown3cc72982012-06-19 16:31:53 +01001070 }
1071
Mark Brown59db9692012-07-09 00:31:36 +02001072 ret = regulator_enable(arizona->dcvdd);
1073 if (ret != 0) {
1074 dev_err(dev, "Failed to enable DCVDD: %d\n", ret);
1075 goto err_enable;
1076 }
1077
Charles Keepax22298752015-05-11 13:58:02 +01001078 arizona_disable_reset(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001079
Mark Brown3cc72982012-06-19 16:31:53 +01001080 regcache_cache_only(arizona->regmap, false);
1081
Mark Brownca76ceb2013-04-09 16:04:35 +01001082 /* Verify that this is a chip we know about */
1083 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1084 if (ret != 0) {
1085 dev_err(dev, "Failed to read ID register: %d\n", ret);
1086 goto err_reset;
1087 }
1088
1089 switch (reg) {
1090 case 0x5102:
1091 case 0x5110:
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001092 case 0x6349:
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +00001093 case 0x6363:
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001094 case 0x8997:
Mark Brownca76ceb2013-04-09 16:04:35 +01001095 break;
1096 default:
1097 dev_err(arizona->dev, "Unknown device ID: %x\n", reg);
Charles Keepax75d8a2b2016-08-31 10:41:30 +01001098 ret = -ENODEV;
Mark Brownca76ceb2013-04-09 16:04:35 +01001099 goto err_reset;
1100 }
1101
1102 /* If we have a /RESET GPIO we'll already be reset */
1103 if (!arizona->pdata.reset) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001104 ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0);
1105 if (ret != 0) {
1106 dev_err(dev, "Failed to reset device: %d\n", ret);
1107 goto err_reset;
1108 }
1109
Lee Jonesb79a9802015-10-28 12:42:30 +00001110 usleep_range(1000, 5000);
Mark Brownca76ceb2013-04-09 16:04:35 +01001111 }
1112
1113 /* Ensure device startup is complete */
1114 switch (arizona->type) {
1115 case WM5102:
Mark Brown48018942014-08-13 11:42:46 +01001116 ret = regmap_read(arizona->regmap,
1117 ARIZONA_WRITE_SEQUENCER_CTRL_3, &val);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001118 if (ret) {
Mark Brownca76ceb2013-04-09 16:04:35 +01001119 dev_err(dev,
1120 "Failed to check write sequencer state: %d\n",
1121 ret);
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001122 } else if (val & 0x01) {
1123 ret = wm5102_clear_write_sequencer(arizona);
1124 if (ret)
1125 return ret;
Mark Brownca76ceb2013-04-09 16:04:35 +01001126 }
1127 break;
Charles Keepax1c1c6bb2015-05-11 13:58:03 +01001128 default:
1129 break;
1130 }
1131
1132 ret = arizona_wait_for_boot(arizona);
1133 if (ret) {
1134 dev_err(arizona->dev, "Device failed initial boot: %d\n", ret);
1135 goto err_reset;
Mark Brownca76ceb2013-04-09 16:04:35 +01001136 }
1137
1138 /* Read the device ID information & do device specific stuff */
Mark Brown3cc72982012-06-19 16:31:53 +01001139 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg);
1140 if (ret != 0) {
1141 dev_err(dev, "Failed to read ID register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001142 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001143 }
1144
1145 ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION,
1146 &arizona->rev);
1147 if (ret != 0) {
1148 dev_err(dev, "Failed to read revision register: %d\n", ret);
Mark Brown59db9692012-07-09 00:31:36 +02001149 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001150 }
1151 arizona->rev &= ARIZONA_DEVICE_REVISION_MASK;
1152
1153 switch (reg) {
1154 case 0x5102:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001155 if (IS_ENABLED(CONFIG_MFD_WM5102)) {
1156 type_name = "WM5102";
1157 if (arizona->type != WM5102) {
1158 dev_warn(arizona->dev,
1159 "WM5102 registered as %d\n",
1160 arizona->type);
1161 arizona->type = WM5102;
1162 }
1163
1164 apply_patch = wm5102_patch;
1165 arizona->rev &= 0x7;
1166 subdevs = wm5102_devs;
1167 n_subdevs = ARRAY_SIZE(wm5102_devs);
Mark Brown3cc72982012-06-19 16:31:53 +01001168 }
Mark Brown3cc72982012-06-19 16:31:53 +01001169 break;
Mark Browne102bef2012-07-10 12:37:58 +01001170 case 0x5110:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001171 if (IS_ENABLED(CONFIG_MFD_WM5110)) {
1172 switch (arizona->type) {
1173 case WM5110:
1174 type_name = "WM5110";
1175 break;
1176 case WM8280:
1177 type_name = "WM8280";
1178 break;
1179 default:
1180 type_name = "WM5110";
1181 dev_warn(arizona->dev,
1182 "WM5110 registered as %d\n",
1183 arizona->type);
1184 arizona->type = WM5110;
1185 break;
1186 }
1187
1188 apply_patch = wm5110_patch;
1189 subdevs = wm5110_devs;
1190 n_subdevs = ARRAY_SIZE(wm5110_devs);
Mark Browne102bef2012-07-10 12:37:58 +01001191 }
Mark Browne102bef2012-07-10 12:37:58 +01001192 break;
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +00001193 case 0x6363:
1194 if (IS_ENABLED(CONFIG_MFD_CS47L24)) {
1195 switch (arizona->type) {
1196 case CS47L24:
1197 type_name = "CS47L24";
1198 break;
1199
1200 case WM1831:
1201 type_name = "WM1831";
1202 break;
1203
1204 default:
1205 dev_warn(arizona->dev,
1206 "CS47L24 registered as %d\n",
1207 arizona->type);
1208 arizona->type = CS47L24;
1209 break;
1210 }
1211
1212 apply_patch = cs47l24_patch;
1213 subdevs = cs47l24_devs;
1214 n_subdevs = ARRAY_SIZE(cs47l24_devs);
1215 }
1216 break;
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001217 case 0x8997:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001218 if (IS_ENABLED(CONFIG_MFD_WM8997)) {
1219 type_name = "WM8997";
1220 if (arizona->type != WM8997) {
1221 dev_warn(arizona->dev,
1222 "WM8997 registered as %d\n",
1223 arizona->type);
1224 arizona->type = WM8997;
1225 }
1226
1227 apply_patch = wm8997_patch;
1228 subdevs = wm8997_devs;
1229 n_subdevs = ARRAY_SIZE(wm8997_devs);
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001230 }
Charles Keepaxdc7d4862013-06-13 09:43:29 +01001231 break;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001232 case 0x6349:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001233 if (IS_ENABLED(CONFIG_MFD_WM8998)) {
1234 switch (arizona->type) {
1235 case WM8998:
1236 type_name = "WM8998";
1237 break;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001238
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001239 case WM1814:
1240 type_name = "WM1814";
1241 break;
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001242
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001243 default:
1244 type_name = "WM8998";
1245 dev_warn(arizona->dev,
1246 "WM8998 registered as %d\n",
1247 arizona->type);
1248 arizona->type = WM8998;
1249 }
1250
1251 apply_patch = wm8998_patch;
1252 subdevs = wm8998_devs;
1253 n_subdevs = ARRAY_SIZE(wm8998_devs);
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001254 }
Richard Fitzgerald6887b042015-07-03 16:16:35 +01001255 break;
Mark Brown3cc72982012-06-19 16:31:53 +01001256 default:
1257 dev_err(arizona->dev, "Unknown device ID %x\n", reg);
Charles Keepax75d8a2b2016-08-31 10:41:30 +01001258 ret = -ENODEV;
Mark Brown59db9692012-07-09 00:31:36 +02001259 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001260 }
1261
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001262 if (!subdevs) {
1263 dev_err(arizona->dev,
1264 "No kernel support for device ID %x\n", reg);
Charles Keepax75d8a2b2016-08-31 10:41:30 +01001265 ret = -ENODEV;
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +01001266 goto err_reset;
1267 }
1268
Mark Brown3cc72982012-06-19 16:31:53 +01001269 dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A');
1270
Mark Brown62d62b52012-12-02 11:41:46 +09001271 if (apply_patch) {
1272 ret = apply_patch(arizona);
1273 if (ret != 0) {
1274 dev_err(arizona->dev, "Failed to apply patch: %d\n",
1275 ret);
1276 goto err_reset;
1277 }
Charles Keepaxe80436b2013-03-26 18:46:15 +00001278
1279 switch (arizona->type) {
1280 case WM5102:
Charles Keepax0be068a2015-05-11 13:58:04 +01001281 ret = wm5102_apply_hardware_patch(arizona);
1282 if (ret) {
Charles Keepaxe80436b2013-03-26 18:46:15 +00001283 dev_err(arizona->dev,
1284 "Failed to apply hardware patch: %d\n",
1285 ret);
1286 goto err_reset;
1287 }
1288 break;
Charles Keepax882bc462015-05-11 13:58:06 +01001289 case WM5110:
1290 case WM8280:
1291 ret = wm5110_apply_sleep_patch(arizona);
1292 if (ret) {
1293 dev_err(arizona->dev,
1294 "Failed to apply sleep patch: %d\n",
1295 ret);
1296 goto err_reset;
1297 }
1298 break;
Charles Keepaxe80436b2013-03-26 18:46:15 +00001299 default:
1300 break;
1301 }
Mark Brown62d62b52012-12-02 11:41:46 +09001302 }
1303
Mark Brown3cc72982012-06-19 16:31:53 +01001304 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
1305 if (!arizona->pdata.gpio_defaults[i])
1306 continue;
1307
1308 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i,
1309 arizona->pdata.gpio_defaults[i]);
1310 }
1311
Mark Brown3cc72982012-06-19 16:31:53 +01001312 /* Chip default */
1313 if (!arizona->pdata.clk32k_src)
1314 arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2;
1315
1316 switch (arizona->pdata.clk32k_src) {
1317 case ARIZONA_32KZ_MCLK1:
1318 case ARIZONA_32KZ_MCLK2:
1319 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1320 ARIZONA_CLK_32K_SRC_MASK,
1321 arizona->pdata.clk32k_src - 1);
Mark Brown767c6dc2013-03-19 19:04:46 +01001322 arizona_clk32k_enable(arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001323 break;
1324 case ARIZONA_32KZ_NONE:
1325 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
1326 ARIZONA_CLK_32K_SRC_MASK, 2);
1327 break;
1328 default:
1329 dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n",
1330 arizona->pdata.clk32k_src);
1331 ret = -EINVAL;
Mark Brown59db9692012-07-09 00:31:36 +02001332 goto err_reset;
Mark Brown3cc72982012-06-19 16:31:53 +01001333 }
1334
Mark Brown3d91f822013-01-29 00:47:37 +08001335 for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) {
Mark Brown544c7aa2013-01-29 18:44:41 +08001336 if (!arizona->pdata.micbias[i].mV &&
1337 !arizona->pdata.micbias[i].bypass)
Mark Brown3d91f822013-01-29 00:47:37 +08001338 continue;
1339
Mark Brown544c7aa2013-01-29 18:44:41 +08001340 /* Apply default for bypass mode */
1341 if (!arizona->pdata.micbias[i].mV)
1342 arizona->pdata.micbias[i].mV = 2800;
1343
Mark Brown3d91f822013-01-29 00:47:37 +08001344 val = (arizona->pdata.micbias[i].mV - 1500) / 100;
Mark Brown544c7aa2013-01-29 18:44:41 +08001345
Mark Brown3d91f822013-01-29 00:47:37 +08001346 val <<= ARIZONA_MICB1_LVL_SHIFT;
1347
1348 if (arizona->pdata.micbias[i].ext_cap)
1349 val |= ARIZONA_MICB1_EXT_CAP;
1350
1351 if (arizona->pdata.micbias[i].discharge)
1352 val |= ARIZONA_MICB1_DISCH;
1353
Charles Keepaxf773fc62013-05-21 14:56:58 +01001354 if (arizona->pdata.micbias[i].soft_start)
Mark Brown3d91f822013-01-29 00:47:37 +08001355 val |= ARIZONA_MICB1_RATE;
1356
Mark Brown544c7aa2013-01-29 18:44:41 +08001357 if (arizona->pdata.micbias[i].bypass)
1358 val |= ARIZONA_MICB1_BYPASS;
1359
Mark Brown3d91f822013-01-29 00:47:37 +08001360 regmap_update_bits(arizona->regmap,
1361 ARIZONA_MIC_BIAS_CTRL_1 + i,
1362 ARIZONA_MICB1_LVL_MASK |
Charles Keepax71d134b2014-09-24 10:37:11 +01001363 ARIZONA_MICB1_EXT_CAP |
Mark Brown3d91f822013-01-29 00:47:37 +08001364 ARIZONA_MICB1_DISCH |
Mark Brown544c7aa2013-01-29 18:44:41 +08001365 ARIZONA_MICB1_BYPASS |
Mark Brown3d91f822013-01-29 00:47:37 +08001366 ARIZONA_MICB1_RATE, val);
1367 }
1368
Charles Keepax72e43162015-06-14 15:41:50 +01001369 pm_runtime_set_active(arizona->dev);
1370 pm_runtime_enable(arizona->dev);
1371
Mark Brown3cc72982012-06-19 16:31:53 +01001372 /* Set up for interrupts */
1373 ret = arizona_irq_init(arizona);
1374 if (ret != 0)
Charles Keepaxd3477922016-06-27 15:19:11 +01001375 goto err_pm;
Mark Brown3cc72982012-06-19 16:31:53 +01001376
Charles Keepax72e43162015-06-14 15:41:50 +01001377 pm_runtime_set_autosuspend_delay(arizona->dev, 100);
1378 pm_runtime_use_autosuspend(arizona->dev);
1379
Mark Brown3cc72982012-06-19 16:31:53 +01001380 arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error",
1381 arizona_clkgen_err, arizona);
1382 arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked",
1383 arizona_overclocked, arizona);
1384 arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked",
1385 arizona_underclocked, arizona);
1386
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001387 ret = mfd_add_devices(arizona->dev, PLATFORM_DEVID_NONE,
1388 subdevs, n_subdevs, NULL, 0, NULL);
Mark Brown3cc72982012-06-19 16:31:53 +01001389
Richard Fitzgeraldae05ea362015-10-02 13:29:13 +01001390 if (ret) {
Mark Brown3cc72982012-06-19 16:31:53 +01001391 dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret);
1392 goto err_irq;
1393 }
1394
1395 return 0;
1396
1397err_irq:
1398 arizona_irq_exit(arizona);
Charles Keepaxd3477922016-06-27 15:19:11 +01001399err_pm:
1400 pm_runtime_disable(arizona->dev);
Mark Brown3cc72982012-06-19 16:31:53 +01001401err_reset:
Charles Keepax22298752015-05-11 13:58:02 +01001402 arizona_enable_reset(arizona);
Mark Brown59db9692012-07-09 00:31:36 +02001403 regulator_disable(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001404err_enable:
Mark Brown3a36a0db2012-07-09 00:45:53 +02001405 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown3cc72982012-06-19 16:31:53 +01001406 arizona->core_supplies);
Charles Keepaxe6021512014-06-02 09:50:41 +01001407err_dcvdd:
1408 regulator_put(arizona->dcvdd);
Mark Brown3cc72982012-06-19 16:31:53 +01001409err_early:
1410 mfd_remove_devices(dev);
1411 return ret;
1412}
1413EXPORT_SYMBOL_GPL(arizona_dev_init);
1414
Bill Pemberton4740f732012-11-19 13:26:01 -05001415int arizona_dev_exit(struct arizona *arizona)
Mark Brown3cc72982012-06-19 16:31:53 +01001416{
Charles Keepaxfb36f772016-11-14 17:15:56 +00001417 disable_irq(arizona->irq);
Charles Keepaxb8040202014-06-02 09:50:39 +01001418 pm_runtime_disable(arizona->dev);
1419
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001420 regulator_disable(arizona->dcvdd);
Charles Keepaxe6021512014-06-02 09:50:41 +01001421 regulator_put(arizona->dcvdd);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001422
Mark Brown3cc72982012-06-19 16:31:53 +01001423 mfd_remove_devices(arizona->dev);
1424 arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona);
1425 arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona);
1426 arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona);
Mark Brown3cc72982012-06-19 16:31:53 +01001427 arizona_irq_exit(arizona);
Charles Keepax22298752015-05-11 13:58:02 +01001428 arizona_enable_reset(arizona);
Charles Keepaxdf6b3352014-06-02 09:50:40 +01001429
Charles Keepax44202862014-06-02 09:50:42 +01001430 regulator_bulk_disable(arizona->num_core_supplies,
Mark Brown1d017b62013-03-26 12:16:26 +00001431 arizona->core_supplies);
Mark Brown3cc72982012-06-19 16:31:53 +01001432 return 0;
1433}
1434EXPORT_SYMBOL_GPL(arizona_dev_exit);