1*8ffdff6aSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ */ 2*8ffdff6aSGreg Kroah-Hartman /* 3*8ffdff6aSGreg Kroah-Hartman * Header file for NI general purpose counter support code (ni_tio.c) 4*8ffdff6aSGreg Kroah-Hartman * 5*8ffdff6aSGreg Kroah-Hartman * COMEDI - Linux Control and Measurement Device Interface 6*8ffdff6aSGreg Kroah-Hartman */ 7*8ffdff6aSGreg Kroah-Hartman 8*8ffdff6aSGreg Kroah-Hartman #ifndef _COMEDI_NI_TIO_H 9*8ffdff6aSGreg Kroah-Hartman #define _COMEDI_NI_TIO_H 10*8ffdff6aSGreg Kroah-Hartman 11*8ffdff6aSGreg Kroah-Hartman #include "../comedidev.h" 12*8ffdff6aSGreg Kroah-Hartman 13*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_register { 14*8ffdff6aSGreg Kroah-Hartman NITIO_G0_AUTO_INC, 15*8ffdff6aSGreg Kroah-Hartman NITIO_G1_AUTO_INC, 16*8ffdff6aSGreg Kroah-Hartman NITIO_G2_AUTO_INC, 17*8ffdff6aSGreg Kroah-Hartman NITIO_G3_AUTO_INC, 18*8ffdff6aSGreg Kroah-Hartman NITIO_G0_CMD, 19*8ffdff6aSGreg Kroah-Hartman NITIO_G1_CMD, 20*8ffdff6aSGreg Kroah-Hartman NITIO_G2_CMD, 21*8ffdff6aSGreg Kroah-Hartman NITIO_G3_CMD, 22*8ffdff6aSGreg Kroah-Hartman NITIO_G0_HW_SAVE, 23*8ffdff6aSGreg Kroah-Hartman NITIO_G1_HW_SAVE, 24*8ffdff6aSGreg Kroah-Hartman NITIO_G2_HW_SAVE, 25*8ffdff6aSGreg Kroah-Hartman NITIO_G3_HW_SAVE, 26*8ffdff6aSGreg Kroah-Hartman NITIO_G0_SW_SAVE, 27*8ffdff6aSGreg Kroah-Hartman NITIO_G1_SW_SAVE, 28*8ffdff6aSGreg Kroah-Hartman NITIO_G2_SW_SAVE, 29*8ffdff6aSGreg Kroah-Hartman NITIO_G3_SW_SAVE, 30*8ffdff6aSGreg Kroah-Hartman NITIO_G0_MODE, 31*8ffdff6aSGreg Kroah-Hartman NITIO_G1_MODE, 32*8ffdff6aSGreg Kroah-Hartman NITIO_G2_MODE, 33*8ffdff6aSGreg Kroah-Hartman NITIO_G3_MODE, 34*8ffdff6aSGreg Kroah-Hartman NITIO_G0_LOADA, 35*8ffdff6aSGreg Kroah-Hartman NITIO_G1_LOADA, 36*8ffdff6aSGreg Kroah-Hartman NITIO_G2_LOADA, 37*8ffdff6aSGreg Kroah-Hartman NITIO_G3_LOADA, 38*8ffdff6aSGreg Kroah-Hartman NITIO_G0_LOADB, 39*8ffdff6aSGreg Kroah-Hartman NITIO_G1_LOADB, 40*8ffdff6aSGreg Kroah-Hartman NITIO_G2_LOADB, 41*8ffdff6aSGreg Kroah-Hartman NITIO_G3_LOADB, 42*8ffdff6aSGreg Kroah-Hartman NITIO_G0_INPUT_SEL, 43*8ffdff6aSGreg Kroah-Hartman NITIO_G1_INPUT_SEL, 44*8ffdff6aSGreg Kroah-Hartman NITIO_G2_INPUT_SEL, 45*8ffdff6aSGreg Kroah-Hartman NITIO_G3_INPUT_SEL, 46*8ffdff6aSGreg Kroah-Hartman NITIO_G0_CNT_MODE, 47*8ffdff6aSGreg Kroah-Hartman NITIO_G1_CNT_MODE, 48*8ffdff6aSGreg Kroah-Hartman NITIO_G2_CNT_MODE, 49*8ffdff6aSGreg Kroah-Hartman NITIO_G3_CNT_MODE, 50*8ffdff6aSGreg Kroah-Hartman NITIO_G0_GATE2, 51*8ffdff6aSGreg Kroah-Hartman NITIO_G1_GATE2, 52*8ffdff6aSGreg Kroah-Hartman NITIO_G2_GATE2, 53*8ffdff6aSGreg Kroah-Hartman NITIO_G3_GATE2, 54*8ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS, 55*8ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS, 56*8ffdff6aSGreg Kroah-Hartman NITIO_G01_RESET, 57*8ffdff6aSGreg Kroah-Hartman NITIO_G23_RESET, 58*8ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS1, 59*8ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS1, 60*8ffdff6aSGreg Kroah-Hartman NITIO_G01_STATUS2, 61*8ffdff6aSGreg Kroah-Hartman NITIO_G23_STATUS2, 62*8ffdff6aSGreg Kroah-Hartman NITIO_G0_DMA_CFG, 63*8ffdff6aSGreg Kroah-Hartman NITIO_G1_DMA_CFG, 64*8ffdff6aSGreg Kroah-Hartman NITIO_G2_DMA_CFG, 65*8ffdff6aSGreg Kroah-Hartman NITIO_G3_DMA_CFG, 66*8ffdff6aSGreg Kroah-Hartman NITIO_G0_DMA_STATUS, 67*8ffdff6aSGreg Kroah-Hartman NITIO_G1_DMA_STATUS, 68*8ffdff6aSGreg Kroah-Hartman NITIO_G2_DMA_STATUS, 69*8ffdff6aSGreg Kroah-Hartman NITIO_G3_DMA_STATUS, 70*8ffdff6aSGreg Kroah-Hartman NITIO_G0_ABZ, 71*8ffdff6aSGreg Kroah-Hartman NITIO_G1_ABZ, 72*8ffdff6aSGreg Kroah-Hartman NITIO_G0_INT_ACK, 73*8ffdff6aSGreg Kroah-Hartman NITIO_G1_INT_ACK, 74*8ffdff6aSGreg Kroah-Hartman NITIO_G2_INT_ACK, 75*8ffdff6aSGreg Kroah-Hartman NITIO_G3_INT_ACK, 76*8ffdff6aSGreg Kroah-Hartman NITIO_G0_STATUS, 77*8ffdff6aSGreg Kroah-Hartman NITIO_G1_STATUS, 78*8ffdff6aSGreg Kroah-Hartman NITIO_G2_STATUS, 79*8ffdff6aSGreg Kroah-Hartman NITIO_G3_STATUS, 80*8ffdff6aSGreg Kroah-Hartman NITIO_G0_INT_ENA, 81*8ffdff6aSGreg Kroah-Hartman NITIO_G1_INT_ENA, 82*8ffdff6aSGreg Kroah-Hartman NITIO_G2_INT_ENA, 83*8ffdff6aSGreg Kroah-Hartman NITIO_G3_INT_ENA, 84*8ffdff6aSGreg Kroah-Hartman NITIO_NUM_REGS, 85*8ffdff6aSGreg Kroah-Hartman }; 86*8ffdff6aSGreg Kroah-Hartman 87*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant { 88*8ffdff6aSGreg Kroah-Hartman ni_gpct_variant_e_series, 89*8ffdff6aSGreg Kroah-Hartman ni_gpct_variant_m_series, 90*8ffdff6aSGreg Kroah-Hartman ni_gpct_variant_660x 91*8ffdff6aSGreg Kroah-Hartman }; 92*8ffdff6aSGreg Kroah-Hartman 93*8ffdff6aSGreg Kroah-Hartman struct ni_gpct { 94*8ffdff6aSGreg Kroah-Hartman struct ni_gpct_device *counter_dev; 95*8ffdff6aSGreg Kroah-Hartman unsigned int counter_index; 96*8ffdff6aSGreg Kroah-Hartman unsigned int chip_index; 97*8ffdff6aSGreg Kroah-Hartman u64 clock_period_ps; /* clock period in picoseconds */ 98*8ffdff6aSGreg Kroah-Hartman struct mite_channel *mite_chan; 99*8ffdff6aSGreg Kroah-Hartman spinlock_t lock; /* protects 'mite_chan' */ 100*8ffdff6aSGreg Kroah-Hartman }; 101*8ffdff6aSGreg Kroah-Hartman 102*8ffdff6aSGreg Kroah-Hartman struct ni_gpct_device { 103*8ffdff6aSGreg Kroah-Hartman struct comedi_device *dev; 104*8ffdff6aSGreg Kroah-Hartman void (*write)(struct ni_gpct *counter, unsigned int value, 105*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_register); 106*8ffdff6aSGreg Kroah-Hartman unsigned int (*read)(struct ni_gpct *counter, enum ni_gpct_register); 107*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant variant; 108*8ffdff6aSGreg Kroah-Hartman struct ni_gpct *counters; 109*8ffdff6aSGreg Kroah-Hartman unsigned int num_counters; 110*8ffdff6aSGreg Kroah-Hartman unsigned int num_chips; 111*8ffdff6aSGreg Kroah-Hartman unsigned int (*regs)[NITIO_NUM_REGS]; /* [num_chips][NITIO_NUM_REGS] */ 112*8ffdff6aSGreg Kroah-Hartman spinlock_t regs_lock; /* protects 'regs' */ 113*8ffdff6aSGreg Kroah-Hartman const struct ni_route_tables *routing_tables; /* link to routes */ 114*8ffdff6aSGreg Kroah-Hartman }; 115*8ffdff6aSGreg Kroah-Hartman 116*8ffdff6aSGreg Kroah-Hartman struct ni_gpct_device * 117*8ffdff6aSGreg Kroah-Hartman ni_gpct_device_construct(struct comedi_device *dev, 118*8ffdff6aSGreg Kroah-Hartman void (*write)(struct ni_gpct *counter, 119*8ffdff6aSGreg Kroah-Hartman unsigned int value, 120*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_register), 121*8ffdff6aSGreg Kroah-Hartman unsigned int (*read)(struct ni_gpct *counter, 122*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_register), 123*8ffdff6aSGreg Kroah-Hartman enum ni_gpct_variant, 124*8ffdff6aSGreg Kroah-Hartman unsigned int num_counters, 125*8ffdff6aSGreg Kroah-Hartman unsigned int counters_per_chip, 126*8ffdff6aSGreg Kroah-Hartman const struct ni_route_tables *routing_tables); 127*8ffdff6aSGreg Kroah-Hartman void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev); 128*8ffdff6aSGreg Kroah-Hartman void ni_tio_init_counter(struct ni_gpct *counter); 129*8ffdff6aSGreg Kroah-Hartman int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, 130*8ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 131*8ffdff6aSGreg Kroah-Hartman int ni_tio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, 132*8ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 133*8ffdff6aSGreg Kroah-Hartman int ni_tio_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, 134*8ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn, unsigned int *data); 135*8ffdff6aSGreg Kroah-Hartman int ni_tio_cmd(struct comedi_device *dev, struct comedi_subdevice *s); 136*8ffdff6aSGreg Kroah-Hartman int ni_tio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, 137*8ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd); 138*8ffdff6aSGreg Kroah-Hartman int ni_tio_cancel(struct ni_gpct *counter); 139*8ffdff6aSGreg Kroah-Hartman void ni_tio_handle_interrupt(struct ni_gpct *counter, 140*8ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s); 141*8ffdff6aSGreg Kroah-Hartman void ni_tio_set_mite_channel(struct ni_gpct *counter, 142*8ffdff6aSGreg Kroah-Hartman struct mite_channel *mite_chan); 143*8ffdff6aSGreg Kroah-Hartman void ni_tio_acknowledge(struct ni_gpct *counter); 144*8ffdff6aSGreg Kroah-Hartman 145*8ffdff6aSGreg Kroah-Hartman /* 146*8ffdff6aSGreg Kroah-Hartman * Retrieves the register value of the current source of the output selector for 147*8ffdff6aSGreg Kroah-Hartman * the given destination. 148*8ffdff6aSGreg Kroah-Hartman * 149*8ffdff6aSGreg Kroah-Hartman * If the terminal for the destination is not already configured as an output, 150*8ffdff6aSGreg Kroah-Hartman * this function returns -EINVAL as error. 151*8ffdff6aSGreg Kroah-Hartman * 152*8ffdff6aSGreg Kroah-Hartman * Return: the register value of the destination output selector; 153*8ffdff6aSGreg Kroah-Hartman * -EINVAL if terminal is not configured for output. 154*8ffdff6aSGreg Kroah-Hartman */ 155*8ffdff6aSGreg Kroah-Hartman int ni_tio_get_routing(struct ni_gpct_device *counter_dev, 156*8ffdff6aSGreg Kroah-Hartman unsigned int destination); 157*8ffdff6aSGreg Kroah-Hartman 158*8ffdff6aSGreg Kroah-Hartman /* 159*8ffdff6aSGreg Kroah-Hartman * Sets the register value of the selector MUX for the given destination. 160*8ffdff6aSGreg Kroah-Hartman * @counter_dev:Pointer to general counter device. 161*8ffdff6aSGreg Kroah-Hartman * @destination:Device-global identifier of route destination. 162*8ffdff6aSGreg Kroah-Hartman * @register_value: 163*8ffdff6aSGreg Kroah-Hartman * The first several bits of this value should store the desired 164*8ffdff6aSGreg Kroah-Hartman * value to write to the register. All other bits are for 165*8ffdff6aSGreg Kroah-Hartman * transmitting information that modify the mode of the particular 166*8ffdff6aSGreg Kroah-Hartman * destination/gate. These mode bits might include a bitwise or of 167*8ffdff6aSGreg Kroah-Hartman * CR_INVERT and CR_EDGE. Note that the calling function should 168*8ffdff6aSGreg Kroah-Hartman * have already validated the correctness of this value. 169*8ffdff6aSGreg Kroah-Hartman */ 170*8ffdff6aSGreg Kroah-Hartman int ni_tio_set_routing(struct ni_gpct_device *counter_dev, 171*8ffdff6aSGreg Kroah-Hartman unsigned int destination, unsigned int register_value); 172*8ffdff6aSGreg Kroah-Hartman 173*8ffdff6aSGreg Kroah-Hartman /* 174*8ffdff6aSGreg Kroah-Hartman * Sets the given destination MUX to its default value or disable it. 175*8ffdff6aSGreg Kroah-Hartman * 176*8ffdff6aSGreg Kroah-Hartman * Return: 0 if successful; -EINVAL if terminal is unknown. 177*8ffdff6aSGreg Kroah-Hartman */ 178*8ffdff6aSGreg Kroah-Hartman int ni_tio_unset_routing(struct ni_gpct_device *counter_dev, 179*8ffdff6aSGreg Kroah-Hartman unsigned int destination); 180*8ffdff6aSGreg Kroah-Hartman 181*8ffdff6aSGreg Kroah-Hartman #endif /* _COMEDI_NI_TIO_H */ 182