tps65090-regulator.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Regulator driver for tps65090 power management chip.
  3. *
  4. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/err.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/regulator/driver.h>
  21. #include <linux/regulator/machine.h>
  22. #include <linux/mfd/tps65090.h>
  23. #include <linux/regulator/tps65090-regulator.h>
  24. struct tps65090_regulator {
  25. int id;
  26. /* used by regulator core */
  27. struct regulator_desc desc;
  28. /* Device */
  29. struct device *dev;
  30. };
  31. static struct regulator_ops tps65090_ops = {
  32. .enable = regulator_enable_regmap,
  33. .disable = regulator_disable_regmap,
  34. .is_enabled = regulator_is_enabled_regmap,
  35. };
  36. #define tps65090_REG(_id) \
  37. { \
  38. .id = TPS65090_ID_##_id, \
  39. .desc = { \
  40. .name = tps65090_rails(_id), \
  41. .id = TPS65090_ID_##_id, \
  42. .ops = &tps65090_ops, \
  43. .type = REGULATOR_VOLTAGE, \
  44. .owner = THIS_MODULE, \
  45. .enable_reg = (TPS65090_ID_##_id) + 12, \
  46. .enable_mask = BIT(0), \
  47. }, \
  48. }
  49. static struct tps65090_regulator TPS65090_regulator[] = {
  50. tps65090_REG(DCDC1),
  51. tps65090_REG(DCDC2),
  52. tps65090_REG(DCDC3),
  53. tps65090_REG(FET1),
  54. tps65090_REG(FET2),
  55. tps65090_REG(FET3),
  56. tps65090_REG(FET4),
  57. tps65090_REG(FET5),
  58. tps65090_REG(FET6),
  59. tps65090_REG(FET7),
  60. };
  61. static inline struct tps65090_regulator *find_regulator_info(int id)
  62. {
  63. struct tps65090_regulator *ri;
  64. int i;
  65. for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
  66. ri = &TPS65090_regulator[i];
  67. if (ri->desc.id == id)
  68. return ri;
  69. }
  70. return NULL;
  71. }
  72. static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
  73. {
  74. struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
  75. struct tps65090_regulator *ri = NULL;
  76. struct regulator_config config = { };
  77. struct regulator_dev *rdev;
  78. struct tps65090_regulator_platform_data *tps_pdata;
  79. int id = pdev->id;
  80. dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
  81. ri = find_regulator_info(id);
  82. if (ri == NULL) {
  83. dev_err(&pdev->dev, "invalid regulator ID specified\n");
  84. return -EINVAL;
  85. }
  86. tps_pdata = pdev->dev.platform_data;
  87. ri->dev = &pdev->dev;
  88. config.dev = &pdev->dev;
  89. config.init_data = &tps_pdata->regulator;
  90. config.driver_data = ri;
  91. config.regmap = tps65090_mfd->rmap;
  92. rdev = regulator_register(&ri->desc, &config);
  93. if (IS_ERR(rdev)) {
  94. dev_err(&pdev->dev, "failed to register regulator %s\n",
  95. ri->desc.name);
  96. return PTR_ERR(rdev);
  97. }
  98. platform_set_drvdata(pdev, rdev);
  99. return 0;
  100. }
  101. static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
  102. {
  103. struct regulator_dev *rdev = platform_get_drvdata(pdev);
  104. regulator_unregister(rdev);
  105. return 0;
  106. }
  107. static struct platform_driver tps65090_regulator_driver = {
  108. .driver = {
  109. .name = "tps65090-regulator",
  110. .owner = THIS_MODULE,
  111. },
  112. .probe = tps65090_regulator_probe,
  113. .remove = __devexit_p(tps65090_regulator_remove),
  114. };
  115. static int __init tps65090_regulator_init(void)
  116. {
  117. return platform_driver_register(&tps65090_regulator_driver);
  118. }
  119. subsys_initcall(tps65090_regulator_init);
  120. static void __exit tps65090_regulator_exit(void)
  121. {
  122. platform_driver_unregister(&tps65090_regulator_driver);
  123. }
  124. module_exit(tps65090_regulator_exit);
  125. MODULE_DESCRIPTION("tps65090 regulator driver");
  126. MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
  127. MODULE_LICENSE("GPL v2");