All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
@ 2022-03-15  5:53 Simon Glass
  2022-03-15 11:24 ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2022-03-15  5:53 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Tom Rini, Marek Vasut, Soeren Moch, Simon Glass, Pavel Herrmann

This is an attempt to cover the common cases found when enabling driver
model for serial on a new board.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/develop/driver-model/serial-howto.rst | 138 ++++++++++++++++++++++
 1 file changed, 138 insertions(+)

diff --git a/doc/develop/driver-model/serial-howto.rst b/doc/develop/driver-model/serial-howto.rst
index 1469131124b..c64a562499b 100644
--- a/doc/develop/driver-model/serial-howto.rst
+++ b/doc/develop/driver-model/serial-howto.rst
@@ -44,3 +44,141 @@ this involves these steps:
 - build and get u-boot-dtb.bin so you can test it
 - Your drivers can now use device tree
 - For device tree in SPL, define CONFIG_SPL_OF_CONTROL
+
+
+Converting boards to CONFIG_DM_SERIAL
+-------------------------------------
+
+If your SoC has a serial driver that uses driver model (has U_BOOT_DRIVER() in
+it) then you may still find that your board has not been converted. To convert
+your board, enable the option and see if you can get it working.
+
+Firstly you will have a lot more success if you have a method of debugging your
+board, such as a JTAG connection. Failing that the debug UART is useful,
+although since you are trying to get the UART driver running, it will interfere
+with your efforts eventually.
+
+Secondly, while the UART is a relatively simple peripheral, it may need quite a
+few pieces to be up and running before it will work, such as the correct pin
+muxing, clocks, power domains and possibly even GPIOs, if an external
+transceiver is used. Look at other boards that use the same SoC, for clues as to
+what is needed.
+
+Thirdly, when added tags, put them in a xxx-u-boot.dtsi file, where xxx is your
+board name, or SoC name. There may already be a file for your SoC which contains
+what you need. U-Boot automatically includes these files: see :ref:`dttweaks`.
+
+Here are some things you might need to consider:
+
+1. The serial driver itself needs to be present before relocation, so that the
+U-Boot banner appears. Make sure it has a u-boot,pre-reloc tag in the device
+tree, so that the serial driver is bound when U-Boot starts.
+
+For example, on iMX6::
+
+   lpuart3: serial@5a090000 {
+      compatible = "fsl,imx8qm-lpuart";
+      ...
+   };
+
+put this in your xxx-u-boot.dtsi file::
+
+   &lpuart3 {
+      u-boot,dm-pre-proper;
+   };
+
+2. If your serial port requires a particular pinmux configuration, you may need
+a pinctrl driver. This needs to have a u-boot,pre-reloc tag also. Take care that
+any subnodes have the same tag, if they are needed to make the correct pinctrl
+available.
+
+For example, on RK3288, the UART2 uses uart2_xfer::
+
+   uart2: serial@ff690000 {
+      ...
+      pinctrl-0 = <&uart2_xfer>;
+   };
+
+which is defined as follows::
+
+   pinctrl: pinctrl {
+      compatible = "rockchip,rk3228-pinctrl";
+
+      uart2: uart2 {
+         uart2_xfer: uart2-xfer {
+            rockchip,pins = <1 RK_PC2 RK_FUNC_2 &pcfg_pull_up>,
+                  <1 RK_PC3 RK_FUNC_2 &pcfg_pull_none>;
+         };
+
+      ...
+   };
+
+This means you must make the uart2-xfer node available as well as all its
+parents, so put this in your xxx-u-boot.dtsi file::
+
+   &pinctrl {
+      u-boot,dm-pre-reloc;
+   };
+
+   &uart2 {
+      u-boot,dm-pre-reloc;
+   };
+
+   &uart2_xfer {
+      u-boot,dm-pre-reloc;
+   };
+
+3. The same applies to power domains. For example, if a particular power domain
+must be enabled for the serial port to work, you need to ensure it is available
+before relocation:
+
+For example, on iMX6, put this in your xxx-u-boot.dtsi file::
+
+   &pd_dma {
+      u-boot,dm-pre-proper;
+   };
+
+   &pd_dma_lpuart3 {
+      u-boot,dm-pre-proper;
+   };
+
+4. The same applies to clocks, in the same way. Make sure that when your driver
+requests a clock, typically with clk_get_by_index(), it is available.
+
+
+Generally a failure to find a required device will cause an error which you can
+catch, if you have the debug UART working. U-Boot outputs serial data to the
+debug UART until the point where the real serial driver takes over. This point
+is marked by gd->flags having the GD_FLG_SERIAL_READY flag set. This change
+happens in serial_init() in serial-uclass.c so until that point the debug UART
+is used. You can see the relevant code in putc()
+, for example::
+
+   /* if we don't have a console yet, use the debug UART */
+   if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) {
+      printch(c);
+      return;
+   }
+   ... carries on to use the console / serial driver
+
+Note that in device_probe() the call to pinctrl_select_state() silently fails
+if the pinctrl driver fails. You can add a temporary check there if needed.
+
+Why do we have all these tags? The problem is that before relocation we don't
+want to bind all the drivers since memory is limited and the CPU may be running
+at a slow speed. So many boards will fail to boot without this optimisation, or
+may take a long time to start up (e.g. hundreds of milliseconds). The tags tell
+U-Boot which drivers to bind.
+
+The good news is that this problem is normally solved by the SoC, so that any
+boards that use it will work as normal. But in some cases there are multiple
+UARTs or multiple pinmux options, which means that each board may need to do
+some customisation.
+
+Serial in SPL
+-------------
+
+A similar process is needed in SPL, but in this case the u-boot,dm-spl or
+u-boot,dm-tpl tags are used. Add these in the same way as above, to ensure that
+the SPL device tree contains the required nodes (see spl/u-boot-spl.dtb for
+what it actually contains).
-- 
2.35.1.723.g4982287a31-goog


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

* Re: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
  2022-03-15  5:53 [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board Simon Glass
@ 2022-03-15 11:24 ` Fabio Estevam
  2022-03-15 13:01   ` Tom Rini
  2022-03-15 21:15   ` Simon Glass
  0 siblings, 2 replies; 6+ messages in thread
From: Fabio Estevam @ 2022-03-15 11:24 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Rini, Marek Vasut, Soeren Moch, Pavel Herrmann

Hi Simon,

On Tue, Mar 15, 2022 at 2:54 AM Simon Glass <sjg@chromium.org> wrote:

> +For example, on iMX6::
> +
> +   lpuart3: serial@5a090000 {
> +      compatible = "fsl,imx8qm-lpuart";

I found this part confusing as i.MX6 does not have lpuart.

> +For example, on iMX6, put this in your xxx-u-boot.dtsi file::
> +
> +   &pd_dma {
> +      u-boot,dm-pre-proper;
> +   };
> +
> +   &pd_dma_lpuart3 {
> +      u-boot,dm-pre-proper;

Same here, these pd_dma and pd_dma_lpuart3 nodes do not exist for i.MX6.

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

* Re: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
  2022-03-15 11:24 ` Fabio Estevam
@ 2022-03-15 13:01   ` Tom Rini
  2022-03-15 21:15   ` Simon Glass
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Rini @ 2022-03-15 13:01 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Simon Glass, U-Boot Mailing List, Marek Vasut, Soeren Moch,
	Pavel Herrmann

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

On Tue, Mar 15, 2022 at 08:24:54AM -0300, Fabio Estevam wrote:
> Hi Simon,
> 
> On Tue, Mar 15, 2022 at 2:54 AM Simon Glass <sjg@chromium.org> wrote:
> 
> > +For example, on iMX6::
> > +
> > +   lpuart3: serial@5a090000 {
> > +      compatible = "fsl,imx8qm-lpuart";
> 
> I found this part confusing as i.MX6 does not have lpuart.
> 
> > +For example, on iMX6, put this in your xxx-u-boot.dtsi file::
> > +
> > +   &pd_dma {
> > +      u-boot,dm-pre-proper;
> > +   };
> > +
> > +   &pd_dma_lpuart3 {
> > +      u-boot,dm-pre-proper;
> 
> Same here, these pd_dma and pd_dma_lpuart3 nodes do not exist for i.MX6.

Yes, lets make sure we have examples here that are correct for a given
SoC.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

* Re: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
  2022-03-15 11:24 ` Fabio Estevam
  2022-03-15 13:01   ` Tom Rini
@ 2022-03-15 21:15   ` Simon Glass
  2022-03-16  0:52     ` Fabio Estevam
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Glass @ 2022-03-15 21:15 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: U-Boot Mailing List, Tom Rini, Marek Vasut, Soeren Moch, Pavel Herrmann

Hi Fabio,

On Tue, 15 Mar 2022 at 05:25, Fabio Estevam <festevam@gmail.com> wrote:
>
> Hi Simon,
>
> On Tue, Mar 15, 2022 at 2:54 AM Simon Glass <sjg@chromium.org> wrote:
>
> > +For example, on iMX6::
> > +
> > +   lpuart3: serial@5a090000 {
> > +      compatible = "fsl,imx8qm-lpuart";
>
> I found this part confusing as i.MX6 does not have lpuart.
>
> > +For example, on iMX6, put this in your xxx-u-boot.dtsi file::
> > +
> > +   &pd_dma {
> > +      u-boot,dm-pre-proper;
> > +   };
> > +
> > +   &pd_dma_lpuart3 {
> > +      u-boot,dm-pre-proper;
>
> Same here, these pd_dma and pd_dma_lpuart3 nodes do not exist for i.MX6.

Oh I think I meant iMX8. Would it be OK to just say that in both places?

Regards,
SImon

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

* Re: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
  2022-03-15 21:15   ` Simon Glass
@ 2022-03-16  0:52     ` Fabio Estevam
  2022-03-16  2:56       ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2022-03-16  0:52 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Rini, Marek Vasut, Soeren Moch, Pavel Herrmann

Hi Simon,

On Tue, Mar 15, 2022 at 6:15 PM Simon Glass <sjg@chromium.org> wrote:

> Oh I think I meant iMX8. Would it be OK to just say that in both places?

Was this tested on a real i.MX8QM board?

If not, you could use an example for i.MX7 that I tested on a imx7s-warp:
https://patchwork.ozlabs.org/project/uboot/patch/20220314232406.1945308-1-festevam@gmail.com/

Regards,

Fabio Estevam

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

* Re: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board
  2022-03-16  0:52     ` Fabio Estevam
@ 2022-03-16  2:56       ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2022-03-16  2:56 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: U-Boot Mailing List, Tom Rini, Marek Vasut, Soeren Moch, Pavel Herrmann

Hi Fabio,

On Tue, 15 Mar 2022 at 18:52, Fabio Estevam <festevam@gmail.com> wrote:
>
> Hi Simon,
>
> On Tue, Mar 15, 2022 at 6:15 PM Simon Glass <sjg@chromium.org> wrote:
>
> > Oh I think I meant iMX8. Would it be OK to just say that in both places?
>
> Was this tested on a real i.MX8QM board?

Yes, an iMX8Q board that I have.

>
> If not, you could use an example for i.MX7 that I tested on a imx7s-warp:
> https://patchwork.ozlabs.org/project/uboot/patch/20220314232406.1945308-1-festevam@gmail.com/

Perhaps I could point to that as well? It seems helpful to have more
examples. Perhaps over time we could add info for other SoCs too.

Regards,
Simon

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

end of thread, other threads:[~2022-03-16  2:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15  5:53 [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board Simon Glass
2022-03-15 11:24 ` Fabio Estevam
2022-03-15 13:01   ` Tom Rini
2022-03-15 21:15   ` Simon Glass
2022-03-16  0:52     ` Fabio Estevam
2022-03-16  2:56       ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.