1 /* 2 * Header file for NI general purpose counter support code (ni_tio.c) 3 * 4 * COMEDI - Linux Control and Measurement Device Interface 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 17 #ifndef _COMEDI_NI_TIO_H 18 #define _COMEDI_NI_TIO_H 19 20 #include "../comedidev.h" 21 22 enum ni_gpct_register { 23 NITIO_G0_AUTO_INC, 24 NITIO_G1_AUTO_INC, 25 NITIO_G2_AUTO_INC, 26 NITIO_G3_AUTO_INC, 27 NITIO_G0_CMD, 28 NITIO_G1_CMD, 29 NITIO_G2_CMD, 30 NITIO_G3_CMD, 31 NITIO_G0_HW_SAVE, 32 NITIO_G1_HW_SAVE, 33 NITIO_G2_HW_SAVE, 34 NITIO_G3_HW_SAVE, 35 NITIO_G0_SW_SAVE, 36 NITIO_G1_SW_SAVE, 37 NITIO_G2_SW_SAVE, 38 NITIO_G3_SW_SAVE, 39 NITIO_G0_MODE, 40 NITIO_G1_MODE, 41 NITIO_G2_MODE, 42 NITIO_G3_MODE, 43 NITIO_G0_LOADA, 44 NITIO_G1_LOADA, 45 NITIO_G2_LOADA, 46 NITIO_G3_LOADA, 47 NITIO_G0_LOADB, 48 NITIO_G1_LOADB, 49 NITIO_G2_LOADB, 50 NITIO_G3_LOADB, 51 NITIO_G0_INPUT_SEL, 52 NITIO_G1_INPUT_SEL, 53 NITIO_G2_INPUT_SEL, 54 NITIO_G3_INPUT_SEL, 55 NITIO_G0_CNT_MODE, 56 NITIO_G1_CNT_MODE, 57 NITIO_G2_CNT_MODE, 58 NITIO_G3_CNT_MODE, 59 NITIO_G0_GATE2, 60 NITIO_G1_GATE2, 61 NITIO_G2_GATE2, 62 NITIO_G3_GATE2, 63 NITIO_G01_STATUS, 64 NITIO_G23_STATUS, 65 NITIO_G01_RESET, 66 NITIO_G23_RESET, 67 NITIO_G01_STATUS1, 68 NITIO_G23_STATUS1, 69 NITIO_G01_STATUS2, 70 NITIO_G23_STATUS2, 71 NITIO_G0_DMA_CFG, 72 NITIO_G1_DMA_CFG, 73 NITIO_G2_DMA_CFG, 74 NITIO_G3_DMA_CFG, 75 NITIO_G0_DMA_STATUS, 76 NITIO_G1_DMA_STATUS, 77 NITIO_G2_DMA_STATUS, 78 NITIO_G3_DMA_STATUS, 79 NITIO_G0_ABZ, 80 NITIO_G1_ABZ, 81 NITIO_G0_INT_ACK, 82 NITIO_G1_INT_ACK, 83 NITIO_G2_INT_ACK, 84 NITIO_G3_INT_ACK, 85 NITIO_G0_STATUS, 86 NITIO_G1_STATUS, 87 NITIO_G2_STATUS, 88 NITIO_G3_STATUS, 89 NITIO_G0_INT_ENA, 90 NITIO_G1_INT_ENA, 91 NITIO_G2_INT_ENA, 92 NITIO_G3_INT_ENA, 93 NITIO_NUM_REGS, 94 }; 95 96 enum ni_gpct_variant { 97 ni_gpct_variant_e_series, 98 ni_gpct_variant_m_series, 99 ni_gpct_variant_660x 100 }; 101 102 struct ni_gpct { 103 struct ni_gpct_device *counter_dev; 104 unsigned int counter_index; 105 unsigned int chip_index; 106 u64 clock_period_ps; /* clock period in picoseconds */ 107 struct mite_channel *mite_chan; 108 spinlock_t lock; /* protects 'mite_chan' */ 109 }; 110 111 struct ni_gpct_device { 112 struct comedi_device *dev; 113 void (*write)(struct ni_gpct *, unsigned int value, 114 enum ni_gpct_register); 115 unsigned int (*read)(struct ni_gpct *, enum ni_gpct_register); 116 enum ni_gpct_variant variant; 117 struct ni_gpct *counters; 118 unsigned int num_counters; 119 unsigned int regs[NITIO_NUM_REGS]; 120 spinlock_t regs_lock; /* protects 'regs' */ 121 }; 122 123 struct ni_gpct_device * 124 ni_gpct_device_construct(struct comedi_device *, 125 void (*write)(struct ni_gpct *, 126 unsigned int value, 127 enum ni_gpct_register), 128 unsigned int (*read)(struct ni_gpct *, 129 enum ni_gpct_register), 130 enum ni_gpct_variant, 131 unsigned int num_counters); 132 void ni_gpct_device_destroy(struct ni_gpct_device *); 133 void ni_tio_init_counter(struct ni_gpct *); 134 int ni_tio_insn_read(struct comedi_device *, struct comedi_subdevice *, 135 struct comedi_insn *, unsigned int *data); 136 int ni_tio_insn_config(struct comedi_device *, struct comedi_subdevice *, 137 struct comedi_insn *, unsigned int *data); 138 int ni_tio_insn_write(struct comedi_device *, struct comedi_subdevice *, 139 struct comedi_insn *, unsigned int *data); 140 int ni_tio_cmd(struct comedi_device *, struct comedi_subdevice *); 141 int ni_tio_cmdtest(struct comedi_device *, struct comedi_subdevice *, 142 struct comedi_cmd *); 143 int ni_tio_cancel(struct ni_gpct *); 144 void ni_tio_handle_interrupt(struct ni_gpct *, struct comedi_subdevice *); 145 void ni_tio_set_mite_channel(struct ni_gpct *, struct mite_channel *); 146 void ni_tio_acknowledge(struct ni_gpct *); 147 148 #endif /* _COMEDI_NI_TIO_H */ 149