0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/mod_devicetable.h>
0013 #include <linux/spi/spi.h>
0014 #include <linux/iio/iio.h>
0015
0016 #include <linux/iio/common/st_sensors.h>
0017 #include <linux/iio/common/st_sensors_spi.h>
0018 #include "st_accel.h"
0019
0020
0021
0022
0023
0024
0025 static const struct of_device_id st_accel_of_match[] = {
0026 {
0027
0028 .compatible = "st,lis302dl-spi",
0029 .data = LIS3LV02DL_ACCEL_DEV_NAME,
0030 },
0031 {
0032 .compatible = "st,lis3lv02dl-accel",
0033 .data = LIS3LV02DL_ACCEL_DEV_NAME,
0034 },
0035 {
0036 .compatible = "st,lis3dh-accel",
0037 .data = LIS3DH_ACCEL_DEV_NAME,
0038 },
0039 {
0040 .compatible = "st,lsm330d-accel",
0041 .data = LSM330D_ACCEL_DEV_NAME,
0042 },
0043 {
0044 .compatible = "st,lsm330dl-accel",
0045 .data = LSM330DL_ACCEL_DEV_NAME,
0046 },
0047 {
0048 .compatible = "st,lsm330dlc-accel",
0049 .data = LSM330DLC_ACCEL_DEV_NAME,
0050 },
0051 {
0052 .compatible = "st,lis331dlh-accel",
0053 .data = LIS331DLH_ACCEL_DEV_NAME,
0054 },
0055 {
0056 .compatible = "st,lsm330-accel",
0057 .data = LSM330_ACCEL_DEV_NAME,
0058 },
0059 {
0060 .compatible = "st,lsm303agr-accel",
0061 .data = LSM303AGR_ACCEL_DEV_NAME,
0062 },
0063 {
0064 .compatible = "st,lis2dh12-accel",
0065 .data = LIS2DH12_ACCEL_DEV_NAME,
0066 },
0067 {
0068 .compatible = "st,lis3l02dq",
0069 .data = LIS3L02DQ_ACCEL_DEV_NAME,
0070 },
0071 {
0072 .compatible = "st,lng2dm-accel",
0073 .data = LNG2DM_ACCEL_DEV_NAME,
0074 },
0075 {
0076 .compatible = "st,h3lis331dl-accel",
0077 .data = H3LIS331DL_ACCEL_DEV_NAME,
0078 },
0079 {
0080 .compatible = "st,lis331dl-accel",
0081 .data = LIS331DL_ACCEL_DEV_NAME,
0082 },
0083 {
0084 .compatible = "st,lis2dw12",
0085 .data = LIS2DW12_ACCEL_DEV_NAME,
0086 },
0087 {
0088 .compatible = "st,lis3dhh",
0089 .data = LIS3DHH_ACCEL_DEV_NAME,
0090 },
0091 {
0092 .compatible = "st,lis3de",
0093 .data = LIS3DE_ACCEL_DEV_NAME,
0094 },
0095 {
0096 .compatible = "st,lis302dl",
0097 .data = LIS302DL_ACCEL_DEV_NAME,
0098 },
0099 {}
0100 };
0101 MODULE_DEVICE_TABLE(of, st_accel_of_match);
0102
0103 static int st_accel_spi_probe(struct spi_device *spi)
0104 {
0105 const struct st_sensor_settings *settings;
0106 struct st_sensor_data *adata;
0107 struct iio_dev *indio_dev;
0108 int err;
0109
0110 st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
0111
0112 settings = st_accel_get_settings(spi->modalias);
0113 if (!settings) {
0114 dev_err(&spi->dev, "device name %s not recognized.\n",
0115 spi->modalias);
0116 return -ENODEV;
0117 }
0118
0119 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata));
0120 if (!indio_dev)
0121 return -ENOMEM;
0122
0123 adata = iio_priv(indio_dev);
0124 adata->sensor_settings = (struct st_sensor_settings *)settings;
0125
0126 err = st_sensors_spi_configure(indio_dev, spi);
0127 if (err < 0)
0128 return err;
0129
0130 err = st_sensors_power_enable(indio_dev);
0131 if (err)
0132 return err;
0133
0134 return st_accel_common_probe(indio_dev);
0135 }
0136
0137 static const struct spi_device_id st_accel_id_table[] = {
0138 { LIS3DH_ACCEL_DEV_NAME },
0139 { LSM330D_ACCEL_DEV_NAME },
0140 { LSM330DL_ACCEL_DEV_NAME },
0141 { LSM330DLC_ACCEL_DEV_NAME },
0142 { LIS331DLH_ACCEL_DEV_NAME },
0143 { LSM330_ACCEL_DEV_NAME },
0144 { LSM303AGR_ACCEL_DEV_NAME },
0145 { LIS2DH12_ACCEL_DEV_NAME },
0146 { LIS3L02DQ_ACCEL_DEV_NAME },
0147 { LNG2DM_ACCEL_DEV_NAME },
0148 { H3LIS331DL_ACCEL_DEV_NAME },
0149 { LIS331DL_ACCEL_DEV_NAME },
0150 { LIS3LV02DL_ACCEL_DEV_NAME },
0151 { LIS2DW12_ACCEL_DEV_NAME },
0152 { LIS3DHH_ACCEL_DEV_NAME },
0153 { LIS3DE_ACCEL_DEV_NAME },
0154 { LIS302DL_ACCEL_DEV_NAME },
0155 {},
0156 };
0157 MODULE_DEVICE_TABLE(spi, st_accel_id_table);
0158
0159 static struct spi_driver st_accel_driver = {
0160 .driver = {
0161 .name = "st-accel-spi",
0162 .of_match_table = st_accel_of_match,
0163 },
0164 .probe = st_accel_spi_probe,
0165 .id_table = st_accel_id_table,
0166 };
0167 module_spi_driver(st_accel_driver);
0168
0169 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0170 MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver");
0171 MODULE_LICENSE("GPL v2");
0172 MODULE_IMPORT_NS(IIO_ST_SENSORS);