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: Trace EC sensors command

For debugging, add tracing for EC_CMD_MOTION_SENSE_CMD command:
- decode the name of the subcommand
- provide internal information for the most common sub-commands:
setting range, frequency, EC probing frequency, ...
- display return status.

When enabled, the tracing output is similar to:
/sys/kernel/debug/tracing # echo 1 > events/cros_ec/enable ; echo 1 > tracing_on ; cat trace_pipe | grep MOTIONSENSE_CMD_SENSOR_ODR
SensorDeviceImp-814 [003] ..... 686.176782: cros_ec_motion_host_cmd: MOTIONSENSE_CMD_SENSOR_ODR, id: 1, data: 200000, result: 4, return: 12500

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20250121232007.1020666-1-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gwendal Grignou and committed by
Jonathan Cameron
3bb41551 1ec0d78d

+96 -4
+2 -1
drivers/iio/common/cros_ec_sensors/Makefile
··· 3 3 # Makefile for sensors seen through the ChromeOS EC sensor hub. 4 4 # 5 5 6 - obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o 6 + cros-ec-sensors-core-objs += cros_ec_sensors_core.o cros_ec_sensors_trace.o 7 + obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros-ec-sensors-core.o 7 8 obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o 8 9 obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
+6 -3
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 23 23 #include <linux/platform_data/cros_ec_sensorhub.h> 24 24 #include <linux/platform_device.h> 25 25 26 + #include "cros_ec_sensors_trace.h" 27 + 26 28 /* 27 29 * Hard coded to the first device to support sensor fifo. The EC has a 2048 28 30 * byte fifo and will trigger an interrupt when fifo is 2/3 full. ··· 415 413 int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state, 416 414 u16 opt_length) 417 415 { 416 + struct ec_response_motion_sense *resp = (struct ec_response_motion_sense *)state->msg->data; 418 417 int ret; 419 418 420 419 if (opt_length) ··· 426 423 memcpy(state->msg->data, &state->param, sizeof(state->param)); 427 424 428 425 ret = cros_ec_cmd_xfer_status(state->ec, state->msg); 426 + trace_cros_ec_motion_host_cmd(&state->param, resp, ret); 429 427 if (ret < 0) 430 428 return ret; 431 429 432 - if (ret && 433 - state->resp != (struct ec_response_motion_sense *)state->msg->data) 434 - memcpy(state->resp, state->msg->data, ret); 430 + if (ret && state->resp != resp) 431 + memcpy(state->resp, resp, ret); 435 432 436 433 return 0; 437 434 }
+32
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_trace.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Trace events for the ChromeOS Embedded Controller 3 + // 4 + // Copyright 2025 Google LLC. 5 + 6 + #define TRACE_SYMBOL(a) {a, #a} 7 + 8 + // Generate the list using the following script: 9 + // sed -n 's/^.*\(MOTIONSENSE_CMD.*\) = .*,$/\tTRACE_SYMBOL(\1), \\/p' include/linux/platform_data/cros_ec_commands.h 10 + #define MOTIONSENSE_CMDS \ 11 + TRACE_SYMBOL(MOTIONSENSE_CMD_DUMP), \ 12 + TRACE_SYMBOL(MOTIONSENSE_CMD_INFO), \ 13 + TRACE_SYMBOL(MOTIONSENSE_CMD_EC_RATE), \ 14 + TRACE_SYMBOL(MOTIONSENSE_CMD_SENSOR_ODR), \ 15 + TRACE_SYMBOL(MOTIONSENSE_CMD_SENSOR_RANGE), \ 16 + TRACE_SYMBOL(MOTIONSENSE_CMD_KB_WAKE_ANGLE), \ 17 + TRACE_SYMBOL(MOTIONSENSE_CMD_DATA), \ 18 + TRACE_SYMBOL(MOTIONSENSE_CMD_FIFO_INFO), \ 19 + TRACE_SYMBOL(MOTIONSENSE_CMD_FIFO_FLUSH), \ 20 + TRACE_SYMBOL(MOTIONSENSE_CMD_FIFO_READ), \ 21 + TRACE_SYMBOL(MOTIONSENSE_CMD_PERFORM_CALIB), \ 22 + TRACE_SYMBOL(MOTIONSENSE_CMD_SENSOR_OFFSET), \ 23 + TRACE_SYMBOL(MOTIONSENSE_CMD_LIST_ACTIVITIES), \ 24 + TRACE_SYMBOL(MOTIONSENSE_CMD_SET_ACTIVITY), \ 25 + TRACE_SYMBOL(MOTIONSENSE_CMD_LID_ANGLE), \ 26 + TRACE_SYMBOL(MOTIONSENSE_CMD_FIFO_INT_ENABLE), \ 27 + TRACE_SYMBOL(MOTIONSENSE_CMD_SPOOF), \ 28 + TRACE_SYMBOL(MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE), \ 29 + TRACE_SYMBOL(MOTIONSENSE_CMD_SENSOR_SCALE) 30 + 31 + #define CREATE_TRACE_POINTS 32 + #include "cros_ec_sensors_trace.h"
+56
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Trace events for the ChromeOS Embedded Controller 4 + * 5 + * Copyright 2025 Google LLC. 6 + */ 7 + 8 + #undef TRACE_SYSTEM 9 + #define TRACE_SYSTEM cros_ec 10 + 11 + #if !defined(_CROS_EC_SENSORS_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) 12 + #define _CROS_EC_SENSORS_TRACE_H_ 13 + 14 + #include <linux/bits.h> 15 + #include <linux/types.h> 16 + #include <linux/platform_data/cros_ec_commands.h> 17 + #include <linux/platform_data/cros_ec_proto.h> 18 + 19 + #include <linux/tracepoint.h> 20 + 21 + TRACE_EVENT(cros_ec_motion_host_cmd, 22 + TP_PROTO(struct ec_params_motion_sense *param, 23 + struct ec_response_motion_sense *resp, 24 + int retval), 25 + TP_ARGS(param, resp, retval), 26 + TP_STRUCT__entry(__field(uint8_t, cmd) 27 + __field(uint8_t, sensor_id) 28 + __field(uint32_t, data) 29 + __field(int, retval) 30 + __field(int32_t, ret) 31 + ), 32 + TP_fast_assign(__entry->cmd = param->cmd; 33 + __entry->sensor_id = param->sensor_odr.sensor_num; 34 + __entry->data = param->sensor_odr.data; 35 + __entry->retval = retval; 36 + __entry->ret = retval > 0 ? resp->sensor_odr.ret : -1; 37 + ), 38 + TP_printk("%s, id: %d, data: %u, result: %u, return: %d", 39 + __print_symbolic(__entry->cmd, MOTIONSENSE_CMDS), 40 + __entry->sensor_id, 41 + __entry->data, 42 + __entry->retval, 43 + __entry->ret) 44 + ); 45 + 46 + #endif /* _CROS_EC_SENSORS_TRACE_H_ */ 47 + 48 + /* this part must be outside header guard */ 49 + 50 + #undef TRACE_INCLUDE_PATH 51 + #define TRACE_INCLUDE_PATH ../../drivers/iio/common/cros_ec_sensors 52 + 53 + #undef TRACE_INCLUDE_FILE 54 + #define TRACE_INCLUDE_FILE cros_ec_sensors_trace 55 + 56 + #include <trace/define_trace.h>