Stephen Hemminger | bce5c2e | 2018-07-21 06:31:39 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 2 | /* |
| 3 | * UIO Hilscher CIF card driver |
| 4 | * |
Hans J. Koch | 318af55 | 2010-10-30 00:36:47 +0200 | [diff] [blame] | 5 | * (C) 2007 Hans J. Koch <hjk@hansjkoch.de> |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 6 | * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de> |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 13 | #include <linux/uio_driver.h> |
| 14 | |
| 15 | #include <asm/io.h> |
| 16 | |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 17 | #define PLX9030_INTCSR 0x4C |
| 18 | #define INTSCR_INT1_ENABLE 0x01 |
| 19 | #define INTSCR_INT1_STATUS 0x04 |
| 20 | #define INT1_ENABLED_AND_ACTIVE (INTSCR_INT1_ENABLE | INTSCR_INT1_STATUS) |
| 21 | |
| 22 | #define PCI_SUBVENDOR_ID_PEP 0x1518 |
| 23 | #define CIF_SUBDEVICE_PROFIBUS 0x430 |
| 24 | #define CIF_SUBDEVICE_DEVICENET 0x432 |
| 25 | |
| 26 | |
| 27 | static irqreturn_t hilscher_handler(int irq, struct uio_info *dev_info) |
| 28 | { |
| 29 | void __iomem *plx_intscr = dev_info->mem[0].internal_addr |
| 30 | + PLX9030_INTCSR; |
| 31 | |
| 32 | if ((ioread8(plx_intscr) & INT1_ENABLED_AND_ACTIVE) |
| 33 | != INT1_ENABLED_AND_ACTIVE) |
| 34 | return IRQ_NONE; |
| 35 | |
| 36 | /* Disable interrupt */ |
| 37 | iowrite8(ioread8(plx_intscr) & ~INTSCR_INT1_ENABLE, plx_intscr); |
| 38 | return IRQ_HANDLED; |
| 39 | } |
| 40 | |
Bill Pemberton | b17b75b | 2012-11-19 13:21:49 -0500 | [diff] [blame] | 41 | static int hilscher_pci_probe(struct pci_dev *dev, |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 42 | const struct pci_device_id *id) |
| 43 | { |
| 44 | struct uio_info *info; |
| 45 | |
Alexandru Ardelean | 0a4ade5 | 2020-11-19 17:49:00 +0200 | [diff] [blame] | 46 | info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 47 | if (!info) |
| 48 | return -ENOMEM; |
| 49 | |
| 50 | if (pci_enable_device(dev)) |
Alexandru Ardelean | 0a4ade5 | 2020-11-19 17:49:00 +0200 | [diff] [blame] | 51 | return -ENODEV; |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 52 | |
| 53 | if (pci_request_regions(dev, "hilscher")) |
| 54 | goto out_disable; |
| 55 | |
| 56 | info->mem[0].addr = pci_resource_start(dev, 0); |
| 57 | if (!info->mem[0].addr) |
| 58 | goto out_release; |
Arjan van de Ven | 7898aa5 | 2008-10-21 11:17:51 +0200 | [diff] [blame] | 59 | info->mem[0].internal_addr = pci_ioremap_bar(dev, 0); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 60 | if (!info->mem[0].internal_addr) |
| 61 | goto out_release; |
| 62 | |
| 63 | info->mem[0].size = pci_resource_len(dev, 0); |
| 64 | info->mem[0].memtype = UIO_MEM_PHYS; |
| 65 | info->mem[1].addr = pci_resource_start(dev, 2); |
| 66 | info->mem[1].size = pci_resource_len(dev, 2); |
| 67 | info->mem[1].memtype = UIO_MEM_PHYS; |
| 68 | switch (id->subdevice) { |
| 69 | case CIF_SUBDEVICE_PROFIBUS: |
| 70 | info->name = "CIF_Profibus"; |
| 71 | break; |
| 72 | case CIF_SUBDEVICE_DEVICENET: |
| 73 | info->name = "CIF_Devicenet"; |
| 74 | break; |
| 75 | default: |
| 76 | info->name = "CIF_???"; |
| 77 | } |
| 78 | info->version = "0.0.1"; |
| 79 | info->irq = dev->irq; |
Hans J. Koch | 14ec539 | 2010-06-10 01:18:08 +0200 | [diff] [blame] | 80 | info->irq_flags = IRQF_SHARED; |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 81 | info->handler = hilscher_handler; |
| 82 | |
| 83 | if (uio_register_device(&dev->dev, info)) |
| 84 | goto out_unmap; |
| 85 | |
| 86 | pci_set_drvdata(dev, info); |
| 87 | |
| 88 | return 0; |
| 89 | out_unmap: |
| 90 | iounmap(info->mem[0].internal_addr); |
| 91 | out_release: |
| 92 | pci_release_regions(dev); |
| 93 | out_disable: |
| 94 | pci_disable_device(dev); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 95 | return -ENODEV; |
| 96 | } |
| 97 | |
| 98 | static void hilscher_pci_remove(struct pci_dev *dev) |
| 99 | { |
| 100 | struct uio_info *info = pci_get_drvdata(dev); |
| 101 | |
| 102 | uio_unregister_device(info); |
| 103 | pci_release_regions(dev); |
| 104 | pci_disable_device(dev); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 105 | iounmap(info->mem[0].internal_addr); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Bill Pemberton | d46f743 | 2012-11-19 13:24:33 -0500 | [diff] [blame] | 108 | static struct pci_device_id hilscher_pci_ids[] = { |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 109 | { |
| 110 | .vendor = PCI_VENDOR_ID_PLX, |
| 111 | .device = PCI_DEVICE_ID_PLX_9030, |
| 112 | .subvendor = PCI_SUBVENDOR_ID_PEP, |
| 113 | .subdevice = CIF_SUBDEVICE_PROFIBUS, |
| 114 | }, |
| 115 | { |
| 116 | .vendor = PCI_VENDOR_ID_PLX, |
| 117 | .device = PCI_DEVICE_ID_PLX_9030, |
| 118 | .subvendor = PCI_SUBVENDOR_ID_PEP, |
| 119 | .subdevice = CIF_SUBDEVICE_DEVICENET, |
| 120 | }, |
| 121 | { 0, } |
| 122 | }; |
| 123 | |
| 124 | static struct pci_driver hilscher_pci_driver = { |
| 125 | .name = "hilscher", |
| 126 | .id_table = hilscher_pci_ids, |
| 127 | .probe = hilscher_pci_probe, |
| 128 | .remove = hilscher_pci_remove, |
| 129 | }; |
| 130 | |
Peter Huewe | ced9017 | 2013-05-20 22:47:42 +0200 | [diff] [blame] | 131 | module_pci_driver(hilscher_pci_driver); |
Hans J. Koch | 912335c4 | 2009-04-11 04:18:25 +0200 | [diff] [blame] | 132 | MODULE_DEVICE_TABLE(pci, hilscher_pci_ids); |
Hans-Jürgen Koch | bc4c4f4 | 2007-03-02 13:03:12 +0100 | [diff] [blame] | 133 | MODULE_LICENSE("GPL v2"); |
| 134 | MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger"); |