2 #include <Magpie_api.h>
3 #include <adf_os_types.h>
4 #include <adf_os_pci.h>
8 #if MAGPIE_ENABLE_WLAN == 0
9 A_PCI_INIT_FUNC g_pci_init_func;
12 #if MAGPIE_ENABLE_PCIE == 0
13 #define EMULATE_PCI_CONFIG
16 #define PCI_CONFIG_BASE_ADDR 0x14000000
18 extern A_PCI_INIT_FUNC g_pci_init_func;
19 adf_drv_info_t* g_wlan_drv = NULL;
20 adf_drv_handle_t g_wlan_drv_handle = NULL;
21 adf_os_drv_intr g_wlan_intr = NULL;
23 void wlan_pci_module_init(void)
25 if (g_pci_init_func != NULL) {
30 void wlan_pci_register_drv(adf_drv_info_t *drv)
35 #define ATHEROS_VENDOR_ID 0x168c
36 #define AR5416_DEVID_PCIE 0x24
38 void wlan_pci_probe(void)
41 adf_os_resource_t drv_res = {0};
42 adf_os_attach_data_t drv_data = {{0}};
46 A_PRINTF("<wlan_pci_probe>: Attaching the driver\n");
48 #if MAGPIE_ENABLE_PCIE == 0
49 vendor_id = ATHEROS_VENDOR_ID;
50 device_id = AR5416_DEVID_PCIE;
52 vendor_id = wlan_pci_config_read(0, 2);
53 device_id = wlan_pci_config_read(2, 2);
55 A_PRINTF("<wlan_pci_probe>: Vendor id 0x%x Dev id 0x%x\n", vendor_id, device_id);
57 if (vendor_id != ATHEROS_VENDOR_ID) {
58 A_PRINTF("<wlan_pci_probe>: Atheros card not found\n");
63 * Allocate the sc & zero down
65 sc = A_ALLOCRAM(sizeof(__adf_softc_t));
67 A_PRINTF("Cannot malloc softc\n");
71 #define AR5416_DEVID_PCIE 0x24
73 drv_data.pci.device = AR5416_DEVID_PCIE;
74 drv_data.pci.vendor = 0x168c;
75 drv_data.pci.subvendor = 0;
76 drv_data.pci.subdevice = 0;
78 drv_res.start = (a_uint32_t) 0;
80 drv_res.type = ADF_OS_RESOURCE_TYPE_MEM;
82 g_wlan_drv_handle = g_wlan_drv->drv_attach(&drv_res, 1, &drv_data, NULL);
89 int wlan_pci_config_write(int offset, a_uint32_t val, int width)
91 #if MAGPIE_ENABLE_PCIE == 1
92 unsigned long addr = ( PCI_CONFIG_BASE_ADDR + offset ) & 0xfffffffc;
93 A_UINT8 *ptr = (A_UINT8 *)addr;
94 A_UINT8 *valptr = (A_UINT8 *)&val;
95 int idx = offset & 0x3;
98 for (i = 0; i < width; i++) {
99 ptr[idx + i] = valptr[3-i];
106 int wlan_pci_config_read(int offset, int width)
108 #if MAGPIE_ENABLE_PCIE == 0
111 unsigned long addr = ( PCI_CONFIG_BASE_ADDR + offset ) & 0xfffffffc;
112 unsigned long value = *((unsigned long *)addr);
113 A_UINT8 *ptr = (A_UINT8 *)&value;
114 int idx = offset & 0x3;
118 for (i = 0; i < width; i++) {
119 result |= (ptr[ 3 - (idx + i)] << (8*i));
128 if (g_wlan_intr != NULL && g_wlan_drv_handle != NULL) {
129 g_wlan_intr(g_wlan_drv_handle);