diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-04-22 15:33:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-23 13:36:27 -0400 |
commit | fa3cb2191091657038ddb9207888b6cfb11fdf6e (patch) | |
tree | 07af605bdd4d1b5596260427eaa5d0900f8f5b2e | |
parent | 4623c3e0a997e7bac5cb45bb57edcd082f131708 (diff) |
staging: comedi: ni_labpc: split out PCI support
Currently the ni_labpc driver is used by the legacy (ISA), PCI, and
PCMCIA versions of the LabPC board. The driver is enabled under the
COMEDI_PCI_DRIVERS section of the Kconfig. This means that PCI support
must be enabled in order to use the ni_labpc driver for the PCI or
PCMCIA drivers.
Split the PCI support code out of the ni_labpc driver into a separate
driver, ni_labpc_pci. The PCMCIA support is already slip out as
ni_labpc_cs.
Modify the Kconfig so that the common code in ni_labpc is enabled by the
Kconfig option COMEDI_NI_LABPC. The ISA support code is currently still
in the ni_labpc driver but is only compiled in if COMEDI_NI_LABPC_ISA is
also enabled.
This allows the PCI and PCMCIA drivers to be enabled without the need
for the ISA stuff.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/Kconfig | 35 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/ni_labpc.c | 185 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/ni_labpc_pci.c | 143 |
4 files changed, 199 insertions, 165 deletions
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 9600225ff641..7871579bb83d 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig | |||
@@ -484,6 +484,19 @@ config COMEDI_NI_ATMIO16D | |||
484 | To compile this driver as a module, choose M here: the module will be | 484 | To compile this driver as a module, choose M here: the module will be |
485 | called ni_atmio16d. | 485 | called ni_atmio16d. |
486 | 486 | ||
487 | config COMEDI_NI_LABPC_ISA | ||
488 | tristate "NI Lab-PC and compatibles ISA support" | ||
489 | select COMEDI_NI_LABPC | ||
490 | depends on VIRT_TO_BUS | ||
491 | ---help--- | ||
492 | Enable support for National Instruments Lab-PC and compatibles | ||
493 | Lab-PC-1200, Lab-PC-1200AI, Lab-PC+. | ||
494 | Kernel-level ISA plug-and-play support for the lab-pc-1200 boards has | ||
495 | not yet been added to the driver. | ||
496 | |||
497 | To compile this driver as a module, choose M here: the module will be | ||
498 | called ni_labpc. | ||
499 | |||
487 | config COMEDI_PCMAD | 500 | config COMEDI_PCMAD |
488 | tristate "Winsystems PCM-A/D12 and PCM-A/D16 PC/104 board support" | 501 | tristate "Winsystems PCM-A/D12 and PCM-A/D16 PC/104 board support" |
489 | ---help--- | 502 | ---help--- |
@@ -1007,20 +1020,15 @@ config COMEDI_NI_670X | |||
1007 | To compile this driver as a module, choose M here: the module will be | 1020 | To compile this driver as a module, choose M here: the module will be |
1008 | called ni_670x. | 1021 | called ni_670x. |
1009 | 1022 | ||
1010 | config COMEDI_NI_LABPC | 1023 | config COMEDI_NI_LABPC_PCI |
1011 | tristate "NI Lab-PC and compatibles ISA and PCI support" | 1024 | tristate "NI Lab-PC PCI-1200 support" |
1025 | select COMEDI_NI_LABPC | ||
1012 | select COMEDI_MITE | 1026 | select COMEDI_MITE |
1013 | select COMEDI_8255 | ||
1014 | select COMEDI_FC | ||
1015 | depends on VIRT_TO_BUS | ||
1016 | ---help--- | 1027 | ---help--- |
1017 | Enable support for National Instruments Lab-PC and compatibles | 1028 | Enable support for National Instruments Lab-PC PCI-1200. |
1018 | Lab-PC-1200, Lab-PC-1200AI, Lab-PC+ and PCI-1200. | ||
1019 | Kernel-level ISA plug-and-play support for the lab-pc-1200 boards has | ||
1020 | not yet been added to the driver. | ||
1021 | 1029 | ||
1022 | To compile this driver as a module, choose M here: the module will be | 1030 | To compile this driver as a module, choose M here: the module will be |
1023 | called ni_labpc. | 1031 | called ni_labpc_pci. |
1024 | 1032 | ||
1025 | config COMEDI_NI_PCIDIO | 1033 | config COMEDI_NI_PCIDIO |
1026 | tristate "NI PCI-DIO32HS, PCI-6533, PCI-6534 support" | 1034 | tristate "NI PCI-DIO32HS, PCI-6533, PCI-6534 support" |
@@ -1142,7 +1150,7 @@ config COMEDI_NI_DAQ_DIO24_CS | |||
1142 | 1150 | ||
1143 | config COMEDI_NI_LABPC_CS | 1151 | config COMEDI_NI_LABPC_CS |
1144 | tristate "NI DAQCard-1200 PCMCIA support" | 1152 | tristate "NI DAQCard-1200 PCMCIA support" |
1145 | depends on COMEDI_NI_LABPC | 1153 | select COMEDI_NI_LABPC |
1146 | ---help--- | 1154 | ---help--- |
1147 | Enable support for the National Instruments PCMCIA DAQCard-1200 | 1155 | Enable support for the National Instruments PCMCIA DAQCard-1200 |
1148 | 1156 | ||
@@ -1255,6 +1263,11 @@ config COMEDI_DAS08 | |||
1255 | tristate | 1263 | tristate |
1256 | select COMEDI_8255 | 1264 | select COMEDI_8255 |
1257 | 1265 | ||
1266 | config COMEDI_NI_LABPC | ||
1267 | tristate | ||
1268 | select COMEDI_8255 | ||
1269 | select COMEDI_FC | ||
1270 | |||
1258 | config COMEDI_NI_TIO | 1271 | config COMEDI_NI_TIO |
1259 | tristate | 1272 | tristate |
1260 | 1273 | ||
diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index bb5634e49883..57e984f0f462 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile | |||
@@ -106,6 +106,7 @@ obj-$(CONFIG_COMEDI_NI_6527) += ni_6527.o | |||
106 | obj-$(CONFIG_COMEDI_NI_65XX) += ni_65xx.o | 106 | obj-$(CONFIG_COMEDI_NI_65XX) += ni_65xx.o |
107 | obj-$(CONFIG_COMEDI_NI_660X) += ni_660x.o | 107 | obj-$(CONFIG_COMEDI_NI_660X) += ni_660x.o |
108 | obj-$(CONFIG_COMEDI_NI_670X) += ni_670x.o | 108 | obj-$(CONFIG_COMEDI_NI_670X) += ni_670x.o |
109 | obj-$(CONFIG_COMEDI_NI_LABPC_PCI) += ni_labpc_pci.o | ||
109 | obj-$(CONFIG_COMEDI_NI_PCIDIO) += ni_pcidio.o | 110 | obj-$(CONFIG_COMEDI_NI_PCIDIO) += ni_pcidio.o |
110 | obj-$(CONFIG_COMEDI_NI_PCIMIO) += ni_pcimio.o | 111 | obj-$(CONFIG_COMEDI_NI_PCIMIO) += ni_pcimio.o |
111 | obj-$(CONFIG_COMEDI_RTD520) += rtd520.o | 112 | obj-$(CONFIG_COMEDI_RTD520) += rtd520.o |
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 96a6837774e0..e8fc6a1c629a 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c | |||
@@ -24,7 +24,6 @@ | |||
24 | * Devices: (National Instruments) Lab-PC-1200 [lab-pc-1200] | 24 | * Devices: (National Instruments) Lab-PC-1200 [lab-pc-1200] |
25 | * (National Instruments) Lab-PC-1200AI [lab-pc-1200ai] | 25 | * (National Instruments) Lab-PC-1200AI [lab-pc-1200ai] |
26 | * (National Instruments) Lab-PC+ [lab-pc+] | 26 | * (National Instruments) Lab-PC+ [lab-pc+] |
27 | * (National Instruments) PCI-1200 [pci-1200] | ||
28 | * Author: Frank Mori Hess <fmhess@users.sourceforge.net> | 27 | * Author: Frank Mori Hess <fmhess@users.sourceforge.net> |
29 | * Status: works | 28 | * Status: works |
30 | * | 29 | * |
@@ -34,9 +33,6 @@ | |||
34 | * conversions) | 33 | * conversions) |
35 | * [2] - DMA channel (optional) | 34 | * [2] - DMA channel (optional) |
36 | * | 35 | * |
37 | * Configuration options - PCI boards: | ||
38 | * not applicable, uses PCI auto config | ||
39 | * | ||
40 | * Tested with lab-pc-1200. For the older Lab-PC+, not all input | 36 | * Tested with lab-pc-1200. For the older Lab-PC+, not all input |
41 | * ranges and analog references will work, the available ranges/arefs | 37 | * ranges and analog references will work, the available ranges/arefs |
42 | * will depend on how you have configured the jumpers on your board | 38 | * will depend on how you have configured the jumpers on your board |
@@ -62,11 +58,9 @@ | |||
62 | * | 58 | * |
63 | * NI manuals: | 59 | * NI manuals: |
64 | * 341309a (labpc-1200 register manual) | 60 | * 341309a (labpc-1200 register manual) |
65 | * 340914a (pci-1200) | ||
66 | * 320502b (lab-pc+) | 61 | * 320502b (lab-pc+) |
67 | */ | 62 | */ |
68 | 63 | ||
69 | #include <linux/pci.h> | ||
70 | #include <linux/interrupt.h> | 64 | #include <linux/interrupt.h> |
71 | #include <linux/slab.h> | 65 | #include <linux/slab.h> |
72 | #include <linux/io.h> | 66 | #include <linux/io.h> |
@@ -78,7 +72,6 @@ | |||
78 | 72 | ||
79 | #include "8253.h" | 73 | #include "8253.h" |
80 | #include "8255.h" | 74 | #include "8255.h" |
81 | #include "mite.h" | ||
82 | #include "comedi_fc.h" | 75 | #include "comedi_fc.h" |
83 | #include "ni_labpc.h" | 76 | #include "ni_labpc.h" |
84 | 77 | ||
@@ -241,6 +234,7 @@ static inline void labpc_writeb(unsigned int byte, unsigned long address) | |||
241 | writeb(byte, (void __iomem *)address); | 234 | writeb(byte, (void __iomem *)address); |
242 | } | 235 | } |
243 | 236 | ||
237 | #ifdef CONFIG_COMEDI_NI_LABPC_ISA | ||
244 | static const struct labpc_boardinfo labpc_boards[] = { | 238 | static const struct labpc_boardinfo labpc_boards[] = { |
245 | { | 239 | { |
246 | .name = "lab-pc-1200", | 240 | .name = "lab-pc-1200", |
@@ -268,21 +262,8 @@ static const struct labpc_boardinfo labpc_boards[] = { | |||
268 | .ai_range_table = &range_labpc_plus_ai, | 262 | .ai_range_table = &range_labpc_plus_ai, |
269 | .ai_range_code = labpc_plus_ai_gain_bits, | 263 | .ai_range_code = labpc_plus_ai_gain_bits, |
270 | }, | 264 | }, |
271 | #ifdef CONFIG_COMEDI_PCI_DRIVERS | ||
272 | { | ||
273 | .name = "pci-1200", | ||
274 | .device_id = 0x161, | ||
275 | .ai_speed = 10000, | ||
276 | .bustype = pci_bustype, | ||
277 | .register_layout = labpc_1200_layout, | ||
278 | .has_ao = 1, | ||
279 | .ai_range_table = &range_labpc_1200_ai, | ||
280 | .ai_range_code = labpc_1200_ai_gain_bits, | ||
281 | .ai_scan_up = 1, | ||
282 | .has_mmio = 1, | ||
283 | }, | ||
284 | #endif | ||
285 | }; | 265 | }; |
266 | #endif | ||
286 | 267 | ||
287 | /* size in bytes of dma buffer */ | 268 | /* size in bytes of dma buffer */ |
288 | static const int dma_buffer_size = 0xff00; | 269 | static const int dma_buffer_size = 0xff00; |
@@ -1754,12 +1735,19 @@ int labpc_common_attach(struct comedi_device *dev, | |||
1754 | } | 1735 | } |
1755 | EXPORT_SYMBOL_GPL(labpc_common_attach); | 1736 | EXPORT_SYMBOL_GPL(labpc_common_attach); |
1756 | 1737 | ||
1738 | void labpc_common_detach(struct comedi_device *dev) | ||
1739 | { | ||
1740 | comedi_spriv_free(dev, 2); | ||
1741 | } | ||
1742 | EXPORT_SYMBOL_GPL(labpc_common_detach); | ||
1743 | |||
1744 | #ifdef CONFIG_COMEDI_NI_LABPC_ISA | ||
1757 | static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) | 1745 | static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
1758 | { | 1746 | { |
1759 | const struct labpc_boardinfo *board = comedi_board(dev); | 1747 | const struct labpc_boardinfo *board = comedi_board(dev); |
1760 | struct labpc_private *devpriv; | 1748 | struct labpc_private *devpriv; |
1761 | unsigned int irq = 0; | 1749 | unsigned int irq = it->options[1]; |
1762 | unsigned int dma_chan = 0; | 1750 | unsigned int dma_chan = it->options[2]; |
1763 | int ret; | 1751 | int ret; |
1764 | 1752 | ||
1765 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); | 1753 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); |
@@ -1767,161 +1755,50 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
1767 | return -ENOMEM; | 1755 | return -ENOMEM; |
1768 | dev->private = devpriv; | 1756 | dev->private = devpriv; |
1769 | 1757 | ||
1770 | /* get base address, irq etc. based on bustype */ | 1758 | ret = comedi_request_region(dev, it->options[0], LABPC_SIZE); |
1771 | switch (board->bustype) { | ||
1772 | case isa_bustype: | ||
1773 | #ifdef CONFIG_ISA_DMA_API | ||
1774 | irq = it->options[1]; | ||
1775 | dma_chan = it->options[2]; | ||
1776 | ret = comedi_request_region(dev, it->options[0], LABPC_SIZE); | ||
1777 | if (ret) | ||
1778 | return ret; | ||
1779 | #else | ||
1780 | dev_err(dev->class_dev, | ||
1781 | "ni_labpc driver has not been built with ISA DMA support.\n"); | ||
1782 | return -EINVAL; | ||
1783 | #endif | ||
1784 | break; | ||
1785 | case pci_bustype: | ||
1786 | #ifdef CONFIG_COMEDI_PCI_DRIVERS | ||
1787 | dev_err(dev->class_dev, | ||
1788 | "manual configuration of PCI board '%s' is not supported\n", | ||
1789 | board->name); | ||
1790 | return -EINVAL; | ||
1791 | #else | ||
1792 | dev_err(dev->class_dev, | ||
1793 | "ni_labpc driver has not been built with PCI support.\n"); | ||
1794 | return -EINVAL; | ||
1795 | #endif | ||
1796 | break; | ||
1797 | default: | ||
1798 | dev_err(dev->class_dev, | ||
1799 | "ni_labpc: bug! couldn't determine board type\n"); | ||
1800 | return -EINVAL; | ||
1801 | break; | ||
1802 | } | ||
1803 | |||
1804 | return labpc_common_attach(dev, irq, dma_chan); | ||
1805 | } | ||
1806 | |||
1807 | static const struct labpc_boardinfo * | ||
1808 | labpc_pci_find_boardinfo(struct pci_dev *pcidev) | ||
1809 | { | ||
1810 | unsigned int device_id = pcidev->device; | ||
1811 | unsigned int n; | ||
1812 | |||
1813 | for (n = 0; n < ARRAY_SIZE(labpc_boards); n++) { | ||
1814 | const struct labpc_boardinfo *board = &labpc_boards[n]; | ||
1815 | if (board->bustype == pci_bustype && | ||
1816 | board->device_id == device_id) | ||
1817 | return board; | ||
1818 | } | ||
1819 | return NULL; | ||
1820 | } | ||
1821 | |||
1822 | static int labpc_auto_attach(struct comedi_device *dev, | ||
1823 | unsigned long context_unused) | ||
1824 | { | ||
1825 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); | ||
1826 | const struct labpc_boardinfo *board; | ||
1827 | struct labpc_private *devpriv; | ||
1828 | unsigned int irq; | ||
1829 | int ret; | ||
1830 | |||
1831 | if (!IS_ENABLED(CONFIG_COMEDI_PCI_DRIVERS)) | ||
1832 | return -ENODEV; | ||
1833 | |||
1834 | ret = comedi_pci_enable(dev); | ||
1835 | if (ret) | 1759 | if (ret) |
1836 | return ret; | 1760 | return ret; |
1837 | 1761 | ||
1838 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); | 1762 | return labpc_common_attach(dev, irq, dma_chan); |
1839 | if (!devpriv) | ||
1840 | return -ENOMEM; | ||
1841 | dev->private = devpriv; | ||
1842 | |||
1843 | board = labpc_pci_find_boardinfo(pcidev); | ||
1844 | if (!board) | ||
1845 | return -ENODEV; | ||
1846 | dev->board_ptr = board; | ||
1847 | dev->board_name = board->name; | ||
1848 | devpriv->mite = mite_alloc(pcidev); | ||
1849 | if (!devpriv->mite) | ||
1850 | return -ENOMEM; | ||
1851 | ret = mite_setup(devpriv->mite); | ||
1852 | if (ret < 0) | ||
1853 | return ret; | ||
1854 | dev->iobase = (unsigned long)devpriv->mite->daq_io_addr; | ||
1855 | irq = mite_irq(devpriv->mite); | ||
1856 | return labpc_common_attach(dev, irq, 0); | ||
1857 | } | 1763 | } |
1858 | 1764 | ||
1859 | void labpc_common_detach(struct comedi_device *dev) | 1765 | void labpc_detach(struct comedi_device *dev) |
1860 | { | 1766 | { |
1861 | const struct labpc_boardinfo *board = comedi_board(dev); | ||
1862 | struct labpc_private *devpriv = dev->private; | 1767 | struct labpc_private *devpriv = dev->private; |
1863 | 1768 | ||
1864 | if (!board) | 1769 | labpc_common_detach(dev); |
1865 | return; | 1770 | |
1866 | comedi_spriv_free(dev, 2); | 1771 | if (devpriv) { |
1867 | #ifdef CONFIG_ISA_DMA_API | 1772 | kfree(devpriv->dma_buffer); |
1868 | /* only free stuff if it has been allocated by _attach */ | 1773 | if (devpriv->dma_chan) |
1869 | kfree(devpriv->dma_buffer); | 1774 | free_dma(devpriv->dma_chan); |
1870 | if (devpriv->dma_chan) | ||
1871 | free_dma(devpriv->dma_chan); | ||
1872 | #endif | ||
1873 | if (board->bustype == isa_bustype) | ||
1874 | comedi_legacy_detach(dev); | ||
1875 | #ifdef CONFIG_COMEDI_PCI_DRIVERS | ||
1876 | if (devpriv->mite) { | ||
1877 | mite_unsetup(devpriv->mite); | ||
1878 | mite_free(devpriv->mite); | ||
1879 | } | ||
1880 | if (board->bustype == pci_bustype) { | ||
1881 | if (dev->irq) | ||
1882 | free_irq(dev->irq, dev); | ||
1883 | comedi_pci_disable(dev); | ||
1884 | } | 1775 | } |
1885 | #endif | 1776 | comedi_legacy_detach(dev); |
1886 | } | 1777 | } |
1887 | EXPORT_SYMBOL_GPL(labpc_common_detach); | ||
1888 | 1778 | ||
1889 | static struct comedi_driver labpc_driver = { | 1779 | static struct comedi_driver labpc_driver = { |
1890 | .driver_name = "ni_labpc", | 1780 | .driver_name = "ni_labpc", |
1891 | .module = THIS_MODULE, | 1781 | .module = THIS_MODULE, |
1892 | .attach = labpc_attach, | 1782 | .attach = labpc_attach, |
1893 | .auto_attach = labpc_auto_attach, | 1783 | .detach = labpc_detach, |
1894 | .detach = labpc_common_detach, | ||
1895 | .num_names = ARRAY_SIZE(labpc_boards), | 1784 | .num_names = ARRAY_SIZE(labpc_boards), |
1896 | .board_name = &labpc_boards[0].name, | 1785 | .board_name = &labpc_boards[0].name, |
1897 | .offset = sizeof(struct labpc_boardinfo), | 1786 | .offset = sizeof(struct labpc_boardinfo), |
1898 | }; | 1787 | }; |
1899 | 1788 | module_comedi_driver(labpc_driver); | |
1900 | #ifdef CONFIG_COMEDI_PCI_DRIVERS | 1789 | #else |
1901 | static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = { | 1790 | static int __init labpc_common_init(void) |
1902 | { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x161) }, | ||
1903 | { 0 } | ||
1904 | }; | ||
1905 | MODULE_DEVICE_TABLE(pci, labpc_pci_table); | ||
1906 | |||
1907 | static int labpc_pci_probe(struct pci_dev *dev, | ||
1908 | const struct pci_device_id *id) | ||
1909 | { | 1791 | { |
1910 | return comedi_pci_auto_config(dev, &labpc_driver, id->driver_data); | 1792 | return 0; |
1911 | } | 1793 | } |
1794 | module_init(labpc_common_init); | ||
1912 | 1795 | ||
1913 | static struct pci_driver labpc_pci_driver = { | 1796 | static void __exit labpc_common_exit(void) |
1914 | .name = "ni_labpc", | 1797 | { |
1915 | .id_table = labpc_pci_table, | 1798 | } |
1916 | .probe = labpc_pci_probe, | 1799 | module_exit(labpc_common_exit); |
1917 | .remove = comedi_pci_auto_unconfig, | ||
1918 | }; | ||
1919 | module_comedi_pci_driver(labpc_driver, labpc_pci_driver); | ||
1920 | #else | ||
1921 | module_comedi_driver(labpc_driver); | ||
1922 | #endif | 1800 | #endif |
1923 | 1801 | ||
1924 | |||
1925 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | 1802 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
1926 | MODULE_DESCRIPTION("Comedi low-level driver"); | 1803 | MODULE_DESCRIPTION("Comedi low-level driver"); |
1927 | MODULE_LICENSE("GPL"); | 1804 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c new file mode 100644 index 000000000000..82e381fe34ee --- /dev/null +++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * comedi/drivers/ni_labpc_pci.c | ||
3 | * Driver for National Instruments Lab-PC PCI-1200 | ||
4 | * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | * Driver: ni_labpc_pci | ||
23 | * Description: National Instruments Lab-PC PCI-1200 | ||
24 | * Devices: (National Instruments) PCI-1200 [ni_pci-1200] | ||
25 | * Author: Frank Mori Hess <fmhess@users.sourceforge.net> | ||
26 | * Status: works | ||
27 | * | ||
28 | * This is the PCI-specific support split off from the ni_labpc driver. | ||
29 | * | ||
30 | * Configuration Options: not applicable, uses PCI auto config | ||
31 | * | ||
32 | * NI manuals: | ||
33 | * 340914a (pci-1200) | ||
34 | */ | ||
35 | |||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/pci.h> | ||
39 | |||
40 | #include "../comedidev.h" | ||
41 | |||
42 | #include "mite.h" | ||
43 | #include "ni_labpc.h" | ||
44 | |||
45 | enum labpc_pci_boardid { | ||
46 | BOARD_NI_PCI1200, | ||
47 | }; | ||
48 | |||
49 | static const struct labpc_boardinfo labpc_pci_boards[] = { | ||
50 | [BOARD_NI_PCI1200] = { | ||
51 | .name = "ni_pci-1200", | ||
52 | .ai_speed = 10000, | ||
53 | .bustype = pci_bustype, | ||
54 | .register_layout = labpc_1200_layout, | ||
55 | .has_ao = 1, | ||
56 | .ai_range_table = &range_labpc_1200_ai, | ||
57 | .ai_range_code = labpc_1200_ai_gain_bits, | ||
58 | .ai_scan_up = 1, | ||
59 | .has_mmio = 1, | ||
60 | }, | ||
61 | }; | ||
62 | |||
63 | static int labpc_pci_auto_attach(struct comedi_device *dev, | ||
64 | unsigned long context) | ||
65 | { | ||
66 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); | ||
67 | const struct labpc_boardinfo *board = NULL; | ||
68 | struct labpc_private *devpriv; | ||
69 | int ret; | ||
70 | |||
71 | if (context < ARRAY_SIZE(labpc_pci_boards)) | ||
72 | board = &labpc_pci_boards[context]; | ||
73 | if (!board) | ||
74 | return -ENODEV; | ||
75 | dev->board_ptr = board; | ||
76 | dev->board_name = board->name; | ||
77 | |||
78 | ret = comedi_pci_enable(dev); | ||
79 | if (ret) | ||
80 | return ret; | ||
81 | |||
82 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); | ||
83 | if (!devpriv) | ||
84 | return -ENOMEM; | ||
85 | dev->private = devpriv; | ||
86 | |||
87 | devpriv->mite = mite_alloc(pcidev); | ||
88 | if (!devpriv->mite) | ||
89 | return -ENOMEM; | ||
90 | ret = mite_setup(devpriv->mite); | ||
91 | if (ret < 0) | ||
92 | return ret; | ||
93 | dev->iobase = (unsigned long)devpriv->mite->daq_io_addr; | ||
94 | |||
95 | return labpc_common_attach(dev, mite_irq(devpriv->mite), 0); | ||
96 | } | ||
97 | |||
98 | static void labpc_pci_detach(struct comedi_device *dev) | ||
99 | { | ||
100 | struct labpc_private *devpriv = dev->private; | ||
101 | |||
102 | labpc_common_detach(dev); | ||
103 | |||
104 | if (devpriv && devpriv->mite) { | ||
105 | mite_unsetup(devpriv->mite); | ||
106 | mite_free(devpriv->mite); | ||
107 | } | ||
108 | if (dev->irq) | ||
109 | free_irq(dev->irq, dev); | ||
110 | comedi_pci_disable(dev); | ||
111 | } | ||
112 | |||
113 | static struct comedi_driver labpc_pci_comedi_driver = { | ||
114 | .driver_name = "labpc_pci", | ||
115 | .module = THIS_MODULE, | ||
116 | .auto_attach = labpc_pci_auto_attach, | ||
117 | .detach = labpc_pci_detach, | ||
118 | }; | ||
119 | |||
120 | static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = { | ||
121 | { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 }, | ||
122 | { 0 } | ||
123 | }; | ||
124 | MODULE_DEVICE_TABLE(pci, labpc_pci_table); | ||
125 | |||
126 | static int labpc_pci_probe(struct pci_dev *dev, | ||
127 | const struct pci_device_id *id) | ||
128 | { | ||
129 | return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver, | ||
130 | id->driver_data); | ||
131 | } | ||
132 | |||
133 | static struct pci_driver labpc_pci_driver = { | ||
134 | .name = "labpc_pci", | ||
135 | .id_table = labpc_pci_table, | ||
136 | .probe = labpc_pci_probe, | ||
137 | .remove = comedi_pci_auto_unconfig, | ||
138 | }; | ||
139 | module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver); | ||
140 | |||
141 | MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver"); | ||
142 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | ||
143 | MODULE_LICENSE("GPL"); | ||