Lines Matching full:arizona

3  * Arizona core driver
27 #include <linux/mfd/arizona/core.h>
28 #include <linux/mfd/arizona/registers.h>
30 #include "arizona.h"
37 int arizona_clk32k_enable(struct arizona *arizona) in arizona_clk32k_enable() argument
41 mutex_lock(&arizona->clk_lock); in arizona_clk32k_enable()
43 arizona->clk32k_ref++; in arizona_clk32k_enable()
45 if (arizona->clk32k_ref == 1) { in arizona_clk32k_enable()
46 switch (arizona->pdata.clk32k_src) { in arizona_clk32k_enable()
48 ret = pm_runtime_get_sync(arizona->dev); in arizona_clk32k_enable()
51 ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK1]); in arizona_clk32k_enable()
53 pm_runtime_put_sync(arizona->dev); in arizona_clk32k_enable()
58 ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK2]); in arizona_clk32k_enable()
64 ret = regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, in arizona_clk32k_enable()
71 arizona->clk32k_ref--; in arizona_clk32k_enable()
73 mutex_unlock(&arizona->clk_lock); in arizona_clk32k_enable()
79 int arizona_clk32k_disable(struct arizona *arizona) in arizona_clk32k_disable() argument
81 mutex_lock(&arizona->clk_lock); in arizona_clk32k_disable()
83 WARN_ON(arizona->clk32k_ref <= 0); in arizona_clk32k_disable()
85 arizona->clk32k_ref--; in arizona_clk32k_disable()
87 if (arizona->clk32k_ref == 0) { in arizona_clk32k_disable()
88 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, in arizona_clk32k_disable()
91 switch (arizona->pdata.clk32k_src) { in arizona_clk32k_disable()
93 pm_runtime_put_sync(arizona->dev); in arizona_clk32k_disable()
94 clk_disable_unprepare(arizona->mclk[ARIZONA_MCLK1]); in arizona_clk32k_disable()
97 clk_disable_unprepare(arizona->mclk[ARIZONA_MCLK2]); in arizona_clk32k_disable()
102 mutex_unlock(&arizona->clk_lock); in arizona_clk32k_disable()
110 struct arizona *arizona = data; in arizona_clkgen_err() local
112 dev_err(arizona->dev, "CLKGEN error\n"); in arizona_clkgen_err()
119 struct arizona *arizona = data; in arizona_underclocked() local
123 ret = regmap_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_8, in arizona_underclocked()
126 dev_err(arizona->dev, "Failed to read underclock status: %d\n", in arizona_underclocked()
132 dev_err(arizona->dev, "AIF3 underclocked\n"); in arizona_underclocked()
134 dev_err(arizona->dev, "AIF2 underclocked\n"); in arizona_underclocked()
136 dev_err(arizona->dev, "AIF1 underclocked\n"); in arizona_underclocked()
138 dev_err(arizona->dev, "ISRC3 underclocked\n"); in arizona_underclocked()
140 dev_err(arizona->dev, "ISRC2 underclocked\n"); in arizona_underclocked()
142 dev_err(arizona->dev, "ISRC1 underclocked\n"); in arizona_underclocked()
144 dev_err(arizona->dev, "FX underclocked\n"); in arizona_underclocked()
146 dev_err(arizona->dev, "ASRC underclocked\n"); in arizona_underclocked()
148 dev_err(arizona->dev, "DAC underclocked\n"); in arizona_underclocked()
150 dev_err(arizona->dev, "ADC underclocked\n"); in arizona_underclocked()
152 dev_err(arizona->dev, "Mixer dropped sample\n"); in arizona_underclocked()
159 struct arizona *arizona = data; in arizona_overclocked() local
163 ret = regmap_bulk_read(arizona->regmap, ARIZONA_INTERRUPT_RAW_STATUS_6, in arizona_overclocked()
166 dev_err(arizona->dev, "Failed to read overclock status: %d\n", in arizona_overclocked()
171 switch (arizona->type) { in arizona_overclocked()
186 dev_err(arizona->dev, "PWM overclocked\n"); in arizona_overclocked()
188 dev_err(arizona->dev, "FX core overclocked\n"); in arizona_overclocked()
190 dev_err(arizona->dev, "DAC SYS overclocked\n"); in arizona_overclocked()
192 dev_err(arizona->dev, "DAC WARP overclocked\n"); in arizona_overclocked()
194 dev_err(arizona->dev, "ADC overclocked\n"); in arizona_overclocked()
196 dev_err(arizona->dev, "Mixer overclocked\n"); in arizona_overclocked()
198 dev_err(arizona->dev, "AIF3 overclocked\n"); in arizona_overclocked()
200 dev_err(arizona->dev, "AIF2 overclocked\n"); in arizona_overclocked()
202 dev_err(arizona->dev, "AIF1 overclocked\n"); in arizona_overclocked()
204 dev_err(arizona->dev, "Pad control overclocked\n"); in arizona_overclocked()
207 dev_err(arizona->dev, "Slimbus subsystem overclocked\n"); in arizona_overclocked()
209 dev_err(arizona->dev, "Slimbus async overclocked\n"); in arizona_overclocked()
211 dev_err(arizona->dev, "Slimbus sync overclocked\n"); in arizona_overclocked()
213 dev_err(arizona->dev, "ASRC async system overclocked\n"); in arizona_overclocked()
215 dev_err(arizona->dev, "ASRC async WARP overclocked\n"); in arizona_overclocked()
217 dev_err(arizona->dev, "ASRC sync system overclocked\n"); in arizona_overclocked()
219 dev_err(arizona->dev, "ASRC sync WARP overclocked\n"); in arizona_overclocked()
221 dev_err(arizona->dev, "DSP1 overclocked\n"); in arizona_overclocked()
223 dev_err(arizona->dev, "ISRC3 overclocked\n"); in arizona_overclocked()
225 dev_err(arizona->dev, "ISRC2 overclocked\n"); in arizona_overclocked()
227 dev_err(arizona->dev, "ISRC1 overclocked\n"); in arizona_overclocked()
230 dev_err(arizona->dev, "SPDIF overclocked\n"); in arizona_overclocked()
247 static int arizona_poll_reg(struct arizona *arizona, in arizona_poll_reg() argument
256 ret = regmap_read(arizona->regmap, reg, &val); in arizona_poll_reg()
263 dev_err(arizona->dev, "Failed polling reg 0x%x: %d\n", in arizona_poll_reg()
268 dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n", reg, val); in arizona_poll_reg()
272 static int arizona_wait_for_boot(struct arizona *arizona) in arizona_wait_for_boot() argument
281 ret = arizona_poll_reg(arizona, 30, ARIZONA_INTERRUPT_RAW_STATUS_5, in arizona_wait_for_boot()
285 regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5, in arizona_wait_for_boot()
288 pm_runtime_mark_last_busy(arizona->dev); in arizona_wait_for_boot()
293 static inline void arizona_enable_reset(struct arizona *arizona) in arizona_enable_reset() argument
295 if (arizona->pdata.reset) in arizona_enable_reset()
296 gpiod_set_raw_value_cansleep(arizona->pdata.reset, 0); in arizona_enable_reset()
299 static void arizona_disable_reset(struct arizona *arizona) in arizona_disable_reset() argument
301 if (arizona->pdata.reset) { in arizona_disable_reset()
302 switch (arizona->type) { in arizona_disable_reset()
312 gpiod_set_raw_value_cansleep(arizona->pdata.reset, 1); in arizona_disable_reset()
322 static int arizona_enable_freerun_sysclk(struct arizona *arizona, in arizona_enable_freerun_sysclk() argument
328 ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll); in arizona_enable_freerun_sysclk()
330 dev_err(arizona->dev, "Failed to cache FLL settings: %d\n", in arizona_enable_freerun_sysclk()
334 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, in arizona_enable_freerun_sysclk()
337 dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n", in arizona_enable_freerun_sysclk()
343 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, in arizona_enable_freerun_sysclk()
346 dev_err(arizona->dev, in arizona_enable_freerun_sysclk()
351 ret = arizona_poll_reg(arizona, 180, ARIZONA_INTERRUPT_RAW_STATUS_5, in arizona_enable_freerun_sysclk()
357 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144); in arizona_enable_freerun_sysclk()
359 dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret); in arizona_enable_freerun_sysclk()
366 err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll); in arizona_enable_freerun_sysclk()
368 dev_err(arizona->dev, in arizona_enable_freerun_sysclk()
374 static int arizona_disable_freerun_sysclk(struct arizona *arizona, in arizona_disable_freerun_sysclk() argument
379 ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, in arizona_disable_freerun_sysclk()
382 dev_err(arizona->dev, in arizona_disable_freerun_sysclk()
387 ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll); in arizona_disable_freerun_sysclk()
389 dev_err(arizona->dev, in arizona_disable_freerun_sysclk()
397 static int wm5102_apply_hardware_patch(struct arizona *arizona) in wm5102_apply_hardware_patch() argument
402 ret = arizona_enable_freerun_sysclk(arizona, &state); in wm5102_apply_hardware_patch()
407 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, in wm5102_apply_hardware_patch()
410 dev_err(arizona->dev, "Failed to start write sequencer: %d\n", in wm5102_apply_hardware_patch()
415 ret = arizona_poll_reg(arizona, 30, ARIZONA_WRITE_SEQUENCER_CTRL_1, in wm5102_apply_hardware_patch()
418 regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0, in wm5102_apply_hardware_patch()
422 err = arizona_disable_freerun_sysclk(arizona, &state); in wm5102_apply_hardware_patch()
438 static int wm5110_apply_sleep_patch(struct arizona *arizona) in wm5110_apply_sleep_patch() argument
443 ret = arizona_enable_freerun_sysclk(arizona, &state); in wm5110_apply_sleep_patch()
447 ret = regmap_multi_reg_write_bypassed(arizona->regmap, in wm5110_apply_sleep_patch()
451 err = arizona_disable_freerun_sysclk(arizona, &state); in wm5110_apply_sleep_patch()
456 static int wm5102_clear_write_sequencer(struct arizona *arizona) in wm5102_clear_write_sequencer() argument
460 ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_3, in wm5102_clear_write_sequencer()
463 dev_err(arizona->dev, in wm5102_clear_write_sequencer()
468 arizona_enable_reset(arizona); in wm5102_clear_write_sequencer()
469 regulator_disable(arizona->dcvdd); in wm5102_clear_write_sequencer()
473 ret = regulator_enable(arizona->dcvdd); in wm5102_clear_write_sequencer()
475 dev_err(arizona->dev, "Failed to re-enable DCVDD: %d\n", ret); in wm5102_clear_write_sequencer()
478 arizona_disable_reset(arizona); in wm5102_clear_write_sequencer()
484 static int arizona_isolate_dcvdd(struct arizona *arizona) in arizona_isolate_dcvdd() argument
488 ret = regmap_update_bits(arizona->regmap, in arizona_isolate_dcvdd()
493 dev_err(arizona->dev, "Failed to isolate DCVDD: %d\n", ret); in arizona_isolate_dcvdd()
498 static int arizona_connect_dcvdd(struct arizona *arizona) in arizona_connect_dcvdd() argument
502 ret = regmap_update_bits(arizona->regmap, in arizona_connect_dcvdd()
506 dev_err(arizona->dev, "Failed to connect DCVDD: %d\n", ret); in arizona_connect_dcvdd()
511 static int arizona_is_jack_det_active(struct arizona *arizona) in arizona_is_jack_det_active() argument
516 ret = regmap_read(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, &val); in arizona_is_jack_det_active()
518 dev_err(arizona->dev, in arizona_is_jack_det_active()
530 struct arizona *arizona = dev_get_drvdata(dev); in arizona_runtime_resume() local
533 dev_dbg(arizona->dev, "Leaving AoD mode\n"); in arizona_runtime_resume()
535 if (arizona->has_fully_powered_off) { in arizona_runtime_resume()
536 dev_dbg(arizona->dev, "Re-enabling core supplies\n"); in arizona_runtime_resume()
538 ret = regulator_bulk_enable(arizona->num_core_supplies, in arizona_runtime_resume()
539 arizona->core_supplies); in arizona_runtime_resume()
547 ret = regulator_enable(arizona->dcvdd); in arizona_runtime_resume()
549 dev_err(arizona->dev, "Failed to enable DCVDD: %d\n", ret); in arizona_runtime_resume()
550 if (arizona->has_fully_powered_off) in arizona_runtime_resume()
551 regulator_bulk_disable(arizona->num_core_supplies, in arizona_runtime_resume()
552 arizona->core_supplies); in arizona_runtime_resume()
556 if (arizona->has_fully_powered_off) { in arizona_runtime_resume()
557 arizona_disable_reset(arizona); in arizona_runtime_resume()
558 enable_irq(arizona->irq); in arizona_runtime_resume()
559 arizona->has_fully_powered_off = false; in arizona_runtime_resume()
562 regcache_cache_only(arizona->regmap, false); in arizona_runtime_resume()
564 switch (arizona->type) { in arizona_runtime_resume()
566 if (arizona->external_dcvdd) { in arizona_runtime_resume()
567 ret = arizona_connect_dcvdd(arizona); in arizona_runtime_resume()
572 ret = wm5102_patch(arizona); in arizona_runtime_resume()
574 dev_err(arizona->dev, "Failed to apply patch: %d\n", in arizona_runtime_resume()
579 ret = wm5102_apply_hardware_patch(arizona); in arizona_runtime_resume()
581 dev_err(arizona->dev, in arizona_runtime_resume()
589 ret = arizona_wait_for_boot(arizona); in arizona_runtime_resume()
593 if (arizona->external_dcvdd) { in arizona_runtime_resume()
594 ret = arizona_connect_dcvdd(arizona); in arizona_runtime_resume()
603 ret = regulator_set_voltage(arizona->dcvdd, in arizona_runtime_resume()
606 dev_err(arizona->dev, in arizona_runtime_resume()
613 ret = wm5110_apply_sleep_patch(arizona); in arizona_runtime_resume()
615 dev_err(arizona->dev, in arizona_runtime_resume()
623 ret = arizona_wait_for_boot(arizona); in arizona_runtime_resume()
628 ret = arizona_wait_for_boot(arizona); in arizona_runtime_resume()
632 if (arizona->external_dcvdd) { in arizona_runtime_resume()
633 ret = arizona_connect_dcvdd(arizona); in arizona_runtime_resume()
640 ret = regcache_sync(arizona->regmap); in arizona_runtime_resume()
642 dev_err(arizona->dev, "Failed to restore register cache\n"); in arizona_runtime_resume()
649 regcache_cache_only(arizona->regmap, true); in arizona_runtime_resume()
650 regulator_disable(arizona->dcvdd); in arizona_runtime_resume()
656 struct arizona *arizona = dev_get_drvdata(dev); in arizona_runtime_suspend() local
660 dev_dbg(arizona->dev, "Entering AoD mode\n"); in arizona_runtime_suspend()
662 switch (arizona->type) { in arizona_runtime_suspend()
665 jd_active = arizona_is_jack_det_active(arizona); in arizona_runtime_suspend()
669 if (arizona->external_dcvdd) { in arizona_runtime_suspend()
670 ret = arizona_isolate_dcvdd(arizona); in arizona_runtime_suspend()
679 ret = regulator_set_voltage(arizona->dcvdd, in arizona_runtime_suspend()
682 dev_err(arizona->dev, in arizona_runtime_suspend()
690 jd_active = arizona_is_jack_det_active(arizona); in arizona_runtime_suspend()
694 if (arizona->external_dcvdd) { in arizona_runtime_suspend()
695 ret = arizona_isolate_dcvdd(arizona); in arizona_runtime_suspend()
701 ret = regmap_write(arizona->regmap, in arizona_runtime_suspend()
704 dev_err(arizona->dev, in arizona_runtime_suspend()
715 jd_active = arizona_is_jack_det_active(arizona); in arizona_runtime_suspend()
719 if (arizona->external_dcvdd) { in arizona_runtime_suspend()
720 ret = arizona_isolate_dcvdd(arizona); in arizona_runtime_suspend()
727 regcache_cache_only(arizona->regmap, true); in arizona_runtime_suspend()
728 regcache_mark_dirty(arizona->regmap); in arizona_runtime_suspend()
729 regulator_disable(arizona->dcvdd); in arizona_runtime_suspend()
733 dev_dbg(arizona->dev, "Fully powering off\n"); in arizona_runtime_suspend()
735 arizona->has_fully_powered_off = true; in arizona_runtime_suspend()
737 disable_irq_nosync(arizona->irq); in arizona_runtime_suspend()
738 arizona_enable_reset(arizona); in arizona_runtime_suspend()
739 regulator_bulk_disable(arizona->num_core_supplies, in arizona_runtime_suspend()
740 arizona->core_supplies); in arizona_runtime_suspend()
750 struct arizona *arizona = dev_get_drvdata(dev); in arizona_suspend() local
752 dev_dbg(arizona->dev, "Suspend, disabling IRQ\n"); in arizona_suspend()
753 disable_irq(arizona->irq); in arizona_suspend()
760 struct arizona *arizona = dev_get_drvdata(dev); in arizona_suspend_noirq() local
762 dev_dbg(arizona->dev, "Late suspend, reenabling IRQ\n"); in arizona_suspend_noirq()
763 enable_irq(arizona->irq); in arizona_suspend_noirq()
770 struct arizona *arizona = dev_get_drvdata(dev); in arizona_resume_noirq() local
772 dev_dbg(arizona->dev, "Early resume, disabling IRQ\n"); in arizona_resume_noirq()
773 disable_irq(arizona->irq); in arizona_resume_noirq()
780 struct arizona *arizona = dev_get_drvdata(dev); in arizona_resume() local
782 dev_dbg(arizona->dev, "Resume, reenabling IRQ\n"); in arizona_resume()
783 enable_irq(arizona->irq); in arizona_resume()
811 static int arizona_of_get_core_pdata(struct arizona *arizona) in arizona_of_get_core_pdata() argument
813 struct arizona_pdata *pdata = &arizona->pdata; in arizona_of_get_core_pdata()
817 pdata->reset = devm_gpiod_get(arizona->dev, "wlf,reset", GPIOD_OUT_LOW); in arizona_of_get_core_pdata()
829 dev_err(arizona->dev, "Reset GPIO malformed: %d\n", in arizona_of_get_core_pdata()
835 ret = of_property_read_u32_array(arizona->dev->of_node, in arizona_of_get_core_pdata()
853 dev_err(arizona->dev, "Failed to parse GPIO defaults: %d\n", in arizona_of_get_core_pdata()
873 static inline int arizona_of_get_core_pdata(struct arizona *arizona) in arizona_of_get_core_pdata() argument
880 { .name = "arizona-ldo1" },
893 { .name = "arizona-micsupp" },
894 { .name = "arizona-gpio" },
896 .name = "arizona-extcon",
900 { .name = "arizona-haptics" },
901 { .name = "arizona-pwm" },
910 { .name = "arizona-micsupp" },
911 { .name = "arizona-gpio" },
913 .name = "arizona-extcon",
917 { .name = "arizona-haptics" },
918 { .name = "arizona-pwm" },
933 { .name = "arizona-gpio" },
934 { .name = "arizona-haptics" },
935 { .name = "arizona-pwm" },
951 { .name = "arizona-micsupp" },
952 { .name = "arizona-gpio" },
954 .name = "arizona-extcon",
958 { .name = "arizona-haptics" },
959 { .name = "arizona-pwm" },
968 { .name = "arizona-micsupp" },
969 { .name = "arizona-gpio" },
971 .name = "arizona-extcon",
975 { .name = "arizona-haptics" },
976 { .name = "arizona-pwm" },
984 int arizona_dev_init(struct arizona *arizona) in arizona_dev_init() argument
987 struct device *dev = arizona->dev; in arizona_dev_init()
990 int (*apply_patch)(struct arizona *) = NULL; in arizona_dev_init()
994 dev_set_drvdata(arizona->dev, arizona); in arizona_dev_init()
995 mutex_init(&arizona->clk_lock); in arizona_dev_init()
997 if (dev_get_platdata(arizona->dev)) { in arizona_dev_init()
998 memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), in arizona_dev_init()
999 sizeof(arizona->pdata)); in arizona_dev_init()
1001 ret = arizona_of_get_core_pdata(arizona); in arizona_dev_init()
1006 BUILD_BUG_ON(ARRAY_SIZE(arizona->mclk) != ARRAY_SIZE(mclk_name)); in arizona_dev_init()
1007 for (i = 0; i < ARRAY_SIZE(arizona->mclk); i++) { in arizona_dev_init()
1008 arizona->mclk[i] = devm_clk_get(arizona->dev, mclk_name[i]); in arizona_dev_init()
1009 if (IS_ERR(arizona->mclk[i])) { in arizona_dev_init()
1010 dev_info(arizona->dev, "Failed to get %s: %ld\n", in arizona_dev_init()
1011 mclk_name[i], PTR_ERR(arizona->mclk[i])); in arizona_dev_init()
1012 arizona->mclk[i] = NULL; in arizona_dev_init()
1016 regcache_cache_only(arizona->regmap, true); in arizona_dev_init()
1018 switch (arizona->type) { in arizona_dev_init()
1028 arizona->core_supplies[i].supply in arizona_dev_init()
1030 arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); in arizona_dev_init()
1033 dev_err(arizona->dev, "Unknown device type %d\n", in arizona_dev_init()
1034 arizona->type); in arizona_dev_init()
1039 arizona->external_dcvdd = true; in arizona_dev_init()
1041 switch (arizona->type) { in arizona_dev_init()
1046 ret = mfd_add_devices(arizona->dev, -1, early_devs, in arizona_dev_init()
1055 ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, in arizona_dev_init()
1056 arizona->core_supplies); in arizona_dev_init()
1069 arizona->dcvdd = regulator_get(arizona->dev, "DCVDD"); in arizona_dev_init()
1070 if (IS_ERR(arizona->dcvdd)) { in arizona_dev_init()
1071 ret = PTR_ERR(arizona->dcvdd); in arizona_dev_init()
1076 if (!arizona->pdata.reset) { in arizona_dev_init()
1078 arizona->pdata.reset = devm_gpiod_get(arizona->dev, "reset", in arizona_dev_init()
1080 if (IS_ERR(arizona->pdata.reset)) { in arizona_dev_init()
1081 ret = PTR_ERR(arizona->pdata.reset); in arizona_dev_init()
1085 dev_err(arizona->dev, in arizona_dev_init()
1088 arizona->pdata.reset = NULL; in arizona_dev_init()
1092 ret = regulator_bulk_enable(arizona->num_core_supplies, in arizona_dev_init()
1093 arizona->core_supplies); in arizona_dev_init()
1100 ret = regulator_enable(arizona->dcvdd); in arizona_dev_init()
1106 arizona_disable_reset(arizona); in arizona_dev_init()
1108 regcache_cache_only(arizona->regmap, false); in arizona_dev_init()
1111 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg); in arizona_dev_init()
1125 dev_err(arizona->dev, "Unknown device ID: %x\n", reg); in arizona_dev_init()
1131 if (!arizona->pdata.reset) { in arizona_dev_init()
1132 ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); in arizona_dev_init()
1142 switch (arizona->type) { in arizona_dev_init()
1144 ret = regmap_read(arizona->regmap, in arizona_dev_init()
1151 ret = wm5102_clear_write_sequencer(arizona); in arizona_dev_init()
1160 ret = arizona_wait_for_boot(arizona); in arizona_dev_init()
1162 dev_err(arizona->dev, "Device failed initial boot: %d\n", ret); in arizona_dev_init()
1167 ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, &reg); in arizona_dev_init()
1173 ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, in arizona_dev_init()
1174 &arizona->rev); in arizona_dev_init()
1179 arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; in arizona_dev_init()
1185 if (arizona->type != WM5102) { in arizona_dev_init()
1186 dev_warn(arizona->dev, in arizona_dev_init()
1188 arizona->type); in arizona_dev_init()
1189 arizona->type = WM5102; in arizona_dev_init()
1193 arizona->rev &= 0x7; in arizona_dev_init()
1200 switch (arizona->type) { in arizona_dev_init()
1209 dev_warn(arizona->dev, in arizona_dev_init()
1211 arizona->type); in arizona_dev_init()
1212 arizona->type = WM5110; in arizona_dev_init()
1223 switch (arizona->type) { in arizona_dev_init()
1233 dev_warn(arizona->dev, in arizona_dev_init()
1235 arizona->type); in arizona_dev_init()
1236 arizona->type = CS47L24; in arizona_dev_init()
1248 if (arizona->type != WM8997) { in arizona_dev_init()
1249 dev_warn(arizona->dev, in arizona_dev_init()
1251 arizona->type); in arizona_dev_init()
1252 arizona->type = WM8997; in arizona_dev_init()
1262 switch (arizona->type) { in arizona_dev_init()
1273 dev_warn(arizona->dev, in arizona_dev_init()
1275 arizona->type); in arizona_dev_init()
1276 arizona->type = WM8998; in arizona_dev_init()
1285 dev_err(arizona->dev, "Unknown device ID %x\n", reg); in arizona_dev_init()
1291 dev_err(arizona->dev, in arizona_dev_init()
1297 dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); in arizona_dev_init()
1300 ret = apply_patch(arizona); in arizona_dev_init()
1302 dev_err(arizona->dev, "Failed to apply patch: %d\n", in arizona_dev_init()
1307 switch (arizona->type) { in arizona_dev_init()
1309 ret = wm5102_apply_hardware_patch(arizona); in arizona_dev_init()
1311 dev_err(arizona->dev, in arizona_dev_init()
1319 ret = wm5110_apply_sleep_patch(arizona); in arizona_dev_init()
1321 dev_err(arizona->dev, in arizona_dev_init()
1332 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { in arizona_dev_init()
1333 if (!arizona->pdata.gpio_defaults[i]) in arizona_dev_init()
1336 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, in arizona_dev_init()
1337 arizona->pdata.gpio_defaults[i]); in arizona_dev_init()
1341 if (!arizona->pdata.clk32k_src) in arizona_dev_init()
1342 arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; in arizona_dev_init()
1344 switch (arizona->pdata.clk32k_src) { in arizona_dev_init()
1347 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, in arizona_dev_init()
1349 arizona->pdata.clk32k_src - 1); in arizona_dev_init()
1350 arizona_clk32k_enable(arizona); in arizona_dev_init()
1353 regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, in arizona_dev_init()
1357 dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", in arizona_dev_init()
1358 arizona->pdata.clk32k_src); in arizona_dev_init()
1364 if (!arizona->pdata.micbias[i].mV && in arizona_dev_init()
1365 !arizona->pdata.micbias[i].bypass) in arizona_dev_init()
1369 if (!arizona->pdata.micbias[i].mV) in arizona_dev_init()
1370 arizona->pdata.micbias[i].mV = 2800; in arizona_dev_init()
1372 val = (arizona->pdata.micbias[i].mV - 1500) / 100; in arizona_dev_init()
1376 if (arizona->pdata.micbias[i].ext_cap) in arizona_dev_init()
1379 if (arizona->pdata.micbias[i].discharge) in arizona_dev_init()
1382 if (arizona->pdata.micbias[i].soft_start) in arizona_dev_init()
1385 if (arizona->pdata.micbias[i].bypass) in arizona_dev_init()
1388 regmap_update_bits(arizona->regmap, in arizona_dev_init()
1397 pm_runtime_set_active(arizona->dev); in arizona_dev_init()
1398 pm_runtime_enable(arizona->dev); in arizona_dev_init()
1401 ret = arizona_irq_init(arizona); in arizona_dev_init()
1405 pm_runtime_set_autosuspend_delay(arizona->dev, 100); in arizona_dev_init()
1406 pm_runtime_use_autosuspend(arizona->dev); in arizona_dev_init()
1408 arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", in arizona_dev_init()
1409 arizona_clkgen_err, arizona); in arizona_dev_init()
1410 arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", in arizona_dev_init()
1411 arizona_overclocked, arizona); in arizona_dev_init()
1412 arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", in arizona_dev_init()
1413 arizona_underclocked, arizona); in arizona_dev_init()
1415 ret = mfd_add_devices(arizona->dev, PLATFORM_DEVID_NONE, in arizona_dev_init()
1419 dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); in arizona_dev_init()
1426 arizona_irq_exit(arizona); in arizona_dev_init()
1428 pm_runtime_disable(arizona->dev); in arizona_dev_init()
1430 switch (arizona->pdata.clk32k_src) { in arizona_dev_init()
1433 arizona_clk32k_disable(arizona); in arizona_dev_init()
1439 arizona_enable_reset(arizona); in arizona_dev_init()
1440 regulator_disable(arizona->dcvdd); in arizona_dev_init()
1442 regulator_bulk_disable(arizona->num_core_supplies, in arizona_dev_init()
1443 arizona->core_supplies); in arizona_dev_init()
1445 regulator_put(arizona->dcvdd); in arizona_dev_init()
1452 int arizona_dev_exit(struct arizona *arizona) in arizona_dev_exit() argument
1454 disable_irq(arizona->irq); in arizona_dev_exit()
1455 pm_runtime_disable(arizona->dev); in arizona_dev_exit()
1457 regulator_disable(arizona->dcvdd); in arizona_dev_exit()
1458 regulator_put(arizona->dcvdd); in arizona_dev_exit()
1460 switch (arizona->pdata.clk32k_src) { in arizona_dev_exit()
1463 arizona_clk32k_disable(arizona); in arizona_dev_exit()
1469 mfd_remove_devices(arizona->dev); in arizona_dev_exit()
1470 arizona_free_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, arizona); in arizona_dev_exit()
1471 arizona_free_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, arizona); in arizona_dev_exit()
1472 arizona_free_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, arizona); in arizona_dev_exit()
1473 arizona_irq_exit(arizona); in arizona_dev_exit()
1474 arizona_enable_reset(arizona); in arizona_dev_exit()
1476 regulator_bulk_disable(arizona->num_core_supplies, in arizona_dev_exit()
1477 arizona->core_supplies); in arizona_dev_exit()