xref: /linux/drivers/iio/pressure/st_pressure_i2c.c (revision 7cf15f4275f5b478035c1422a15fe049829cc34c)
1fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2217494e5SDenis CIOCCA /*
3217494e5SDenis CIOCCA  * STMicroelectronics pressures driver
4217494e5SDenis CIOCCA  *
5217494e5SDenis CIOCCA  * Copyright 2013 STMicroelectronics Inc.
6217494e5SDenis CIOCCA  *
7217494e5SDenis CIOCCA  * Denis Ciocca <denis.ciocca@st.com>
8217494e5SDenis CIOCCA  */
9217494e5SDenis CIOCCA 
109c6cd755SJonathan Cameron #include <linux/acpi.h>
11217494e5SDenis CIOCCA #include <linux/kernel.h>
12217494e5SDenis CIOCCA #include <linux/module.h>
139c6cd755SJonathan Cameron #include <linux/mod_devicetable.h>
14217494e5SDenis CIOCCA #include <linux/i2c.h>
15217494e5SDenis CIOCCA #include <linux/iio/iio.h>
16217494e5SDenis CIOCCA 
17217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors.h>
18217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors_i2c.h>
19217494e5SDenis CIOCCA #include "st_pressure.h"
20217494e5SDenis CIOCCA 
212d7768a8SLinus Walleij static const struct of_device_id st_press_of_match[] = {
222d7768a8SLinus Walleij 	{
232d7768a8SLinus Walleij 		.compatible = "st,lps001wp-press",
242d7768a8SLinus Walleij 		.data = LPS001WP_PRESS_DEV_NAME,
252d7768a8SLinus Walleij 	},
262d7768a8SLinus Walleij 	{
272d7768a8SLinus Walleij 		.compatible = "st,lps25h-press",
282d7768a8SLinus Walleij 		.data = LPS25H_PRESS_DEV_NAME,
292d7768a8SLinus Walleij 	},
302d7768a8SLinus Walleij 	{
312d7768a8SLinus Walleij 		.compatible = "st,lps331ap-press",
322d7768a8SLinus Walleij 		.data = LPS331AP_PRESS_DEV_NAME,
332d7768a8SLinus Walleij 	},
34e039e2f5SGregor Boirie 	{
35e039e2f5SGregor Boirie 		.compatible = "st,lps22hb-press",
36e039e2f5SGregor Boirie 		.data = LPS22HB_PRESS_DEV_NAME,
37e039e2f5SGregor Boirie 	},
38b954d77aSLorenzo Bianconi 	{
39b954d77aSLorenzo Bianconi 		.compatible = "st,lps33hw",
40b954d77aSLorenzo Bianconi 		.data = LPS33HW_PRESS_DEV_NAME,
41b954d77aSLorenzo Bianconi 	},
42b954d77aSLorenzo Bianconi 	{
43b954d77aSLorenzo Bianconi 		.compatible = "st,lps35hw",
44b954d77aSLorenzo Bianconi 		.data = LPS35HW_PRESS_DEV_NAME,
45b954d77aSLorenzo Bianconi 	},
46e5aab7b0Smario tesi 	{
47e5aab7b0Smario tesi 		.compatible = "st,lps22hh",
48e5aab7b0Smario tesi 		.data = LPS22HH_PRESS_DEV_NAME,
49e5aab7b0Smario tesi 	},
5092ba0ab9SMartyn Welch 	{
5192ba0ab9SMartyn Welch 		.compatible = "st,lps22df",
5292ba0ab9SMartyn Welch 		.data = LPS22DF_PRESS_DEV_NAME,
5392ba0ab9SMartyn Welch 	},
542d7768a8SLinus Walleij 	{},
552d7768a8SLinus Walleij };
562d7768a8SLinus Walleij MODULE_DEVICE_TABLE(of, st_press_of_match);
572d7768a8SLinus Walleij 
589d317724SShrirang Bagul #ifdef CONFIG_ACPI
599d317724SShrirang Bagul static const struct acpi_device_id st_press_acpi_match[] = {
609d317724SShrirang Bagul 	{"SNO9210", LPS22HB},
619d317724SShrirang Bagul 	{ },
629d317724SShrirang Bagul };
639d317724SShrirang Bagul MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
649d317724SShrirang Bagul #endif
659d317724SShrirang Bagul 
669d317724SShrirang Bagul static const struct i2c_device_id st_press_id_table[] = {
679d317724SShrirang Bagul 	{ LPS001WP_PRESS_DEV_NAME, LPS001WP },
689d317724SShrirang Bagul 	{ LPS25H_PRESS_DEV_NAME,  LPS25H },
699d317724SShrirang Bagul 	{ LPS331AP_PRESS_DEV_NAME, LPS331AP },
709d317724SShrirang Bagul 	{ LPS22HB_PRESS_DEV_NAME, LPS22HB },
71b954d77aSLorenzo Bianconi 	{ LPS33HW_PRESS_DEV_NAME, LPS33HW },
72b954d77aSLorenzo Bianconi 	{ LPS35HW_PRESS_DEV_NAME, LPS35HW },
73e5aab7b0Smario tesi 	{ LPS22HH_PRESS_DEV_NAME, LPS22HH },
7492ba0ab9SMartyn Welch 	{ LPS22DF_PRESS_DEV_NAME, LPS22DF },
759d317724SShrirang Bagul 	{},
769d317724SShrirang Bagul };
779d317724SShrirang Bagul MODULE_DEVICE_TABLE(i2c, st_press_id_table);
789d317724SShrirang Bagul 
79a52833a5SUwe Kleine-König static int st_press_i2c_probe(struct i2c_client *client)
80217494e5SDenis CIOCCA {
81570c2c55SDenis Ciocca 	const struct st_sensor_settings *settings;
82a1dcf429SDenis CIOCCA 	struct st_sensor_data *press_data;
83570c2c55SDenis Ciocca 	struct iio_dev *indio_dev;
849d317724SShrirang Bagul 	int ret;
85217494e5SDenis CIOCCA 
86efc78983SAndy Shevchenko 	st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
87217494e5SDenis CIOCCA 
88570c2c55SDenis Ciocca 	settings = st_press_get_settings(client->name);
89570c2c55SDenis Ciocca 	if (!settings) {
90570c2c55SDenis Ciocca 		dev_err(&client->dev, "device name %s not recognized.\n",
91570c2c55SDenis Ciocca 			client->name);
92570c2c55SDenis Ciocca 		return -ENODEV;
93570c2c55SDenis Ciocca 	}
94570c2c55SDenis Ciocca 
95570c2c55SDenis Ciocca 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
96570c2c55SDenis Ciocca 	if (!indio_dev)
97570c2c55SDenis Ciocca 		return -ENOMEM;
98570c2c55SDenis Ciocca 
99570c2c55SDenis Ciocca 	press_data = iio_priv(indio_dev);
100570c2c55SDenis Ciocca 	press_data->sensor_settings = (struct st_sensor_settings *)settings;
101570c2c55SDenis Ciocca 
102062809efSDenis Ciocca 	ret = st_sensors_i2c_configure(indio_dev, client);
103062809efSDenis Ciocca 	if (ret < 0)
104062809efSDenis Ciocca 		return ret;
105217494e5SDenis CIOCCA 
1067db4f2caSAndy Shevchenko 	ret = st_sensors_power_enable(indio_dev);
1077db4f2caSAndy Shevchenko 	if (ret)
1089d317724SShrirang Bagul 		return ret;
109217494e5SDenis CIOCCA 
1105363c6c1SAlexandru Ardelean 	return st_press_common_probe(indio_dev);
111217494e5SDenis CIOCCA }
112217494e5SDenis CIOCCA 
113217494e5SDenis CIOCCA static struct i2c_driver st_press_driver = {
114217494e5SDenis CIOCCA 	.driver = {
115217494e5SDenis CIOCCA 		.name = "st-press-i2c",
116ecb27c5eSAndy Shevchenko 		.of_match_table = st_press_of_match,
1179d317724SShrirang Bagul 		.acpi_match_table = ACPI_PTR(st_press_acpi_match),
118217494e5SDenis CIOCCA 	},
119*7cf15f42SUwe Kleine-König 	.probe = st_press_i2c_probe,
120217494e5SDenis CIOCCA 	.id_table = st_press_id_table,
121217494e5SDenis CIOCCA };
122217494e5SDenis CIOCCA module_i2c_driver(st_press_driver);
123217494e5SDenis CIOCCA 
124217494e5SDenis CIOCCA MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
125217494e5SDenis CIOCCA MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
126217494e5SDenis CIOCCA MODULE_LICENSE("GPL v2");
1270805b512SJonathan Cameron MODULE_IMPORT_NS(IIO_ST_SENSORS);
128