Commit 700001af authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: move id-matching back to core

Move id-matching back to core and the bus code where it belongs.
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent f65fa47f
...@@ -68,41 +68,6 @@ struct device_type greybus_bundle_type = { ...@@ -68,41 +68,6 @@ struct device_type greybus_bundle_type = {
.release = gb_bundle_release, .release = gb_bundle_release,
}; };
static int gb_bundle_match_one_id(struct gb_bundle *bundle,
const struct greybus_bundle_id *id)
{
if ((id->match_flags & GREYBUS_ID_MATCH_VENDOR) &&
(id->vendor != bundle->intf->vendor))
return 0;
if ((id->match_flags & GREYBUS_ID_MATCH_PRODUCT) &&
(id->product != bundle->intf->product))
return 0;
if ((id->match_flags & GREYBUS_ID_MATCH_CLASS) &&
(id->class != bundle->class))
return 0;
return 1;
}
const struct greybus_bundle_id *
gb_bundle_match_id(struct gb_bundle *bundle,
const struct greybus_bundle_id *id)
{
if (id == NULL)
return NULL;
for (; id->vendor || id->product || id->class || id->driver_info;
id++) {
if (gb_bundle_match_one_id(bundle, id))
return id;
}
return NULL;
}
/* XXX This could be per-host device or per-module */ /* XXX This could be per-host device or per-module */
static DEFINE_SPINLOCK(gb_bundles_lock); static DEFINE_SPINLOCK(gb_bundles_lock);
......
...@@ -29,13 +29,46 @@ int greybus_disabled(void) ...@@ -29,13 +29,46 @@ int greybus_disabled(void)
} }
EXPORT_SYMBOL_GPL(greybus_disabled); EXPORT_SYMBOL_GPL(greybus_disabled);
static int greybus_match_one_id(struct gb_bundle *bundle,
const struct greybus_bundle_id *id)
{
if ((id->match_flags & GREYBUS_ID_MATCH_VENDOR) &&
(id->vendor != bundle->intf->vendor))
return 0;
if ((id->match_flags & GREYBUS_ID_MATCH_PRODUCT) &&
(id->product != bundle->intf->product))
return 0;
if ((id->match_flags & GREYBUS_ID_MATCH_CLASS) &&
(id->class != bundle->class))
return 0;
return 1;
}
static const struct greybus_bundle_id *
greybus_match_id(struct gb_bundle *bundle, const struct greybus_bundle_id *id)
{
if (id == NULL)
return NULL;
for (; id->vendor || id->product || id->class || id->driver_info;
id++) {
if (greybus_match_one_id(bundle, id))
return id;
}
return NULL;
}
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_bundle *bundle = to_gb_bundle(dev); struct gb_bundle *bundle = to_gb_bundle(dev);
const struct greybus_bundle_id *id; const struct greybus_bundle_id *id;
id = gb_bundle_match_id(bundle, driver->id_table); id = greybus_match_id(bundle, driver->id_table);
if (id) if (id)
return 1; return 1;
/* FIXME - Dynamic ids? */ /* FIXME - Dynamic ids? */
...@@ -97,7 +130,7 @@ static int greybus_probe(struct device *dev) ...@@ -97,7 +130,7 @@ static int greybus_probe(struct device *dev)
int retval; int retval;
/* match id */ /* match id */
id = gb_bundle_match_id(bundle, driver->id_table); id = greybus_match_id(bundle, driver->id_table);
if (!id) if (!id)
return -ENODEV; return -ENODEV;
......
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