staging: comedi: ni_routes: Allow alternate board name for routes
authorIan Abbott <abbotti@mev.co.uk>
Fri, 7 Feb 2020 15:13:58 +0000 (15:13 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Feb 2020 18:25:06 +0000 (10:25 -0800)
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: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20200207151400.272678-3-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_660x.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/ni_routes.c
drivers/staging/comedi/drivers/ni_routes.h

index 4ee9b260eab0ec90b22f39c265d16e0978afa75e..75d5c9c2459602986079e4730cd97cb86de7f368 100644 (file)
@@ -1035,7 +1035,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
        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,
+       if (ni_assign_device_routes("ni_660x", board->name, NULL,
                                    &devpriv->routing_tables) < 0) {
                dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
                         __func__, board->name);
index f98e3ae27bff96d09299a41bf3c91e851d4be8ec..a1578868ee96d5699ce5f9b7660e0b5d14267b4c 100644 (file)
@@ -5974,7 +5974,7 @@ static int ni_E_init(struct comedi_device *dev,
                                                      : "ni_eseries";
 
        /* 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) {
                dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
                         __func__, board->name);
index 508f76c5c5744cef205241404cddf3474415b00b..07cb970340dba56fd6703601ecbb810971a1adc8 100644 (file)
@@ -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
- * 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.
  */
 static int ni_find_device_routes(const char *device_family,
                                 const char *board_name,
+                                const char *alt_board_name,
                                 struct ni_route_tables *tables)
 {
        const struct ni_device_routes *dr;
@@ -104,6 +106,8 @@ static int ni_find_device_routes(const char *device_family,
 
        /* Second, find the set of routes valid for this device. */
        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->valid_routes = dr;
@@ -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
  *                            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.
  */
 int ni_assign_device_routes(const char *device_family,
                            const char *board_name,
+                           const char *alt_board_name,
                            struct ni_route_tables *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);
 
index 3211a16adc6f191d36aa00047dae3ace1cbcd2ee..b7680fd2afe190ece19cb53f8bbbefdce8d74745 100644 (file)
@@ -76,6 +76,7 @@ struct ni_route_tables {
  */
 int ni_assign_device_routes(const char *device_family,
                            const char *board_name,
+                           const char *alt_board_name,
                            struct ni_route_tables *tables);
 
 /*