Commit 347e2448 authored by Spencer E. Olson's avatar Spencer E. Olson Committed by Greg Kroah-Hartman

staging: comedi: tio: implement global tio/ctr routing

Adds ability to use device-global names in command args, in particular
cmd->start_arg (for NI_CtrArmStartTrigger), and cmd->scan_begin_arg or
cmd->convert_arg (either is used to specify NI_CtrGate, with preference
given to cmd->scan_begin_arg, if it is set).

The actual arguments of cmd->start_arg are not fully checked against known
register values for the particular devices because these are not documented
or currently known.  This follows the precedence of prior versions of the
tio driver.  Should these become known, they should be annotated in the
route_values tables and the set of lines in ni_tio_cmdtest should be
uncommented to allow the tests to be made.

This patch also adds interface functions that allow routes for particular
counter route destinations to be made/queried/unmade.  This allows overseer
modules to implement test_route, connect_route, and disconnect_route.  As a
part of these changes, various functions were cleaned up and clarified.

These new interface functions allow direct writing/reading of register
values.  This is an example of exactly what the new device-global access
was intended to solve:  the old interface was not consistent with other
portions of the ni_* drivers--it did not allow full register values to be
given for various MUXes.  Instead, the old interface _did_ abstract away
some of the actual hardware from the underlying devices, but it was not
consistent with any other NI hardware.  Allowing the device-global
identifiers to be used, the new patch provides for consistency across all
ni_* drivers.  One final note:  these changes provide for backwards
compatibility by allowing the older values to still be used in through the
pre-existing kernel interfaces--though not in the new device-global
test/dis/connect/route interfaces.
Signed-off-by: default avatarSpencer E. Olson <olsonse@umich.edu>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 02d1c6e8
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "mite.h" #include "mite.h"
#include "ni_tio.h" #include "ni_tio.h"
#include "ni_routes.h"
/* See Register-Level Programmer Manual page 3.1 */ /* See Register-Level Programmer Manual page 3.1 */
enum ni_660x_register { enum ni_660x_register {
...@@ -259,6 +260,7 @@ struct ni_660x_private { ...@@ -259,6 +260,7 @@ struct ni_660x_private {
unsigned int dma_cfg[NI660X_MAX_CHIPS]; unsigned int dma_cfg[NI660X_MAX_CHIPS];
unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS]; unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
u64 io_dir; u64 io_dir;
struct ni_route_tables routing_tables;
}; };
static void ni_660x_write(struct comedi_device *dev, unsigned int chip, static void ni_660x_write(struct comedi_device *dev, unsigned int chip,
...@@ -730,12 +732,23 @@ static int ni_660x_auto_attach(struct comedi_device *dev, ...@@ -730,12 +732,23 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_init_tio_chips(dev, board->n_chips); ni_660x_init_tio_chips(dev, board->n_chips);
/* prepare the device for globally-named routes. */
if (ni_assign_device_routes("ni_660x", board->name,
&devpriv->routing_tables) < 0) {
dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
__func__, board->name);
dev_warn(dev->class_dev, "%s: High level NI signal names will not be available for this %s board.\n",
__func__, board->name);
}
n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP; n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
gpct_dev = ni_gpct_device_construct(dev, gpct_dev = ni_gpct_device_construct(dev,
ni_660x_gpct_write, ni_660x_gpct_write,
ni_660x_gpct_read, ni_660x_gpct_read,
ni_gpct_variant_660x, ni_gpct_variant_660x,
n_counters); n_counters,
NI660X_COUNTERS_PER_CHIP,
&devpriv->routing_tables);
if (!gpct_dev) if (!gpct_dev)
return -ENOMEM; return -ENOMEM;
devpriv->counter_dev = gpct_dev; devpriv->counter_dev = gpct_dev;
...@@ -831,9 +844,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev, ...@@ -831,9 +844,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (i < n_counters) { if (i < n_counters) {
struct ni_gpct *counter = &gpct_dev->counters[i]; struct ni_gpct *counter = &gpct_dev->counters[i];
counter->chip_index = i / NI660X_COUNTERS_PER_CHIP;
counter->counter_index = i % NI660X_COUNTERS_PER_CHIP;
s->type = COMEDI_SUBD_COUNTER; s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
SDF_LSAMPL | SDF_CMD_READ; SDF_LSAMPL | SDF_CMD_READ;
......
...@@ -6213,7 +6213,9 @@ static int ni_E_init(struct comedi_device *dev, ...@@ -6213,7 +6213,9 @@ static int ni_E_init(struct comedi_device *dev,
(devpriv->is_m_series) (devpriv->is_m_series)
? ni_gpct_variant_m_series ? ni_gpct_variant_m_series
: ni_gpct_variant_e_series, : ni_gpct_variant_e_series,
NUM_GPCT); NUM_GPCT,
NUM_GPCT,
&devpriv->routing_tables);
if (!devpriv->counter_dev) if (!devpriv->counter_dev)
return -ENOMEM; return -ENOMEM;
...@@ -6222,8 +6224,6 @@ static int ni_E_init(struct comedi_device *dev, ...@@ -6222,8 +6224,6 @@ static int ni_E_init(struct comedi_device *dev,
struct ni_gpct *gpct = &devpriv->counter_dev->counters[i]; struct ni_gpct *gpct = &devpriv->counter_dev->counters[i];
/* setup and initialize the counter */ /* setup and initialize the counter */
gpct->chip_index = 0;
gpct->counter_index = i;
ni_tio_init_counter(gpct); ni_tio_init_counter(gpct);
s = &dev->subdevices[NI_GPCT_SUBDEV(i)]; s = &dev->subdevices[NI_GPCT_SUBDEV(i)];
......
This diff is collapsed.
...@@ -107,8 +107,10 @@ struct ni_gpct_device { ...@@ -107,8 +107,10 @@ struct ni_gpct_device {
enum ni_gpct_variant variant; enum ni_gpct_variant variant;
struct ni_gpct *counters; struct ni_gpct *counters;
unsigned int num_counters; unsigned int num_counters;
unsigned int counters_per_chip;
unsigned int regs[NITIO_NUM_REGS]; unsigned int regs[NITIO_NUM_REGS];
spinlock_t regs_lock; /* protects 'regs' */ spinlock_t regs_lock; /* protects 'regs' */
const struct ni_route_tables *routing_tables; /* link to routes */
}; };
struct ni_gpct_device * struct ni_gpct_device *
...@@ -119,7 +121,9 @@ ni_gpct_device_construct(struct comedi_device *dev, ...@@ -119,7 +121,9 @@ ni_gpct_device_construct(struct comedi_device *dev,
unsigned int (*read)(struct ni_gpct *counter, unsigned int (*read)(struct ni_gpct *counter,
enum ni_gpct_register), enum ni_gpct_register),
enum ni_gpct_variant, enum ni_gpct_variant,
unsigned int num_counters); unsigned int num_counters,
unsigned int counters_per_chip,
const struct ni_route_tables *routing_tables);
void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev); void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev);
void ni_tio_init_counter(struct ni_gpct *counter); void ni_tio_init_counter(struct ni_gpct *counter);
int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
...@@ -138,4 +142,40 @@ void ni_tio_set_mite_channel(struct ni_gpct *counter, ...@@ -138,4 +142,40 @@ void ni_tio_set_mite_channel(struct ni_gpct *counter,
struct mite_channel *mite_chan); struct mite_channel *mite_chan);
void ni_tio_acknowledge(struct ni_gpct *counter); void ni_tio_acknowledge(struct ni_gpct *counter);
/*
* Retrieves the register value of the current source of the output selector for
* the given destination.
*
* If the terminal for the destination is not already configured as an output,
* this function returns -EINVAL as error.
*
* Return: the register value of the destination output selector;
* -EINVAL if terminal is not configured for output.
*/
int ni_tio_get_routing(struct ni_gpct_device *counter_dev,
unsigned int destination);
/*
* Sets the register value of the selector MUX for the given destination.
* @counter_dev:Pointer to general counter device.
* @destination:Device-global identifier of route destination.
* @register_value:
* The first several bits of this value should store the desired
* value to write to the register. All other bits are for
* transmitting information that modify the mode of the particular
* destination/gate. These mode bits might include a bitwise or of
* CR_INVERT and CR_EDGE. Note that the calling function should
* have already validated the correctness of this value.
*/
int ni_tio_set_routing(struct ni_gpct_device *counter_dev,
unsigned int destination, unsigned int register_value);
/*
* Sets the given destination MUX to its default value or disable it.
*
* Return: 0 if successful; -EINVAL if terminal is unknown.
*/
int ni_tio_unset_routing(struct ni_gpct_device *counter_dev,
unsigned int destination);
#endif /* _COMEDI_NI_TIO_H */ #endif /* _COMEDI_NI_TIO_H */
...@@ -170,5 +170,7 @@ unsigned int ni_tio_get_soft_copy(const struct ni_gpct *counter, ...@@ -170,5 +170,7 @@ unsigned int ni_tio_get_soft_copy(const struct ni_gpct *counter,
int ni_tio_arm(struct ni_gpct *counter, bool arm, unsigned int start_trigger); int ni_tio_arm(struct ni_gpct *counter, bool arm, unsigned int start_trigger);
int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned int gate, int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned int gate,
unsigned int src); unsigned int src);
int ni_tio_set_gate_src_raw(struct ni_gpct *counter, unsigned int gate,
unsigned int src);
#endif /* _COMEDI_NI_TIO_INTERNAL_H */ #endif /* _COMEDI_NI_TIO_INTERNAL_H */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/module.h> #include <linux/module.h>
#include "ni_tio_internal.h" #include "ni_tio_internal.h"
#include "mite.h" #include "mite.h"
#include "ni_routes.h"
static void ni_tio_configure_dma(struct ni_gpct *counter, static void ni_tio_configure_dma(struct ni_gpct *counter,
bool enable, bool read) bool enable, bool read)
...@@ -100,6 +101,8 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s) ...@@ -100,6 +101,8 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
{ {
struct ni_gpct *counter = s->private; struct ni_gpct *counter = s->private;
struct ni_gpct_device *counter_dev = counter->counter_dev; struct ni_gpct_device *counter_dev = counter->counter_dev;
const struct ni_route_tables *routing_tables =
counter_dev->routing_tables;
unsigned int cidx = counter->counter_index; unsigned int cidx = counter->counter_index;
struct comedi_async *async = s->async; struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd; struct comedi_cmd *cmd = &async->cmd;
...@@ -128,8 +131,19 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s) ...@@ -128,8 +131,19 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
if (cmd->start_src == TRIG_NOW) if (cmd->start_src == TRIG_NOW)
ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE); ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE);
else if (cmd->start_src == TRIG_EXT) else if (cmd->start_src == TRIG_EXT) {
ret = ni_tio_arm(counter, true, cmd->start_arg); int reg = CR_CHAN(cmd->start_arg);
if (reg >= NI_NAMES_BASE) {
/* using a device-global name. lookup reg */
reg = ni_get_reg_value(reg,
NI_CtrArmStartTrigger(cidx),
routing_tables);
/* mark this as a raw register value */
reg |= NI_GPCT_HW_ARM;
}
ret = ni_tio_arm(counter, true, reg);
}
} }
return ret; return ret;
} }
...@@ -148,6 +162,8 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s) ...@@ -148,6 +162,8 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s)
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
struct ni_gpct *counter = s->private; struct ni_gpct *counter = s->private;
unsigned int cidx = counter->counter_index; unsigned int cidx = counter->counter_index;
const struct ni_route_tables *routing_tables =
counter->counter_dev->routing_tables;
int set_gate_source = 0; int set_gate_source = 0;
unsigned int gate_source; unsigned int gate_source;
int retval = 0; int retval = 0;
...@@ -159,8 +175,24 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s) ...@@ -159,8 +175,24 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s)
set_gate_source = 1; set_gate_source = 1;
gate_source = cmd->convert_arg; gate_source = cmd->convert_arg;
} }
if (set_gate_source) if (set_gate_source) {
retval = ni_tio_set_gate_src(counter, 0, gate_source); if (CR_CHAN(gate_source) >= NI_NAMES_BASE) {
/* Lookup and use the real register values */
int reg = ni_get_reg_value(CR_CHAN(gate_source),
NI_CtrGate(cidx),
routing_tables);
if (reg < 0)
return -EINVAL;
retval = ni_tio_set_gate_src_raw(counter, 0, reg);
} else {
/*
* This function must be used separately since it does
* not expect real register values and attempts to
* convert these to real register values.
*/
retval = ni_tio_set_gate_src(counter, 0, gate_source);
}
}
if (cmd->flags & CMDF_WAKE_EOS) { if (cmd->flags & CMDF_WAKE_EOS) {
ni_tio_set_bits(counter, NITIO_INT_ENA_REG(cidx), ni_tio_set_bits(counter, NITIO_INT_ENA_REG(cidx),
GI_GATE_INTERRUPT_ENABLE(cidx), GI_GATE_INTERRUPT_ENABLE(cidx),
...@@ -203,6 +235,9 @@ int ni_tio_cmdtest(struct comedi_device *dev, ...@@ -203,6 +235,9 @@ int ni_tio_cmdtest(struct comedi_device *dev,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
struct ni_gpct *counter = s->private; struct ni_gpct *counter = s->private;
unsigned int cidx = counter->counter_index;
const struct ni_route_tables *routing_tables =
counter->counter_dev->routing_tables;
int err = 0; int err = 0;
unsigned int sources; unsigned int sources;
...@@ -247,14 +282,37 @@ int ni_tio_cmdtest(struct comedi_device *dev, ...@@ -247,14 +282,37 @@ int ni_tio_cmdtest(struct comedi_device *dev,
break; break;
case TRIG_EXT: case TRIG_EXT:
/* start_arg is the start_trigger passed to ni_tio_arm() */ /* start_arg is the start_trigger passed to ni_tio_arm() */
/*
* This should be done, but we don't yet know the actual
* register values. These should be tested and then documented
* in the ni_route_values/ni_*.csv files, with indication of
* who/when/which/how these these were tested.
* When at least a e/m/660x series have been tested, this code
* should be uncommented:
*
* err |= ni_check_trigger_arg(CR_CHAN(cmd->start_arg),
* NI_CtrArmStartTrigger(cidx),
* routing_tables);
*/
break; break;
} }
/*
* It seems that convention is to allow either scan_begin_arg or
* convert_arg to specify the Gate source, with scan_begin_arg taking
* precedence.
*/
if (cmd->scan_begin_src != TRIG_EXT) if (cmd->scan_begin_src != TRIG_EXT)
err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
else
err |= ni_check_trigger_arg(CR_CHAN(cmd->scan_begin_arg),
NI_CtrGate(cidx), routing_tables);
if (cmd->convert_src != TRIG_EXT) if (cmd->convert_src != TRIG_EXT)
err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
else
err |= ni_check_trigger_arg(CR_CHAN(cmd->convert_arg),
NI_CtrGate(cidx), routing_tables);
err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
cmd->chanlist_len); cmd->chanlist_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment