Match devices to drivers by their modalias when the ACPI and the OF
match fails.

Cc: Rob Herring <r...@kernel.org>
Cc: Johan Hovold <jo...@kernel.org>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: Jiri Slaby <jsl...@suse.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/tty/serdev/core.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index df93b727e984..2c79f47fc0db 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -79,8 +79,23 @@ static const struct device_type serdev_ctrl_type = {
        .release        = serdev_ctrl_release,
 };
 
+static int serdev_match_id(const struct serdev_device_id *id,
+                          const struct serdev_device *sdev)
+{
+       while (id->name[0]) {
+               if (!strcmp(sdev->modalias, id->name))
+                       return 1;
+               id++;
+       }
+
+       return 0;
+}
+
 static int serdev_device_match(struct device *dev, struct device_driver *drv)
 {
+       const struct serdev_device *sdev = to_serdev_device(dev);
+       const struct serdev_device_driver *sdrv = to_serdev_device_driver(drv);
+
        if (!is_serdev_device(dev))
                return 0;
 
@@ -88,7 +103,13 @@ static int serdev_device_match(struct device *dev, struct 
device_driver *drv)
        if (acpi_driver_match_device(dev, drv))
                return 1;
 
-       return of_driver_match_device(dev, drv);
+       if (of_driver_match_device(dev, drv))
+               return 1;
+
+       if (sdrv->id_table)
+               return serdev_match_id(sdrv->id_table, sdev);
+
+       return strcmp(sdev->modalias, drv->name) == 0;
 }
 
 /**
-- 
2.17.1

Reply via email to