blob: 20ce569b8a43d3e3b4dcba10f0f5f9f193a395de [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,
Andrey Borzenkovd14c7c12009-01-25 23:08:43 +03004 * but are connected to the PCI bus by a TMD7160.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 *
David Kilroy47445cb2009-02-04 23:05:48 +000030 * The actual driving is done by main.c, this is just resource
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * 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{
Pavel Roskin933d5942011-07-13 11:19:57 -040062 struct hermes *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 */
Nicholas Mc Guirec1f1f662015-02-04 03:07:41 -050074 timeout = jiffies + msecs_to_jiffies(TMD_RESET_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 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;
Pavel Roskinb884c872006-04-07 04:10:57 -040097 void __iomem *hermes_io, *bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
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);
Pavel Roskinb884c872006-04-07 04:10:57 -0400106 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
108 goto fail_resources;
109 }
110
Pavel Roskinb884c872006-04-07 04:10:57 -0400111 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
125 /* Allocate network device */
David Kilroya2608362009-06-18 23:21:23 +0100126 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
127 orinoco_tmd_cor_reset, NULL);
128 if (!priv) {
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400135 card->bridge_io = bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Pavel Roskinb884c872006-04-07 04:10:57 -0400137 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700139 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
David Kilroy53819562009-06-18 23:21:28 +0100140 DRIVER_NAME, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (err) {
142 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
143 err = -EBUSY;
144 goto fail_irq;
145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 err = orinoco_tmd_cor_reset(priv);
148 if (err) {
149 printk(KERN_ERR PFX "Initial reset failed\n");
150 goto fail;
151 }
152
David Kilroy8e638262009-06-18 23:21:24 +0100153 err = orinoco_init(priv);
154 if (err) {
155 printk(KERN_ERR PFX "orinoco_init() failed\n");
156 goto fail;
157 }
158
David Kilroy593ef092010-05-01 14:05:39 +0100159 err = orinoco_if_add(priv, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (err) {
David Kilroy53819562009-06-18 23:21:28 +0100161 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 goto fail;
163 }
164
David Kilroya2608362009-06-18 23:21:23 +0100165 pci_set_drvdata(pdev, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 return 0;
168
169 fail:
David Kilroya2608362009-06-18 23:21:23 +0100170 free_irq(pdev->irq, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 fail_irq:
David Kilroya2608362009-06-18 23:21:23 +0100173 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
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
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500190static void orinoco_tmd_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
David Kilroya2608362009-06-18 23:21:23 +0100192 struct orinoco_private *priv = pci_get_drvdata(pdev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400193 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
David Kilroy53819562009-06-18 23:21:28 +0100195 orinoco_if_del(priv);
David Kilroya2608362009-06-18 23:21:23 +0100196 free_irq(pdev->irq, priv);
David Kilroya2608362009-06-18 23:21:23 +0100197 free_orinocodev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400199 pci_iounmap(pdev, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 pci_release_regions(pdev);
201 pci_disable_device(pdev);
202}
203
Benoit Taine9baa3c32014-08-08 15:56:03 +0200204static const struct pci_device_id orinoco_tmd_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 {0x15e8, 0x0131, PCI_ANY_ID, PCI_ANY_ID,}, /* NDC and OEMs, e.g. pheecom */
206 {0,},
207};
208
Pavel Roskinb884c872006-04-07 04:10:57 -0400209MODULE_DEVICE_TABLE(pci, orinoco_tmd_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211static struct pci_driver orinoco_tmd_driver = {
212 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400213 .id_table = orinoco_tmd_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .probe = orinoco_tmd_init_one,
Bill Pembertonbaa366c2012-12-03 09:56:37 -0500215 .remove = orinoco_tmd_remove_one,
Pavel Roskinb884c872006-04-07 04:10:57 -0400216 .suspend = orinoco_pci_suspend,
217 .resume = orinoco_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
219
220static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
221 " (Joerg Dorchain <joerg@dorchain.net>)";
222MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
223MODULE_DESCRIPTION("Driver for wireless LAN cards using the TMD7160 PCI bridge");
224MODULE_LICENSE("Dual MPL/GPL");
225
226static int __init orinoco_tmd_init(void)
227{
228 printk(KERN_DEBUG "%s\n", version);
Jeff Garzik29917622006-08-19 17:48:59 -0400229 return pci_register_driver(&orinoco_tmd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
232static void __exit orinoco_tmd_exit(void)
233{
234 pci_unregister_driver(&orinoco_tmd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237module_init(orinoco_tmd_init);
238module_exit(orinoco_tmd_exit);
239
240/*
241 * Local variables:
242 * c-indent-level: 8
243 * c-basic-offset: 8
244 * tab-width: 8
245 * End:
246 */