mc13xxx.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
  3. *
  4. * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef __LINUX_REGULATOR_MC13XXX_H
  12. #define __LINUX_REGULATOR_MC13XXX_H
  13. #include <linux/regulator/driver.h>
  14. struct mc13xxx_regulator {
  15. struct regulator_desc desc;
  16. int reg;
  17. int enable_bit;
  18. int vsel_reg;
  19. int vsel_shift;
  20. int vsel_mask;
  21. int hi_bit;
  22. int const *voltages;
  23. };
  24. struct mc13xxx_regulator_priv {
  25. struct mc13xxx *mc13xxx;
  26. u32 powermisc_pwgt_state;
  27. struct mc13xxx_regulator *mc13xxx_regulators;
  28. int num_regulators;
  29. struct regulator_dev *regulators[];
  30. };
  31. extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
  32. extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
  33. extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
  34. int min_uV, int max_uV);
  35. extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
  36. unsigned selector);
  37. extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
  38. int min_uV, int max_uV, unsigned *selector);
  39. extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
  40. #ifdef CONFIG_OF
  41. extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
  42. extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
  43. struct platform_device *pdev, struct mc13xxx_regulator *regulators,
  44. int num_regulators);
  45. #else
  46. static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
  47. {
  48. return -ENODEV;
  49. }
  50. static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
  51. struct platform_device *pdev, struct mc13xxx_regulator *regulators,
  52. int num_regulators)
  53. {
  54. return NULL;
  55. }
  56. #endif
  57. extern struct regulator_ops mc13xxx_regulator_ops;
  58. extern struct regulator_ops mc13xxx_fixed_regulator_ops;
  59. #define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \
  60. [prefix ## _name] = { \
  61. .desc = { \
  62. .name = #_name, \
  63. .n_voltages = ARRAY_SIZE(_voltages), \
  64. .ops = &_ops, \
  65. .type = REGULATOR_VOLTAGE, \
  66. .id = prefix ## _name, \
  67. .owner = THIS_MODULE, \
  68. }, \
  69. .reg = prefix ## _reg, \
  70. .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
  71. .vsel_reg = prefix ## _vsel_reg, \
  72. .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
  73. .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
  74. .voltages = _voltages, \
  75. }
  76. #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
  77. [prefix ## _name] = { \
  78. .desc = { \
  79. .name = #_name, \
  80. .n_voltages = ARRAY_SIZE(_voltages), \
  81. .ops = &_ops, \
  82. .type = REGULATOR_VOLTAGE, \
  83. .id = prefix ## _name, \
  84. .owner = THIS_MODULE, \
  85. }, \
  86. .reg = prefix ## _reg, \
  87. .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
  88. .voltages = _voltages, \
  89. }
  90. #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
  91. [prefix ## _name] = { \
  92. .desc = { \
  93. .name = #_name, \
  94. .n_voltages = ARRAY_SIZE(_voltages), \
  95. .ops = &_ops, \
  96. .type = REGULATOR_VOLTAGE, \
  97. .id = prefix ## _name, \
  98. .owner = THIS_MODULE, \
  99. }, \
  100. .reg = prefix ## _reg, \
  101. .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
  102. .voltages = _voltages, \
  103. }
  104. #define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
  105. MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
  106. #define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \
  107. MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)
  108. #endif