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/spi/spi.h>
14 #include <linux/iio/iio.h>
16 #include <linux/iio/common/st_sensors.h>
17 #include <linux/iio/common/st_sensors_spi.h>
21 * For new single-chip sensors use <device_name> as compatible string.
22 * For old single-chip devices keep <device_name>-accel to maintain
25 static const struct of_device_id st_accel_of_match
[] = {
27 /* An older compatible */
28 .compatible
= "st,lis302dl-spi",
29 .data
= LIS3LV02DL_ACCEL_DEV_NAME
,
32 .compatible
= "st,lis3lv02dl-accel",
33 .data
= LIS3LV02DL_ACCEL_DEV_NAME
,
36 .compatible
= "st,lis3dh-accel",
37 .data
= LIS3DH_ACCEL_DEV_NAME
,
40 .compatible
= "st,lsm330d-accel",
41 .data
= LSM330D_ACCEL_DEV_NAME
,
44 .compatible
= "st,lsm330dl-accel",
45 .data
= LSM330DL_ACCEL_DEV_NAME
,
48 .compatible
= "st,lsm330dlc-accel",
49 .data
= LSM330DLC_ACCEL_DEV_NAME
,
52 .compatible
= "st,lis331dlh-accel",
53 .data
= LIS331DLH_ACCEL_DEV_NAME
,
56 .compatible
= "st,lsm330-accel",
57 .data
= LSM330_ACCEL_DEV_NAME
,
60 .compatible
= "st,lsm303agr-accel",
61 .data
= LSM303AGR_ACCEL_DEV_NAME
,
64 .compatible
= "st,lis2dh12-accel",
65 .data
= LIS2DH12_ACCEL_DEV_NAME
,
68 .compatible
= "st,lis2ds12",
69 .data
= LIS2DS12_ACCEL_DEV_NAME
,
72 .compatible
= "st,lis3l02dq",
73 .data
= LIS3L02DQ_ACCEL_DEV_NAME
,
76 .compatible
= "st,lng2dm-accel",
77 .data
= LNG2DM_ACCEL_DEV_NAME
,
80 .compatible
= "st,h3lis331dl-accel",
81 .data
= H3LIS331DL_ACCEL_DEV_NAME
,
84 .compatible
= "st,lis331dl-accel",
85 .data
= LIS331DL_ACCEL_DEV_NAME
,
88 .compatible
= "st,lis2dw12",
89 .data
= LIS2DW12_ACCEL_DEV_NAME
,
92 .compatible
= "st,lis3dhh",
93 .data
= LIS3DHH_ACCEL_DEV_NAME
,
96 .compatible
= "st,lis3de",
97 .data
= LIS3DE_ACCEL_DEV_NAME
,
100 .compatible
= "st,lis302dl",
101 .data
= LIS302DL_ACCEL_DEV_NAME
,
104 .compatible
= "st,lsm303c-accel",
105 .data
= LSM303C_ACCEL_DEV_NAME
,
108 .compatible
= "st,iis328dq",
109 .data
= IIS328DQ_ACCEL_DEV_NAME
,
113 MODULE_DEVICE_TABLE(of
, st_accel_of_match
);
115 static int st_accel_spi_probe(struct spi_device
*spi
)
117 const struct st_sensor_settings
*settings
;
118 struct st_sensor_data
*adata
;
119 struct iio_dev
*indio_dev
;
122 st_sensors_dev_name_probe(&spi
->dev
, spi
->modalias
, sizeof(spi
->modalias
));
124 settings
= st_accel_get_settings(spi
->modalias
);
126 dev_err(&spi
->dev
, "device name %s not recognized.\n",
131 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*adata
));
135 adata
= iio_priv(indio_dev
);
136 adata
->sensor_settings
= (struct st_sensor_settings
*)settings
;
138 err
= st_sensors_spi_configure(indio_dev
, spi
);
142 err
= st_sensors_power_enable(indio_dev
);
146 return st_accel_common_probe(indio_dev
);
149 static const struct spi_device_id st_accel_id_table
[] = {
150 { LIS3DH_ACCEL_DEV_NAME
},
151 { LSM330D_ACCEL_DEV_NAME
},
152 { LSM330DL_ACCEL_DEV_NAME
},
153 { LSM330DLC_ACCEL_DEV_NAME
},
154 { LIS331DLH_ACCEL_DEV_NAME
},
155 { LSM330_ACCEL_DEV_NAME
},
156 { LSM303AGR_ACCEL_DEV_NAME
},
157 { LIS2DH12_ACCEL_DEV_NAME
},
158 { LIS2DS12_ACCEL_DEV_NAME
},
159 { LIS3L02DQ_ACCEL_DEV_NAME
},
160 { LNG2DM_ACCEL_DEV_NAME
},
161 { H3LIS331DL_ACCEL_DEV_NAME
},
162 { LIS331DL_ACCEL_DEV_NAME
},
163 { LIS3LV02DL_ACCEL_DEV_NAME
},
164 { LIS2DW12_ACCEL_DEV_NAME
},
165 { LIS3DHH_ACCEL_DEV_NAME
},
166 { LIS3DE_ACCEL_DEV_NAME
},
167 { LIS302DL_ACCEL_DEV_NAME
},
168 { LSM303C_ACCEL_DEV_NAME
},
169 { IIS328DQ_ACCEL_DEV_NAME
},
172 MODULE_DEVICE_TABLE(spi
, st_accel_id_table
);
174 static struct spi_driver st_accel_driver
= {
176 .name
= "st-accel-spi",
177 .of_match_table
= st_accel_of_match
,
179 .probe
= st_accel_spi_probe
,
180 .id_table
= st_accel_id_table
,
182 module_spi_driver(st_accel_driver
);
184 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
185 MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver");
186 MODULE_LICENSE("GPL v2");
187 MODULE_IMPORT_NS(IIO_ST_SENSORS
);