^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (C) STMicroelectronics 2019
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Author(s): Fabrice Gasnier <fabrice.gasnier@st.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* STM32H7 SYSCFG register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define STM32H7_SYSCFG_PMCR 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define STM32H7_SYSCFG_BOOSTE_MASK BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* STM32MP1 SYSCFG has set and clear registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define STM32MP1_SYSCFG_PMCSETR 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define STM32MP1_SYSCFG_PMCCLRR 0x44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define STM32MP1_SYSCFG_EN_BOOSTER_MASK BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static const struct regulator_ops stm32h7_booster_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static const struct regulator_desc stm32h7_booster_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .name = "booster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .supply_name = "vdda",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .fixed_uV = 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .ramp_delay = 66000, /* up to 50us to stabilize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .ops = &stm32h7_booster_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .enable_reg = STM32H7_SYSCFG_PMCR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .enable_mask = STM32H7_SYSCFG_BOOSTE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int stm32mp1_booster_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCSETR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) STM32MP1_SYSCFG_EN_BOOSTER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int stm32mp1_booster_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCCLRR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) STM32MP1_SYSCFG_EN_BOOSTER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static const struct regulator_ops stm32mp1_booster_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .enable = stm32mp1_booster_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .disable = stm32mp1_booster_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static const struct regulator_desc stm32mp1_booster_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .name = "booster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .supply_name = "vdda",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .fixed_uV = 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .ramp_delay = 66000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .ops = &stm32mp1_booster_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .enable_reg = STM32MP1_SYSCFG_PMCSETR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .enable_mask = STM32MP1_SYSCFG_EN_BOOSTER_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int stm32_booster_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct regulator_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (IS_ERR(regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) desc = (const struct regulator_desc *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) of_match_device(dev->driver->of_match_table, dev)->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) config.regmap = regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) config.dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) config.of_node = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) config.init_data = of_get_regulator_init_data(dev, np, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) rdev = devm_regulator_register(dev, desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ret = PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) dev_err(dev, "register failed with error %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct of_device_id __maybe_unused stm32_booster_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .compatible = "st,stm32h7-booster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .data = (void *)&stm32h7_booster_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .compatible = "st,stm32mp1-booster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .data = (void *)&stm32mp1_booster_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_DEVICE_TABLE(of, stm32_booster_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct platform_driver stm32_booster_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .probe = stm32_booster_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .name = "stm32-booster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .of_match_table = of_match_ptr(stm32_booster_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) module_platform_driver(stm32_booster_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MODULE_DESCRIPTION("STMicroelectronics STM32 booster regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MODULE_ALIAS("platform:stm32-booster");