rt5033-regulator.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Regulator driver for the Richtek RT5033
  4. *
  5. * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
  6. * Author: Beomho Seo <beomho.seo@samsung.com>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regulator/driver.h>
  11. #include <linux/mfd/rt5033.h>
  12. #include <linux/mfd/rt5033-private.h>
  13. #include <linux/regulator/of_regulator.h>
  14. static const struct regulator_ops rt5033_safe_ldo_ops = {
  15. .is_enabled = regulator_is_enabled_regmap,
  16. .enable = regulator_enable_regmap,
  17. .disable = regulator_disable_regmap,
  18. .list_voltage = regulator_list_voltage_linear,
  19. };
  20. static const struct regulator_ops rt5033_buck_ops = {
  21. .is_enabled = regulator_is_enabled_regmap,
  22. .enable = regulator_enable_regmap,
  23. .disable = regulator_disable_regmap,
  24. .list_voltage = regulator_list_voltage_linear,
  25. .map_voltage = regulator_map_voltage_linear,
  26. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  27. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  28. };
  29. static const struct regulator_desc rt5033_supported_regulators[] = {
  30. [RT5033_BUCK] = {
  31. .name = "BUCK",
  32. .of_match = of_match_ptr("BUCK"),
  33. .regulators_node = of_match_ptr("regulators"),
  34. .id = RT5033_BUCK,
  35. .ops = &rt5033_buck_ops,
  36. .type = REGULATOR_VOLTAGE,
  37. .owner = THIS_MODULE,
  38. .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
  39. .min_uV = RT5033_REGULATOR_BUCK_VOLTAGE_MIN,
  40. .uV_step = RT5033_REGULATOR_BUCK_VOLTAGE_STEP,
  41. .enable_reg = RT5033_REG_CTRL,
  42. .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
  43. .vsel_reg = RT5033_REG_BUCK_CTRL,
  44. .vsel_mask = RT5033_BUCK_CTRL_MASK,
  45. },
  46. [RT5033_LDO] = {
  47. .name = "LDO",
  48. .of_match = of_match_ptr("LDO"),
  49. .regulators_node = of_match_ptr("regulators"),
  50. .id = RT5033_LDO,
  51. .ops = &rt5033_buck_ops,
  52. .type = REGULATOR_VOLTAGE,
  53. .owner = THIS_MODULE,
  54. .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
  55. .min_uV = RT5033_REGULATOR_LDO_VOLTAGE_MIN,
  56. .uV_step = RT5033_REGULATOR_LDO_VOLTAGE_STEP,
  57. .enable_reg = RT5033_REG_CTRL,
  58. .enable_mask = RT5033_CTRL_EN_LDO_MASK,
  59. .vsel_reg = RT5033_REG_LDO_CTRL,
  60. .vsel_mask = RT5033_LDO_CTRL_MASK,
  61. },
  62. [RT5033_SAFE_LDO] = {
  63. .name = "SAFE_LDO",
  64. .of_match = of_match_ptr("SAFE_LDO"),
  65. .regulators_node = of_match_ptr("regulators"),
  66. .id = RT5033_SAFE_LDO,
  67. .ops = &rt5033_safe_ldo_ops,
  68. .type = REGULATOR_VOLTAGE,
  69. .owner = THIS_MODULE,
  70. .n_voltages = 1,
  71. .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
  72. .enable_reg = RT5033_REG_CTRL,
  73. .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
  74. },
  75. };
  76. static int rt5033_regulator_probe(struct platform_device *pdev)
  77. {
  78. struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
  79. int ret, i;
  80. struct regulator_config config = {};
  81. config.dev = rt5033->dev;
  82. config.driver_data = rt5033;
  83. for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
  84. struct regulator_dev *regulator;
  85. config.regmap = rt5033->regmap;
  86. regulator = devm_regulator_register(&pdev->dev,
  87. &rt5033_supported_regulators[i], &config);
  88. if (IS_ERR(regulator)) {
  89. ret = PTR_ERR(regulator);
  90. dev_err(&pdev->dev,
  91. "Regulator init failed %d: with error: %d\n",
  92. i, ret);
  93. return ret;
  94. }
  95. }
  96. return 0;
  97. }
  98. static const struct platform_device_id rt5033_regulator_id[] = {
  99. { "rt5033-regulator", },
  100. { }
  101. };
  102. MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
  103. static struct platform_driver rt5033_regulator_driver = {
  104. .driver = {
  105. .name = "rt5033-regulator",
  106. },
  107. .probe = rt5033_regulator_probe,
  108. .id_table = rt5033_regulator_id,
  109. };
  110. module_platform_driver(rt5033_regulator_driver);
  111. MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
  112. MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
  113. MODULE_LICENSE("GPL");