xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/dhd_custom_rockchip.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #ifdef CONFIG_DHD_PLAT_ROCKCHIP
2 #include <osl.h>
3 #include <dhd_linux.h>
4 #include <linux/gpio.h>
5 #include <linux/rfkill-wlan.h>
6 
7 static int dhd_wlan_set_power(int on);
8 static int dhd_wlan_set_reset(int onoff);
9 static int dhd_wlan_set_carddetect(int present);
10 static int dhd_wlan_get_mac_addr(unsigned char *buf);
11 static void *dhd_wlan_get_country_code(char *ccode
12 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined(CUSTOM_COUNTRY_CODE)
13     , u32 flags
14 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) */
15     );
16 
17 struct wifi_platform_data dhd_wlan_control = {
18 	.set_power	= dhd_wlan_set_power,
19 	.set_reset	= dhd_wlan_set_reset,
20 	.set_carddetect	= dhd_wlan_set_carddetect,
21 	.get_mac_addr	= dhd_wlan_get_mac_addr,
22 	.get_country_code = dhd_wlan_get_country_code,
23 };
24 
25 struct resource dhd_wlan_resources = {
26 		.name	= "bcmdhd_wlan_irq",
27 		.start	= 0,
28 		.end	= 0,
29 		.flags	= IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE,
30 };
31 
32 static struct cntry_locales_custom brcm_wlan_translate_custom_table[] = {
33 	/* Table should be filled out based on custom platform regulatory requirement */
34 	{"",   "XT", 49},  /* Universal if Country code is unknown or empty */
35 	{"US", "US", 0},
36 };
37 
38 #ifdef CUSTOM_FORCE_NODFS_FLAG
39 struct cntry_locales_custom brcm_wlan_translate_nodfs_table[] = {
40 	{"",   "XT", 50},  /* Universal if Country code is unknown or empty */
41 	{"US", "US", 0},
42 };
43 #endif /* CUSTOM_FORCE_NODFS_FLAG */
44 
dhd_wlan_set_power(int on)45 static int dhd_wlan_set_power(int on)
46 {
47 	return rockchip_wifi_power(on);
48 }
49 
dhd_wlan_set_reset(int onoff)50 static int dhd_wlan_set_reset(int onoff)
51 {
52 	return 0;
53 }
54 
dhd_wlan_set_carddetect(int present)55 static int dhd_wlan_set_carddetect(int present)
56 {
57 	return rockchip_wifi_set_carddetect(present);
58 }
59 
dhd_wlan_get_mac_addr(unsigned char * buf)60 static int dhd_wlan_get_mac_addr(unsigned char *buf)
61 {
62 	return rockchip_wifi_mac_addr(buf);
63 }
64 
dhd_wlan_get_country_code(char * ccode,u32 flags)65 static void *dhd_wlan_get_country_code(char *ccode
66 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) || defined(CUSTOM_COUNTRY_CODE)
67     , u32 flags
68 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58)) */
69     )
70 {
71 	struct cntry_locales_custom *locales;
72 	int size;
73 	int i;
74 
75 	if (!ccode)
76 		return NULL;
77 
78 #ifdef CUSTOM_FORCE_NODFS_FLAG
79 	if (flags & WLAN_PLAT_NODFS_FLAG) {
80 		locales = brcm_wlan_translate_nodfs_table;
81 		size = ARRAY_SIZE(brcm_wlan_translate_nodfs_table);
82 	} else {
83 #endif
84 		locales = brcm_wlan_translate_custom_table;
85 		size = ARRAY_SIZE(brcm_wlan_translate_custom_table);
86 #ifdef CUSTOM_FORCE_NODFS_FLAG
87 	}
88 #endif
89 
90 	for (i = 0; i < size; i++)
91 		if (strcmp(ccode, locales[i].iso_abbrev) == 0)
92 			return &locales[i];
93 	return NULL;
94 }
95 
96 
dhd_wlan_init_plat_data(void)97 int dhd_wlan_init_plat_data(void)
98 {
99     uint irq;
100 	int irq_flags = -1;
101 
102 	printf("%s, enter", __FUNCTION__);
103 
104     irq = rockchip_wifi_get_oob_irq();
105 
106 	printf("%s, irq = %d", __FUNCTION__, irq);
107 
108     dhd_wlan_resources.start = irq;
109     dhd_wlan_resources.end = irq;
110 
111 	irq_flags = rockchip_wifi_get_oob_irq_flag();
112 	if (irq_flags == 1) {
113 		dhd_wlan_resources.flags |= IORESOURCE_IRQ_HIGHLEVEL;
114     } else if (irq_flags == 0) {
115 		dhd_wlan_resources.flags |= IORESOURCE_IRQ_LOWLEVEL;
116     } else {
117 		pr_warn("%s: unknown oob irqflags !\n", __func__);
118     }
119 
120 	return 0;
121 }
122 
dhd_wlan_deinit_plat_data(void)123 int dhd_wlan_deinit_plat_data(void)
124 {
125     return 0;
126 }
127 #endif /* CONFIG_DHD_PLAT_ROCKCHIP */
128