vreg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. };
  65. struct vreg *vreg_get(struct device *dev, const char *id)
  66. {
  67. int n;
  68. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  69. if (!strcmp(vregs[n].name, id))
  70. return vregs + n;
  71. }
  72. return ERR_PTR(-ENOENT);
  73. }
  74. void vreg_put(struct vreg *vreg)
  75. {
  76. }
  77. int vreg_enable(struct vreg *vreg)
  78. {
  79. unsigned id = vreg->id;
  80. unsigned enable = 1;
  81. if (vreg->refcnt == 0)
  82. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  83. if ((vreg->refcnt < UINT_MAX) && (!vreg->status))
  84. vreg->refcnt++;
  85. return vreg->status;
  86. }
  87. int vreg_disable(struct vreg *vreg)
  88. {
  89. unsigned id = vreg->id;
  90. unsigned enable = 0;
  91. if (!vreg->refcnt)
  92. return 0;
  93. if (vreg->refcnt == 1)
  94. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  95. if (!vreg->status)
  96. vreg->refcnt--;
  97. return vreg->status;
  98. }
  99. int vreg_set_level(struct vreg *vreg, unsigned mv)
  100. {
  101. unsigned id = vreg->id;
  102. vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
  103. return vreg->status;
  104. }
  105. #if defined(CONFIG_DEBUG_FS)
  106. static int vreg_debug_set(void *data, u64 val)
  107. {
  108. struct vreg *vreg = data;
  109. switch (val) {
  110. case 0:
  111. vreg_disable(vreg);
  112. break;
  113. case 1:
  114. vreg_enable(vreg);
  115. break;
  116. default:
  117. vreg_set_level(vreg, val);
  118. break;
  119. }
  120. return 0;
  121. }
  122. static int vreg_debug_get(void *data, u64 *val)
  123. {
  124. struct vreg *vreg = data;
  125. if (!vreg->status)
  126. *val = 0;
  127. else
  128. *val = 1;
  129. return 0;
  130. }
  131. static int vreg_debug_count_set(void *data, u64 val)
  132. {
  133. struct vreg *vreg = data;
  134. if (val > UINT_MAX)
  135. val = UINT_MAX;
  136. vreg->refcnt = val;
  137. return 0;
  138. }
  139. static int vreg_debug_count_get(void *data, u64 *val)
  140. {
  141. struct vreg *vreg = data;
  142. *val = vreg->refcnt;
  143. return 0;
  144. }
  145. DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
  146. DEFINE_SIMPLE_ATTRIBUTE(vreg_count_fops, vreg_debug_count_get,
  147. vreg_debug_count_set, "%llu\n");
  148. static int __init vreg_debug_init(void)
  149. {
  150. struct dentry *dent;
  151. int n;
  152. char name[32];
  153. const char *refcnt_name = "_refcnt";
  154. dent = debugfs_create_dir("vreg", 0);
  155. if (IS_ERR(dent))
  156. return 0;
  157. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  158. (void) debugfs_create_file(vregs[n].name, 0644,
  159. dent, vregs + n, &vreg_fops);
  160. strlcpy(name, vregs[n].name, sizeof(name));
  161. strlcat(name, refcnt_name, sizeof(name));
  162. (void) debugfs_create_file(name, 0644,
  163. dent, vregs + n, &vreg_count_fops);
  164. }
  165. return 0;
  166. }
  167. device_initcall(vreg_debug_init);
  168. #endif