18ffdff6aSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ */ 28ffdff6aSGreg Kroah-Hartman /* 38ffdff6aSGreg Kroah-Hartman * Header file for NI general purpose counter support code (ni_tio.c) 48ffdff6aSGreg Kroah-Hartman * 58ffdff6aSGreg Kroah-Hartman * COMEDI - Linux Control and Measurement Device Interface 68ffdff6aSGreg Kroah-Hartman */ 78ffdff6aSGreg Kroah-Hartman 88ffdff6aSGreg Kroah-Hartman #ifndef _COMEDI_NI_TIO_H 98ffdff6aSGreg Kroah-Hartman #define _COMEDI_NI_TIO_H 108ffdff6aSGreg Kroah-Hartman 11*df0e68c1SIan Abbott #include <linux/comedi/comedidev.h> 128ffdff6aSGreg Kroah-Hartman 138ffdff6aSGreg Kroah-Hartman enum ni_gpct_register { 148ffdff6aSGreg Kroah-Hartman NITIO_G0_AUTO_INC, 158ffdff6aSGreg Kroah-Hartman NITIO_G1_AUTO_INC, 168ffdff6aSGreg Kroah-Hartman NITIO_G2_AUTO_INC, 178ffdff6aSGreg Kroah-Hartman NITIO_G3_AUTO_INC, 188ffdff6aSGreg Kroah-Hartman NITIO_G0_CMD, 198ffdff6aSGreg Kroah-Hartman NITIO_G1_CMD, 208ffdff6aSGreg Kroah-Hartman NITIO_G2_CMD, 218ffdff6aSGreg Kroah-Hartman NITIO_G3_CMD, 228ffdff6aSGreg Kroah-Hartman NITIO_G0_HW_SAVE, 238ffdff6aSGreg Kroah-Hartman NITIO_G1_HW_SAVE, 248ffdff6aSGreg Kroah-Hartman NITIO_G2_HW_SAVE, 258ffdff6aSGreg Kroah-Hartman NITIO_G3_HW_SAVE, 268ffdff6aSGreg Kroah-Hartman NITIO_G0_SW_SAVE, 278ffdff6aSGreg Kroah-Hartman NITIO_G1_SW_SAVE, 288ffdff6aSGreg Kroah-Hartman NITIO_G2_SW_SAVE, 298ffdff6aSGreg Kroah-Hartman NITIO_G3_SW_SAVE, 308ffdff6aSGreg Kroah-Hartman NITIO_G0_MODE, 318ffdff6aSGreg Kroah-Hartman NITIO_G1_MODE, 328ffdff6aSGreg Kroah-Hartman NITIO_G2_MODE, 338ffdff6aSGreg Kroah-Hartman NITIO_G3_MODE, 348ffdff6aSGreg Kroah-Hartman NITIO_G0_LOADA, 358ffdff6aSGreg Kroah-Hartman NITIO_G1_LOADA, 368ffdff6aSGreg Kroah-Hartman NITIO_G2_LOADA, 378ffdff6aSGreg Kroah-Hartman NITIO_G3_LOADA, 388ffdff6aSGreg Kroah-Hartman NITIO_G0_LOADB, 398ffdff6aSGreg Kroah-Hartman NITIO_G1_LOADB, 408ffdff6aSGreg Kroah-Hartman NITIO_G2_LOADB, 418ffdff6aSGreg Kroah-Hartman NITIO_G3_LOADB, 428ffdff6aSGreg Kroah-Hartman NITIO_G0_INPUT_SEL, 438ffdff6aSGreg Kroah-Hartman NITIO_G1_INPUT_SEL, 448ffdff6aSGreg Kroah-Hartman NITIO_G2_INPUT_SEL, 458ffdff6aSGreg Kroah-Hartman NITIO_G3_INPUT_SEL, 468ffdff6aSGreg Kroah-Hartman NITIO_G0_CNT_MODE, 478ffdff6aSGreg Kroah-Hartman NITIO_G1_CNT_MODE, 488ffdff6aSGreg Kroah-Hartman NITIO_G2_CNT_MODE, 498ffdff6aSGreg Kroah-Hartman NITIO_G3_CNT_MODE, 508ffdff6aSGreg Kroah-Hartman NITIO_G0_GATE2, 518ffdff6aSGreg Kroah-Hartman NITIO_G1_GATE2, 528ffdff6aSGreg Kroah-Hartman NITIO_G2_GATE2, 538ffdff6aSGreg Kroah-Hartman NITIO_G3_GATE2, 548ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS, 558ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS, 568ffdff6aSGreg Kroah-Hartman NITIO_G01_RESET, 578ffdff6aSGreg Kroah-Hartman NITIO_G23_RESET, 588ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS1, 598ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS1, 608ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS2, 618ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS2, 628ffdff6aSGreg Kroah-Hartman NITIO_G0_DMA_CFG, 638ffdff6aSGreg Kroah-Hartman NITIO_G1_DMA_CFG, 648ffdff6aSGreg Kroah-Hartman NITIO_G2_DMA_CFG, 658ffdff6aSGreg Kroah-Hartman NITIO_G3_DMA_CFG, 668ffdff6aSGreg Kroah-Hartman NITIO_G0_DMA_STATUS, 678ffdff6aSGreg Kroah-Hartman NITIO_G1_DMA_STATUS, 688ffdff6aSGreg Kroah-Hartman NITIO_G2_DMA_STATUS, 698ffdff6aSGreg Kroah-Hartman NITIO_G3_DMA_STATUS, 708ffdff6aSGreg Kroah-Hartman NITIO_G0_ABZ, 718ffdff6aSGreg Kroah-Hartman NITIO_G1_ABZ, 728ffdff6aSGreg Kroah-Hartman NITIO_G0_INT_ACK, 738ffdff6aSGreg Kroah-Hartman NITIO_G1_INT_ACK, 748ffdff6aSGreg Kroah-Hartman NITIO_G2_INT_ACK, 758ffdff6aSGreg Kroah-Hartman NITIO_G3_INT_ACK, 768ffdff6aSGreg Kroah-Hartman NITIO_G0_STATUS, 778ffdff6aSGreg Kroah-Hartman NITIO_G1_STATUS, 788ffdff6aSGreg Kroah-Hartman NITIO_G2_STATUS, 798ffdff6aSGreg Kroah-Hartman NITIO_G3_STATUS, 808ffdff6aSGreg Kroah-Hartman NITIO_G0_INT_ENA, 818ffdff6aSGreg Kroah-Hartman NITIO_G1_INT_ENA, 828ffdff6aSGreg Kroah-Hartman NITIO_G2_INT_ENA, 838ffdff6aSGreg Kroah-Hartman NITIO_G3_INT_ENA, 848ffdff6aSGreg Kroah-Hartman NITIO_NUM_REGS, 858ffdff6aSGreg Kroah-Hartman }; 868ffdff6aSGreg Kroah-Hartman 878ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant { 888ffdff6aSGreg Kroah-Hartman ni_gpct_variant_e_series, 898ffdff6aSGreg Kroah-Hartman ni_gpct_variant_m_series, 908ffdff6aSGreg Kroah-Hartman ni_gpct_variant_660x 918ffdff6aSGreg Kroah-Hartman }; 928ffdff6aSGreg Kroah-Hartman 938ffdff6aSGreg Kroah-Hartman struct ni_gpct { 948ffdff6aSGreg Kroah-Hartman struct ni_gpct_device *counter_dev; 958ffdff6aSGreg Kroah-Hartman unsigned int counter_index; 968ffdff6aSGreg Kroah-Hartman unsigned int chip_index; 978ffdff6aSGreg Kroah-Hartman u64 clock_period_ps; /* clock period in picoseconds */ 988ffdff6aSGreg Kroah-Hartman struct mite_channel *mite_chan; 998ffdff6aSGreg Kroah-Hartman spinlock_t lock; /* protects 'mite_chan' */ 1008ffdff6aSGreg Kroah-Hartman }; 1018ffdff6aSGreg Kroah-Hartman 1028ffdff6aSGreg Kroah-Hartman struct ni_gpct_device { 1038ffdff6aSGreg Kroah-Hartman struct comedi_device *dev; 1048ffdff6aSGreg Kroah-Hartman void (*write)(struct ni_gpct *counter, unsigned int value, 1058ffdff6aSGreg Kroah-Hartman enum ni_gpct_register); 1068ffdff6aSGreg Kroah-Hartman unsigned int (*read)(struct ni_gpct *counter, enum ni_gpct_register); 1078ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant variant; 1088ffdff6aSGreg Kroah-Hartman struct ni_gpct *counters; 1098ffdff6aSGreg Kroah-Hartman unsigned int num_counters; 1108ffdff6aSGreg Kroah-Hartman unsigned int num_chips; 1118ffdff6aSGreg Kroah-Hartman unsigned int (*regs)[NITIO_NUM_REGS]; /* [num_chips][NITIO_NUM_REGS] */ 1128ffdff6aSGreg Kroah-Hartman spinlock_t regs_lock; /* protects 'regs' */ 1138ffdff6aSGreg Kroah-Hartman const struct ni_route_tables *routing_tables; /* link to routes */ 1148ffdff6aSGreg Kroah-Hartman }; 1158ffdff6aSGreg Kroah-Hartman 1168ffdff6aSGreg Kroah-Hartman struct ni_gpct_device * 1178ffdff6aSGreg Kroah-Hartman ni_gpct_device_construct(struct comedi_device *dev, 1188ffdff6aSGreg Kroah-Hartman void (*write)(struct ni_gpct *counter, 1198ffdff6aSGreg Kroah-Hartman unsigned int value, 1208ffdff6aSGreg Kroah-Hartman enum ni_gpct_register), 1218ffdff6aSGreg Kroah-Hartman unsigned int (*read)(struct ni_gpct *counter, 1228ffdff6aSGreg Kroah-Hartman enum ni_gpct_register), 1238ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant, 1248ffdff6aSGreg Kroah-Hartman unsigned int num_counters, 1258ffdff6aSGreg Kroah-Hartman unsigned int counters_per_chip, 1268ffdff6aSGreg Kroah-Hartman const struct ni_route_tables *routing_tables); 1278ffdff6aSGreg Kroah-Hartman void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev); 1288ffdff6aSGreg Kroah-Hartman void ni_tio_init_counter(struct ni_gpct *counter); 1298ffdff6aSGreg Kroah-Hartman int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, 1308ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 1318ffdff6aSGreg Kroah-Hartman int ni_tio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, 1328ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 1338ffdff6aSGreg Kroah-Hartman int ni_tio_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, 1348ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 1358ffdff6aSGreg Kroah-Hartman int ni_tio_cmd(struct comedi_device *dev, struct comedi_subdevice *s); 1368ffdff6aSGreg Kroah-Hartman int ni_tio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, 1378ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd); 1388ffdff6aSGreg Kroah-Hartman int ni_tio_cancel(struct ni_gpct *counter); 1398ffdff6aSGreg Kroah-Hartman void ni_tio_handle_interrupt(struct ni_gpct *counter, 1408ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s); 1418ffdff6aSGreg Kroah-Hartman void ni_tio_set_mite_channel(struct ni_gpct *counter, 1428ffdff6aSGreg Kroah-Hartman struct mite_channel *mite_chan); 1438ffdff6aSGreg Kroah-Hartman void ni_tio_acknowledge(struct ni_gpct *counter); 1448ffdff6aSGreg Kroah-Hartman 1458ffdff6aSGreg Kroah-Hartman /* 1468ffdff6aSGreg Kroah-Hartman * Retrieves the register value of the current source of the output selector for 1478ffdff6aSGreg Kroah-Hartman * the given destination. 1488ffdff6aSGreg Kroah-Hartman * 1498ffdff6aSGreg Kroah-Hartman * If the terminal for the destination is not already configured as an output, 1508ffdff6aSGreg Kroah-Hartman * this function returns -EINVAL as error. 1518ffdff6aSGreg Kroah-Hartman * 1528ffdff6aSGreg Kroah-Hartman * Return: the register value of the destination output selector; 1538ffdff6aSGreg Kroah-Hartman * -EINVAL if terminal is not configured for output. 1548ffdff6aSGreg Kroah-Hartman */ 1558ffdff6aSGreg Kroah-Hartman int ni_tio_get_routing(struct ni_gpct_device *counter_dev, 1568ffdff6aSGreg Kroah-Hartman unsigned int destination); 1578ffdff6aSGreg Kroah-Hartman 1588ffdff6aSGreg Kroah-Hartman /* 1598ffdff6aSGreg Kroah-Hartman * Sets the register value of the selector MUX for the given destination. 1608ffdff6aSGreg Kroah-Hartman * @counter_dev:Pointer to general counter device. 1618ffdff6aSGreg Kroah-Hartman * @destination:Device-global identifier of route destination. 1628ffdff6aSGreg Kroah-Hartman * @register_value: 1638ffdff6aSGreg Kroah-Hartman * The first several bits of this value should store the desired 1648ffdff6aSGreg Kroah-Hartman * value to write to the register. All other bits are for 1658ffdff6aSGreg Kroah-Hartman * transmitting information that modify the mode of the particular 1668ffdff6aSGreg Kroah-Hartman * destination/gate. These mode bits might include a bitwise or of 1678ffdff6aSGreg Kroah-Hartman * CR_INVERT and CR_EDGE. Note that the calling function should 1688ffdff6aSGreg Kroah-Hartman * have already validated the correctness of this value. 1698ffdff6aSGreg Kroah-Hartman */ 1708ffdff6aSGreg Kroah-Hartman int ni_tio_set_routing(struct ni_gpct_device *counter_dev, 1718ffdff6aSGreg Kroah-Hartman unsigned int destination, unsigned int register_value); 1728ffdff6aSGreg Kroah-Hartman 1738ffdff6aSGreg Kroah-Hartman /* 1748ffdff6aSGreg Kroah-Hartman * Sets the given destination MUX to its default value or disable it. 1758ffdff6aSGreg Kroah-Hartman * 1768ffdff6aSGreg Kroah-Hartman * Return: 0 if successful; -EINVAL if terminal is unknown. 1778ffdff6aSGreg Kroah-Hartman */ 1788ffdff6aSGreg Kroah-Hartman int ni_tio_unset_routing(struct ni_gpct_device *counter_dev, 1798ffdff6aSGreg Kroah-Hartman unsigned int destination); 1808ffdff6aSGreg Kroah-Hartman 1818ffdff6aSGreg Kroah-Hartman #endif /* _COMEDI_NI_TIO_H */ 182