platform_ARM_SUNnI_sdio.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2013 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. /*
  16. * Description:
  17. * This file can be applied to following platforms:
  18. * CONFIG_PLATFORM_ARM_SUN6I
  19. * CONFIG_PLATFORM_ARM_SUN7I
  20. * CONFIG_PLATFORM_ARM_SUN8I
  21. */
  22. #include <drv_types.h>
  23. #include <mach/sys_config.h>
  24. #ifdef CONFIG_GPIO_WAKEUP
  25. #include <linux/gpio.h>
  26. #endif
  27. #ifdef CONFIG_MMC
  28. static int sdc_id = -1;
  29. static signed int gpio_eint_wlan = -1;
  30. static u32 eint_wlan_handle = 0;
  31. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  32. extern void sw_mci_rescan_card(unsigned id, unsigned insert);
  33. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  34. extern void sunxi_mci_rescan_card(unsigned id, unsigned insert);
  35. #endif
  36. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  37. extern int get_rf_mod_type(void);
  38. #else
  39. extern int wifi_pm_get_mod_type(void);
  40. #endif
  41. extern void wifi_pm_power(int on);
  42. #ifdef CONFIG_GPIO_WAKEUP
  43. extern unsigned int oob_irq;
  44. #endif
  45. #endif /* CONFIG_MMC */
  46. /*
  47. * Return:
  48. * 0: power on successfully
  49. * others: power on failed
  50. */
  51. int platform_wifi_power_on(void)
  52. {
  53. int ret = 0;
  54. #ifdef CONFIG_MMC
  55. {
  56. script_item_u val;
  57. script_item_value_type_e type;
  58. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  59. unsigned int mod_sel = get_rf_mod_type();
  60. #else
  61. unsigned int mod_sel = wifi_pm_get_mod_type();
  62. #endif
  63. type = script_get_item("wifi_para", "wifi_sdc_id", &val);
  64. if (SCIRPT_ITEM_VALUE_TYPE_INT != type) {
  65. RTW_INFO("get wifi_sdc_id failed\n");
  66. ret = -1;
  67. } else {
  68. sdc_id = val.val;
  69. RTW_INFO("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel);
  70. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  71. sw_mci_rescan_card(sdc_id, 1);
  72. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  73. sunxi_mci_rescan_card(sdc_id, 1);
  74. #endif
  75. mdelay(100);
  76. wifi_pm_power(1);
  77. RTW_INFO("%s: power up, rescan card.\n", __FUNCTION__);
  78. }
  79. #ifdef CONFIG_GPIO_WAKEUP
  80. #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
  81. type = script_get_item("wifi_para", "wl_host_wake", &val);
  82. #else
  83. #ifdef CONFIG_RTL8723B
  84. type = script_get_item("wifi_para", "rtl8723bs_wl_host_wake", &val);
  85. #endif
  86. #ifdef CONFIG_RTL8188E
  87. type = script_get_item("wifi_para", "rtl8189es_host_wake", &val);
  88. #endif
  89. #endif /* CONFIG_PLATFORM_ARM_SUN8I_W5P1 */
  90. if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {
  91. RTW_INFO("No definition of wake up host PIN\n");
  92. ret = -1;
  93. } else {
  94. gpio_eint_wlan = val.gpio.gpio;
  95. #ifdef CONFIG_PLATFORM_ARM_SUN8I
  96. oob_irq = gpio_to_irq(gpio_eint_wlan);
  97. #endif
  98. }
  99. #endif /* CONFIG_GPIO_WAKEUP */
  100. }
  101. #endif /* CONFIG_MMC */
  102. return ret;
  103. }
  104. void platform_wifi_power_off(void)
  105. {
  106. #ifdef CONFIG_MMC
  107. #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
  108. sw_mci_rescan_card(sdc_id, 0);
  109. #elif defined(CONFIG_PLATFORM_ARM_SUN8I)
  110. sunxi_mci_rescan_card(sdc_id, 0);
  111. #endif
  112. mdelay(100);
  113. wifi_pm_power(0);
  114. RTW_INFO("%s: remove card, power off.\n", __FUNCTION__);
  115. #endif /* CONFIG_MMC */
  116. }