OSHW-DEIMOS/SOFTWARE/A64-TERES/linux-a64/drivers/net/wireless/bcmdhd/dhd_gpio.c
Dimitar Gamishev f9b0e7a283 linux
2017-10-13 14:07:04 +03:00

161 lines
3.8 KiB
C
Executable File

#include <osl.h>
#include <dngl_stats.h>
#include <dhd.h>
#ifdef CONFIG_MACH_ODROID_4210
#include <mach/gpio.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <plat/sdhci.h>
#include <plat/devs.h>
#define sdmmc_channel s3c_device_hsmmc0
#endif
#ifdef CUSTOMER_HW_ALLWINNER
#include <linux/gpio.h>
extern void sunxi_mmc_rescan_card(unsigned ids);
extern void sunxi_wlan_set_power(int on);
extern int sunxi_wlan_get_bus_index(void);
extern int sunxi_wlan_get_oob_irq(void);
extern int sunxi_wlan_get_oob_irq_flags(void);
#endif
struct wifi_platform_data dhd_wlan_control = {0};
#ifdef CUSTOMER_OOB
uint bcm_wlan_get_oob_irq(void)
{
uint host_oob_irq = 0;
#ifdef CONFIG_MACH_ODROID_4210
printk("GPIO(WL_HOST_WAKE) = EXYNOS4_GPX0(7) = %d\n", EXYNOS4_GPX0(7));
host_oob_irq = gpio_to_irq(EXYNOS4_GPX0(7));
gpio_direction_input(EXYNOS4_GPX0(7));
#endif
#ifdef CUSTOMER_HW_ALLWINNER
host_oob_irq = sunxi_wlan_get_oob_irq();
#endif
printk("host_oob_irq: %d \r\n", host_oob_irq);
return host_oob_irq;
}
uint bcm_wlan_get_oob_irq_flags(void)
{
uint host_oob_irq_flags = 0;
#ifdef CONFIG_MACH_ODROID_4210
host_oob_irq_flags = (IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE) & IRQF_TRIGGER_MASK;
#endif
#ifdef CUSTOMER_HW_ALLWINNER
host_oob_irq_flags = sunxi_wlan_get_oob_irq_flags();
#endif
printk("host_oob_irq_flags=%d\n", host_oob_irq_flags);
return host_oob_irq_flags;
}
#endif
int bcm_wlan_set_power(bool on)
{
int err = 0;
if (on) {
printk("======== PULL WL_REG_ON HIGH! ========\n");
#ifdef CONFIG_MACH_ODROID_4210
err = gpio_set_value(EXYNOS4_GPK1(0), 1);
#endif
#ifdef CUSTOMER_HW_ALLWINNER
sunxi_wlan_set_power(1);
#endif
/* Lets customer power to get stable */
mdelay(100);
} else {
printk("======== PULL WL_REG_ON LOW! ========\n");
#ifdef CONFIG_MACH_ODROID_4210
err = gpio_set_value(EXYNOS4_GPK1(0), 0);
#endif
#ifdef CUSTOMER_HW_ALLWINNER
sunxi_wlan_set_power(0);
#endif
}
return err;
}
int bcm_wlan_set_carddetect(bool present)
{
int err = 0;
#ifdef CUSTOMER_HW_ALLWINNER
int wlan_bus_index = sunxi_wlan_get_bus_index();
if(wlan_bus_index < 0)
return wlan_bus_index;
#endif
if (present) {
printk("======== Card detection to detect SDIO card! ========\n");
#ifdef CONFIG_MACH_ODROID_4210
err = sdhci_s3c_force_presence_change(&sdmmc_channel, 1);
#endif
#ifdef CUSTOMER_HW_ALLWINNER
sunxi_mmc_rescan_card(wlan_bus_index);
#endif
} else {
printk("======== Card detection to remove SDIO card! ========\n");
#ifdef CONFIG_MACH_ODROID_4210
err = sdhci_s3c_force_presence_change(&sdmmc_channel, 0);
#endif
#ifdef CUSTOMER_HW_ALLWINNER
sunxi_mmc_rescan_card(wlan_bus_index);
#endif
}
return err;
}
int bcm_wlan_get_mac_address(unsigned char *buf)
{
int err = 0;
printk("======== %s ========\n", __FUNCTION__);
#ifdef EXAMPLE_GET_MAC
/* EXAMPLE code */
{
struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
}
#endif /* EXAMPLE_GET_MAC */
return err;
}
#ifdef CONFIG_DHD_USE_STATIC_BUF
extern void *bcmdhd_mem_prealloc(int section, unsigned long size);
void* bcm_wlan_prealloc(int section, unsigned long size)
{
void *alloc_ptr = NULL;
alloc_ptr = bcmdhd_mem_prealloc(section, size);
if (alloc_ptr) {
printk("success alloc section %d, size %ld\n", section, size);
if (size != 0L)
bzero(alloc_ptr, size);
return alloc_ptr;
}
printk("can't alloc section %d\n", section);
return NULL;
}
#endif
int bcm_wlan_set_plat_data(void) {
printk("======== %s ========\n", __FUNCTION__);
dhd_wlan_control.set_power = bcm_wlan_set_power;
dhd_wlan_control.set_carddetect = bcm_wlan_set_carddetect;
dhd_wlan_control.get_mac_addr = bcm_wlan_get_mac_address;
#ifdef CONFIG_DHD_USE_STATIC_BUF
dhd_wlan_control.mem_prealloc = bcm_wlan_prealloc;
#endif
return 0;
}