xref: /linux/drivers/iio/pressure/st_pressure_i2c.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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 
10217494e5SDenis CIOCCA #include <linux/kernel.h>
11217494e5SDenis CIOCCA #include <linux/module.h>
129c6cd755SJonathan Cameron #include <linux/mod_devicetable.h>
13217494e5SDenis CIOCCA #include <linux/i2c.h>
14217494e5SDenis CIOCCA #include <linux/iio/iio.h>
15217494e5SDenis CIOCCA 
16217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors.h>
17217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors_i2c.h>
18217494e5SDenis CIOCCA #include "st_pressure.h"
19217494e5SDenis CIOCCA 
202d7768a8SLinus Walleij static const struct of_device_id st_press_of_match[] = {
212d7768a8SLinus Walleij 	{
222d7768a8SLinus Walleij 		.compatible = "st,lps001wp-press",
232d7768a8SLinus Walleij 		.data = LPS001WP_PRESS_DEV_NAME,
242d7768a8SLinus Walleij 	},
252d7768a8SLinus Walleij 	{
262d7768a8SLinus Walleij 		.compatible = "st,lps25h-press",
272d7768a8SLinus Walleij 		.data = LPS25H_PRESS_DEV_NAME,
282d7768a8SLinus Walleij 	},
292d7768a8SLinus Walleij 	{
302d7768a8SLinus Walleij 		.compatible = "st,lps331ap-press",
312d7768a8SLinus Walleij 		.data = LPS331AP_PRESS_DEV_NAME,
322d7768a8SLinus Walleij 	},
33e039e2f5SGregor Boirie 	{
34e039e2f5SGregor Boirie 		.compatible = "st,lps22hb-press",
35e039e2f5SGregor Boirie 		.data = LPS22HB_PRESS_DEV_NAME,
36e039e2f5SGregor Boirie 	},
37b954d77aSLorenzo Bianconi 	{
38b954d77aSLorenzo Bianconi 		.compatible = "st,lps33hw",
39b954d77aSLorenzo Bianconi 		.data = LPS33HW_PRESS_DEV_NAME,
40b954d77aSLorenzo Bianconi 	},
41b954d77aSLorenzo Bianconi 	{
42b954d77aSLorenzo Bianconi 		.compatible = "st,lps35hw",
43b954d77aSLorenzo Bianconi 		.data = LPS35HW_PRESS_DEV_NAME,
44b954d77aSLorenzo Bianconi 	},
45e5aab7b0Smario tesi 	{
46e5aab7b0Smario tesi 		.compatible = "st,lps22hh",
47e5aab7b0Smario tesi 		.data = LPS22HH_PRESS_DEV_NAME,
48e5aab7b0Smario tesi 	},
4992ba0ab9SMartyn Welch 	{
5092ba0ab9SMartyn Welch 		.compatible = "st,lps22df",
5192ba0ab9SMartyn Welch 		.data = LPS22DF_PRESS_DEV_NAME,
5292ba0ab9SMartyn Welch 	},
532d7768a8SLinus Walleij 	{},
542d7768a8SLinus Walleij };
552d7768a8SLinus Walleij MODULE_DEVICE_TABLE(of, st_press_of_match);
562d7768a8SLinus Walleij 
579d317724SShrirang Bagul static const struct acpi_device_id st_press_acpi_match[] = {
589d317724SShrirang Bagul 	{"SNO9210", LPS22HB},
599d317724SShrirang Bagul 	{ },
609d317724SShrirang Bagul };
619d317724SShrirang Bagul MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
629d317724SShrirang Bagul 
639d317724SShrirang Bagul static const struct i2c_device_id st_press_id_table[] = {
649d317724SShrirang Bagul 	{ LPS001WP_PRESS_DEV_NAME, LPS001WP },
659d317724SShrirang Bagul 	{ LPS25H_PRESS_DEV_NAME,  LPS25H },
669d317724SShrirang Bagul 	{ LPS331AP_PRESS_DEV_NAME, LPS331AP },
679d317724SShrirang Bagul 	{ LPS22HB_PRESS_DEV_NAME, LPS22HB },
68b954d77aSLorenzo Bianconi 	{ LPS33HW_PRESS_DEV_NAME, LPS33HW },
69b954d77aSLorenzo Bianconi 	{ LPS35HW_PRESS_DEV_NAME, LPS35HW },
70e5aab7b0Smario tesi 	{ LPS22HH_PRESS_DEV_NAME, LPS22HH },
7192ba0ab9SMartyn Welch 	{ LPS22DF_PRESS_DEV_NAME, LPS22DF },
729d317724SShrirang Bagul 	{},
739d317724SShrirang Bagul };
749d317724SShrirang Bagul MODULE_DEVICE_TABLE(i2c, st_press_id_table);
759d317724SShrirang Bagul 
st_press_i2c_probe(struct i2c_client * client)76a52833a5SUwe Kleine-König static int st_press_i2c_probe(struct i2c_client *client)
77217494e5SDenis CIOCCA {
78570c2c55SDenis Ciocca 	const struct st_sensor_settings *settings;
79a1dcf429SDenis CIOCCA 	struct st_sensor_data *press_data;
80570c2c55SDenis Ciocca 	struct iio_dev *indio_dev;
819d317724SShrirang Bagul 	int ret;
82217494e5SDenis CIOCCA 
83efc78983SAndy Shevchenko 	st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
84217494e5SDenis CIOCCA 
85570c2c55SDenis Ciocca 	settings = st_press_get_settings(client->name);
86570c2c55SDenis Ciocca 	if (!settings) {
87570c2c55SDenis Ciocca 		dev_err(&client->dev, "device name %s not recognized.\n",
88570c2c55SDenis Ciocca 			client->name);
89570c2c55SDenis Ciocca 		return -ENODEV;
90570c2c55SDenis Ciocca 	}
91570c2c55SDenis Ciocca 
92570c2c55SDenis Ciocca 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
93570c2c55SDenis Ciocca 	if (!indio_dev)
94570c2c55SDenis Ciocca 		return -ENOMEM;
95570c2c55SDenis Ciocca 
96570c2c55SDenis Ciocca 	press_data = iio_priv(indio_dev);
97570c2c55SDenis Ciocca 	press_data->sensor_settings = (struct st_sensor_settings *)settings;
98570c2c55SDenis Ciocca 
99062809efSDenis Ciocca 	ret = st_sensors_i2c_configure(indio_dev, client);
100062809efSDenis Ciocca 	if (ret < 0)
101062809efSDenis Ciocca 		return ret;
102217494e5SDenis CIOCCA 
1037db4f2caSAndy Shevchenko 	ret = st_sensors_power_enable(indio_dev);
1047db4f2caSAndy Shevchenko 	if (ret)
1059d317724SShrirang Bagul 		return ret;
106217494e5SDenis CIOCCA 
1075363c6c1SAlexandru Ardelean 	return st_press_common_probe(indio_dev);
108217494e5SDenis CIOCCA }
109217494e5SDenis CIOCCA 
110217494e5SDenis CIOCCA static struct i2c_driver st_press_driver = {
111217494e5SDenis CIOCCA 	.driver = {
112217494e5SDenis CIOCCA 		.name = "st-press-i2c",
113ecb27c5eSAndy Shevchenko 		.of_match_table = st_press_of_match,
114*042ffa6dSJonathan Cameron 		.acpi_match_table = st_press_acpi_match,
115217494e5SDenis CIOCCA 	},
1167cf15f42SUwe Kleine-König 	.probe = st_press_i2c_probe,
117217494e5SDenis CIOCCA 	.id_table = st_press_id_table,
118217494e5SDenis CIOCCA };
119217494e5SDenis CIOCCA module_i2c_driver(st_press_driver);
120217494e5SDenis CIOCCA 
121217494e5SDenis CIOCCA MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
122217494e5SDenis CIOCCA MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
123217494e5SDenis CIOCCA MODULE_LICENSE("GPL v2");
1240805b512SJonathan Cameron MODULE_IMPORT_NS(IIO_ST_SENSORS);
125