tps65090-regulator.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/err.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/driver.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/mfd/tps65090.h>
  24. #include <linux/regulator/tps65090-regulator.h>
  25. struct tps65090_regulator {
  26. int id;
  27. /* used by regulator core */
  28. struct regulator_desc desc;
  29. /* Device */
  30. struct device *dev;
  31. };
  32. static struct regulator_ops tps65090_ops = {
  33. .enable = regulator_enable_regmap,
  34. .disable = regulator_disable_regmap,
  35. .is_enabled = regulator_is_enabled_regmap,
  36. };
  37. #define tps65090_REG(_id) \
  38. { \
  39. .id = TPS65090_ID_##_id, \
  40. .desc = { \
  41. .name = tps65090_rails(_id), \
  42. .id = TPS65090_ID_##_id, \
  43. .ops = &tps65090_ops, \
  44. .type = REGULATOR_VOLTAGE, \
  45. .owner = THIS_MODULE, \
  46. .enable_reg = (TPS65090_ID_##_id) + 12, \
  47. .enable_mask = BIT(0), \
  48. }, \
  49. }
  50. static struct tps65090_regulator TPS65090_regulator[] = {
  51. tps65090_REG(DCDC1),
  52. tps65090_REG(DCDC2),
  53. tps65090_REG(DCDC3),
  54. tps65090_REG(FET1),
  55. tps65090_REG(FET2),
  56. tps65090_REG(FET3),
  57. tps65090_REG(FET4),
  58. tps65090_REG(FET5),
  59. tps65090_REG(FET6),
  60. tps65090_REG(FET7),
  61. };
  62. static inline struct tps65090_regulator *find_regulator_info(int id)
  63. {
  64. struct tps65090_regulator *ri;
  65. int i;
  66. for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
  67. ri = &TPS65090_regulator[i];
  68. if (ri->desc.id == id)
  69. return ri;
  70. }
  71. return NULL;
  72. }
  73. static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
  74. {
  75. struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
  76. struct tps65090_regulator *ri = NULL;
  77. struct regulator_config config = { };
  78. struct regulator_dev *rdev;
  79. struct tps65090_regulator_platform_data *tps_pdata;
  80. int id = pdev->id;
  81. dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
  82. ri = find_regulator_info(id);
  83. if (ri == NULL) {
  84. dev_err(&pdev->dev, "invalid regulator ID specified\n");
  85. return -EINVAL;
  86. }
  87. tps_pdata = pdev->dev.platform_data;
  88. ri->dev = &pdev->dev;
  89. config.dev = &pdev->dev;
  90. config.init_data = &tps_pdata->regulator;
  91. config.driver_data = ri;
  92. config.regmap = tps65090_mfd->rmap;
  93. rdev = regulator_register(&ri->desc, &config);
  94. if (IS_ERR(rdev)) {
  95. dev_err(&pdev->dev, "failed to register regulator %s\n",
  96. ri->desc.name);
  97. return PTR_ERR(rdev);
  98. }
  99. platform_set_drvdata(pdev, rdev);
  100. return 0;
  101. }
  102. static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
  103. {
  104. struct regulator_dev *rdev = platform_get_drvdata(pdev);
  105. regulator_unregister(rdev);
  106. return 0;
  107. }
  108. static struct platform_driver tps65090_regulator_driver = {
  109. .driver = {
  110. .name = "tps65090-regulator",
  111. .owner = THIS_MODULE,
  112. },
  113. .probe = tps65090_regulator_probe,
  114. .remove = __devexit_p(tps65090_regulator_remove),
  115. };
  116. static int __init tps65090_regulator_init(void)
  117. {
  118. return platform_driver_register(&tps65090_regulator_driver);
  119. }
  120. subsys_initcall(tps65090_regulator_init);
  121. static void __exit tps65090_regulator_exit(void)
  122. {
  123. platform_driver_unregister(&tps65090_regulator_driver);
  124. }
  125. module_exit(tps65090_regulator_exit);
  126. MODULE_DESCRIPTION("tps65090 regulator driver");
  127. MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
  128. MODULE_LICENSE("GPL v2");