Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: comedi: clarify/unify macros for NI macro-defined terminals

Uses a single macro to define multiple macros that represent a series of
terminals for NI devices. This patch also redefines NI_MAX_COUNTERS as the
maximum number of counters possible on NI devices (instead of the maximum
index of the counters). This was a little confusing and caused a bug in
commit 347e244884c3b ("staging: comedi: tio: implement global tio/ctr routing")
when setting/reading registers for counter terminals.

Fixes: 347e244884c3b ("staging: comedi: tio: implement global tio/ctr routing")
Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Spencer E. Olson and committed by
Greg Kroah-Hartman
4dc2a3cd b7c56d7b

+21 -18
+21 -18
drivers/staging/comedi/comedi.h
··· 1005 1005 * and INSN_DEVICE_CONFIG_GET_ROUTES. 1006 1006 */ 1007 1007 #define NI_NAMES_BASE 0x8000u 1008 + 1009 + #define _TERM_N(base, n, x) ((base) + ((x) & ((n) - 1))) 1010 + 1008 1011 /* 1009 1012 * not necessarily all allowed 64 PFIs are valid--certainly not for all devices 1010 1013 */ 1011 - #define NI_PFI(x) (NI_NAMES_BASE + ((x) & 0x3f)) 1014 + #define NI_PFI(x) _TERM_N(NI_NAMES_BASE, 64, x) 1012 1015 /* 8 trigger lines by standard, Some devices cannot talk to all eight. */ 1013 - #define TRIGGER_LINE(x) (NI_PFI(-1) + 1 + ((x) & 0x7)) 1016 + #define TRIGGER_LINE(x) _TERM_N(NI_PFI(-1) + 1, 8, x) 1014 1017 /* 4 RTSI shared MUXes to route signals to/from TRIGGER_LINES on NI hardware */ 1015 - #define NI_RTSI_BRD(x) (TRIGGER_LINE(-1) + 1 + ((x) & 0x3)) 1018 + #define NI_RTSI_BRD(x) _TERM_N(TRIGGER_LINE(-1) + 1, 4, x) 1016 1019 1017 1020 /* *** Counter/timer names : 8 counters max *** */ 1018 - #define NI_COUNTER_NAMES_BASE (NI_RTSI_BRD(-1) + 1) 1019 - #define NI_MAX_COUNTERS 7 1020 - #define NI_CtrSource(x) (NI_COUNTER_NAMES_BASE + ((x) & NI_MAX_COUNTERS)) 1021 + #define NI_MAX_COUNTERS 8 1022 + #define NI_COUNTER_NAMES_BASE (NI_RTSI_BRD(-1) + 1) 1023 + #define NI_CtrSource(x) _TERM_N(NI_COUNTER_NAMES_BASE, NI_MAX_COUNTERS, x) 1021 1024 /* Gate, Aux, A,B,Z are all treated, at times as gates */ 1022 - #define NI_GATES_NAMES_BASE (NI_CtrSource(-1) + 1) 1023 - #define NI_CtrGate(x) (NI_GATES_NAMES_BASE + ((x) & NI_MAX_COUNTERS)) 1024 - #define NI_CtrAux(x) (NI_CtrGate(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1025 - #define NI_CtrA(x) (NI_CtrAux(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1026 - #define NI_CtrB(x) (NI_CtrA(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1027 - #define NI_CtrZ(x) (NI_CtrB(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1028 - #define NI_GATES_NAMES_MAX NI_CtrZ(-1) 1029 - #define NI_CtrArmStartTrigger(x) (NI_CtrZ(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1025 + #define NI_GATES_NAMES_BASE (NI_CtrSource(-1) + 1) 1026 + #define NI_CtrGate(x) _TERM_N(NI_GATES_NAMES_BASE, NI_MAX_COUNTERS, x) 1027 + #define NI_CtrAux(x) _TERM_N(NI_CtrGate(-1) + 1, NI_MAX_COUNTERS, x) 1028 + #define NI_CtrA(x) _TERM_N(NI_CtrAux(-1) + 1, NI_MAX_COUNTERS, x) 1029 + #define NI_CtrB(x) _TERM_N(NI_CtrA(-1) + 1, NI_MAX_COUNTERS, x) 1030 + #define NI_CtrZ(x) _TERM_N(NI_CtrB(-1) + 1, NI_MAX_COUNTERS, x) 1031 + #define NI_GATES_NAMES_MAX NI_CtrZ(-1) 1032 + #define NI_CtrArmStartTrigger(x) _TERM_N(NI_CtrZ(-1) + 1, NI_MAX_COUNTERS, x) 1030 1033 #define NI_CtrInternalOutput(x) \ 1031 - (NI_CtrArmStartTrigger(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1034 + _TERM_N(NI_CtrArmStartTrigger(-1) + 1, NI_MAX_COUNTERS, x) 1032 1035 /** external pin(s) labeled conveniently as Ctr<i>Out. */ 1033 - #define NI_CtrOut(x) (NI_CtrInternalOutput(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1036 + #define NI_CtrOut(x) _TERM_N(NI_CtrInternalOutput(-1) + 1, NI_MAX_COUNTERS, x) 1034 1037 /** For Buffered sampling of ctr -- x series capability. */ 1035 - #define NI_CtrSampleClock(x) (NI_CtrOut(-1) + 1 + ((x) & NI_MAX_COUNTERS)) 1036 - #define NI_COUNTER_NAMES_MAX NI_CtrSampleClock(-1) 1038 + #define NI_CtrSampleClock(x) _TERM_N(NI_CtrOut(-1) + 1, NI_MAX_COUNTERS, x) 1039 + #define NI_COUNTER_NAMES_MAX NI_CtrSampleClock(-1) 1037 1040 1038 1041 enum ni_common_signal_names { 1039 1042 /* PXI_Star: this is a non-NI-specific signal */