18ffdff6aSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
28ffdff6aSGreg Kroah-Hartman /* comedi/drivers/amplc_dio200_pci.c
38ffdff6aSGreg Kroah-Hartman *
48ffdff6aSGreg Kroah-Hartman * Driver for Amplicon PCI215, PCI272, PCIe215, PCIe236, PCIe296.
58ffdff6aSGreg Kroah-Hartman *
68ffdff6aSGreg Kroah-Hartman * Copyright (C) 2005-2013 MEV Ltd. <https://www.mev.co.uk/>
78ffdff6aSGreg Kroah-Hartman *
88ffdff6aSGreg Kroah-Hartman * COMEDI - Linux Control and Measurement Device Interface
98ffdff6aSGreg Kroah-Hartman * Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
108ffdff6aSGreg Kroah-Hartman */
118ffdff6aSGreg Kroah-Hartman
128ffdff6aSGreg Kroah-Hartman /*
138ffdff6aSGreg Kroah-Hartman * Driver: amplc_dio200_pci
148ffdff6aSGreg Kroah-Hartman * Description: Amplicon 200 Series PCI Digital I/O
158ffdff6aSGreg Kroah-Hartman * Author: Ian Abbott <abbotti@mev.co.uk>
168ffdff6aSGreg Kroah-Hartman * Devices: [Amplicon] PCI215 (amplc_dio200_pci), PCIe215, PCIe236,
178ffdff6aSGreg Kroah-Hartman * PCI272, PCIe296
188ffdff6aSGreg Kroah-Hartman * Updated: Mon, 18 Mar 2013 15:03:50 +0000
198ffdff6aSGreg Kroah-Hartman * Status: works
208ffdff6aSGreg Kroah-Hartman *
218ffdff6aSGreg Kroah-Hartman * Configuration options:
228ffdff6aSGreg Kroah-Hartman * none
238ffdff6aSGreg Kroah-Hartman *
248ffdff6aSGreg Kroah-Hartman * Manual configuration of PCI(e) cards is not supported; they are configured
258ffdff6aSGreg Kroah-Hartman * automatically.
268ffdff6aSGreg Kroah-Hartman *
278ffdff6aSGreg Kroah-Hartman * SUBDEVICES
288ffdff6aSGreg Kroah-Hartman *
298ffdff6aSGreg Kroah-Hartman * PCI215 PCIe215 PCIe236
308ffdff6aSGreg Kroah-Hartman * ------------- ------------- -------------
318ffdff6aSGreg Kroah-Hartman * Subdevices 5 8 8
328ffdff6aSGreg Kroah-Hartman * 0 PPI-X PPI-X PPI-X
338ffdff6aSGreg Kroah-Hartman * 1 PPI-Y UNUSED UNUSED
348ffdff6aSGreg Kroah-Hartman * 2 CTR-Z1 PPI-Y UNUSED
358ffdff6aSGreg Kroah-Hartman * 3 CTR-Z2 UNUSED UNUSED
368ffdff6aSGreg Kroah-Hartman * 4 INTERRUPT CTR-Z1 CTR-Z1
378ffdff6aSGreg Kroah-Hartman * 5 CTR-Z2 CTR-Z2
388ffdff6aSGreg Kroah-Hartman * 6 TIMER TIMER
398ffdff6aSGreg Kroah-Hartman * 7 INTERRUPT INTERRUPT
408ffdff6aSGreg Kroah-Hartman *
418ffdff6aSGreg Kroah-Hartman *
428ffdff6aSGreg Kroah-Hartman * PCI272 PCIe296
438ffdff6aSGreg Kroah-Hartman * ------------- -------------
448ffdff6aSGreg Kroah-Hartman * Subdevices 4 8
458ffdff6aSGreg Kroah-Hartman * 0 PPI-X PPI-X1
468ffdff6aSGreg Kroah-Hartman * 1 PPI-Y PPI-X2
478ffdff6aSGreg Kroah-Hartman * 2 PPI-Z PPI-Y1
488ffdff6aSGreg Kroah-Hartman * 3 INTERRUPT PPI-Y2
498ffdff6aSGreg Kroah-Hartman * 4 CTR-Z1
508ffdff6aSGreg Kroah-Hartman * 5 CTR-Z2
518ffdff6aSGreg Kroah-Hartman * 6 TIMER
528ffdff6aSGreg Kroah-Hartman * 7 INTERRUPT
538ffdff6aSGreg Kroah-Hartman *
548ffdff6aSGreg Kroah-Hartman * Each PPI is a 8255 chip providing 24 DIO channels. The DIO channels
558ffdff6aSGreg Kroah-Hartman * are configurable as inputs or outputs in four groups:
568ffdff6aSGreg Kroah-Hartman *
578ffdff6aSGreg Kroah-Hartman * Port A - channels 0 to 7
588ffdff6aSGreg Kroah-Hartman * Port B - channels 8 to 15
598ffdff6aSGreg Kroah-Hartman * Port CL - channels 16 to 19
608ffdff6aSGreg Kroah-Hartman * Port CH - channels 20 to 23
618ffdff6aSGreg Kroah-Hartman *
628ffdff6aSGreg Kroah-Hartman * Only mode 0 of the 8255 chips is supported.
638ffdff6aSGreg Kroah-Hartman *
648ffdff6aSGreg Kroah-Hartman * Each CTR is a 8254 chip providing 3 16-bit counter channels. Each
658ffdff6aSGreg Kroah-Hartman * channel is configured individually with INSN_CONFIG instructions. The
668ffdff6aSGreg Kroah-Hartman * specific type of configuration instruction is specified in data[0].
678ffdff6aSGreg Kroah-Hartman * Some configuration instructions expect an additional parameter in
688ffdff6aSGreg Kroah-Hartman * data[1]; others return a value in data[1]. The following configuration
698ffdff6aSGreg Kroah-Hartman * instructions are supported:
708ffdff6aSGreg Kroah-Hartman *
718ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_SET_COUNTER_MODE. Sets the counter channel's mode and
728ffdff6aSGreg Kroah-Hartman * BCD/binary setting specified in data[1].
738ffdff6aSGreg Kroah-Hartman *
748ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_8254_READ_STATUS. Reads the status register value for the
758ffdff6aSGreg Kroah-Hartman * counter channel into data[1].
768ffdff6aSGreg Kroah-Hartman *
778ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_SET_CLOCK_SRC. Sets the counter channel's clock source as
788ffdff6aSGreg Kroah-Hartman * specified in data[1] (this is a hardware-specific value). Not
798ffdff6aSGreg Kroah-Hartman * supported on PC214E. For the other boards, valid clock sources are
808ffdff6aSGreg Kroah-Hartman * 0 to 7 as follows:
818ffdff6aSGreg Kroah-Hartman *
828ffdff6aSGreg Kroah-Hartman * 0. CLK n, the counter channel's dedicated CLK input from the SK1
838ffdff6aSGreg Kroah-Hartman * connector. (N.B. for other values, the counter channel's CLKn
848ffdff6aSGreg Kroah-Hartman * pin on the SK1 connector is an output!)
858ffdff6aSGreg Kroah-Hartman * 1. Internal 10 MHz clock.
868ffdff6aSGreg Kroah-Hartman * 2. Internal 1 MHz clock.
878ffdff6aSGreg Kroah-Hartman * 3. Internal 100 kHz clock.
888ffdff6aSGreg Kroah-Hartman * 4. Internal 10 kHz clock.
898ffdff6aSGreg Kroah-Hartman * 5. Internal 1 kHz clock.
908ffdff6aSGreg Kroah-Hartman * 6. OUT n-1, the output of counter channel n-1 (see note 1 below).
918ffdff6aSGreg Kroah-Hartman * 7. Ext Clock, the counter chip's dedicated Ext Clock input from
928ffdff6aSGreg Kroah-Hartman * the SK1 connector. This pin is shared by all three counter
938ffdff6aSGreg Kroah-Hartman * channels on the chip.
948ffdff6aSGreg Kroah-Hartman *
958ffdff6aSGreg Kroah-Hartman * For the PCIe boards, clock sources in the range 0 to 31 are allowed
968ffdff6aSGreg Kroah-Hartman * and the following additional clock sources are defined:
978ffdff6aSGreg Kroah-Hartman *
988ffdff6aSGreg Kroah-Hartman * 8. HIGH logic level.
998ffdff6aSGreg Kroah-Hartman * 9. LOW logic level.
1008ffdff6aSGreg Kroah-Hartman * 10. "Pattern present" signal.
1018ffdff6aSGreg Kroah-Hartman * 11. Internal 20 MHz clock.
1028ffdff6aSGreg Kroah-Hartman *
1038ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_GET_CLOCK_SRC. Returns the counter channel's current
1048ffdff6aSGreg Kroah-Hartman * clock source in data[1]. For internal clock sources, data[2] is set
1058ffdff6aSGreg Kroah-Hartman * to the period in ns.
1068ffdff6aSGreg Kroah-Hartman *
1078ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_SET_GATE_SRC. Sets the counter channel's gate source as
1088ffdff6aSGreg Kroah-Hartman * specified in data[2] (this is a hardware-specific value). Not
1098ffdff6aSGreg Kroah-Hartman * supported on PC214E. For the other boards, valid gate sources are 0
1108ffdff6aSGreg Kroah-Hartman * to 7 as follows:
1118ffdff6aSGreg Kroah-Hartman *
1128ffdff6aSGreg Kroah-Hartman * 0. VCC (internal +5V d.c.), i.e. gate permanently enabled.
1138ffdff6aSGreg Kroah-Hartman * 1. GND (internal 0V d.c.), i.e. gate permanently disabled.
1148ffdff6aSGreg Kroah-Hartman * 2. GAT n, the counter channel's dedicated GAT input from the SK1
1158ffdff6aSGreg Kroah-Hartman * connector. (N.B. for other values, the counter channel's GATn
1168ffdff6aSGreg Kroah-Hartman * pin on the SK1 connector is an output!)
1178ffdff6aSGreg Kroah-Hartman * 3. /OUT n-2, the inverted output of counter channel n-2 (see note
1188ffdff6aSGreg Kroah-Hartman * 2 below).
1198ffdff6aSGreg Kroah-Hartman * 4. Reserved.
1208ffdff6aSGreg Kroah-Hartman * 5. Reserved.
1218ffdff6aSGreg Kroah-Hartman * 6. Reserved.
1228ffdff6aSGreg Kroah-Hartman * 7. Reserved.
1238ffdff6aSGreg Kroah-Hartman *
1248ffdff6aSGreg Kroah-Hartman * For the PCIe boards, gate sources in the range 0 to 31 are allowed;
1258ffdff6aSGreg Kroah-Hartman * the following additional clock sources and clock sources 6 and 7 are
1268ffdff6aSGreg Kroah-Hartman * (re)defined:
1278ffdff6aSGreg Kroah-Hartman *
1288ffdff6aSGreg Kroah-Hartman * 6. /GAT n, negated version of the counter channel's dedicated
1298ffdff6aSGreg Kroah-Hartman * GAT input (negated version of gate source 2).
1308ffdff6aSGreg Kroah-Hartman * 7. OUT n-2, the non-inverted output of counter channel n-2
1318ffdff6aSGreg Kroah-Hartman * (negated version of gate source 3).
1328ffdff6aSGreg Kroah-Hartman * 8. "Pattern present" signal, HIGH while pattern present.
1338ffdff6aSGreg Kroah-Hartman * 9. "Pattern occurred" latched signal, latches HIGH when pattern
1348ffdff6aSGreg Kroah-Hartman * occurs.
1358ffdff6aSGreg Kroah-Hartman * 10. "Pattern gone away" latched signal, latches LOW when pattern
1368ffdff6aSGreg Kroah-Hartman * goes away after it occurred.
1378ffdff6aSGreg Kroah-Hartman * 11. Negated "pattern present" signal, LOW while pattern present
1388ffdff6aSGreg Kroah-Hartman * (negated version of gate source 8).
1398ffdff6aSGreg Kroah-Hartman * 12. Negated "pattern occurred" latched signal, latches LOW when
1408ffdff6aSGreg Kroah-Hartman * pattern occurs (negated version of gate source 9).
1418ffdff6aSGreg Kroah-Hartman * 13. Negated "pattern gone away" latched signal, latches LOW when
1428ffdff6aSGreg Kroah-Hartman * pattern goes away after it occurred (negated version of gate
1438ffdff6aSGreg Kroah-Hartman * source 10).
1448ffdff6aSGreg Kroah-Hartman *
1458ffdff6aSGreg Kroah-Hartman * INSN_CONFIG_GET_GATE_SRC. Returns the counter channel's current gate
1468ffdff6aSGreg Kroah-Hartman * source in data[2].
1478ffdff6aSGreg Kroah-Hartman *
1488ffdff6aSGreg Kroah-Hartman * Clock and gate interconnection notes:
1498ffdff6aSGreg Kroah-Hartman *
1508ffdff6aSGreg Kroah-Hartman * 1. Clock source OUT n-1 is the output of the preceding channel on the
1518ffdff6aSGreg Kroah-Hartman * same counter subdevice if n > 0, or the output of channel 2 on the
1528ffdff6aSGreg Kroah-Hartman * preceding counter subdevice (see note 3) if n = 0.
1538ffdff6aSGreg Kroah-Hartman *
1548ffdff6aSGreg Kroah-Hartman * 2. Gate source /OUT n-2 is the inverted output of channel 0 on the
1558ffdff6aSGreg Kroah-Hartman * same counter subdevice if n = 2, or the inverted output of channel n+1
1568ffdff6aSGreg Kroah-Hartman * on the preceding counter subdevice (see note 3) if n < 2.
1578ffdff6aSGreg Kroah-Hartman *
1588ffdff6aSGreg Kroah-Hartman * 3. The counter subdevices are connected in a ring, so the highest
1598ffdff6aSGreg Kroah-Hartman * counter subdevice precedes the lowest.
1608ffdff6aSGreg Kroah-Hartman *
1618ffdff6aSGreg Kroah-Hartman * The 'TIMER' subdevice is a free-running 32-bit timer subdevice.
1628ffdff6aSGreg Kroah-Hartman *
1638ffdff6aSGreg Kroah-Hartman * The 'INTERRUPT' subdevice pretends to be a digital input subdevice. The
1648ffdff6aSGreg Kroah-Hartman * digital inputs come from the interrupt status register. The number of
1658ffdff6aSGreg Kroah-Hartman * channels matches the number of interrupt sources. The PC214E does not
1668ffdff6aSGreg Kroah-Hartman * have an interrupt status register; see notes on 'INTERRUPT SOURCES'
1678ffdff6aSGreg Kroah-Hartman * below.
1688ffdff6aSGreg Kroah-Hartman *
1698ffdff6aSGreg Kroah-Hartman * INTERRUPT SOURCES
1708ffdff6aSGreg Kroah-Hartman *
1718ffdff6aSGreg Kroah-Hartman * PCI215 PCIe215 PCIe236
1728ffdff6aSGreg Kroah-Hartman * ------------- ------------- -------------
1738ffdff6aSGreg Kroah-Hartman * Sources 6 6 6
1748ffdff6aSGreg Kroah-Hartman * 0 PPI-X-C0 PPI-X-C0 PPI-X-C0
1758ffdff6aSGreg Kroah-Hartman * 1 PPI-X-C3 PPI-X-C3 PPI-X-C3
1768ffdff6aSGreg Kroah-Hartman * 2 PPI-Y-C0 PPI-Y-C0 unused
1778ffdff6aSGreg Kroah-Hartman * 3 PPI-Y-C3 PPI-Y-C3 unused
1788ffdff6aSGreg Kroah-Hartman * 4 CTR-Z1-OUT1 CTR-Z1-OUT1 CTR-Z1-OUT1
1798ffdff6aSGreg Kroah-Hartman * 5 CTR-Z2-OUT1 CTR-Z2-OUT1 CTR-Z2-OUT1
1808ffdff6aSGreg Kroah-Hartman *
1818ffdff6aSGreg Kroah-Hartman * PCI272 PCIe296
1828ffdff6aSGreg Kroah-Hartman * ------------- -------------
1838ffdff6aSGreg Kroah-Hartman * Sources 6 6
1848ffdff6aSGreg Kroah-Hartman * 0 PPI-X-C0 PPI-X1-C0
1858ffdff6aSGreg Kroah-Hartman * 1 PPI-X-C3 PPI-X1-C3
1868ffdff6aSGreg Kroah-Hartman * 2 PPI-Y-C0 PPI-Y1-C0
1878ffdff6aSGreg Kroah-Hartman * 3 PPI-Y-C3 PPI-Y1-C3
1888ffdff6aSGreg Kroah-Hartman * 4 PPI-Z-C0 CTR-Z1-OUT1
1898ffdff6aSGreg Kroah-Hartman * 5 PPI-Z-C3 CTR-Z2-OUT1
1908ffdff6aSGreg Kroah-Hartman *
1918ffdff6aSGreg Kroah-Hartman * When an interrupt source is enabled in the interrupt source enable
1928ffdff6aSGreg Kroah-Hartman * register, a rising edge on the source signal latches the corresponding
1938ffdff6aSGreg Kroah-Hartman * bit to 1 in the interrupt status register.
1948ffdff6aSGreg Kroah-Hartman *
1958ffdff6aSGreg Kroah-Hartman * When the interrupt status register value as a whole (actually, just the
1968ffdff6aSGreg Kroah-Hartman * 6 least significant bits) goes from zero to non-zero, the board will
1978ffdff6aSGreg Kroah-Hartman * generate an interrupt. The interrupt will remain asserted until the
1988ffdff6aSGreg Kroah-Hartman * interrupt status register is cleared to zero. To clear a bit to zero in
1998ffdff6aSGreg Kroah-Hartman * the interrupt status register, the corresponding interrupt source must
2008ffdff6aSGreg Kroah-Hartman * be disabled in the interrupt source enable register (there is no
2018ffdff6aSGreg Kroah-Hartman * separate interrupt clear register).
2028ffdff6aSGreg Kroah-Hartman *
2038ffdff6aSGreg Kroah-Hartman * COMMANDS
2048ffdff6aSGreg Kroah-Hartman *
2058ffdff6aSGreg Kroah-Hartman * The driver supports a read streaming acquisition command on the
2068ffdff6aSGreg Kroah-Hartman * 'INTERRUPT' subdevice. The channel list selects the interrupt sources
2078ffdff6aSGreg Kroah-Hartman * to be enabled. All channels will be sampled together (convert_src ==
2088ffdff6aSGreg Kroah-Hartman * TRIG_NOW). The scan begins a short time after the hardware interrupt
2098ffdff6aSGreg Kroah-Hartman * occurs, subject to interrupt latencies (scan_begin_src == TRIG_EXT,
2108ffdff6aSGreg Kroah-Hartman * scan_begin_arg == 0). The value read from the interrupt status register
2118ffdff6aSGreg Kroah-Hartman * is packed into a short value, one bit per requested channel, in the
2128ffdff6aSGreg Kroah-Hartman * order they appear in the channel list.
2138ffdff6aSGreg Kroah-Hartman */
2148ffdff6aSGreg Kroah-Hartman
2158ffdff6aSGreg Kroah-Hartman #include <linux/module.h>
2168ffdff6aSGreg Kroah-Hartman #include <linux/interrupt.h>
217*df0e68c1SIan Abbott #include <linux/comedi/comedi_pci.h>
2188ffdff6aSGreg Kroah-Hartman
2198ffdff6aSGreg Kroah-Hartman #include "amplc_dio200.h"
2208ffdff6aSGreg Kroah-Hartman
2218ffdff6aSGreg Kroah-Hartman /*
2228ffdff6aSGreg Kroah-Hartman * Board descriptions.
2238ffdff6aSGreg Kroah-Hartman */
2248ffdff6aSGreg Kroah-Hartman
2258ffdff6aSGreg Kroah-Hartman enum dio200_pci_model {
2268ffdff6aSGreg Kroah-Hartman pci215_model,
2278ffdff6aSGreg Kroah-Hartman pci272_model,
2288ffdff6aSGreg Kroah-Hartman pcie215_model,
2298ffdff6aSGreg Kroah-Hartman pcie236_model,
2308ffdff6aSGreg Kroah-Hartman pcie296_model
2318ffdff6aSGreg Kroah-Hartman };
2328ffdff6aSGreg Kroah-Hartman
2338ffdff6aSGreg Kroah-Hartman static const struct dio200_board dio200_pci_boards[] = {
2348ffdff6aSGreg Kroah-Hartman [pci215_model] = {
2358ffdff6aSGreg Kroah-Hartman .name = "pci215",
2368ffdff6aSGreg Kroah-Hartman .mainbar = 2,
2378ffdff6aSGreg Kroah-Hartman .n_subdevs = 5,
2388ffdff6aSGreg Kroah-Hartman .sdtype = {
2398ffdff6aSGreg Kroah-Hartman sd_8255, sd_8255, sd_8254, sd_8254, sd_intr
2408ffdff6aSGreg Kroah-Hartman },
2418ffdff6aSGreg Kroah-Hartman .sdinfo = { 0x00, 0x08, 0x10, 0x14, 0x3f },
2428ffdff6aSGreg Kroah-Hartman .has_int_sce = true,
2438ffdff6aSGreg Kroah-Hartman .has_clk_gat_sce = true,
2448ffdff6aSGreg Kroah-Hartman },
2458ffdff6aSGreg Kroah-Hartman [pci272_model] = {
2468ffdff6aSGreg Kroah-Hartman .name = "pci272",
2478ffdff6aSGreg Kroah-Hartman .mainbar = 2,
2488ffdff6aSGreg Kroah-Hartman .n_subdevs = 4,
2498ffdff6aSGreg Kroah-Hartman .sdtype = {
2508ffdff6aSGreg Kroah-Hartman sd_8255, sd_8255, sd_8255, sd_intr
2518ffdff6aSGreg Kroah-Hartman },
2528ffdff6aSGreg Kroah-Hartman .sdinfo = { 0x00, 0x08, 0x10, 0x3f },
2538ffdff6aSGreg Kroah-Hartman .has_int_sce = true,
2548ffdff6aSGreg Kroah-Hartman },
2558ffdff6aSGreg Kroah-Hartman [pcie215_model] = {
2568ffdff6aSGreg Kroah-Hartman .name = "pcie215",
2578ffdff6aSGreg Kroah-Hartman .mainbar = 1,
2588ffdff6aSGreg Kroah-Hartman .n_subdevs = 8,
2598ffdff6aSGreg Kroah-Hartman .sdtype = {
2608ffdff6aSGreg Kroah-Hartman sd_8255, sd_none, sd_8255, sd_none,
2618ffdff6aSGreg Kroah-Hartman sd_8254, sd_8254, sd_timer, sd_intr
2628ffdff6aSGreg Kroah-Hartman },
2638ffdff6aSGreg Kroah-Hartman .sdinfo = {
2648ffdff6aSGreg Kroah-Hartman 0x00, 0x00, 0x08, 0x00, 0x10, 0x14, 0x00, 0x3f
2658ffdff6aSGreg Kroah-Hartman },
2668ffdff6aSGreg Kroah-Hartman .has_int_sce = true,
2678ffdff6aSGreg Kroah-Hartman .has_clk_gat_sce = true,
2688ffdff6aSGreg Kroah-Hartman .is_pcie = true,
2698ffdff6aSGreg Kroah-Hartman },
2708ffdff6aSGreg Kroah-Hartman [pcie236_model] = {
2718ffdff6aSGreg Kroah-Hartman .name = "pcie236",
2728ffdff6aSGreg Kroah-Hartman .mainbar = 1,
2738ffdff6aSGreg Kroah-Hartman .n_subdevs = 8,
2748ffdff6aSGreg Kroah-Hartman .sdtype = {
2758ffdff6aSGreg Kroah-Hartman sd_8255, sd_none, sd_none, sd_none,
2768ffdff6aSGreg Kroah-Hartman sd_8254, sd_8254, sd_timer, sd_intr
2778ffdff6aSGreg Kroah-Hartman },
2788ffdff6aSGreg Kroah-Hartman .sdinfo = {
2798ffdff6aSGreg Kroah-Hartman 0x00, 0x00, 0x00, 0x00, 0x10, 0x14, 0x00, 0x3f
2808ffdff6aSGreg Kroah-Hartman },
2818ffdff6aSGreg Kroah-Hartman .has_int_sce = true,
2828ffdff6aSGreg Kroah-Hartman .has_clk_gat_sce = true,
2838ffdff6aSGreg Kroah-Hartman .is_pcie = true,
2848ffdff6aSGreg Kroah-Hartman },
2858ffdff6aSGreg Kroah-Hartman [pcie296_model] = {
2868ffdff6aSGreg Kroah-Hartman .name = "pcie296",
2878ffdff6aSGreg Kroah-Hartman .mainbar = 1,
2888ffdff6aSGreg Kroah-Hartman .n_subdevs = 8,
2898ffdff6aSGreg Kroah-Hartman .sdtype = {
2908ffdff6aSGreg Kroah-Hartman sd_8255, sd_8255, sd_8255, sd_8255,
2918ffdff6aSGreg Kroah-Hartman sd_8254, sd_8254, sd_timer, sd_intr
2928ffdff6aSGreg Kroah-Hartman },
2938ffdff6aSGreg Kroah-Hartman .sdinfo = {
2948ffdff6aSGreg Kroah-Hartman 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x00, 0x3f
2958ffdff6aSGreg Kroah-Hartman },
2968ffdff6aSGreg Kroah-Hartman .has_int_sce = true,
2978ffdff6aSGreg Kroah-Hartman .has_clk_gat_sce = true,
2988ffdff6aSGreg Kroah-Hartman .is_pcie = true,
2998ffdff6aSGreg Kroah-Hartman },
3008ffdff6aSGreg Kroah-Hartman };
3018ffdff6aSGreg Kroah-Hartman
3028ffdff6aSGreg Kroah-Hartman /*
3038ffdff6aSGreg Kroah-Hartman * This function does some special set-up for the PCIe boards
3048ffdff6aSGreg Kroah-Hartman * PCIe215, PCIe236, PCIe296.
3058ffdff6aSGreg Kroah-Hartman */
dio200_pcie_board_setup(struct comedi_device * dev)3068ffdff6aSGreg Kroah-Hartman static int dio200_pcie_board_setup(struct comedi_device *dev)
3078ffdff6aSGreg Kroah-Hartman {
3088ffdff6aSGreg Kroah-Hartman struct pci_dev *pcidev = comedi_to_pci_dev(dev);
3098ffdff6aSGreg Kroah-Hartman void __iomem *brbase;
3108ffdff6aSGreg Kroah-Hartman
3118ffdff6aSGreg Kroah-Hartman /*
3128ffdff6aSGreg Kroah-Hartman * The board uses Altera Cyclone IV with PCI-Express hard IP.
3138ffdff6aSGreg Kroah-Hartman * The FPGA configuration has the PCI-Express Avalon-MM Bridge
3148ffdff6aSGreg Kroah-Hartman * Control registers in PCI BAR 0, offset 0, and the length of
3158ffdff6aSGreg Kroah-Hartman * these registers is 0x4000.
3168ffdff6aSGreg Kroah-Hartman *
3178ffdff6aSGreg Kroah-Hartman * We need to write 0x80 to the "Avalon-MM to PCI-Express Interrupt
3188ffdff6aSGreg Kroah-Hartman * Enable" register at offset 0x50 to allow generation of PCIe
3198ffdff6aSGreg Kroah-Hartman * interrupts when RXmlrq_i is asserted in the SOPC Builder system.
3208ffdff6aSGreg Kroah-Hartman */
3218ffdff6aSGreg Kroah-Hartman if (pci_resource_len(pcidev, 0) < 0x4000) {
3228ffdff6aSGreg Kroah-Hartman dev_err(dev->class_dev, "error! bad PCI region!\n");
3238ffdff6aSGreg Kroah-Hartman return -EINVAL;
3248ffdff6aSGreg Kroah-Hartman }
3258ffdff6aSGreg Kroah-Hartman brbase = pci_ioremap_bar(pcidev, 0);
3268ffdff6aSGreg Kroah-Hartman if (!brbase) {
3278ffdff6aSGreg Kroah-Hartman dev_err(dev->class_dev, "error! failed to map registers!\n");
3288ffdff6aSGreg Kroah-Hartman return -ENOMEM;
3298ffdff6aSGreg Kroah-Hartman }
3308ffdff6aSGreg Kroah-Hartman writel(0x80, brbase + 0x50);
3318ffdff6aSGreg Kroah-Hartman iounmap(brbase);
3328ffdff6aSGreg Kroah-Hartman /* Enable "enhanced" features of board. */
3338ffdff6aSGreg Kroah-Hartman amplc_dio200_set_enhance(dev, 1);
3348ffdff6aSGreg Kroah-Hartman return 0;
3358ffdff6aSGreg Kroah-Hartman }
3368ffdff6aSGreg Kroah-Hartman
dio200_pci_auto_attach(struct comedi_device * dev,unsigned long context_model)3378ffdff6aSGreg Kroah-Hartman static int dio200_pci_auto_attach(struct comedi_device *dev,
3388ffdff6aSGreg Kroah-Hartman unsigned long context_model)
3398ffdff6aSGreg Kroah-Hartman {
3408ffdff6aSGreg Kroah-Hartman struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
3418ffdff6aSGreg Kroah-Hartman const struct dio200_board *board = NULL;
3428ffdff6aSGreg Kroah-Hartman unsigned int bar;
3438ffdff6aSGreg Kroah-Hartman int ret;
3448ffdff6aSGreg Kroah-Hartman
3458ffdff6aSGreg Kroah-Hartman if (context_model < ARRAY_SIZE(dio200_pci_boards))
3468ffdff6aSGreg Kroah-Hartman board = &dio200_pci_boards[context_model];
3478ffdff6aSGreg Kroah-Hartman if (!board)
3488ffdff6aSGreg Kroah-Hartman return -EINVAL;
3498ffdff6aSGreg Kroah-Hartman dev->board_ptr = board;
3508ffdff6aSGreg Kroah-Hartman dev->board_name = board->name;
3518ffdff6aSGreg Kroah-Hartman
3528ffdff6aSGreg Kroah-Hartman dev_info(dev->class_dev, "%s: attach pci %s (%s)\n",
3538ffdff6aSGreg Kroah-Hartman dev->driver->driver_name, pci_name(pci_dev), dev->board_name);
3548ffdff6aSGreg Kroah-Hartman
3558ffdff6aSGreg Kroah-Hartman ret = comedi_pci_enable(dev);
3568ffdff6aSGreg Kroah-Hartman if (ret)
3578ffdff6aSGreg Kroah-Hartman return ret;
3588ffdff6aSGreg Kroah-Hartman
3598ffdff6aSGreg Kroah-Hartman bar = board->mainbar;
3608ffdff6aSGreg Kroah-Hartman if (pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) {
3618ffdff6aSGreg Kroah-Hartman dev->mmio = pci_ioremap_bar(pci_dev, bar);
3628ffdff6aSGreg Kroah-Hartman if (!dev->mmio) {
3638ffdff6aSGreg Kroah-Hartman dev_err(dev->class_dev,
3648ffdff6aSGreg Kroah-Hartman "error! cannot remap registers\n");
3658ffdff6aSGreg Kroah-Hartman return -ENOMEM;
3668ffdff6aSGreg Kroah-Hartman }
3678ffdff6aSGreg Kroah-Hartman } else {
3688ffdff6aSGreg Kroah-Hartman dev->iobase = pci_resource_start(pci_dev, bar);
3698ffdff6aSGreg Kroah-Hartman }
3708ffdff6aSGreg Kroah-Hartman
3718ffdff6aSGreg Kroah-Hartman if (board->is_pcie) {
3728ffdff6aSGreg Kroah-Hartman ret = dio200_pcie_board_setup(dev);
3738ffdff6aSGreg Kroah-Hartman if (ret < 0)
3748ffdff6aSGreg Kroah-Hartman return ret;
3758ffdff6aSGreg Kroah-Hartman }
3768ffdff6aSGreg Kroah-Hartman
3778ffdff6aSGreg Kroah-Hartman return amplc_dio200_common_attach(dev, pci_dev->irq, IRQF_SHARED);
3788ffdff6aSGreg Kroah-Hartman }
3798ffdff6aSGreg Kroah-Hartman
3808ffdff6aSGreg Kroah-Hartman static struct comedi_driver dio200_pci_comedi_driver = {
3818ffdff6aSGreg Kroah-Hartman .driver_name = "amplc_dio200_pci",
3828ffdff6aSGreg Kroah-Hartman .module = THIS_MODULE,
3838ffdff6aSGreg Kroah-Hartman .auto_attach = dio200_pci_auto_attach,
3848ffdff6aSGreg Kroah-Hartman .detach = comedi_pci_detach,
3858ffdff6aSGreg Kroah-Hartman };
3868ffdff6aSGreg Kroah-Hartman
3878ffdff6aSGreg Kroah-Hartman static const struct pci_device_id dio200_pci_table[] = {
3888ffdff6aSGreg Kroah-Hartman { PCI_VDEVICE(AMPLICON, 0x000b), pci215_model },
3898ffdff6aSGreg Kroah-Hartman { PCI_VDEVICE(AMPLICON, 0x000a), pci272_model },
3908ffdff6aSGreg Kroah-Hartman { PCI_VDEVICE(AMPLICON, 0x0011), pcie236_model },
3918ffdff6aSGreg Kroah-Hartman { PCI_VDEVICE(AMPLICON, 0x0012), pcie215_model },
3928ffdff6aSGreg Kroah-Hartman { PCI_VDEVICE(AMPLICON, 0x0014), pcie296_model },
3938ffdff6aSGreg Kroah-Hartman {0}
3948ffdff6aSGreg Kroah-Hartman };
3958ffdff6aSGreg Kroah-Hartman
3968ffdff6aSGreg Kroah-Hartman MODULE_DEVICE_TABLE(pci, dio200_pci_table);
3978ffdff6aSGreg Kroah-Hartman
dio200_pci_probe(struct pci_dev * dev,const struct pci_device_id * id)3988ffdff6aSGreg Kroah-Hartman static int dio200_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
3998ffdff6aSGreg Kroah-Hartman {
4008ffdff6aSGreg Kroah-Hartman return comedi_pci_auto_config(dev, &dio200_pci_comedi_driver,
4018ffdff6aSGreg Kroah-Hartman id->driver_data);
4028ffdff6aSGreg Kroah-Hartman }
4038ffdff6aSGreg Kroah-Hartman
4048ffdff6aSGreg Kroah-Hartman static struct pci_driver dio200_pci_pci_driver = {
4058ffdff6aSGreg Kroah-Hartman .name = "amplc_dio200_pci",
4068ffdff6aSGreg Kroah-Hartman .id_table = dio200_pci_table,
4078ffdff6aSGreg Kroah-Hartman .probe = dio200_pci_probe,
4088ffdff6aSGreg Kroah-Hartman .remove = comedi_pci_auto_unconfig,
4098ffdff6aSGreg Kroah-Hartman };
4108ffdff6aSGreg Kroah-Hartman module_comedi_pci_driver(dio200_pci_comedi_driver, dio200_pci_pci_driver);
4118ffdff6aSGreg Kroah-Hartman
4128ffdff6aSGreg Kroah-Hartman MODULE_AUTHOR("Comedi https://www.comedi.org");
4138ffdff6aSGreg Kroah-Hartman MODULE_DESCRIPTION("Comedi driver for Amplicon 200 Series PCI(e) DIO boards");
4148ffdff6aSGreg Kroah-Hartman MODULE_LICENSE("GPL");
415