2 * STMicroelectronics magnetometers driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/spi/spi.h>
15 #include <linux/iio/iio.h>
17 #include <linux/iio/common/st_sensors.h>
18 #include <linux/iio/common/st_sensors_spi.h>
23 * For new single-chip sensors use <device_name> as compatible string.
24 * For old single-chip devices keep <device_name>-magn to maintain
27 static const struct of_device_id st_magn_of_match
[] = {
29 .compatible
= "st,lis3mdl-magn",
30 .data
= LIS3MDL_MAGN_DEV_NAME
,
33 .compatible
= "st,lsm303agr-magn",
34 .data
= LSM303AGR_MAGN_DEV_NAME
,
37 .compatible
= "st,lis2mdl",
38 .data
= LIS2MDL_MAGN_DEV_NAME
,
42 MODULE_DEVICE_TABLE(of
, st_magn_of_match
);
44 #define st_magn_of_match NULL
47 static int st_magn_spi_probe(struct spi_device
*spi
)
49 struct iio_dev
*indio_dev
;
50 struct st_sensor_data
*mdata
;
53 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*mdata
));
57 mdata
= iio_priv(indio_dev
);
59 st_sensors_of_name_probe(&spi
->dev
, st_magn_of_match
,
60 spi
->modalias
, sizeof(spi
->modalias
));
61 st_sensors_spi_configure(indio_dev
, spi
, mdata
);
63 err
= st_magn_common_probe(indio_dev
);
70 static int st_magn_spi_remove(struct spi_device
*spi
)
72 struct iio_dev
*indio_dev
= spi_get_drvdata(spi
);
73 st_magn_common_remove(indio_dev
);
78 static const struct spi_device_id st_magn_id_table
[] = {
79 { LIS3MDL_MAGN_DEV_NAME
},
80 { LSM303AGR_MAGN_DEV_NAME
},
81 { LIS2MDL_MAGN_DEV_NAME
},
84 MODULE_DEVICE_TABLE(spi
, st_magn_id_table
);
86 static struct spi_driver st_magn_driver
= {
88 .name
= "st-magn-spi",
89 .of_match_table
= of_match_ptr(st_magn_of_match
),
91 .probe
= st_magn_spi_probe
,
92 .remove
= st_magn_spi_remove
,
93 .id_table
= st_magn_id_table
,
95 module_spi_driver(st_magn_driver
);
97 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
98 MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
99 MODULE_LICENSE("GPL v2");