Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / net / wireless / orinoco / orinoco_tmd.c
blob93159d68ec937eb2fa4fed0b6d56db2934792f78
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 * The actual driving is done by main.c, this is just resource
31 * allocation stuff.
33 * This driver is modeled after the orinoco_plx driver. The main
34 * difference is that the TMD chip has only IO port ranges and doesn't
35 * provide access to the PCMCIA attribute space.
37 * Pheecom sells cards with the TMD chip as "ASIC version"
40 #define DRIVER_NAME "orinoco_tmd"
41 #define PFX DRIVER_NAME ": "
43 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/init.h>
46 #include <linux/delay.h>
47 #include <linux/pci.h>
48 #include <pcmcia/cisreg.h>
50 #include "orinoco.h"
51 #include "orinoco_pci.h"
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 */
58 * Do a soft reset of the card using the Configuration Option Register
60 static int orinoco_tmd_cor_reset(struct orinoco_private *priv)
62 struct hermes *hw = &priv->hw;
63 struct orinoco_pci_card *card = priv->card;
64 unsigned long timeout;
65 u16 reg;
67 iowrite8(COR_VALUE | COR_RESET, card->bridge_io);
68 mdelay(1);
70 iowrite8(COR_VALUE, card->bridge_io);
71 mdelay(1);
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);
81 /* Still busy? */
82 if (reg & HERMES_CMD_BUSY) {
83 printk(KERN_ERR PFX "Busy timeout\n");
84 return -ETIMEDOUT;
87 return 0;
91 static int orinoco_tmd_init_one(struct pci_dev *pdev,
92 const struct pci_device_id *ent)
94 int err;
95 struct orinoco_private *priv;
96 struct orinoco_pci_card *card;
97 void __iomem *hermes_io, *bridge_io;
99 err = pci_enable_device(pdev);
100 if (err) {
101 printk(KERN_ERR PFX "Cannot enable PCI device\n");
102 return err;
105 err = pci_request_regions(pdev, DRIVER_NAME);
106 if (err) {
107 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
108 goto fail_resources;
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;
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;
125 /* Allocate network device */
126 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
127 orinoco_tmd_cor_reset, NULL);
128 if (!priv) {
129 printk(KERN_ERR PFX "Cannot allocate network device\n");
130 err = -ENOMEM;
131 goto fail_alloc;
134 card = priv->card;
135 card->bridge_io = bridge_io;
137 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
139 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
140 DRIVER_NAME, priv);
141 if (err) {
142 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
143 err = -EBUSY;
144 goto fail_irq;
147 err = orinoco_tmd_cor_reset(priv);
148 if (err) {
149 printk(KERN_ERR PFX "Initial reset failed\n");
150 goto fail;
153 err = orinoco_init(priv);
154 if (err) {
155 printk(KERN_ERR PFX "orinoco_init() failed\n");
156 goto fail;
159 err = orinoco_if_add(priv, 0, 0, NULL);
160 if (err) {
161 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
162 goto fail;
165 pci_set_drvdata(pdev, priv);
167 return 0;
169 fail:
170 free_irq(pdev->irq, priv);
172 fail_irq:
173 pci_set_drvdata(pdev, NULL);
174 free_orinocodev(priv);
176 fail_alloc:
177 pci_iounmap(pdev, hermes_io);
179 fail_map_hermes:
180 pci_iounmap(pdev, bridge_io);
182 fail_map_bridge:
183 pci_release_regions(pdev);
185 fail_resources:
186 pci_disable_device(pdev);
188 return err;
191 static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
193 struct orinoco_private *priv = pci_get_drvdata(pdev);
194 struct orinoco_pci_card *card = priv->card;
196 orinoco_if_del(priv);
197 free_irq(pdev->irq, priv);
198 pci_set_drvdata(pdev, NULL);
199 free_orinocodev(priv);
200 pci_iounmap(pdev, priv->hw.iobase);
201 pci_iounmap(pdev, card->bridge_io);
202 pci_release_regions(pdev);
203 pci_disable_device(pdev);
206 static DEFINE_PCI_DEVICE_TABLE(orinoco_tmd_id_table) = {
207 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
208 {0,},
211 MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
213 static struct pci_driver orinoco_tmd_driver = {
214 .name = DRIVER_NAME,
215 .id_table = orinoco_tmd_id_table,
216 .probe = orinoco_tmd_init_one,
217 .remove = __devexit_p(orinoco_tmd_remove_one),
218 .suspend = orinoco_pci_suspend,
219 .resume = orinoco_pci_resume,
222 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
223 " (Joerg Dorchain <joerg@dorchain.net>)";
224 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
225 MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
226 MODULE_LICENSE("Dual MPL/GPL");
228 static int __init orinoco_tmd_init(void)
230 printk(KERN_DEBUG "%s\n", version);
231 return pci_register_driver(&orinoco_tmd_driver);
234 static void __exit orinoco_tmd_exit(void)
236 pci_unregister_driver(&orinoco_tmd_driver);
239 module_init(orinoco_tmd_init);
240 module_exit(orinoco_tmd_exit);
243 * Local variables:
244 * c-indent-level: 8
245 * c-basic-offset: 8
246 * tab-width: 8
247 * End: