4 * Copyright 2012 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #include <linux/delay.h>
14 #include <linux/err.h>
15 #include <linux/gpio.h>
16 #include <linux/interrupt.h>
17 #include <linux/mfd/core.h>
18 #include <linux/module.h>
20 #include <linux/of_device.h>
21 #include <linux/of_gpio.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/regmap.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/slab.h>
28 #include <linux/mfd/arizona/core.h>
29 #include <linux/mfd/arizona/registers.h>
33 static const char *wm5102_core_supplies[] = {
38 int arizona_clk32k_enable(struct arizona *arizona)
42 mutex_lock(&arizona->clk_lock);
44 arizona->clk32k_ref++;
46 if (arizona->clk32k_ref == 1) {
47 switch (arizona->pdata.clk32k_src) {
48 case ARIZONA_32KZ_MCLK1:
49 ret = pm_runtime_get_sync(arizona->dev);
55 ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
62 arizona->clk32k_ref--;
64 mutex_unlock(&arizona->clk_lock);
68 EXPORT_SYMBOL_GPL(arizona_clk32k_enable);
70 int arizona_clk32k_disable(struct arizona *arizona)
74 mutex_lock(&arizona->clk_lock);
76 BUG_ON(arizona->clk32k_ref <= 0);
78 arizona->clk32k_ref--;
80 if (arizona->clk32k_ref == 0) {
81 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
82 ARIZONA_CLK_32K_ENA, 0);
84 switch (arizona->pdata.clk32k_src) {
85 case ARIZONA_32KZ_MCLK1:
86 pm_runtime_put_sync(arizona->dev);
91 mutex_unlock(&arizona->clk_lock);
95 EXPORT_SYMBOL_GPL(arizona_clk32k_disable);
97 static irqreturn_t arizona_clkgen_err(int irq, void *data)
99 struct arizona *arizona = data;
101 dev_err(arizona->dev, "CLKGEN error\n");
106 static irqreturn_t arizona_underclocked(int irq, void *data)
108 struct arizona *arizona = data;
112 ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8,
115 dev_err(arizona->dev, "Failed to read underclock status: %d\n",
120 if (val & ARIZONA_AIF3_UNDERCLOCKED_STS)
121 dev_err(arizona->dev, "AIF3 underclocked\n");
122 if (val & ARIZONA_AIF2_UNDERCLOCKED_STS)
123 dev_err(arizona->dev, "AIF2 underclocked\n");
124 if (val & ARIZONA_AIF1_UNDERCLOCKED_STS)
125 dev_err(arizona->dev, "AIF1 underclocked\n");
126 if (val & ARIZONA_ISRC2_UNDERCLOCKED_STS)
127 dev_err(arizona->dev, "ISRC2 underclocked\n");
128 if (val & ARIZONA_ISRC1_UNDERCLOCKED_STS)
129 dev_err(arizona->dev, "ISRC1 underclocked\n");
130 if (val & ARIZONA_FX_UNDERCLOCKED_STS)
131 dev_err(arizona->dev, "FX underclocked\n");
132 if (val & ARIZONA_ASRC_UNDERCLOCKED_STS)
133 dev_err(arizona->dev, "ASRC underclocked\n");
134 if (val & ARIZONA_DAC_UNDERCLOCKED_STS)
135 dev_err(arizona->dev, "DAC underclocked\n");
136 if (val & ARIZONA_ADC_UNDERCLOCKED_STS)
137 dev_err(arizona->dev, "ADC underclocked\n");
138 if (val & ARIZONA_MIXER_UNDERCLOCKED_STS)
139 dev_err(arizona->dev, "Mixer dropped sample\n");
144 static irqreturn_t arizona_overclocked(int irq, void *data)
146 struct arizona *arizona = data;
150 ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6,
153 dev_err(arizona->dev, "Failed to read overclock status: %d\n",
158 if (val[0] & ARIZONA_PWM_OVERCLOCKED_STS)
159 dev_err(arizona->dev, "PWM overclocked\n");
160 if (val[0] & ARIZONA_FX_CORE_OVERCLOCKED_STS)
161 dev_err(arizona->dev, "FX core overclocked\n");
162 if (val[0] & ARIZONA_DAC_SYS_OVERCLOCKED_STS)
163 dev_err(arizona->dev, "DAC SYS overclocked\n");
164 if (val[0] & ARIZONA_DAC_WARP_OVERCLOCKED_STS)
165 dev_err(arizona->dev, "DAC WARP overclocked\n");
166 if (val[0] & ARIZONA_ADC_OVERCLOCKED_STS)
167 dev_err(arizona->dev, "ADC overclocked\n");
168 if (val[0] & ARIZONA_MIXER_OVERCLOCKED_STS)
169 dev_err(arizona->dev, "Mixer overclocked\n");
170 if (val[0] & ARIZONA_AIF3_SYNC_OVERCLOCKED_STS)
171 dev_err(arizona->dev, "AIF3 overclocked\n");
172 if (val[0] & ARIZONA_AIF2_SYNC_OVERCLOCKED_STS)
173 dev_err(arizona->dev, "AIF2 overclocked\n");
174 if (val[0] & ARIZONA_AIF1_SYNC_OVERCLOCKED_STS)
175 dev_err(arizona->dev, "AIF1 overclocked\n");
176 if (val[0] & ARIZONA_PAD_CTRL_OVERCLOCKED_STS)
177 dev_err(arizona->dev, "Pad control overclocked\n");
179 if (val[1] & ARIZONA_SLIMBUS_SUBSYS_OVERCLOCKED_STS)
180 dev_err(arizona->dev, "Slimbus subsystem overclocked\n");
181 if (val[1] & ARIZONA_SLIMBUS_ASYNC_OVERCLOCKED_STS)
182 dev_err(arizona->dev, "Slimbus async overclocked\n");
183 if (val[1] & ARIZONA_SLIMBUS_SYNC_OVERCLOCKED_STS)
184 dev_err(arizona->dev, "Slimbus sync overclocked\n");
185 if (val[1] & ARIZONA_ASRC_ASYNC_SYS_OVERCLOCKED_STS)
186 dev_err(arizona->dev, "ASRC async system overclocked\n");
187 if (val[1] & ARIZONA_ASRC_ASYNC_WARP_OVERCLOCKED_STS)
188 dev_err(arizona->dev, "ASRC async WARP overclocked\n");
189 if (val[1] & ARIZONA_ASRC_SYNC_SYS_OVERCLOCKED_STS)
190 dev_err(arizona->dev, "ASRC sync system overclocked\n");
191 if (val[1] & ARIZONA_ASRC_SYNC_WARP_OVERCLOCKED_STS)
192 dev_err(arizona->dev, "ASRC sync WARP overclocked\n");
193 if (val[1] & ARIZONA_ADSP2_1_OVERCLOCKED_STS)
194 dev_err(arizona->dev, "DSP1 overclocked\n");
195 if (val[1] & ARIZONA_ISRC2_OVERCLOCKED_STS)
196 dev_err(arizona->dev, "ISRC2 overclocked\n");
197 if (val[1] & ARIZONA_ISRC1_OVERCLOCKED_STS)
198 dev_err(arizona->dev, "ISRC1 overclocked\n");
203 static int arizona_poll_reg(struct arizona *arizona,
204 int timeout, unsigned int reg,
205 unsigned int mask, unsigned int target)
207 unsigned int val = 0;
210 for (i = 0; i < timeout; i++) {
211 ret = regmap_read(arizona->regmap, reg, &val);
213 dev_err(arizona->dev, "Failed to read reg %u: %d\n",
218 if ((val & mask) == target)
224 dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val);
228 static int arizona_wait_for_boot(struct arizona *arizona)
233 * We can't use an interrupt as we need to runtime resume to do so,
234 * we won't race with the interrupt handler as it'll be blocked on
237 ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5,
238 ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
241 regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
242 ARIZONA_BOOT_DONE_STS);
244 pm_runtime_mark_last_busy(arizona->dev);
249 static int arizona_apply_hardware_patch(struct arizona* arizona)
251 unsigned int fll, sysclk;
254 /* Cache existing FLL and SYSCLK settings */
255 ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &fll);
257 dev_err(arizona->dev, "Failed to cache FLL settings: %d\n",
261 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, &sysclk);
263 dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
268 /* Start up SYSCLK using the FLL in free running mode */
269 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1,
270 ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN);
272 dev_err(arizona->dev,
273 "Failed to start FLL in freerunning mode: %d\n",
277 ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
278 ARIZONA_FLL1_CLOCK_OK_STS,
279 ARIZONA_FLL1_CLOCK_OK_STS);
285 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
287 dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
291 /* Start the write sequencer and wait for it to finish */
292 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
293 ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160);
295 dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
299 ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
300 ARIZONA_WSEQ_BUSY, 0);
302 regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
308 err = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, sysclk);
310 dev_err(arizona->dev,
311 "Failed to re-apply old SYSCLK settings: %d\n",
316 err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, fll);
318 dev_err(arizona->dev,
319 "Failed to re-apply old FLL settings: %d\n",
329 #ifdef CONFIG_PM_RUNTIME
330 static int arizona_runtime_resume(struct device *dev)
332 struct arizona *arizona = dev_get_drvdata(dev);
335 dev_dbg(arizona->dev, "Leaving AoD mode\n");
337 ret = regulator_enable(arizona->dcvdd);
339 dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret);
343 regcache_cache_only(arizona->regmap, false);
345 switch (arizona->type) {
347 if (arizona->external_dcvdd) {
348 ret = regmap_update_bits(arizona->regmap,
349 ARIZONA_ISOLATION_CONTROL,
350 ARIZONA_ISOLATE_DCVDD1, 0);
352 dev_err(arizona->dev,
353 "Failed to connect DCVDD: %d\n", ret);
358 ret = wm5102_patch(arizona);
360 dev_err(arizona->dev, "Failed to apply patch: %d\n",
365 ret = arizona_apply_hardware_patch(arizona);
367 dev_err(arizona->dev,
368 "Failed to apply hardware patch: %d\n",
374 ret = arizona_wait_for_boot(arizona);
379 if (arizona->external_dcvdd) {
380 ret = regmap_update_bits(arizona->regmap,
381 ARIZONA_ISOLATION_CONTROL,
382 ARIZONA_ISOLATE_DCVDD1, 0);
384 dev_err(arizona->dev,
385 "Failed to connect DCVDD: %d\n", ret);
392 switch (arizona->type) {
394 ret = wm5102_patch(arizona);
396 dev_err(arizona->dev, "Failed to apply patch: %d\n",
404 ret = regcache_sync(arizona->regmap);
406 dev_err(arizona->dev, "Failed to restore register cache\n");
413 regcache_cache_only(arizona->regmap, true);
414 regulator_disable(arizona->dcvdd);
418 static int arizona_runtime_suspend(struct device *dev)
420 struct arizona *arizona = dev_get_drvdata(dev);
423 dev_dbg(arizona->dev, "Entering AoD mode\n");
425 if (arizona->external_dcvdd) {
426 ret = regmap_update_bits(arizona->regmap,
427 ARIZONA_ISOLATION_CONTROL,
428 ARIZONA_ISOLATE_DCVDD1,
429 ARIZONA_ISOLATE_DCVDD1);
431 dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n",
437 regcache_cache_only(arizona->regmap, true);
438 regcache_mark_dirty(arizona->regmap);
439 regulator_disable(arizona->dcvdd);
445 #ifdef CONFIG_PM_SLEEP
446 static int arizona_suspend(struct device *dev)
448 struct arizona *arizona = dev_get_drvdata(dev);
450 dev_dbg(arizona->dev, "Suspend, disabling IRQ\n");
451 disable_irq(arizona->irq);
456 static int arizona_suspend_late(struct device *dev)
458 struct arizona *arizona = dev_get_drvdata(dev);
460 dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n");
461 enable_irq(arizona->irq);
466 static int arizona_resume_noirq(struct device *dev)
468 struct arizona *arizona = dev_get_drvdata(dev);
470 dev_dbg(arizona->dev, "Early resume, disabling IRQ\n");
471 disable_irq(arizona->irq);
476 static int arizona_resume(struct device *dev)
478 struct arizona *arizona = dev_get_drvdata(dev);
480 dev_dbg(arizona->dev, "Late resume, reenabling IRQ\n");
481 enable_irq(arizona->irq);
487 const struct dev_pm_ops arizona_pm_ops = {
488 SET_RUNTIME_PM_OPS(arizona_runtime_suspend,
489 arizona_runtime_resume,
491 SET_SYSTEM_SLEEP_PM_OPS(arizona_suspend, arizona_resume)
492 #ifdef CONFIG_PM_SLEEP
493 .suspend_late = arizona_suspend_late,
494 .resume_noirq = arizona_resume_noirq,
497 EXPORT_SYMBOL_GPL(arizona_pm_ops);
500 unsigned long arizona_of_get_type(struct device *dev)
502 const struct of_device_id *id = of_match_device(arizona_of_match, dev);
505 return (unsigned long)id->data;
509 EXPORT_SYMBOL_GPL(arizona_of_get_type);
511 int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop,
516 gpio = of_get_named_gpio(arizona->dev->of_node, prop, 0);
519 dev_err(arizona->dev,
520 "Mandatory DT gpio %s missing/malformed: %d\n",
528 EXPORT_SYMBOL_GPL(arizona_of_get_named_gpio);
530 static int arizona_of_get_core_pdata(struct arizona *arizona)
532 struct arizona_pdata *pdata = &arizona->pdata;
535 pdata->reset = arizona_of_get_named_gpio(arizona, "wlf,reset", true);
537 ret = of_property_read_u32_array(arizona->dev->of_node,
539 arizona->pdata.gpio_defaults,
540 ARRAY_SIZE(arizona->pdata.gpio_defaults));
543 * All values are literal except out of range values
544 * which are chip default, translate into platform
545 * data which uses 0 as chip default and out of range
548 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
549 if (arizona->pdata.gpio_defaults[i] > 0xffff)
550 arizona->pdata.gpio_defaults[i] = 0;
551 else if (arizona->pdata.gpio_defaults[i] == 0)
552 arizona->pdata.gpio_defaults[i] = 0x10000;
555 dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n",
562 const struct of_device_id arizona_of_match[] = {
563 { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
564 { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
565 { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
568 EXPORT_SYMBOL_GPL(arizona_of_match);
570 static inline int arizona_of_get_core_pdata(struct arizona *arizona)
576 static const struct mfd_cell early_devs[] = {
577 { .name = "arizona-ldo1" },
580 static const char *wm5102_supplies[] = {
589 static const struct mfd_cell wm5102_devs[] = {
590 { .name = "arizona-micsupp" },
591 { .name = "arizona-extcon" },
592 { .name = "arizona-gpio" },
593 { .name = "arizona-haptics" },
594 { .name = "arizona-pwm" },
596 .name = "wm5102-codec",
597 .parent_supplies = wm5102_supplies,
598 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
602 static const struct mfd_cell wm5110_devs[] = {
603 { .name = "arizona-micsupp" },
604 { .name = "arizona-extcon" },
605 { .name = "arizona-gpio" },
606 { .name = "arizona-haptics" },
607 { .name = "arizona-pwm" },
609 .name = "wm5110-codec",
610 .parent_supplies = wm5102_supplies,
611 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
615 static const char *wm8997_supplies[] = {
622 static const struct mfd_cell wm8997_devs[] = {
623 { .name = "arizona-micsupp" },
624 { .name = "arizona-extcon" },
625 { .name = "arizona-gpio" },
626 { .name = "arizona-haptics" },
627 { .name = "arizona-pwm" },
629 .name = "wm8997-codec",
630 .parent_supplies = wm8997_supplies,
631 .num_parent_supplies = ARRAY_SIZE(wm8997_supplies),
635 int arizona_dev_init(struct arizona *arizona)
637 struct device *dev = arizona->dev;
638 const char *type_name;
639 unsigned int reg, val;
640 int (*apply_patch)(struct arizona *) = NULL;
643 dev_set_drvdata(arizona->dev, arizona);
644 mutex_init(&arizona->clk_lock);
646 if (dev_get_platdata(arizona->dev))
647 memcpy(&arizona->pdata, dev_get_platdata(arizona->dev),
648 sizeof(arizona->pdata));
650 arizona_of_get_core_pdata(arizona);
652 regcache_cache_only(arizona->regmap, true);
654 switch (arizona->type) {
658 for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++)
659 arizona->core_supplies[i].supply
660 = wm5102_core_supplies[i];
661 arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies);
664 dev_err(arizona->dev, "Unknown device type %d\n",
669 /* Mark DCVDD as external, LDO1 driver will clear if internal */
670 arizona->external_dcvdd = true;
672 ret = mfd_add_devices(arizona->dev, -1, early_devs,
673 ARRAY_SIZE(early_devs), NULL, 0, NULL);
675 dev_err(dev, "Failed to add early children: %d\n", ret);
679 ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies,
680 arizona->core_supplies);
682 dev_err(dev, "Failed to request core supplies: %d\n",
688 * Don't use devres here because the only device we have to get
689 * against is the MFD device and DCVDD will likely be supplied by
690 * one of its children. Meaning that the regulator will be
691 * destroyed by the time devres calls regulator put.
693 arizona->dcvdd = regulator_get(arizona->dev, "DCVDD");
694 if (IS_ERR(arizona->dcvdd)) {
695 ret = PTR_ERR(arizona->dcvdd);
696 dev_err(dev, "Failed to request DCVDD: %d\n", ret);
700 if (arizona->pdata.reset) {
701 /* Start out with /RESET low to put the chip into reset */
702 ret = gpio_request_one(arizona->pdata.reset,
703 GPIOF_DIR_OUT | GPIOF_INIT_LOW,
706 dev_err(dev, "Failed to request /RESET: %d\n", ret);
711 ret = regulator_bulk_enable(arizona->num_core_supplies,
712 arizona->core_supplies);
714 dev_err(dev, "Failed to enable core supplies: %d\n",
719 ret = regulator_enable(arizona->dcvdd);
721 dev_err(dev, "Failed to enable DCVDD: %d\n", ret);
725 if (arizona->pdata.reset) {
726 gpio_set_value_cansleep(arizona->pdata.reset, 1);
730 regcache_cache_only(arizona->regmap, false);
732 /* Verify that this is a chip we know about */
733 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®);
735 dev_err(dev, "Failed to read ID register: %d\n", ret);
745 dev_err(arizona->dev, "Unknown device ID: %x\n", reg);
749 /* If we have a /RESET GPIO we'll already be reset */
750 if (!arizona->pdata.reset) {
751 regcache_mark_dirty(arizona->regmap);
753 ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0);
755 dev_err(dev, "Failed to reset device: %d\n", ret);
761 ret = regcache_sync(arizona->regmap);
763 dev_err(dev, "Failed to sync device: %d\n", ret);
768 /* Ensure device startup is complete */
769 switch (arizona->type) {
771 ret = regmap_read(arizona->regmap, 0x19, &val);
774 "Failed to check write sequencer state: %d\n",
780 ret = arizona_wait_for_boot(arizona);
782 dev_err(arizona->dev,
783 "Device failed initial boot: %d\n", ret);
789 /* Read the device ID information & do device specific stuff */
790 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®);
792 dev_err(dev, "Failed to read ID register: %d\n", ret);
796 ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION,
799 dev_err(dev, "Failed to read revision register: %d\n", ret);
802 arizona->rev &= ARIZONA_DEVICE_REVISION_MASK;
805 #ifdef CONFIG_MFD_WM5102
807 type_name = "WM5102";
808 if (arizona->type != WM5102) {
809 dev_err(arizona->dev, "WM5102 registered as %d\n",
811 arizona->type = WM5102;
813 apply_patch = wm5102_patch;
817 #ifdef CONFIG_MFD_WM5110
819 type_name = "WM5110";
820 if (arizona->type != WM5110) {
821 dev_err(arizona->dev, "WM5110 registered as %d\n",
823 arizona->type = WM5110;
825 apply_patch = wm5110_patch;
828 #ifdef CONFIG_MFD_WM8997
830 type_name = "WM8997";
831 if (arizona->type != WM8997) {
832 dev_err(arizona->dev, "WM8997 registered as %d\n",
834 arizona->type = WM8997;
836 apply_patch = wm8997_patch;
840 dev_err(arizona->dev, "Unknown device ID %x\n", reg);
844 dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A');
847 ret = apply_patch(arizona);
849 dev_err(arizona->dev, "Failed to apply patch: %d\n",
854 switch (arizona->type) {
856 ret = arizona_apply_hardware_patch(arizona);
858 dev_err(arizona->dev,
859 "Failed to apply hardware patch: %d\n",
869 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
870 if (!arizona->pdata.gpio_defaults[i])
873 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i,
874 arizona->pdata.gpio_defaults[i]);
877 pm_runtime_set_autosuspend_delay(arizona->dev, 100);
878 pm_runtime_use_autosuspend(arizona->dev);
879 pm_runtime_enable(arizona->dev);
882 if (!arizona->pdata.clk32k_src)
883 arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2;
885 switch (arizona->pdata.clk32k_src) {
886 case ARIZONA_32KZ_MCLK1:
887 case ARIZONA_32KZ_MCLK2:
888 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
889 ARIZONA_CLK_32K_SRC_MASK,
890 arizona->pdata.clk32k_src - 1);
891 arizona_clk32k_enable(arizona);
893 case ARIZONA_32KZ_NONE:
894 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1,
895 ARIZONA_CLK_32K_SRC_MASK, 2);
898 dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n",
899 arizona->pdata.clk32k_src);
904 for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) {
905 if (!arizona->pdata.micbias[i].mV &&
906 !arizona->pdata.micbias[i].bypass)
909 /* Apply default for bypass mode */
910 if (!arizona->pdata.micbias[i].mV)
911 arizona->pdata.micbias[i].mV = 2800;
913 val = (arizona->pdata.micbias[i].mV - 1500) / 100;
915 val <<= ARIZONA_MICB1_LVL_SHIFT;
917 if (arizona->pdata.micbias[i].ext_cap)
918 val |= ARIZONA_MICB1_EXT_CAP;
920 if (arizona->pdata.micbias[i].discharge)
921 val |= ARIZONA_MICB1_DISCH;
923 if (arizona->pdata.micbias[i].soft_start)
924 val |= ARIZONA_MICB1_RATE;
926 if (arizona->pdata.micbias[i].bypass)
927 val |= ARIZONA_MICB1_BYPASS;
929 regmap_update_bits(arizona->regmap,
930 ARIZONA_MIC_BIAS_CTRL_1 + i,
931 ARIZONA_MICB1_LVL_MASK |
932 ARIZONA_MICB1_DISCH |
933 ARIZONA_MICB1_BYPASS |
934 ARIZONA_MICB1_RATE, val);
937 for (i = 0; i < ARIZONA_MAX_INPUT; i++) {
938 /* Default for both is 0 so noop with defaults */
939 val = arizona->pdata.dmic_ref[i]
940 << ARIZONA_IN1_DMIC_SUP_SHIFT;
941 val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT;
943 regmap_update_bits(arizona->regmap,
944 ARIZONA_IN1L_CONTROL + (i * 8),
945 ARIZONA_IN1_DMIC_SUP_MASK |
946 ARIZONA_IN1_MODE_MASK, val);
949 for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) {
950 /* Default is 0 so noop with defaults */
951 if (arizona->pdata.out_mono[i])
952 val = ARIZONA_OUT1_MONO;
956 regmap_update_bits(arizona->regmap,
957 ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8),
958 ARIZONA_OUT1_MONO, val);
961 for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) {
962 if (arizona->pdata.spk_mute[i])
963 regmap_update_bits(arizona->regmap,
964 ARIZONA_PDM_SPK1_CTRL_1 + (i * 2),
965 ARIZONA_SPK1_MUTE_ENDIAN_MASK |
966 ARIZONA_SPK1_MUTE_SEQ1_MASK,
967 arizona->pdata.spk_mute[i]);
969 if (arizona->pdata.spk_fmt[i])
970 regmap_update_bits(arizona->regmap,
971 ARIZONA_PDM_SPK1_CTRL_2 + (i * 2),
972 ARIZONA_SPK1_FMT_MASK,
973 arizona->pdata.spk_fmt[i]);
976 /* Set up for interrupts */
977 ret = arizona_irq_init(arizona);
981 arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error",
982 arizona_clkgen_err, arizona);
983 arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked",
984 arizona_overclocked, arizona);
985 arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked",
986 arizona_underclocked, arizona);
988 switch (arizona->type) {
990 ret = mfd_add_devices(arizona->dev, -1, wm5102_devs,
991 ARRAY_SIZE(wm5102_devs), NULL, 0, NULL);
994 ret = mfd_add_devices(arizona->dev, -1, wm5110_devs,
995 ARRAY_SIZE(wm5110_devs), NULL, 0, NULL);
998 ret = mfd_add_devices(arizona->dev, -1, wm8997_devs,
999 ARRAY_SIZE(wm8997_devs), NULL, 0, NULL);
1004 dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret);
1008 #ifdef CONFIG_PM_RUNTIME
1009 regulator_disable(arizona->dcvdd);
1015 arizona_irq_exit(arizona);
1017 if (arizona->pdata.reset) {
1018 gpio_set_value_cansleep(arizona->pdata.reset, 0);
1019 gpio_free(arizona->pdata.reset);
1021 regulator_disable(arizona->dcvdd);
1023 regulator_bulk_disable(arizona->num_core_supplies,
1024 arizona->core_supplies);
1026 regulator_put(arizona->dcvdd);
1028 mfd_remove_devices(dev);
1031 EXPORT_SYMBOL_GPL(arizona_dev_init);
1033 int arizona_dev_exit(struct arizona *arizona)
1035 pm_runtime_disable(arizona->dev);
1037 regulator_disable(arizona->dcvdd);
1038 regulator_put(arizona->dcvdd);
1040 mfd_remove_devices(arizona->dev);
1041 arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona);
1042 arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona);
1043 arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona);
1044 arizona_irq_exit(arizona);
1045 if (arizona->pdata.reset)
1046 gpio_set_value_cansleep(arizona->pdata.reset, 0);
1048 regulator_bulk_disable(arizona->num_core_supplies,
1049 arizona->core_supplies);
1052 EXPORT_SYMBOL_GPL(arizona_dev_exit);