1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics accelerometers driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/acpi.h>
14 #include <linux/i2c.h>
15 #include <linux/iio/iio.h>
17 #include <linux/iio/common/st_sensors_i2c.h>
20 static const struct of_device_id st_accel_of_match[] = {
22 /* An older compatible */
23 .compatible = "st,lis3lv02d",
24 .data = LIS3LV02DL_ACCEL_DEV_NAME,
27 .compatible = "st,lis3lv02dl-accel",
28 .data = LIS3LV02DL_ACCEL_DEV_NAME,
31 .compatible = "st,lsm303dlh-accel",
32 .data = LSM303DLH_ACCEL_DEV_NAME,
35 .compatible = "st,lsm303dlhc-accel",
36 .data = LSM303DLHC_ACCEL_DEV_NAME,
39 .compatible = "st,lis3dh-accel",
40 .data = LIS3DH_ACCEL_DEV_NAME,
43 .compatible = "st,lsm330d-accel",
44 .data = LSM330D_ACCEL_DEV_NAME,
47 .compatible = "st,lsm330dl-accel",
48 .data = LSM330DL_ACCEL_DEV_NAME,
51 .compatible = "st,lsm330dlc-accel",
52 .data = LSM330DLC_ACCEL_DEV_NAME,
55 .compatible = "st,lis331dl-accel",
56 .data = LIS331DL_ACCEL_DEV_NAME,
59 .compatible = "st,lis331dlh-accel",
60 .data = LIS331DLH_ACCEL_DEV_NAME,
63 .compatible = "st,lsm303dl-accel",
64 .data = LSM303DL_ACCEL_DEV_NAME,
67 .compatible = "st,lsm303dlm-accel",
68 .data = LSM303DLM_ACCEL_DEV_NAME,
71 .compatible = "st,lsm330-accel",
72 .data = LSM330_ACCEL_DEV_NAME,
75 .compatible = "st,lsm303agr-accel",
76 .data = LSM303AGR_ACCEL_DEV_NAME,
79 .compatible = "st,lis2dh12-accel",
80 .data = LIS2DH12_ACCEL_DEV_NAME,
83 .compatible = "st,h3lis331dl-accel",
84 .data = H3LIS331DL_ACCEL_DEV_NAME,
87 .compatible = "st,lis3l02dq",
88 .data = LIS3L02DQ_ACCEL_DEV_NAME,
91 .compatible = "st,lng2dm-accel",
92 .data = LNG2DM_ACCEL_DEV_NAME,
95 .compatible = "st,lis2dw12",
96 .data = LIS2DW12_ACCEL_DEV_NAME,
99 .compatible = "st,lis3de",
100 .data = LIS3DE_ACCEL_DEV_NAME,
103 .compatible = "st,lis2de12",
104 .data = LIS2DE12_ACCEL_DEV_NAME,
107 .compatible = "st,lis2hh12",
108 .data = LIS2HH12_ACCEL_DEV_NAME,
112 MODULE_DEVICE_TABLE(of, st_accel_of_match);
115 static const struct acpi_device_id st_accel_acpi_match[] = {
116 {"SMO8840", (kernel_ulong_t)LIS2DH12_ACCEL_DEV_NAME},
117 {"SMO8A90", (kernel_ulong_t)LNG2DM_ACCEL_DEV_NAME},
120 MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match);
123 static const struct i2c_device_id st_accel_id_table[] = {
124 { LSM303DLH_ACCEL_DEV_NAME },
125 { LSM303DLHC_ACCEL_DEV_NAME },
126 { LIS3DH_ACCEL_DEV_NAME },
127 { LSM330D_ACCEL_DEV_NAME },
128 { LSM330DL_ACCEL_DEV_NAME },
129 { LSM330DLC_ACCEL_DEV_NAME },
130 { LIS331DLH_ACCEL_DEV_NAME },
131 { LSM303DL_ACCEL_DEV_NAME },
132 { LSM303DLM_ACCEL_DEV_NAME },
133 { LSM330_ACCEL_DEV_NAME },
134 { LSM303AGR_ACCEL_DEV_NAME },
135 { LIS2DH12_ACCEL_DEV_NAME },
136 { LIS3L02DQ_ACCEL_DEV_NAME },
137 { LNG2DM_ACCEL_DEV_NAME },
138 { H3LIS331DL_ACCEL_DEV_NAME },
139 { LIS331DL_ACCEL_DEV_NAME },
140 { LIS3LV02DL_ACCEL_DEV_NAME },
141 { LIS2DW12_ACCEL_DEV_NAME },
142 { LIS3DE_ACCEL_DEV_NAME },
143 { LIS2DE12_ACCEL_DEV_NAME },
144 { LIS2HH12_ACCEL_DEV_NAME },
147 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
149 static int st_accel_i2c_probe(struct i2c_client *client)
151 const struct st_sensor_settings *settings;
152 struct st_sensor_data *adata;
153 struct iio_dev *indio_dev;
156 st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
158 settings = st_accel_get_settings(client->name);
160 dev_err(&client->dev, "device name %s not recognized.\n",
165 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
169 adata = iio_priv(indio_dev);
170 adata->sensor_settings = (struct st_sensor_settings *)settings;
172 ret = st_sensors_i2c_configure(indio_dev, client);
176 ret = st_sensors_power_enable(indio_dev);
180 ret = st_accel_common_probe(indio_dev);
182 goto st_accel_power_off;
187 st_sensors_power_disable(indio_dev);
192 static int st_accel_i2c_remove(struct i2c_client *client)
194 struct iio_dev *indio_dev = i2c_get_clientdata(client);
196 st_accel_common_remove(indio_dev);
198 st_sensors_power_disable(indio_dev);
203 static struct i2c_driver st_accel_driver = {
205 .name = "st-accel-i2c",
206 .of_match_table = st_accel_of_match,
207 .acpi_match_table = ACPI_PTR(st_accel_acpi_match),
209 .probe_new = st_accel_i2c_probe,
210 .remove = st_accel_i2c_remove,
211 .id_table = st_accel_id_table,
213 module_i2c_driver(st_accel_driver);
215 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
216 MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
217 MODULE_LICENSE("GPL v2");