vreg.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* arch/arm/mach-msm/vreg.c
  2. *
  3. * Copyright (C) 2008 Google, Inc.
  4. * Author: Brian Swetland <swetland@google.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/device.h>
  18. #include <linux/init.h>
  19. #include <linux/debugfs.h>
  20. #include <mach/vreg.h>
  21. #include "proc_comm.h"
  22. struct vreg {
  23. const char *name;
  24. unsigned id;
  25. };
  26. #define VREG(_name, _id) { .name = _name, .id = _id, }
  27. static struct vreg vregs[] = {
  28. VREG("msma", 0),
  29. VREG("msmp", 1),
  30. VREG("msme1", 2),
  31. VREG("msmc1", 3),
  32. VREG("msmc2", 4),
  33. VREG("gp3", 5),
  34. VREG("msme2", 6),
  35. VREG("gp4", 7),
  36. VREG("gp1", 8),
  37. VREG("tcxo", 9),
  38. VREG("pa", 10),
  39. VREG("rftx", 11),
  40. VREG("rfrx1", 12),
  41. VREG("rfrx2", 13),
  42. VREG("synt", 14),
  43. VREG("wlan", 15),
  44. VREG("usb", 16),
  45. VREG("boost", 17),
  46. VREG("mmc", 18),
  47. VREG("ruim", 19),
  48. VREG("msmc0", 20),
  49. VREG("gp2", 21),
  50. VREG("gp5", 22),
  51. VREG("gp6", 23),
  52. VREG("rf", 24),
  53. VREG("rf_vco", 26),
  54. VREG("mpll", 27),
  55. VREG("s2", 28),
  56. VREG("s3", 29),
  57. VREG("rfubm", 30),
  58. VREG("ncp", 31),
  59. };
  60. struct vreg *vreg_get(struct device *dev, const char *id)
  61. {
  62. int n;
  63. for (n = 0; n < ARRAY_SIZE(vregs); n++) {
  64. if (!strcmp(vregs[n].name, id))
  65. return vregs + n;
  66. }
  67. return 0;
  68. }
  69. void vreg_put(struct vreg *vreg)
  70. {
  71. }
  72. int vreg_enable(struct vreg *vreg)
  73. {
  74. unsigned id = vreg->id;
  75. unsigned enable = 1;
  76. return msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  77. }
  78. void vreg_disable(struct vreg *vreg)
  79. {
  80. unsigned id = vreg->id;
  81. unsigned enable = 0;
  82. msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
  83. }
  84. int vreg_set_level(struct vreg *vreg, unsigned mv)
  85. {
  86. unsigned id = vreg->id;
  87. return msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
  88. }
  89. #if defined(CONFIG_DEBUG_FS)
  90. static int vreg_debug_set(void *data, u64 val)
  91. {
  92. struct vreg *vreg = data;
  93. switch (val) {
  94. case 0:
  95. vreg_disable(vreg);
  96. break;
  97. case 1:
  98. vreg_enable(vreg);
  99. break;
  100. default:
  101. vreg_set_level(vreg, val);
  102. break;
  103. }
  104. return 0;
  105. }
  106. static int vreg_debug_get(void *data, u64 *val)
  107. {
  108. return -ENOSYS;
  109. }
  110. DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
  111. static int __init vreg_debug_init(void)
  112. {
  113. struct dentry *dent;
  114. int n;
  115. dent = debugfs_create_dir("vreg", 0);
  116. if (IS_ERR(dent))
  117. return 0;
  118. for (n = 0; n < ARRAY_SIZE(vregs); n++)
  119. (void) debugfs_create_file(vregs[n].name, 0644,
  120. dent, vregs + n, &vreg_fops);
  121. return 0;
  122. }
  123. device_initcall(vreg_debug_init);
  124. #endif