Commit 79dda609 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: endo: clean up id assignment code

Recently code was added (back) to assign a unique id to each
endo, so satisfy uniqueness requirements of the Linux device
subsystem.  An ID allocator is used to manage the space of IDs.

Now that we have gb_endo_init(), we can initialize the map there,
and fully hide the ID map within "endo.c".

The original functions gb_endo_id_alloc() and gb_endo_id_free()
provided a nice abstract interface, but the direct ID allocation
calls are quite simple, so just call them directly.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent f35ab903
...@@ -256,8 +256,6 @@ static int __init gb_init(void) ...@@ -256,8 +256,6 @@ static int __init gb_init(void)
goto error_bus; goto error_bus;
} }
ida_init(&greybus_endo_id_map);
retval = gb_ap_init(); retval = gb_ap_init();
if (retval) { if (retval) {
pr_err("gb_ap_init failed (%d)\n", retval); pr_err("gb_ap_init failed (%d)\n", retval);
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#define max_endo_interface_id(endo_layout) \ #define max_endo_interface_id(endo_layout) \
(4 + ((endo_layout)->max_ribs + 1) * 2) (4 + ((endo_layout)->max_ribs + 1) * 2)
struct ida greybus_endo_id_map; static struct ida greybus_endo_id_map;
/* endo sysfs attributes */ /* endo sysfs attributes */
static ssize_t serial_number_show(struct device *dev, static ssize_t serial_number_show(struct device *dev,
...@@ -434,42 +434,13 @@ static int create_modules(struct gb_endo *endo) ...@@ -434,42 +434,13 @@ static int create_modules(struct gb_endo *endo)
return 0; return 0;
} }
/*
* Allocate an available Id to uniquely identify the endo device. The lowest
* available id is returned, so the first call is guaranteed to allocate endo Id
* 0.
*
* Assigns the endo's id and returns 0 if successful.
* Returns error otherwise.
*/
static int gb_endo_id_alloc(struct gb_endo *endo)
{
int id;
id = ida_simple_get(&greybus_endo_id_map, 0, 0, GFP_ATOMIC);
if (id < 0)
return id;
endo->dev_id = (u16)id;
return 0;
}
/*
* Free a previously-allocated Endo Id.
*/
static void gb_endo_id_free(struct gb_endo *endo)
{
ida_simple_remove(&greybus_endo_id_map, endo->dev_id);
}
static int gb_endo_register(struct greybus_host_device *hd, static int gb_endo_register(struct greybus_host_device *hd,
struct gb_endo *endo) struct gb_endo *endo)
{ {
int retval; int retval;
retval = gb_endo_id_alloc(endo); retval = ida_simple_get(&greybus_endo_id_map, 0, 0, GFP_ATOMIC);
if (retval) if (retval < 0)
return retval; return retval;
endo->dev.parent = hd->parent; endo->dev.parent = hd->parent;
...@@ -491,7 +462,7 @@ static int gb_endo_register(struct greybus_host_device *hd, ...@@ -491,7 +462,7 @@ static int gb_endo_register(struct greybus_host_device *hd,
dev_err(hd->parent, "failed to add endo device of id 0x%04x\n", dev_err(hd->parent, "failed to add endo device of id 0x%04x\n",
endo->id); endo->id);
put_device(&endo->dev); put_device(&endo->dev);
gb_endo_id_free(endo); ida_simple_remove(&greybus_endo_id_map, endo->dev_id);
} }
return retval; return retval;
...@@ -547,12 +518,14 @@ void gb_endo_remove(struct gb_endo *endo) ...@@ -547,12 +518,14 @@ void gb_endo_remove(struct gb_endo *endo)
/* remove all modules for this endo */ /* remove all modules for this endo */
gb_module_remove_all(endo); gb_module_remove_all(endo);
gb_endo_id_free(endo); ida_simple_remove(&greybus_endo_id_map, endo->dev_id);
device_unregister(&endo->dev); device_unregister(&endo->dev);
} }
int __init gb_endo_init(void) int __init gb_endo_init(void)
{ {
ida_init(&greybus_endo_id_map);
return 0; return 0;
} }
......
...@@ -46,8 +46,6 @@ struct gb_endo { ...@@ -46,8 +46,6 @@ struct gb_endo {
}; };
#define to_gb_endo(d) container_of(d, struct gb_endo, dev) #define to_gb_endo(d) container_of(d, struct gb_endo, dev)
extern struct ida greybus_endo_id_map;
/* Greybus "private" definitions */ /* Greybus "private" definitions */
struct greybus_host_device; struct greybus_host_device;
......
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