.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * cros_ec_baro - Driver for barometer sensor behind CrosEC. |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
14 | 6 | */ |
---|
15 | 7 | |
---|
16 | | -#include <linux/delay.h> |
---|
17 | 8 | #include <linux/device.h> |
---|
18 | 9 | #include <linux/iio/buffer.h> |
---|
19 | 10 | #include <linux/iio/common/cros_ec_sensors_core.h> |
---|
.. | .. |
---|
23 | 14 | #include <linux/iio/triggered_buffer.h> |
---|
24 | 15 | #include <linux/iio/trigger_consumer.h> |
---|
25 | 16 | #include <linux/kernel.h> |
---|
26 | | -#include <linux/mfd/cros_ec.h> |
---|
27 | | -#include <linux/mfd/cros_ec_commands.h> |
---|
28 | 17 | #include <linux/module.h> |
---|
29 | 18 | #include <linux/slab.h> |
---|
| 19 | +#include <linux/platform_data/cros_ec_commands.h> |
---|
| 20 | +#include <linux/platform_data/cros_ec_proto.h> |
---|
30 | 21 | #include <linux/platform_device.h> |
---|
31 | 22 | |
---|
32 | 23 | /* |
---|
.. | .. |
---|
48 | 39 | { |
---|
49 | 40 | struct cros_ec_baro_state *st = iio_priv(indio_dev); |
---|
50 | 41 | u16 data = 0; |
---|
51 | | - int ret = IIO_VAL_INT; |
---|
| 42 | + int ret; |
---|
52 | 43 | int idx = chan->scan_index; |
---|
53 | 44 | |
---|
54 | 45 | mutex_lock(&st->core.cmd_lock); |
---|
55 | 46 | |
---|
56 | 47 | switch (mask) { |
---|
57 | 48 | 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 | + |
---|
61 | 54 | *val = data; |
---|
| 55 | + ret = IIO_VAL_INT; |
---|
62 | 56 | break; |
---|
63 | 57 | case IIO_CHAN_INFO_SCALE: |
---|
64 | 58 | st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; |
---|
65 | 59 | st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; |
---|
66 | 60 | |
---|
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) |
---|
69 | 63 | break; |
---|
70 | | - } |
---|
| 64 | + |
---|
71 | 65 | *val = st->core.resp->sensor_range.ret; |
---|
72 | 66 | |
---|
73 | 67 | /* scale * in_pressure_raw --> kPa */ |
---|
.. | .. |
---|
102 | 96 | /* Always roundup, so caller gets at least what it asks for. */ |
---|
103 | 97 | st->core.param.sensor_range.roundup = 1; |
---|
104 | 98 | |
---|
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 | + } |
---|
107 | 104 | break; |
---|
108 | 105 | default: |
---|
109 | 106 | ret = cros_ec_sensors_core_write(&st->core, chan, val, val2, |
---|
.. | .. |
---|
119 | 116 | static const struct iio_info cros_ec_baro_info = { |
---|
120 | 117 | .read_raw = &cros_ec_baro_read, |
---|
121 | 118 | .write_raw = &cros_ec_baro_write, |
---|
| 119 | + .read_avail = &cros_ec_sensors_core_read_avail, |
---|
122 | 120 | }; |
---|
123 | 121 | |
---|
124 | 122 | static int cros_ec_baro_probe(struct platform_device *pdev) |
---|
.. | .. |
---|
139 | 137 | if (!indio_dev) |
---|
140 | 138 | return -ENOMEM; |
---|
141 | 139 | |
---|
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); |
---|
143 | 144 | if (ret) |
---|
144 | 145 | return ret; |
---|
145 | 146 | |
---|
.. | .. |
---|
152 | 153 | channel->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); |
---|
153 | 154 | channel->info_mask_shared_by_all = |
---|
154 | 155 | 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); |
---|
157 | 159 | channel->scan_type.realbits = CROS_EC_SENSOR_BITS; |
---|
158 | 160 | channel->scan_type.storagebits = CROS_EC_SENSOR_BITS; |
---|
159 | 161 | channel->scan_type.shift = 0; |
---|
160 | 162 | channel->scan_index = 0; |
---|
161 | 163 | channel->ext_info = cros_ec_sensors_ext_info; |
---|
162 | 164 | channel->scan_type.sign = 'u'; |
---|
163 | | - |
---|
164 | | - state->core.calib[0] = 0; |
---|
165 | 165 | |
---|
166 | 166 | /* Sensor specific */ |
---|
167 | 167 | switch (state->core.type) { |
---|
.. | .. |
---|
187 | 187 | |
---|
188 | 188 | state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; |
---|
189 | 189 | |
---|
190 | | - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, |
---|
191 | | - cros_ec_sensors_capture, NULL); |
---|
192 | | - if (ret) |
---|
193 | | - return ret; |
---|
194 | | - |
---|
195 | 190 | return devm_iio_device_register(dev, indio_dev); |
---|
196 | 191 | } |
---|
197 | 192 | |
---|
.. | .. |
---|
206 | 201 | static struct platform_driver cros_ec_baro_platform_driver = { |
---|
207 | 202 | .driver = { |
---|
208 | 203 | .name = "cros-ec-baro", |
---|
| 204 | + .pm = &cros_ec_sensors_pm_ops, |
---|
209 | 205 | }, |
---|
210 | 206 | .probe = cros_ec_baro_probe, |
---|
211 | 207 | .id_table = cros_ec_baro_ids, |
---|