2 * Linux cfg80211 driver - Android related functions
4 * Copyright (C) 1999-2011, Broadcom Corporation
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
24 * $Id: wl_android.c,v 1.1.4.1.2.14 2011/02/09 01:40:07 Exp $
27 #include <linux/module.h>
28 #include <linux/netdevice.h>
30 #include <wl_android.h>
31 #include <wldev_common.h>
34 #include <linux_osl.h>
36 #include <dngl_stats.h>
40 #include <wl_cfg80211.h>
42 #if defined(CONFIG_WIFI_CONTROL_FUNC)
43 #include <linux/platform_device.h>
44 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
45 #include <linux/wlan_plat.h>
47 #include <linux/wifi_tiwlan.h>
49 #endif /* CONFIG_WIFI_CONTROL_FUNC */
52 * Android private command strings, PLEASE define new private commands here
53 * so they can be updated easily in the future (if needed)
56 #define CMD_START "START"
57 #define CMD_STOP "STOP"
58 #define CMD_SCAN_ACTIVE "SCAN-ACTIVE"
59 #define CMD_SCAN_PASSIVE "SCAN-PASSIVE"
60 #define CMD_RSSI "RSSI"
61 #define CMD_LINKSPEED "LINKSPEED"
62 #define CMD_RXFILTER_START "RXFILTER-START"
63 #define CMD_RXFILTER_STOP "RXFILTER-STOP"
64 #define CMD_RXFILTER_ADD "RXFILTER-ADD"
65 #define CMD_RXFILTER_REMOVE "RXFILTER-REMOVE"
66 #define CMD_BTCOEXSCAN_START "BTCOEXSCAN-START"
67 #define CMD_BTCOEXSCAN_STOP "BTCOEXSCAN-STOP"
68 #define CMD_BTCOEXMODE "BTCOEXMODE"
69 #define CMD_SETSUSPENDOPT "SETSUSPENDOPT"
70 #define CMD_SETSUSPENDMODE "SETSUSPENDMODE"
71 #define CMD_P2P_DEV_ADDR "P2P_DEV_ADDR"
72 #define CMD_SETFWPATH "SETFWPATH"
73 #define CMD_SETBAND "SETBAND"
74 #define CMD_GETBAND "GETBAND"
75 #define CMD_COUNTRY "COUNTRY"
76 #define CMD_P2P_SET_NOA "P2P_SET_NOA"
77 #if !defined WL_ENABLE_P2P_IF
78 #define CMD_P2P_GET_NOA "P2P_GET_NOA"
80 #define CMD_P2P_SET_PS "P2P_SET_PS"
81 #define CMD_SET_AP_WPS_P2P_IE "SET_AP_WPS_P2P_IE"
85 #define CMD_PNOSSIDCLR_SET "PNOSSIDCLR"
86 #define CMD_PNOSETUP_SET "PNOSETUP "
87 #define CMD_PNOENABLE_SET "PNOFORCE"
88 #define CMD_PNODEBUG_SET "PNODEBUG"
90 #define PNO_TLV_PREFIX 'S'
91 #define PNO_TLV_VERSION '1'
92 #define PNO_TLV_SUBVERSION '2'
93 #define PNO_TLV_RESERVED '0'
94 #define PNO_TLV_TYPE_SSID_IE 'S'
95 #define PNO_TLV_TYPE_TIME 'T'
96 #define PNO_TLV_FREQ_REPEAT 'R'
97 #define PNO_TLV_FREQ_EXPO_MAX 'M'
99 typedef struct cmd_tlv {
105 #endif /* PNO_SUPPORT */
107 typedef struct android_wifi_priv_cmd {
111 } android_wifi_priv_cmd;
114 * Extern function declarations (TODO: move them to dhd_linux.h)
116 void dhd_customer_gpio_wlan_ctrl(int onoff);
117 uint dhd_dev_reset(struct net_device *dev, uint8 flag);
118 int dhd_dev_init_ioctl(struct net_device *dev);
120 int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
121 int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, char *command);
123 int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr)
125 int wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len)
127 int wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len)
129 int wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len)
132 extern int dhd_os_check_if_up(void *dhdp);
133 extern void *bcmsdh_get_drvdata(void);
135 extern bool ap_fw_loaded;
137 extern char iface_name[IFNAMSIZ];
141 * Local (static) functions and variables
144 /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
145 * time (only) in dhd_open, subsequential wifi on will be handled by
148 static int g_wifi_on = TRUE;
151 * Local (static) function definitions
153 static int wl_android_get_link_speed(struct net_device *net, char *command, int total_len)
159 error = wldev_get_link_speed(net, &link_speed);
163 /* Convert Kbps to Android Mbps */
164 link_speed = link_speed / 1000;
165 bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
166 DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command));
167 return bytes_written;
170 static int wl_android_get_rssi(struct net_device *net, char *command, int total_len)
172 wlc_ssid_t ssid = {0};
174 int bytes_written = 0;
177 error = wldev_get_rssi(net, &rssi);
181 error = wldev_get_ssid(net, &ssid);
184 if ((ssid.SSID_len == 0) || (ssid.SSID_len > DOT11_MAX_SSID_LEN)) {
185 DHD_ERROR(("%s: wldev_get_ssid failed\n", __FUNCTION__));
187 memcpy(command, ssid.SSID, ssid.SSID_len);
188 bytes_written = ssid.SSID_len;
190 bytes_written += snprintf(&command[bytes_written], total_len, " rssi %d", rssi);
191 DHD_INFO(("%s: command result is %s (%d)\n", __FUNCTION__, command, bytes_written));
192 return bytes_written;
195 static int wl_android_set_suspendopt(struct net_device *dev, char *command, int total_len)
201 suspend_flag = *(command + strlen(CMD_SETSUSPENDOPT) + 1) - '0';
203 if (suspend_flag != 0)
205 ret_now = net_os_set_suspend_disable(dev, suspend_flag);
207 if (ret_now != suspend_flag) {
208 if (!(ret = net_os_set_suspend(dev, ret_now, 1)))
209 DHD_INFO(("%s: Suspend Flag %d -> %d\n",
210 __FUNCTION__, ret_now, suspend_flag));
212 DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret));
217 static int wl_android_set_suspendmode(struct net_device *dev, char *command, int total_len)
221 #if !defined(CONFIG_HAS_EARLYSUSPEND) || !defined(DHD_USE_EARLYSUSPEND)
224 suspend_flag = *(command + strlen(CMD_SETSUSPENDMODE) + 1) - '0';
226 if (suspend_flag != 0)
229 if (!(ret = net_os_set_suspend(dev, suspend_flag, 0)))
230 DHD_INFO(("%s: Suspend Mode %d\n",__FUNCTION__,suspend_flag));
232 DHD_ERROR(("%s: failed %d\n",__FUNCTION__,ret));
237 static int wl_android_get_band(struct net_device *dev, char *command, int total_len)
243 error = wldev_get_band(dev, &band);
246 bytes_written = snprintf(command, total_len, "Band %d", band);
247 return bytes_written;
250 #if defined(PNO_SUPPORT) && !defined(WL_SCHED_SCAN)
251 static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len)
253 wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT];
256 cmd_tlv_t *cmd_tlv_temp;
261 int pno_freq_expo_max = 0;
265 char pno_in_example[] = {
266 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
270 'd', 'l', 'i', 'n', 'k',
282 #endif /* PNO_SET_DEBUG */
284 DHD_INFO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
286 if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) {
287 DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len));
292 memcpy(command, pno_in_example, sizeof(pno_in_example));
293 for (i = 0; i < sizeof(pno_in_example); i++)
294 printf("%02X ", command[i]);
296 total_len = sizeof(pno_in_example);
299 str_ptr = command + strlen(CMD_PNOSETUP_SET);
300 tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET);
302 cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
303 memset(ssids_local, 0, sizeof(ssids_local));
305 if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
306 (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
307 (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) {
309 str_ptr += sizeof(cmd_tlv_t);
310 tlv_size_left -= sizeof(cmd_tlv_t);
312 if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
313 MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) {
314 DHD_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid));
317 if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
318 DHD_ERROR(("%s scan duration corrupted field size %d\n",
319 __FUNCTION__, tlv_size_left));
323 pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
324 DHD_INFO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
326 if (str_ptr[0] != 0) {
327 if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
328 DHD_ERROR(("%s pno repeat : corrupted field\n",
333 pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
334 DHD_INFO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat));
335 if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
336 DHD_ERROR(("%s FREQ_EXPO_MAX corrupted field size\n",
341 pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
342 DHD_INFO(("%s: pno_freq_expo_max=%d\n",
343 __FUNCTION__, pno_freq_expo_max));
347 DHD_ERROR(("%s get wrong TLV command\n", __FUNCTION__));
351 res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
356 #endif /* PNO_SUPPORT && !WL_SCHED_SCAN */
358 static int wl_android_get_p2p_dev_addr(struct net_device *ndev, char *command, int total_len)
361 int bytes_written = 0;
363 ret = wl_cfg80211_get_p2p_dev_addr(ndev, (struct ether_addr*)command);
366 bytes_written = sizeof(struct ether_addr);
367 return bytes_written;
371 * Global function definitions (declared in wl_android.h)
374 int wl_android_wifi_on(struct net_device *dev)
378 printk("%s in\n", __FUNCTION__);
380 DHD_ERROR(("%s: dev is null\n", __FUNCTION__));
384 dhd_net_if_lock(dev);
386 dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON);
387 sdioh_start(NULL, 0);
388 ret = dhd_dev_reset(dev, FALSE);
389 sdioh_start(NULL, 1);
391 if (dhd_dev_init_ioctl(dev) < 0)
396 dhd_net_if_unlock(dev);
401 int wl_android_wifi_off(struct net_device *dev)
405 printk("%s in\n", __FUNCTION__);
407 DHD_TRACE(("%s: dev is null\n", __FUNCTION__));
411 dhd_net_if_lock(dev);
413 ret = dhd_dev_reset(dev, TRUE);
415 dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
418 dhd_net_if_unlock(dev);
423 static int wl_android_set_fwpath(struct net_device *net, char *command, int total_len)
425 if ((strlen(command) - strlen(CMD_SETFWPATH)) > MOD_PARAM_PATHLEN)
427 bcm_strncpy_s(fw_path, sizeof(fw_path),
428 command + strlen(CMD_SETFWPATH) + 1, MOD_PARAM_PATHLEN - 1);
429 if (strstr(fw_path, "apsta") != NULL) {
430 DHD_INFO(("GOT APSTA FIRMWARE\n"));
433 DHD_INFO(("GOT STA FIRMWARE\n"));
434 ap_fw_loaded = FALSE;
439 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
442 char *command = NULL;
443 int bytes_written = 0;
444 android_wifi_priv_cmd priv_cmd;
446 net_os_wake_lock(net);
448 if (!ifr->ifr_data) {
452 if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
456 command = kmalloc(priv_cmd.total_len, GFP_KERNEL);
459 DHD_ERROR(("%s: failed to allocate memory\n", __FUNCTION__));
463 if (copy_from_user(command, priv_cmd.buf, priv_cmd.total_len)) {
468 DHD_INFO(("%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, command, ifr->ifr_name));
470 if (strnicmp(command, CMD_START, strlen(CMD_START)) == 0) {
471 DHD_INFO(("%s, Received regular START command\n", __FUNCTION__));
472 bytes_written = wl_android_wifi_on(net);
474 else if (strnicmp(command, CMD_SETFWPATH, strlen(CMD_SETFWPATH)) == 0) {
475 bytes_written = wl_android_set_fwpath(net, command, priv_cmd.total_len);
479 DHD_ERROR(("%s: Ignore private cmd \"%s\" - iface %s is down\n",
480 __FUNCTION__, command, ifr->ifr_name));
485 if (strnicmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) {
486 bytes_written = wl_android_wifi_off(net);
488 else if (strnicmp(command, CMD_SCAN_ACTIVE, strlen(CMD_SCAN_ACTIVE)) == 0) {
489 /* TBD: SCAN-ACTIVE */
491 else if (strnicmp(command, CMD_SCAN_PASSIVE, strlen(CMD_SCAN_PASSIVE)) == 0) {
492 /* TBD: SCAN-PASSIVE */
494 else if (strnicmp(command, CMD_RSSI, strlen(CMD_RSSI)) == 0) {
495 bytes_written = wl_android_get_rssi(net, command, priv_cmd.total_len);
497 else if (strnicmp(command, CMD_LINKSPEED, strlen(CMD_LINKSPEED)) == 0) {
498 bytes_written = wl_android_get_link_speed(net, command, priv_cmd.total_len);
500 else if (strnicmp(command, CMD_RXFILTER_START, strlen(CMD_RXFILTER_START)) == 0) {
501 bytes_written = net_os_set_packet_filter(net, 1);
503 else if (strnicmp(command, CMD_RXFILTER_STOP, strlen(CMD_RXFILTER_STOP)) == 0) {
504 bytes_written = net_os_set_packet_filter(net, 0);
506 else if (strnicmp(command, CMD_RXFILTER_ADD, strlen(CMD_RXFILTER_ADD)) == 0) {
507 int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
508 bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
510 else if (strnicmp(command, CMD_RXFILTER_REMOVE, strlen(CMD_RXFILTER_REMOVE)) == 0) {
511 int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
512 bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
514 else if (strnicmp(command, CMD_BTCOEXSCAN_START, strlen(CMD_BTCOEXSCAN_START)) == 0) {
515 /* TBD: BTCOEXSCAN-START */
517 else if (strnicmp(command, CMD_BTCOEXSCAN_STOP, strlen(CMD_BTCOEXSCAN_STOP)) == 0) {
518 /* TBD: BTCOEXSCAN-STOP */
520 else if (strnicmp(command, CMD_BTCOEXMODE, strlen(CMD_BTCOEXMODE)) == 0) {
521 uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
524 net_os_set_packet_filter(net, 0); /* DHCP starts */
526 net_os_set_packet_filter(net, 1); /* DHCP ends */
528 bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
531 else if (strnicmp(command, CMD_SETSUSPENDOPT, strlen(CMD_SETSUSPENDOPT)) == 0) {
532 bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
534 else if (strnicmp(command, CMD_SETSUSPENDMODE, strlen(CMD_SETSUSPENDMODE)) == 0) {
535 bytes_written = wl_android_set_suspendmode(net, command, priv_cmd.total_len);
537 else if (strnicmp(command, CMD_SETBAND, strlen(CMD_SETBAND)) == 0) {
538 uint band = *(command + strlen(CMD_SETBAND) + 1) - '0';
539 bytes_written = wldev_set_band(net, band);
541 else if (strnicmp(command, CMD_GETBAND, strlen(CMD_GETBAND)) == 0) {
542 bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
544 else if (strnicmp(command, CMD_COUNTRY, strlen(CMD_COUNTRY)) == 0) {
545 char *country_code = command + strlen(CMD_COUNTRY) + 1;
546 bytes_written = wldev_set_country(net, country_code);
548 #if defined(PNO_SUPPORT) && !defined(WL_SCHED_SCAN)
549 else if (strnicmp(command, CMD_PNOSSIDCLR_SET, strlen(CMD_PNOSSIDCLR_SET)) == 0) {
550 bytes_written = dhd_dev_pno_reset(net);
552 else if (strnicmp(command, CMD_PNOSETUP_SET, strlen(CMD_PNOSETUP_SET)) == 0) {
553 bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
555 else if (strnicmp(command, CMD_PNOENABLE_SET, strlen(CMD_PNOENABLE_SET)) == 0) {
556 uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
557 bytes_written = dhd_dev_pno_enable(net, pfn_enabled);
560 else if (strnicmp(command, CMD_P2P_DEV_ADDR, strlen(CMD_P2P_DEV_ADDR)) == 0) {
561 bytes_written = wl_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
563 else if (strnicmp(command, CMD_P2P_SET_NOA, strlen(CMD_P2P_SET_NOA)) == 0) {
564 int skip = strlen(CMD_P2P_SET_NOA) + 1;
565 bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip,
566 priv_cmd.total_len - skip);
568 #if !defined WL_ENABLE_P2P_IF
569 else if (strnicmp(command, CMD_P2P_GET_NOA, strlen(CMD_P2P_GET_NOA)) == 0) {
570 bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
573 else if (strnicmp(command, CMD_P2P_SET_PS, strlen(CMD_P2P_SET_PS)) == 0) {
574 int skip = strlen(CMD_P2P_SET_PS) + 1;
575 bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip,
576 priv_cmd.total_len - skip);
579 else if (strnicmp(command, CMD_SET_AP_WPS_P2P_IE,
580 strlen(CMD_SET_AP_WPS_P2P_IE)) == 0) {
581 int skip = strlen(CMD_SET_AP_WPS_P2P_IE) + 3;
582 bytes_written = wl_cfg80211_set_wps_p2p_ie(net, command + skip,
583 priv_cmd.total_len - skip, *(command + skip - 2) - '0');
585 #endif /* WL_CFG80211 */
587 DHD_ERROR(("Unknown PRIVATE command %s - ignored\n", command));
588 snprintf(command, 3, "OK");
589 bytes_written = strlen("OK");
592 if (bytes_written >= 0) {
593 if ((bytes_written == 0) && (priv_cmd.total_len > 0))
595 if (bytes_written >= priv_cmd.total_len) {
596 DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written));
597 bytes_written = priv_cmd.total_len;
601 priv_cmd.used_len = bytes_written;
602 if (copy_to_user(priv_cmd.buf, command, bytes_written)) {
603 DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__));
612 net_os_wake_unlock(net);
620 int wl_android_init(void)
624 dhd_msg_level |= DHD_ERROR_VAL;
625 #ifdef ENABLE_INSMOD_NO_FW_LOAD
626 dhd_download_fw_on_driverload = FALSE;
627 #endif /* ENABLE_INSMOD_NO_FW_LOAD */
629 if (!iface_name[0]) {
630 memset(iface_name, 0, IFNAMSIZ);
631 bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ);
633 #endif /* CUSTOMER_HW2 */
637 int wl_android_exit(void)
644 void wl_android_post_init(void)
646 if (!dhd_download_fw_on_driverload) {
647 /* Call customer gpio to turn off power with WL_REG_ON signal */
648 dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
653 * Functions for Android WiFi card detection
655 #if defined(CONFIG_WIFI_CONTROL_FUNC)
657 static int g_wifidev_registered = 0;
658 static struct semaphore wifi_control_sem;
659 static struct wifi_platform_data *wifi_control_data = NULL;
660 static struct resource *wifi_irqres = NULL;
662 static int wifi_add_dev(void);
663 static void wifi_del_dev(void);
665 int wl_android_wifictrl_func_add(void)
668 sema_init(&wifi_control_sem, 0);
670 ret = wifi_add_dev();
672 DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
675 g_wifidev_registered = 1;
677 /* Waiting callback after platform_driver_register is done or exit with error */
678 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
680 DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
686 void wl_android_wifictrl_func_del(void)
688 if (g_wifidev_registered)
691 g_wifidev_registered = 0;
695 void* wl_android_prealloc(int section, unsigned long size)
697 void *alloc_ptr = NULL;
698 if (wifi_control_data && wifi_control_data->mem_prealloc) {
699 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
701 DHD_INFO(("success alloc section %d\n", section));
703 bzero(alloc_ptr, size);
708 DHD_ERROR(("can't alloc section %d\n", section));
712 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
715 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
716 return (int)wifi_irqres->start;
718 #ifdef CUSTOM_OOB_GPIO_NUM
719 return CUSTOM_OOB_GPIO_NUM;
725 int wifi_set_power(int on, unsigned long msec)
727 DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
728 if (wifi_control_data && wifi_control_data->set_power) {
729 wifi_control_data->set_power(on);
736 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
737 int wifi_get_mac_addr(unsigned char *buf)
739 DHD_TRACE(("%s\n", __FUNCTION__));
742 if (wifi_control_data && wifi_control_data->get_mac_addr) {
743 return wifi_control_data->get_mac_addr(buf);
747 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
749 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
750 void *wifi_get_country_code(char *ccode)
752 DHD_TRACE(("%s\n", __FUNCTION__));
755 if (wifi_control_data && wifi_control_data->get_country_code) {
756 return wifi_control_data->get_country_code(ccode);
760 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
762 static int wifi_set_carddetect(int on)
764 DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
765 if (wifi_control_data && wifi_control_data->set_carddetect) {
766 wifi_control_data->set_carddetect(on);
771 static int wifi_probe(struct platform_device *pdev)
773 struct wifi_platform_data *wifi_ctrl =
774 (struct wifi_platform_data *)(pdev->dev.platform_data);
776 DHD_ERROR(("## %s\n", __FUNCTION__));
777 wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
778 if (wifi_irqres == NULL)
779 wifi_irqres = platform_get_resource_byname(pdev,
780 IORESOURCE_IRQ, "bcm4329_wlan_irq");
781 wifi_control_data = wifi_ctrl;
783 wifi_set_power(1, 0); /* Power On */
784 wifi_set_carddetect(1); /* CardDetect (0->1) */
786 up(&wifi_control_sem);
790 static int wifi_remove(struct platform_device *pdev)
792 struct wifi_platform_data *wifi_ctrl =
793 (struct wifi_platform_data *)(pdev->dev.platform_data);
795 DHD_ERROR(("## %s\n", __FUNCTION__));
796 wifi_control_data = wifi_ctrl;
798 wifi_set_power(0, 0); /* Power Off */
799 wifi_set_carddetect(0); /* CardDetect (1->0) */
801 up(&wifi_control_sem);
805 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
807 DHD_TRACE(("##> %s\n", __FUNCTION__));
808 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
809 bcmsdh_oob_intr_set(0);
814 static int wifi_resume(struct platform_device *pdev)
816 DHD_TRACE(("##> %s\n", __FUNCTION__));
817 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
818 if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
819 bcmsdh_oob_intr_set(1);
824 static struct platform_driver wifi_device = {
826 .remove = wifi_remove,
827 .suspend = wifi_suspend,
828 .resume = wifi_resume,
830 .name = "bcmdhd_wlan",
834 static struct platform_driver wifi_device_legacy = {
836 .remove = wifi_remove,
837 .suspend = wifi_suspend,
838 .resume = wifi_resume,
840 .name = "bcm4329_wlan",
844 static int wifi_add_dev(void)
846 DHD_TRACE(("## Calling platform_driver_register\n"));
847 platform_driver_register(&wifi_device);
848 platform_driver_register(&wifi_device_legacy);
852 static void wifi_del_dev(void)
854 DHD_TRACE(("## Unregister platform_driver_register\n"));
855 platform_driver_unregister(&wifi_device);
856 platform_driver_unregister(&wifi_device_legacy);
858 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */