2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <Magpie_api.h>
37 #include <adf_os_types.h>
38 #include <adf_os_pci.h>
42 #if MAGPIE_ENABLE_WLAN == 0
43 A_PCI_INIT_FUNC g_pci_init_func;
46 #if MAGPIE_ENABLE_PCIE == 0
47 #define EMULATE_PCI_CONFIG
50 #define PCI_CONFIG_BASE_ADDR 0x14000000
52 extern A_PCI_INIT_FUNC g_pci_init_func;
53 adf_drv_info_t* g_wlan_drv = NULL;
54 adf_drv_handle_t g_wlan_drv_handle = NULL;
55 adf_os_drv_intr g_wlan_intr = NULL;
57 void wlan_pci_module_init(void)
59 if (g_pci_init_func != NULL) {
64 void wlan_pci_register_drv(adf_drv_info_t *drv)
69 #define ATHEROS_VENDOR_ID 0x168c
70 #define AR5416_DEVID_PCIE 0x24
72 void wlan_pci_probe(void)
75 adf_os_resource_t drv_res = {0};
76 adf_os_attach_data_t drv_data = {{0}};
80 A_PRINTF("<wlan_pci_probe>: Attaching the driver\n");
82 #if MAGPIE_ENABLE_PCIE == 0
83 vendor_id = ATHEROS_VENDOR_ID;
84 device_id = AR5416_DEVID_PCIE;
86 vendor_id = wlan_pci_config_read(0, 2);
87 device_id = wlan_pci_config_read(2, 2);
89 A_PRINTF("<wlan_pci_probe>: Vendor id 0x%x Dev id 0x%x\n", vendor_id, device_id);
91 if (vendor_id != ATHEROS_VENDOR_ID) {
92 A_PRINTF("<wlan_pci_probe>: Atheros card not found\n");
97 * Allocate the sc & zero down
99 sc = A_ALLOCRAM(sizeof(__adf_softc_t));
101 A_PRINTF("Cannot malloc softc\n");
105 #define AR5416_DEVID_PCIE 0x24
107 drv_data.pci.device = AR5416_DEVID_PCIE;
108 drv_data.pci.vendor = 0x168c;
109 drv_data.pci.subvendor = 0;
110 drv_data.pci.subdevice = 0;
112 drv_res.start = (a_uint32_t) 0;
114 drv_res.type = ADF_OS_RESOURCE_TYPE_MEM;
116 g_wlan_drv_handle = g_wlan_drv->drv_attach(&drv_res, 1, &drv_data, NULL);
123 int wlan_pci_config_write(int offset, a_uint32_t val, int width)
125 #if MAGPIE_ENABLE_PCIE == 1
126 unsigned long addr = ( PCI_CONFIG_BASE_ADDR + offset ) & 0xfffffffc;
127 A_UINT8 *ptr = (A_UINT8 *)addr;
128 A_UINT8 *valptr = (A_UINT8 *)&val;
129 int idx = offset & 0x3;
132 for (i = 0; i < width; i++) {
133 ptr[idx + i] = valptr[3-i];
140 int wlan_pci_config_read(int offset, int width)
142 #if MAGPIE_ENABLE_PCIE == 0
145 unsigned long addr = ( PCI_CONFIG_BASE_ADDR + offset ) & 0xfffffffc;
146 unsigned long value = *((unsigned long *)addr);
147 A_UINT8 *ptr = (A_UINT8 *)&value;
148 int idx = offset & 0x3;
152 for (i = 0; i < width; i++) {
153 result |= (ptr[ 3 - (idx + i)] << (8*i));
162 if (g_wlan_intr != NULL && g_wlan_drv_handle != NULL) {
163 g_wlan_intr(g_wlan_drv_handle);