Lines Matching +full:regulator +full:- +full:changeable +full:- +full:in +full:- +full:suspend

1 // SPDX-License-Identifier: GPL-2.0
3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
10 #include <linux/mfd/rohm-bd718x7.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/regulator/of_regulator.h>
19 /* Typical regulator startup times as per data sheet in uS */
51 * controlled by software - or by PMIC internal HW state machine. Whether
52 * regulator should be under SW or HW control can be defined from device-tree.
98 * We assume PMIC is in RUN state because SW running and able to query the
103 * Note for next hacker - these PMICs have a register where the HW state can be
104 * read. If assuming RUN appears to be false in your use-case - you can
123 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); in bd71837_get_buck34_enable_hwctrl()
138 * guarantee minimum of 1ms sleep - it shouldn't matter if we in voltage_change_done()
143 ret = regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in voltage_change_done()
146 dev_err(&rdev->dev, in voltage_change_done()
147 "Failed to re-enable voltage monitoring (%d)\n", in voltage_change_done()
158 if (rdev->desc->ops->is_enabled(rdev)) { in voltage_change_prepare()
161 now = rdev->desc->ops->get_voltage_sel(rdev); in voltage_change_prepare()
165 now = rdev->desc->ops->list_voltage(rdev, now); in voltage_change_prepare()
169 new = rdev->desc->ops->list_voltage(rdev, sel); in voltage_change_prepare()
175 * disable the power-good detection until voltage has reached in voltage_change_prepare()
178 * this might be less - and we could probably use DT to give in voltage_change_prepare()
190 int ldo_offset = rdev->desc->id - BD718XX_LDO1; in voltage_change_prepare()
193 ret = regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in voltage_change_prepare()
196 dev_err(&rdev->dev, in voltage_change_prepare()
203 ret = regmap_set_bits(rdev->regmap, in voltage_change_prepare()
206 /* ...and we also want to re-enable it */ in voltage_change_prepare()
210 dev_err(&rdev->dev, in voltage_change_prepare()
255 if (rdev->desc->ops->is_enabled(rdev)) in bd71837_set_voltage_sel_pickable_restricted()
256 return -EBUSY; in bd71837_set_voltage_sel_pickable_restricted()
446 dev_err(&rdev->dev, in bd718x7_xvp_sanity_check()
448 return -EINVAL; in bd718x7_xvp_sanity_check()
452 * And protection limit is not changeable. It can only be enabled in bd718x7_xvp_sanity_check()
456 return -EINVAL; in bd718x7_xvp_sanity_check()
464 int ldo_offset = rdev->desc->id - BD718XX_LDO1; in bd718x7_set_ldo_uvp()
474 return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in bd718x7_set_ldo_uvp()
477 return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, in bd718x7_set_ldo_uvp()
486 return -EINVAL; in bd718x7_get_buck_prot_reg()
532 ret = bd718x7_get_buck_uvp_info(rdev->desc->id, &reg, &bit); in bd718x7_set_buck_uvp()
537 return regmap_clear_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_uvp()
539 return regmap_set_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_uvp()
553 ret = bd718x7_get_buck_ovp_info(rdev->desc->id, &reg, &bit); in bd718x7_set_buck_ovp()
558 return regmap_clear_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_ovp()
560 return regmap_set_bits(rdev->regmap, reg, bit); in bd718x7_set_buck_ovp()
645 * when buck enable state is under HW state machine control. In that case the
646 * bit [2] in CTRL register is used to indicate if regulator should be ON.
660 * OPS for all of the ICs - BD718(37/47/50)
671 * There is a HW quirk in BD71837. The shutdown sequence timings for
674 * beginning of shut-down sequence. As bucks 6 and 7 are parent
675 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
677 * emergency state instead of poweroff. In order to avoid this we
704 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); in buck_set_hw_dvs_levels()
1498 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match)) in mark_hw_controlled()
1501 *info |= 1 << (i - 1); in mark_hw_controlled()
1502 dev_dbg(dev, "regulator %d runlevel controlled\n", i); in mark_hw_controlled()
1505 dev_warn(dev, "Bad regulator node\n"); in mark_hw_controlled()
1509 * Setups where regulator (especially the buck8) output voltage is scaled
1510 * by adding external connection where some other regulator output is connected
1511 * to feedback-pin (over suitable resistors) is getting popular amongst users
1516 * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1522 * |------------|
1523 * | buck 8 |-------+----->Vout
1525 * |------------| |
1528 * +-------+--R2---+
1532 * V FB-pull-up
1536 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1542 * Vpu is the pull-up voltage V FB-pull-up in the picture
1546 * VLDO = 1.6V (used as FB-pull-up)
1559 * We do adjust the values in the global desc based on DT settings. in setup_feedback_loop()
1561 * one PMIC is controlled from same processor. I don't see such use-case in setup_feedback_loop()
1562 * for BD718x7 now - so we spare some bits. in setup_feedback_loop()
1564 * If this will point out to be a problem - then we can allocate new in setup_feedback_loop()
1569 * that means allocating new array for each PMIC - and currently I see in setup_feedback_loop()
1577 if (!of_node_name_eq(np, desc->of_match)) in setup_feedback_loop()
1581 if (desc->id >= BD718XX_LDO1) in setup_feedback_loop()
1582 return -EINVAL; in setup_feedback_loop()
1584 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms", in setup_feedback_loop()
1590 return -EINVAL; in setup_feedback_loop()
1592 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms", in setup_feedback_loop()
1597 if (desc->n_linear_ranges && desc->linear_ranges) { in setup_feedback_loop()
1600 new = devm_kzalloc(dev, desc->n_linear_ranges * in setup_feedback_loop()
1604 return -ENOMEM; in setup_feedback_loop()
1606 for (j = 0; j < desc->n_linear_ranges; j++) { in setup_feedback_loop()
1607 int min = desc->linear_ranges[j].min; in setup_feedback_loop()
1608 int step = desc->linear_ranges[j].step; in setup_feedback_loop()
1610 min -= (fb_uv - min)*r2/r1; in setup_feedback_loop()
1618 desc->name, desc->linear_ranges[j].min, in setup_feedback_loop()
1619 desc->linear_ranges[j].step); in setup_feedback_loop()
1623 desc->linear_ranges = new; in setup_feedback_loop()
1625 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n", in setup_feedback_loop()
1626 desc->name); in setup_feedback_loop()
1631 return -ENODEV; in setup_feedback_loop()
1643 struct device_node *nproot __free(device_node) = of_get_child_by_name(dev->of_node, in get_special_regulators()
1647 return -ENODEV; in get_special_regulators()
1650 if (of_property_read_bool(np, "rohm,no-regulator-enable-control")) in get_special_regulators()
1653 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt", in get_special_regulators()
1656 if (ret == -EINVAL) in get_special_regulators()
1678 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; in bd718xx_probe()
1681 regmap = dev_get_regmap(pdev->dev.parent, NULL); in bd718xx_probe()
1683 dev_err(&pdev->dev, "No MFD driver data\n"); in bd718xx_probe()
1684 return -EINVAL; in bd718xx_probe()
1701 dev_err(&pdev->dev, "Unsupported chip type\n"); in bd718xx_probe()
1702 return -EINVAL; in bd718xx_probe()
1709 return dev_err_probe(&pdev->dev, err, "Failed to unlock PMIC\n"); in bd718xx_probe()
1711 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", in bd718xx_probe()
1714 use_snvs = of_property_read_bool(pdev->dev.parent->of_node, in bd718xx_probe()
1715 "rohm,reset-snvs-powered"); in bd718xx_probe()
1730 return dev_err_probe(&pdev->dev, err, in bd718xx_probe()
1733 dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n"); in bd718xx_probe()
1736 config.dev = pdev->dev.parent; in bd718xx_probe()
1739 * There are cases when we want to leave the enable-control for in bd718xx_probe()
1742 * in order to set the system to SUSPEND state. in bd718xx_probe()
1744 * If regulator is taken under SW control the regulator state will not in bd718xx_probe()
1745 * be affected by PMIC state machine - Eg. regulator is likely to stay in bd718xx_probe()
1746 * on even in SUSPEND in bd718xx_probe()
1748 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data, in bd718xx_probe()
1761 desc = &r->desc; in bd718xx_probe()
1764 desc->ops = hwops[i]; in bd718xx_probe()
1766 desc->ops = swops[i]; in bd718xx_probe()
1768 rdev = devm_regulator_register(&pdev->dev, desc, &config); in bd718xx_probe()
1770 return dev_err_probe(&pdev->dev, PTR_ERR(rdev), in bd718xx_probe()
1771 "failed to register %s regulator\n", in bd718xx_probe()
1772 desc->name); in bd718xx_probe()
1775 * Regulator register gets the regulator constraints and in bd718xx_probe()
1783 * transition from POWEROFF is done to SNVS - then all power in bd718xx_probe()
1791 !rdev->constraints->always_on || in bd718xx_probe()
1792 !rdev->constraints->boot_on)) { in bd718xx_probe()
1793 err = regmap_update_bits(regmap, r->init.reg, in bd718xx_probe()
1794 r->init.mask, r->init.val); in bd718xx_probe()
1796 return dev_err_probe(&pdev->dev, err, in bd718xx_probe()
1798 desc->name); in bd718xx_probe()
1800 for (j = 0; j < r->additional_init_amnt; j++) { in bd718xx_probe()
1802 r->additional_inits[j].reg, in bd718xx_probe()
1803 r->additional_inits[j].mask, in bd718xx_probe()
1804 r->additional_inits[j].val); in bd718xx_probe()
1806 return dev_err_probe(&pdev->dev, err, in bd718xx_probe()
1808 desc->name); in bd718xx_probe()
1816 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1817 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1824 .name = "bd718xx-pmic",
1834 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1836 MODULE_ALIAS("platform:bd718xx-pmic");