blob: df493185a4af65a2b815b4542fbd9f55e71904ba [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_tmd.c
Pavel Roskinb884c872006-04-07 04:10:57 -04002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 *
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
Pavel Roskindc3437d2006-04-07 04:11:00 -040034 * difference is that the TMD chip has only IO port ranges and doesn't
35 * provide access to the PCMCIA attribute space.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/module.h>
44#include <linux/kernel.h>
45#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040046#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <pcmcia/cisreg.h>
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040051#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
54#define COR_RESET (0x80) /* reset bit in the COR register */
55#define TMD_RESET_TIME (500) /* milliseconds */
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Do a soft reset of the card using the Configuration Option Register
59 */
60static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
61{
62 hermes_t *hw = &priv->hw;
Pavel Roskinb884c872006-04-07 04:10:57 -040063 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 unsigned long timeout;
65 u16 reg;
66
Pavel Roskinb884c872006-04-07 04:10:57 -040067 iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 mdelay(1);
69
Pavel Roskinb884c872006-04-07 04:10:57 -040070 iowrite8(COR_VALUE, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 mdelay(1);
72
73 /* Just in case, wait more until the card is no longer busy */
74 timeout = jiffies + (TMD_RESET_TIME * HZ / 1000);
75 reg = hermes_read_regn(hw, CMD);
76 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
77 mdelay(1);
78 reg = hermes_read_regn(hw, CMD);
79 }
80
Pavel Roskinb884c872006-04-07 04:10:57 -040081 /* Still busy? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 if (reg & HERMES_CMD_BUSY) {
83 printk(KERN_ERR PFX "Busy timeout\n");
84 return -ETIMEDOUT;
85 }
86
87 return 0;
88}
89
90
91static int orinoco_tmd_init_one(struct pci_dev *pdev,
92 const struct pci_device_id *ent)
93{
Pavel Roskinb884c872006-04-07 04:10:57 -040094 int err;
95 struct orinoco_private *priv;
96 struct orinoco_pci_card *card;
97 struct net_device *dev;
98 void __iomem *hermes_io, *bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 err = pci_enable_device(pdev);
101 if (err) {
102 printk(KERN_ERR PFX "Cannot enable PCI device\n");
103 return err;
104 }
105
106 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400107 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
109 goto fail_resources;
110 }
111
Pavel Roskinb884c872006-04-07 04:10:57 -0400112 bridge_io = pci_iomap(pdev, 1, 0);
113 if (!bridge_io) {
114 printk(KERN_ERR PFX "Cannot map bridge registers\n");
115 err = -EIO;
116 goto fail_map_bridge;
117 }
118
119 hermes_io = pci_iomap(pdev, 2, 0);
120 if (!hermes_io) {
121 printk(KERN_ERR PFX "Cannot map chipset registers\n");
122 err = -EIO;
123 goto fail_map_hermes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
126 /* Allocate network device */
127 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
Pavel Roskinb884c872006-04-07 04:10:57 -0400128 if (!dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 printk(KERN_ERR PFX "Cannot allocate network device\n");
130 err = -ENOMEM;
131 goto fail_alloc;
132 }
133
134 priv = netdev_priv(dev);
135 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400136 card->bridge_io = bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 SET_NETDEV_DEV(dev, &pdev->dev);
138
Pavel Roskinb884c872006-04-07 04:10:57 -0400139 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700141 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 dev->name, dev);
143 if (err) {
144 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
145 err = -EBUSY;
146 goto fail_irq;
147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 err = orinoco_tmd_cor_reset(priv);
150 if (err) {
151 printk(KERN_ERR PFX "Initial reset failed\n");
152 goto fail;
153 }
154
155 err = register_netdev(dev);
156 if (err) {
157 printk(KERN_ERR PFX "Cannot register network device\n");
158 goto fail;
159 }
160
161 pci_set_drvdata(pdev, dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400162 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name,
163 pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 return 0;
166
167 fail:
168 free_irq(pdev->irq, dev);
169
170 fail_irq:
171 pci_set_drvdata(pdev, NULL);
172 free_orinocodev(dev);
173
174 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400175 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Pavel Roskinb884c872006-04-07 04:10:57 -0400177 fail_map_hermes:
178 pci_iounmap(pdev, bridge_io);
179
180 fail_map_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 pci_release_regions(pdev);
182
183 fail_resources:
184 pci_disable_device(pdev);
185
186 return err;
187}
188
189static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
190{
191 struct net_device *dev = pci_get_drvdata(pdev);
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +0200192 struct orinoco_private *priv = netdev_priv(dev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400193 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 unregister_netdev(dev);
Pavel Roskin461c0782006-05-01 02:13:33 -0400196 free_irq(pdev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 pci_set_drvdata(pdev, NULL);
198 free_orinocodev(dev);
199 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400200 pci_iounmap(pdev, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 pci_release_regions(pdev);
202 pci_disable_device(pdev);
203}
204
Pavel Roskinb884c872006-04-07 04:10:57 -0400205static struct pci_device_id orinoco_tmd_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
207 {0,},
208};
209
Pavel Roskinb884c872006-04-07 04:10:57 -0400210MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212static struct pci_driver orinoco_tmd_driver = {
213 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400214 .id_table = orinoco_tmd_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .probe = orinoco_tmd_init_one,
216 .remove = __devexit_p(orinoco_tmd_remove_one),
Pavel Roskinb884c872006-04-07 04:10:57 -0400217 .suspend = orinoco_pci_suspend,
218 .resume = orinoco_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
221static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
222 " (Joerg Dorchain <joerg@dorchain.net>)";
223MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
224MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
225MODULE_LICENSE("Dual MPL/GPL");
226
227static int __init orinoco_tmd_init(void)
228{
229 printk(KERN_DEBUG "%s\n", version);
Jeff Garzik29917622006-08-19 17:48:59 -0400230 return pci_register_driver(&orinoco_tmd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233static void __exit orinoco_tmd_exit(void)
234{
235 pci_unregister_driver(&orinoco_tmd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238module_init(orinoco_tmd_init);
239module_exit(orinoco_tmd_exit);
240
241/*
242 * Local variables:
243 * c-indent-level: 8
244 * c-basic-offset: 8
245 * tab-width: 8
246 * End:
247 */