[PATCH] orinoco: reduce differences between PCI drivers, create orinoco_pci.h
[linux-2.6/mini2440.git] / drivers / net / wireless / orinoco_tmd.c
blob438fe545b184db9bedf37e82970b4b0e2aeafcc0
1 /* orinoco_tmd.c
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.
6 * Copyright (C) 2003 Joerg Dorchain <joerg AT dorchain.net>
7 * based heavily upon orinoco_plx.c Copyright (C) 2001 Daniel Barlow
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/
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.
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.
30 * Caution: this is experimental and probably buggy. For success and
31 * failure reports for different cards and adaptors, see
32 * orinoco_tmd_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".
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.
41 * The actual driving is done by orinoco.c, this is just resource
42 * allocation stuff.
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.
49 * Pheecom sells cards with the TMD chip as "ASIC version"
52 #define DRIVER_NAME "orinoco_tmd"
53 #define PFX DRIVER_NAME ": "
55 #include <linux/config.h>
56 #include <linux/module.h>
57 #include <linux/kernel.h>
58 #include <linux/init.h>
59 #include <linux/delay.h>
60 #include <linux/pci.h>
61 #include <pcmcia/cisreg.h>
63 #include "orinoco.h"
64 #include "orinoco_pci.h"
66 #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
67 #define COR_RESET (0x80) /* reset bit in the COR register */
68 #define TMD_RESET_TIME (500) /* milliseconds */
71 * Do a soft reset of the card using the Configuration Option Register
73 static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
75 hermes_t *hw = &priv->hw;
76 struct orinoco_pci_card *card = priv->card;
77 unsigned long timeout;
78 u16 reg;
80 iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
81 mdelay(1);
83 iowrite8(COR_VALUE, card->bridge_io);
84 mdelay(1);
86 /* Just in case, wait more until the card is no longer busy */
87 timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
88 reg = hermes_read_regn(hw, CMD);
89 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
90 mdelay(1);
91 reg = hermes_read_regn(hw, CMD);
94 /* Still busy? */
95 if (reg & HERMES_CMD_BUSY) {
96 printk(KERN_ERR PFX "Busy timeout\n");
97 return -ETIMEDOUT;
100 return 0;
104 static int orinoco_tmd_init_one(struct pci_dev *pdev,
105 const struct pci_device_id *ent)
107 int err;
108 struct orinoco_private *priv;
109 struct orinoco_pci_card *card;
110 struct net_device *dev;
111 void __iomem *hermes_io, *bridge_io;
113 err = pci_enable_device(pdev);
114 if (err) {
115 printk(KERN_ERR PFX "Cannot enable PCI device\n");
116 return err;
119 err = pci_request_regions(pdev, DRIVER_NAME);
120 if (err) {
121 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
122 goto fail_resources;
125 bridge_io = pci_iomap(pdev, 1, 0);
126 if (!bridge_io) {
127 printk(KERN_ERR PFX "Cannot map bridge registers\n");
128 err = -EIO;
129 goto fail_map_bridge;
132 hermes_io = pci_iomap(pdev, 2, 0);
133 if (!hermes_io) {
134 printk(KERN_ERR PFX "Cannot map chipset registers\n");
135 err = -EIO;
136 goto fail_map_hermes;
139 /* Allocate network device */
140 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
141 if (!dev) {
142 printk(KERN_ERR PFX "Cannot allocate network device\n");
143 err = -ENOMEM;
144 goto fail_alloc;
147 priv = netdev_priv(dev);
148 card = priv->card;
149 card->bridge_io = bridge_io;
150 SET_MODULE_OWNER(dev);
151 SET_NETDEV_DEV(dev, &pdev->dev);
153 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
155 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
156 dev->name, dev);
157 if (err) {
158 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
159 err = -EBUSY;
160 goto fail_irq;
162 orinoco_pci_setup_netdev(dev, pdev, 2);
164 err = orinoco_tmd_cor_reset(priv);
165 if (err) {
166 printk(KERN_ERR PFX "Initial reset failed\n");
167 goto fail;
170 err = register_netdev(dev);
171 if (err) {
172 printk(KERN_ERR PFX "Cannot register network device\n");
173 goto fail;
176 pci_set_drvdata(pdev, dev);
178 return 0;
180 fail:
181 free_irq(pdev->irq, dev);
183 fail_irq:
184 pci_set_drvdata(pdev, NULL);
185 free_orinocodev(dev);
187 fail_alloc:
188 pci_iounmap(pdev, hermes_io);
190 fail_map_hermes:
191 pci_iounmap(pdev, bridge_io);
193 fail_map_bridge:
194 pci_release_regions(pdev);
196 fail_resources:
197 pci_disable_device(pdev);
199 return err;
202 static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
204 struct net_device *dev = pci_get_drvdata(pdev);
205 struct orinoco_private *priv = dev->priv;
206 struct orinoco_pci_card *card = priv->card;
208 unregister_netdev(dev);
209 free_irq(dev->irq, dev);
210 pci_set_drvdata(pdev, NULL);
211 free_orinocodev(dev);
212 pci_iounmap(pdev, priv->hw.iobase);
213 pci_iounmap(pdev, card->bridge_io);
214 pci_release_regions(pdev);
215 pci_disable_device(pdev);
218 static struct pci_device_id orinoco_tmd_id_table[] = {
219 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
220 {0,},
223 MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
225 static struct pci_driver orinoco_tmd_driver = {
226 .name = DRIVER_NAME,
227 .id_table = orinoco_tmd_id_table,
228 .probe = orinoco_tmd_init_one,
229 .remove = __devexit_p(orinoco_tmd_remove_one),
230 .suspend = orinoco_pci_suspend,
231 .resume = orinoco_pci_resume,
234 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
235 " (Joerg Dorchain <joerg@dorchain.net>)";
236 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
237 MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
238 MODULE_LICENSE("Dual MPL/GPL");
240 static int __init orinoco_tmd_init(void)
242 printk(KERN_DEBUG "%s\n", version);
243 return pci_module_init(&orinoco_tmd_driver);
246 static void __exit orinoco_tmd_exit(void)
248 pci_unregister_driver(&orinoco_tmd_driver);
251 module_init(orinoco_tmd_init);
252 module_exit(orinoco_tmd_exit);
255 * Local variables:
256 * c-indent-level: 8
257 * c-basic-offset: 8
258 * tab-width: 8
259 * End: