rt5033-regulator.c 3.8 KB

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