platform_ARM_SUNnI_sdio.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2013 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. /*
  21. * Description:
  22. * This file can be applied to following platforms:
  23. * CONFIG_PLATFORM_ARM_SUN6I
  24. * CONFIG_PLATFORM_ARM_SUN7I
  25. * CONFIG_PLATFORM_ARM_SUN8I
  26. */
  27. #include <drv_types.h>
  28. #include <mach/sys_config.h>
  29. #ifdef CONFIG_GPIO_WAKEUP
  30. #include <linux/gpio.h>
  31. #endif
  32. #ifdef CONFIG_MMC
  33. static int sdc_id = -1;
  34. static signed int gpio_eint_wlan = -1;
  35. static u32 eint_wlan_handle = 0;
  36. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  37. extern void sw_mci_rescan_card(unsigned id, unsigned insert);
  38. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  39. extern void sunxi_mci_rescan_card(unsigned id, unsigned insert);
  40. #endif
  41. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  42. extern int get_rf_mod_type(void);
  43. #else
  44. extern int wifi_pm_get_mod_type(void);
  45. #endif
  46. extern void wifi_pm_power(int on);
  47. #ifdef CONFIG_GPIO_WAKEUP
  48. extern unsigned int oob_irq;
  49. #endif
  50. #endif /* CONFIG_MMC */
  51. /*
  52. * Return:
  53. * 0: power on successfully
  54. * others: power on failed
  55. */
  56. int platform_wifi_power_on(void)
  57. {
  58. int ret = 0;
  59. #ifdef CONFIG_MMC
  60. {
  61. script_item_u val;
  62. script_item_value_type_e type;
  63. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  64. unsigned int mod_sel = get_rf_mod_type();
  65. #else
  66. unsigned int mod_sel = wifi_pm_get_mod_type();
  67. #endif
  68. type = script_get_item("wifi_para", "wifi_sdc_id", &val);
  69. if (SCIRPT_ITEM_VALUE_TYPE_INT != type) {
  70. RTW_INFO("get wifi_sdc_id failed\n");
  71. ret = -1;
  72. } else {
  73. sdc_id = val.val;
  74. RTW_INFO("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel);
  75. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  76. sw_mci_rescan_card(sdc_id, 1);
  77. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  78. sunxi_mci_rescan_card(sdc_id, 1);
  79. #endif
  80. mdelay(100);
  81. wifi_pm_power(1);
  82. RTW_INFO("%s: power up, rescan card.\n", __FUNCTION__);
  83. }
  84. #ifdef CONFIG_GPIO_WAKEUP
  85. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  86. type = script_get_item("wifi_para", "wl_host_wake", &val);
  87. #else
  88. #ifdef CONFIG_RTL8723B
  89. type = script_get_item("wifi_para", "rtl8723bs_wl_host_wake", &val);
  90. #endif
  91. #ifdef CONFIG_RTL8188E
  92. type = script_get_item("wifi_para", "rtl8189es_host_wake", &val);
  93. #endif
  94. #endif /* CONFIG_PLATFORM_ARM_SUN8I_W5P1 */
  95. if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {
  96. RTW_INFO("No definition of wake up host PIN\n");
  97. ret = -1;
  98. } else {
  99. gpio_eint_wlan = val.gpio.gpio;
  100. #ifdef CONFIG_PLATFORM_ARM_SUN8I
  101. oob_irq = gpio_to_irq(gpio_eint_wlan);
  102. #endif
  103. }
  104. #endif /* CONFIG_GPIO_WAKEUP */
  105. }
  106. #endif /* CONFIG_MMC */
  107. return ret;
  108. }
  109. void platform_wifi_power_off(void)
  110. {
  111. #ifdef CONFIG_MMC
  112. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  113. sw_mci_rescan_card(sdc_id, 0);
  114. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  115. sunxi_mci_rescan_card(sdc_id, 0);
  116. #endif
  117. mdelay(100);
  118. wifi_pm_power(0);
  119. RTW_INFO("%s: remove card, power off.\n", __FUNCTION__);
  120. #endif /* CONFIG_MMC */
  121. }