platform_ARM_SUNxI_sdio.c 2.8 KB

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