Lines Matching +full:regulator +full:- +full:soft +full:- +full:start
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2015-2018 Cirrus Logic
21 #include <linux/regulator/consumer.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/regulator/of_regulator.h>
48 .name = "madera-ldo1",
60 { .name = "madera-pinctrl", },
61 { .name = "madera-irq", },
62 { .name = "madera-gpio", },
64 .name = "madera-extcon",
69 .name = "cs47l15-codec",
84 { .name = "madera-pinctrl", },
85 { .name = "madera-irq", },
86 { .name = "madera-micsupp", },
87 { .name = "madera-gpio", },
89 .name = "madera-extcon",
94 .name = "cs47l35-codec",
112 { .name = "madera-pinctrl", },
113 { .name = "madera-irq", },
114 { .name = "madera-micsupp", },
115 { .name = "madera-gpio", },
117 .name = "madera-extcon",
122 .name = "cs47l85-codec",
138 { .name = "madera-pinctrl", },
139 { .name = "madera-irq", },
140 { .name = "madera-micsupp", },
141 { .name = "madera-gpio", },
143 .name = "madera-extcon",
148 .name = "cs47l90-codec",
161 { .name = "madera-pinctrl", },
162 { .name = "madera-irq", },
163 { .name = "madera-micsupp", },
164 { .name = "madera-gpio", },
166 .name = "madera-extcon",
171 .name = "cs47l92-codec",
177 /* Used by madera-i2c and madera-spi drivers */
222 regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_1, &val); in madera_wait_for_boot_noack()
227 regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_1, &val); in madera_wait_for_boot_noack()
231 dev_err(madera->dev, "Polling BOOT_DONE_STS timed out\n"); in madera_wait_for_boot_noack()
232 ret = -ETIMEDOUT; in madera_wait_for_boot_noack()
246 regmap_write(madera->regmap, MADERA_IRQ1_STATUS_1, in madera_wait_for_boot()
249 pm_runtime_mark_last_busy(madera->dev); in madera_wait_for_boot()
258 ret = regmap_write(madera->regmap, MADERA_SOFTWARE_RESET, 0); in madera_soft_reset()
260 dev_err(madera->dev, "Failed to soft reset device: %d\n", ret); in madera_soft_reset()
273 * There are many existing out-of-tree users of these codecs that we in madera_enable_hard_reset()
277 gpiod_set_raw_value_cansleep(madera->pdata.reset, 0); in madera_enable_hard_reset()
282 gpiod_set_raw_value_cansleep(madera->pdata.reset, 1); in madera_disable_hard_reset()
294 ret = regulator_enable(madera->dcvdd); in madera_runtime_resume()
300 regcache_cache_only(madera->regmap, false); in madera_runtime_resume()
301 regcache_cache_only(madera->regmap_32bit, false); in madera_runtime_resume()
309 ret = regcache_sync(madera->regmap); in madera_runtime_resume()
311 dev_err(dev, "Failed to restore 16-bit register cache\n"); in madera_runtime_resume()
315 ret = regcache_sync(madera->regmap_32bit); in madera_runtime_resume()
317 dev_err(dev, "Failed to restore 32-bit register cache\n"); in madera_runtime_resume()
324 regcache_cache_only(madera->regmap_32bit, true); in madera_runtime_resume()
325 regcache_cache_only(madera->regmap, true); in madera_runtime_resume()
326 regulator_disable(madera->dcvdd); in madera_runtime_resume()
335 dev_dbg(madera->dev, "Entering sleep mode\n"); in madera_runtime_suspend()
337 regcache_cache_only(madera->regmap, true); in madera_runtime_suspend()
338 regcache_mark_dirty(madera->regmap); in madera_runtime_suspend()
339 regcache_cache_only(madera->regmap_32bit, true); in madera_runtime_suspend()
340 regcache_mark_dirty(madera->regmap_32bit); in madera_runtime_suspend()
342 regulator_disable(madera->dcvdd); in madera_runtime_suspend()
373 if (madera->pdata.reset) in madera_get_reset_gpio()
376 reset = devm_gpiod_get_optional(madera->dev, "reset", GPIOD_OUT_LOW); in madera_get_reset_gpio()
378 return dev_err_probe(madera->dev, PTR_ERR(reset), in madera_get_reset_gpio()
387 dev_warn(madera->dev, in madera_get_reset_gpio()
390 madera->pdata.reset = reset; in madera_get_reset_gpio()
401 switch (madera->type) { in madera_set_micbias_info()
403 madera->num_micbias = 1; in madera_set_micbias_info()
404 madera->num_childbias[0] = 3; in madera_set_micbias_info()
407 madera->num_micbias = 2; in madera_set_micbias_info()
408 madera->num_childbias[0] = 2; in madera_set_micbias_info()
409 madera->num_childbias[1] = 2; in madera_set_micbias_info()
413 madera->num_micbias = 4; in madera_set_micbias_info()
418 madera->num_micbias = 2; in madera_set_micbias_info()
419 madera->num_childbias[0] = 4; in madera_set_micbias_info()
420 madera->num_childbias[1] = 4; in madera_set_micbias_info()
425 madera->num_micbias = 2; in madera_set_micbias_info()
426 madera->num_childbias[0] = 4; in madera_set_micbias_info()
427 madera->num_childbias[1] = 2; in madera_set_micbias_info()
436 struct device *dev = madera->dev; in madera_dev_init()
443 dev_set_drvdata(madera->dev, madera); in madera_dev_init()
444 BLOCKING_INIT_NOTIFIER_HEAD(&madera->notifier); in madera_dev_init()
445 mutex_init(&madera->dapm_ptr_lock); in madera_dev_init()
453 if (dev_get_platdata(madera->dev)) { in madera_dev_init()
454 memcpy(&madera->pdata, dev_get_platdata(madera->dev), in madera_dev_init()
455 sizeof(madera->pdata)); in madera_dev_init()
458 madera->mclk[MADERA_MCLK1].id = "mclk1"; in madera_dev_init()
459 madera->mclk[MADERA_MCLK2].id = "mclk2"; in madera_dev_init()
460 madera->mclk[MADERA_MCLK3].id = "mclk3"; in madera_dev_init()
462 ret = devm_clk_bulk_get_optional(madera->dev, ARRAY_SIZE(madera->mclk), in madera_dev_init()
463 madera->mclk); in madera_dev_init()
465 dev_err(madera->dev, "Failed to get clocks: %d\n", ret); in madera_dev_init()
470 if (!madera->mclk[MADERA_MCLK2].clk) in madera_dev_init()
471 dev_warn(madera->dev, "Missing MCLK2, requires 32kHz clock\n"); in madera_dev_init()
477 regcache_cache_only(madera->regmap, true); in madera_dev_init()
478 regcache_cache_only(madera->regmap_32bit, true); in madera_dev_init()
481 madera->core_supplies[i].supply = madera_core_supplies[i]; in madera_dev_init()
483 madera->num_core_supplies = ARRAY_SIZE(madera_core_supplies); in madera_dev_init()
490 switch (madera->type) { in madera_dev_init()
501 ret = mfd_add_devices(madera->dev, PLATFORM_DEVID_NONE, in madera_dev_init()
512 dev_err(madera->dev, "Unknown device type %d\n", madera->type); in madera_dev_init()
513 return -ENODEV; in madera_dev_init()
516 ret = devm_regulator_bulk_get(dev, madera->num_core_supplies, in madera_dev_init()
517 madera->core_supplies); in madera_dev_init()
524 * Don't use devres here. If the regulator is one of our children it in madera_dev_init()
528 madera->dcvdd = regulator_get(madera->dev, "DCVDD"); in madera_dev_init()
529 if (IS_ERR(madera->dcvdd)) { in madera_dev_init()
530 ret = PTR_ERR(madera->dcvdd); in madera_dev_init()
535 ret = regulator_bulk_enable(madera->num_core_supplies, in madera_dev_init()
536 madera->core_supplies); in madera_dev_init()
542 ret = regulator_enable(madera->dcvdd); in madera_dev_init()
550 regcache_cache_only(madera->regmap, false); in madera_dev_init()
551 regcache_cache_only(madera->regmap_32bit, false); in madera_dev_init()
555 dev_err(madera->dev, "Device failed initial boot: %d\n", ret); in madera_dev_init()
561 * before we start doing any writes to its registers. in madera_dev_init()
563 ret = regmap_read(madera->regmap, MADERA_SOFTWARE_RESET, &hwid); in madera_dev_init()
572 switch (madera->type) { in madera_dev_init()
585 switch (madera->type) { in madera_dev_init()
598 switch (madera->type) { in madera_dev_init()
612 switch (madera->type) { in madera_dev_init()
626 switch (madera->type) { in madera_dev_init()
640 dev_err(madera->dev, "Unknown device ID: %x\n", hwid); in madera_dev_init()
641 ret = -EINVAL; in madera_dev_init()
646 dev_err(madera->dev, "Device ID 0x%x not a %s\n", hwid, in madera_dev_init()
647 madera->type_name); in madera_dev_init()
648 ret = -ENODEV; in madera_dev_init()
654 * we can now attempt a soft reset. in madera_dev_init()
656 if (!madera->pdata.reset) { in madera_dev_init()
664 dev_err(madera->dev, "Failed to clear boot done: %d\n", ret); in madera_dev_init()
668 ret = regmap_read(madera->regmap, MADERA_HARDWARE_REVISION, in madera_dev_init()
669 &madera->rev); in madera_dev_init()
674 madera->rev &= MADERA_HW_REVISION_MASK; in madera_dev_init()
676 dev_info(dev, "%s silicon revision %d\n", madera->type_name, in madera_dev_init()
677 madera->rev); in madera_dev_init()
683 dev_err(madera->dev, "Failed to apply patch %d\n", ret); in madera_dev_init()
689 ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2].clk); in madera_dev_init()
691 dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret); in madera_dev_init()
695 ret = regmap_update_bits(madera->regmap, in madera_dev_init()
700 dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret); in madera_dev_init()
704 pm_runtime_set_active(madera->dev); in madera_dev_init()
705 pm_runtime_enable(madera->dev); in madera_dev_init()
706 pm_runtime_set_autosuspend_delay(madera->dev, 100); in madera_dev_init()
707 pm_runtime_use_autosuspend(madera->dev); in madera_dev_init()
710 ret = mfd_add_devices(madera->dev, PLATFORM_DEVID_NONE, in madera_dev_init()
714 dev_err(madera->dev, "Failed to add subdevices: %d\n", ret); in madera_dev_init()
721 pm_runtime_disable(madera->dev); in madera_dev_init()
723 clk_disable_unprepare(madera->mclk[MADERA_MCLK2].clk); in madera_dev_init()
726 regulator_disable(madera->dcvdd); in madera_dev_init()
728 regulator_bulk_disable(madera->num_core_supplies, in madera_dev_init()
729 madera->core_supplies); in madera_dev_init()
731 regulator_put(madera->dcvdd); in madera_dev_init()
742 disable_irq(madera->irq); in madera_dev_exit()
744 pm_runtime_get_sync(madera->dev); in madera_dev_exit()
746 mfd_remove_devices(madera->dev); in madera_dev_exit()
748 pm_runtime_disable(madera->dev); in madera_dev_exit()
750 regulator_disable(madera->dcvdd); in madera_dev_exit()
751 regulator_put(madera->dcvdd); in madera_dev_exit()
753 mfd_remove_devices_late(madera->dev); in madera_dev_exit()
755 pm_runtime_set_suspended(madera->dev); in madera_dev_exit()
756 pm_runtime_put_noidle(madera->dev); in madera_dev_exit()
758 clk_disable_unprepare(madera->mclk[MADERA_MCLK2].clk); in madera_dev_exit()
762 regulator_bulk_disable(madera->num_core_supplies, in madera_dev_exit()
763 madera->core_supplies); in madera_dev_exit()