diff mbox series

event: add an event for livetree fixups

Message ID 20240412190542.1576801-1-caleb.connolly@linaro.org
State New
Headers show
Series event: add an event for livetree fixups | expand

Commit Message

Caleb Connolly April 12, 2024, 7:04 p.m. UTC
Introduce a new EVT_OF_LIVE event to allow for the livetree to be
modified before dm_init_and_scan(). Boards can perform fixups here to
handle incompatibilities between U-Boot drivers and upstream DT.

This will be used by Qualcomm platforms in future patches to enable
setting the dr_mode property if the board doesn't provide one. This has to be
set before dm_init_and_scan() is called as this property effects the binding of
drivers.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 common/board_r.c |  1 +
 common/event.c   |  2 ++
 include/event.h  | 12 ++++++++++++
 3 files changed, 15 insertions(+)

Comments

Tom Rini April 12, 2024, 7:45 p.m. UTC | #1
On Fri, Apr 12, 2024 at 08:04:02PM +0100, Caleb Connolly wrote:

> Introduce a new EVT_OF_LIVE event to allow for the livetree to be
> modified before dm_init_and_scan(). Boards can perform fixups here to
> handle incompatibilities between U-Boot drivers and upstream DT.
> 
> This will be used by Qualcomm platforms in future patches to enable
> setting the dr_mode property if the board doesn't provide one. This has to be
> set before dm_init_and_scan() is called as this property effects the binding of
> drivers.

This doesn't quite explain why the answer isn't "fix the device tree
source" and instead "perform a live fixup". Thanks.
Caleb Connolly April 15, 2024, 10:45 a.m. UTC | #2
On 12/04/2024 20:45, Tom Rini wrote:
> On Fri, Apr 12, 2024 at 08:04:02PM +0100, Caleb Connolly wrote:
> 
>> Introduce a new EVT_OF_LIVE event to allow for the livetree to be
>> modified before dm_init_and_scan(). Boards can perform fixups here to
>> handle incompatibilities between U-Boot drivers and upstream DT.
>>
>> This will be used by Qualcomm platforms in future patches to enable
>> setting the dr_mode property if the board doesn't provide one. This has to be
>> set before dm_init_and_scan() is called as this property effects the binding of
>> drivers.
> 
> This doesn't quite explain why the answer isn't "fix the device tree
> source" and instead "perform a live fixup". Thanks.

Hi Tom,

I think the specifics here that make this difficult is that on some
Qualcomm boards there is only one USB controller, which can be muxed
either to a type-c port or to a USB hub via a DIP switch (the state of
which cannot easily be read out).

The DT should therefore either not set dr_mode or set it to OTG. This is
what Linux expects (and it can do proper role detection).

The dwc3 driver in U-Boot currently doesn't have the ability to
dynamically mode switch, this is something I'd like to add (as it would
let us easily flash these boards from U-Boot as well as boot from USB or
ethernet), but in the mean time the only way to get these boards into
host mode (which is the preferred default) is to modify the DT in a way
that breaks Linux.

Hence the proposal in this patch.

If this is ok for you then I'll re-send with this additional context in
the commit description.

Thanks and regards,
Tom Rini April 16, 2024, 4:05 p.m. UTC | #3
On Mon, Apr 15, 2024 at 11:45:29AM +0100, Caleb Connolly wrote:
> 
> 
> On 12/04/2024 20:45, Tom Rini wrote:
> > On Fri, Apr 12, 2024 at 08:04:02PM +0100, Caleb Connolly wrote:
> > 
> >> Introduce a new EVT_OF_LIVE event to allow for the livetree to be
> >> modified before dm_init_and_scan(). Boards can perform fixups here to
> >> handle incompatibilities between U-Boot drivers and upstream DT.
> >>
> >> This will be used by Qualcomm platforms in future patches to enable
> >> setting the dr_mode property if the board doesn't provide one. This has to be
> >> set before dm_init_and_scan() is called as this property effects the binding of
> >> drivers.
> > 
> > This doesn't quite explain why the answer isn't "fix the device tree
> > source" and instead "perform a live fixup". Thanks.
> 
> Hi Tom,
> 
> I think the specifics here that make this difficult is that on some
> Qualcomm boards there is only one USB controller, which can be muxed
> either to a type-c port or to a USB hub via a DIP switch (the state of
> which cannot easily be read out).
> 
> The DT should therefore either not set dr_mode or set it to OTG. This is
> what Linux expects (and it can do proper role detection).
> 
> The dwc3 driver in U-Boot currently doesn't have the ability to
> dynamically mode switch, this is something I'd like to add (as it would
> let us easily flash these boards from U-Boot as well as boot from USB or
> ethernet), but in the mean time the only way to get these boards into
> host mode (which is the preferred default) is to modify the DT in a way
> that breaks Linux.
> 
> Hence the proposal in this patch.
> 
> If this is ok for you then I'll re-send with this additional context in
> the commit description.

So this seems even more special cased than what I was thinking it was.
Would it really be so hard to just add a dummy driver for a few
compatibles in this case? I prefer having two or three real users of a
use case before designing the abstraction for it. Thanks.
diff mbox series

Patch

diff --git a/common/board_r.c b/common/board_r.c
index da0b80f24ff0..7d2da51193ab 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -217,8 +217,9 @@  static int initr_of_live(void)
 				    (struct device_node **)gd_of_root_ptr());
 		bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
 		if (ret)
 			return ret;
+		event_notify_null(EVT_OF_LIVE);
 	}
 
 	return 0;
 }
diff --git a/common/event.c b/common/event.c
index 16c2ba6cc921..db32ea0d06f8 100644
--- a/common/event.c
+++ b/common/event.c
@@ -45,8 +45,10 @@  const char *const type_name[] = {
 
 	/* fdt hooks */
 	"ft_fixup",
 
+	"of_live",
+
 	/* main loop events */
 	"main_loop",
 };
 
diff --git a/include/event.h b/include/event.h
index a8f046da3c32..c6436c07d16f 100644
--- a/include/event.h
+++ b/include/event.h
@@ -144,8 +144,20 @@  enum event_t {
 	 * images fail.
 	 */
 	EVT_FT_FIXUP,
 
+	/**
+	 * @EVT_OF_LIVE:
+	 * This event is triggered when using CONFIG_OF_LIVE immediately after
+	 * the live tree has been created. It has no parameters, the live tree
+	 * can be accessed from gd->of_root, or using the of_* helpers.
+	 *
+	 * This is intended to be used for performing board specific fixups
+	 * on the tree before it is used by U-Boot. It is much more efficient
+	 * to access and modify than the FDT.
+	 */
+	EVT_OF_LIVE,
+
 	/**
 	 * @EVT_MAIN_LOOP:
 	 * This event is triggered immediately before calling main_loop() which
 	 * is the entry point of the command line. Its parameter is NULL.