14e210fbeSFabrice Gasnier // SPDX-License-Identifier: GPL-2.0 24e210fbeSFabrice Gasnier // Copyright (C) STMicroelectronics 2019 34e210fbeSFabrice Gasnier // Author(s): Fabrice Gasnier <fabrice.gasnier@st.com>. 44e210fbeSFabrice Gasnier 54e210fbeSFabrice Gasnier #include <linux/mfd/syscon.h> 64e210fbeSFabrice Gasnier #include <linux/module.h> 74e210fbeSFabrice Gasnier #include <linux/of_device.h> 84e210fbeSFabrice Gasnier #include <linux/platform_device.h> 94e210fbeSFabrice Gasnier #include <linux/regmap.h> 104e210fbeSFabrice Gasnier #include <linux/regulator/driver.h> 114e210fbeSFabrice Gasnier #include <linux/regulator/of_regulator.h> 124e210fbeSFabrice Gasnier 134e210fbeSFabrice Gasnier /* STM32H7 SYSCFG register */ 144e210fbeSFabrice Gasnier #define STM32H7_SYSCFG_PMCR 0x04 154e210fbeSFabrice Gasnier #define STM32H7_SYSCFG_BOOSTE_MASK BIT(8) 164e210fbeSFabrice Gasnier 174e210fbeSFabrice Gasnier /* STM32MP1 SYSCFG has set and clear registers */ 184e210fbeSFabrice Gasnier #define STM32MP1_SYSCFG_PMCSETR 0x04 194e210fbeSFabrice Gasnier #define STM32MP1_SYSCFG_PMCCLRR 0x44 204e210fbeSFabrice Gasnier #define STM32MP1_SYSCFG_EN_BOOSTER_MASK BIT(8) 214e210fbeSFabrice Gasnier 224e210fbeSFabrice Gasnier static const struct regulator_ops stm32h7_booster_ops = { 234e210fbeSFabrice Gasnier .list_voltage = regulator_list_voltage_linear, 244e210fbeSFabrice Gasnier .enable = regulator_enable_regmap, 254e210fbeSFabrice Gasnier .disable = regulator_disable_regmap, 264e210fbeSFabrice Gasnier .is_enabled = regulator_is_enabled_regmap, 274e210fbeSFabrice Gasnier }; 284e210fbeSFabrice Gasnier 294e210fbeSFabrice Gasnier static const struct regulator_desc stm32h7_booster_desc = { 304e210fbeSFabrice Gasnier .name = "booster", 314e210fbeSFabrice Gasnier .supply_name = "vdda", 324e210fbeSFabrice Gasnier .n_voltages = 1, 334e210fbeSFabrice Gasnier .type = REGULATOR_VOLTAGE, 344e210fbeSFabrice Gasnier .min_uV = 3300000, 354e210fbeSFabrice Gasnier .fixed_uV = 3300000, 364e210fbeSFabrice Gasnier .ramp_delay = 66000, /* up to 50us to stabilize */ 374e210fbeSFabrice Gasnier .ops = &stm32h7_booster_ops, 384e210fbeSFabrice Gasnier .enable_reg = STM32H7_SYSCFG_PMCR, 394e210fbeSFabrice Gasnier .enable_mask = STM32H7_SYSCFG_BOOSTE_MASK, 404e210fbeSFabrice Gasnier .owner = THIS_MODULE, 414e210fbeSFabrice Gasnier }; 424e210fbeSFabrice Gasnier 434e210fbeSFabrice Gasnier static int stm32mp1_booster_enable(struct regulator_dev *rdev) 444e210fbeSFabrice Gasnier { 454e210fbeSFabrice Gasnier return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCSETR, 464e210fbeSFabrice Gasnier STM32MP1_SYSCFG_EN_BOOSTER_MASK); 474e210fbeSFabrice Gasnier } 484e210fbeSFabrice Gasnier 494e210fbeSFabrice Gasnier static int stm32mp1_booster_disable(struct regulator_dev *rdev) 504e210fbeSFabrice Gasnier { 514e210fbeSFabrice Gasnier return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCCLRR, 524e210fbeSFabrice Gasnier STM32MP1_SYSCFG_EN_BOOSTER_MASK); 534e210fbeSFabrice Gasnier } 544e210fbeSFabrice Gasnier 554e210fbeSFabrice Gasnier static const struct regulator_ops stm32mp1_booster_ops = { 564e210fbeSFabrice Gasnier .list_voltage = regulator_list_voltage_linear, 574e210fbeSFabrice Gasnier .enable = stm32mp1_booster_enable, 584e210fbeSFabrice Gasnier .disable = stm32mp1_booster_disable, 594e210fbeSFabrice Gasnier .is_enabled = regulator_is_enabled_regmap, 604e210fbeSFabrice Gasnier }; 614e210fbeSFabrice Gasnier 624e210fbeSFabrice Gasnier static const struct regulator_desc stm32mp1_booster_desc = { 634e210fbeSFabrice Gasnier .name = "booster", 644e210fbeSFabrice Gasnier .supply_name = "vdda", 654e210fbeSFabrice Gasnier .n_voltages = 1, 664e210fbeSFabrice Gasnier .type = REGULATOR_VOLTAGE, 674e210fbeSFabrice Gasnier .min_uV = 3300000, 684e210fbeSFabrice Gasnier .fixed_uV = 3300000, 694e210fbeSFabrice Gasnier .ramp_delay = 66000, 704e210fbeSFabrice Gasnier .ops = &stm32mp1_booster_ops, 714e210fbeSFabrice Gasnier .enable_reg = STM32MP1_SYSCFG_PMCSETR, 724e210fbeSFabrice Gasnier .enable_mask = STM32MP1_SYSCFG_EN_BOOSTER_MASK, 734e210fbeSFabrice Gasnier .owner = THIS_MODULE, 744e210fbeSFabrice Gasnier }; 754e210fbeSFabrice Gasnier 764e210fbeSFabrice Gasnier static int stm32_booster_probe(struct platform_device *pdev) 774e210fbeSFabrice Gasnier { 784e210fbeSFabrice Gasnier struct device *dev = &pdev->dev; 794e210fbeSFabrice Gasnier struct device_node *np = pdev->dev.of_node; 804e210fbeSFabrice Gasnier struct regulator_config config = { }; 814e210fbeSFabrice Gasnier const struct regulator_desc *desc; 824e210fbeSFabrice Gasnier struct regulator_dev *rdev; 834e210fbeSFabrice Gasnier struct regmap *regmap; 844e210fbeSFabrice Gasnier int ret; 854e210fbeSFabrice Gasnier 864e210fbeSFabrice Gasnier regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); 874e210fbeSFabrice Gasnier if (IS_ERR(regmap)) 884e210fbeSFabrice Gasnier return PTR_ERR(regmap); 894e210fbeSFabrice Gasnier 904e210fbeSFabrice Gasnier desc = (const struct regulator_desc *) 914e210fbeSFabrice Gasnier of_match_device(dev->driver->of_match_table, dev)->data; 924e210fbeSFabrice Gasnier 934e210fbeSFabrice Gasnier config.regmap = regmap; 944e210fbeSFabrice Gasnier config.dev = dev; 954e210fbeSFabrice Gasnier config.of_node = np; 964e210fbeSFabrice Gasnier config.init_data = of_get_regulator_init_data(dev, np, desc); 974e210fbeSFabrice Gasnier 984e210fbeSFabrice Gasnier rdev = devm_regulator_register(dev, desc, &config); 994e210fbeSFabrice Gasnier if (IS_ERR(rdev)) { 1004e210fbeSFabrice Gasnier ret = PTR_ERR(rdev); 1014e210fbeSFabrice Gasnier dev_err(dev, "register failed with error %d\n", ret); 1024e210fbeSFabrice Gasnier return ret; 1034e210fbeSFabrice Gasnier } 1044e210fbeSFabrice Gasnier 1054e210fbeSFabrice Gasnier return 0; 1064e210fbeSFabrice Gasnier } 1074e210fbeSFabrice Gasnier 1084e210fbeSFabrice Gasnier static const struct of_device_id stm32_booster_of_match[] = { 1094e210fbeSFabrice Gasnier { 1104e210fbeSFabrice Gasnier .compatible = "st,stm32h7-booster", 1114e210fbeSFabrice Gasnier .data = (void *)&stm32h7_booster_desc 1124e210fbeSFabrice Gasnier }, { 1134e210fbeSFabrice Gasnier .compatible = "st,stm32mp1-booster", 1144e210fbeSFabrice Gasnier .data = (void *)&stm32mp1_booster_desc 1154e210fbeSFabrice Gasnier }, { 1164e210fbeSFabrice Gasnier }, 1174e210fbeSFabrice Gasnier }; 1184e210fbeSFabrice Gasnier MODULE_DEVICE_TABLE(of, stm32_booster_of_match); 1194e210fbeSFabrice Gasnier 1204e210fbeSFabrice Gasnier static struct platform_driver stm32_booster_driver = { 1214e210fbeSFabrice Gasnier .probe = stm32_booster_probe, 1224e210fbeSFabrice Gasnier .driver = { 1234e210fbeSFabrice Gasnier .name = "stm32-booster", 1244e210fbeSFabrice Gasnier .of_match_table = of_match_ptr(stm32_booster_of_match), 1254e210fbeSFabrice Gasnier }, 1264e210fbeSFabrice Gasnier }; 1274e210fbeSFabrice Gasnier module_platform_driver(stm32_booster_driver); 1284e210fbeSFabrice Gasnier 1294e210fbeSFabrice Gasnier MODULE_LICENSE("GPL v2"); 1304e210fbeSFabrice Gasnier MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>"); 1314e210fbeSFabrice Gasnier MODULE_DESCRIPTION("STMicroelectronics STM32 booster regulator driver"); 1324e210fbeSFabrice Gasnier MODULE_ALIAS("platform:stm32-booster"); 133