voltage.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * arch/arm/mach-meson6/voltage.c
  3. *
  4. * Copyright (C) 2011-2012 Amlogic, Inc.
  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. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/regulator/machine.h>
  23. #include <mach/voltage.h>
  24. struct meson_opp meson_vcck_opp_table[] = {
  25. /* freq must be in descending order */
  26. {
  27. .freq = 1500000,
  28. .min_uV = 1209000,
  29. .max_uV = 1209000,
  30. },
  31. {
  32. .freq = 1320000,
  33. .min_uV = 1209000,
  34. .max_uV = 1209000,
  35. },
  36. {
  37. .freq = 1200000,
  38. .min_uV = 1192000,
  39. .max_uV = 1192000,
  40. },
  41. /* {
  42. .freq = 1000000,
  43. .min_uV = 1143000,
  44. .max_uV = 1143000,
  45. },*/
  46. {
  47. .freq = 1080000,
  48. .min_uV = 1110000,
  49. .max_uV = 1110000,
  50. },
  51. {
  52. .freq = 840000,
  53. .min_uV = 1012000,
  54. .max_uV = 1012000,
  55. },
  56. {
  57. .freq = 600000,
  58. .min_uV = 996000,
  59. .max_uV = 996000,
  60. },
  61. {
  62. .freq = 200000,
  63. .min_uV = 979000,
  64. .max_uV = 979000,
  65. }
  66. };
  67. const int meson_vcck_opp_table_size = ARRAY_SIZE(meson_vcck_opp_table);
  68. unsigned int meson_vcck_cur_max_freq(struct regulator *reg,
  69. struct meson_opp *table, int tablesize)
  70. {
  71. int i, v;
  72. if (!reg)
  73. return 0;
  74. v = regulator_get_voltage(reg);
  75. if (v <= 0)
  76. return 0;
  77. for (i = 0; i < tablesize; i++) {
  78. if (table[i].min_uV <= v &&
  79. table[i].max_uV >= v) {
  80. return table[i].freq;
  81. }
  82. }
  83. return 0;
  84. }
  85. EXPORT_SYMBOL(meson_vcck_cur_max_freq);
  86. int meson_vcck_scale(struct regulator *reg, struct meson_opp *table,
  87. int tablesize, unsigned int frequency)
  88. {
  89. int i, optimal;
  90. struct meson_opp *opp;
  91. if (!reg)
  92. return -ENODEV;
  93. optimal = 0;
  94. for (i = 0; i < tablesize; i++) {
  95. if (table[i].freq >= frequency)
  96. optimal = i;
  97. }
  98. opp = &table[optimal];
  99. pr_devel("vcck_set_voltage setting {%u,%u} for %u\n", opp->min_uV, opp->freq, frequency);
  100. return regulator_set_voltage(reg, opp->min_uV, opp->max_uV);
  101. }
  102. EXPORT_SYMBOL(meson_vcck_scale);