From: Greg Kroah-Hartman Date: Thu, 11 Dec 2014 22:10:55 +0000 (-0500) Subject: greybus: interface_block: rename module.[c|h] to interface_block.[c|h] X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e50522209a2e86ffac2d8c9a99c0979914cff5dd;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git greybus: interface_block: rename module.[c|h] to interface_block.[c|h] "modules" in the driver model here, are really "interface blocks" as that is what they are physically tied to. So rename the files before we start changing the code to make it obvious what is going on. Reviewed-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/Makefile b/drivers/staging/greybus/Makefile index 4fa9b3f29e57..41186b7bb2e4 100644 --- a/drivers/staging/greybus/Makefile +++ b/drivers/staging/greybus/Makefile @@ -3,7 +3,7 @@ greybus-y := core.o \ debugfs.o \ ap.o \ manifest.o \ - module.o \ + interface_block.o \ interface.o \ connection.o \ protocol.o \ diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 11f4e5529d9a..101b71168491 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -23,7 +23,7 @@ #include "greybus_id.h" #include "greybus_manifest.h" #include "manifest.h" -#include "module.h" +#include "interface_block.h" #include "interface.h" #include "connection.h" #include "protocol.h" diff --git a/drivers/staging/greybus/interface_block.c b/drivers/staging/greybus/interface_block.c new file mode 100644 index 000000000000..c424a5ac25e7 --- /dev/null +++ b/drivers/staging/greybus/interface_block.c @@ -0,0 +1,201 @@ +/* + * Greybus modules + * + * Copyright 2014 Google Inc. + * + * Released under the GPLv2 only. + */ + +#include "greybus.h" + +/* XXX This could be per-host device */ +static DEFINE_SPINLOCK(gb_modules_lock); + +static int gb_module_match_one_id(struct gb_module *gmod, + const struct greybus_module_id *id) +{ + if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_VENDOR) && + (id->vendor != gmod->vendor)) + return 0; + + if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_PRODUCT) && + (id->product != gmod->product)) + return 0; + + if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_SERIAL) && + (id->unique_id != gmod->unique_id)) + return 0; + + return 1; +} + +const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod, + const struct greybus_module_id *id) +{ + if (id == NULL) + return NULL; + + for (; id->vendor || id->product || id->unique_id || + id->driver_info; id++) { + if (gb_module_match_one_id(gmod, id)) + return id; + } + + return NULL; +} + +struct gb_module *gb_module_find(struct greybus_host_device *hd, u8 module_id) +{ + struct gb_module *module; + + list_for_each_entry(module, &hd->modules, links) + if (module->module_id == module_id) + return module; + + return NULL; +} + +static void greybus_module_release(struct device *dev) +{ + struct gb_module *gmod = to_gb_module(dev); + + kfree(gmod); +} + +struct device_type greybus_module_type = { + .name = "greybus_module", + .release = greybus_module_release, +}; + +/* + * A Greybus module represents a user-replicable component on an Ara + * phone. + * + * Create a gb_module 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) +{ + struct gb_module *gmod; + int retval; + + gmod = gb_module_find(hd, module_id); + if (gmod) { + 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) + return NULL; + + gmod->hd = hd; /* XXX refcount? */ + gmod->module_id = module_id; + INIT_LIST_HEAD(&gmod->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); + + retval = device_add(&gmod->dev); + if (retval) { + pr_err("failed to add module device for id 0x%02hhx\n", + module_id); + put_device(&gmod->dev); + kfree(gmod); + return NULL; + } + + spin_lock_irq(&gb_modules_lock); + list_add_tail(&gmod->links, &hd->modules); + spin_unlock_irq(&gb_modules_lock); + + return gmod; +} + +/* + * Tear down a previously set up module. + */ +void gb_module_destroy(struct gb_module *gmod) +{ + if (WARN_ON(!gmod)) + return; + + spin_lock_irq(&gb_modules_lock); + list_del(&gmod->links); + spin_unlock_irq(&gb_modules_lock); + + gb_interface_destroy(gmod); + + kfree(gmod->product_string); + kfree(gmod->vendor_string); + /* kref_put(module->hd); */ + + device_del(&gmod->dev); +} + +/** + * gb_add_module + * + * Pass in a buffer that _should_ contain a Greybus module manifest + * and register a greybus device structure with the kernel core. + */ +void gb_add_module(struct greybus_host_device *hd, u8 module_id, + u8 *data, int size) +{ + struct gb_module *gmod; + + gmod = gb_module_create(hd, module_id); + if (!gmod) { + dev_err(hd->parent, "failed to create module\n"); + return; + } + + /* + * Parse the manifest and build up our data structures + * representing what's in it. + */ + if (!gb_manifest_parse(gmod, data, size)) { + dev_err(hd->parent, "manifest error\n"); + goto err_module; + } + + /* + * XXX + * We've successfully parsed the manifest. Now we need to + * allocate CPort Id's for connecting to the CPorts found on + * other modules. For each of these, establish a connection + * between the local and remote CPorts (including + * configuring the switch to allow them to communicate). + */ + + return; + +err_module: + gb_module_destroy(gmod); +} + +void gb_remove_module(struct greybus_host_device *hd, u8 module_id) +{ + struct gb_module *gmod = gb_module_find(hd, module_id); + + if (gmod) + gb_module_destroy(gmod); + else + dev_err(hd->parent, "module id %d not found\n", module_id); +} + +void gb_remove_modules(struct greybus_host_device *hd) +{ + struct gb_module *gmod, *temp; + + list_for_each_entry_safe(gmod, temp, &hd->modules, links) + gb_module_destroy(gmod); +} diff --git a/drivers/staging/greybus/interface_block.h b/drivers/staging/greybus/interface_block.h new file mode 100644 index 000000000000..2fdca57398d2 --- /dev/null +++ b/drivers/staging/greybus/interface_block.h @@ -0,0 +1,55 @@ +/* + * Greybus modules + * + * Copyright 2014 Google Inc. + * + * Released under the GPLv2 only. + */ + +#ifndef __MODULE_H +#define __MODULE_H + +/* Increase these values if needed */ +#define MAX_CPORTS_PER_MODULE 10 +#define MAX_STRINGS_PER_MODULE 10 + +struct gb_module { + struct device dev; + + struct list_head interfaces; + struct list_head links; /* greybus_host_device->modules */ + u8 module_id; /* Physical location within the Endo */ + + /* Information taken from the manifest module descriptor */ + u16 vendor; + u16 product; + char *vendor_string; + char *product_string; + u64 unique_id; + + struct greybus_host_device *hd; +}; +#define to_gb_module(d) container_of(d, struct gb_module, dev) + +static inline void +gb_module_set_drvdata(struct gb_module *gmod, void *data) +{ + dev_set_drvdata(&gmod->dev, data); +} + +static inline void *gb_module_get_drvdata(struct gb_module *gmod) +{ + return dev_get_drvdata(&gmod->dev); +} + +const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod, + const struct greybus_module_id *id); + +struct gb_module *gb_module_create(struct greybus_host_device *hd, + u8 module_id); +void gb_module_destroy(struct gb_module *module); + +struct gb_module *gb_module_find(struct greybus_host_device *hd, + u8 module_id); + +#endif /* __MODULE_H */ diff --git a/drivers/staging/greybus/module.c b/drivers/staging/greybus/module.c deleted file mode 100644 index c424a5ac25e7..000000000000 --- a/drivers/staging/greybus/module.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Greybus modules - * - * Copyright 2014 Google Inc. - * - * Released under the GPLv2 only. - */ - -#include "greybus.h" - -/* XXX This could be per-host device */ -static DEFINE_SPINLOCK(gb_modules_lock); - -static int gb_module_match_one_id(struct gb_module *gmod, - const struct greybus_module_id *id) -{ - if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_VENDOR) && - (id->vendor != gmod->vendor)) - return 0; - - if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_PRODUCT) && - (id->product != gmod->product)) - return 0; - - if ((id->match_flags & GREYBUS_DEVICE_ID_MATCH_SERIAL) && - (id->unique_id != gmod->unique_id)) - return 0; - - return 1; -} - -const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod, - const struct greybus_module_id *id) -{ - if (id == NULL) - return NULL; - - for (; id->vendor || id->product || id->unique_id || - id->driver_info; id++) { - if (gb_module_match_one_id(gmod, id)) - return id; - } - - return NULL; -} - -struct gb_module *gb_module_find(struct greybus_host_device *hd, u8 module_id) -{ - struct gb_module *module; - - list_for_each_entry(module, &hd->modules, links) - if (module->module_id == module_id) - return module; - - return NULL; -} - -static void greybus_module_release(struct device *dev) -{ - struct gb_module *gmod = to_gb_module(dev); - - kfree(gmod); -} - -struct device_type greybus_module_type = { - .name = "greybus_module", - .release = greybus_module_release, -}; - -/* - * A Greybus module represents a user-replicable component on an Ara - * phone. - * - * Create a gb_module 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) -{ - struct gb_module *gmod; - int retval; - - gmod = gb_module_find(hd, module_id); - if (gmod) { - 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) - return NULL; - - gmod->hd = hd; /* XXX refcount? */ - gmod->module_id = module_id; - INIT_LIST_HEAD(&gmod->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); - - retval = device_add(&gmod->dev); - if (retval) { - pr_err("failed to add module device for id 0x%02hhx\n", - module_id); - put_device(&gmod->dev); - kfree(gmod); - return NULL; - } - - spin_lock_irq(&gb_modules_lock); - list_add_tail(&gmod->links, &hd->modules); - spin_unlock_irq(&gb_modules_lock); - - return gmod; -} - -/* - * Tear down a previously set up module. - */ -void gb_module_destroy(struct gb_module *gmod) -{ - if (WARN_ON(!gmod)) - return; - - spin_lock_irq(&gb_modules_lock); - list_del(&gmod->links); - spin_unlock_irq(&gb_modules_lock); - - gb_interface_destroy(gmod); - - kfree(gmod->product_string); - kfree(gmod->vendor_string); - /* kref_put(module->hd); */ - - device_del(&gmod->dev); -} - -/** - * gb_add_module - * - * Pass in a buffer that _should_ contain a Greybus module manifest - * and register a greybus device structure with the kernel core. - */ -void gb_add_module(struct greybus_host_device *hd, u8 module_id, - u8 *data, int size) -{ - struct gb_module *gmod; - - gmod = gb_module_create(hd, module_id); - if (!gmod) { - dev_err(hd->parent, "failed to create module\n"); - return; - } - - /* - * Parse the manifest and build up our data structures - * representing what's in it. - */ - if (!gb_manifest_parse(gmod, data, size)) { - dev_err(hd->parent, "manifest error\n"); - goto err_module; - } - - /* - * XXX - * We've successfully parsed the manifest. Now we need to - * allocate CPort Id's for connecting to the CPorts found on - * other modules. For each of these, establish a connection - * between the local and remote CPorts (including - * configuring the switch to allow them to communicate). - */ - - return; - -err_module: - gb_module_destroy(gmod); -} - -void gb_remove_module(struct greybus_host_device *hd, u8 module_id) -{ - struct gb_module *gmod = gb_module_find(hd, module_id); - - if (gmod) - gb_module_destroy(gmod); - else - dev_err(hd->parent, "module id %d not found\n", module_id); -} - -void gb_remove_modules(struct greybus_host_device *hd) -{ - struct gb_module *gmod, *temp; - - list_for_each_entry_safe(gmod, temp, &hd->modules, links) - gb_module_destroy(gmod); -} diff --git a/drivers/staging/greybus/module.h b/drivers/staging/greybus/module.h deleted file mode 100644 index 2fdca57398d2..000000000000 --- a/drivers/staging/greybus/module.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Greybus modules - * - * Copyright 2014 Google Inc. - * - * Released under the GPLv2 only. - */ - -#ifndef __MODULE_H -#define __MODULE_H - -/* Increase these values if needed */ -#define MAX_CPORTS_PER_MODULE 10 -#define MAX_STRINGS_PER_MODULE 10 - -struct gb_module { - struct device dev; - - struct list_head interfaces; - struct list_head links; /* greybus_host_device->modules */ - u8 module_id; /* Physical location within the Endo */ - - /* Information taken from the manifest module descriptor */ - u16 vendor; - u16 product; - char *vendor_string; - char *product_string; - u64 unique_id; - - struct greybus_host_device *hd; -}; -#define to_gb_module(d) container_of(d, struct gb_module, dev) - -static inline void -gb_module_set_drvdata(struct gb_module *gmod, void *data) -{ - dev_set_drvdata(&gmod->dev, data); -} - -static inline void *gb_module_get_drvdata(struct gb_module *gmod) -{ - return dev_get_drvdata(&gmod->dev); -} - -const struct greybus_module_id *gb_module_match_id(struct gb_module *gmod, - const struct greybus_module_id *id); - -struct gb_module *gb_module_create(struct greybus_host_device *hd, - u8 module_id); -void gb_module_destroy(struct gb_module *module); - -struct gb_module *gb_module_find(struct greybus_host_device *hd, - u8 module_id); - -#endif /* __MODULE_H */