static void svc_management(struct svc_function_unipro_management *management,
int payload_length, struct greybus_host_device *hd)
{
- struct gb_module *module;
+ struct gb_interface_block *gb_ib;
int ret;
if (payload_length != sizeof(*management)) {
hd->device_id = management->ap_id.device_id;
break;
case SVC_MANAGEMENT_LINK_UP:
- module = gb_module_find(hd, management->link_up.module_id);
- if (!module) {
+ gb_ib = gb_ib_find(hd, management->link_up.module_id);
+ if (!gb_ib) {
dev_err(hd->parent, "Module ID %d not found\n",
management->link_up.module_id);
return;
}
- ret = gb_interface_init(module,
+ ret = gb_interface_init(gb_ib,
management->link_up.interface_id,
management->link_up.device_id);
if (ret)
dev_err(hd->parent, "error %d initializing "
- "module %hhu interface %hhu\n",
+ "interface block %hhu interface %hhu\n",
ret, management->link_up.module_id,
management->link_up.interface_id);
break;
b->num_properties = ARRAY_SIZE(battery_props),
b->get_property = get_property,
- retval = power_supply_register(&connection->interface->gmod->dev, b);
+ retval = power_supply_register(&connection->interface->gb_ib->dev, b);
if (retval) {
kfree(gb);
return retval;
return NULL;
}
- hd = interface->gmod->hd;
+ hd = interface->gb_ib->hd;
connection->hd = hd;
if (!gb_connection_hd_cport_id_alloc(connection)) {
gb_protocol_put(connection->protocol);
vaf.va = &args;
pr_err("greybus: [%hhu:%hhu:%hu]: %pV\n",
- connection->interface->gmod->module_id,
+ connection->interface->gb_ib->module_id,
connection->interface->id,
connection->interface_cport_id, &vaf);
static int greybus_module_match(struct device *dev, struct device_driver *drv)
{
struct greybus_driver *driver = to_greybus_driver(drv);
- struct gb_module *gmod = to_gb_module(dev);
+ struct gb_interface_block *gb_ib = to_gb_interface_block(dev);
const struct greybus_module_id *id;
- id = gb_module_match_id(gmod, driver->id_table);
+ id = gb_ib_match_id(gb_ib, driver->id_table);
if (id)
return 1;
/* FIXME - Dynamic ids? */
static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env)
{
- struct gb_module *gmod = NULL;
+ struct gb_interface_block *gb_ib = NULL;
struct gb_interface *interface = NULL;
struct gb_connection *connection = NULL;
- if (is_gb_module(dev)) {
- gmod = to_gb_module(dev);
+ if (is_gb_interface_block(dev)) {
+ gb_ib = to_gb_interface_block(dev);
} else if (is_gb_interface(dev)) {
interface = to_gb_interface(dev);
- gmod = interface->gmod;
+ gb_ib = interface->gb_ib;
} else if (is_gb_connection(dev)) {
connection = to_gb_connection(dev);
interface = connection->interface;
- gmod = interface->gmod;
+ gb_ib = interface->gb_ib;
} else {
dev_WARN(dev, "uevent for unknown greybus device \"type\"!\n");
return -EINVAL;
static int greybus_probe(struct device *dev)
{
struct greybus_driver *driver = to_greybus_driver(dev->driver);
- struct gb_module *gmod = to_gb_module(dev);
+ struct gb_interface_block *gb_ib = to_gb_interface_block(dev);
const struct greybus_module_id *id;
int retval;
/* match id */
- id = gb_module_match_id(gmod, driver->id_table);
+ id = gb_ib_match_id(gb_ib, driver->id_table);
if (!id)
return -ENODEV;
- retval = driver->probe(gmod, id);
+ retval = driver->probe(gb_ib, id);
if (retval)
return retval;
static int greybus_remove(struct device *dev)
{
struct greybus_driver *driver = to_greybus_driver(dev->driver);
- struct gb_module *gmod = to_gb_module(dev);
+ struct gb_interface_block *gb_ib = to_gb_interface_block(dev);
- driver->disconnect(gmod);
+ driver->disconnect(gb_ib);
return 0;
}
struct greybus_driver {
const char *name;
- int (*probe)(struct gb_module *gmod,
+ int (*probe)(struct gb_interface_block *gb_ib,
const struct greybus_module_id *id);
- void (*disconnect)(struct gb_module *gmod);
+ void (*disconnect)(struct gb_interface_block *gb_ib);
- int (*suspend)(struct gb_module *gmod, pm_message_t message);
- int (*resume)(struct gb_module *gmod);
+ int (*suspend)(struct gb_interface_block *gb_ib, pm_message_t message);
+ int (*resume)(struct gb_interface_block *gb_ib);
const struct greybus_module_id *id_table;
int svc_set_route_send(struct gb_interface *interface,
struct greybus_host_device *hd);
-extern struct device_type greybus_module_type;
+extern struct device_type greybus_interface_block_type;
extern struct device_type greybus_interface_type;
extern struct device_type greybus_connection_type;
-static inline int is_gb_module(const struct device *dev)
+static inline int is_gb_interface_block(const struct device *dev)
{
- return dev->type == &greybus_module_type;
+ return dev->type == &greybus_interface_block_type;
}
static inline int is_gb_interface(const struct device *dev)
* pointer if a failure occurs due to memory exhaustion.
*/
struct gb_interface *
-gb_interface_create(struct gb_module *gmod, u8 interface_id)
+gb_interface_create(struct gb_interface_block *gb_ib, u8 interface_id)
{
struct gb_interface *interface;
int retval;
if (!interface)
return NULL;
- interface->gmod = gmod;
+ interface->gb_ib = gb_ib;
interface->id = interface_id;
interface->device_id = 0xff; /* Invalid device id to start with */
INIT_LIST_HEAD(&interface->connections);
/* Build up the interface device structures and register it with the
* driver core */
- interface->dev.parent = &gmod->dev;
+ interface->dev.parent = &gb_ib->dev;
interface->dev.bus = &greybus_bus_type;
interface->dev.type = &greybus_interface_type;
interface->dev.groups = interface_groups;
device_initialize(&interface->dev);
- dev_set_name(&interface->dev, "%d:%d", gmod->module_id, interface_id);
+ dev_set_name(&interface->dev, "%d:%d", gb_ib->module_id, interface_id);
retval = device_add(&interface->dev);
if (retval) {
}
spin_lock_irq(&gb_interfaces_lock);
- list_add_tail(&interface->links, &gmod->interfaces);
+ list_add_tail(&interface->links, &gb_ib->interfaces);
spin_unlock_irq(&gb_interfaces_lock);
return interface;
/*
* Tear down a previously set up interface.
*/
-void gb_interface_destroy(struct gb_module *gmod)
+void gb_interface_destroy(struct gb_interface_block *gb_ib)
{
struct gb_interface *interface;
struct gb_interface *temp;
- if (WARN_ON(!gmod))
+ if (WARN_ON(!gb_ib))
return;
spin_lock_irq(&gb_interfaces_lock);
- list_for_each_entry_safe(interface, temp, &gmod->interfaces, links) {
+ list_for_each_entry_safe(interface, temp, &gb_ib->interfaces, links) {
list_del(&interface->links);
gb_interface_connections_exit(interface);
device_del(&interface->dev);
spin_unlock_irq(&gb_interfaces_lock);
}
-int gb_interface_init(struct gb_module *gmod, u8 interface_id, u8 device_id)
+int gb_interface_init(struct gb_interface_block *gb_ib, u8 interface_id, u8 device_id)
{
struct gb_interface *interface;
int ret;
- interface = gb_interface_find(gmod, interface_id);
+ interface = gb_interface_find(gb_ib, interface_id);
if (!interface) {
- dev_err(gmod->hd->parent, "module %hhu not found\n",
+ dev_err(gb_ib->hd->parent, "module %hhu not found\n",
interface_id);
return -ENOENT;
}
interface->device_id = device_id;
- ret = svc_set_route_send(interface, gmod->hd);
+ ret = svc_set_route_send(interface, gb_ib->hd);
if (ret) {
- dev_err(gmod->hd->parent, "failed to set route (%d)\n", ret);
+ dev_err(gb_ib->hd->parent, "failed to set route (%d)\n", ret);
return ret;
}
ret = gb_interface_connections_init(interface);
if (ret) {
- dev_err(gmod->hd->parent, "module interface init error %d\n",
+ dev_err(gb_ib->hd->parent, "module interface init error %d\n",
ret);
/* XXX clear route */
return ret;
return 0;
}
-struct gb_interface *gb_interface_find(struct gb_module *module,
+struct gb_interface *gb_interface_find(struct gb_interface_block *gb_ib,
u8 interface_id)
{
struct gb_interface *interface;
spin_lock_irq(&gb_interfaces_lock);
- list_for_each_entry(interface, &module->interfaces, links)
+ list_for_each_entry(interface, &gb_ib->interfaces, links)
if (interface->id == interface_id) {
spin_unlock_irq(&gb_interfaces_lock);
return interface;
struct gb_interface {
struct device dev;
- struct gb_module *gmod;
+ struct gb_interface_block *gb_ib;
u8 id;
u8 device_id;
struct list_head connections;
};
#define to_gb_interface(d) container_of(d, struct gb_interface, dev)
-struct gb_interface *gb_interface_create(struct gb_module *gmod, u8 module_id);
-void gb_interface_destroy(struct gb_module *gmod);
-int gb_interface_init(struct gb_module *gmod, u8 module_id, u8 device_id);
+struct gb_interface *gb_interface_create(struct gb_interface_block *gb_ib, u8 module_id);
+void gb_interface_destroy(struct gb_interface_block *gb_ib);
+int gb_interface_init(struct gb_interface_block *gb_ib, u8 module_id, u8 device_id);
-struct gb_interface *gb_interface_find(struct gb_module *gmod, u8 interface_id);
+struct gb_interface *gb_interface_find(struct gb_interface_block *gb_ib, u8 interface_id);
int gb_interface_connections_init(struct gb_interface *interface);
void gb_interface_connections_exit(struct gb_interface *interface);
/* XXX This could be per-host device */
static DEFINE_SPINLOCK(gb_modules_lock);
-static int gb_module_match_one_id(struct gb_module *gmod,
+static int gb_module_match_one_id(struct gb_interface_block *gb_ib,
const struct greybus_module_id *id)
{
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_VENDOR) &&
- (id->vendor != gmod->vendor))
+ (id->vendor != gb_ib->vendor))
return 0;
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_PRODUCT) &&
- (id->product != gmod->product))
+ (id->product != gb_ib->product))
return 0;
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_SERIAL) &&
- (id->unique_id != gmod->unique_id))
+ (id->unique_id != gb_ib->unique_id))
return 0;
return 1;
}
-const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod,
+const struct greybus_module_id *gb_ib_match_id(struct gb_interface_block *gb_ib,
const struct greybus_module_id *id)
{
if (id == NULL)
for (; id->vendor || id->product || id->unique_id ||
id->driver_info; id++) {
- if (gb_module_match_one_id(gmod, id))
+ if (gb_module_match_one_id(gb_ib, id))
return id;
}
return NULL;
}
-struct gb_module *gb_module_find(struct greybus_host_device *hd, u8 module_id)
+struct gb_interface_block *gb_ib_find(struct greybus_host_device *hd, u8 module_id)
{
- struct gb_module *module;
+ struct gb_interface_block *gb_ib;
- list_for_each_entry(module, &hd->modules, links)
- if (module->module_id == module_id)
- return module;
+ list_for_each_entry(gb_ib, &hd->modules, links)
+ if (gb_ib->module_id == module_id)
+ return gb_ib;
return NULL;
}
-static void greybus_module_release(struct device *dev)
+static void greybus_ib_release(struct device *dev)
{
- struct gb_module *gmod = to_gb_module(dev);
+ struct gb_interface_block *gb_ib = to_gb_interface_block(dev);
- kfree(gmod);
+ kfree(gb_ib);
}
-struct device_type greybus_module_type = {
- .name = "greybus_module",
- .release = greybus_module_release,
+struct device_type greybus_interface_block_type = {
+ .name = "greybus_interface_block",
+ .release = greybus_ib_release,
};
/*
* A Greybus module represents a user-replicable component on an Ara
- * phone.
+ * phone. An interface block is the physical connection on that module. A
+ * module may have more than one interface block.
*
- * Create a gb_module structure to represent a discovered module.
+ * Create a gb_interface_block structure to represent a discovered module.
* The position within the Endo is encoded in the "module_id" argument.
* Returns a pointer to the new module or a null pointer if a
* failure occurs due to memory exhaustion.
*/
-struct gb_module *gb_module_create(struct greybus_host_device *hd, u8 module_id)
+static struct gb_interface_block *gb_ib_create(struct greybus_host_device *hd,
+ u8 module_id)
{
- struct gb_module *gmod;
+ struct gb_interface_block *gb_ib;
int retval;
- gmod = gb_module_find(hd, module_id);
- if (gmod) {
+ gb_ib = gb_ib_find(hd, module_id);
+ if (gb_ib) {
dev_err(hd->parent, "Duplicate module id %d will not be created\n",
module_id);
return NULL;
}
- gmod = kzalloc(sizeof(*gmod), GFP_KERNEL);
- if (!gmod)
+ gb_ib = kzalloc(sizeof(*gb_ib), GFP_KERNEL);
+ if (!gb_ib)
return NULL;
- gmod->hd = hd; /* XXX refcount? */
- gmod->module_id = module_id;
- INIT_LIST_HEAD(&gmod->interfaces);
+ gb_ib->hd = hd; /* XXX refcount? */
+ gb_ib->module_id = module_id;
+ INIT_LIST_HEAD(&gb_ib->interfaces);
- gmod->dev.parent = hd->parent;
- gmod->dev.bus = &greybus_bus_type;
- gmod->dev.type = &greybus_module_type;
- gmod->dev.groups = greybus_module_groups;
- gmod->dev.dma_mask = hd->parent->dma_mask;
- device_initialize(&gmod->dev);
- dev_set_name(&gmod->dev, "%d", module_id);
+ gb_ib->dev.parent = hd->parent;
+ gb_ib->dev.bus = &greybus_bus_type;
+ gb_ib->dev.type = &greybus_interface_block_type;
+ gb_ib->dev.groups = greybus_module_groups;
+ gb_ib->dev.dma_mask = hd->parent->dma_mask;
+ device_initialize(&gb_ib->dev);
+ dev_set_name(&gb_ib->dev, "%d", module_id);
- retval = device_add(&gmod->dev);
+ retval = device_add(&gb_ib->dev);
if (retval) {
pr_err("failed to add module device for id 0x%02hhx\n",
module_id);
- put_device(&gmod->dev);
- kfree(gmod);
+ put_device(&gb_ib->dev);
+ kfree(gb_ib);
return NULL;
}
spin_lock_irq(&gb_modules_lock);
- list_add_tail(&gmod->links, &hd->modules);
+ list_add_tail(&gb_ib->links, &hd->modules);
spin_unlock_irq(&gb_modules_lock);
- return gmod;
+ return gb_ib;
}
/*
* Tear down a previously set up module.
*/
-void gb_module_destroy(struct gb_module *gmod)
+static void gb_ib_destroy(struct gb_interface_block *gb_ib)
{
- if (WARN_ON(!gmod))
+ if (WARN_ON(!gb_ib))
return;
spin_lock_irq(&gb_modules_lock);
- list_del(&gmod->links);
+ list_del(&gb_ib->links);
spin_unlock_irq(&gb_modules_lock);
- gb_interface_destroy(gmod);
+ gb_interface_destroy(gb_ib);
- kfree(gmod->product_string);
- kfree(gmod->vendor_string);
+ kfree(gb_ib->product_string);
+ kfree(gb_ib->vendor_string);
/* kref_put(module->hd); */
- device_del(&gmod->dev);
+ device_del(&gb_ib->dev);
}
/**
void gb_add_module(struct greybus_host_device *hd, u8 module_id,
u8 *data, int size)
{
- struct gb_module *gmod;
+ struct gb_interface_block *gb_ib;
- gmod = gb_module_create(hd, module_id);
- if (!gmod) {
- dev_err(hd->parent, "failed to create module\n");
+ gb_ib = gb_ib_create(hd, module_id);
+ if (!gb_ib) {
+ dev_err(hd->parent, "failed to create interface block\n");
return;
}
* Parse the manifest and build up our data structures
* representing what's in it.
*/
- if (!gb_manifest_parse(gmod, data, size)) {
+ if (!gb_manifest_parse(gb_ib, data, size)) {
dev_err(hd->parent, "manifest error\n");
goto err_module;
}
return;
err_module:
- gb_module_destroy(gmod);
+ gb_ib_destroy(gb_ib);
}
void gb_remove_module(struct greybus_host_device *hd, u8 module_id)
{
- struct gb_module *gmod = gb_module_find(hd, module_id);
+ struct gb_interface_block *gb_ib = gb_ib_find(hd, module_id);
- if (gmod)
- gb_module_destroy(gmod);
+ if (gb_ib)
+ gb_ib_destroy(gb_ib);
else
- dev_err(hd->parent, "module id %d not found\n", module_id);
+ dev_err(hd->parent, "interface block id %d not found\n", module_id);
}
void gb_remove_modules(struct greybus_host_device *hd)
{
- struct gb_module *gmod, *temp;
+ struct gb_interface_block *gb_ib, *temp;
- list_for_each_entry_safe(gmod, temp, &hd->modules, links)
- gb_module_destroy(gmod);
+ list_for_each_entry_safe(gb_ib, temp, &hd->modules, links)
+ gb_ib_destroy(gb_ib);
}
/*
- * Greybus modules
+ * Greybus Interface Block code
*
* Copyright 2014 Google Inc.
*
* Released under the GPLv2 only.
*/
-#ifndef __MODULE_H
-#define __MODULE_H
+#ifndef __INTERFACE_BLOCK_H
+#define __INTERFACE_BLOCK_H
/* Increase these values if needed */
#define MAX_CPORTS_PER_MODULE 10
#define MAX_STRINGS_PER_MODULE 10
-struct gb_module {
+
+/* Greybus "public" definitions" */
+struct gb_interface_block {
struct device dev;
struct list_head interfaces;
struct greybus_host_device *hd;
};
-#define to_gb_module(d) container_of(d, struct gb_module, dev)
+#define to_gb_interface_block(d) container_of(d, struct gb_interface_block, dev)
static inline void
-gb_module_set_drvdata(struct gb_module *gmod, void *data)
+gb_interface_block_set_drvdata(struct gb_interface_block *gb_ib, void *data)
{
- dev_set_drvdata(&gmod->dev, data);
+ dev_set_drvdata(&gb_ib->dev, data);
}
-static inline void *gb_module_get_drvdata(struct gb_module *gmod)
+static inline void *
+gb_interface_block_get_drvdata(struct gb_interface_block *gb_ib)
{
- return dev_get_drvdata(&gmod->dev);
+ return dev_get_drvdata(&gb_ib->dev);
}
-const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod,
- const struct greybus_module_id *id);
+/* Greybus "private" definitions */
-struct gb_module *gb_module_create(struct greybus_host_device *hd,
- u8 module_id);
-void gb_module_destroy(struct gb_module *module);
+const struct greybus_module_id *gb_ib_match_id(struct gb_interface_block *gb_ib,
+ const struct greybus_module_id *id);
-struct gb_module *gb_module_find(struct greybus_host_device *hd,
- u8 module_id);
+struct gb_interface_block *gb_ib_find(struct greybus_host_device *hd,
+ u8 module_id);
-#endif /* __MODULE_H */
+#endif /* __INTERFACE_BLOCK_H */
* structures. Returns the number of interfaces set up for the
* given module.
*/
-static u32 gb_manifest_parse_interfaces(struct gb_module *gmod)
+static u32 gb_manifest_parse_interfaces(struct gb_interface_block *gb_ib)
{
u32 count = 0;
/* Found one. Set up its interface structure*/
desc_interface = descriptor->data;
- interface = gb_interface_create(gmod, desc_interface->id);
+ interface = gb_interface_create(gb_ib, desc_interface->id);
if (!interface)
return 0; /* Error */
return count;
}
-static bool gb_manifest_parse_module(struct gb_module *gmod,
+static bool gb_manifest_parse_module(struct gb_interface_block *gb_ib,
struct manifest_desc *module_desc)
{
struct greybus_descriptor_module *desc_module = module_desc->data;
/* Handle the strings first--they can fail */
- gmod->vendor_string = gb_string_get(desc_module->vendor_stringid);
- if (IS_ERR(gmod->vendor_string))
+ gb_ib->vendor_string = gb_string_get(desc_module->vendor_stringid);
+ if (IS_ERR(gb_ib->vendor_string))
return false;
- gmod->product_string = gb_string_get(desc_module->product_stringid);
- if (IS_ERR(gmod->product_string)) {
+ gb_ib->product_string = gb_string_get(desc_module->product_stringid);
+ if (IS_ERR(gb_ib->product_string)) {
goto out_free_vendor_string;
}
- gmod->vendor = le16_to_cpu(desc_module->vendor);
- gmod->product = le16_to_cpu(desc_module->product);
- gmod->unique_id = le64_to_cpu(desc_module->unique_id);
+ gb_ib->vendor = le16_to_cpu(desc_module->vendor);
+ gb_ib->product = le16_to_cpu(desc_module->product);
+ gb_ib->unique_id = le64_to_cpu(desc_module->unique_id);
/* Release the module descriptor, now that we're done with it */
release_manifest_descriptor(module_desc);
/* A module must have at least one interface descriptor */
- if (!gb_manifest_parse_interfaces(gmod)) {
+ if (!gb_manifest_parse_interfaces(gb_ib)) {
pr_err("manifest interface descriptors not valid\n");
goto out_err;
}
return true;
out_err:
- kfree(gmod->product_string);
- gmod->product_string = NULL;
+ kfree(gb_ib->product_string);
+ gb_ib->product_string = NULL;
out_free_vendor_string:
- kfree(gmod->vendor_string);
- gmod->vendor_string = NULL;
+ kfree(gb_ib->vendor_string);
+ gb_ib->vendor_string = NULL;
return false;
}
*
* Returns true if parsing was successful, false otherwise.
*/
-bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size)
+bool gb_manifest_parse(struct gb_interface_block *gb_ib, void *data, size_t size)
{
struct greybus_manifest *manifest;
struct greybus_manifest_header *header;
}
/* Parse the module manifest, starting with the module descriptor */
- result = gb_manifest_parse_module(gmod, module_desc);
+ result = gb_manifest_parse_module(gb_ib, module_desc);
/*
* We really should have no remaining descriptors, but we
#ifndef __MANIFEST_H
#define __MANIFEST_H
-struct gb_module;
-bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size);
+struct gb_interface_block;
+bool gb_manifest_parse(struct gb_interface_block *gb_ib, void *data, size_t size);
#endif /* __MANIFEST_H */
struct device_attribute *attr, \
char *buf) \
{ \
- struct gb_module *gmod = to_gb_module(dev); \
- return sprintf(buf, "%"#type"\n", gmod->field); \
+ struct gb_interface_block *gb_ib = to_gb_interface_block(dev); \
+ return sprintf(buf, "%"#type"\n", gb_ib->field); \
} \
static DEVICE_ATTR_RO(module_##field)