greybus: interface: use an enum for interface type
authorJohan Hovold <johan@hovoldconsulting.com>
Wed, 20 Jul 2016 14:40:20 +0000 (16:40 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 20 Jul 2016 17:16:54 +0000 (10:16 -0700)
Use an enum for the interface type instead of using the SVC protocol
values directly.

Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/interface.c
drivers/staging/greybus/interface.h
drivers/staging/greybus/module.c

index 22b7342..e21491b 100644 (file)
@@ -494,10 +494,11 @@ static DEVICE_ATTR_RO(power_now);
 static const char *gb_interface_type_string(struct gb_interface *intf)
 {
        static const char * const types[] = {
-               [GB_SVC_INTF_TYPE_UNKNOWN] = "unknown",
-               [GB_SVC_INTF_TYPE_DUMMY] = "dummy",
-               [GB_SVC_INTF_TYPE_UNIPRO] = "unipro",
-               [GB_SVC_INTF_TYPE_GREYBUS] = "greybus",
+               [GB_INTERFACE_TYPE_INVALID] = "invalid",
+               [GB_INTERFACE_TYPE_UNKNOWN] = "unknown",
+               [GB_INTERFACE_TYPE_DUMMY] = "dummy",
+               [GB_INTERFACE_TYPE_UNIPRO] = "unipro",
+               [GB_INTERFACE_TYPE_GREYBUS] = "greybus",
        };
 
        return types[intf->type];
@@ -545,8 +546,8 @@ static umode_t interface_unipro_is_visible(struct kobject *kobj,
        struct gb_interface *intf = to_gb_interface(dev);
 
        switch (intf->type) {
-       case GB_SVC_INTF_TYPE_UNIPRO:
-       case GB_SVC_INTF_TYPE_GREYBUS:
+       case GB_INTERFACE_TYPE_UNIPRO:
+       case GB_INTERFACE_TYPE_GREYBUS:
                return attr->mode;
        default:
                return 0;
@@ -560,7 +561,7 @@ static umode_t interface_greybus_is_visible(struct kobject *kobj,
        struct gb_interface *intf = to_gb_interface(dev);
 
        switch (intf->type) {
-       case GB_SVC_INTF_TYPE_GREYBUS:
+       case GB_INTERFACE_TYPE_GREYBUS:
                return attr->mode;
        default:
                return 0;
@@ -574,8 +575,8 @@ static umode_t interface_power_is_visible(struct kobject *kobj,
        struct gb_interface *intf = to_gb_interface(dev);
 
        switch (intf->type) {
-       case GB_SVC_INTF_TYPE_UNIPRO:
-       case GB_SVC_INTF_TYPE_GREYBUS:
+       case GB_INTERFACE_TYPE_UNIPRO:
+       case GB_INTERFACE_TYPE_GREYBUS:
                return attr->mode;
        default:
                return 0;
@@ -825,21 +826,22 @@ static int gb_interface_activate_operation(struct gb_interface *intf)
                return ret;
        }
 
-       intf->type = type;
-
        switch (type) {
        case GB_SVC_INTF_TYPE_DUMMY:
+               intf->type = GB_INTERFACE_TYPE_DUMMY;
                /* FIXME: handle as an error for now */
                return -ENODEV;
        case GB_SVC_INTF_TYPE_UNIPRO:
+               intf->type = GB_INTERFACE_TYPE_UNIPRO;
                dev_err(&intf->dev, "interface type UniPro not supported\n");
                /* FIXME: check if this is a Toshiba bridge before retrying? */
                return -EAGAIN;
        case GB_SVC_INTF_TYPE_GREYBUS:
+               intf->type = GB_INTERFACE_TYPE_GREYBUS;
                break;
        default:
                dev_err(&intf->dev, "unknown interface type: %u\n", type);
-               intf->type = GB_SVC_INTF_TYPE_UNKNOWN;
+               intf->type = GB_INTERFACE_TYPE_UNKNOWN;
                return -ENODEV;
        }
 
@@ -1134,15 +1136,17 @@ int gb_interface_add(struct gb_interface *intf)
                        gb_interface_type_string(intf));
 
        switch (intf->type) {
-       case GB_SVC_INTF_TYPE_GREYBUS:
+       case GB_INTERFACE_TYPE_GREYBUS:
                dev_info(&intf->dev, "Ara VID=0x%08x, PID=0x%08x\n",
                                intf->vendor_id, intf->product_id);
                /* fall-through */
-       case GB_SVC_INTF_TYPE_UNIPRO:
+       case GB_INTERFACE_TYPE_UNIPRO:
                dev_info(&intf->dev, "DDBL1 Manufacturer=0x%08x, Product=0x%08x\n",
                                intf->ddbl1_manufacturer_id,
                                intf->ddbl1_product_id);
                break;
+       default:
+               break;
        }
 
        return 0;
index 05a3909..bba1881 100644 (file)
 #ifndef __INTERFACE_H
 #define __INTERFACE_H
 
+enum gb_interface_type {
+       GB_INTERFACE_TYPE_INVALID = 0,
+       GB_INTERFACE_TYPE_UNKNOWN,
+       GB_INTERFACE_TYPE_DUMMY,
+       GB_INTERFACE_TYPE_UNIPRO,
+       GB_INTERFACE_TYPE_GREYBUS,
+};
+
 #define GB_INTERFACE_QUIRK_NO_CPORT_FEATURES           BIT(0)
 #define GB_INTERFACE_QUIRK_NO_INIT_STATUS              BIT(1)
 #define GB_INTERFACE_QUIRK_NO_ARA_IDS                  BIT(2)
@@ -26,7 +34,8 @@ struct gb_interface {
        u8 interface_id;        /* Physical location within the Endo */
        u8 device_id;
        u8 features;            /* Feature flags set in the manifest */
-       u8 type;
+
+       enum gb_interface_type type;
 
        u32 ddbl1_manufacturer_id;
        u32 ddbl1_product_id;
index 242be49..3ae5876 100644 (file)
@@ -153,7 +153,7 @@ static void gb_module_register_interface(struct gb_interface *intf)
                        break;
        }
        if (ret) {
-               if (intf->type != GB_SVC_INTF_TYPE_DUMMY) {
+               if (intf->type != GB_INTERFACE_TYPE_DUMMY) {
                        dev_err(&module->dev,
                                        "failed to activate interface %u: %d\n",
                                        intf_id, ret);