rt5033-regulator.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Regulator driver for the Richtek RT5033
  3. *
  4. * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
  5. * Author: Beomho Seo <beomho.seo@samsung.com>
  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. .id = RT5033_BUCK,
  36. .ops = &rt5033_buck_ops,
  37. .type = REGULATOR_VOLTAGE,
  38. .owner = THIS_MODULE,
  39. .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
  40. .min_uV = RT5033_REGULATOR_BUCK_VOLTAGE_MIN,
  41. .uV_step = RT5033_REGULATOR_BUCK_VOLTAGE_STEP,
  42. .enable_reg = RT5033_REG_CTRL,
  43. .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
  44. .vsel_reg = RT5033_REG_BUCK_CTRL,
  45. .vsel_mask = RT5033_BUCK_CTRL_MASK,
  46. },
  47. [RT5033_LDO] = {
  48. .name = "LDO",
  49. .id = RT5033_LDO,
  50. .ops = &rt5033_buck_ops,
  51. .type = REGULATOR_VOLTAGE,
  52. .owner = THIS_MODULE,
  53. .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
  54. .min_uV = RT5033_REGULATOR_LDO_VOLTAGE_MIN,
  55. .uV_step = RT5033_REGULATOR_LDO_VOLTAGE_STEP,
  56. .enable_reg = RT5033_REG_CTRL,
  57. .enable_mask = RT5033_CTRL_EN_LDO_MASK,
  58. .vsel_reg = RT5033_REG_LDO_CTRL,
  59. .vsel_mask = RT5033_LDO_CTRL_MASK,
  60. },
  61. [RT5033_SAFE_LDO] = {
  62. .name = "SAFE_LDO",
  63. .id = RT5033_SAFE_LDO,
  64. .ops = &rt5033_safe_ldo_ops,
  65. .type = REGULATOR_VOLTAGE,
  66. .owner = THIS_MODULE,
  67. .n_voltages = 1,
  68. .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
  69. .enable_reg = RT5033_REG_CTRL,
  70. .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
  71. },
  72. };
  73. static int rt5033_regulator_probe(struct platform_device *pdev)
  74. {
  75. struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
  76. int ret, i;
  77. struct regulator_config config = {};
  78. config.dev = &pdev->dev;
  79. config.driver_data = rt5033;
  80. for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
  81. struct regulator_dev *regulator;
  82. config.regmap = rt5033->regmap;
  83. regulator = devm_regulator_register(&pdev->dev,
  84. &rt5033_supported_regulators[i], &config);
  85. if (IS_ERR(regulator)) {
  86. ret = PTR_ERR(regulator);
  87. dev_err(&pdev->dev,
  88. "Regulator init failed %d: with error: %d\n",
  89. i, ret);
  90. return ret;
  91. }
  92. }
  93. return 0;
  94. }
  95. static const struct platform_device_id rt5033_regulator_id[] = {
  96. { "rt5033-regulator", },
  97. { }
  98. };
  99. MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
  100. static struct platform_driver rt5033_regulator_driver = {
  101. .driver = {
  102. .name = "rt5033-regulator",
  103. },
  104. .probe = rt5033_regulator_probe,
  105. .id_table = rt5033_regulator_id,
  106. };
  107. module_platform_driver(rt5033_regulator_driver);
  108. MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
  109. MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
  110. MODULE_LICENSE("GPL");