Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: cros_ec_sensors: Flush when changing the FIFO timeout

|hwfifo_timeout| is used by the EC firmware only when new samples are
available.
When the timeout changes, espcially when the new timeout is shorter than
the current one, send the samples waiting in the FIFO to the host.
Inline the call to transmit |hwfifo_timeout| value to the firmware.

Now flush when a sensor is suspended (ODR set to 0) as well.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Link: https://patch.msgid.link/20250423220506.2061021-1-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gwendal Grignou and committed by
Jonathan Cameron
e50cf7e2 50ed17cd

+31 -17
+31 -17
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 91 91 } 92 92 } 93 93 94 - static int cros_ec_sensor_set_ec_rate(struct cros_ec_sensors_core_state *st, 95 - int rate) 96 - { 97 - int ret; 98 - 99 - if (rate > U16_MAX) 100 - rate = U16_MAX; 101 - 102 - mutex_lock(&st->cmd_lock); 103 - st->param.cmd = MOTIONSENSE_CMD_EC_RATE; 104 - st->param.ec_rate.data = rate; 105 - ret = cros_ec_motion_send_host_cmd(st, 0); 106 - mutex_unlock(&st->cmd_lock); 107 - return ret; 108 - } 109 - 110 94 static ssize_t cros_ec_sensor_set_report_latency(struct device *dev, 111 95 struct device_attribute *attr, 112 96 const char *buf, size_t len) ··· 106 122 107 123 /* EC rate is in ms. */ 108 124 latency = integer * 1000 + fract / 1000; 109 - ret = cros_ec_sensor_set_ec_rate(st, latency); 125 + 126 + mutex_lock(&st->cmd_lock); 127 + st->param.cmd = MOTIONSENSE_CMD_EC_RATE; 128 + st->param.ec_rate.data = min(U16_MAX, latency); 129 + ret = cros_ec_motion_send_host_cmd(st, 0); 130 + if (ret < 0) { 131 + mutex_unlock(&st->cmd_lock); 132 + return ret; 133 + } 134 + 135 + /* 136 + * Flush samples currently in the FIFO, especially when the new latency 137 + * is shorter than the old one: new timeout value is only considered when 138 + * there is a new sample available. It can take a while for a slow 139 + * sensor. 140 + */ 141 + st->param.cmd = MOTIONSENSE_CMD_FIFO_FLUSH; 142 + ret = cros_ec_motion_send_host_cmd(st, 0); 143 + mutex_unlock(&st->cmd_lock); 110 144 if (ret < 0) 111 145 return ret; 112 146 ··· 834 832 st->param.sensor_odr.roundup = 1; 835 833 836 834 ret = cros_ec_motion_send_host_cmd(st, 0); 835 + if (ret) 836 + break; 837 + 838 + /* Flush the FIFO when a sensor is stopped. 839 + * If the FIFO has just been emptied, pending samples will be 840 + * stuck until new samples are available. It will not happen 841 + * when all the sensors are stopped. 842 + */ 843 + if (frequency == 0) { 844 + st->param.cmd = MOTIONSENSE_CMD_FIFO_FLUSH; 845 + ret = cros_ec_motion_send_host_cmd(st, 0); 846 + } 837 847 break; 838 848 default: 839 849 ret = -EINVAL;