hwmon: (lm70) Add support for ACPI
authorAndrej Picej <andpicej@gmail.com>
Thu, 23 Apr 2020 13:27:33 +0000 (15:27 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 22 May 2020 13:28:38 +0000 (06:28 -0700)
This commit adds support for lm70 commpatible drivers with systems that
use ACPI.

Signed-off-by: Andrej Picej <andpicej@gmail.com>
[groeck: Fix various issues seen if CONFIG_ACPI=n]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm70.c

index 4122e59f0bb4cfddc877a4ab3bb44ef13904a77f..ae2b84263a4455a4ed5258e6d272adc945565f1f 100644 (file)
@@ -25,7 +25,7 @@
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
 #include <linux/of_device.h>
-
+#include <linux/acpi.h>
 
 #define DRVNAME                "lm70"
 
@@ -148,18 +148,50 @@ static const struct of_device_id lm70_of_ids[] = {
 MODULE_DEVICE_TABLE(of, lm70_of_ids);
 #endif
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id lm70_acpi_ids[] = {
+       {
+               .id = "LM000070",
+               .driver_data = LM70_CHIP_LM70,
+       },
+       {
+               .id = "TMP00121",
+               .driver_data = LM70_CHIP_TMP121,
+       },
+       {
+               .id = "LM000071",
+               .driver_data = LM70_CHIP_LM71,
+       },
+       {
+               .id = "LM000074",
+               .driver_data = LM70_CHIP_LM74,
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(acpi, lm70_acpi_ids);
+#endif
+
 static int lm70_probe(struct spi_device *spi)
 {
-       const struct of_device_id *match;
+       const struct of_device_id *of_match;
        struct device *hwmon_dev;
        struct lm70 *p_lm70;
        int chip;
 
-       match = of_match_device(lm70_of_ids, &spi->dev);
-       if (match)
-               chip = (int)(uintptr_t)match->data;
-       else
-               chip = spi_get_device_id(spi)->driver_data;
+       of_match = of_match_device(lm70_of_ids, &spi->dev);
+       if (of_match)
+               chip = (int)(uintptr_t)of_match->data;
+       else {
+#ifdef CONFIG_ACPI
+               const struct acpi_device_id *acpi_match;
+
+               acpi_match = acpi_match_device(lm70_acpi_ids, &spi->dev);
+               if (acpi_match)
+                       chip = (int)(uintptr_t)acpi_match->driver_data;
+               else
+#endif
+                       chip = spi_get_device_id(spi)->driver_data;
+       }
 
        /* signaling is SPI_MODE_0 */
        if (spi->mode & (SPI_CPOL | SPI_CPHA))
@@ -195,6 +227,7 @@ static struct spi_driver lm70_driver = {
        .driver = {
                .name   = "lm70",
                .of_match_table = of_match_ptr(lm70_of_ids),
+               .acpi_match_table = ACPI_PTR(lm70_acpi_ids),
        },
        .id_table = lm70_ids,
        .probe  = lm70_probe,