greybus: interface: use an enum for interface type

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>
This commit is contained in:
Johan Hovold 2016-07-20 16:40:20 +02:00 committed by Greg Kroah-Hartman
parent 6633d80afb
commit a212b75867
3 changed files with 29 additions and 16 deletions

View 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;

View File

@ -10,6 +10,14 @@
#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;

View 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);