dhd_custom_msm.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Platform Dependent file for Qualcomm MSM/APQ
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. * <<Broadcom-WL-IPTag/Open:>>
  27. *
  28. * $Id: dhd_custom_msm.c 695148 2017-04-19 04:15:17Z $
  29. *
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/delay.h>
  35. #include <linux/err.h>
  36. #include <linux/gpio.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/wlan_plat.h>
  39. #include <linux/mmc/host.h>
  40. #include <linux/msm_pcie.h>
  41. #include <linux/fcntl.h>
  42. #include <linux/fs.h>
  43. #include <linux/of_gpio.h>
  44. #if defined(CONFIG_ARCH_MSM8996) || defined(CONFIG_ARCH_MSM8998) || \
  45. defined(CONFIG_ARCH_SDM845) || defined(CONFIG_ARCH_SM8150)
  46. #include <linux/msm_pcie.h>
  47. #endif /* CONFIG_ARCH_MSM8996 || CONFIG_ARCH_MSM8998 ||
  48. CONFIG_ARCH_SDM845 || CONFIG_ARCH_SM8150
  49. */
  50. #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
  51. extern int dhd_init_wlan_mem(void);
  52. extern void *dhd_wlan_mem_prealloc(int section, unsigned long size);
  53. #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */
  54. #define WIFI_TURNON_DELAY 200
  55. static int wlan_reg_on = -1;
  56. #define DHD_DT_COMPAT_ENTRY "android,bcmdhd_wlan"
  57. #ifdef CUSTOMER_HW2
  58. #define WIFI_WL_REG_ON_PROPNAME "wl_reg_on"
  59. #else
  60. #define WIFI_WL_REG_ON_PROPNAME "wlan-en-gpio"
  61. #endif /* CUSTOMER_HW2 */
  62. #if defined(CONFIG_ARCH_MSM8996) || defined(CONFIG_ARCH_MSM8998) || \
  63. defined(CONFIG_ARCH_SDM845) || defined(CONFIG_ARCH_SM8150)
  64. #define MSM_PCIE_CH_NUM 0
  65. #else
  66. #define MSM_PCIE_CH_NUM 1
  67. #endif /* CONFIG_ARCH_MSM8996 || CONFIG_ARCH_MSM8998
  68. || CONFIG_ARCH_SDM845 || CONFIG_ARCH_SM8150
  69. */
  70. #ifdef CONFIG_BCMDHD_OOB_HOST_WAKE
  71. static int wlan_host_wake_up = -1;
  72. static int wlan_host_wake_irq = 0;
  73. #ifdef CUSTOMER_HW2
  74. #define WIFI_WLAN_HOST_WAKE_PROPNAME "wl_host_wake"
  75. #else
  76. #define WIFI_WLAN_HOST_WAKE_PROPNAME "wlan-host-wake-gpio"
  77. #endif /* CUSTOMER_HW2 */
  78. #endif /* CONFIG_BCMDHD_OOB_HOST_WAKE */
  79. int __init
  80. dhd_wifi_init_gpio(void)
  81. {
  82. char *wlan_node = DHD_DT_COMPAT_ENTRY;
  83. struct device_node *root_node = NULL;
  84. root_node = of_find_compatible_node(NULL, NULL, wlan_node);
  85. if (!root_node) {
  86. WARN(1, "failed to get device node of BRCM WLAN\n");
  87. return -ENODEV;
  88. }
  89. /* ========== WLAN_PWR_EN ============ */
  90. wlan_reg_on = of_get_named_gpio(root_node, WIFI_WL_REG_ON_PROPNAME, 0);
  91. printk(KERN_INFO "%s: gpio_wlan_power : %d\n", __FUNCTION__, wlan_reg_on);
  92. if (gpio_request_one(wlan_reg_on, GPIOF_OUT_INIT_LOW, "WL_REG_ON")) {
  93. printk(KERN_ERR "%s: Faiiled to request gpio %d for WL_REG_ON\n",
  94. __FUNCTION__, wlan_reg_on);
  95. } else {
  96. printk(KERN_ERR "%s: gpio_request WL_REG_ON done - WLAN_EN: GPIO %d\n",
  97. __FUNCTION__, wlan_reg_on);
  98. }
  99. if (gpio_direction_output(wlan_reg_on, 1)) {
  100. printk(KERN_ERR "%s: WL_REG_ON failed to pull up\n", __FUNCTION__);
  101. } else {
  102. printk(KERN_ERR "%s: WL_REG_ON is pulled up\n", __FUNCTION__);
  103. }
  104. if (gpio_get_value(wlan_reg_on)) {
  105. printk(KERN_INFO "%s: Initial WL_REG_ON: [%d]\n",
  106. __FUNCTION__, gpio_get_value(wlan_reg_on));
  107. }
  108. /* Wait for WIFI_TURNON_DELAY due to power stability */
  109. msleep(WIFI_TURNON_DELAY);
  110. #ifdef CONFIG_BCMDHD_OOB_HOST_WAKE
  111. /* ========== WLAN_HOST_WAKE ============ */
  112. wlan_host_wake_up = of_get_named_gpio(root_node, WIFI_WLAN_HOST_WAKE_PROPNAME, 0);
  113. printk(KERN_INFO "%s: gpio_wlan_host_wake : %d\n", __FUNCTION__, wlan_host_wake_up);
  114. #ifndef CUSTOMER_HW2
  115. if (gpio_request_one(wlan_host_wake_up, GPIOF_IN, "WLAN_HOST_WAKE")) {
  116. printk(KERN_ERR "%s: Faiiled to request gpio %d for WLAN_HOST_WAKE\n",
  117. __FUNCTION__, wlan_host_wake_up);
  118. return -ENODEV;
  119. } else {
  120. printk(KERN_ERR "%s: gpio_request WLAN_HOST_WAKE done"
  121. " - WLAN_HOST_WAKE: GPIO %d\n",
  122. __FUNCTION__, wlan_host_wake_up);
  123. }
  124. #endif /* !CUSTOMER_HW2 */
  125. gpio_direction_input(wlan_host_wake_up);
  126. wlan_host_wake_irq = gpio_to_irq(wlan_host_wake_up);
  127. #endif /* CONFIG_BCMDHD_OOB_HOST_WAKE */
  128. #if defined(CONFIG_BCM4359) || defined(CONFIG_BCM4361) || defined(CONFIG_BCM4375)
  129. printk(KERN_INFO "%s: Call msm_pcie_enumerate\n", __FUNCTION__);
  130. msm_pcie_enumerate(MSM_PCIE_CH_NUM);
  131. #endif /* CONFIG_BCM4359 || CONFIG_BCM4361 || CONFIG_BCM4375 */
  132. return 0;
  133. }
  134. int
  135. dhd_wlan_power(int onoff)
  136. {
  137. printk(KERN_INFO"------------------------------------------------");
  138. printk(KERN_INFO"------------------------------------------------\n");
  139. printk(KERN_INFO"%s Enter: power %s\n", __func__, onoff ? "on" : "off");
  140. if (onoff) {
  141. if (gpio_direction_output(wlan_reg_on, 1)) {
  142. printk(KERN_ERR "%s: WL_REG_ON is failed to pull up\n", __FUNCTION__);
  143. return -EIO;
  144. }
  145. if (gpio_get_value(wlan_reg_on)) {
  146. printk(KERN_INFO"WL_REG_ON on-step-2 : [%d]\n",
  147. gpio_get_value(wlan_reg_on));
  148. } else {
  149. printk("[%s] gpio value is 0. We need reinit.\n", __func__);
  150. if (gpio_direction_output(wlan_reg_on, 1)) {
  151. printk(KERN_ERR "%s: WL_REG_ON is "
  152. "failed to pull up\n", __func__);
  153. }
  154. }
  155. } else {
  156. if (gpio_direction_output(wlan_reg_on, 0)) {
  157. printk(KERN_ERR "%s: WL_REG_ON is failed to pull up\n", __FUNCTION__);
  158. return -EIO;
  159. }
  160. if (gpio_get_value(wlan_reg_on)) {
  161. printk(KERN_INFO"WL_REG_ON on-step-2 : [%d]\n",
  162. gpio_get_value(wlan_reg_on));
  163. }
  164. }
  165. return 0;
  166. }
  167. EXPORT_SYMBOL(dhd_wlan_power);
  168. static int
  169. dhd_wlan_reset(int onoff)
  170. {
  171. return 0;
  172. }
  173. static int
  174. dhd_wlan_set_carddetect(int val)
  175. {
  176. return 0;
  177. }
  178. #if defined(CONFIG_BCMDHD_OOB_HOST_WAKE) && defined(CONFIG_BCMDHD_GET_OOB_STATE)
  179. int
  180. dhd_get_wlan_oob_gpio(void)
  181. {
  182. return gpio_is_valid(wlan_host_wake_up) ?
  183. gpio_get_value(wlan_host_wake_up) : -1;
  184. }
  185. EXPORT_SYMBOL(dhd_get_wlan_oob_gpio);
  186. #endif /* CONFIG_BCMDHD_OOB_HOST_WAKE && CONFIG_BCMDHD_GET_OOB_STATE */
  187. struct resource dhd_wlan_resources = {
  188. .name = "bcmdhd_wlan_irq",
  189. .start = 0, /* Dummy */
  190. .end = 0, /* Dummy */
  191. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE |
  192. #ifdef CONFIG_BCMDHD_PCIE
  193. IORESOURCE_IRQ_HIGHEDGE,
  194. #else
  195. IORESOURCE_IRQ_HIGHLEVEL,
  196. #endif /* CONFIG_BCMDHD_PCIE */
  197. };
  198. EXPORT_SYMBOL(dhd_wlan_resources);
  199. struct wifi_platform_data dhd_wlan_control = {
  200. .set_power = dhd_wlan_power,
  201. .set_reset = dhd_wlan_reset,
  202. .set_carddetect = dhd_wlan_set_carddetect,
  203. #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
  204. .mem_prealloc = dhd_wlan_mem_prealloc,
  205. #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */
  206. };
  207. EXPORT_SYMBOL(dhd_wlan_control);
  208. int __init
  209. dhd_wlan_init(void)
  210. {
  211. int ret;
  212. printk(KERN_INFO"%s: START.......\n", __FUNCTION__);
  213. ret = dhd_wifi_init_gpio();
  214. if (ret < 0) {
  215. printk(KERN_ERR "%s: failed to initiate GPIO, ret=%d\n",
  216. __FUNCTION__, ret);
  217. goto fail;
  218. }
  219. #ifdef CONFIG_BCMDHD_OOB_HOST_WAKE
  220. dhd_wlan_resources.start = wlan_host_wake_irq;
  221. dhd_wlan_resources.end = wlan_host_wake_irq;
  222. #endif /* CONFIG_BCMDHD_OOB_HOST_WAKE */
  223. #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
  224. ret = dhd_init_wlan_mem();
  225. if (ret < 0) {
  226. printk(KERN_ERR "%s: failed to alloc reserved memory,"
  227. " ret=%d\n", __FUNCTION__, ret);
  228. }
  229. #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */
  230. fail:
  231. printk(KERN_INFO"%s: FINISH.......\n", __FUNCTION__);
  232. return ret;
  233. }
  234. #if defined(CONFIG_ARCH_MSM8996) || defined(CONFIG_ARCH_MSM8998) || \
  235. defined(CONFIG_ARCH_SDM845) || defined(CONFIG_ARCH_SM8150)
  236. #if defined(CONFIG_DEFERRED_INITCALLS)
  237. deferred_module_init(dhd_wlan_init);
  238. #else
  239. late_initcall(dhd_wlan_init);
  240. #endif /* CONFIG_DEFERRED_INITCALLS */
  241. #else
  242. device_initcall(dhd_wlan_init);
  243. #endif /* CONFIG_ARCH_MSM8996 || CONFIG_ARCH_MSM8998
  244. * CONFIG_ARCH_SDM845 || CONFIG_ARCH_SM8150
  245. */