pcf50633-regulator.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* NXP PCF50633 PMIC Driver
  2. *
  3. * (C) 2006-2008 by Openmoko, Inc.
  4. * Author: Balaji Rao <balajirrao@openmoko.org>
  5. * All rights reserved.
  6. *
  7. * Broken down from monstrous PCF50633 driver mainly by
  8. * Harald Welte and Andy Green and Werner Almesberger
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/device.h>
  20. #include <linux/err.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/mfd/pcf50633/core.h>
  23. #include <linux/mfd/pcf50633/pmic.h>
  24. #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \
  25. { \
  26. .name = _name, \
  27. .id = PCF50633_REGULATOR_##_id, \
  28. .ops = &pcf50633_regulator_ops, \
  29. .n_voltages = _n, \
  30. .min_uV = _min_uV, \
  31. .uV_step = _uV_step, \
  32. .linear_min_sel = _min_sel, \
  33. .type = REGULATOR_VOLTAGE, \
  34. .owner = THIS_MODULE, \
  35. .vsel_reg = PCF50633_REG_##_id##OUT, \
  36. .vsel_mask = 0xff, \
  37. .enable_reg = PCF50633_REG_##_id##OUT + 1, \
  38. .enable_mask = PCF50633_REGULATOR_ON, \
  39. }
  40. static struct regulator_ops pcf50633_regulator_ops = {
  41. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  42. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  43. .list_voltage = regulator_list_voltage_linear,
  44. .map_voltage = regulator_map_voltage_linear,
  45. .enable = regulator_enable_regmap,
  46. .disable = regulator_disable_regmap,
  47. .is_enabled = regulator_is_enabled_regmap,
  48. };
  49. static const struct regulator_desc regulators[] = {
  50. [PCF50633_REGULATOR_AUTO] =
  51. PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128),
  52. [PCF50633_REGULATOR_DOWN1] =
  53. PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96),
  54. [PCF50633_REGULATOR_DOWN2] =
  55. PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96),
  56. [PCF50633_REGULATOR_LDO1] =
  57. PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28),
  58. [PCF50633_REGULATOR_LDO2] =
  59. PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28),
  60. [PCF50633_REGULATOR_LDO3] =
  61. PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28),
  62. [PCF50633_REGULATOR_LDO4] =
  63. PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28),
  64. [PCF50633_REGULATOR_LDO5] =
  65. PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28),
  66. [PCF50633_REGULATOR_LDO6] =
  67. PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28),
  68. [PCF50633_REGULATOR_HCLDO] =
  69. PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28),
  70. [PCF50633_REGULATOR_MEMLDO] =
  71. PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28),
  72. };
  73. static int pcf50633_regulator_probe(struct platform_device *pdev)
  74. {
  75. struct regulator_dev *rdev;
  76. struct pcf50633 *pcf;
  77. struct regulator_config config = { };
  78. /* Already set by core driver */
  79. pcf = dev_to_pcf50633(pdev->dev.parent);
  80. config.dev = &pdev->dev;
  81. config.init_data = dev_get_platdata(&pdev->dev);
  82. config.driver_data = pcf;
  83. config.regmap = pcf->regmap;
  84. rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id],
  85. &config);
  86. if (IS_ERR(rdev))
  87. return PTR_ERR(rdev);
  88. platform_set_drvdata(pdev, rdev);
  89. if (pcf->pdata->regulator_registered)
  90. pcf->pdata->regulator_registered(pcf, pdev->id);
  91. return 0;
  92. }
  93. static struct platform_driver pcf50633_regulator_driver = {
  94. .driver = {
  95. .name = "pcf50633-regulator",
  96. },
  97. .probe = pcf50633_regulator_probe,
  98. };
  99. static int __init pcf50633_regulator_init(void)
  100. {
  101. return platform_driver_register(&pcf50633_regulator_driver);
  102. }
  103. subsys_initcall(pcf50633_regulator_init);
  104. static void __exit pcf50633_regulator_exit(void)
  105. {
  106. platform_driver_unregister(&pcf50633_regulator_driver);
  107. }
  108. module_exit(pcf50633_regulator_exit);
  109. MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
  110. MODULE_DESCRIPTION("PCF50633 regulator driver");
  111. MODULE_LICENSE("GPL");
  112. MODULE_ALIAS("platform:pcf50633-regulator");