[PATCH] orinoco: don't put PCI resource data to the network device
[linux-2.6-block.git] / drivers / net / wireless / orinoco_tmd.c
CommitLineData
1da177e4 1/* orinoco_tmd.c
b884c872 2 *
1da177e4
LT
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.
1da177e4
LT
29 *
30 * The actual driving is done by orinoco.c, this is just resource
31 * allocation stuff.
32 *
33 * This driver is modeled after the orinoco_plx driver. The main
dc3437d2
PR
34 * difference is that the TMD chip has only IO port ranges and doesn't
35 * provide access to the PCMCIA attribute space.
1da177e4
LT
36 *
37 * Pheecom sells cards with the TMD chip as "ASIC version"
38 */
39
40#define DRIVER_NAME "orinoco_tmd"
41#define PFX DRIVER_NAME ": "
42
43#include <linux/config.h>
1da177e4
LT
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
ef846bf0 47#include <linux/delay.h>
1da177e4 48#include <linux/pci.h>
1da177e4
LT
49#include <pcmcia/cisreg.h>
50
1da177e4 51#include "orinoco.h"
b884c872 52#include "orinoco_pci.h"
1da177e4
LT
53
54#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
55#define COR_RESET (0x80) /* reset bit in the COR register */
56#define TMD_RESET_TIME (500) /* milliseconds */
57
1da177e4
LT
58/*
59 * Do a soft reset of the card using the Configuration Option Register
60 */
61static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
62{
63 hermes_t *hw = &priv->hw;
b884c872 64 struct orinoco_pci_card *card = priv->card;
1da177e4
LT
65 unsigned long timeout;
66 u16 reg;
67
b884c872 68 iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
1da177e4
LT
69 mdelay(1);
70
b884c872 71 iowrite8(COR_VALUE, card->bridge_io);
1da177e4
LT
72 mdelay(1);
73
74 /* Just in case, wait more until the card is no longer busy */
75 timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
76 reg = hermes_read_regn(hw, CMD);
77 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
78 mdelay(1);
79 reg = hermes_read_regn(hw, CMD);
80 }
81
b884c872 82 /* Still busy? */
1da177e4
LT
83 if (reg & HERMES_CMD_BUSY) {
84 printk(KERN_ERR PFX "Busy timeout\n");
85 return -ETIMEDOUT;
86 }
87
88 return 0;
89}
90
91
92static int orinoco_tmd_init_one(struct pci_dev *pdev,
93 const struct pci_device_id *ent)
94{
b884c872
PR
95 int err;
96 struct orinoco_private *priv;
97 struct orinoco_pci_card *card;
98 struct net_device *dev;
99 void __iomem *hermes_io, *bridge_io;
1da177e4
LT
100
101 err = pci_enable_device(pdev);
102 if (err) {
103 printk(KERN_ERR PFX "Cannot enable PCI device\n");
104 return err;
105 }
106
107 err = pci_request_regions(pdev, DRIVER_NAME);
b884c872 108 if (err) {
1da177e4
LT
109 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
110 goto fail_resources;
111 }
112
b884c872
PR
113 bridge_io = pci_iomap(pdev, 1, 0);
114 if (!bridge_io) {
115 printk(KERN_ERR PFX "Cannot map bridge registers\n");
116 err = -EIO;
117 goto fail_map_bridge;
118 }
119
120 hermes_io = pci_iomap(pdev, 2, 0);
121 if (!hermes_io) {
122 printk(KERN_ERR PFX "Cannot map chipset registers\n");
123 err = -EIO;
124 goto fail_map_hermes;
1da177e4
LT
125 }
126
127 /* Allocate network device */
128 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
b884c872 129 if (!dev) {
1da177e4
LT
130 printk(KERN_ERR PFX "Cannot allocate network device\n");
131 err = -ENOMEM;
132 goto fail_alloc;
133 }
134
135 priv = netdev_priv(dev);
136 card = priv->card;
b884c872 137 card->bridge_io = bridge_io;
1da177e4
LT
138 SET_MODULE_OWNER(dev);
139 SET_NETDEV_DEV(dev, &pdev->dev);
140
b884c872 141 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
1da177e4
LT
142
143 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
144 dev->name, dev);
145 if (err) {
146 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
147 err = -EBUSY;
148 goto fail_irq;
149 }
1da177e4
LT
150
151 err = orinoco_tmd_cor_reset(priv);
152 if (err) {
153 printk(KERN_ERR PFX "Initial reset failed\n");
154 goto fail;
155 }
156
157 err = register_netdev(dev);
158 if (err) {
159 printk(KERN_ERR PFX "Cannot register network device\n");
160 goto fail;
161 }
162
163 pci_set_drvdata(pdev, dev);
461c078c
PR
164 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
165 pci_name(pdev));
1da177e4
LT
166
167 return 0;
168
169 fail:
170 free_irq(pdev->irq, dev);
171
172 fail_irq:
173 pci_set_drvdata(pdev, NULL);
174 free_orinocodev(dev);
175
176 fail_alloc:
b884c872 177 pci_iounmap(pdev, hermes_io);
1da177e4 178
b884c872
PR
179 fail_map_hermes:
180 pci_iounmap(pdev, bridge_io);
181
182 fail_map_bridge:
1da177e4
LT
183 pci_release_regions(pdev);
184
185 fail_resources:
186 pci_disable_device(pdev);
187
188 return err;
189}
190
191static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
192{
193 struct net_device *dev = pci_get_drvdata(pdev);
194 struct orinoco_private *priv = dev->priv;
b884c872 195 struct orinoco_pci_card *card = priv->card;
1da177e4
LT
196
197 unregister_netdev(dev);
461c078c 198 free_irq(pdev->irq, dev);
1da177e4
LT
199 pci_set_drvdata(pdev, NULL);
200 free_orinocodev(dev);
201 pci_iounmap(pdev, priv->hw.iobase);
b884c872 202 pci_iounmap(pdev, card->bridge_io);
1da177e4
LT
203 pci_release_regions(pdev);
204 pci_disable_device(pdev);
205}
206
b884c872 207static struct pci_device_id orinoco_tmd_id_table[] = {
1da177e4
LT
208 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
209 {0,},
210};
211
b884c872 212MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
1da177e4
LT
213
214static struct pci_driver orinoco_tmd_driver = {
215 .name = DRIVER_NAME,
b884c872 216 .id_table = orinoco_tmd_id_table,
1da177e4
LT
217 .probe = orinoco_tmd_init_one,
218 .remove = __devexit_p(orinoco_tmd_remove_one),
b884c872
PR
219 .suspend = orinoco_pci_suspend,
220 .resume = orinoco_pci_resume,
1da177e4
LT
221};
222
223static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
224 " (Joerg Dorchain <joerg@dorchain.net>)";
225MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
226MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
227MODULE_LICENSE("Dual MPL/GPL");
228
229static int __init orinoco_tmd_init(void)
230{
231 printk(KERN_DEBUG "%s\n", version);
232 return pci_module_init(&orinoco_tmd_driver);
233}
234
235static void __exit orinoco_tmd_exit(void)
236{
237 pci_unregister_driver(&orinoco_tmd_driver);
1da177e4
LT
238}
239
240module_init(orinoco_tmd_init);
241module_exit(orinoco_tmd_exit);
242
243/*
244 * Local variables:
245 * c-indent-level: 8
246 * c-basic-offset: 8
247 * tab-width: 8
248 * End:
249 */