Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-block.git] / drivers / iio / accel / st_accel_i2c.c
CommitLineData
fda8d26e 1// SPDX-License-Identifier: GPL-2.0-only
d6251168
DC
2/*
3 * STMicroelectronics accelerometers driver
4 *
5 * Copyright 2012-2013 STMicroelectronics Inc.
6 *
7 * Denis Ciocca <denis.ciocca@st.com>
d6251168
DC
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
9c6cd755 12#include <linux/mod_devicetable.h>
d6251168
DC
13#include <linux/i2c.h>
14#include <linux/iio/iio.h>
d6251168 15
d6251168
DC
16#include <linux/iio/common/st_sensors_i2c.h>
17#include "st_accel.h"
18
2d7768a8 19static const struct of_device_id st_accel_of_match[] = {
76222772
LW
20 {
21 /* An older compatible */
22 .compatible = "st,lis3lv02d",
23 .data = LIS3LV02DL_ACCEL_DEV_NAME,
24 },
3acddf74
LW
25 {
26 .compatible = "st,lis3lv02dl-accel",
27 .data = LIS3LV02DL_ACCEL_DEV_NAME,
28 },
2d7768a8
LW
29 {
30 .compatible = "st,lsm303dlh-accel",
31 .data = LSM303DLH_ACCEL_DEV_NAME,
32 },
33 {
34 .compatible = "st,lsm303dlhc-accel",
35 .data = LSM303DLHC_ACCEL_DEV_NAME,
36 },
37 {
38 .compatible = "st,lis3dh-accel",
39 .data = LIS3DH_ACCEL_DEV_NAME,
40 },
41 {
42 .compatible = "st,lsm330d-accel",
43 .data = LSM330D_ACCEL_DEV_NAME,
44 },
45 {
46 .compatible = "st,lsm330dl-accel",
47 .data = LSM330DL_ACCEL_DEV_NAME,
48 },
49 {
50 .compatible = "st,lsm330dlc-accel",
51 .data = LSM330DLC_ACCEL_DEV_NAME,
52 },
bbf5f037
LW
53 {
54 .compatible = "st,lis331dl-accel",
55 .data = LIS331DL_ACCEL_DEV_NAME,
56 },
2d7768a8
LW
57 {
58 .compatible = "st,lis331dlh-accel",
59 .data = LIS331DLH_ACCEL_DEV_NAME,
60 },
61 {
62 .compatible = "st,lsm303dl-accel",
63 .data = LSM303DL_ACCEL_DEV_NAME,
64 },
65 {
66 .compatible = "st,lsm303dlm-accel",
67 .data = LSM303DLM_ACCEL_DEV_NAME,
68 },
69 {
70 .compatible = "st,lsm330-accel",
71 .data = LSM330_ACCEL_DEV_NAME,
72 },
ddc05fa2
GB
73 {
74 .compatible = "st,lsm303agr-accel",
75 .data = LSM303AGR_ACCEL_DEV_NAME,
76 },
34dc578d
GB
77 {
78 .compatible = "st,lis2dh12-accel",
79 .data = LIS2DH12_ACCEL_DEV_NAME,
80 },
1e52fefc
TB
81 {
82 .compatible = "st,h3lis331dl-accel",
b30f1593 83 .data = H3LIS331DL_ACCEL_DEV_NAME,
1e52fefc 84 },
4e68cfbf
JC
85 {
86 .compatible = "st,lis3l02dq",
87 .data = LIS3L02DQ_ACCEL_DEV_NAME,
88 },
dcdb0a78
LB
89 {
90 .compatible = "st,lng2dm-accel",
91 .data = LNG2DM_ACCEL_DEV_NAME,
92 },
f94124f9
LB
93 {
94 .compatible = "st,lis2dw12",
95 .data = LIS2DW12_ACCEL_DEV_NAME,
96 },
49b62373
HS
97 {
98 .compatible = "st,lis3de",
99 .data = LIS3DE_ACCEL_DEV_NAME,
100 },
63440a63
RJ
101 {
102 .compatible = "st,lis2de12",
103 .data = LIS2DE12_ACCEL_DEV_NAME,
104 },
f168a6db
KC
105 {
106 .compatible = "st,lis2ds12",
107 .data = LIS2DS12_ACCEL_DEV_NAME,
108 },
3f4a559b
GA
109 {
110 .compatible = "st,lis2hh12",
111 .data = LIS2HH12_ACCEL_DEV_NAME,
112 },
8a7449d6
SM
113 {
114 .compatible = "st,lis302dl",
115 .data = LIS302DL_ACCEL_DEV_NAME,
116 },
23fd6f0b
SG
117 {
118 .compatible = "st,lsm303c-accel",
119 .data = LSM303C_ACCEL_DEV_NAME,
120 },
c7a43b08
SH
121 {
122 .compatible = "silan,sc7a20",
123 .data = SC7A20_ACCEL_DEV_NAME,
124 },
46e33707
SW
125 {
126 .compatible = "st,iis328dq",
127 .data = IIS328DQ_ACCEL_DEV_NAME,
128 },
70788d26 129 { }
2d7768a8
LW
130};
131MODULE_DEVICE_TABLE(of, st_accel_of_match);
2d7768a8 132
89a2a93f 133static const struct acpi_device_id st_accel_acpi_match[] = {
e43d110c 134 {"SMO8840", (kernel_ulong_t)LIS2DH12_ACCEL_DEV_NAME},
19868faa 135 {"SMO8A90", (kernel_ulong_t)LNG2DM_ACCEL_DEV_NAME},
70788d26 136 { }
89a2a93f
SB
137};
138MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match);
89a2a93f
SB
139
140static const struct i2c_device_id st_accel_id_table[] = {
19868faa
NV
141 { LSM303DLH_ACCEL_DEV_NAME },
142 { LSM303DLHC_ACCEL_DEV_NAME },
143 { LIS3DH_ACCEL_DEV_NAME },
144 { LSM330D_ACCEL_DEV_NAME },
145 { LSM330DL_ACCEL_DEV_NAME },
146 { LSM330DLC_ACCEL_DEV_NAME },
147 { LIS331DLH_ACCEL_DEV_NAME },
148 { LSM303DL_ACCEL_DEV_NAME },
149 { LSM303DLM_ACCEL_DEV_NAME },
150 { LSM330_ACCEL_DEV_NAME },
151 { LSM303AGR_ACCEL_DEV_NAME },
152 { LIS2DH12_ACCEL_DEV_NAME },
153 { LIS3L02DQ_ACCEL_DEV_NAME },
154 { LNG2DM_ACCEL_DEV_NAME },
155 { H3LIS331DL_ACCEL_DEV_NAME },
156 { LIS331DL_ACCEL_DEV_NAME },
157 { LIS3LV02DL_ACCEL_DEV_NAME },
158 { LIS2DW12_ACCEL_DEV_NAME },
49b62373 159 { LIS3DE_ACCEL_DEV_NAME },
63440a63 160 { LIS2DE12_ACCEL_DEV_NAME },
f168a6db 161 { LIS2DS12_ACCEL_DEV_NAME },
3f4a559b 162 { LIS2HH12_ACCEL_DEV_NAME },
8a7449d6 163 { LIS302DL_ACCEL_DEV_NAME },
23fd6f0b 164 { LSM303C_ACCEL_DEV_NAME },
c7a43b08 165 { SC7A20_ACCEL_DEV_NAME },
46e33707 166 { IIS328DQ_ACCEL_DEV_NAME },
70788d26 167 { }
89a2a93f
SB
168};
169MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
170
6b0b3e37 171static int st_accel_i2c_probe(struct i2c_client *client)
d6251168 172{
feba6b18 173 const struct st_sensor_settings *settings;
d6251168 174 struct st_sensor_data *adata;
feba6b18 175 struct iio_dev *indio_dev;
89a2a93f 176 int ret;
d6251168 177
35752815 178 st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
feba6b18
DC
179
180 settings = st_accel_get_settings(client->name);
181 if (!settings) {
182 dev_err(&client->dev, "device name %s not recognized.\n",
183 client->name);
184 return -ENODEV;
185 }
186
6b7e0a9c
SK
187 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
188 if (!indio_dev)
189 return -ENOMEM;
d6251168
DC
190
191 adata = iio_priv(indio_dev);
feba6b18 192 adata->sensor_settings = (struct st_sensor_settings *)settings;
d6251168 193
062809ef
DC
194 ret = st_sensors_i2c_configure(indio_dev, client);
195 if (ret < 0)
196 return ret;
d6251168 197
7db4f2ca
AS
198 ret = st_sensors_power_enable(indio_dev);
199 if (ret)
200 return ret;
201
5363c6c1 202 return st_accel_common_probe(indio_dev);
d6251168
DC
203}
204
d6251168
DC
205static struct i2c_driver st_accel_driver = {
206 .driver = {
d6251168 207 .name = "st-accel-i2c",
ecb27c5e 208 .of_match_table = st_accel_of_match,
042ffa6d 209 .acpi_match_table = st_accel_acpi_match,
d6251168 210 },
7cf15f42 211 .probe = st_accel_i2c_probe,
d6251168
DC
212 .id_table = st_accel_id_table,
213};
214module_i2c_driver(st_accel_driver);
215
216MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
217MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
218MODULE_LICENSE("GPL v2");
cdd30ebb 219MODULE_IMPORT_NS("IIO_ST_SENSORS");