vreg.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <mach/vreg.h>
  22. #include "proc_comm.h"
  23. struct vreg {
  24. const char *name;
  25. unsigned id;
  26. int status;
  27. };
  28. #define VREG(_name, _id, _status) \
  29. { .name = _name, .id = _id, .status = _status }
  30. static struct vreg vregs[] = {
  31. VREG("msma", 0, 0),
  32. VREG("msmp", 1, 0),
  33. VREG("msme1", 2, 0),
  34. VREG("msmc1", 3, 0),
  35. VREG("msmc2", 4, 0),
  36. VREG("gp3", 5, 0),
  37. VREG("msme2", 6, 0),
  38. VREG("gp4", 7, 0),
  39. VREG("gp1", 8, 0),
  40. VREG("tcxo", 9, 0),
  41. VREG("pa", 10, 0),
  42. VREG("rftx", 11, 0),
  43. VREG("rfrx1", 12, 0),
  44. VREG("rfrx2", 13, 0),
  45. VREG("synt", 14, 0),
  46. VREG("wlan", 15, 0),
  47. VREG("usb", 16, 0),
  48. VREG("boost", 17, 0),
  49. VREG("mmc", 18, 0),
  50. VREG("ruim", 19, 0),
  51. VREG("msmc0", 20, 0),
  52. VREG("gp2", 21, 0),
  53. VREG("gp5", 22, 0),
  54. VREG("gp6", 23, 0),
  55. VREG("rf", 24, 0),
  56. VREG("rf_vco", 26, 0),
  57. VREG("mpll", 27, 0),
  58. VREG("s2", 28, 0),
  59. VREG("s3", 29, 0),
  60. VREG("rfubm", 30, 0),
  61. VREG("ncp", 31, 0),
  62. };
  63. struct vreg *vreg_get(struct device *dev, const char *id)
  64. {
  65. int n;
  66. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  67. if (!strcmp(vregs[n].name, id))
  68. return vregs + n;
  69. }
  70. return ERR_PTR(-ENOENT);
  71. }
  72. void vreg_put(struct vreg *vreg)
  73. {
  74. }
  75. int vreg_enable(struct vreg *vreg)
  76. {
  77. unsigned id = vreg->id;
  78. unsigned enable = 1;
  79. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  80. return vreg->status;
  81. }
  82. int vreg_disable(struct vreg *vreg)
  83. {
  84. unsigned id = vreg->id;
  85. unsigned enable = 0;
  86. vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  87. return vreg->status;
  88. }
  89. int vreg_set_level(struct vreg *vreg, unsigned mv)
  90. {
  91. unsigned id = vreg->id;
  92. vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
  93. return vreg->status;
  94. }
  95. #if defined(CONFIG_DEBUG_FS)
  96. static int vreg_debug_set(void *data, u64 val)
  97. {
  98. struct vreg *vreg = data;
  99. switch (val) {
  100. case 0:
  101. vreg_disable(vreg);
  102. break;
  103. case 1:
  104. vreg_enable(vreg);
  105. break;
  106. default:
  107. vreg_set_level(vreg, val);
  108. break;
  109. }
  110. return 0;
  111. }
  112. static int vreg_debug_get(void *data, u64 *val)
  113. {
  114. struct vreg *vreg = data;
  115. if (!vreg->status)
  116. *val = 0;
  117. else
  118. *val = 1;
  119. return 0;
  120. }
  121. DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
  122. static int __init vreg_debug_init(void)
  123. {
  124. struct dentry *dent;
  125. int n;
  126. dent = debugfs_create_dir("vreg", 0);
  127. if (IS_ERR(dent))
  128. return 0;
  129. for (n = 0; n < ARRAY_SIZE(vregs); n++)
  130. (void) debugfs_create_file(vregs[n].name, 0644,
  131. dent, vregs + n, &vreg_fops);
  132. return 0;
  133. }
  134. device_initcall(vreg_debug_init);
  135. #endif