1 /*
2 * Linux ARCnet driver - COM20020 PCI support
3 * for Contemporary Controls PCI20 and SOHARD SH-ARC PCI with com20020 chipset
4 *
5 * Written 1994-1999 by Avery Pennarun,
6 * based on an ISA version by David Woodhouse.
7 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
8 * Derived from skeleton.c by Donald Becker.
9 *
10 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
11 * for sponsoring the further development of this driver.
12 *
13 * **********************
14 *
15 * The original copyright of skeleton.c was as follows:
16 *
17 * skeleton.c Written 1993 by Donald Becker.
18 * Copyright 1993 United States Government as represented by the
19 * Director, National Security Agency. This software may only be used
20 * and distributed according to the terms of the GNU General Public License as
21 * modified by SRC, incorporated herein by reference.
22 *
23 * **********************
24 *
25 * For more details, see drivers/net/arcnet.c
26 *
27 * **********************
28 */
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/ioport.h>
33 #include <linux/slab.h>
34 #include <linux/errno.h>
35 #include <linux/netdevice.h>
36 #include <linux/init.h>
37 #include <linux/pci.h>
38 #include <linux/arcdevice.h>
39 #include <linux/com20020.h>
40
41 #include <asm/io.h>
42
43
44 #define VERSION "arcnet: COM20020 PCI support\n"
45
46 /* Module parameters */
47
48 static int node;
49 static char *device; /* use eg. device="arc1" to change name */
50 static int timeout = 3;
51 static int backplane;
52 static int clockp;
53 static int clockm;
54
55 MODULE_PARM(node, "i");
56 MODULE_PARM(device, "s");
57 MODULE_PARM(timeout, "i");
58 MODULE_PARM(backplane, "i");
59 MODULE_PARM(clockp, "i");
60 MODULE_PARM(clockm, "i");
61 MODULE_LICENSE("GPL");
62
com20020pci_open_close(struct net_device * dev,bool open)63 static void com20020pci_open_close(struct net_device *dev, bool open)
64 {
65 if (open)
66 MOD_INC_USE_COUNT;
67 else
68 MOD_DEC_USE_COUNT;
69 }
70
com20020pci_probe(struct pci_dev * pdev,const struct pci_device_id * id)71 static int __devinit com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
72 {
73 struct net_device *dev;
74 struct arcnet_local *lp;
75 int ioaddr, err;
76
77 if (pci_enable_device(pdev))
78 return -EIO;
79 dev = dev_alloc(device ? : "arc%d", &err);
80 if (!dev)
81 return err;
82 lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
83 if (!lp) {
84 err = -ENOMEM;
85 goto out_dev;
86 }
87 memset(lp, 0, sizeof(struct arcnet_local));
88 pci_set_drvdata(pdev, dev);
89
90 // SOHARD needs PCI base addr 4
91 if (pdev->vendor==0x10B5) {
92 BUGMSG(D_NORMAL, "SOHARD\n");
93 ioaddr = pci_resource_start(pdev, 4);
94 }
95 else {
96 BUGMSG(D_NORMAL, "Contemporary Controls\n");
97 ioaddr = pci_resource_start(pdev, 2);
98 }
99
100 // Dummy access after Reset
101 // ARCNET controller needs this access to detect bustype
102 outb(0x00,ioaddr+1);
103 inb(ioaddr+1);
104
105 dev->base_addr = ioaddr;
106 dev->irq = pdev->irq;
107 dev->dev_addr[0] = node;
108 lp->card_name = pdev->name;
109 lp->card_flags = id->driver_data;
110 lp->backplane = backplane;
111 lp->clockp = clockp & 7;
112 lp->clockm = clockm & 3;
113 lp->timeout = timeout;
114 lp->hw.open_close_ll = com20020pci_open_close;
115
116 if (check_region(ioaddr, ARCNET_TOTAL_SIZE)) {
117 BUGMSG(D_INIT, "IO region %xh-%xh already allocated.\n",
118 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
119 err = -EBUSY;
120 goto out_priv;
121 }
122 if (ASTATUS() == 0xFF) {
123 BUGMSG(D_NORMAL, "IO address %Xh was reported by PCI BIOS, "
124 "but seems empty!\n", ioaddr);
125 err = -EIO;
126 goto out_priv;
127 }
128 if (com20020_check(dev)) {
129 err = -EIO;
130 goto out_priv;
131 }
132
133 if ((err = com20020_found(dev, SA_SHIRQ)) != 0)
134 goto out_priv;
135
136 return 0;
137
138 out_priv:
139 kfree(dev->priv);
140 out_dev:
141 kfree(dev);
142 return err;
143 }
144
com20020pci_remove(struct pci_dev * pdev)145 static void __devexit com20020pci_remove(struct pci_dev *pdev)
146 {
147 com20020_remove(pci_get_drvdata(pdev));
148 }
149
150 static struct pci_device_id com20020pci_id_table[] __devinitdata = {
151 { 0x1571, 0xa001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
152 { 0x1571, 0xa002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
153 { 0x1571, 0xa003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
154 { 0x1571, 0xa004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
155 { 0x1571, 0xa005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
156 { 0x1571, 0xa006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
157 { 0x1571, 0xa007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
158 { 0x1571, 0xa008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
159 { 0x1571, 0xa009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
160 { 0x1571, 0xa00a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
161 { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
162 { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
163 { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
164 { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
165 { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
166 { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
167 { 0x1571, 0xa204, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
168 { 0x1571, 0xa205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
169 { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
170 { 0x10B5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
171 {0,}
172 };
173
174 MODULE_DEVICE_TABLE(pci, com20020pci_id_table);
175
176 static struct pci_driver com20020pci_driver = {
177 name: "com20020",
178 id_table: com20020pci_id_table,
179 probe: com20020pci_probe,
180 remove: __devexit_p(com20020pci_remove),
181 };
182
com20020pci_init(void)183 static int __init com20020pci_init(void)
184 {
185 BUGLVL(D_NORMAL) printk(VERSION);
186 #ifndef MODULE
187 arcnet_init();
188 #endif
189 return pci_module_init(&com20020pci_driver);
190 }
191
com20020pci_cleanup(void)192 static void __exit com20020pci_cleanup(void)
193 {
194 pci_unregister_driver(&com20020pci_driver);
195 }
196
197 module_init(com20020pci_init)
198 module_exit(com20020pci_cleanup)
199