Subject: [PATCH] [ACPI] Add a match function to the ACPI bus type - This is a simple match implementation that matches either the device's HID or one of it's CIDs. It's not as intelligent as the original matching function, but should work for almost all devices. Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/bus.c | 59 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) applies-to: ace76e471014ba20ba117f803457e57f5b55925a 7a3cec388d0d0ae50e9f493fdbd7d32030a82226 diff --git a/drivers/acpi/drivers/core/bus.c b/drivers/acpi/drivers/core/bus.c index 06f5a96..dc463e3 100644 --- a/drivers/acpi/drivers/core/bus.c +++ b/drivers/acpi/drivers/core/bus.c @@ -14,8 +14,67 @@ #include "core.h" +static int match_id(struct acpi_dev * ad, struct acpi_device_driver * adrv, char * id) +{ + int found = 0; + int i; + + if (strlen(id)) { + for (i = 0; i < adrv->d_num_ids; i++) { + if (!strcmp(id, adrv->d_ids[i])) { + found = 1; + break; + } + } + } + if (found) + dbg("Matched %s to driver '%s' with HID '%s'\n", + acpi_dev_bid(ad), adrv->d_drv.name, id); + return found; +} + +static int match_cid(struct acpi_dev * ad, struct acpi_device_driver * adrv) +{ + struct acpi_compatible_id_list * c; + int i; + + c = ad->acpi_device->pnp.cid_list; + if (c) { + for (i = 0; i < c->count; i++) { + if (match_id(ad, adrv, c->id[i].value)) + return 1; + } + } + + return 0; +} + +static int acpi_bus_match(struct device * dev, struct device_driver * drv) +{ + struct acpi_dev * ad = to_acpi_dev(dev); + struct acpi_device_driver * adrv = to_acpi_driver(drv); + + /* + * First, try the HID.. + */ + if (match_id(ad, adrv, acpi_dev_hid(ad))) + return 1; + + /* + * If that doesn't work, try to match each _CID of the + * device with each UID that the driver supports. + */ + + if (match_cid(ad, adrv)) + return 1; + + return 0; +} + + struct bus_type acpi_bus = { .name = "acpi", + .match = acpi_bus_match, }; static int acpi_bus_init(void) --- 0.99.9.GIT