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
26 * For multi-chip devices, use <device_name>-magn to distinguish which
27 * capability is being used
29 static const struct of_device_id st_magn_of_match
[] = {
31 .compatible
= "st,lis3mdl-magn",
32 .data
= LIS3MDL_MAGN_DEV_NAME
,
35 .compatible
= "st,lsm303agr-magn",
36 .data
= LSM303AGR_MAGN_DEV_NAME
,
39 .compatible
= "st,lis2mdl",
40 .data
= LIS2MDL_MAGN_DEV_NAME
,
43 .compatible
= "st,lsm9ds1-magn",
44 .data
= LSM9DS1_MAGN_DEV_NAME
,
48 MODULE_DEVICE_TABLE(of
, st_magn_of_match
);
50 #define st_magn_of_match NULL
53 static int st_magn_spi_probe(struct spi_device
*spi
)
55 struct iio_dev
*indio_dev
;
56 struct st_sensor_data
*mdata
;
59 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*mdata
));
63 mdata
= iio_priv(indio_dev
);
65 st_sensors_of_name_probe(&spi
->dev
, st_magn_of_match
,
66 spi
->modalias
, sizeof(spi
->modalias
));
67 st_sensors_spi_configure(indio_dev
, spi
, mdata
);
69 err
= st_magn_common_probe(indio_dev
);
76 static int st_magn_spi_remove(struct spi_device
*spi
)
78 struct iio_dev
*indio_dev
= spi_get_drvdata(spi
);
79 st_magn_common_remove(indio_dev
);
84 static const struct spi_device_id st_magn_id_table
[] = {
85 { LIS3MDL_MAGN_DEV_NAME
},
86 { LSM303AGR_MAGN_DEV_NAME
},
87 { LIS2MDL_MAGN_DEV_NAME
},
88 { LSM9DS1_MAGN_DEV_NAME
},
91 MODULE_DEVICE_TABLE(spi
, st_magn_id_table
);
93 static struct spi_driver st_magn_driver
= {
95 .name
= "st-magn-spi",
96 .of_match_table
= of_match_ptr(st_magn_of_match
),
98 .probe
= st_magn_spi_probe
,
99 .remove
= st_magn_spi_remove
,
100 .id_table
= st_magn_id_table
,
102 module_spi_driver(st_magn_driver
);
104 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
105 MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
106 MODULE_LICENSE("GPL v2");