diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 7bfdbadb6250..223c396c9992 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -178,7 +178,8 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver { struct greybus_host_device *hd; struct gb_endo *endo; - u16 endo_id = 0x4755; // FIXME - get endo "ID" from the SVC + u16 endo_id = 0x4755; // FIXME - get endo "ID" from the SVC + u8 ap_intf_id = 0x01; // FIXME - get AP interface ID from the SVC /* * Validate that the driver implements all of the callbacks @@ -212,7 +213,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver ida_init(&hd->cport_id_map); hd->buffer_size_max = buffer_size_max; - endo = gb_endo_create(hd, endo_id); + endo = gb_endo_create(hd, endo_id, ap_intf_id); if (IS_ERR(endo)) { greybus_remove_hd(hd); return ERR_CAST(endo); diff --git a/drivers/staging/greybus/endo.c b/drivers/staging/greybus/endo.c index 72037fff2c31..7128a0478cd3 100644 --- a/drivers/staging/greybus/endo.c +++ b/drivers/staging/greybus/endo.c @@ -82,8 +82,18 @@ static ssize_t endo_id_show(struct device *dev, } static DEVICE_ATTR_RO(endo_id); +static ssize_t ap_intf_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gb_endo *endo = to_gb_endo(dev); + + return sprintf(buf, "0x%02x", endo->ap_intf_id); +} +static DEVICE_ATTR_RO(ap_intf_id); + static struct attribute *endo_attrs[] = { &dev_attr_endo_id.attr, + &dev_attr_ap_intf_id.attr, NULL, }; @@ -452,7 +462,8 @@ static int gb_endo_register(struct greybus_host_device *hd, return retval; } -struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) +struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id, + u8 ap_intf_id) { struct gb_endo *endo; int retval; @@ -466,8 +477,12 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) retval = -EINVAL; goto free_endo; } - + if (ap_intf_id > max_endo_interface_id(&endo->layout)) { + retval = -EINVAL; + goto free_endo; + } endo->id = endo_id; + endo->ap_intf_id = ap_intf_id; /* Register Endo device */ retval = gb_endo_register(hd, endo); diff --git a/drivers/staging/greybus/endo.h b/drivers/staging/greybus/endo.h index c1ccbcd576f3..01ef5c86bf5a 100644 --- a/drivers/staging/greybus/endo.h +++ b/drivers/staging/greybus/endo.h @@ -40,6 +40,7 @@ struct gb_endo { struct endo_layout layout; struct gb_svc_info svc_info; u16 id; + u8 ap_intf_id; }; #define to_gb_endo(d) container_of(d, struct gb_endo, dev) @@ -47,7 +48,8 @@ struct gb_endo { /* Greybus "private" definitions */ struct greybus_host_device; -struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id); +struct gb_endo *gb_endo_create(struct greybus_host_device *hd, + u16 endo_id, u8 ap_intf_id); void gb_endo_remove(struct gb_endo *endo); u8 endo_get_module_id(struct gb_endo *endo, u8 interface_id);