OSDN Git Service

greybus: endo: encapsulate computing the max interface id
authorAlex Elder <elder@linaro.org>
Fri, 22 May 2015 17:56:46 +0000 (12:56 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Sat, 23 May 2015 23:44:45 +0000 (16:44 -0700)
The maximum interface id on an Endo is the result of a non-trivial
calculation.  It'll be needed for an upcoming patch, so create a
macro to compute it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/endo.c

index 5b5a3c6..e4faa5c 100644 (file)
 #define endo_back_left_ribs(id, ribs)          (((id) >> (ribs)) & ENDO_BACK_SIDE_RIBS_MASK(ribs))
 #define endo_back_right_ribs(id, ribs)         ((id) & ENDO_BACK_SIDE_RIBS_MASK(ribs))
 
+/*
+ * An Endo has interface block positions on the front and back.
+ * Each has numeric ID, starting with 1 (interface 0 represents
+ * the SVC within the Endo itself).  The maximum interface ID is the
+ * also the number of non-SVC interfaces possible on the endo.
+ *
+ * Total number of interfaces:
+ * - Front: 4
+ * - Back left: max_ribs + 1
+ * - Back right: max_ribs + 1
+ */
+#define max_endo_interface_id(endo_layout) \
+               (4 + ((endo_layout)->max_ribs + 1) * 2)
+
 /* endo sysfs attributes */
 static ssize_t serial_number_show(struct device *dev,
                                  struct device_attribute *attr, char *buf)
@@ -361,19 +375,12 @@ static int create_modules(struct gb_endo *endo)
        int prev_module_id = 0;
        int interface_id;
        int module_id;
-       int interfaces;
+       int max_id;
 
-       /*
-        * Total number of interfaces:
-        * - Front: 4
-        * - Back:
-        *   - Left: max_ribs + 1
-        *   - Right: max_ribs + 1
-        */
-       interfaces = 4 + (endo->layout.max_ribs + 1) * 2;
+       max_id = max_endo_interface_id(&endo->layout);
 
        /* Find module corresponding to each interface */
-       for (interface_id = 1; interface_id <= interfaces; interface_id++) {
+       for (interface_id = 1; interface_id <= max_id; interface_id++) {
                module_id = endo_get_module_id(endo, interface_id);
 
                if (WARN_ON(!module_id))