blob: 0496663e837c5d4b6e9dacb7eca48ffd5ad51bc8 [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
43#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040047#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cisreg.h>
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -040052#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*
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;
Pavel Roskinb884c872006-04-07 04:10:57 -040064 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 unsigned long timeout;
66 u16 reg;
67
Pavel Roskinb884c872006-04-07 04:10:57 -040068 iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 mdelay(1);
70
Pavel Roskinb884c872006-04-07 04:10:57 -040071 iowrite8(COR_VALUE, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 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
Pavel Roskinb884c872006-04-07 04:10:57 -040082 /* Still busy? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 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{
Pavel Roskinb884c872006-04-07 04:10:57 -040095 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
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);
Pavel Roskinb884c872006-04-07 04:10:57 -0400108 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
110 goto fail_resources;
111 }
112
Pavel Roskinb884c872006-04-07 04:10:57 -0400113 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
127 /* Allocate network device */
128 dev = alloc_orinocodev(sizeof(*card), orinoco_tmd_cor_reset);
Pavel Roskinb884c872006-04-07 04:10:57 -0400129 if (!dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 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;
Pavel Roskinb884c872006-04-07 04:10:57 -0400137 card->bridge_io = bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 SET_MODULE_OWNER(dev);
139 SET_NETDEV_DEV(dev, &pdev->dev);
140
Pavel Roskinb884c872006-04-07 04:10:57 -0400141 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
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 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400150 orinoco_pci_setup_netdev(dev, pdev, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 err = orinoco_tmd_cor_reset(priv);
153 if (err) {
154 printk(KERN_ERR PFX "Initial reset failed\n");
155 goto fail;
156 }
157
158 err = register_netdev(dev);
159 if (err) {
160 printk(KERN_ERR PFX "Cannot register network device\n");
161 goto fail;
162 }
163
164 pci_set_drvdata(pdev, dev);
165
166 return 0;
167
168 fail:
169 free_irq(pdev->irq, dev);
170
171 fail_irq:
172 pci_set_drvdata(pdev, NULL);
173 free_orinocodev(dev);
174
175 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400176 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Pavel Roskinb884c872006-04-07 04:10:57 -0400178 fail_map_hermes:
179 pci_iounmap(pdev, bridge_io);
180
181 fail_map_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 pci_release_regions(pdev);
183
184 fail_resources:
185 pci_disable_device(pdev);
186
187 return err;
188}
189
190static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
191{
192 struct net_device *dev = pci_get_drvdata(pdev);
193 struct orinoco_private *priv = dev->priv;
Pavel Roskinb884c872006-04-07 04:10:57 -0400194 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 unregister_netdev(dev);
197 free_irq(dev->irq, dev);
198 pci_set_drvdata(pdev, NULL);
199 free_orinocodev(dev);
200 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400201 pci_iounmap(pdev, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 pci_release_regions(pdev);
203 pci_disable_device(pdev);
204}
205
Pavel Roskinb884c872006-04-07 04:10:57 -0400206static struct pci_device_id orinoco_tmd_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
208 {0,},
209};
210
Pavel Roskinb884c872006-04-07 04:10:57 -0400211MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213static struct pci_driver orinoco_tmd_driver = {
214 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400215 .id_table = orinoco_tmd_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 .probe = orinoco_tmd_init_one,
217 .remove = __devexit_p(orinoco_tmd_remove_one),
Pavel Roskinb884c872006-04-07 04:10:57 -0400218 .suspend = orinoco_pci_suspend,
219 .resume = orinoco_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
222static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
223 " (Joerg Dorchain <joerg@dorchain.net>)";
224MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
225MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
226MODULE_LICENSE("Dual MPL/GPL");
227
228static int __init orinoco_tmd_init(void)
229{
230 printk(KERN_DEBUG "%s\n", version);
231 return pci_module_init(&orinoco_tmd_driver);
232}
233
234static void __exit orinoco_tmd_exit(void)
235{
236 pci_unregister_driver(&orinoco_tmd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239module_init(orinoco_tmd_init);
240module_exit(orinoco_tmd_exit);
241
242/*
243 * Local variables:
244 * c-indent-level: 8
245 * c-basic-offset: 8
246 * tab-width: 8
247 * End:
248 */