Lines Matching +full:regulator +full:- +full:allow +full:- +full:bypass
1 // SPDX-License-Identifier: GPL-2.0-only
28 #include <linux/regulator/consumer.h>
104 ret = regmap_read(twl6040->regmap, reg, &val); in twl6040_reg_read()
116 ret = regmap_write(twl6040->regmap, reg, val); in twl6040_reg_write()
124 return regmap_update_bits(twl6040->regmap, reg, mask, mask); in twl6040_set_bits()
130 return regmap_update_bits(twl6040->regmap, reg, mask, 0); in twl6040_clear_bits()
134 /* twl6040 codec manual power-up sequence */
140 /* enable high-side LDO, reference system and internal oscillator */ in twl6040_power_up_manual()
154 /* enable low-side LDO */ in twl6040_power_up_manual()
161 /* enable low-power PLL */ in twl6040_power_up_manual()
189 dev_err(twl6040->dev, "manual power-up failed\n"); in twl6040_power_up_manual()
193 /* twl6040 manual power-down sequence */
207 /* disable low-power PLL */ in twl6040_power_down_manual()
211 /* disable low-side LDO */ in twl6040_power_down_manual()
219 /* disable high-side LDO, reference system and internal oscillator */ in twl6040_power_down_manual()
228 complete(&twl6040->ready); in twl6040_readyint_handler()
240 dev_warn(twl6040->dev, "Thermal shutdown, powering-off"); in twl6040_thint_handler()
243 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on"); in twl6040_thint_handler()
254 gpio_set_value(twl6040->audpwron, 1); in twl6040_power_up_automatic()
256 time_left = wait_for_completion_timeout(&twl6040->ready, in twl6040_power_up_automatic()
261 dev_warn(twl6040->dev, "timeout waiting for READYINT\n"); in twl6040_power_up_automatic()
264 dev_err(twl6040->dev, "automatic power-up failed\n"); in twl6040_power_up_automatic()
265 gpio_set_value(twl6040->audpwron, 0); in twl6040_power_up_automatic()
266 return -ETIMEDOUT; in twl6040_power_up_automatic()
277 mutex_lock(&twl6040->mutex); in twl6040_power()
280 /* already powered-up */ in twl6040_power()
281 if (twl6040->power_count++) in twl6040_power()
284 ret = clk_prepare_enable(twl6040->clk32k); in twl6040_power()
286 twl6040->power_count = 0; in twl6040_power()
290 /* Allow writes to the chip */ in twl6040_power()
291 regcache_cache_only(twl6040->regmap, false); in twl6040_power()
293 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
294 /* use automatic power-up sequence */ in twl6040_power()
297 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
298 twl6040->power_count = 0; in twl6040_power()
302 /* use manual power-up sequence */ in twl6040_power()
305 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
306 twl6040->power_count = 0; in twl6040_power()
312 * Register access can produce errors after power-up unless we in twl6040_power()
318 ret = regcache_sync(twl6040->regmap); in twl6040_power()
320 dev_err(twl6040->dev, "Failed to sync with the HW: %i\n", in twl6040_power()
326 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; in twl6040_power()
327 twl6040->sysclk_rate = 19200000; in twl6040_power()
329 /* already powered-down */ in twl6040_power()
330 if (!twl6040->power_count) { in twl6040_power()
331 dev_err(twl6040->dev, in twl6040_power()
332 "device is already powered-off\n"); in twl6040_power()
333 ret = -EPERM; in twl6040_power()
337 if (--twl6040->power_count) in twl6040_power()
340 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
342 gpio_set_value(twl6040->audpwron, 0); in twl6040_power()
344 /* power-down sequence latency */ in twl6040_power()
347 /* use manual power-down sequence */ in twl6040_power()
352 regcache_cache_only(twl6040->regmap, true); in twl6040_power()
353 regcache_mark_dirty(twl6040->regmap); in twl6040_power()
355 twl6040->sysclk_rate = 0; in twl6040_power()
357 if (twl6040->pll == TWL6040_SYSCLK_SEL_HPPLL) { in twl6040_power()
358 clk_disable_unprepare(twl6040->mclk); in twl6040_power()
359 twl6040->mclk_rate = 0; in twl6040_power()
362 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
366 mutex_unlock(&twl6040->mutex); in twl6040_power()
377 mutex_lock(&twl6040->mutex); in twl6040_set_pll()
383 if (pll_id != twl6040->pll) { in twl6040_set_pll()
384 twl6040->sysclk_rate = 0; in twl6040_set_pll()
385 twl6040->mclk_rate = 0; in twl6040_set_pll()
390 /* low-power PLL divider */ in twl6040_set_pll()
392 if (twl6040->sysclk_rate != freq_out) { in twl6040_set_pll()
401 dev_err(twl6040->dev, in twl6040_set_pll()
404 ret = -EINVAL; in twl6040_set_pll()
412 if (twl6040->pll == pll_id) in twl6040_set_pll()
429 dev_err(twl6040->dev, in twl6040_set_pll()
431 ret = -EINVAL; in twl6040_set_pll()
435 clk_disable_unprepare(twl6040->mclk); in twl6040_set_pll()
438 /* high-performance PLL can provide only 19.2 MHz */ in twl6040_set_pll()
440 dev_err(twl6040->dev, in twl6040_set_pll()
442 ret = -EINVAL; in twl6040_set_pll()
446 if (twl6040->mclk_rate != freq_in) { in twl6040_set_pll()
456 /* PLL enabled, bypass mode */ in twl6040_set_pll()
466 /* PLL enabled, bypass mode */ in twl6040_set_pll()
471 dev_err(twl6040->dev, in twl6040_set_pll()
473 ret = -EINVAL; in twl6040_set_pll()
478 if (pll_id != twl6040->pll) in twl6040_set_pll()
479 clk_prepare_enable(twl6040->mclk); in twl6040_set_pll()
496 twl6040->mclk_rate = freq_in; in twl6040_set_pll()
500 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); in twl6040_set_pll()
501 ret = -EINVAL; in twl6040_set_pll()
505 twl6040->sysclk_rate = freq_out; in twl6040_set_pll()
506 twl6040->pll = pll_id; in twl6040_set_pll()
509 mutex_unlock(&twl6040->mutex); in twl6040_set_pll()
516 if (twl6040->power_count) in twl6040_get_pll()
517 return twl6040->pll; in twl6040_get_pll()
519 return -ENODEV; in twl6040_get_pll()
525 return twl6040->sysclk_rate; in twl6040_get_sysclk()
536 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, ®); in twl6040_get_vibralr_status()
541 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, ®); in twl6040_get_vibralr_status()
639 struct device_node *node = client->dev.of_node; in twl6040_probe()
645 dev_err(&client->dev, "of node is missing\n"); in twl6040_probe()
646 return -EINVAL; in twl6040_probe()
650 if (!client->irq) { in twl6040_probe()
651 dev_err(&client->dev, "Invalid IRQ configuration\n"); in twl6040_probe()
652 return -EINVAL; in twl6040_probe()
655 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), in twl6040_probe()
658 return -ENOMEM; in twl6040_probe()
660 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); in twl6040_probe()
661 if (IS_ERR(twl6040->regmap)) in twl6040_probe()
662 return PTR_ERR(twl6040->regmap); in twl6040_probe()
666 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k"); in twl6040_probe()
667 if (IS_ERR(twl6040->clk32k)) { in twl6040_probe()
668 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER) in twl6040_probe()
669 return -EPROBE_DEFER; in twl6040_probe()
670 dev_dbg(&client->dev, "clk32k is not handled\n"); in twl6040_probe()
671 twl6040->clk32k = NULL; in twl6040_probe()
674 twl6040->mclk = devm_clk_get(&client->dev, "mclk"); in twl6040_probe()
675 if (IS_ERR(twl6040->mclk)) { in twl6040_probe()
676 if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER) in twl6040_probe()
677 return -EPROBE_DEFER; in twl6040_probe()
678 dev_dbg(&client->dev, "mclk is not handled\n"); in twl6040_probe()
679 twl6040->mclk = NULL; in twl6040_probe()
682 twl6040->supplies[0].supply = "vio"; in twl6040_probe()
683 twl6040->supplies[1].supply = "v2v1"; in twl6040_probe()
684 ret = devm_regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES, in twl6040_probe()
685 twl6040->supplies); in twl6040_probe()
687 dev_err(&client->dev, "Failed to get supplies: %d\n", ret); in twl6040_probe()
691 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
693 dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); in twl6040_probe()
697 twl6040->dev = &client->dev; in twl6040_probe()
698 twl6040->irq = client->irq; in twl6040_probe()
700 mutex_init(&twl6040->mutex); in twl6040_probe()
701 init_completion(&twl6040->ready); in twl6040_probe()
703 regmap_register_patch(twl6040->regmap, twl6040_patch, in twl6040_probe()
706 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); in twl6040_probe()
707 if (twl6040->rev < 0) { in twl6040_probe()
708 dev_err(&client->dev, "Failed to read revision register: %d\n", in twl6040_probe()
709 twl6040->rev); in twl6040_probe()
710 ret = twl6040->rev; in twl6040_probe()
714 /* ERRATA: Automatic power-up is not possible in ES1.0 */ in twl6040_probe()
716 twl6040->audpwron = of_get_named_gpio(node, in twl6040_probe()
717 "ti,audpwron-gpio", 0); in twl6040_probe()
719 twl6040->audpwron = -EINVAL; in twl6040_probe()
721 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_probe()
722 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron, in twl6040_probe()
731 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT, in twl6040_probe()
732 0, &twl6040_irq_chip, &twl6040->irq_data); in twl6040_probe()
736 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
738 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
741 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL, in twl6040_probe()
745 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); in twl6040_probe()
749 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL, in twl6040_probe()
753 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); in twl6040_probe()
761 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); in twl6040_probe()
762 cell = &twl6040->cells[children]; in twl6040_probe()
763 cell->name = "twl6040-codec"; in twl6040_probe()
766 cell->resources = twl6040_codec_rsrc; in twl6040_probe()
767 cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc); in twl6040_probe()
772 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); in twl6040_probe()
774 cell = &twl6040->cells[children]; in twl6040_probe()
775 cell->name = "twl6040-vibra"; in twl6040_probe()
778 cell->resources = twl6040_vibra_rsrc; in twl6040_probe()
779 cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc); in twl6040_probe()
784 cell = &twl6040->cells[children]; in twl6040_probe()
785 cell->name = "twl6040-gpo"; in twl6040_probe()
789 cell = &twl6040->cells[children]; in twl6040_probe()
790 cell->name = "twl6040-pdmclk"; in twl6040_probe()
794 regcache_cache_only(twl6040->regmap, true); in twl6040_probe()
795 regcache_mark_dirty(twl6040->regmap); in twl6040_probe()
797 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, in twl6040_probe()
805 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_probe()
807 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
815 if (twl6040->power_count) in twl6040_remove()
818 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_remove()
820 mfd_remove_devices(&client->dev); in twl6040_remove()
822 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_remove()