2 * STMicroelectronics pressures driver
4 * Copyright 2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
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,
42 MODULE_DEVICE_TABLE(of, st_press_of_match);
44 #define st_press_of_match NULL
48 static const struct acpi_device_id st_press_acpi_match[] = {
52 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
54 #define st_press_acpi_match NULL
57 static const struct i2c_device_id st_press_id_table[] = {
58 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
59 { LPS25H_PRESS_DEV_NAME, LPS25H },
60 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
61 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
64 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
66 static int st_press_i2c_probe(struct i2c_client *client,
67 const struct i2c_device_id *id)
69 struct iio_dev *indio_dev;
70 struct st_sensor_data *press_data;
73 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
77 press_data = iio_priv(indio_dev);
79 if (client->dev.of_node) {
80 st_sensors_of_name_probe(&client->dev, st_press_of_match,
81 client->name, sizeof(client->name));
82 } else if (ACPI_HANDLE(&client->dev)) {
83 ret = st_sensors_match_acpi_device(&client->dev);
84 if ((ret < 0) || (ret >= ST_PRESS_MAX))
87 strncpy(client->name, st_press_id_table[ret].name,
88 sizeof(client->name));
89 client->name[sizeof(client->name) - 1] = '\0';
93 st_sensors_i2c_configure(indio_dev, client, press_data);
95 ret = st_press_common_probe(indio_dev);
102 static int st_press_i2c_remove(struct i2c_client *client)
104 st_press_common_remove(i2c_get_clientdata(client));
109 static struct i2c_driver st_press_driver = {
111 .name = "st-press-i2c",
112 .of_match_table = of_match_ptr(st_press_of_match),
113 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
115 .probe = st_press_i2c_probe,
116 .remove = st_press_i2c_remove,
117 .id_table = st_press_id_table,
119 module_i2c_driver(st_press_driver);
121 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
122 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
123 MODULE_LICENSE("GPL v2");