| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Device driver for the the HMC5843 multi-chip module designed |
|---|
| 3 | 4 | * for low field magnetic sensing. |
|---|
| .. | .. |
|---|
| 8 | 9 | * Acknowledgment: Jonathan Cameron <jic23@kernel.org> for valuable inputs. |
|---|
| 9 | 10 | * Support for HMC5883 and HMC5883L by Peter Meerwald <pmeerw@pmeerw.net>. |
|---|
| 10 | 11 | * 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. |
|---|
| 21 | 12 | */ |
|---|
| 22 | 13 | |
|---|
| 23 | 14 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 237 | 228 | return hmc5843_set_meas_conf(data, meas_conf); |
|---|
| 238 | 229 | } |
|---|
| 239 | 230 | |
|---|
| 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 | + |
|---|
| 240 | 240 | static const struct iio_enum hmc5843_meas_conf_enum = { |
|---|
| 241 | 241 | .items = hmc5843_meas_conf_modes, |
|---|
| 242 | 242 | .num_items = ARRAY_SIZE(hmc5843_meas_conf_modes), |
|---|
| .. | .. |
|---|
| 245 | 245 | }; |
|---|
| 246 | 246 | |
|---|
| 247 | 247 | 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), |
|---|
| 249 | 249 | IIO_ENUM_AVAILABLE("meas_conf", &hmc5843_meas_conf_enum), |
|---|
| 250 | | - { }, |
|---|
| 250 | + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix), |
|---|
| 251 | + { } |
|---|
| 251 | 252 | }; |
|---|
| 252 | 253 | |
|---|
| 253 | 254 | static const struct iio_enum hmc5983_meas_conf_enum = { |
|---|
| .. | .. |
|---|
| 258 | 259 | }; |
|---|
| 259 | 260 | |
|---|
| 260 | 261 | 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), |
|---|
| 262 | 263 | IIO_ENUM_AVAILABLE("meas_conf", &hmc5983_meas_conf_enum), |
|---|
| 263 | | - { }, |
|---|
| 264 | + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix), |
|---|
| 265 | + { } |
|---|
| 264 | 266 | }; |
|---|
| 265 | 267 | |
|---|
| 266 | 268 | static |
|---|
| .. | .. |
|---|
| 444 | 446 | } |
|---|
| 445 | 447 | |
|---|
| 446 | 448 | 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)); |
|---|
| 448 | 450 | |
|---|
| 449 | 451 | mutex_unlock(&data->lock); |
|---|
| 450 | 452 | if (ret < 0) |
|---|
| 451 | 453 | goto done; |
|---|
| 452 | 454 | |
|---|
| 453 | | - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, |
|---|
| 455 | + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, |
|---|
| 454 | 456 | iio_get_time_ns(indio_dev)); |
|---|
| 455 | 457 | |
|---|
| 456 | 458 | done: |
|---|
| .. | .. |
|---|
| 635 | 637 | data->variant = &hmc5843_chip_info_tbl[id]; |
|---|
| 636 | 638 | mutex_init(&data->lock); |
|---|
| 637 | 639 | |
|---|
| 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 | + |
|---|
| 639 | 645 | indio_dev->name = name; |
|---|
| 640 | 646 | indio_dev->info = &hmc5843_info; |
|---|
| 641 | 647 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|