blob: 5e68b7026186bc9f497c1abbf9d14259e4a96bca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_tmd.c
2 *
3 * Driver for Prism II devices which would usually be driven by orinoco_cs,
4 * but are connected to the PCI bus by a TMD7160.
5 *
6 * Copyright (C) 2003 Joerg Dorchain <joerg AT dorchain.net>
7 * based heavily upon orinoco_plx.c Copyright (C) 2001 Daniel Barlow
8 *
9 * The contents of this file are subject to the Mozilla Public License
10 * Version 1.1 (the "License"); you may not use this file except in
11 * compliance with the License. You may obtain a copy of the License
12 * at http://www.mozilla.org/MPL/
13 *
14 * Software distributed under the License is distributed on an "AS IS"
15 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16 * the License for the specific language governing rights and
17 * limitations under the License.
18 *
19 * Alternatively, the contents of this file may be used under the
20 * terms of the GNU General Public License version 2 (the "GPL"), in
21 * which case the provisions of the GPL are applicable instead of the
22 * above. If you wish to allow the use of your version of this file
23 * only under the terms of the GPL and not to allow others to use your
24 * version of this file under the MPL, indicate your decision by
25 * deleting the provisions above and replace them with the notice and
26 * other provisions required by the GPL. If you do not delete the
27 * provisions above, a recipient may use your version of this file
28 * under either the MPL or the GPL.
29
30 * Caution: this is experimental and probably buggy. For success and
31 * failure reports for different cards and adaptors, see
32 * orinoco_tmd_pci_id_table near the end of the file. If you have a
33 * card we don't have the PCI id for, and looks like it should work,
34 * drop me mail with the id and "it works"/"it doesn't work".
35 *
36 * Note: if everything gets detected fine but it doesn't actually send
37 * or receive packets, your first port of call should probably be to
38 * try newer firmware in the card. Especially if you're doing Ad-Hoc
39 * modes
40 *
41 * The actual driving is done by orinoco.c, this is just resource
42 * allocation stuff.
43 *
44 * This driver is modeled after the orinoco_plx driver. The main
45 * difference is that the TMD chip has only IO port ranges and no
46 * memory space, i.e. no access to the CIS. Compared to the PLX chip,
47 * the io range functionalities are exchanged.
48 *
49 * Pheecom sells cards with the TMD chip as "ASIC version"
50 */
51
52#define DRIVER_NAME "orinoco_tmd"
53#define PFX DRIVER_NAME ": "
54
55#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040059#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <pcmcia/cisreg.h>
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "orinoco.h"
64
65#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
66#define COR_RESET (0x80) /* reset bit in the COR register */
67#define TMD_RESET_TIME (500) /* milliseconds */
68
69/* Orinoco TMD specific data */
70struct orinoco_tmd_card {
71 u32 tmd_io;
72};
73
74
75/*
76 * Do a soft reset of the card using the Configuration Option Register
77 */
78static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
79{
80 hermes_t *hw = &priv->hw;
81 struct orinoco_tmd_card *card = priv->card;
82 u32 addr = card->tmd_io;
83 unsigned long timeout;
84 u16 reg;
85
86 outb(COR_VALUE | COR_RESET, addr);
87 mdelay(1);
88
89 outb(COR_VALUE, addr);
90 mdelay(1);
91
92 /* Just in case, wait more until the card is no longer busy */
93 timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
94 reg = hermes_read_regn(hw, CMD);
95 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
96 mdelay(1);
97 reg = hermes_read_regn(hw, CMD);
98 }
99
100 /* Did we timeout ? */
101 if (reg & HERMES_CMD_BUSY) {
102 printk(KERN_ERR PFX "Busy timeout\n");
103 return -ETIMEDOUT;
104 }
105
106 return 0;
107}
108
109
110static int orinoco_tmd_init_one(struct pci_dev *pdev,
111 const struct pci_device_id *ent)
112{
113 int err = 0;
114 struct orinoco_private *priv = NULL;
115 struct orinoco_tmd_card *card;
116 struct net_device *dev = NULL;
117 void __iomem *mem;
118
119 err = pci_enable_device(pdev);
120 if (err) {
121 printk(KERN_ERR PFX "Cannot enable PCI device\n");
122 return err;
123 }
124
125 err = pci_request_regions(pdev, DRIVER_NAME);
126 if (err != 0) {
127 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
128 goto fail_resources;
129 }
130
131 mem = pci_iomap(pdev, 2, 0);
132 if (! mem) {
133 err = -ENOMEM;
134 goto fail_iomap;
135 }
136
137 /* Allocate network device */
138 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
139 if (! dev) {
140 printk(KERN_ERR PFX "Cannot allocate network device\n");
141 err = -ENOMEM;
142 goto fail_alloc;
143 }
144
145 priv = netdev_priv(dev);
146 card = priv->card;
147 card->tmd_io = pci_resource_start(pdev, 1);
148 dev->base_addr = pci_resource_start(pdev, 2);
149 SET_MODULE_OWNER(dev);
150 SET_NETDEV_DEV(dev, &pdev->dev);
151
152 hermes_struct_init(&priv->hw, mem, HERMES_16BIT_REGSPACING);
153
154 printk(KERN_DEBUG PFX "Detected Orinoco/Prism2 TMD device "
155 "at %s irq:%d, io addr:0x%lx\n", pci_name(pdev), pdev->irq,
156 dev->base_addr);
157
158 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
159 dev->name, dev);
160 if (err) {
161 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
162 err = -EBUSY;
163 goto fail_irq;
164 }
165 dev->irq = pdev->irq;
166
167 err = orinoco_tmd_cor_reset(priv);
168 if (err) {
169 printk(KERN_ERR PFX "Initial reset failed\n");
170 goto fail;
171 }
172
173 err = register_netdev(dev);
174 if (err) {
175 printk(KERN_ERR PFX "Cannot register network device\n");
176 goto fail;
177 }
178
179 pci_set_drvdata(pdev, dev);
180
181 return 0;
182
183 fail:
184 free_irq(pdev->irq, dev);
185
186 fail_irq:
187 pci_set_drvdata(pdev, NULL);
188 free_orinocodev(dev);
189
190 fail_alloc:
191 pci_iounmap(pdev, mem);
192
193 fail_iomap:
194 pci_release_regions(pdev);
195
196 fail_resources:
197 pci_disable_device(pdev);
198
199 return err;
200}
201
202static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
203{
204 struct net_device *dev = pci_get_drvdata(pdev);
205 struct orinoco_private *priv = dev->priv;
206
207 BUG_ON(! dev);
208
209 unregister_netdev(dev);
210 free_irq(dev->irq, dev);
211 pci_set_drvdata(pdev, NULL);
212 free_orinocodev(dev);
213 pci_iounmap(pdev, priv->hw.iobase);
214 pci_release_regions(pdev);
215 pci_disable_device(pdev);
216}
217
218
219static struct pci_device_id orinoco_tmd_pci_id_table[] = {
220 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
221 {0,},
222};
223
224MODULE_DEVICE_TABLE(pci, orinoco_tmd_pci_id_table);
225
226static struct pci_driver orinoco_tmd_driver = {
227 .name = DRIVER_NAME,
228 .id_table = orinoco_tmd_pci_id_table,
229 .probe = orinoco_tmd_init_one,
230 .remove = __devexit_p(orinoco_tmd_remove_one),
231};
232
233static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
234 " (Joerg Dorchain <joerg@dorchain.net>)";
235MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
236MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
237MODULE_LICENSE("Dual MPL/GPL");
238
239static int __init orinoco_tmd_init(void)
240{
241 printk(KERN_DEBUG "%s\n", version);
242 return pci_module_init(&orinoco_tmd_driver);
243}
244
245static void __exit orinoco_tmd_exit(void)
246{
247 pci_unregister_driver(&orinoco_tmd_driver);
248 ssleep(1);
249}
250
251module_init(orinoco_tmd_init);
252module_exit(orinoco_tmd_exit);
253
254/*
255 * Local variables:
256 * c-indent-level: 8
257 * c-basic-offset: 8
258 * tab-width: 8
259 * End:
260 */