Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] usb: typec: add trace point for typec_set_mode
@ 2026-06-17 20:03 Ahmad Fatoum
  2026-06-18 10:56 ` Heikki Krogerus
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2026-06-17 20:03 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Steven Rostedt,
	Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-usb, linux-trace-kernel, kernel, Ahmad Fatoum

Some Type-C controllers toggle muxes themselves. Other controllers like
the TUSB320 report the mode to the host, so it can control the muxes.

To improve debuggability of both kinds of drivers, add a trace point that
can be used to keep track of the mode being set inside the Type-C
framework:

  echo 1 > /sys/kernel/debug/tracing/events/typec/typec_mode/enable

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 MAINTAINERS                  |  1 +
 drivers/usb/typec/class.c    |  9 ++++++++-
 include/trace/events/typec.h | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index c8d4b913f26c..ddd59e5e6eaf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27753,6 +27753,7 @@ F:	Documentation/ABI/testing/sysfs-class-typec
 F:	Documentation/driver-api/usb/typec.rst
 F:	drivers/usb/typec/
 F:	include/linux/usb/typec.h
+F:	include/trace/events/typec*.h
 
 USB TYPEC INTEL PMC MUX DRIVER
 M:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 0977581ad1b6..9316d067f19a 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -20,6 +20,9 @@
 #include "class.h"
 #include "pd.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/typec.h>
+
 static DEFINE_IDA(typec_index_ida);
 
 const struct class typec_class = {
@@ -2427,10 +2430,14 @@ EXPORT_SYMBOL_GPL(typec_get_orientation);
 int typec_set_mode(struct typec_port *port, int mode)
 {
 	struct typec_mux_state state = { };
+	int ret;
 
 	state.mode = mode;
 
-	return typec_mux_set(port->mux, &state);
+	ret = typec_mux_set(port->mux, &state);
+	trace_typec_mode(port, mode, ret);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(typec_set_mode);
 
diff --git a/include/trace/events/typec.h b/include/trace/events/typec.h
new file mode 100644
index 000000000000..a7dcb9f3fd49
--- /dev/null
+++ b/include/trace/events/typec.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM typec
+
+#if !defined(_TRACE_TYPEC_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_TYPEC_H
+
+#include <linux/usb/typec.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(typec_mode,
+
+	TP_PROTO(struct typec_port *port, int mode, int err),
+
+	TP_ARGS(port, mode, err),
+
+	TP_STRUCT__entry(
+		__string(device, dev_name(&port->dev))
+		__field(int, mode)
+		__field(int, err)
+	),
+
+	TP_fast_assign(
+		__assign_str(device);
+		__entry->mode = mode;
+		__entry->err = err;
+	),
+
+	TP_printk("%s mode=%d (%d)",
+		  __get_str(device), __entry->mode, __entry->err)
+);
+
+#endif /* if !defined(_TRACE_TYPEC_H) || defined(TRACE_HEADER_MULTI_READ) */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>

---
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
change-id: 20260617-typec_set_mode-tracepoint-011fc43feaca

Best regards,
--  
Ahmad Fatoum <a.fatoum@pengutronix.de>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: add trace point for typec_set_mode
  2026-06-17 20:03 [PATCH] usb: typec: add trace point for typec_set_mode Ahmad Fatoum
@ 2026-06-18 10:56 ` Heikki Krogerus
  2026-06-18 11:00   ` Ahmad Fatoum
  0 siblings, 1 reply; 4+ messages in thread
From: Heikki Krogerus @ 2026-06-18 10:56 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Greg Kroah-Hartman, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, linux-kernel, linux-usb, linux-trace-kernel,
	kernel

Hi Ahmad,

On Wed, Jun 17, 2026 at 10:03:04PM +0200, Ahmad Fatoum wrote:
> Some Type-C controllers toggle muxes themselves. Other controllers like
> the TUSB320 report the mode to the host, so it can control the muxes.
> 
> To improve debuggability of both kinds of drivers, add a trace point that
> can be used to keep track of the mode being set inside the Type-C
> framework:
> 
>   echo 1 > /sys/kernel/debug/tracing/events/typec/typec_mode/enable
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  MAINTAINERS                  |  1 +
>  drivers/usb/typec/class.c    |  9 ++++++++-
>  include/trace/events/typec.h | 36 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index c8d4b913f26c..ddd59e5e6eaf 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -27753,6 +27753,7 @@ F:	Documentation/ABI/testing/sysfs-class-typec
>  F:	Documentation/driver-api/usb/typec.rst
>  F:	drivers/usb/typec/
>  F:	include/linux/usb/typec.h
> +F:	include/trace/events/typec*.h
>  
>  USB TYPEC INTEL PMC MUX DRIVER
>  M:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 0977581ad1b6..9316d067f19a 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -20,6 +20,9 @@
>  #include "class.h"
>  #include "pd.h"
>  
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/typec.h>

Those should probable go to drivers/usb/typec/trace.c and then you
need add something like this to drivers/usb/typec/Makefile:

 obj-$(CONFIG_TYPEC)            += typec.o
 typec-y                                := class.o mux.o bus.o pd.o retimer.o mode_selection.o
 typec-$(CONFIG_ACPI)           += port-mapper.o
+typec-$(CONFIG_TRACING)                += trace.o
 obj-$(CONFIG_TYPEC)            += altmodes/
 obj-$(CONFIG_TYPEC_TCPM)       += tcpm/
 obj-$(CONFIG_TYPEC_UCSI)       += ucsi/


Thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: add trace point for typec_set_mode
  2026-06-18 10:56 ` Heikki Krogerus
@ 2026-06-18 11:00   ` Ahmad Fatoum
  2026-06-18 11:31     ` Heikki Krogerus
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2026-06-18 11:00 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg Kroah-Hartman, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, linux-kernel, linux-usb, linux-trace-kernel,
	kernel

Hello Heikki,

On 6/18/26 12:56 PM, Heikki Krogerus wrote:
> On Wed, Jun 17, 2026 at 10:03:04PM +0200, Ahmad Fatoum wrote:
>> --- a/drivers/usb/typec/class.c
>> +++ b/drivers/usb/typec/class.c
>> @@ -20,6 +20,9 @@
>>  #include "class.h"
>>  #include "pd.h"
>>  
>> +#define CREATE_TRACE_POINTS
>> +#include <trace/events/typec.h>
> 
> Those should probable go to drivers/usb/typec/trace.c and then you
> need add something like this to drivers/usb/typec/Makefile:
> 
>  obj-$(CONFIG_TYPEC)            += typec.o
>  typec-y                                := class.o mux.o bus.o pd.o retimer.o mode_selection.o
>  typec-$(CONFIG_ACPI)           += port-mapper.o
> +typec-$(CONFIG_TRACING)                += trace.o

Thanks for the suggestion. I will do that for v2.

I also saw there is Sashiko AI feedback on this patch[1], but I am not
familiar enough with how the event headers are used outside the kernel
to determine if that's actionable advice or if it can be ignored.

Do you have an opinion on that?

[1]:
https://sashiko.dev/#/patchset/20260617-typec_set_mode-tracepoint-v1-1-bdfbb39cfccd%40pengutronix.de

Thanks,
Ahmad

> 
> 
> Thanks,
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: typec: add trace point for typec_set_mode
  2026-06-18 11:00   ` Ahmad Fatoum
@ 2026-06-18 11:31     ` Heikki Krogerus
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2026-06-18 11:31 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Greg Kroah-Hartman, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, linux-kernel, linux-usb, linux-trace-kernel,
	kernel

Hi,

On Thu, Jun 18, 2026 at 01:00:58PM +0200, Ahmad Fatoum wrote:
> Hello Heikki,
> 
> On 6/18/26 12:56 PM, Heikki Krogerus wrote:
> > On Wed, Jun 17, 2026 at 10:03:04PM +0200, Ahmad Fatoum wrote:
> >> --- a/drivers/usb/typec/class.c
> >> +++ b/drivers/usb/typec/class.c
> >> @@ -20,6 +20,9 @@
> >>  #include "class.h"
> >>  #include "pd.h"
> >>  
> >> +#define CREATE_TRACE_POINTS
> >> +#include <trace/events/typec.h>
> > 
> > Those should probable go to drivers/usb/typec/trace.c and then you
> > need add something like this to drivers/usb/typec/Makefile:
> > 
> >  obj-$(CONFIG_TYPEC)            += typec.o
> >  typec-y                                := class.o mux.o bus.o pd.o retimer.o mode_selection.o
> >  typec-$(CONFIG_ACPI)           += port-mapper.o
> > +typec-$(CONFIG_TRACING)                += trace.o
> 
> Thanks for the suggestion. I will do that for v2.
> 
> I also saw there is Sashiko AI feedback on this patch[1], but I am not
> familiar enough with how the event headers are used outside the kernel
> to determine if that's actionable advice or if it can be ignored.
> 
> Do you have an opinion on that?
> 
> [1]:
> https://sashiko.dev/#/patchset/20260617-typec_set_mode-tracepoint-v1-1-bdfbb39cfccd%40pengutronix.de

It's correct. You need to use a private trace.h in this case, so just
move it here: drivers/usb/typec/trace.h

And also make sure you include everything needed in that header like
it's telling you.

Thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-18 11:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-17 20:03 [PATCH] usb: typec: add trace point for typec_set_mode Ahmad Fatoum
2026-06-18 10:56 ` Heikki Krogerus
2026-06-18 11:00   ` Ahmad Fatoum
2026-06-18 11:31     ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox