drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / drivers / iio / magnetometer / st_magn_spi.c
blobfe4d0e63133c03c8fff68c37a23dce2ea2ad4e7b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics magnetometers driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
8 */
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>
18 #include "st_magn.h"
21 * For new single-chip sensors use <device_name> as compatible string.
22 * For old single-chip devices keep <device_name>-magn to maintain
23 * compatibility
24 * For multi-chip devices, use <device_name>-magn to distinguish which
25 * capability is being used
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,
41 .compatible = "st,lsm9ds1-magn",
42 .data = LSM9DS1_MAGN_DEV_NAME,
45 .compatible = "st,iis2mdc",
46 .data = IIS2MDC_MAGN_DEV_NAME,
49 .compatible = "st,lsm303c-magn",
50 .data = LSM303C_MAGN_DEV_NAME,
54 MODULE_DEVICE_TABLE(of, st_magn_of_match);
56 static int st_magn_spi_probe(struct spi_device *spi)
58 const struct st_sensor_settings *settings;
59 struct st_sensor_data *mdata;
60 struct iio_dev *indio_dev;
61 int err;
63 st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
65 settings = st_magn_get_settings(spi->modalias);
66 if (!settings) {
67 dev_err(&spi->dev, "device name %s not recognized.\n",
68 spi->modalias);
69 return -ENODEV;
72 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata));
73 if (!indio_dev)
74 return -ENOMEM;
76 mdata = iio_priv(indio_dev);
77 mdata->sensor_settings = (struct st_sensor_settings *)settings;
79 err = st_sensors_spi_configure(indio_dev, spi);
80 if (err < 0)
81 return err;
83 err = st_sensors_power_enable(indio_dev);
84 if (err)
85 return err;
87 return st_magn_common_probe(indio_dev);
90 static const struct spi_device_id st_magn_id_table[] = {
91 { LIS3MDL_MAGN_DEV_NAME },
92 { LSM303AGR_MAGN_DEV_NAME },
93 { LIS2MDL_MAGN_DEV_NAME },
94 { LSM9DS1_MAGN_DEV_NAME },
95 { IIS2MDC_MAGN_DEV_NAME },
96 { LSM303C_MAGN_DEV_NAME },
97 {},
99 MODULE_DEVICE_TABLE(spi, st_magn_id_table);
101 static struct spi_driver st_magn_driver = {
102 .driver = {
103 .name = "st-magn-spi",
104 .of_match_table = st_magn_of_match,
106 .probe = st_magn_spi_probe,
107 .id_table = st_magn_id_table,
109 module_spi_driver(st_magn_driver);
111 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
112 MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
113 MODULE_LICENSE("GPL v2");
114 MODULE_IMPORT_NS("IIO_ST_SENSORS");