Path: blob/master/ALFA-W1F1/RTL8814AU/platform/platform_hisilicon_hi3798_sdio.c
1307 views
/******************************************************************************1*2* Copyright(c) 2017 - 2018 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#include <linux/delay.h> /* mdelay() */15#include <mach/hardware.h> /* __io_address(), readl(), writel() */16#include "platform_hisilicon_hi3798_sdio.h" /* HI_S32() and etc. */1718typedef enum hi_GPIO_DIR_E {19HI_DIR_OUT = 0,20HI_DIR_IN = 1,21} HI_GPIO_DIR_E;2223#define RTL_REG_ON_GPIO (4*8 + 3)2425#define REG_BASE_CTRL __io_address(0xf8a20008)2627int gpio_wlan_reg_on = RTL_REG_ON_GPIO;28#if 029module_param(gpio_wlan_reg_on, uint, 0644);30MODULE_PARM_DESC(gpio_wlan_reg_on, "wlan reg_on gpio num (default:gpio4_3)");31#endif3233static int hi_gpio_set_value(u32 gpio, u32 value)34{35HI_S32 s32Status;3637s32Status = HI_DRV_GPIO_SetDirBit(gpio, HI_DIR_OUT);38if (s32Status != HI_SUCCESS) {39pr_err("gpio(%d) HI_DRV_GPIO_SetDirBit HI_DIR_OUT failed\n",40gpio);41return -1;42}4344s32Status = HI_DRV_GPIO_WriteBit(gpio, value);45if (s32Status != HI_SUCCESS) {46pr_err("gpio(%d) HI_DRV_GPIO_WriteBit value(%d) failed\n",47gpio, value);48return -1;49}5051return 0;52}5354static int hisi_wlan_set_carddetect(bool present)55{56u32 regval;57u32 mask;585960#ifndef CONFIG_HISI_SDIO_ID61return;62#endif63pr_info("SDIO ID=%d\n", CONFIG_HISI_SDIO_ID);64#if (CONFIG_HISI_SDIO_ID == 1)65mask = 1;66#elif (CONFIG_HISI_SDIO_ID == 0)67mask = 2;68#endif6970regval = readl(REG_BASE_CTRL);71if (present) {72pr_info("====== Card detection to detect SDIO card! ======\n");73/* set card_detect low to detect card */74regval |= mask;75} else {76pr_info("====== Card detection to remove SDIO card! ======\n");77/* set card_detect high to remove card */78regval &= ~(mask);79}80writel(regval, REG_BASE_CTRL);8182return 0;83}8485/*86* Return:87* 0: power on successfully88* others: power on failed89*/90int platform_wifi_power_on(void)91{92int ret = 0;939495hi_gpio_set_value(gpio_wlan_reg_on, 1);96mdelay(100);97hisi_wlan_set_carddetect(1);98mdelay(2000);99pr_info("======== set_carddetect delay 2s! ========\n");100101return ret;102}103104void platform_wifi_power_off(void)105{106hisi_wlan_set_carddetect(0);107mdelay(100);108hi_gpio_set_value(gpio_wlan_reg_on, 0);109}110111112