forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/magnetometer/hmc5843_core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Device driver for the the HMC5843 multi-chip module designed
34 * for low field magnetic sensing.
....@@ -8,16 +9,6 @@
89 * Acknowledgment: Jonathan Cameron <jic23@kernel.org> for valuable inputs.
910 * Support for HMC5883 and HMC5883L by Peter Meerwald <pmeerw@pmeerw.net>.
1011 * Split to multiple files by Josef Gajdusek <atx@atx.name> - 2014
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2 of the License, or
15
- * (at your option) any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
2112 */
2213
2314 #include <linux/module.h>
....@@ -237,6 +228,15 @@
237228 return hmc5843_set_meas_conf(data, meas_conf);
238229 }
239230
231
+static const struct iio_mount_matrix *
232
+hmc5843_get_mount_matrix(const struct iio_dev *indio_dev,
233
+ const struct iio_chan_spec *chan)
234
+{
235
+ struct hmc5843_data *data = iio_priv(indio_dev);
236
+
237
+ return &data->orientation;
238
+}
239
+
240240 static const struct iio_enum hmc5843_meas_conf_enum = {
241241 .items = hmc5843_meas_conf_modes,
242242 .num_items = ARRAY_SIZE(hmc5843_meas_conf_modes),
....@@ -245,9 +245,10 @@
245245 };
246246
247247 static const struct iio_chan_spec_ext_info hmc5843_ext_info[] = {
248
- IIO_ENUM("meas_conf", true, &hmc5843_meas_conf_enum),
248
+ IIO_ENUM("meas_conf", IIO_SHARED_BY_TYPE, &hmc5843_meas_conf_enum),
249249 IIO_ENUM_AVAILABLE("meas_conf", &hmc5843_meas_conf_enum),
250
- { },
250
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
251
+ { }
251252 };
252253
253254 static const struct iio_enum hmc5983_meas_conf_enum = {
....@@ -258,9 +259,10 @@
258259 };
259260
260261 static const struct iio_chan_spec_ext_info hmc5983_ext_info[] = {
261
- IIO_ENUM("meas_conf", true, &hmc5983_meas_conf_enum),
262
+ IIO_ENUM("meas_conf", IIO_SHARED_BY_TYPE, &hmc5983_meas_conf_enum),
262263 IIO_ENUM_AVAILABLE("meas_conf", &hmc5983_meas_conf_enum),
263
- { },
264
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
265
+ { }
264266 };
265267
266268 static
....@@ -444,13 +446,13 @@
444446 }
445447
446448 ret = regmap_bulk_read(data->regmap, HMC5843_DATA_OUT_MSB_REGS,
447
- data->buffer, 3 * sizeof(__be16));
449
+ data->scan.chans, sizeof(data->scan.chans));
448450
449451 mutex_unlock(&data->lock);
450452 if (ret < 0)
451453 goto done;
452454
453
- iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
455
+ iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
454456 iio_get_time_ns(indio_dev));
455457
456458 done:
....@@ -635,7 +637,11 @@
635637 data->variant = &hmc5843_chip_info_tbl[id];
636638 mutex_init(&data->lock);
637639
638
- indio_dev->dev.parent = dev;
640
+ ret = iio_read_mount_matrix(dev, "mount-matrix",
641
+ &data->orientation);
642
+ if (ret)
643
+ return ret;
644
+
639645 indio_dev->name = name;
640646 indio_dev->info = &hmc5843_info;
641647 indio_dev->modes = INDIO_DIRECT_MODE;