platform_hisilicon_hi3798_sdio.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2017 - 2018 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 <linux/delay.h> /* mdelay() */
  16. #include <mach/hardware.h> /* __io_address(), readl(), writel() */
  17. #include "platform_hisilicon_hi3798_sdio.h" /* HI_S32() and etc. */
  18. typedef enum hi_GPIO_DIR_E {
  19. HI_DIR_OUT = 0,
  20. HI_DIR_IN = 1,
  21. } HI_GPIO_DIR_E;
  22. #define RTL_REG_ON_GPIO (4*8 + 3)
  23. #define REG_BASE_CTRL __io_address(0xf8a20008)
  24. int gpio_wlan_reg_on = RTL_REG_ON_GPIO;
  25. #if 0
  26. module_param(gpio_wlan_reg_on, uint, 0644);
  27. MODULE_PARM_DESC(gpio_wlan_reg_on, "wlan reg_on gpio num (default:gpio4_3)");
  28. #endif
  29. static int hi_gpio_set_value(u32 gpio, u32 value)
  30. {
  31. HI_S32 s32Status;
  32. s32Status = HI_DRV_GPIO_SetDirBit(gpio, HI_DIR_OUT);
  33. if (s32Status != HI_SUCCESS) {
  34. pr_err("gpio(%d) HI_DRV_GPIO_SetDirBit HI_DIR_OUT failed\n",
  35. gpio);
  36. return -1;
  37. }
  38. s32Status = HI_DRV_GPIO_WriteBit(gpio, value);
  39. if (s32Status != HI_SUCCESS) {
  40. pr_err("gpio(%d) HI_DRV_GPIO_WriteBit value(%d) failed\n",
  41. gpio, value);
  42. return -1;
  43. }
  44. return 0;
  45. }
  46. static int hisi_wlan_set_carddetect(bool present)
  47. {
  48. u32 regval;
  49. u32 mask;
  50. #ifndef CONFIG_HISI_SDIO_ID
  51. return;
  52. #endif
  53. pr_info("SDIO ID=%d\n", CONFIG_HISI_SDIO_ID);
  54. #if (CONFIG_HISI_SDIO_ID == 1)
  55. mask = 1;
  56. #elif (CONFIG_HISI_SDIO_ID == 0)
  57. mask = 2;
  58. #endif
  59. regval = readl(REG_BASE_CTRL);
  60. if (present) {
  61. pr_info("====== Card detection to detect SDIO card! ======\n");
  62. /* set card_detect low to detect card */
  63. regval |= mask;
  64. } else {
  65. pr_info("====== Card detection to remove SDIO card! ======\n");
  66. /* set card_detect high to remove card */
  67. regval &= ~(mask);
  68. }
  69. writel(regval, REG_BASE_CTRL);
  70. return 0;
  71. }
  72. /*
  73. * Return:
  74. * 0: power on successfully
  75. * others: power on failed
  76. */
  77. int platform_wifi_power_on(void)
  78. {
  79. int ret = 0;
  80. hi_gpio_set_value(gpio_wlan_reg_on, 1);
  81. mdelay(100);
  82. hisi_wlan_set_carddetect(1);
  83. mdelay(2000);
  84. pr_info("======== set_carddetect delay 2s! ========\n");
  85. return ret;
  86. }
  87. void platform_wifi_power_off(void)
  88. {
  89. hisi_wlan_set_carddetect(0);
  90. mdelay(100);
  91. hi_gpio_set_value(gpio_wlan_reg_on, 0);
  92. }