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_gyro.h"
0019
0020
0021
0022
0023
0024
0025 static const struct of_device_id st_gyro_of_match[] = {
0026 {
0027 .compatible = "st,l3g4200d-gyro",
0028 .data = L3G4200D_GYRO_DEV_NAME,
0029 },
0030 {
0031 .compatible = "st,lsm330d-gyro",
0032 .data = LSM330D_GYRO_DEV_NAME,
0033 },
0034 {
0035 .compatible = "st,lsm330dl-gyro",
0036 .data = LSM330DL_GYRO_DEV_NAME,
0037 },
0038 {
0039 .compatible = "st,lsm330dlc-gyro",
0040 .data = LSM330DLC_GYRO_DEV_NAME,
0041 },
0042 {
0043 .compatible = "st,l3gd20-gyro",
0044 .data = L3GD20_GYRO_DEV_NAME,
0045 },
0046 {
0047 .compatible = "st,l3gd20h-gyro",
0048 .data = L3GD20H_GYRO_DEV_NAME,
0049 },
0050 {
0051 .compatible = "st,l3g4is-gyro",
0052 .data = L3G4IS_GYRO_DEV_NAME,
0053 },
0054 {
0055 .compatible = "st,lsm330-gyro",
0056 .data = LSM330_GYRO_DEV_NAME,
0057 },
0058 {
0059 .compatible = "st,lsm9ds0-gyro",
0060 .data = LSM9DS0_GYRO_DEV_NAME,
0061 },
0062 {},
0063 };
0064 MODULE_DEVICE_TABLE(of, st_gyro_of_match);
0065
0066 static int st_gyro_spi_probe(struct spi_device *spi)
0067 {
0068 const struct st_sensor_settings *settings;
0069 struct st_sensor_data *gdata;
0070 struct iio_dev *indio_dev;
0071 int err;
0072
0073 st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
0074
0075 settings = st_gyro_get_settings(spi->modalias);
0076 if (!settings) {
0077 dev_err(&spi->dev, "device name %s not recognized.\n",
0078 spi->modalias);
0079 return -ENODEV;
0080 }
0081
0082 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata));
0083 if (!indio_dev)
0084 return -ENOMEM;
0085
0086 gdata = iio_priv(indio_dev);
0087 gdata->sensor_settings = (struct st_sensor_settings *)settings;
0088
0089 err = st_sensors_spi_configure(indio_dev, spi);
0090 if (err < 0)
0091 return err;
0092
0093 err = st_sensors_power_enable(indio_dev);
0094 if (err)
0095 return err;
0096
0097 return st_gyro_common_probe(indio_dev);
0098 }
0099
0100 static const struct spi_device_id st_gyro_id_table[] = {
0101 { L3G4200D_GYRO_DEV_NAME },
0102 { LSM330D_GYRO_DEV_NAME },
0103 { LSM330DL_GYRO_DEV_NAME },
0104 { LSM330DLC_GYRO_DEV_NAME },
0105 { L3GD20_GYRO_DEV_NAME },
0106 { L3GD20H_GYRO_DEV_NAME },
0107 { L3G4IS_GYRO_DEV_NAME },
0108 { LSM330_GYRO_DEV_NAME },
0109 { LSM9DS0_GYRO_DEV_NAME },
0110 {},
0111 };
0112 MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
0113
0114 static struct spi_driver st_gyro_driver = {
0115 .driver = {
0116 .name = "st-gyro-spi",
0117 .of_match_table = st_gyro_of_match,
0118 },
0119 .probe = st_gyro_spi_probe,
0120 .id_table = st_gyro_id_table,
0121 };
0122 module_spi_driver(st_gyro_driver);
0123
0124 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0125 MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver");
0126 MODULE_LICENSE("GPL v2");
0127 MODULE_IMPORT_NS(IIO_ST_SENSORS);