vreg.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* arch/arm/mach-msm/vreg.c
  2. *
  3. * Copyright (C) 2008 Google, Inc.
  4. * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  5. * Author: Brian Swetland <swetland@google.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/device.h>
  19. #include <linux/init.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/string.h>
  22. #include <mach/vreg.h>
  23. #include "proc_comm.h"
  24. struct vreg {
  25. const char *name;
  26. unsigned id;
  27. int status;
  28. unsigned refcnt;
  29. };
  30. #define VREG(_name, _id, _status, _refcnt) \
  31. { .name = _name, .id = _id, .status = _status, .refcnt = _refcnt }
  32. static struct vreg vregs[] = {
  33. VREG("msma", 0, 0, 0),
  34. VREG("msmp", 1, 0, 0),
  35. VREG("msme1", 2, 0, 0),
  36. VREG("msmc1", 3, 0, 0),
  37. VREG("msmc2", 4, 0, 0),
  38. VREG("gp3", 5, 0, 0),
  39. VREG("msme2", 6, 0, 0),
  40. VREG("gp4", 7, 0, 0),
  41. VREG("gp1", 8, 0, 0),
  42. VREG("tcxo", 9, 0, 0),
  43. VREG("pa", 10, 0, 0),
  44. VREG("rftx", 11, 0, 0),
  45. VREG("rfrx1", 12, 0, 0),
  46. VREG("rfrx2", 13, 0, 0),
  47. VREG("synt", 14, 0, 0),
  48. VREG("wlan", 15, 0, 0),
  49. VREG("usb", 16, 0, 0),
  50. VREG("boost", 17, 0, 0),
  51. VREG("mmc", 18, 0, 0),
  52. VREG("ruim", 19, 0, 0),
  53. VREG("msmc0", 20, 0, 0),
  54. VREG("gp2", 21, 0, 0),
  55. VREG("gp5", 22, 0, 0),
  56. VREG("gp6", 23, 0, 0),
  57. VREG("rf", 24, 0, 0),
  58. VREG("rf_vco", 26, 0, 0),
  59. VREG("mpll", 27, 0, 0),
  60. VREG("s2", 28, 0, 0),
  61. VREG("s3", 29, 0, 0),
  62. VREG("rfubm", 30, 0, 0),
  63. VREG("ncp", 31, 0, 0),
  64. VREG("gp7", 32, 0, 0),
  65. VREG("gp8", 33, 0, 0),
  66. VREG("gp9", 34, 0, 0),
  67. VREG("gp10", 35, 0, 0),
  68. VREG("gp11", 36, 0, 0),
  69. VREG("gp12", 37, 0, 0),
  70. VREG("gp13", 38, 0, 0),
  71. VREG("gp14", 39, 0, 0),
  72. VREG("gp15", 40, 0, 0),
  73. VREG("gp16", 41, 0, 0),
  74. VREG("gp17", 42, 0, 0),
  75. VREG("s4", 43, 0, 0),
  76. VREG("usb2", 44, 0, 0),
  77. VREG("wlan2", 45, 0, 0),
  78. VREG("xo_out", 46, 0, 0),
  79. VREG("lvsw0", 47, 0, 0),
  80. VREG("lvsw1", 48, 0, 0),
  81. };
  82. struct vreg *vreg_get(struct device *dev, const char *id)
  83. {
  84. int n;
  85. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  86. if (!strcmp(vregs[n].name, id))
  87. return vregs + n;
  88. }
  89. return ERR_PTR(-ENOENT);
  90. }
  91. void vreg_put(struct vreg *vreg)
  92. {
  93. }
  94. int vreg_enable(struct vreg *vreg)
  95. {
  96. unsigned id = vreg->id;
  97. unsigned enable = 1;
  98. if (vreg->refcnt == 0)
  99. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  100. if ((vreg->refcnt < UINT_MAX) && (!vreg->status))
  101. vreg->refcnt++;
  102. return vreg->status;
  103. }
  104. int vreg_disable(struct vreg *vreg)
  105. {
  106. unsigned id = vreg->id;
  107. unsigned enable = 0;
  108. if (!vreg->refcnt)
  109. return 0;
  110. if (vreg->refcnt == 1)
  111. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  112. if (!vreg->status)
  113. vreg->refcnt--;
  114. return vreg->status;
  115. }
  116. int vreg_set_level(struct vreg *vreg, unsigned mv)
  117. {
  118. unsigned id = vreg->id;
  119. vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
  120. return vreg->status;
  121. }
  122. #if defined(CONFIG_DEBUG_FS)
  123. static int vreg_debug_set(void *data, u64 val)
  124. {
  125. struct vreg *vreg = data;
  126. switch (val) {
  127. case 0:
  128. vreg_disable(vreg);
  129. break;
  130. case 1:
  131. vreg_enable(vreg);
  132. break;
  133. default:
  134. vreg_set_level(vreg, val);
  135. break;
  136. }
  137. return 0;
  138. }
  139. static int vreg_debug_get(void *data, u64 *val)
  140. {
  141. struct vreg *vreg = data;
  142. if (!vreg->status)
  143. *val = 0;
  144. else
  145. *val = 1;
  146. return 0;
  147. }
  148. static int vreg_debug_count_set(void *data, u64 val)
  149. {
  150. struct vreg *vreg = data;
  151. if (val > UINT_MAX)
  152. val = UINT_MAX;
  153. vreg->refcnt = val;
  154. return 0;
  155. }
  156. static int vreg_debug_count_get(void *data, u64 *val)
  157. {
  158. struct vreg *vreg = data;
  159. *val = vreg->refcnt;
  160. return 0;
  161. }
  162. DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
  163. DEFINE_SIMPLE_ATTRIBUTE(vreg_count_fops, vreg_debug_count_get,
  164. vreg_debug_count_set, "%llu\n");
  165. static int __init vreg_debug_init(void)
  166. {
  167. struct dentry *dent;
  168. int n;
  169. char name[32];
  170. const char *refcnt_name = "_refcnt";
  171. dent = debugfs_create_dir("vreg", 0);
  172. if (IS_ERR(dent))
  173. return 0;
  174. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  175. (void) debugfs_create_file(vregs[n].name, 0644,
  176. dent, vregs + n, &vreg_fops);
  177. strlcpy(name, vregs[n].name, sizeof(name));
  178. strlcat(name, refcnt_name, sizeof(name));
  179. (void) debugfs_create_file(name, 0644,
  180. dent, vregs + n, &vreg_count_fops);
  181. }
  182. return 0;
  183. }
  184. device_initcall(vreg_debug_init);
  185. #endif