Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* orinoco_tmd.c |
b884c872 | 2 | * |
1da177e4 | 3 | * Driver for Prism II devices which would usually be driven by orinoco_cs, |
d14c7c1d | 4 | * but are connected to the PCI bus by a TMD7160. |
1da177e4 LT |
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 | 29 | * |
47445cb9 | 30 | * The actual driving is done by main.c, this is just resource |
1da177e4 LT |
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 | ||
1da177e4 LT |
43 | #include <linux/module.h> |
44 | #include <linux/kernel.h> | |
45 | #include <linux/init.h> | |
ef846bf0 | 46 | #include <linux/delay.h> |
1da177e4 | 47 | #include <linux/pci.h> |
1da177e4 LT |
48 | #include <pcmcia/cisreg.h> |
49 | ||
1da177e4 | 50 | #include "orinoco.h" |
b884c872 | 51 | #include "orinoco_pci.h" |
1da177e4 LT |
52 | |
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 | ||
1da177e4 LT |
57 | /* |
58 | * Do a soft reset of the card using the Configuration Option Register | |
59 | */ | |
60 | static int orinoco_tmd_cor_reset(struct orinoco_private *priv) | |
61 | { | |
933d5943 | 62 | struct hermes *hw = &priv->hw; |
b884c872 | 63 | struct orinoco_pci_card *card = priv->card; |
1da177e4 LT |
64 | unsigned long timeout; |
65 | u16 reg; | |
66 | ||
b884c872 | 67 | iowrite8(COR_VALUE | COR_RESET, card->bridge_io); |
1da177e4 LT |
68 | mdelay(1); |
69 | ||
b884c872 | 70 | iowrite8(COR_VALUE, card->bridge_io); |
1da177e4 LT |
71 | mdelay(1); |
72 | ||
73 | /* Just in case, wait more until the card is no longer busy */ | |
c1f1f666 | 74 | timeout = jiffies + msecs_to_jiffies(TMD_RESET_TIME); |
1da177e4 LT |
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 | ||
b884c872 | 81 | /* Still busy? */ |
1da177e4 LT |
82 | if (reg & HERMES_CMD_BUSY) { |
83 | printk(KERN_ERR PFX "Busy timeout\n"); | |
84 | return -ETIMEDOUT; | |
85 | } | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
90 | ||
91 | static int orinoco_tmd_init_one(struct pci_dev *pdev, | |
92 | const struct pci_device_id *ent) | |
93 | { | |
b884c872 PR |
94 | int err; |
95 | struct orinoco_private *priv; | |
96 | struct orinoco_pci_card *card; | |
b884c872 | 97 | void __iomem *hermes_io, *bridge_io; |
1da177e4 LT |
98 | |
99 | err = pci_enable_device(pdev); | |
100 | if (err) { | |
101 | printk(KERN_ERR PFX "Cannot enable PCI device\n"); | |
102 | return err; | |
103 | } | |
104 | ||
105 | err = pci_request_regions(pdev, DRIVER_NAME); | |
b884c872 | 106 | if (err) { |
1da177e4 LT |
107 | printk(KERN_ERR PFX "Cannot obtain PCI resources\n"); |
108 | goto fail_resources; | |
109 | } | |
110 | ||
b884c872 PR |
111 | bridge_io = pci_iomap(pdev, 1, 0); |
112 | if (!bridge_io) { | |
113 | printk(KERN_ERR PFX "Cannot map bridge registers\n"); | |
114 | err = -EIO; | |
115 | goto fail_map_bridge; | |
116 | } | |
117 | ||
118 | hermes_io = pci_iomap(pdev, 2, 0); | |
119 | if (!hermes_io) { | |
120 | printk(KERN_ERR PFX "Cannot map chipset registers\n"); | |
121 | err = -EIO; | |
122 | goto fail_map_hermes; | |
1da177e4 LT |
123 | } |
124 | ||
125 | /* Allocate network device */ | |
a2608362 DK |
126 | priv = alloc_orinocodev(sizeof(*card), &pdev->dev, |
127 | orinoco_tmd_cor_reset, NULL); | |
128 | if (!priv) { | |
1da177e4 LT |
129 | printk(KERN_ERR PFX "Cannot allocate network device\n"); |
130 | err = -ENOMEM; | |
131 | goto fail_alloc; | |
132 | } | |
133 | ||
1da177e4 | 134 | card = priv->card; |
b884c872 | 135 | card->bridge_io = bridge_io; |
1da177e4 | 136 | |
b884c872 | 137 | hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING); |
1da177e4 | 138 | |
1fb9df5d | 139 | err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, |
5381956b | 140 | DRIVER_NAME, priv); |
1da177e4 LT |
141 | if (err) { |
142 | printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); | |
143 | err = -EBUSY; | |
144 | goto fail_irq; | |
145 | } | |
1da177e4 LT |
146 | |
147 | err = orinoco_tmd_cor_reset(priv); | |
148 | if (err) { | |
149 | printk(KERN_ERR PFX "Initial reset failed\n"); | |
150 | goto fail; | |
151 | } | |
152 | ||
8e638267 DK |
153 | err = orinoco_init(priv); |
154 | if (err) { | |
155 | printk(KERN_ERR PFX "orinoco_init() failed\n"); | |
156 | goto fail; | |
157 | } | |
158 | ||
593ef09c | 159 | err = orinoco_if_add(priv, 0, 0, NULL); |
1da177e4 | 160 | if (err) { |
5381956b | 161 | printk(KERN_ERR PFX "orinoco_if_add() failed\n"); |
1da177e4 LT |
162 | goto fail; |
163 | } | |
164 | ||
a2608362 | 165 | pci_set_drvdata(pdev, priv); |
1da177e4 LT |
166 | |
167 | return 0; | |
168 | ||
169 | fail: | |
a2608362 | 170 | free_irq(pdev->irq, priv); |
1da177e4 LT |
171 | |
172 | fail_irq: | |
a2608362 | 173 | free_orinocodev(priv); |
1da177e4 LT |
174 | |
175 | fail_alloc: | |
b884c872 | 176 | pci_iounmap(pdev, hermes_io); |
1da177e4 | 177 | |
b884c872 PR |
178 | fail_map_hermes: |
179 | pci_iounmap(pdev, bridge_io); | |
180 | ||
181 | fail_map_bridge: | |
1da177e4 LT |
182 | pci_release_regions(pdev); |
183 | ||
184 | fail_resources: | |
185 | pci_disable_device(pdev); | |
186 | ||
187 | return err; | |
188 | } | |
189 | ||
baa366cd | 190 | static void orinoco_tmd_remove_one(struct pci_dev *pdev) |
1da177e4 | 191 | { |
a2608362 | 192 | struct orinoco_private *priv = pci_get_drvdata(pdev); |
b884c872 | 193 | struct orinoco_pci_card *card = priv->card; |
1da177e4 | 194 | |
5381956b | 195 | orinoco_if_del(priv); |
a2608362 | 196 | free_irq(pdev->irq, priv); |
a2608362 | 197 | free_orinocodev(priv); |
1da177e4 | 198 | pci_iounmap(pdev, priv->hw.iobase); |
b884c872 | 199 | pci_iounmap(pdev, card->bridge_io); |
1da177e4 LT |
200 | pci_release_regions(pdev); |
201 | pci_disable_device(pdev); | |
202 | } | |
203 | ||
9baa3c34 | 204 | static const struct pci_device_id orinoco_tmd_id_table[] = { |
1da177e4 LT |
205 | {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */ |
206 | {0,}, | |
207 | }; | |
208 | ||
b884c872 | 209 | MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table); |
1da177e4 LT |
210 | |
211 | static struct pci_driver orinoco_tmd_driver = { | |
212 | .name = DRIVER_NAME, | |
b884c872 | 213 | .id_table = orinoco_tmd_id_table, |
1da177e4 | 214 | .probe = orinoco_tmd_init_one, |
baa366cd | 215 | .remove = orinoco_tmd_remove_one, |
c689a62b | 216 | .driver.pm = &orinoco_pci_pm_ops, |
1da177e4 LT |
217 | }; |
218 | ||
219 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
220 | " (Joerg Dorchain <joerg@dorchain.net>)"; | |
221 | MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>"); | |
222 | MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge"); | |
223 | MODULE_LICENSE("Dual MPL/GPL"); | |
224 | ||
225 | static int __init orinoco_tmd_init(void) | |
226 | { | |
227 | printk(KERN_DEBUG "%s\n", version); | |
29917620 | 228 | return pci_register_driver(&orinoco_tmd_driver); |
1da177e4 LT |
229 | } |
230 | ||
231 | static void __exit orinoco_tmd_exit(void) | |
232 | { | |
233 | pci_unregister_driver(&orinoco_tmd_driver); | |
1da177e4 LT |
234 | } |
235 | ||
236 | module_init(orinoco_tmd_init); | |
237 | module_exit(orinoco_tmd_exit); |