2 * STMicroelectronics pressures driver
4 * Copyright 2013 STMicroelectronics Inc.
8 * Licensed under the GPL-2.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/acpi.h>
15 #include <linux/i2c.h>
16 #include <linux/iio/iio.h>
18 #include <linux/iio/common/st_sensors.h>
19 #include <linux/iio/common/st_sensors_i2c.h>
20 #include "st_pressure.h"
23 static const struct of_device_id st_press_of_match[] = {
25 .compatible = "st,lps001wp-press",
26 .data = LPS001WP_PRESS_DEV_NAME,
29 .compatible = "st,lps25h-press",
30 .data = LPS25H_PRESS_DEV_NAME,
33 .compatible = "st,lps331ap-press",
34 .data = LPS331AP_PRESS_DEV_NAME,
37 .compatible = "st,lps22hb-press",
38 .data = LPS22HB_PRESS_DEV_NAME,
41 .compatible = "st,lps33hw",
42 .data = LPS33HW_PRESS_DEV_NAME,
45 .compatible = "st,lps35hw",
46 .data = LPS35HW_PRESS_DEV_NAME,
49 .compatible = "st,lps22hh",
50 .data = LPS22HH_PRESS_DEV_NAME,
54 MODULE_DEVICE_TABLE(of, st_press_of_match);
56 #define st_press_of_match NULL
60 static const struct acpi_device_id st_press_acpi_match[] = {
64 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
66 #define st_press_acpi_match NULL
69 static const struct i2c_device_id st_press_id_table[] = {
70 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
71 { LPS25H_PRESS_DEV_NAME, LPS25H },
72 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
73 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
74 { LPS33HW_PRESS_DEV_NAME, LPS33HW },
75 { LPS35HW_PRESS_DEV_NAME, LPS35HW },
76 { LPS22HH_PRESS_DEV_NAME, LPS22HH },
79 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
81 static int st_press_i2c_probe(struct i2c_client *client,
82 const struct i2c_device_id *id)
84 struct iio_dev *indio_dev;
85 struct st_sensor_data *press_data;
88 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
92 press_data = iio_priv(indio_dev);
94 if (client->dev.of_node) {
95 st_sensors_of_name_probe(&client->dev, st_press_of_match,
96 client->name, sizeof(client->name));
97 } else if (ACPI_HANDLE(&client->dev)) {
98 ret = st_sensors_match_acpi_device(&client->dev);
99 if ((ret < 0) || (ret >= ST_PRESS_MAX))
102 strlcpy(client->name, st_press_id_table[ret].name,
103 sizeof(client->name));
107 st_sensors_i2c_configure(indio_dev, client, press_data);
109 ret = st_press_common_probe(indio_dev);
116 static int st_press_i2c_remove(struct i2c_client *client)
118 st_press_common_remove(i2c_get_clientdata(client));
123 static struct i2c_driver st_press_driver = {
125 .name = "st-press-i2c",
126 .of_match_table = of_match_ptr(st_press_of_match),
127 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
129 .probe = st_press_i2c_probe,
130 .remove = st_press_i2c_remove,
131 .id_table = st_press_id_table,
133 module_i2c_driver(st_press_driver);
136 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
137 MODULE_LICENSE("GPL v2");