Lines Matching +full:regulator +full:- +full:uv +full:- +full:protection +full:- +full:microvolt
1 // SPDX-License-Identifier: GPL-2.0
3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
9 #include <linux/mfd/rohm-bd718x7.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/machine.h>
15 #include <linux/regulator/of_regulator.h>
18 /* Typical regulator startup times as per data sheet in uS */
50 * controlled by software - or by PMIC internal HW state machine. Whether
51 * regulator should be under SW or HW control can be defined from device-tree.
102 * Note for next hacker - these PMICs have a register where the HW state can be
103 * read. If assuming RUN appears to be false in your use-case - you can
122 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); in bd71837_get_buck34_enable_hwctrl()
137 * guarantee minimum of 1ms sleep - it shouldn't matter if we in voltage_change_done()
142 ret = regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in voltage_change_done()
145 dev_err(&rdev->dev, in voltage_change_done()
146 "Failed to re-enable voltage monitoring (%d)\n", in voltage_change_done()
157 if (rdev->desc->ops->is_enabled(rdev)) { in voltage_change_prepare()
160 now = rdev->desc->ops->get_voltage_sel(rdev); in voltage_change_prepare()
164 now = rdev->desc->ops->list_voltage(rdev, now); in voltage_change_prepare()
168 new = rdev->desc->ops->list_voltage(rdev, sel); in voltage_change_prepare()
174 * disable the power-good detection until voltage has reached in voltage_change_prepare()
177 * this might be less - and we could probably use DT to give in voltage_change_prepare()
189 int ldo_offset = rdev->desc->id - BD718XX_LDO1; in voltage_change_prepare()
192 ret = regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in voltage_change_prepare()
195 dev_err(&rdev->dev, in voltage_change_prepare()
201 /* We disable protection if it was enabled... */ in voltage_change_prepare()
202 ret = regmap_set_bits(rdev->regmap, in voltage_change_prepare()
205 /* ...and we also want to re-enable it */ in voltage_change_prepare()
209 dev_err(&rdev->dev, in voltage_change_prepare()
254 if (rdev->desc->ops->is_enabled(rdev)) in bd71837_set_voltage_sel_pickable_restricted()
255 return -EBUSY; in bd71837_set_voltage_sel_pickable_restricted()
442 * warnings, only protection in bd718x7_xvp_sanity_check()
445 dev_err(&rdev->dev, in bd718x7_xvp_sanity_check()
446 "Unsupported Under Voltage protection level\n"); in bd718x7_xvp_sanity_check()
447 return -EINVAL; in bd718x7_xvp_sanity_check()
451 * And protection limit is not changeable. It can only be enabled in bd718x7_xvp_sanity_check()
455 return -EINVAL; in bd718x7_xvp_sanity_check()
463 int ldo_offset = rdev->desc->id - BD718XX_LDO1; in bd718x7_set_ldo_uvp()
473 return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in bd718x7_set_ldo_uvp()
476 return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in bd718x7_set_ldo_uvp()
485 return -EINVAL; in bd718x7_get_buck_prot_reg()
531 ret = bd718x7_get_buck_uvp_info(rdev->desc->id, ®, &bit); in bd718x7_set_buck_uvp()
536 return regmap_clear_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_uvp()
538 return regmap_set_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_uvp()
552 ret = bd718x7_get_buck_ovp_info(rdev->desc->id, ®, &bit); in bd718x7_set_buck_ovp()
557 return regmap_clear_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_ovp()
559 return regmap_set_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_ovp()
645 * bit [2] in CTRL register is used to indicate if regulator should be ON.
659 * OPS for all of the ICs - BD718(37/47/50)
673 * beginning of shut-down sequence. As bucks 6 and 7 are parent
674 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
703 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); in buck_set_hw_dvs_levels()
1497 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match)) in mark_hw_controlled()
1500 *info |= 1 << (i - 1); in mark_hw_controlled()
1501 dev_dbg(dev, "regulator %d runlevel controlled\n", i); in mark_hw_controlled()
1504 dev_warn(dev, "Bad regulator node\n"); in mark_hw_controlled()
1508 * Setups where regulator (especially the buck8) output voltage is scaled
1509 * by adding external connection where some other regulator output is connected
1510 * to feedback-pin (over suitable resistors) is getting popular amongst users
1515 * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1521 * |------------|
1522 * | buck 8 |-------+----->Vout
1524 * |------------| |
1527 * +-------+--R2---+
1531 * V FB-pull-up
1535 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1541 * Vpu is the pull-up voltage V FB-pull-up in the picture
1545 * VLDO = 1.6V (used as FB-pull-up)
1560 * one PMIC is controlled from same processor. I don't see such use-case in setup_feedback_loop()
1561 * for BD718x7 now - so we spare some bits. in setup_feedback_loop()
1563 * If this will point out to be a problem - then we can allocate new in setup_feedback_loop()
1568 * that means allocating new array for each PMIC - and currently I see in setup_feedback_loop()
1576 if (!of_node_name_eq(np, desc->of_match)) in setup_feedback_loop()
1579 pr_info("Looking at node '%s'\n", desc->of_match); in setup_feedback_loop()
1582 if (desc->id >= BD718XX_LDO1) in setup_feedback_loop()
1583 return -EINVAL; in setup_feedback_loop()
1585 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms", in setup_feedback_loop()
1591 return -EINVAL; in setup_feedback_loop()
1593 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms", in setup_feedback_loop()
1598 if (desc->n_linear_ranges && desc->linear_ranges) { in setup_feedback_loop()
1601 new = devm_kzalloc(dev, desc->n_linear_ranges * in setup_feedback_loop()
1605 return -ENOMEM; in setup_feedback_loop()
1607 for (j = 0; j < desc->n_linear_ranges; j++) { in setup_feedback_loop()
1608 int min = desc->linear_ranges[j].min; in setup_feedback_loop()
1609 int step = desc->linear_ranges[j].step; in setup_feedback_loop()
1611 min -= (fb_uv - min)*r2/r1; in setup_feedback_loop()
1619 desc->name, desc->linear_ranges[j].min, in setup_feedback_loop()
1620 desc->linear_ranges[j].step); in setup_feedback_loop()
1624 desc->linear_ranges = new; in setup_feedback_loop()
1626 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n", in setup_feedback_loop()
1627 desc->name); in setup_feedback_loop()
1632 return -ENODEV; in setup_feedback_loop()
1641 struct device_node *nproot = dev->of_node; in get_special_regulators()
1642 int uv; in get_special_regulators() local
1649 return -ENODEV; in get_special_regulators()
1652 if (of_property_read_bool(np, "rohm,no-regulator-enable-control")) in get_special_regulators()
1655 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt", in get_special_regulators()
1656 &uv); in get_special_regulators()
1658 if (ret == -EINVAL) in get_special_regulators()
1664 ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv); in get_special_regulators()
1687 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; in bd718xx_probe()
1690 regmap = dev_get_regmap(pdev->dev.parent, NULL); in bd718xx_probe()
1692 dev_err(&pdev->dev, "No MFD driver data\n"); in bd718xx_probe()
1693 return -EINVAL; in bd718xx_probe()
1710 dev_err(&pdev->dev, "Unsupported chip type\n"); in bd718xx_probe()
1711 err = -EINVAL; in bd718xx_probe()
1719 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); in bd718xx_probe()
1722 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", in bd718xx_probe()
1726 use_snvs = of_property_read_bool(pdev->dev.parent->of_node, in bd718xx_probe()
1727 "rohm,reset-snvs-powered"); in bd718xx_probe()
1742 dev_err(&pdev->dev, "Failed to change reset target\n"); in bd718xx_probe()
1745 dev_dbg(&pdev->dev, in bd718xx_probe()
1750 config.dev = pdev->dev.parent; in bd718xx_probe()
1753 * There are cases when we want to leave the enable-control for in bd718xx_probe()
1758 * If regulator is taken under SW control the regulator state will not in bd718xx_probe()
1759 * be affected by PMIC state machine - Eg. regulator is likely to stay in bd718xx_probe()
1762 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data, in bd718xx_probe()
1775 desc = &r->desc; in bd718xx_probe()
1778 desc->ops = hwops[i]; in bd718xx_probe()
1780 desc->ops = swops[i]; in bd718xx_probe()
1782 rdev = devm_regulator_register(&pdev->dev, desc, &config); in bd718xx_probe()
1784 dev_err(&pdev->dev, in bd718xx_probe()
1785 "failed to register %s regulator\n", in bd718xx_probe()
1786 desc->name); in bd718xx_probe()
1792 * Regulator register gets the regulator constraints and in bd718xx_probe()
1800 * transition from POWEROFF is done to SNVS - then all power in bd718xx_probe()
1808 !rdev->constraints->always_on || in bd718xx_probe()
1809 !rdev->constraints->boot_on)) { in bd718xx_probe()
1810 err = regmap_update_bits(regmap, r->init.reg, in bd718xx_probe()
1811 r->init.mask, r->init.val); in bd718xx_probe()
1813 dev_err(&pdev->dev, in bd718xx_probe()
1815 desc->name); in bd718xx_probe()
1819 for (j = 0; j < r->additional_init_amnt; j++) { in bd718xx_probe()
1821 r->additional_inits[j].reg, in bd718xx_probe()
1822 r->additional_inits[j].mask, in bd718xx_probe()
1823 r->additional_inits[j].val); in bd718xx_probe()
1825 dev_err(&pdev->dev, in bd718xx_probe()
1827 desc->name); in bd718xx_probe()
1838 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1839 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1846 .name = "bd718xx-pmic",
1855 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1857 MODULE_ALIAS("platform:bd718xx-pmic");