rt5033-regulator.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <[email protected]>
  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 linear_range rt5033_buck_ranges[] = {
  15. REGULATOR_LINEAR_RANGE(1000000, 0, 20, 100000),
  16. REGULATOR_LINEAR_RANGE(3000000, 21, 31, 0),
  17. };
  18. static const struct linear_range rt5033_ldo_ranges[] = {
  19. REGULATOR_LINEAR_RANGE(1200000, 0, 18, 100000),
  20. REGULATOR_LINEAR_RANGE(3000000, 19, 31, 0),
  21. };
  22. static const struct regulator_ops rt5033_safe_ldo_ops = {
  23. .is_enabled = regulator_is_enabled_regmap,
  24. .enable = regulator_enable_regmap,
  25. .disable = regulator_disable_regmap,
  26. .list_voltage = regulator_list_voltage_linear,
  27. };
  28. static const struct regulator_ops rt5033_buck_ops = {
  29. .is_enabled = regulator_is_enabled_regmap,
  30. .enable = regulator_enable_regmap,
  31. .disable = regulator_disable_regmap,
  32. .list_voltage = regulator_list_voltage_linear_range,
  33. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  34. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  35. };
  36. static const struct regulator_desc rt5033_supported_regulators[] = {
  37. [RT5033_BUCK] = {
  38. .name = "BUCK",
  39. .of_match = of_match_ptr("BUCK"),
  40. .regulators_node = of_match_ptr("regulators"),
  41. .id = RT5033_BUCK,
  42. .ops = &rt5033_buck_ops,
  43. .type = REGULATOR_VOLTAGE,
  44. .owner = THIS_MODULE,
  45. .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
  46. .linear_ranges = rt5033_buck_ranges,
  47. .n_linear_ranges = ARRAY_SIZE(rt5033_buck_ranges),
  48. .enable_reg = RT5033_REG_CTRL,
  49. .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
  50. .vsel_reg = RT5033_REG_BUCK_CTRL,
  51. .vsel_mask = RT5033_BUCK_CTRL_MASK,
  52. },
  53. [RT5033_LDO] = {
  54. .name = "LDO",
  55. .of_match = of_match_ptr("LDO"),
  56. .regulators_node = of_match_ptr("regulators"),
  57. .id = RT5033_LDO,
  58. .ops = &rt5033_buck_ops,
  59. .type = REGULATOR_VOLTAGE,
  60. .owner = THIS_MODULE,
  61. .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
  62. .linear_ranges = rt5033_ldo_ranges,
  63. .n_linear_ranges = ARRAY_SIZE(rt5033_ldo_ranges),
  64. .enable_reg = RT5033_REG_CTRL,
  65. .enable_mask = RT5033_CTRL_EN_LDO_MASK,
  66. .vsel_reg = RT5033_REG_LDO_CTRL,
  67. .vsel_mask = RT5033_LDO_CTRL_MASK,
  68. },
  69. [RT5033_SAFE_LDO] = {
  70. .name = "SAFE_LDO",
  71. .of_match = of_match_ptr("SAFE_LDO"),
  72. .regulators_node = of_match_ptr("regulators"),
  73. .id = RT5033_SAFE_LDO,
  74. .ops = &rt5033_safe_ldo_ops,
  75. .type = REGULATOR_VOLTAGE,
  76. .owner = THIS_MODULE,
  77. .n_voltages = 1,
  78. .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
  79. .enable_reg = RT5033_REG_CTRL,
  80. .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
  81. },
  82. };
  83. static int rt5033_regulator_probe(struct platform_device *pdev)
  84. {
  85. struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
  86. int ret, i;
  87. struct regulator_config config = {};
  88. config.dev = rt5033->dev;
  89. config.driver_data = rt5033;
  90. for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
  91. struct regulator_dev *regulator;
  92. config.regmap = rt5033->regmap;
  93. regulator = devm_regulator_register(&pdev->dev,
  94. &rt5033_supported_regulators[i], &config);
  95. if (IS_ERR(regulator)) {
  96. ret = PTR_ERR(regulator);
  97. dev_err(&pdev->dev,
  98. "Regulator init failed %d: with error: %d\n",
  99. i, ret);
  100. return ret;
  101. }
  102. }
  103. return 0;
  104. }
  105. static const struct platform_device_id rt5033_regulator_id[] = {
  106. { "rt5033-regulator", },
  107. { }
  108. };
  109. MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
  110. static struct platform_driver rt5033_regulator_driver = {
  111. .driver = {
  112. .name = "rt5033-regulator",
  113. },
  114. .probe = rt5033_regulator_probe,
  115. .id_table = rt5033_regulator_id,
  116. };
  117. module_platform_driver(rt5033_regulator_driver);
  118. MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
  119. MODULE_AUTHOR("Beomho Seo <[email protected]>");
  120. MODULE_LICENSE("GPL");