Skip to content

Commit cb87556

Browse files
gwendalcrEnric Balletbo i Serra
authored andcommitted
iio: cros_ec: Report hwfifo_watermark_max
Report the maximum amount of sample the EC can hold. This is not tunable, but can be useful for application to find out the maximum amount of time it can sleep when hwfifo_timeout is set to a large number. Signed-off-by: Gwendal Grignou <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent 6562793 commit cb87556

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#include <linux/platform_data/cros_ec_sensorhub.h>
2323
#include <linux/platform_device.h>
2424

25+
/*
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.
28+
*/
29+
#define CROS_EC_FIFO_SIZE (2048 * 2 / 3)
30+
2531
static char *cros_ec_loc[] = {
2632
[MOTIONSENSE_LOC_BASE] = "base",
2733
[MOTIONSENSE_LOC_LID] = "lid",
@@ -55,8 +61,15 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
5561

5662
static void get_default_min_max_freq(enum motionsensor_type type,
5763
u32 *min_freq,
58-
u32 *max_freq)
64+
u32 *max_freq,
65+
u32 *max_fifo_events)
5966
{
67+
/*
68+
* We don't know fifo size, set to size previously used by older
69+
* hardware.
70+
*/
71+
*max_fifo_events = CROS_EC_FIFO_SIZE;
72+
6073
switch (type) {
6174
case MOTIONSENSE_TYPE_ACCEL:
6275
case MOTIONSENSE_TYPE_GYRO:
@@ -149,8 +162,21 @@ static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
149162
cros_ec_sensor_get_report_latency,
150163
cros_ec_sensor_set_report_latency, 0);
151164

165+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
166+
struct device_attribute *attr,
167+
char *buf)
168+
{
169+
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
170+
struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
171+
172+
return sprintf(buf, "%d\n", st->fifo_max_event_count);
173+
}
174+
175+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
176+
152177
const struct attribute *cros_ec_sensor_fifo_attributes[] = {
153178
&iio_dev_attr_hwfifo_timeout.dev_attr.attr,
179+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
154180
NULL,
155181
};
156182
EXPORT_SYMBOL_GPL(cros_ec_sensor_fifo_attributes);
@@ -279,12 +305,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
279305
if (state->msg->version < 3) {
280306
get_default_min_max_freq(state->resp->info.type,
281307
&state->frequencies[1],
282-
&state->frequencies[2]);
308+
&state->frequencies[2],
309+
&state->fifo_max_event_count);
283310
} else {
284311
state->frequencies[1] =
285312
state->resp->info_3.min_frequency;
286313
state->frequencies[2] =
287314
state->resp->info_3.max_frequency;
315+
state->fifo_max_event_count =
316+
state->resp->info_3.fifo_max_event_count;
288317
}
289318

290319
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {

include/linux/iio/common/cros_ec_sensors_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef irqreturn_t (*cros_ec_sensors_capture_t)(int irq, void *p);
5050
* the timestamp. The timestamp is always last and
5151
* is always 8-byte aligned.
5252
* @read_ec_sensors_data: function used for accessing sensors values
53+
* @fifo_max_event_count: Size of the EC sensor FIFO
5354
*/
5455
struct cros_ec_sensors_core_state {
5556
struct cros_ec_device *ec;
@@ -72,6 +73,8 @@ struct cros_ec_sensors_core_state {
7273
int (*read_ec_sensors_data)(struct iio_dev *indio_dev,
7374
unsigned long scan_mask, s16 *data);
7475

76+
u32 fifo_max_event_count;
77+
7578
/* Table of known available frequencies : 0, Min and Max in mHz */
7679
int frequencies[3];
7780
};

0 commit comments

Comments
 (0)