forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/magnetometer/st_magn_spi.c
....@@ -1,11 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * STMicroelectronics magnetometers driver
34 *
45 * Copyright 2012-2013 STMicroelectronics Inc.
56 *
67 * Denis Ciocca <denis.ciocca@st.com>
7
- *
8
- * Licensed under the GPL-2.
98 */
109
1110 #include <linux/kernel.h>
....@@ -18,11 +17,12 @@
1817 #include <linux/iio/common/st_sensors_spi.h>
1918 #include "st_magn.h"
2019
21
-#ifdef CONFIG_OF
2220 /*
2321 * For new single-chip sensors use <device_name> as compatible string.
2422 * For old single-chip devices keep <device_name>-magn to maintain
2523 * compatibility
24
+ * For multi-chip devices, use <device_name>-magn to distinguish which
25
+ * capability is being used
2626 */
2727 static const struct of_device_id st_magn_of_match[] = {
2828 {
....@@ -37,40 +37,64 @@
3737 .compatible = "st,lis2mdl",
3838 .data = LIS2MDL_MAGN_DEV_NAME,
3939 },
40
+ {
41
+ .compatible = "st,lsm9ds1-magn",
42
+ .data = LSM9DS1_MAGN_DEV_NAME,
43
+ },
4044 {}
4145 };
4246 MODULE_DEVICE_TABLE(of, st_magn_of_match);
43
-#else
44
-#define st_magn_of_match NULL
45
-#endif
4647
4748 static int st_magn_spi_probe(struct spi_device *spi)
4849 {
49
- struct iio_dev *indio_dev;
50
+ const struct st_sensor_settings *settings;
5051 struct st_sensor_data *mdata;
52
+ struct iio_dev *indio_dev;
5153 int err;
54
+
55
+ st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
56
+
57
+ settings = st_magn_get_settings(spi->modalias);
58
+ if (!settings) {
59
+ dev_err(&spi->dev, "device name %s not recognized.\n",
60
+ spi->modalias);
61
+ return -ENODEV;
62
+ }
5263
5364 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata));
5465 if (!indio_dev)
5566 return -ENOMEM;
5667
5768 mdata = iio_priv(indio_dev);
69
+ mdata->sensor_settings = (struct st_sensor_settings *)settings;
5870
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);
62
-
63
- err = st_magn_common_probe(indio_dev);
71
+ err = st_sensors_spi_configure(indio_dev, spi);
6472 if (err < 0)
6573 return err;
6674
75
+ err = st_sensors_power_enable(indio_dev);
76
+ if (err)
77
+ return err;
78
+
79
+ err = st_magn_common_probe(indio_dev);
80
+ if (err < 0)
81
+ goto st_magn_power_off;
82
+
6783 return 0;
84
+
85
+st_magn_power_off:
86
+ st_sensors_power_disable(indio_dev);
87
+
88
+ return err;
6889 }
6990
7091 static int st_magn_spi_remove(struct spi_device *spi)
7192 {
7293 struct iio_dev *indio_dev = spi_get_drvdata(spi);
94
+
7395 st_magn_common_remove(indio_dev);
96
+
97
+ st_sensors_power_disable(indio_dev);
7498
7599 return 0;
76100 }
....@@ -79,6 +103,7 @@
79103 { LIS3MDL_MAGN_DEV_NAME },
80104 { LSM303AGR_MAGN_DEV_NAME },
81105 { LIS2MDL_MAGN_DEV_NAME },
106
+ { LSM9DS1_MAGN_DEV_NAME },
82107 {},
83108 };
84109 MODULE_DEVICE_TABLE(spi, st_magn_id_table);
....@@ -86,7 +111,7 @@
86111 static struct spi_driver st_magn_driver = {
87112 .driver = {
88113 .name = "st-magn-spi",
89
- .of_match_table = of_match_ptr(st_magn_of_match),
114
+ .of_match_table = st_magn_of_match,
90115 },
91116 .probe = st_magn_spi_probe,
92117 .remove = st_magn_spi_remove,