|
22 | 22 | #include <linux/platform_data/cros_ec_sensorhub.h>
|
23 | 23 | #include <linux/platform_device.h>
|
24 | 24 |
|
| 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 | + |
25 | 31 | static char *cros_ec_loc[] = {
|
26 | 32 | [MOTIONSENSE_LOC_BASE] = "base",
|
27 | 33 | [MOTIONSENSE_LOC_LID] = "lid",
|
@@ -55,8 +61,15 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
|
55 | 61 |
|
56 | 62 | static void get_default_min_max_freq(enum motionsensor_type type,
|
57 | 63 | u32 *min_freq,
|
58 |
| - u32 *max_freq) |
| 64 | + u32 *max_freq, |
| 65 | + u32 *max_fifo_events) |
59 | 66 | {
|
| 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 | + |
60 | 73 | switch (type) {
|
61 | 74 | case MOTIONSENSE_TYPE_ACCEL:
|
62 | 75 | case MOTIONSENSE_TYPE_GYRO:
|
@@ -149,8 +162,21 @@ static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
|
149 | 162 | cros_ec_sensor_get_report_latency,
|
150 | 163 | cros_ec_sensor_set_report_latency, 0);
|
151 | 164 |
|
| 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 | + |
152 | 177 | const struct attribute *cros_ec_sensor_fifo_attributes[] = {
|
153 | 178 | &iio_dev_attr_hwfifo_timeout.dev_attr.attr,
|
| 179 | + &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, |
154 | 180 | NULL,
|
155 | 181 | };
|
156 | 182 | EXPORT_SYMBOL_GPL(cros_ec_sensor_fifo_attributes);
|
@@ -279,12 +305,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
|
279 | 305 | if (state->msg->version < 3) {
|
280 | 306 | get_default_min_max_freq(state->resp->info.type,
|
281 | 307 | &state->frequencies[1],
|
282 |
| - &state->frequencies[2]); |
| 308 | + &state->frequencies[2], |
| 309 | + &state->fifo_max_event_count); |
283 | 310 | } else {
|
284 | 311 | state->frequencies[1] =
|
285 | 312 | state->resp->info_3.min_frequency;
|
286 | 313 | state->frequencies[2] =
|
287 | 314 | state->resp->info_3.max_frequency;
|
| 315 | + state->fifo_max_event_count = |
| 316 | + state->resp->info_3.fifo_max_event_count; |
288 | 317 | }
|
289 | 318 |
|
290 | 319 | if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
|
|
0 commit comments