Commit 4ec7b079 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

greybus: interface_block: s/gb_module/gb_interface_block/

Rename struct gb_module to struct gb_interface_block

It's a complex rename, some functions got their name changed where
needed, but primarily this change is focused on the structure and where
it is used.  Future changes will clean up the remaining usages of the
term "module" in individual changes, this one spanned the whole
subsystem so do it all at once.
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent e5052220
...@@ -123,7 +123,7 @@ static void svc_handshake(struct svc_function_handshake *handshake, ...@@ -123,7 +123,7 @@ static void svc_handshake(struct svc_function_handshake *handshake,
static void svc_management(struct svc_function_unipro_management *management, static void svc_management(struct svc_function_unipro_management *management,
int payload_length, struct greybus_host_device *hd) int payload_length, struct greybus_host_device *hd)
{ {
struct gb_module *module; struct gb_interface_block *gb_ib;
int ret; int ret;
if (payload_length != sizeof(*management)) { if (payload_length != sizeof(*management)) {
...@@ -138,18 +138,18 @@ static void svc_management(struct svc_function_unipro_management *management, ...@@ -138,18 +138,18 @@ static void svc_management(struct svc_function_unipro_management *management,
hd->device_id = management->ap_id.device_id; hd->device_id = management->ap_id.device_id;
break; break;
case SVC_MANAGEMENT_LINK_UP: case SVC_MANAGEMENT_LINK_UP:
module = gb_module_find(hd, management->link_up.module_id); gb_ib = gb_ib_find(hd, management->link_up.module_id);
if (!module) { if (!gb_ib) {
dev_err(hd->parent, "Module ID %d not found\n", dev_err(hd->parent, "Module ID %d not found\n",
management->link_up.module_id); management->link_up.module_id);
return; return;
} }
ret = gb_interface_init(module, ret = gb_interface_init(gb_ib,
management->link_up.interface_id, management->link_up.interface_id,
management->link_up.device_id); management->link_up.device_id);
if (ret) if (ret)
dev_err(hd->parent, "error %d initializing " dev_err(hd->parent, "error %d initializing "
"module %hhu interface %hhu\n", "interface block %hhu interface %hhu\n",
ret, management->link_up.module_id, ret, management->link_up.module_id,
management->link_up.interface_id); management->link_up.interface_id);
break; break;
......
...@@ -340,7 +340,7 @@ static int gb_battery_connection_init(struct gb_connection *connection) ...@@ -340,7 +340,7 @@ static int gb_battery_connection_init(struct gb_connection *connection)
b->num_properties = ARRAY_SIZE(battery_props), b->num_properties = ARRAY_SIZE(battery_props),
b->get_property = get_property, 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) { if (retval) {
kfree(gb); kfree(gb);
return retval; return retval;
......
...@@ -155,7 +155,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, ...@@ -155,7 +155,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
return NULL; return NULL;
} }
hd = interface->gmod->hd; hd = interface->gb_ib->hd;
connection->hd = hd; connection->hd = hd;
if (!gb_connection_hd_cport_id_alloc(connection)) { if (!gb_connection_hd_cport_id_alloc(connection)) {
gb_protocol_put(connection->protocol); gb_protocol_put(connection->protocol);
...@@ -236,7 +236,7 @@ void gb_connection_err(struct gb_connection *connection, const char *fmt, ...) ...@@ -236,7 +236,7 @@ void gb_connection_err(struct gb_connection *connection, const char *fmt, ...)
vaf.va = &args; vaf.va = &args;
pr_err("greybus: [%hhu:%hhu:%hu]: %pV\n", pr_err("greybus: [%hhu:%hhu:%hu]: %pV\n",
connection->interface->gmod->module_id, connection->interface->gb_ib->module_id,
connection->interface->id, connection->interface->id,
connection->interface_cport_id, &vaf); connection->interface_cport_id, &vaf);
......
...@@ -33,10 +33,10 @@ EXPORT_SYMBOL_GPL(greybus_disabled); ...@@ -33,10 +33,10 @@ EXPORT_SYMBOL_GPL(greybus_disabled);
static int greybus_module_match(struct device *dev, struct device_driver *drv) static int greybus_module_match(struct device *dev, struct device_driver *drv)
{ {
struct greybus_driver *driver = to_greybus_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; 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) if (id)
return 1; return 1;
/* FIXME - Dynamic ids? */ /* FIXME - Dynamic ids? */
...@@ -45,19 +45,19 @@ static int greybus_module_match(struct device *dev, struct device_driver *drv) ...@@ -45,19 +45,19 @@ static int greybus_module_match(struct device *dev, struct device_driver *drv)
static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env) 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_interface *interface = NULL;
struct gb_connection *connection = NULL; struct gb_connection *connection = NULL;
if (is_gb_module(dev)) { if (is_gb_interface_block(dev)) {
gmod = to_gb_module(dev); gb_ib = to_gb_interface_block(dev);
} else if (is_gb_interface(dev)) { } else if (is_gb_interface(dev)) {
interface = to_gb_interface(dev); interface = to_gb_interface(dev);
gmod = interface->gmod; gb_ib = interface->gb_ib;
} else if (is_gb_connection(dev)) { } else if (is_gb_connection(dev)) {
connection = to_gb_connection(dev); connection = to_gb_connection(dev);
interface = connection->interface; interface = connection->interface;
gmod = interface->gmod; gb_ib = interface->gb_ib;
} else { } else {
dev_WARN(dev, "uevent for unknown greybus device \"type\"!\n"); dev_WARN(dev, "uevent for unknown greybus device \"type\"!\n");
return -EINVAL; return -EINVAL;
...@@ -93,16 +93,16 @@ struct bus_type greybus_bus_type = { ...@@ -93,16 +93,16 @@ struct bus_type greybus_bus_type = {
static int greybus_probe(struct device *dev) static int greybus_probe(struct device *dev)
{ {
struct greybus_driver *driver = to_greybus_driver(dev->driver); 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; const struct greybus_module_id *id;
int retval; int retval;
/* match id */ /* match id */
id = gb_module_match_id(gmod, driver->id_table); id = gb_ib_match_id(gb_ib, driver->id_table);
if (!id) if (!id)
return -ENODEV; return -ENODEV;
retval = driver->probe(gmod, id); retval = driver->probe(gb_ib, id);
if (retval) if (retval)
return retval; return retval;
...@@ -112,9 +112,9 @@ static int greybus_probe(struct device *dev) ...@@ -112,9 +112,9 @@ static int greybus_probe(struct device *dev)
static int greybus_remove(struct device *dev) static int greybus_remove(struct device *dev)
{ {
struct greybus_driver *driver = to_greybus_driver(dev->driver); 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; return 0;
} }
......
...@@ -118,12 +118,12 @@ void greybus_remove_hd(struct greybus_host_device *hd); ...@@ -118,12 +118,12 @@ void greybus_remove_hd(struct greybus_host_device *hd);
struct greybus_driver { struct greybus_driver {
const char *name; const char *name;
int (*probe)(struct gb_module *gmod, int (*probe)(struct gb_interface_block *gb_ib,
const struct greybus_module_id *id); 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 (*suspend)(struct gb_interface_block *gb_ib, pm_message_t message);
int (*resume)(struct gb_module *gmod); int (*resume)(struct gb_interface_block *gb_ib);
const struct greybus_module_id *id_table; const struct greybus_module_id *id_table;
...@@ -175,13 +175,13 @@ void gb_uart_device_exit(struct gb_connection *connection); ...@@ -175,13 +175,13 @@ void gb_uart_device_exit(struct gb_connection *connection);
int svc_set_route_send(struct gb_interface *interface, int svc_set_route_send(struct gb_interface *interface,
struct greybus_host_device *hd); 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_interface_type;
extern struct device_type greybus_connection_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) static inline int is_gb_interface(const struct device *dev)
......
...@@ -52,7 +52,7 @@ static DEFINE_SPINLOCK(gb_interfaces_lock); ...@@ -52,7 +52,7 @@ static DEFINE_SPINLOCK(gb_interfaces_lock);
* pointer if a failure occurs due to memory exhaustion. * pointer if a failure occurs due to memory exhaustion.
*/ */
struct gb_interface * 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; struct gb_interface *interface;
int retval; int retval;
...@@ -61,19 +61,19 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id) ...@@ -61,19 +61,19 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id)
if (!interface) if (!interface)
return NULL; return NULL;
interface->gmod = gmod; interface->gb_ib = gb_ib;
interface->id = interface_id; interface->id = interface_id;
interface->device_id = 0xff; /* Invalid device id to start with */ interface->device_id = 0xff; /* Invalid device id to start with */
INIT_LIST_HEAD(&interface->connections); INIT_LIST_HEAD(&interface->connections);
/* Build up the interface device structures and register it with the /* Build up the interface device structures and register it with the
* driver core */ * driver core */
interface->dev.parent = &gmod->dev; interface->dev.parent = &gb_ib->dev;
interface->dev.bus = &greybus_bus_type; interface->dev.bus = &greybus_bus_type;
interface->dev.type = &greybus_interface_type; interface->dev.type = &greybus_interface_type;
interface->dev.groups = interface_groups; interface->dev.groups = interface_groups;
device_initialize(&interface->dev); 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); retval = device_add(&interface->dev);
if (retval) { if (retval) {
...@@ -85,7 +85,7 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id) ...@@ -85,7 +85,7 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id)
} }
spin_lock_irq(&gb_interfaces_lock); 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); spin_unlock_irq(&gb_interfaces_lock);
return interface; return interface;
...@@ -94,16 +94,16 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id) ...@@ -94,16 +94,16 @@ gb_interface_create(struct gb_module *gmod, u8 interface_id)
/* /*
* Tear down a previously set up 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 *interface;
struct gb_interface *temp; struct gb_interface *temp;
if (WARN_ON(!gmod)) if (WARN_ON(!gb_ib))
return; return;
spin_lock_irq(&gb_interfaces_lock); 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); list_del(&interface->links);
gb_interface_connections_exit(interface); gb_interface_connections_exit(interface);
device_del(&interface->dev); device_del(&interface->dev);
...@@ -111,28 +111,28 @@ void gb_interface_destroy(struct gb_module *gmod) ...@@ -111,28 +111,28 @@ void gb_interface_destroy(struct gb_module *gmod)
spin_unlock_irq(&gb_interfaces_lock); 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; struct gb_interface *interface;
int ret; int ret;
interface = gb_interface_find(gmod, interface_id); interface = gb_interface_find(gb_ib, interface_id);
if (!interface) { 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); interface_id);
return -ENOENT; return -ENOENT;
} }
interface->device_id = device_id; interface->device_id = device_id;
ret = svc_set_route_send(interface, gmod->hd); ret = svc_set_route_send(interface, gb_ib->hd);
if (ret) { 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; return ret;
} }
ret = gb_interface_connections_init(interface); ret = gb_interface_connections_init(interface);
if (ret) { 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); ret);
/* XXX clear route */ /* XXX clear route */
return ret; return ret;
...@@ -141,13 +141,13 @@ int gb_interface_init(struct gb_module *gmod, u8 interface_id, u8 device_id) ...@@ -141,13 +141,13 @@ int gb_interface_init(struct gb_module *gmod, u8 interface_id, u8 device_id)
return 0; 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) u8 interface_id)
{ {
struct gb_interface *interface; struct gb_interface *interface;
spin_lock_irq(&gb_interfaces_lock); 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) { if (interface->id == interface_id) {
spin_unlock_irq(&gb_interfaces_lock); spin_unlock_irq(&gb_interfaces_lock);
return interface; return interface;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
struct gb_interface { struct gb_interface {
struct device dev; struct device dev;
struct gb_module *gmod; struct gb_interface_block *gb_ib;
u8 id; u8 id;
u8 device_id; u8 device_id;
struct list_head connections; struct list_head connections;
...@@ -22,11 +22,11 @@ struct gb_interface { ...@@ -22,11 +22,11 @@ struct gb_interface {
}; };
#define to_gb_interface(d) container_of(d, struct gb_interface, dev) #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); struct gb_interface *gb_interface_create(struct gb_interface_block *gb_ib, u8 module_id);
void gb_interface_destroy(struct gb_module *gmod); void gb_interface_destroy(struct gb_interface_block *gb_ib);
int gb_interface_init(struct gb_module *gmod, u8 module_id, u8 device_id); 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); int gb_interface_connections_init(struct gb_interface *interface);
void gb_interface_connections_exit(struct gb_interface *interface); void gb_interface_connections_exit(struct gb_interface *interface);
......
...@@ -11,25 +11,25 @@ ...@@ -11,25 +11,25 @@
/* XXX This could be per-host device */ /* XXX This could be per-host device */
static DEFINE_SPINLOCK(gb_modules_lock); 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) const struct greybus_module_id *id)
{ {
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_VENDOR) && if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_VENDOR) &&
(id->vendor != gmod->vendor)) (id->vendor != gb_ib->vendor))
return 0; return 0;
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_PRODUCT) && if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_PRODUCT) &&
(id->product != gmod->product)) (id->product != gb_ib->product))
return 0; return 0;
if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_SERIAL) && 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 0;
return 1; 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) const struct greybus_module_id *id)
{ {
if (id == NULL) if (id == NULL)
...@@ -37,108 +37,110 @@ const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod, ...@@ -37,108 +37,110 @@ const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod,
for (; id->vendor || id->product || id->unique_id || for (; id->vendor || id->product || id->unique_id ||
id->driver_info; 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 id;
} }
return NULL; 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) list_for_each_entry(gb_ib, &hd->modules, links)
if (module->module_id == module_id) if (gb_ib->module_id == module_id)
return module; return gb_ib;
return NULL; 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 = { struct device_type greybus_interface_block_type = {
.name = "greybus_module", .name = "greybus_interface_block",
.release = greybus_module_release, .release = greybus_ib_release,
}; };
/* /*
* A Greybus module represents a user-replicable component on an Ara * 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. * 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 * Returns a pointer to the new module or a null pointer if a
* failure occurs due to memory exhaustion. * 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; int retval;
gmod = gb_module_find(hd, module_id); gb_ib = gb_ib_find(hd, module_id);
if (gmod) { if (gb_ib) {
dev_err(hd->parent, "Duplicate module id %d will not be created\n", dev_err(hd->parent, "Duplicate module id %d will not be created\n",
module_id); module_id);
return NULL; return NULL;
} }
gmod = kzalloc(sizeof(*gmod), GFP_KERNEL); gb_ib = kzalloc(sizeof(*gb_ib), GFP_KERNEL);
if (!gmod) if (!gb_ib)
return NULL; return NULL;
gmod->hd = hd; /* XXX refcount? */ gb_ib->hd = hd; /* XXX refcount? */
gmod->module_id = module_id; gb_ib->module_id = module_id;
INIT_LIST_HEAD(&gmod->interfaces); INIT_LIST_HEAD(&gb_ib->interfaces);
gmod->dev.parent = hd->parent; gb_ib->dev.parent = hd->parent;
gmod->dev.bus = &greybus_bus_type; gb_ib->dev.bus = &greybus_bus_type;
gmod->dev.type = &greybus_module_type; gb_ib->dev.type = &greybus_interface_block_type;
gmod->dev.groups = greybus_module_groups; gb_ib->dev.groups = greybus_module_groups;
gmod->dev.dma_mask = hd->parent->dma_mask; gb_ib->dev.dma_mask = hd->parent->dma_mask;
device_initialize(&gmod->dev); device_initialize(&gb_ib->dev);
dev_set_name(&gmod->dev, "%d", module_id); dev_set_name(&gb_ib->dev, "%d", module_id);
retval = device_add(&gmod->dev); retval = device_add(&gb_ib->dev);
if (retval) { if (retval) {
pr_err("failed to add module device for id 0x%02hhx\n", pr_err("failed to add module device for id 0x%02hhx\n",
module_id); module_id);
put_device(&gmod->dev); put_device(&gb_ib->dev);
kfree(gmod); kfree(gb_ib);
return NULL; return NULL;
} }
spin_lock_irq(&gb_modules_lock); 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); spin_unlock_irq(&gb_modules_lock);
return gmod; return gb_ib;
} }
/* /*
* Tear down a previously set up module. * 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; return;
spin_lock_irq(&gb_modules_lock); spin_lock_irq(&gb_modules_lock);
list_del(&gmod->links); list_del(&gb_ib->links);
spin_unlock_irq(&gb_modules_lock); spin_unlock_irq(&gb_modules_lock);
gb_interface_destroy(gmod); gb_interface_destroy(gb_ib);
kfree(gmod->product_string); kfree(gb_ib->product_string);
kfree(gmod->vendor_string); kfree(gb_ib->vendor_string);
/* kref_put(module->hd); */ /* kref_put(module->hd); */
device_del(&gmod->dev); device_del(&gb_ib->dev);
} }
/** /**
...@@ -150,11 +152,11 @@ void gb_module_destroy(struct gb_module *gmod) ...@@ -150,11 +152,11 @@ void gb_module_destroy(struct gb_module *gmod)
void gb_add_module(struct greybus_host_device *hd, u8 module_id, void gb_add_module(struct greybus_host_device *hd, u8 module_id,
u8 *data, int size) u8 *data, int size)
{ {
struct gb_module *gmod; struct gb_interface_block *gb_ib;
gmod = gb_module_create(hd, module_id); gb_ib = gb_ib_create(hd, module_id);
if (!gmod) { if (!gb_ib) {
dev_err(hd->parent, "failed to create module\n"); dev_err(hd->parent, "failed to create interface block\n");
return; return;
} }
...@@ -162,7 +164,7 @@ void gb_add_module(struct greybus_host_device *hd, u8 module_id, ...@@ -162,7 +164,7 @@ void gb_add_module(struct greybus_host_device *hd, u8 module_id,
* Parse the manifest and build up our data structures * Parse the manifest and build up our data structures
* representing what's in it. * 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"); dev_err(hd->parent, "manifest error\n");
goto err_module; goto err_module;
} }
...@@ -179,23 +181,23 @@ void gb_add_module(struct greybus_host_device *hd, u8 module_id, ...@@ -179,23 +181,23 @@ void gb_add_module(struct greybus_host_device *hd, u8 module_id,
return; return;
err_module: err_module:
gb_module_destroy(gmod); gb_ib_destroy(gb_ib);
} }
void gb_remove_module(struct greybus_host_device *hd, u8 module_id) 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) if (gb_ib)
gb_module_destroy(gmod); gb_ib_destroy(gb_ib);
else 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) 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) list_for_each_entry_safe(gb_ib, temp, &hd->modules, links)
gb_module_destroy(gmod); gb_ib_destroy(gb_ib);
} }
/* /*
* Greybus modules * Greybus Interface Block code
* *
* Copyright 2014 Google Inc. * Copyright 2014 Google Inc.
* *
* Released under the GPLv2 only. * Released under the GPLv2 only.
*/ */
#ifndef __MODULE_H #ifndef __INTERFACE_BLOCK_H
#define __MODULE_H #define __INTERFACE_BLOCK_H
/* Increase these values if needed */ /* Increase these values if needed */
#define MAX_CPORTS_PER_MODULE 10 #define MAX_CPORTS_PER_MODULE 10
#define MAX_STRINGS_PER_MODULE 10 #define MAX_STRINGS_PER_MODULE 10
struct gb_module {
/* Greybus "public" definitions" */
struct gb_interface_block {
struct device dev; struct device dev;
struct list_head interfaces; struct list_head interfaces;
...@@ -29,27 +31,26 @@ struct gb_module { ...@@ -29,27 +31,26 @@ struct gb_module {
struct greybus_host_device *hd; 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 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, /* Greybus "private" definitions */
const struct greybus_module_id *id);
struct gb_module *gb_module_create(struct greybus_host_device *hd, const struct greybus_module_id *gb_ib_match_id(struct gb_interface_block *gb_ib,
u8 module_id); const struct greybus_module_id *id);
void gb_module_destroy(struct gb_module *module);
struct gb_module *gb_module_find(struct greybus_host_device *hd, struct gb_interface_block *gb_ib_find(struct greybus_host_device *hd,
u8 module_id); u8 module_id);
#endif /* __MODULE_H */ #endif /* __INTERFACE_BLOCK_H */
...@@ -217,7 +217,7 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface) ...@@ -217,7 +217,7 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface)
* structures. Returns the number of interfaces set up for the * structures. Returns the number of interfaces set up for the
* given module. * 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; u32 count = 0;
...@@ -239,7 +239,7 @@ static u32 gb_manifest_parse_interfaces(struct gb_module *gmod) ...@@ -239,7 +239,7 @@ static u32 gb_manifest_parse_interfaces(struct gb_module *gmod)
/* Found one. Set up its interface structure*/ /* Found one. Set up its interface structure*/
desc_interface = descriptor->data; desc_interface = descriptor->data;
interface = gb_interface_create(gmod, desc_interface->id); interface = gb_interface_create(gb_ib, desc_interface->id);
if (!interface) if (!interface)
return 0; /* Error */ return 0; /* Error */
...@@ -256,41 +256,41 @@ static u32 gb_manifest_parse_interfaces(struct gb_module *gmod) ...@@ -256,41 +256,41 @@ static u32 gb_manifest_parse_interfaces(struct gb_module *gmod)
return count; 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 manifest_desc *module_desc)
{ {
struct greybus_descriptor_module *desc_module = module_desc->data; struct greybus_descriptor_module *desc_module = module_desc->data;
/* Handle the strings first--they can fail */ /* Handle the strings first--they can fail */
gmod->vendor_string = gb_string_get(desc_module->vendor_stringid); gb_ib->vendor_string = gb_string_get(desc_module->vendor_stringid);
if (IS_ERR(gmod->vendor_string)) if (IS_ERR(gb_ib->vendor_string))
return false; return false;
gmod->product_string = gb_string_get(desc_module->product_stringid); gb_ib->product_string = gb_string_get(desc_module->product_stringid);
if (IS_ERR(gmod->product_string)) { if (IS_ERR(gb_ib->product_string)) {
goto out_free_vendor_string; goto out_free_vendor_string;
} }
gmod->vendor = le16_to_cpu(desc_module->vendor); gb_ib->vendor = le16_to_cpu(desc_module->vendor);
gmod->product = le16_to_cpu(desc_module->product); gb_ib->product = le16_to_cpu(desc_module->product);
gmod->unique_id = le64_to_cpu(desc_module->unique_id); gb_ib->unique_id = le64_to_cpu(desc_module->unique_id);
/* Release the module descriptor, now that we're done with it */ /* Release the module descriptor, now that we're done with it */
release_manifest_descriptor(module_desc); release_manifest_descriptor(module_desc);
/* A module must have at least one interface descriptor */ /* 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"); pr_err("manifest interface descriptors not valid\n");
goto out_err; goto out_err;
} }
return true; return true;
out_err: out_err:
kfree(gmod->product_string); kfree(gb_ib->product_string);
gmod->product_string = NULL; gb_ib->product_string = NULL;
out_free_vendor_string: out_free_vendor_string:
kfree(gmod->vendor_string); kfree(gb_ib->vendor_string);
gmod->vendor_string = NULL; gb_ib->vendor_string = NULL;
return false; return false;
} }
...@@ -318,7 +318,7 @@ static bool gb_manifest_parse_module(struct gb_module *gmod, ...@@ -318,7 +318,7 @@ static bool gb_manifest_parse_module(struct gb_module *gmod,
* *
* Returns true if parsing was successful, false otherwise. * 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 *manifest;
struct greybus_manifest_header *header; struct greybus_manifest_header *header;
...@@ -388,7 +388,7 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size) ...@@ -388,7 +388,7 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size)
} }
/* Parse the module manifest, starting with the module descriptor */ /* 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 * We really should have no remaining descriptors, but we
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef __MANIFEST_H #ifndef __MANIFEST_H
#define __MANIFEST_H #define __MANIFEST_H
struct gb_module; struct gb_interface_block;
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);
#endif /* __MANIFEST_H */ #endif /* __MANIFEST_H */
...@@ -25,8 +25,8 @@ static ssize_t module_##field##_show(struct device *dev, \ ...@@ -25,8 +25,8 @@ static ssize_t module_##field##_show(struct device *dev, \
struct device_attribute *attr, \ struct device_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
struct gb_module *gmod = to_gb_module(dev); \ struct gb_interface_block *gb_ib = to_gb_interface_block(dev); \
return sprintf(buf, "%"#type"\n", gmod->field); \ return sprintf(buf, "%"#type"\n", gb_ib->field); \
} \ } \
static DEVICE_ATTR_RO(module_##field) static DEVICE_ATTR_RO(module_##field)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment