Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / iio / pressure / st_pressure_i2c.c
blobb7d9ba706abc52ce0c6d05abd1ae5b3eb6034764
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics pressures driver
5 * Copyright 2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/acpi.h>
14 #include <linux/i2c.h>
15 #include <linux/iio/iio.h>
17 #include <linux/iio/common/st_sensors.h>
18 #include <linux/iio/common/st_sensors_i2c.h>
19 #include "st_pressure.h"
21 #ifdef CONFIG_OF
22 static const struct of_device_id st_press_of_match[] = {
24 .compatible = "st,lps001wp-press",
25 .data = LPS001WP_PRESS_DEV_NAME,
28 .compatible = "st,lps25h-press",
29 .data = LPS25H_PRESS_DEV_NAME,
32 .compatible = "st,lps331ap-press",
33 .data = LPS331AP_PRESS_DEV_NAME,
36 .compatible = "st,lps22hb-press",
37 .data = LPS22HB_PRESS_DEV_NAME,
40 .compatible = "st,lps33hw",
41 .data = LPS33HW_PRESS_DEV_NAME,
44 .compatible = "st,lps35hw",
45 .data = LPS35HW_PRESS_DEV_NAME,
48 .compatible = "st,lps22hh",
49 .data = LPS22HH_PRESS_DEV_NAME,
51 {},
53 MODULE_DEVICE_TABLE(of, st_press_of_match);
54 #else
55 #define st_press_of_match NULL
56 #endif
58 #ifdef CONFIG_ACPI
59 static const struct acpi_device_id st_press_acpi_match[] = {
60 {"SNO9210", LPS22HB},
61 { },
63 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
64 #else
65 #define st_press_acpi_match NULL
66 #endif
68 static const struct i2c_device_id st_press_id_table[] = {
69 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
70 { LPS25H_PRESS_DEV_NAME, LPS25H },
71 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
72 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
73 { LPS33HW_PRESS_DEV_NAME, LPS33HW },
74 { LPS35HW_PRESS_DEV_NAME, LPS35HW },
75 { LPS22HH_PRESS_DEV_NAME, LPS22HH },
76 {},
78 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
80 static int st_press_i2c_probe(struct i2c_client *client,
81 const struct i2c_device_id *id)
83 struct iio_dev *indio_dev;
84 struct st_sensor_data *press_data;
85 int ret;
87 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
88 if (!indio_dev)
89 return -ENOMEM;
91 press_data = iio_priv(indio_dev);
93 if (client->dev.of_node) {
94 st_sensors_of_name_probe(&client->dev, st_press_of_match,
95 client->name, sizeof(client->name));
96 } else if (ACPI_HANDLE(&client->dev)) {
97 ret = st_sensors_match_acpi_device(&client->dev);
98 if ((ret < 0) || (ret >= ST_PRESS_MAX))
99 return -ENODEV;
101 strlcpy(client->name, st_press_id_table[ret].name,
102 sizeof(client->name));
103 } else if (!id)
104 return -ENODEV;
106 st_sensors_i2c_configure(indio_dev, client, press_data);
108 ret = st_press_common_probe(indio_dev);
109 if (ret < 0)
110 return ret;
112 return 0;
115 static int st_press_i2c_remove(struct i2c_client *client)
117 st_press_common_remove(i2c_get_clientdata(client));
119 return 0;
122 static struct i2c_driver st_press_driver = {
123 .driver = {
124 .name = "st-press-i2c",
125 .of_match_table = of_match_ptr(st_press_of_match),
126 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
128 .probe = st_press_i2c_probe,
129 .remove = st_press_i2c_remove,
130 .id_table = st_press_id_table,
132 module_i2c_driver(st_press_driver);
134 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
135 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
136 MODULE_LICENSE("GPL v2");