hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/iio/pressure/cros_ec_baro.c
....@@ -1,19 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * cros_ec_baro - Driver for barometer sensor behind CrosEC.
34 *
45 * Copyright (C) 2017 Google, Inc
5
- *
6
- * This software is licensed under the terms of the GNU General Public
7
- * License version 2, as published by the Free Software Foundation, and
8
- * may be copied, distributed, and modified under those terms.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
16
-#include <linux/delay.h>
178 #include <linux/device.h>
189 #include <linux/iio/buffer.h>
1910 #include <linux/iio/common/cros_ec_sensors_core.h>
....@@ -23,10 +14,10 @@
2314 #include <linux/iio/triggered_buffer.h>
2415 #include <linux/iio/trigger_consumer.h>
2516 #include <linux/kernel.h>
26
-#include <linux/mfd/cros_ec.h>
27
-#include <linux/mfd/cros_ec_commands.h>
2817 #include <linux/module.h>
2918 #include <linux/slab.h>
19
+#include <linux/platform_data/cros_ec_commands.h>
20
+#include <linux/platform_data/cros_ec_proto.h>
3021 #include <linux/platform_device.h>
3122
3223 /*
....@@ -48,26 +39,29 @@
4839 {
4940 struct cros_ec_baro_state *st = iio_priv(indio_dev);
5041 u16 data = 0;
51
- int ret = IIO_VAL_INT;
42
+ int ret;
5243 int idx = chan->scan_index;
5344
5445 mutex_lock(&st->core.cmd_lock);
5546
5647 switch (mask) {
5748 case IIO_CHAN_INFO_RAW:
58
- if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
59
- (s16 *)&data) < 0)
60
- ret = -EIO;
49
+ ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
50
+ (s16 *)&data);
51
+ if (ret)
52
+ break;
53
+
6154 *val = data;
55
+ ret = IIO_VAL_INT;
6256 break;
6357 case IIO_CHAN_INFO_SCALE:
6458 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
6559 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
6660
67
- if (cros_ec_motion_send_host_cmd(&st->core, 0)) {
68
- ret = -EIO;
61
+ ret = cros_ec_motion_send_host_cmd(&st->core, 0);
62
+ if (ret)
6963 break;
70
- }
64
+
7165 *val = st->core.resp->sensor_range.ret;
7266
7367 /* scale * in_pressure_raw --> kPa */
....@@ -102,8 +96,11 @@
10296 /* Always roundup, so caller gets at least what it asks for. */
10397 st->core.param.sensor_range.roundup = 1;
10498
105
- if (cros_ec_motion_send_host_cmd(&st->core, 0))
106
- ret = -EIO;
99
+ ret = cros_ec_motion_send_host_cmd(&st->core, 0);
100
+ if (ret == 0) {
101
+ st->core.range_updated = true;
102
+ st->core.curr_range = val;
103
+ }
107104 break;
108105 default:
109106 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
....@@ -119,6 +116,7 @@
119116 static const struct iio_info cros_ec_baro_info = {
120117 .read_raw = &cros_ec_baro_read,
121118 .write_raw = &cros_ec_baro_write,
119
+ .read_avail = &cros_ec_sensors_core_read_avail,
122120 };
123121
124122 static int cros_ec_baro_probe(struct platform_device *pdev)
....@@ -139,7 +137,10 @@
139137 if (!indio_dev)
140138 return -ENOMEM;
141139
142
- ret = cros_ec_sensors_core_init(pdev, indio_dev, true);
140
+ ret = cros_ec_sensors_core_init(pdev, indio_dev, true,
141
+ cros_ec_sensors_capture,
142
+ cros_ec_sensors_push_data,
143
+ true);
143144 if (ret)
144145 return ret;
145146
....@@ -152,16 +153,15 @@
152153 channel->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
153154 channel->info_mask_shared_by_all =
154155 BIT(IIO_CHAN_INFO_SCALE) |
155
- BIT(IIO_CHAN_INFO_SAMP_FREQ) |
156
- BIT(IIO_CHAN_INFO_FREQUENCY);
156
+ BIT(IIO_CHAN_INFO_SAMP_FREQ);
157
+ channel->info_mask_shared_by_all_available =
158
+ BIT(IIO_CHAN_INFO_SAMP_FREQ);
157159 channel->scan_type.realbits = CROS_EC_SENSOR_BITS;
158160 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS;
159161 channel->scan_type.shift = 0;
160162 channel->scan_index = 0;
161163 channel->ext_info = cros_ec_sensors_ext_info;
162164 channel->scan_type.sign = 'u';
163
-
164
- state->core.calib[0] = 0;
165165
166166 /* Sensor specific */
167167 switch (state->core.type) {
....@@ -187,11 +187,6 @@
187187
188188 state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd;
189189
190
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
191
- cros_ec_sensors_capture, NULL);
192
- if (ret)
193
- return ret;
194
-
195190 return devm_iio_device_register(dev, indio_dev);
196191 }
197192
....@@ -206,6 +201,7 @@
206201 static struct platform_driver cros_ec_baro_platform_driver = {
207202 .driver = {
208203 .name = "cros-ec-baro",
204
+ .pm = &cros_ec_sensors_pm_ops,
209205 },
210206 .probe = cros_ec_baro_probe,
211207 .id_table = cros_ec_baro_ids,