xref: /linux/drivers/iio/pressure/st_pressure_i2c.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * STMicroelectronics pressures driver
4  *
5  * Copyright 2013 STMicroelectronics Inc.
6  *
7  * Denis Ciocca <denis.ciocca@st.com>
8  */
9 
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/i2c.h>
14 #include <linux/iio/iio.h>
15 
16 #include <linux/iio/common/st_sensors.h>
17 #include <linux/iio/common/st_sensors_i2c.h>
18 #include "st_pressure.h"
19 
20 static const struct of_device_id st_press_of_match[] = {
21 	{
22 		.compatible = "st,lps001wp-press",
23 		.data = LPS001WP_PRESS_DEV_NAME,
24 	},
25 	{
26 		.compatible = "st,lps25h-press",
27 		.data = LPS25H_PRESS_DEV_NAME,
28 	},
29 	{
30 		.compatible = "st,lps331ap-press",
31 		.data = LPS331AP_PRESS_DEV_NAME,
32 	},
33 	{
34 		.compatible = "st,lps22hb-press",
35 		.data = LPS22HB_PRESS_DEV_NAME,
36 	},
37 	{
38 		.compatible = "st,lps33hw",
39 		.data = LPS33HW_PRESS_DEV_NAME,
40 	},
41 	{
42 		.compatible = "st,lps35hw",
43 		.data = LPS35HW_PRESS_DEV_NAME,
44 	},
45 	{
46 		.compatible = "st,lps22hh",
47 		.data = LPS22HH_PRESS_DEV_NAME,
48 	},
49 	{
50 		.compatible = "st,lps22df",
51 		.data = LPS22DF_PRESS_DEV_NAME,
52 	},
53 	{},
54 };
55 MODULE_DEVICE_TABLE(of, st_press_of_match);
56 
57 static const struct acpi_device_id st_press_acpi_match[] = {
58 	{"SNO9210", LPS22HB},
59 	{ },
60 };
61 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
62 
63 static const struct i2c_device_id st_press_id_table[] = {
64 	{ LPS001WP_PRESS_DEV_NAME, LPS001WP },
65 	{ LPS25H_PRESS_DEV_NAME,  LPS25H },
66 	{ LPS331AP_PRESS_DEV_NAME, LPS331AP },
67 	{ LPS22HB_PRESS_DEV_NAME, LPS22HB },
68 	{ LPS33HW_PRESS_DEV_NAME, LPS33HW },
69 	{ LPS35HW_PRESS_DEV_NAME, LPS35HW },
70 	{ LPS22HH_PRESS_DEV_NAME, LPS22HH },
71 	{ LPS22DF_PRESS_DEV_NAME, LPS22DF },
72 	{},
73 };
74 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
75 
st_press_i2c_probe(struct i2c_client * client)76 static int st_press_i2c_probe(struct i2c_client *client)
77 {
78 	const struct st_sensor_settings *settings;
79 	struct st_sensor_data *press_data;
80 	struct iio_dev *indio_dev;
81 	int ret;
82 
83 	st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
84 
85 	settings = st_press_get_settings(client->name);
86 	if (!settings) {
87 		dev_err(&client->dev, "device name %s not recognized.\n",
88 			client->name);
89 		return -ENODEV;
90 	}
91 
92 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
93 	if (!indio_dev)
94 		return -ENOMEM;
95 
96 	press_data = iio_priv(indio_dev);
97 	press_data->sensor_settings = (struct st_sensor_settings *)settings;
98 
99 	ret = st_sensors_i2c_configure(indio_dev, client);
100 	if (ret < 0)
101 		return ret;
102 
103 	ret = st_sensors_power_enable(indio_dev);
104 	if (ret)
105 		return ret;
106 
107 	return st_press_common_probe(indio_dev);
108 }
109 
110 static struct i2c_driver st_press_driver = {
111 	.driver = {
112 		.name = "st-press-i2c",
113 		.of_match_table = st_press_of_match,
114 		.acpi_match_table = st_press_acpi_match,
115 	},
116 	.probe = st_press_i2c_probe,
117 	.id_table = st_press_id_table,
118 };
119 module_i2c_driver(st_press_driver);
120 
121 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
122 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
123 MODULE_LICENSE("GPL v2");
124 MODULE_IMPORT_NS(IIO_ST_SENSORS);
125