qcomwlan7x27a_pwrif.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* Copyright (c) 2011, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/regulator/consumer.h>
  14. #include <linux/gpio.h>
  15. #include <mach/rpc_pmapp.h>
  16. #include <linux/err.h>
  17. #include <linux/qcomwlan7x27a_pwrif.h>
  18. #include <linux/module.h>
  19. #define WLAN_GPIO_EXT_POR_N 134
  20. static const char *id = "WLAN";
  21. enum {
  22. WLAN_VREG_L17 = 0,
  23. WLAN_VREG_S3,
  24. WLAN_VREG_TCXO_L11,
  25. WLAN_VREG_L19,
  26. WLAN_VREG_L5,
  27. WLAN_VREG_L6
  28. };
  29. struct wlan_vreg_info {
  30. const char *vreg_id;
  31. unsigned int level_min;
  32. unsigned int level_max;
  33. unsigned int pmapp_id;
  34. unsigned int is_vreg_pin_controlled;
  35. struct regulator *reg;
  36. };
  37. static struct wlan_vreg_info vreg_info[] = {
  38. {"bt", 3050000, 3050000, 21, 1, NULL},
  39. {"msme1", 1800000, 1800000, 2, 0, NULL},
  40. {"wlan_tcx0", 1800000, 1800000, 53, 0, NULL},
  41. {"wlan4", 1200000, 1200000, 23, 0, NULL},
  42. {"wlan2", 1350000, 1350000, 9, 1, NULL},
  43. {"wlan3", 1200000, 1200000, 10, 1, NULL},
  44. };
  45. static int qrf6285_init_regs(void)
  46. {
  47. struct regulator_bulk_data regs[ARRAY_SIZE(vreg_info)];
  48. int i, rc;
  49. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  50. regs[i].supply = vreg_info[i].vreg_id;
  51. regs[i].min_uV = vreg_info[i].level_min;
  52. regs[i].max_uV = vreg_info[i].level_max;
  53. }
  54. rc = regulator_bulk_get(NULL, ARRAY_SIZE(regs), regs);
  55. if (rc) {
  56. pr_err("%s: could not get regulators: %d\n", __func__, rc);
  57. goto out;
  58. }
  59. for (i = 0; i < ARRAY_SIZE(regs); i++)
  60. vreg_info[i].reg = regs[i].consumer;
  61. return 0;
  62. out:
  63. return rc;
  64. }
  65. int chip_power_qrf6285(bool on)
  66. {
  67. static bool init_done;
  68. int rc = 0, index = 0;
  69. if (unlikely(!init_done)) {
  70. rc = qrf6285_init_regs();
  71. if (rc)
  72. return rc;
  73. else
  74. init_done = true;
  75. }
  76. if (on) {
  77. rc = gpio_request(WLAN_GPIO_EXT_POR_N, "WLAN_DEEP_SLEEP_N");
  78. if (rc) {
  79. pr_err("WLAN reset GPIO %d request failed %d\n",
  80. WLAN_GPIO_EXT_POR_N, rc);
  81. goto fail;
  82. }
  83. rc = gpio_direction_output(WLAN_GPIO_EXT_POR_N, 1);
  84. if (rc < 0) {
  85. pr_err("WLAN reset GPIO %d set direction failed %d\n",
  86. WLAN_GPIO_EXT_POR_N, rc);
  87. goto fail_gpio_dir_out;
  88. }
  89. rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_A0,
  90. PMAPP_CLOCK_VOTE_ON);
  91. if (rc) {
  92. pr_err("%s: Configuring A0 to always"
  93. " on failed %d\n", __func__, rc);
  94. goto clock_vote_fail;
  95. }
  96. } else {
  97. gpio_set_value_cansleep(WLAN_GPIO_EXT_POR_N, 0);
  98. rc = gpio_direction_input(WLAN_GPIO_EXT_POR_N);
  99. if (rc) {
  100. pr_err("WLAN reset GPIO %d set direction failed %d\n",
  101. WLAN_GPIO_EXT_POR_N, rc);
  102. }
  103. gpio_free(WLAN_GPIO_EXT_POR_N);
  104. rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_A0,
  105. PMAPP_CLOCK_VOTE_OFF);
  106. if (rc) {
  107. pr_err("%s: Configuring A0 to turn OFF"
  108. " failed %d\n", __func__, rc);
  109. }
  110. }
  111. for (index = 0; index < ARRAY_SIZE(vreg_info); index++) {
  112. if (on) {
  113. rc = regulator_set_voltage(vreg_info[index].reg,
  114. vreg_info[index].level_min,
  115. vreg_info[index].level_max);
  116. if (rc) {
  117. pr_err("%s:%s set voltage failed %d\n",
  118. __func__, vreg_info[index].vreg_id, rc);
  119. goto vreg_fail;
  120. }
  121. rc = regulator_enable(vreg_info[index].reg);
  122. if (rc) {
  123. pr_err("%s:%s vreg enable failed %d\n",
  124. __func__, vreg_info[index].vreg_id, rc);
  125. goto vreg_fail;
  126. }
  127. if (vreg_info[index].is_vreg_pin_controlled) {
  128. rc = pmapp_vreg_lpm_pincntrl_vote(id,
  129. vreg_info[index].pmapp_id,
  130. PMAPP_CLOCK_ID_A0, 1);
  131. if (rc) {
  132. pr_err("%s:%s pmapp_vreg_lpm_pincntrl"
  133. " for enable failed %d\n",
  134. __func__,
  135. vreg_info[index].vreg_id, rc);
  136. goto vreg_clock_vote_fail;
  137. }
  138. }
  139. /*At this point CLK_PWR_REQ is high*/
  140. if (WLAN_VREG_L6 == index) {
  141. /*
  142. * Configure A0 clock to be slave to
  143. * WLAN_CLK_PWR_REQ
  144. ` */
  145. rc = pmapp_clock_vote(id, PMAPP_CLOCK_ID_A0,
  146. PMAPP_CLOCK_VOTE_PIN_CTRL);
  147. if (rc) {
  148. pr_err("%s: Configuring A0 to Pin"
  149. " controllable failed %d\n",
  150. __func__, rc);
  151. goto vreg_clock_vote_fail;
  152. }
  153. }
  154. } else {
  155. if (vreg_info[index].is_vreg_pin_controlled) {
  156. rc = pmapp_vreg_lpm_pincntrl_vote(id,
  157. vreg_info[index].pmapp_id,
  158. PMAPP_CLOCK_ID_A0, 0);
  159. if (rc) {
  160. pr_err("%s:%s pmapp_vreg_lpm_pincntrl"
  161. " for disable failed %d\n",
  162. __func__,
  163. vreg_info[index].vreg_id, rc);
  164. }
  165. }
  166. rc = regulator_disable(vreg_info[index].reg);
  167. if (rc) {
  168. pr_err("%s:%s vreg disable failed %d\n",
  169. __func__, vreg_info[index].vreg_id, rc);
  170. }
  171. }
  172. }
  173. return 0;
  174. vreg_fail:
  175. index--;
  176. vreg_clock_vote_fail:
  177. while (index >= 0) {
  178. rc = regulator_disable(vreg_info[index].reg);
  179. if (rc) {
  180. pr_err("%s:%s vreg disable failed %d\n",
  181. __func__, vreg_info[index].vreg_id, rc);
  182. }
  183. index--;
  184. }
  185. if (!on)
  186. goto fail;
  187. clock_vote_fail:
  188. gpio_set_value_cansleep(WLAN_GPIO_EXT_POR_N, 0);
  189. rc = gpio_direction_input(WLAN_GPIO_EXT_POR_N);
  190. if (rc) {
  191. pr_err("WLAN reset GPIO %d set direction failed %d\n",
  192. WLAN_GPIO_EXT_POR_N, rc);
  193. }
  194. fail_gpio_dir_out:
  195. gpio_free(WLAN_GPIO_EXT_POR_N);
  196. fail:
  197. return rc;
  198. }
  199. EXPORT_SYMBOL(chip_power_qrf6285);