Commit e3b7ce73 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: ni_routes: Allow alternate board name for routes

We do not have or provide routing information available for all
supported boards.  Some of the boards for which we do not currently
provide routing information actually have identical routes to a similar
board for which we do provide routing information.  To avoid having to
provide duplicate routing information, add an "alternate board name"
parameter (possibly `NULl`) to `ni_assign_device_routes()` and
`ni_find_device_routes()`.  If the routing information cannot be found
for the actual board name, try finding it using the alternate board
name.

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20200207151400.272678-3-abbotti@mev.co.ukSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 075a3295
...@@ -1035,7 +1035,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev, ...@@ -1035,7 +1035,7 @@ 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. */ /* prepare the device for globally-named routes. */
if (ni_assign_device_routes("ni_660x", board->name, if (ni_assign_device_routes("ni_660x", board->name, NULL,
&devpriv->routing_tables) < 0) { &devpriv->routing_tables) < 0) {
dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n", dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
__func__, board->name); __func__, board->name);
......
...@@ -5974,7 +5974,7 @@ static int ni_E_init(struct comedi_device *dev, ...@@ -5974,7 +5974,7 @@ static int ni_E_init(struct comedi_device *dev,
: "ni_eseries"; : "ni_eseries";
/* prepare the device for globally-named routes. */ /* prepare the device for globally-named routes. */
if (ni_assign_device_routes(dev_family, board->name, if (ni_assign_device_routes(dev_family, board->name, NULL,
&devpriv->routing_tables) < 0) { &devpriv->routing_tables) < 0) {
dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n", dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
__func__, board->name); __func__, board->name);
......
...@@ -88,12 +88,14 @@ ni_find_valid_routes(const char *board_name) ...@@ -88,12 +88,14 @@ ni_find_valid_routes(const char *board_name)
/* /*
* Find the proper route_values and ni_device_routes tables for this particular * Find the proper route_values and ni_device_routes tables for this particular
* device. * device. Possibly try an alternate board name if device routes not found
* for the actual board name.
* *
* Return: -ENODATA if either was not found; 0 if both were found. * Return: -ENODATA if either was not found; 0 if both were found.
*/ */
static int ni_find_device_routes(const char *device_family, static int ni_find_device_routes(const char *device_family,
const char *board_name, const char *board_name,
const char *alt_board_name,
struct ni_route_tables *tables) struct ni_route_tables *tables)
{ {
const struct ni_device_routes *dr; const struct ni_device_routes *dr;
...@@ -104,6 +106,8 @@ static int ni_find_device_routes(const char *device_family, ...@@ -104,6 +106,8 @@ static int ni_find_device_routes(const char *device_family,
/* Second, find the set of routes valid for this device. */ /* Second, find the set of routes valid for this device. */
dr = ni_find_valid_routes(board_name); dr = ni_find_valid_routes(board_name);
if (!dr && alt_board_name)
dr = ni_find_valid_routes(alt_board_name);
tables->route_values = rv; tables->route_values = rv;
tables->valid_routes = dr; tables->valid_routes = dr;
...@@ -117,15 +121,28 @@ static int ni_find_device_routes(const char *device_family, ...@@ -117,15 +121,28 @@ static int ni_find_device_routes(const char *device_family,
/** /**
* ni_assign_device_routes() - Assign the proper lookup table for NI signal * ni_assign_device_routes() - Assign the proper lookup table for NI signal
* routing to the specified NI device. * routing to the specified NI device.
* @device_family: Device family name (determines route values).
* @board_name: Board name (determines set of routes).
* @alt_board_name: Optional alternate board name to try on failure.
* @tables: Pointer to assigned routing information.
*
* Finds the route values for the device family and the set of valid routes
* for the board. If valid routes could not be found for the actual board
* name and an alternate board name has been specified, try that one.
*
* On failure, the assigned routing information may be partially filled
* (for example, with the route values but not the set of valid routes).
* *
* Return: -ENODATA if assignment was not successful; 0 if successful. * Return: -ENODATA if assignment was not successful; 0 if successful.
*/ */
int ni_assign_device_routes(const char *device_family, int ni_assign_device_routes(const char *device_family,
const char *board_name, const char *board_name,
const char *alt_board_name,
struct ni_route_tables *tables) struct ni_route_tables *tables)
{ {
memset(tables, 0, sizeof(struct ni_route_tables)); memset(tables, 0, sizeof(struct ni_route_tables));
return ni_find_device_routes(device_family, board_name, tables); return ni_find_device_routes(device_family, board_name, alt_board_name,
tables);
} }
EXPORT_SYMBOL_GPL(ni_assign_device_routes); EXPORT_SYMBOL_GPL(ni_assign_device_routes);
......
...@@ -76,6 +76,7 @@ struct ni_route_tables { ...@@ -76,6 +76,7 @@ struct ni_route_tables {
*/ */
int ni_assign_device_routes(const char *device_family, int ni_assign_device_routes(const char *device_family,
const char *board_name, const char *board_name,
const char *alt_board_name,
struct ni_route_tables *tables); struct ni_route_tables *tables);
/* /*
......
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