forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/gyro/bmg160_core.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * BMG160 Gyro Sensor driver
34 * Copyright (c) 2014, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
135 */
146
157 #include <linux/module.h>
....@@ -102,6 +94,7 @@
10294 struct regmap *regmap;
10395 struct iio_trigger *dready_trig;
10496 struct iio_trigger *motion_trig;
97
+ struct iio_mount_matrix orientation;
10598 struct mutex mutex;
10699 /* Ensure naturally aligned timestamp */
107100 struct {
....@@ -798,6 +791,20 @@
798791 return 0;
799792 }
800793
794
+static const struct iio_mount_matrix *
795
+bmg160_get_mount_matrix(const struct iio_dev *indio_dev,
796
+ const struct iio_chan_spec *chan)
797
+{
798
+ struct bmg160_data *data = iio_priv(indio_dev);
799
+
800
+ return &data->orientation;
801
+}
802
+
803
+static const struct iio_chan_spec_ext_info bmg160_ext_info[] = {
804
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bmg160_get_mount_matrix),
805
+ { }
806
+};
807
+
801808 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("100 200 400 1000 2000");
802809
803810 static IIO_CONST_ATTR(in_anglvel_scale_available,
....@@ -835,6 +842,7 @@
835842 .storagebits = 16, \
836843 .endianness = IIO_LE, \
837844 }, \
845
+ .ext_info = bmg160_ext_info, \
838846 .event_spec = &bmg160_event, \
839847 .num_event_specs = 1 \
840848 }
....@@ -1047,8 +1055,6 @@
10471055
10481056 static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
10491057 .preenable = bmg160_buffer_preenable,
1050
- .postenable = iio_triggered_buffer_postenable,
1051
- .predisable = iio_triggered_buffer_predisable,
10521058 .postdisable = bmg160_buffer_postdisable,
10531059 };
10541060
....@@ -1079,6 +1085,11 @@
10791085 data->irq = irq;
10801086 data->regmap = regmap;
10811087
1088
+ ret = iio_read_mount_matrix(dev, "mount-matrix",
1089
+ &data->orientation);
1090
+ if (ret)
1091
+ return ret;
1092
+
10821093 ret = bmg160_chip_init(data);
10831094 if (ret < 0)
10841095 return ret;
....@@ -1088,7 +1099,6 @@
10881099 if (ACPI_HANDLE(dev))
10891100 name = bmg160_match_acpi_device(dev);
10901101
1091
- indio_dev->dev.parent = dev;
10921102 indio_dev->channels = bmg160_channels;
10931103 indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
10941104 indio_dev->name = name;
....@@ -1160,11 +1170,14 @@
11601170 ret = iio_device_register(indio_dev);
11611171 if (ret < 0) {
11621172 dev_err(dev, "unable to register iio device\n");
1163
- goto err_buffer_cleanup;
1173
+ goto err_pm_cleanup;
11641174 }
11651175
11661176 return 0;
11671177
1178
+err_pm_cleanup:
1179
+ pm_runtime_dont_use_autosuspend(dev);
1180
+ pm_runtime_disable(dev);
11681181 err_buffer_cleanup:
11691182 iio_triggered_buffer_cleanup(indio_dev);
11701183 err_trigger_unregister: