hwmon: (amc6821) add of_match table
authorJosua Mayer <josua@solid-run.com>
Thu, 7 Mar 2024 11:06:58 +0000 (12:06 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 7 Mar 2024 17:17:40 +0000 (09:17 -0800)
Add of_match table for "ti,amc6821" compatible string.
This fixes automatic driver loading by userspace when using device-tree,
and if built as a module like major linux distributions do.

While devices probe just fine with i2c_device_id table, userspace can't
match the "ti,amc6821" compatible string from dt with the plain
"amc6821" device id. As a result, the kernel module can not be loaded.

Cc: stable@vger.kernel.org
Signed-off-by: Josua Mayer <josua@solid-run.com>
Link: https://lore.kernel.org/r/20240307-amc6821-of-match-v1-1-5f40464a3110@solid-run.com
[groeck: Cleaned up patch description]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/amc6821.c

index 2a7a4b6b00942b34ee411ef1d2276176f4a132f7..9b02b304c2f5d4ca3c4c164cc0fe1fa7dc9bfd3a 100644 (file)
@@ -934,10 +934,21 @@ static const struct i2c_device_id amc6821_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, amc6821_id);
 
+static const struct of_device_id __maybe_unused amc6821_of_match[] = {
+       {
+               .compatible = "ti,amc6821",
+               .data = (void *)amc6821,
+       },
+       { }
+};
+
+MODULE_DEVICE_TABLE(of, amc6821_of_match);
+
 static struct i2c_driver amc6821_driver = {
        .class = I2C_CLASS_HWMON,
        .driver = {
                .name   = "amc6821",
+               .of_match_table = of_match_ptr(amc6821_of_match),
        },
        .probe = amc6821_probe,
        .id_table = amc6821_id,