2 * Linux ARCnet driver - COM20020 PCI support
3 * Contemporary Controls PCI20 and SOHARD SH-ARC PCI
5 * Written 1994-1999 by Avery Pennarun,
6 * based on an ISA version by David Woodhouse.
8 * Derived from skeleton.c by Donald Becker.
10 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
11 * for sponsoring the further development of this driver.
13 * **********************
15 * The original copyright of skeleton.c was as follows:
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.
23 * **********************
25 * For more details, see drivers/net/arcnet.c
27 * **********************
30 #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/ioport.h>
37 #include <linux/errno.h>
38 #include <linux/netdevice.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.h>
41 #include <linux/pci.h>
42 #include <linux/list.h>
44 #include <linux/leds.h>
46 #include "arcdevice.h"
49 /* Module parameters */
52 static char device[9]; /* use eg. device="arc1" to change name */
53 static int timeout = 3;
58 module_param(node, int, 0);
59 module_param_string(device, device, sizeof(device), 0);
60 module_param(timeout, int, 0);
61 module_param(backplane, int, 0);
62 module_param(clockp, int, 0);
63 module_param(clockm, int, 0);
64 MODULE_DESCRIPTION("ARCnet COM20020 chipset PCI driver");
65 MODULE_LICENSE("GPL");
67 static void led_tx_set(struct led_classdev *led_cdev,
68 enum led_brightness value)
70 struct com20020_dev *card;
71 struct com20020_priv *priv;
72 struct com20020_pci_card_info *ci;
74 card = container_of(led_cdev, struct com20020_dev, tx_led);
76 priv = card->pci_priv;
79 outb(!!value, priv->misc + ci->leds[card->index].green);
82 static void led_recon_set(struct led_classdev *led_cdev,
83 enum led_brightness value)
85 struct com20020_dev *card;
86 struct com20020_priv *priv;
87 struct com20020_pci_card_info *ci;
89 card = container_of(led_cdev, struct com20020_dev, recon_led);
91 priv = card->pci_priv;
94 outb(!!value, priv->misc + ci->leds[card->index].red);
97 static ssize_t backplane_mode_show(struct device *dev,
98 struct device_attribute *attr,
101 struct net_device *net_dev = to_net_dev(dev);
102 struct arcnet_local *lp = netdev_priv(net_dev);
104 return sprintf(buf, "%s\n", lp->backplane ? "true" : "false");
106 static DEVICE_ATTR_RO(backplane_mode);
108 static struct attribute *com20020_state_attrs[] = {
109 &dev_attr_backplane_mode.attr,
113 static const struct attribute_group com20020_state_group = {
115 .attrs = com20020_state_attrs,
118 static void com20020pci_remove(struct pci_dev *pdev);
120 static int com20020pci_probe(struct pci_dev *pdev,
121 const struct pci_device_id *id)
123 struct com20020_pci_card_info *ci;
124 struct com20020_pci_channel_map *mm;
125 struct net_device *dev;
126 struct arcnet_local *lp;
127 struct com20020_priv *priv;
133 if (pci_enable_device(pdev))
136 priv = devm_kzalloc(&pdev->dev, sizeof(struct com20020_priv),
141 ci = (struct com20020_pci_card_info *)id->driver_data;
148 pci_set_drvdata(pdev, priv);
150 INIT_LIST_HEAD(&priv->list_dev);
153 ioaddr = pci_resource_start(pdev, mm->bar) + mm->offset;
154 r = devm_request_region(&pdev->dev, ioaddr, mm->size,
157 pr_err("IO region %xh-%xh already allocated.\n",
158 ioaddr, ioaddr + mm->size - 1);
164 for (i = 0; i < ci->devcount; i++) {
165 struct com20020_pci_channel_map *cm = &ci->chan_map_tbl[i];
166 struct com20020_dev *card;
167 int dev_id_mask = 0xf;
169 dev = alloc_arcdev(device);
176 dev->netdev_ops = &com20020_netdev_ops;
178 lp = netdev_priv(dev);
180 arc_printk(D_NORMAL, dev, "%s Controls\n", ci->name);
181 ioaddr = pci_resource_start(pdev, cm->bar) + cm->offset;
183 r = devm_request_region(&pdev->dev, ioaddr, cm->size,
186 pr_err("IO region %xh-%xh already allocated\n",
187 ioaddr, ioaddr + cm->size - 1);
189 goto err_free_arcdev;
192 /* Dummy access after Reset
193 * ARCNET controller needs
194 * this access to detect bustype
196 arcnet_outb(0x00, ioaddr, COM20020_REG_W_COMMAND);
197 arcnet_inb(ioaddr, COM20020_REG_R_DIAGSTAT);
199 SET_NETDEV_DEV(dev, &pdev->dev);
200 dev->base_addr = ioaddr;
201 arcnet_set_addr(dev, node);
202 dev->sysfs_groups[0] = &com20020_state_group;
203 dev->irq = pdev->irq;
204 lp->card_name = "PCI COM20020";
205 lp->card_flags = ci->flags;
206 lp->backplane = backplane;
207 lp->clockp = clockp & 7;
208 lp->clockm = clockm & 3;
209 lp->timeout = timeout;
210 lp->hw.owner = THIS_MODULE;
212 lp->backplane = (inb(priv->misc) >> (2 + i)) & 0x1;
214 if (!strncmp(ci->name, "EAE PLX-PCI FB2", 15))
217 if (ci->flags & ARC_HAS_ROTARY) {
218 /* Get the dev_id from the PLX rotary coder */
219 if (!strncmp(ci->name, "EAE PLX-PCI MA1", 15))
221 dev->dev_id = (inb(priv->misc + ci->rotary) >> 4) & dev_id_mask;
222 snprintf(dev->name, sizeof(dev->name), "arc%d-%d", dev->dev_id, i);
225 if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
226 pr_err("IO address %Xh is empty!\n", ioaddr);
228 goto err_free_arcdev;
230 if (com20020_check(dev)) {
232 goto err_free_arcdev;
235 ret = com20020_found(dev, IRQF_SHARED);
237 goto err_free_arcdev;
239 card = devm_kzalloc(&pdev->dev, sizeof(struct com20020_dev),
243 goto err_free_arcdev;
247 card->pci_priv = priv;
249 if (ci->flags & ARC_HAS_LED) {
250 card->tx_led.brightness_set = led_tx_set;
251 card->tx_led.default_trigger = devm_kasprintf(&pdev->dev,
252 GFP_KERNEL, "arc%d-%d-tx",
254 card->tx_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
255 "pci:green:tx:%d-%d",
258 card->tx_led.dev = &dev->dev;
259 card->recon_led.brightness_set = led_recon_set;
260 card->recon_led.default_trigger = devm_kasprintf(&pdev->dev,
261 GFP_KERNEL, "arc%d-%d-recon",
263 card->recon_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
264 "pci:red:recon:%d-%d",
266 card->recon_led.dev = &dev->dev;
268 ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);
270 goto err_free_arcdev;
272 ret = devm_led_classdev_register(&pdev->dev, &card->recon_led);
274 goto err_free_arcdev;
276 dev_set_drvdata(&dev->dev, card);
277 devm_arcnet_led_init(dev, dev->dev_id, i);
281 list_add(&card->list, &priv->list_dev);
289 com20020pci_remove(pdev);
293 static void com20020pci_remove(struct pci_dev *pdev)
295 struct com20020_dev *card, *tmpcard;
296 struct com20020_priv *priv;
298 priv = pci_get_drvdata(pdev);
300 list_for_each_entry_safe(card, tmpcard, &priv->list_dev, list) {
301 struct net_device *dev = card->dev;
303 unregister_netdev(dev);
304 free_irq(dev->irq, dev);
309 static struct com20020_pci_card_info card_info_10mbit = {
319 .flags = ARC_CAN_10MBIT,
322 static struct com20020_pci_card_info card_info_5mbit = {
332 .flags = ARC_IS_5MBIT,
335 static struct com20020_pci_card_info card_info_sohard = {
336 .name = "SOHARD SH ARC-PCI",
338 /* SOHARD needs PCI base addr 4 */
346 .flags = ARC_CAN_10MBIT,
349 static struct com20020_pci_card_info card_info_eae_arc1 = {
350 .name = "EAE PLX-PCI ARC1",
371 .flags = ARC_HAS_ROTARY | ARC_HAS_LED | ARC_CAN_10MBIT,
374 static struct com20020_pci_card_info card_info_eae_ma1 = {
375 .name = "EAE PLX-PCI MA1",
403 .flags = ARC_HAS_ROTARY | ARC_HAS_LED | ARC_CAN_10MBIT,
406 static struct com20020_pci_card_info card_info_eae_fb2 = {
407 .name = "EAE PLX-PCI FB2",
428 .flags = ARC_HAS_ROTARY | ARC_HAS_LED | ARC_CAN_10MBIT,
431 static const struct pci_device_id com20020pci_id_table[] = {
434 PCI_ANY_ID, PCI_ANY_ID,
440 PCI_ANY_ID, PCI_ANY_ID,
446 PCI_ANY_ID, PCI_ANY_ID,
452 PCI_ANY_ID, PCI_ANY_ID,
458 PCI_ANY_ID, PCI_ANY_ID,
464 PCI_ANY_ID, PCI_ANY_ID,
470 PCI_ANY_ID, PCI_ANY_ID,
476 PCI_ANY_ID, PCI_ANY_ID,
482 PCI_ANY_ID, PCI_ANY_ID,
484 (kernel_ulong_t)&card_info_5mbit
488 PCI_ANY_ID, PCI_ANY_ID,
490 (kernel_ulong_t)&card_info_5mbit
494 PCI_ANY_ID, PCI_ANY_ID,
496 (kernel_ulong_t)&card_info_5mbit
500 PCI_ANY_ID, PCI_ANY_ID,
502 (kernel_ulong_t)&card_info_5mbit
506 PCI_ANY_ID, PCI_ANY_ID,
508 (kernel_ulong_t)&card_info_5mbit
512 PCI_ANY_ID, PCI_ANY_ID,
514 (kernel_ulong_t)&card_info_5mbit
518 PCI_ANY_ID, PCI_ANY_ID,
520 (kernel_ulong_t)&card_info_10mbit
524 PCI_ANY_ID, PCI_ANY_ID,
526 (kernel_ulong_t)&card_info_10mbit
530 PCI_ANY_ID, PCI_ANY_ID,
532 (kernel_ulong_t)&card_info_10mbit
536 PCI_ANY_ID, PCI_ANY_ID,
538 (kernel_ulong_t)&card_info_10mbit
542 PCI_ANY_ID, PCI_ANY_ID,
544 (kernel_ulong_t)&card_info_10mbit
548 PCI_ANY_ID, PCI_ANY_ID,
550 (kernel_ulong_t)&card_info_10mbit
556 (kernel_ulong_t)&card_info_sohard
562 (kernel_ulong_t)&card_info_sohard
568 (kernel_ulong_t)&card_info_eae_arc1
574 (kernel_ulong_t)&card_info_eae_ma1
580 (kernel_ulong_t)&card_info_eae_fb2
584 PCI_ANY_ID, PCI_ANY_ID,
586 (kernel_ulong_t)&card_info_10mbit
590 PCI_ANY_ID, PCI_ANY_ID,
592 (kernel_ulong_t)&card_info_10mbit
597 MODULE_DEVICE_TABLE(pci, com20020pci_id_table);
599 static struct pci_driver com20020pci_driver = {
601 .id_table = com20020pci_id_table,
602 .probe = com20020pci_probe,
603 .remove = com20020pci_remove,
606 static int __init com20020pci_init(void)
608 if (BUGLVL(D_NORMAL))
609 pr_info("%s\n", "COM20020 PCI support");
610 return pci_register_driver(&com20020pci_driver);
613 static void __exit com20020pci_cleanup(void)
615 pci_unregister_driver(&com20020pci_driver);
618 module_init(com20020pci_init)
619 module_exit(com20020pci_cleanup)