platform_ARM_SUNxI_sdio.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include <drv_types.h>
  16. #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
  17. #ifdef CONFIG_WITS_EVB_V13
  18. #define SDIOID 0
  19. #else /* !CONFIG_WITS_EVB_V13 */
  20. #define SDIOID (CONFIG_CHIP_ID == 1123 ? 3 : 1)
  21. #endif /* !CONFIG_WITS_EVB_V13 */
  22. #define SUNXI_SDIO_WIFI_NUM_RTL8189ES 10
  23. extern void sunximmc_rescan_card(unsigned id, unsigned insert);
  24. extern int mmc_pm_get_mod_type(void);
  25. extern int mmc_pm_gpio_ctrl(char *name, int level);
  26. /*
  27. * rtl8189es_shdn = port:PH09<1><default><default><0>
  28. * rtl8189es_wakeup = port:PH10<1><default><default><1>
  29. * rtl8189es_vdd_en = port:PH11<1><default><default><0>
  30. * rtl8189es_vcc_en = port:PH12<1><default><default><0>
  31. */
  32. int rtl8189es_sdio_powerup(void)
  33. {
  34. mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 1);
  35. udelay(100);
  36. mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 1);
  37. udelay(50);
  38. mmc_pm_gpio_ctrl("rtl8189es_shdn", 1);
  39. return 0;
  40. }
  41. int rtl8189es_sdio_poweroff(void)
  42. {
  43. mmc_pm_gpio_ctrl("rtl8189es_shdn", 0);
  44. mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 0);
  45. mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 0);
  46. return 0;
  47. }
  48. #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
  49. /*
  50. * Return:
  51. * 0: power on successfully
  52. * others: power on failed
  53. */
  54. int platform_wifi_power_on(void)
  55. {
  56. int ret = 0;
  57. #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
  58. unsigned int mod_sel = mmc_pm_get_mod_type();
  59. #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
  60. #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
  61. if (mod_sel == SUNXI_SDIO_WIFI_NUM_RTL8189ES) {
  62. rtl8189es_sdio_powerup();
  63. sunximmc_rescan_card(SDIOID, 1);
  64. printk("[rtl8189es] %s: power up, rescan card.\n", __FUNCTION__);
  65. } else {
  66. ret = -1;
  67. printk("[rtl8189es] %s: mod_sel = %d is incorrect.\n", __FUNCTION__, mod_sel);
  68. }
  69. #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
  70. return ret;
  71. }
  72. void platform_wifi_power_off(void)
  73. {
  74. #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
  75. sunximmc_rescan_card(SDIOID, 0);
  76. #ifdef CONFIG_RTL8188E
  77. rtl8189es_sdio_poweroff();
  78. printk("[rtl8189es] %s: remove card, power off.\n", __FUNCTION__);
  79. #endif /* CONFIG_RTL8188E */
  80. #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
  81. }