Setting up repository
[linux-libre-firmware.git] / ath9k_htc / target_firmware / wlan / if_ath_pci.c
1 /*-
2  * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting
3  * Copyright (c) 2004 Atheros Communications, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer,
11  *    without modification.
12  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14  *    redistribution must be conditioned upon including a substantially
15  *    similar Disclaimer requirement for further binary redistribution.
16  * 3. Neither the names of the above-listed copyright holders nor the names
17  *    of any contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * NO WARRANTY
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
28  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
29  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
30  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
33  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35  * THE POSSIBILITY OF SUCH DAMAGES.
36  *
37  * $Id: //depot/sw/branches/fusion_usb/target_firmware/wlan/target/madwifi/ath/if_ath_pci.c#1 $
38  */
39
40 #ifndef EXPORT_SYMTAB
41 #define EXPORT_SYMTAB
42 #endif
43
44 #include <adf_os_types.h>
45 #include <adf_os_dma.h>
46 #include <adf_os_pci.h>
47 #include <adf_os_timer.h>
48 #include <adf_os_lock.h>
49 #include <adf_os_io.h>
50 #include <adf_os_mem.h>
51 #include <adf_os_module.h>
52 #include <adf_os_util.h>
53 #include <adf_os_stdtypes.h>
54 #include <adf_os_defer.h>
55 #include <adf_os_atomic.h>
56 #include <adf_nbuf.h>
57 #include <adf_net.h>
58 #include <adf_os_irq.h>
59
60 #include <adf_net_wcmd.h>
61
62 #include <ieee80211_var.h>
63 #include "if_athvar.h"
64 #include "if_ath_pci.h"
65
66 extern a_int32_t ath_tgt_attach(a_uint32_t devid, struct ath_softc_tgt *sc, adf_os_device_t osdev);
67 extern a_int32_t ath_detach(void *);
68 extern adf_os_irq_resp_t ath_intr(adf_drv_handle_t hdl);
69
70 struct ath_pci_softc {
71         struct ath_softc_tgt aps_sc;
72 #ifdef CONFIG_PM
73         u32 ps_pmstate[16];
74 #endif
75 };
76
77 /*
78  * User a static table of PCI id's for now.  While this is the
79  * "new way" to do things, we may want to switch back to having
80  * the HAL check them by defining a probe method.
81  */
82 #ifdef ATH_SUPPORT_XB_ONLY
83 static adf_os_pci_dev_id_t ath_pci_id_table[] = {
84     { 0x168c, 0x0024, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* PCI-E (XB)    */
85     { 0 },
86 };
87 #else
88
89 static adf_os_pci_dev_id_t ath_pci_id_table[] = {
90     { 0x168c, 0x0007, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
91     { 0x168c, 0x0012, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
92     { 0x168c, 0x0013, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
93     { 0xa727, 0x0013, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* 3com */
94     { 0x10b7, 0x0013, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* 3com 3CRDAG675 */
95     { 0x168c, 0x1014, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* IBM minipci 5212 */
96     { 0x168c, 0x101a, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* some Griffin-Lite */
97     { 0x168c, 0x0015, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
98     { 0x168c, 0x0016, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
99     { 0x168c, 0x0017, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
100     { 0x168c, 0x0018, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
101     { 0x168c, 0x0019, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
102     { 0x168c, 0x001a, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
103     { 0x168c, 0x001b, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
104     { 0x168c, 0x001c, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
105     { 0x168c, 0x001d, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID },
106     { 0x168c, 0xff1d, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* owl emulation */
107     { 0x168c, 0xff1c, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* owl emulation */
108     { 0x168c, 0x0023, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* PCI (MB/CB)   */
109     { 0x168c, 0x0024, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* PCI-E (XB)    */
110     { 0x168c, 0x0027, ADF_OS_PCI_ANY_ID, ADF_OS_PCI_ANY_ID }, /* Sowl PCI     */
111     { 0 },
112 };
113 #endif
114
115 void exit_ath_pci(void);
116 a_int32_t init_ath_pci(void);
117
118 static adf_drv_handle_t
119 ath_pci_probe(adf_os_resource_t *res,a_int32_t count, adf_os_attach_data_t *data,
120               adf_os_device_t osdev)
121 {
122         struct ath_pci_softc *sc;
123         a_uint8_t csz = 32;
124         adf_os_pci_dev_id_t *id = (adf_os_pci_dev_id_t *)data;
125
126         adf_os_pci_config_write8(osdev, ATH_PCI_CACHE_LINE_SIZE, csz);
127         adf_os_pci_config_write8(osdev, ATH_PCI_LATENCY_TIMER, 0xa8);
128
129         sc = adf_os_mem_alloc(sizeof(struct ath_pci_softc));
130
131         if (sc == NULL) {
132                 adf_os_print("ath_pci: no memory for device state\n");
133                 goto bad2;
134         }
135         adf_os_mem_set(sc, 0, sizeof(struct ath_pci_softc));
136
137         /*
138          * Mark the device as detached to avoid processing
139          * interrupts until setup is complete.
140          */
141         sc->aps_sc.sc_invalid = 1;
142
143         adf_os_print("ath_pci_probe %x\n",id->device);
144
145         if (ath_tgt_attach(id->device, &sc->aps_sc, osdev) != 0)
146                 goto bad3;
147
148         /* ready to process interrupts */
149         sc->aps_sc.sc_invalid = 0;
150         adf_os_setup_intr(osdev, ath_intr);
151         return (adf_drv_handle_t)sc;
152 bad3:
153 bad2:
154         return NULL;
155 }
156
157 static void
158 ath_pci_remove(adf_drv_handle_t hdl)
159 {
160         struct ath_softc_tgt *sc = hdl;
161
162         ath_detach((struct ath_softc_tgt *)hdl);
163         adf_os_free_intr(sc->sc_dev);
164 }
165
166 static void
167 ath_pci_suspend(adf_drv_handle_t hdl, adf_os_pm_t pm)
168 {
169 }
170
171 static void
172 ath_pci_resume(adf_drv_handle_t hdl)
173 {
174 }
175
176 static adf_drv_info_t ath_drv_info = adf_os_pci_set_drv_info(ath_pci_tgt,&ath_pci_id_table[0], ath_pci_probe, ath_pci_remove, ath_pci_suspend, ath_pci_resume);
177
178 a_int32_t
179 init_ath_pci(void)
180 {
181         return adf_net_register_drv( &ath_drv_info );
182 }
183
184 void
185 exit_ath_pci(void)
186 {
187         adf_net_unregister_drv("ath_pci");
188 }
189
190 adf_os_pci_module_init(init_ath_pci);
191 adf_os_pci_module_exit(exit_ath_pci);
192 adf_os_module_dep(ath_pci_tgt, adf_net);
193 adf_os_module_dep(ath_pci_tgt, hal);
194 adf_os_module_dep(ath_pci_tgt, ath_pci);
195 adf_os_module_dep(ath_pci_tgt, wlan_tgt);
196 adf_os_module_dep(ath_pci_tgt, htc_tgt);
197 adf_os_module_dep(ath_pci_tgt, inproc_hif);