1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics gyroscopes 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>-gyro to maintain
25 static const struct of_device_id st_gyro_of_match
[] = {
27 .compatible
= "st,l3g4200d-gyro",
28 .data
= L3G4200D_GYRO_DEV_NAME
,
31 .compatible
= "st,lsm330d-gyro",
32 .data
= LSM330D_GYRO_DEV_NAME
,
35 .compatible
= "st,lsm330dl-gyro",
36 .data
= LSM330DL_GYRO_DEV_NAME
,
39 .compatible
= "st,lsm330dlc-gyro",
40 .data
= LSM330DLC_GYRO_DEV_NAME
,
43 .compatible
= "st,l3gd20-gyro",
44 .data
= L3GD20_GYRO_DEV_NAME
,
47 .compatible
= "st,l3gd20h-gyro",
48 .data
= L3GD20H_GYRO_DEV_NAME
,
51 .compatible
= "st,l3g4is-gyro",
52 .data
= L3G4IS_GYRO_DEV_NAME
,
55 .compatible
= "st,lsm330-gyro",
56 .data
= LSM330_GYRO_DEV_NAME
,
59 .compatible
= "st,lsm9ds0-gyro",
60 .data
= LSM9DS0_GYRO_DEV_NAME
,
64 MODULE_DEVICE_TABLE(of
, st_gyro_of_match
);
66 static int st_gyro_spi_probe(struct spi_device
*spi
)
68 const struct st_sensor_settings
*settings
;
69 struct st_sensor_data
*gdata
;
70 struct iio_dev
*indio_dev
;
73 st_sensors_dev_name_probe(&spi
->dev
, spi
->modalias
, sizeof(spi
->modalias
));
75 settings
= st_gyro_get_settings(spi
->modalias
);
77 dev_err(&spi
->dev
, "device name %s not recognized.\n",
82 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*gdata
));
86 gdata
= iio_priv(indio_dev
);
87 gdata
->sensor_settings
= (struct st_sensor_settings
*)settings
;
89 err
= st_sensors_spi_configure(indio_dev
, spi
);
93 err
= st_sensors_power_enable(indio_dev
);
97 return st_gyro_common_probe(indio_dev
);
100 static const struct spi_device_id st_gyro_id_table
[] = {
101 { L3G4200D_GYRO_DEV_NAME
},
102 { LSM330D_GYRO_DEV_NAME
},
103 { LSM330DL_GYRO_DEV_NAME
},
104 { LSM330DLC_GYRO_DEV_NAME
},
105 { L3GD20_GYRO_DEV_NAME
},
106 { L3GD20H_GYRO_DEV_NAME
},
107 { L3G4IS_GYRO_DEV_NAME
},
108 { LSM330_GYRO_DEV_NAME
},
109 { LSM9DS0_GYRO_DEV_NAME
},
112 MODULE_DEVICE_TABLE(spi
, st_gyro_id_table
);
114 static struct spi_driver st_gyro_driver
= {
116 .name
= "st-gyro-spi",
117 .of_match_table
= st_gyro_of_match
,
119 .probe
= st_gyro_spi_probe
,
120 .id_table
= st_gyro_id_table
,
122 module_spi_driver(st_gyro_driver
);
124 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
125 MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver");
126 MODULE_LICENSE("GPL v2");
127 MODULE_IMPORT_NS(IIO_ST_SENSORS
);