iio: st_pressure: Support i2c probe using acpi
authorShrirang Bagul <shrirang.bagul@canonical.com>
Thu, 24 Nov 2016 05:33:45 +0000 (13:33 +0800)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 Dec 2016 08:56:27 +0000 (08:56 +0000)
Compatible strings are not available on ACPI based systems. This patch adds
support to use DSDT information read from platform BIOS instead for probing
st pressure sensors.

Signed-off-by: Shrirang Bagul <shrirang.bagul@canonical.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/pressure/st_pressure.h
drivers/iio/pressure/st_pressure_i2c.c

index 903a21e46874327052d300708169e34146bef26d..7d995937adbab2483612b5a8ead2df8e1bde00c1 100644 (file)
 #include <linux/types.h>
 #include <linux/iio/common/st_sensors.h>
 
+enum st_press_type {
+       LPS001WP,
+       LPS25H,
+       LPS331AP,
+       LPS22HB,
+       ST_PRESS_MAX,
+};
+
 #define LPS001WP_PRESS_DEV_NAME                "lps001wp"
 #define LPS25H_PRESS_DEV_NAME          "lps25h"
 #define LPS331AP_PRESS_DEV_NAME                "lps331ap"
index ed18701c68c97efe1d5604a85e6178bd097ea123..17417a4d5a5f955be36aeb48ff8ec73f558e4bdc 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/acpi.h>
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
 
@@ -43,25 +44,56 @@ MODULE_DEVICE_TABLE(of, st_press_of_match);
 #define st_press_of_match NULL
 #endif
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id st_press_acpi_match[] = {
+       {"SNO9210", LPS22HB},
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
+#else
+#define st_press_acpi_match NULL
+#endif
+
+static const struct i2c_device_id st_press_id_table[] = {
+       { LPS001WP_PRESS_DEV_NAME, LPS001WP },
+       { LPS25H_PRESS_DEV_NAME,  LPS25H },
+       { LPS331AP_PRESS_DEV_NAME, LPS331AP },
+       { LPS22HB_PRESS_DEV_NAME, LPS22HB },
+       {},
+};
+MODULE_DEVICE_TABLE(i2c, st_press_id_table);
+
 static int st_press_i2c_probe(struct i2c_client *client,
                                                const struct i2c_device_id *id)
 {
        struct iio_dev *indio_dev;
        struct st_sensor_data *press_data;
-       int err;
+       int ret;
 
        indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
        if (!indio_dev)
                return -ENOMEM;
 
        press_data = iio_priv(indio_dev);
-       st_sensors_of_i2c_probe(client, st_press_of_match);
+
+       if (client->dev.of_node) {
+               st_sensors_of_i2c_probe(client, st_press_of_match);
+       } else if (ACPI_HANDLE(&client->dev)) {
+               ret = st_sensors_match_acpi_device(&client->dev);
+               if ((ret < 0) || (ret >= ST_PRESS_MAX))
+                       return -ENODEV;
+
+               strncpy(client->name, st_press_id_table[ret].name,
+                               sizeof(client->name));
+               client->name[sizeof(client->name) - 1] = '\0';
+       } else if (!id)
+               return -ENODEV;
 
        st_sensors_i2c_configure(indio_dev, client, press_data);
 
-       err = st_press_common_probe(indio_dev);
-       if (err < 0)
-               return err;
+       ret = st_press_common_probe(indio_dev);
+       if (ret < 0)
+               return ret;
 
        return 0;
 }
@@ -73,18 +105,11 @@ static int st_press_i2c_remove(struct i2c_client *client)
        return 0;
 }
 
-static const struct i2c_device_id st_press_id_table[] = {
-       { LPS001WP_PRESS_DEV_NAME },
-       { LPS25H_PRESS_DEV_NAME },
-       { LPS331AP_PRESS_DEV_NAME },
-       {},
-};
-MODULE_DEVICE_TABLE(i2c, st_press_id_table);
-
 static struct i2c_driver st_press_driver = {
        .driver = {
                .name = "st-press-i2c",
                .of_match_table = of_match_ptr(st_press_of_match),
+               .acpi_match_table = ACPI_PTR(st_press_acpi_match),
        },
        .probe = st_press_i2c_probe,
        .remove = st_press_i2c_remove,