]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/iio/pressure/st_pressure_i2c.c
a60849dd4ea7bf63d2f18ea09de03ca84c8d10b0
[mirror_ubuntu-eoan-kernel.git] / drivers / iio / pressure / st_pressure_i2c.c
1 /*
2 * STMicroelectronics pressures driver
3 *
4 * Copyright 2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
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>
17
18 #include <linux/iio/common/st_sensors.h>
19 #include <linux/iio/common/st_sensors_i2c.h>
20 #include "st_pressure.h"
21
22 #ifdef CONFIG_OF
23 static const struct of_device_id st_press_of_match[] = {
24 {
25 .compatible = "st,lps001wp-press",
26 .data = LPS001WP_PRESS_DEV_NAME,
27 },
28 {
29 .compatible = "st,lps25h-press",
30 .data = LPS25H_PRESS_DEV_NAME,
31 },
32 {
33 .compatible = "st,lps331ap-press",
34 .data = LPS331AP_PRESS_DEV_NAME,
35 },
36 {
37 .compatible = "st,lps22hb-press",
38 .data = LPS22HB_PRESS_DEV_NAME,
39 },
40 {
41 .compatible = "st,lps33hw",
42 .data = LPS33HW_PRESS_DEV_NAME,
43 },
44 {
45 .compatible = "st,lps35hw",
46 .data = LPS35HW_PRESS_DEV_NAME,
47 },
48 {
49 .compatible = "st,lps22hh",
50 .data = LPS22HH_PRESS_DEV_NAME,
51 },
52 {},
53 };
54 MODULE_DEVICE_TABLE(of, st_press_of_match);
55 #else
56 #define st_press_of_match NULL
57 #endif
58
59 #ifdef CONFIG_ACPI
60 static const struct acpi_device_id st_press_acpi_match[] = {
61 {"SNO9210", LPS22HB},
62 { },
63 };
64 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
65 #else
66 #define st_press_acpi_match NULL
67 #endif
68
69 static const struct i2c_device_id st_press_id_table[] = {
70 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
71 { LPS25H_PRESS_DEV_NAME, LPS25H },
72 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
73 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
74 { LPS33HW_PRESS_DEV_NAME, LPS33HW },
75 { LPS35HW_PRESS_DEV_NAME, LPS35HW },
76 { LPS22HH_PRESS_DEV_NAME, LPS22HH },
77 {},
78 };
79 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
80
81 static int st_press_i2c_probe(struct i2c_client *client,
82 const struct i2c_device_id *id)
83 {
84 struct iio_dev *indio_dev;
85 struct st_sensor_data *press_data;
86 int ret;
87
88 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
89 if (!indio_dev)
90 return -ENOMEM;
91
92 press_data = iio_priv(indio_dev);
93
94 if (client->dev.of_node) {
95 st_sensors_of_name_probe(&client->dev, st_press_of_match,
96 client->name, sizeof(client->name));
97 } else if (ACPI_HANDLE(&client->dev)) {
98 ret = st_sensors_match_acpi_device(&client->dev);
99 if ((ret < 0) || (ret >= ST_PRESS_MAX))
100 return -ENODEV;
101
102 strlcpy(client->name, st_press_id_table[ret].name,
103 sizeof(client->name));
104 } else if (!id)
105 return -ENODEV;
106
107 st_sensors_i2c_configure(indio_dev, client, press_data);
108
109 ret = st_press_common_probe(indio_dev);
110 if (ret < 0)
111 return ret;
112
113 return 0;
114 }
115
116 static int st_press_i2c_remove(struct i2c_client *client)
117 {
118 st_press_common_remove(i2c_get_clientdata(client));
119
120 return 0;
121 }
122
123 static struct i2c_driver st_press_driver = {
124 .driver = {
125 .name = "st-press-i2c",
126 .of_match_table = of_match_ptr(st_press_of_match),
127 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
128 },
129 .probe = st_press_i2c_probe,
130 .remove = st_press_i2c_remove,
131 .id_table = st_press_id_table,
132 };
133 module_i2c_driver(st_press_driver);
134
135 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
136 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
137 MODULE_LICENSE("GPL v2");