1 // SPDX-License-Identifier: GPL-2.0
3 * cros_ec_sensors_core - Common function for Chrome OS EC sensor driver.
5 * Copyright (C) 2016 Google, Inc
8 #include <linux/delay.h>
9 #include <linux/device.h>
10 #include <linux/iio/buffer.h>
11 #include <linux/iio/common/cros_ec_sensors_core.h>
12 #include <linux/iio/iio.h>
13 #include <linux/iio/kfifo_buf.h>
14 #include <linux/iio/sysfs.h>
15 #include <linux/iio/trigger_consumer.h>
16 #include <linux/iio/triggered_buffer.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/platform_data/cros_ec_commands.h>
21 #include <linux/platform_data/cros_ec_proto.h>
22 #include <linux/platform_data/cros_ec_sensorhub.h>
23 #include <linux/platform_device.h>
26 * Hard coded to the first device to support sensor fifo. The EC has a 2048
27 * byte fifo and will trigger an interrupt when fifo is 2/3 full.
29 #define CROS_EC_FIFO_SIZE (2048 * 2 / 3)
31 static char *cros_ec_loc[] = {
32 [MOTIONSENSE_LOC_BASE] = "base",
33 [MOTIONSENSE_LOC_LID] = "lid",
34 [MOTIONSENSE_LOC_MAX] = "unknown",
37 static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
38 u16 cmd_offset, u16 cmd, u32 *mask)
42 struct cros_ec_command msg;
44 struct ec_params_get_cmd_versions params;
45 struct ec_response_get_cmd_versions resp;
49 .command = EC_CMD_GET_CMD_VERSIONS + cmd_offset,
50 .insize = sizeof(struct ec_response_get_cmd_versions),
51 .outsize = sizeof(struct ec_params_get_cmd_versions)
53 .params = {.cmd = cmd}
56 ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg);
58 *mask = buf.resp.version_mask;
62 static void get_default_min_max_freq(enum motionsensor_type type,
68 * We don't know fifo size, set to size previously used by older
71 *max_fifo_events = CROS_EC_FIFO_SIZE;
74 case MOTIONSENSE_TYPE_ACCEL:
78 case MOTIONSENSE_TYPE_GYRO:
82 case MOTIONSENSE_TYPE_MAG:
86 case MOTIONSENSE_TYPE_PROX:
87 case MOTIONSENSE_TYPE_LIGHT:
91 case MOTIONSENSE_TYPE_BARO:
95 case MOTIONSENSE_TYPE_ACTIVITY:
103 static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st,
111 mutex_lock(&st->cmd_lock);
112 st->param.cmd = MOTIONSENSE_CMD_EC_RATE;
113 st->param.ec_rate.data = rate;
114 ret = cros_ec_motion_send_host_cmd(st, 0);
115 mutex_unlock(&st->cmd_lock);
119 static ssize_t cros_ec_sensor_set_report_latency(struct device *dev,
120 struct device_attribute *attr,
121 const char *buf, size_t len)
123 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
124 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
125 int integer, fract, ret;
128 ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract);
132 /* EC rate is in ms. */
133 latency = integer * 1000 + fract / 1000;
134 ret = cros_ec_sensor_set_ec_rate(st, latency);
141 static ssize_t cros_ec_sensor_get_report_latency(struct device *dev,
142 struct device_attribute *attr,
145 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
146 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
149 mutex_lock(&st->cmd_lock);
150 st->param.cmd = MOTIONSENSE_CMD_EC_RATE;
151 st->param.ec_rate.data = EC_MOTION_SENSE_NO_VALUE;
153 ret = cros_ec_motion_send_host_cmd(st, 0);
154 latency = st->resp->ec_rate.ret;
155 mutex_unlock(&st->cmd_lock);
159 return sprintf(buf, "%d.%06u\n",
161 (latency % 1000) * 1000);
164 static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
165 cros_ec_sensor_get_report_latency,
166 cros_ec_sensor_set_report_latency, 0);
168 static ssize_t hwfifo_watermark_max_show(struct device *dev,
169 struct device_attribute *attr,
172 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
173 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
175 return sprintf(buf, "%d\n", st->fifo_max_event_count);
178 static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
180 static const struct attribute *cros_ec_sensor_fifo_attributes[] = {
181 &iio_dev_attr_hwfifo_timeout.dev_attr.attr,
182 &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
186 int cros_ec_sensors_push_data(struct iio_dev *indio_dev,
190 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
196 * Ignore samples if the buffer is not set: it is needed if the ODR is
197 * set but the buffer is not enabled yet.
199 if (!iio_buffer_enabled(indio_dev))
202 out = (s16 *)st->samples;
204 indio_dev->active_scan_mask,
205 indio_dev->masklength) {
210 if (iio_device_get_clock(indio_dev) != CLOCK_BOOTTIME)
211 delta = iio_get_time_ns(indio_dev) - cros_ec_get_time_ns();
215 iio_push_to_buffers_with_timestamp(indio_dev, st->samples,
220 EXPORT_SYMBOL_GPL(cros_ec_sensors_push_data);
222 static void cros_ec_sensors_core_clean(void *arg)
224 struct platform_device *pdev = (struct platform_device *)arg;
225 struct cros_ec_sensorhub *sensor_hub =
226 dev_get_drvdata(pdev->dev.parent);
227 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
228 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
229 u8 sensor_num = st->param.info.sensor_num;
231 cros_ec_sensorhub_unregister_push_data(sensor_hub, sensor_num);
235 * cros_ec_sensors_core_init() - basic initialization of the core structure
236 * @pdev: platform device created for the sensors
237 * @indio_dev: iio device structure of the device
238 * @physical_device: true if the device refers to a physical device
239 * @trigger_capture: function pointer to call buffer is triggered,
240 * for backward compatibility.
241 * @push_data: function to call when cros_ec_sensorhub receives
242 * a sample for that sensor.
243 * @has_hw_fifo: Set true if this device has/uses a HW FIFO
245 * Return: 0 on success, -errno on failure.
247 int cros_ec_sensors_core_init(struct platform_device *pdev,
248 struct iio_dev *indio_dev,
249 bool physical_device,
250 cros_ec_sensors_capture_t trigger_capture,
251 cros_ec_sensorhub_push_data_cb_t push_data,
254 struct device *dev = &pdev->dev;
255 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
256 struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
257 struct cros_ec_dev *ec = sensor_hub->ec;
258 struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
260 int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
263 platform_set_drvdata(pdev, indio_dev);
265 state->ec = ec->ec_dev;
266 state->msg = devm_kzalloc(&pdev->dev,
267 max((u16)sizeof(struct ec_params_motion_sense),
268 state->ec->max_response), GFP_KERNEL);
272 state->resp = (struct ec_response_motion_sense *)state->msg->data;
274 mutex_init(&state->cmd_lock);
276 ret = cros_ec_get_host_cmd_version_mask(state->ec,
278 EC_CMD_MOTION_SENSE_CMD,
283 /* Set up the host command structure. */
284 state->msg->version = fls(ver_mask) - 1;
285 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
286 state->msg->outsize = sizeof(struct ec_params_motion_sense);
288 indio_dev->name = pdev->name;
290 if (physical_device) {
291 state->param.cmd = MOTIONSENSE_CMD_INFO;
292 state->param.info.sensor_num = sensor_platform->sensor_num;
293 ret = cros_ec_motion_send_host_cmd(state, 0);
295 dev_warn(dev, "Can not access sensor info\n");
298 state->type = state->resp->info.type;
299 state->loc = state->resp->info.location;
301 /* Set sign vector, only used for backward compatibility. */
302 memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
304 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
305 state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
307 /* 0 is a correct value used to stop the device */
308 if (state->msg->version < 3) {
309 get_default_min_max_freq(state->resp->info.type,
312 &state->fifo_max_event_count);
314 if (state->resp->info_3.max_frequency == 0) {
315 get_default_min_max_freq(state->resp->info.type,
320 frequencies[1] = state->resp->info_3.min_frequency;
321 frequencies[2] = state->resp->info_3.max_frequency;
323 state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
325 for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
326 state->frequencies[2 * i] = frequencies[i] / 1000;
327 state->frequencies[2 * i + 1] =
328 (frequencies[i] % 1000) * 1000;
331 if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
333 * Create a software buffer, feed by the EC FIFO.
334 * We can not use trigger here, as events are generated
335 * as soon as sample_frequency is set.
337 struct iio_buffer *buffer;
339 buffer = devm_iio_kfifo_allocate(dev);
343 iio_device_attach_buffer(indio_dev, buffer);
344 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
346 ret = cros_ec_sensorhub_register_push_data(
347 sensor_hub, sensor_platform->sensor_num,
348 indio_dev, push_data);
352 ret = devm_add_action_or_reset(
353 dev, cros_ec_sensors_core_clean, pdev);
357 /* Timestamp coming from FIFO are in ns since boot. */
358 ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
363 * The only way to get samples in buffer is to set a
364 * software trigger (systrig, hrtimer).
366 ret = devm_iio_triggered_buffer_setup(
367 dev, indio_dev, NULL, trigger_capture,
373 iio_buffer_set_attrs(indio_dev->buffer,
374 cros_ec_sensor_fifo_attributes);
380 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_init);
383 * cros_ec_motion_send_host_cmd() - send motion sense host command
384 * @state: pointer to state information for device
385 * @opt_length: optional length to reduce the response size, useful on the data
386 * path. Otherwise, the maximal allowed response size is used
388 * When called, the sub-command is assumed to be set in param->cmd.
390 * Return: 0 on success, -errno on failure.
392 int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state,
398 state->msg->insize = min(opt_length, state->ec->max_response);
400 state->msg->insize = state->ec->max_response;
402 memcpy(state->msg->data, &state->param, sizeof(state->param));
404 ret = cros_ec_cmd_xfer_status(state->ec, state->msg);
409 state->resp != (struct ec_response_motion_sense *)state->msg->data)
410 memcpy(state->resp, state->msg->data, ret);
414 EXPORT_SYMBOL_GPL(cros_ec_motion_send_host_cmd);
416 static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev,
417 uintptr_t private, const struct iio_chan_spec *chan,
418 const char *buf, size_t len)
420 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
424 ret = strtobool(buf, &calibrate);
430 mutex_lock(&st->cmd_lock);
431 st->param.cmd = MOTIONSENSE_CMD_PERFORM_CALIB;
432 ret = cros_ec_motion_send_host_cmd(st, 0);
434 dev_warn(&indio_dev->dev, "Unable to calibrate sensor\n");
437 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
438 st->calib[i].offset = st->resp->perform_calib.offset[i];
440 mutex_unlock(&st->cmd_lock);
442 return ret ? ret : len;
445 static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev,
447 const struct iio_chan_spec *chan, char *buf)
449 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
451 return snprintf(buf, PAGE_SIZE, "%d\n", st->param.info.sensor_num);
454 static ssize_t cros_ec_sensors_loc(struct iio_dev *indio_dev,
455 uintptr_t private, const struct iio_chan_spec *chan,
458 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
460 return snprintf(buf, PAGE_SIZE, "%s\n", cros_ec_loc[st->loc]);
463 const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {
466 .shared = IIO_SHARED_BY_ALL,
467 .write = cros_ec_sensors_calibrate
471 .shared = IIO_SHARED_BY_ALL,
472 .read = cros_ec_sensors_id
476 .shared = IIO_SHARED_BY_ALL,
477 .read = cros_ec_sensors_loc
481 EXPORT_SYMBOL_GPL(cros_ec_sensors_ext_info);
484 * cros_ec_sensors_idx_to_reg - convert index into offset in shared memory
485 * @st: pointer to state information for device
486 * @idx: sensor index (should be element of enum sensor_index)
488 * Return: address to read at
490 static unsigned int cros_ec_sensors_idx_to_reg(
491 struct cros_ec_sensors_core_state *st,
495 * When using LPC interface, only space for 2 Accel and one Gyro.
496 * First halfword of MOTIONSENSE_TYPE_ACCEL is used by angle.
498 if (st->type == MOTIONSENSE_TYPE_ACCEL)
499 return EC_MEMMAP_ACC_DATA + sizeof(u16) *
500 (1 + idx + st->param.info.sensor_num *
501 CROS_EC_SENSOR_MAX_AXIS);
503 return EC_MEMMAP_GYRO_DATA + sizeof(u16) * idx;
506 static int cros_ec_sensors_cmd_read_u8(struct cros_ec_device *ec,
507 unsigned int offset, u8 *dest)
509 return ec->cmd_readmem(ec, offset, 1, dest);
512 static int cros_ec_sensors_cmd_read_u16(struct cros_ec_device *ec,
513 unsigned int offset, u16 *dest)
516 int ret = ec->cmd_readmem(ec, offset, 2, &tmp);
519 *dest = le16_to_cpu(tmp);
525 * cros_ec_sensors_read_until_not_busy() - read until is not busy
527 * @st: pointer to state information for device
529 * Read from EC status byte until it reads not busy.
530 * Return: 8-bit status if ok, -errno on failure.
532 static int cros_ec_sensors_read_until_not_busy(
533 struct cros_ec_sensors_core_state *st)
535 struct cros_ec_device *ec = st->ec;
537 int ret, attempts = 0;
539 ret = cros_ec_sensors_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS, &status);
543 while (status & EC_MEMMAP_ACC_STATUS_BUSY_BIT) {
544 /* Give up after enough attempts, return error. */
545 if (attempts++ >= 50)
548 /* Small delay every so often. */
549 if (attempts % 5 == 0)
552 ret = cros_ec_sensors_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS,
562 * read_ec_sensors_data_unsafe() - read acceleration data from EC shared memory
563 * @indio_dev: pointer to IIO device
564 * @scan_mask: bitmap of the sensor indices to scan
565 * @data: location to store data
567 * This is the unsafe function for reading the EC data. It does not guarantee
568 * that the EC will not modify the data as it is being read in.
570 * Return: 0 on success, -errno on failure.
572 static int cros_ec_sensors_read_data_unsafe(struct iio_dev *indio_dev,
573 unsigned long scan_mask, s16 *data)
575 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
576 struct cros_ec_device *ec = st->ec;
580 /* Read all sensors enabled in scan_mask. Each value is 2 bytes. */
581 for_each_set_bit(i, &scan_mask, indio_dev->masklength) {
582 ret = cros_ec_sensors_cmd_read_u16(ec,
583 cros_ec_sensors_idx_to_reg(st, i),
588 *data *= st->sign[i];
596 * cros_ec_sensors_read_lpc() - read acceleration data from EC shared memory.
597 * @indio_dev: pointer to IIO device.
598 * @scan_mask: bitmap of the sensor indices to scan.
599 * @data: location to store data.
601 * Note: this is the safe function for reading the EC data. It guarantees
602 * that the data sampled was not modified by the EC while being read.
604 * Return: 0 on success, -errno on failure.
606 int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev,
607 unsigned long scan_mask, s16 *data)
609 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
610 struct cros_ec_device *ec = st->ec;
611 u8 samp_id = 0xff, status = 0;
612 int ret, attempts = 0;
615 * Continually read all data from EC until the status byte after
616 * all reads reflects that the EC is not busy and the sample id
617 * matches the sample id from before all reads. This guarantees
618 * that data read in was not modified by the EC while reading.
620 while ((status & (EC_MEMMAP_ACC_STATUS_BUSY_BIT |
621 EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK)) != samp_id) {
622 /* If we have tried to read too many times, return error. */
626 /* Read status byte until EC is not busy. */
627 ret = cros_ec_sensors_read_until_not_busy(st);
632 * Store the current sample id so that we can compare to the
633 * sample id after reading the data.
635 samp_id = ret & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
637 /* Read all EC data, format it, and store it into data. */
638 ret = cros_ec_sensors_read_data_unsafe(indio_dev, scan_mask,
643 /* Read status byte. */
644 ret = cros_ec_sensors_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS,
652 EXPORT_SYMBOL_GPL(cros_ec_sensors_read_lpc);
655 * cros_ec_sensors_read_cmd() - retrieve data using the EC command protocol
656 * @indio_dev: pointer to IIO device
657 * @scan_mask: bitmap of the sensor indices to scan
658 * @data: location to store data
660 * Return: 0 on success, -errno on failure.
662 int cros_ec_sensors_read_cmd(struct iio_dev *indio_dev,
663 unsigned long scan_mask, s16 *data)
665 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
669 /* Read all sensor data through a command. */
670 st->param.cmd = MOTIONSENSE_CMD_DATA;
671 ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->data));
673 dev_warn(&indio_dev->dev, "Unable to read sensor data\n");
677 for_each_set_bit(i, &scan_mask, indio_dev->masklength) {
678 *data = st->resp->data.data[i];
684 EXPORT_SYMBOL_GPL(cros_ec_sensors_read_cmd);
687 * cros_ec_sensors_capture() - the trigger handler function
688 * @irq: the interrupt number.
689 * @p: a pointer to the poll function.
691 * On a trigger event occurring, if the pollfunc is attached then this
692 * handler is called as a threaded interrupt (and hence may sleep). It
693 * is responsible for grabbing data from the device and pushing it into
694 * the associated buffer.
696 * Return: IRQ_HANDLED
698 irqreturn_t cros_ec_sensors_capture(int irq, void *p)
700 struct iio_poll_func *pf = p;
701 struct iio_dev *indio_dev = pf->indio_dev;
702 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
705 mutex_lock(&st->cmd_lock);
707 /* Clear capture data. */
708 memset(st->samples, 0, indio_dev->scan_bytes);
710 /* Read data based on which channels are enabled in scan mask. */
711 ret = st->read_ec_sensors_data(indio_dev,
712 *(indio_dev->active_scan_mask),
717 iio_push_to_buffers_with_timestamp(indio_dev, st->samples,
718 iio_get_time_ns(indio_dev));
722 * Tell the core we are done with this trigger and ready for the
725 iio_trigger_notify_done(indio_dev->trig);
727 mutex_unlock(&st->cmd_lock);
731 EXPORT_SYMBOL_GPL(cros_ec_sensors_capture);
734 * cros_ec_sensors_core_read() - function to request a value from the sensor
735 * @st: pointer to state information for device
736 * @chan: channel specification structure table
737 * @val: will contain one element making up the returned value
738 * @val2: will contain another element making up the returned value
739 * @mask: specifies which values to be requested
741 * Return: the type of value returned by the device
743 int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
744 struct iio_chan_spec const *chan,
745 int *val, int *val2, long mask)
750 case IIO_CHAN_INFO_SAMP_FREQ:
751 st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR;
752 st->param.sensor_odr.data =
753 EC_MOTION_SENSE_NO_VALUE;
755 ret = cros_ec_motion_send_host_cmd(st, 0);
759 frequency = st->resp->sensor_odr.ret;
760 *val = frequency / 1000;
761 *val2 = (frequency % 1000) * 1000;
762 ret = IIO_VAL_INT_PLUS_MICRO;
771 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_read);
774 * cros_ec_sensors_core_read_avail() - get available values
775 * @indio_dev: pointer to state information for device
776 * @chan: channel specification structure table
777 * @vals: list of available values
778 * @type: type of data returned
779 * @length: number of data returned in the array
780 * @mask: specifies which values to be requested
782 * Return: an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST
784 int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev,
785 struct iio_chan_spec const *chan,
791 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
794 case IIO_CHAN_INFO_SAMP_FREQ:
795 *length = ARRAY_SIZE(state->frequencies);
796 *vals = (const int *)&state->frequencies;
797 *type = IIO_VAL_INT_PLUS_MICRO;
798 return IIO_AVAIL_LIST;
803 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_read_avail);
806 * cros_ec_sensors_core_write() - function to write a value to the sensor
807 * @st: pointer to state information for device
808 * @chan: channel specification structure table
809 * @val: first part of value to write
810 * @val2: second part of value to write
811 * @mask: specifies which values to write
813 * Return: the type of value returned by the device
815 int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,
816 struct iio_chan_spec const *chan,
817 int val, int val2, long mask)
822 case IIO_CHAN_INFO_SAMP_FREQ:
823 frequency = val * 1000 + val2 / 1000;
824 st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR;
825 st->param.sensor_odr.data = frequency;
827 /* Always roundup, so caller gets at least what it asks for. */
828 st->param.sensor_odr.roundup = 1;
830 ret = cros_ec_motion_send_host_cmd(st, 0);
838 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
840 static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
842 struct platform_device *pdev = to_platform_device(dev);
843 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
844 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
847 if (st->range_updated) {
848 mutex_lock(&st->cmd_lock);
849 st->param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
850 st->param.sensor_range.data = st->curr_range;
851 st->param.sensor_range.roundup = 1;
852 ret = cros_ec_motion_send_host_cmd(st, 0);
853 mutex_unlock(&st->cmd_lock);
858 SIMPLE_DEV_PM_OPS(cros_ec_sensors_pm_ops, NULL, cros_ec_sensors_resume);
859 EXPORT_SYMBOL_GPL(cros_ec_sensors_pm_ops);
861 MODULE_DESCRIPTION("ChromeOS EC sensor hub core functions");
862 MODULE_LICENSE("GPL v2");