OSDN Git Service

greybus: endo: record AP interface id
authorAlex Elder <elder@linaro.org>
Fri, 22 May 2015 17:56:48 +0000 (12:56 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Sat, 23 May 2015 23:44:45 +0000 (16:44 -0700)
The AP resides in a particular position on an Endo, which is
identified by an interface ID.  (For now we'll assume the AP uses
just one interface.)  Record the this AP interface ID when creating
an Endo.  Add a sysfs attribute to display it as well.

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

index 7bfdbad..223c396 100644 (file)
@@ -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);
index 72037ff..7128a04 100644 (file)
@@ -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);
index c1ccbcd..01ef5c8 100644 (file)
@@ -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);