forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/iio/accel/bmc150-accel-core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 3-axis accelerometer driver supporting following Bosch-Sensortec chips:
34 * - BMC150
....@@ -8,15 +9,6 @@
89 * - BMA280
910 *
1011 * Copyright (c) 2014, Intel Corporation.
11
- *
12
- * This program is free software; you can redistribute it and/or modify it
13
- * under the terms and conditions of the GNU General Public License,
14
- * version 2, as published by the Free Software Foundation.
15
- *
16
- * This program is distributed in the hope it will be useful, but WITHOUT
17
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19
- * more details.
2012 */
2113
2214 #include <linux/module.h>
....@@ -212,6 +204,7 @@
212204 int ev_enable_state;
213205 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
214206 const struct bmc150_accel_chip_info *chip_info;
207
+ struct iio_mount_matrix orientation;
215208 };
216209
217210 static const struct {
....@@ -401,7 +394,7 @@
401394
402395 if (ret < 0) {
403396 dev_err(dev,
404
- "Failed: bmc150_accel_set_power_state for %d\n", on);
397
+ "Failed: %s for %d\n", __func__, on);
405398 if (on)
406399 pm_runtime_put_noidle(dev);
407400
....@@ -804,6 +797,20 @@
804797 return sprintf(buf, "%d\n", state);
805798 }
806799
800
+static const struct iio_mount_matrix *
801
+bmc150_accel_get_mount_matrix(const struct iio_dev *indio_dev,
802
+ const struct iio_chan_spec *chan)
803
+{
804
+ struct bmc150_accel_data *data = iio_priv(indio_dev);
805
+
806
+ return &data->orientation;
807
+}
808
+
809
+static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
810
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bmc150_accel_get_mount_matrix),
811
+ { }
812
+};
813
+
807814 static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
808815 static IIO_CONST_ATTR(hwfifo_watermark_max,
809816 __stringify(BMC150_ACCEL_FIFO_LENGTH));
....@@ -987,6 +994,7 @@
987994 .shift = 16 - (bits), \
988995 .endianness = IIO_LE, \
989996 }, \
997
+ .ext_info = bmc150_accel_ext_info, \
990998 .event_spec = &bmc150_accel_event, \
991999 .num_event_specs = 1 \
9921000 }
....@@ -1412,7 +1420,7 @@
14121420 int ret = 0;
14131421
14141422 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1415
- return iio_triggered_buffer_postenable(indio_dev);
1423
+ return 0;
14161424
14171425 mutex_lock(&data->mutex);
14181426
....@@ -1444,7 +1452,7 @@
14441452 struct bmc150_accel_data *data = iio_priv(indio_dev);
14451453
14461454 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1447
- return iio_triggered_buffer_predisable(indio_dev);
1455
+ return 0;
14481456
14491457 mutex_lock(&data->mutex);
14501458
....@@ -1564,13 +1572,17 @@
15641572
15651573 data->regmap = regmap;
15661574
1575
+ ret = iio_read_mount_matrix(dev, "mount-matrix",
1576
+ &data->orientation);
1577
+ if (ret)
1578
+ return ret;
1579
+
15671580 ret = bmc150_accel_chip_init(data);
15681581 if (ret < 0)
15691582 return ret;
15701583
15711584 mutex_init(&data->mutex);
15721585
1573
- indio_dev->dev.parent = dev;
15741586 indio_dev->channels = data->chip_info->channels;
15751587 indio_dev->num_channels = data->chip_info->num_channels;
15761588 indio_dev->name = name ? name : data->chip_info->name;
....@@ -1636,11 +1648,14 @@
16361648 ret = iio_device_register(indio_dev);
16371649 if (ret < 0) {
16381650 dev_err(dev, "Unable to register iio device\n");
1639
- goto err_trigger_unregister;
1651
+ goto err_pm_cleanup;
16401652 }
16411653
16421654 return 0;
16431655
1656
+err_pm_cleanup:
1657
+ pm_runtime_dont_use_autosuspend(dev);
1658
+ pm_runtime_disable(dev);
16441659 err_trigger_unregister:
16451660 bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
16461661 err_buffer_cleanup: