stm32-booster.c 3.5 KB

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