Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DA62C433F5 for ; Tue, 22 Mar 2022 21:34:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DDB2983BA1; Tue, 22 Mar 2022 22:34:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="cq31WGhU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4AB5283BA1; Tue, 22 Mar 2022 22:34:22 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A9EC83BA3 for ; Tue, 22 Mar 2022 22:34:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1647984855; bh=o3EH6xCAQ9v6aHNvZVZtfW+V3MOKjP3Ajij7HEFrE8g=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=cq31WGhUTXs1keh04y3Ziq7I635788PqgNyilxOi0qcIU277BVDLx3BxmZNVQdHhF tB8gPOSkBR5bYpG3Ej+KLln3oDuakNMd5Bb1D3RzzWoq52Ytl9nJGFUtXj4MAMcobg RviyaUnPP/SijwVRHfOIc3Rb3k44vAD9i54gkSRQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([88.152.144.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MC30Z-1nNCR81vYL-00CNqh; Tue, 22 Mar 2022 22:34:15 +0100 Message-ID: <711e86df-36e4-79e4-c4de-60017e839df1@gmx.de> Date: Tue, 22 Mar 2022 22:34:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v2] dm: Add docs to explain how to enable DM_SERIAL for a board Content-Language: en-US To: Simon Glass Cc: Tom Rini , Fabio Estevam , Marek Vasut , Soeren Moch , Pavel Herrmann , U-Boot Mailing List References: <20220316030321.1008573-1-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20220316030321.1008573-1-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:6bQ33Bl4o+ykx/7gT36WOTk5f7rzYKRFOku0ZeQjUTy/6bYjzsw eSWa/G5dGIHRmOP7qqHkRDONFW3rv2W4421BBAB5JqVTK2trVq0NuEBiG+3oUQ/oQMvJZ9W u5m6YjrYLsY6JFwYpBwfpW6zFGm8KYtL0qXZFsi4Mv7d8zum/KHIVQ7pJIC1QMbJw9wDRhe m+RPFKXwMlgwoILMwk/xw== X-UI-Out-Filterresults: notjunk:1;V03:K0:zK2DB4Os1Vc=:RqBbOA5lruS1kussljUMjW MhlN+RZIVZ+oDGNHuZjAqdqLmOeSPR9llRS0DenFDhB2LWsxhxHjMD9U7/7DQ597ypttF3Zvd WCVXjZLi88dj1z75XjMOrDHqLoFoeDiMwscL8MHe6yqGh74tOpfLSoLKFgydQu1xF9bnWLrwP bOe1Xrw9ktkW3lnF+t97VQx0OjgENh3aWN/t/aBbxDYT8p8ryPQHAhYbdqUI2Vw0526kjUrXk Qzf1XWqWAuCbAnvQpqof7h4HW+C5xGQLa77I4qGVH4fKVNVXKjatwfh86QeAMuKxS1zPKzurR Pd/nMOnYZ+T+KwiLLouWXMIOYvBDbQFMRKZyWUbYcNzmkjz0BouJDLuOEKHk9JqRfBWsZ02tG +HBdNwJxT/ykNfNzQ1hWoEEVCVeS/bcGzXdX51nUgLSw+xOFTTC7VsgMTDq3g0+CAn+mJ38HJ kHyjqbjSlazDS+KBdh1g95hv+hVxYJHDUpPz5lLYR2Mxsuh5CNzr1IvvJQ1ELRMjckl9vRbP0 jS8UxEOPRKen3AupIb+9KksYiSiqfZ+a8WI+LdtrmfQ/72uyr9IfxmuAC0FQm0XsseWlg1oBB rZvJmmxiHJTnQbpopiJuc6Vy0HEpLQwkBvkt/dj1H2RaYZsLOBzcj/LCEYDOx+EFbGfwqFhhz 3Gky4esLk5BleeX8W9vWDz1XKi7SOSNcGpN6GcguSmu81j/wlEHhmxy3Vl9SCyO+oHpkoKBoL hx1BJ1f5NqzGV2OEI7Db42yec5EuiPUTMlHpgTcC93lHmCYwGOoy87ItBZzSz20iCtxrGShma Dllmnf/dUYDBMsXIJXrhBc0iX45lvVAtu2nfaeXb/0sxo5KXD9GEpcdaOhGgWr1iZm0ikIahN IMXlqpRfIWBen5XyBd2Ss4iLZaTytbMFqlP+b+SvFgIHxQEanRcw86+G+PCGWRuC1lgn3aq4R UAXRJDg5yqOAhl6wmoCUOBbvfH/oLUX3I425htzB31FQx4Iw/ytYVv8hH6TEIxS8tGpFqlnkQ OxDBalyGmY6qosg6YnL8ZeV1Oz00AzW7jTPBZTHhCE5zJH64a9GPn8PaPHK6TbhKZwx/vY748 +BMOwtojCWGrtg= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On 3/16/22 04:03, Simon Glass wrote: > 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 > --- > > Changes in v2: > - Add an example patch > - Mention removing old code that is not used > > doc/develop/driver-model/serial-howto.rst | 152 ++++++++++++++++++++++ > 1 file changed, 152 insertions(+) > > diff --git a/doc/develop/driver-model/serial-howto.rst b/doc/develop/dri= ver-model/serial-howto.rst > index 1469131124b..e595049c0a3 100644 > --- a/doc/develop/driver-model/serial-howto.rst > +++ b/doc/develop/driver-model/serial-howto.rst > @@ -44,3 +44,155 @@ 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_DRIV= ER() in %s/uses/uses the/ > +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 debugg= ing 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 i= nterfere > +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 correc= t 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 cl= ues as to > +what is needed. > + > +Thirdly, when added tags, put them in a xxx-u-boot.dtsi file, where xxx= is your %s/added/adding/ ? What is a tag meant to be here? Tags do not exist in the driver model up to now. This really needs a link to a chapter describing what a tag is. > +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:`dtt= weaks`. > + > +Here are some things you might need to consider: > + > +1. The serial driver itself needs to be present before relocation, so t= hat the Is this meant to be the first item of an numbered list? If so, please fix the indentation. Please, check the output of 'make htmldocs' for correct formatting. Best regards Heinrich > +U-Boot banner appears. Make sure it has a u-boot,pre-reloc tag in the d= evice > +tree, so that the serial driver is bound when U-Boot starts. > + > +For example, on iMX8:: > + > + lpuart3: serial@5a090000 { > + compatible =3D "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 =3D <&uart2_xfer>; > + }; > + > +which is defined as follows:: > + > + pinctrl: pinctrl { > + compatible =3D "rockchip,rk3228-pinctrl"; > + > + uart2: uart2 { > + uart2_xfer: uart2-xfer { > + rockchip,pins =3D <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 i= ts > +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 powe= r domain > +must be enabled for the serial port to work, you need to ensure it is a= vailable > +before relocation: > + > +For example, on iMX8, 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 you= r 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 t= o the > +debug UART until the point where the real serial driver takes over. Thi= s point > +is marked by gd->flags having the GD_FLG_SERIAL_READY flag set. This ch= ange > +happens in serial_init() in serial-uclass.c so until that point the deb= ug 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_REA= DY)) { > + 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 nee= ded. > + > +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 optimisa= tion, or > +may take a long time to start up (e.g. hundreds of milliseconds). The t= ags tell > +U-Boot which drivers to bind. > + > +The good news is that this problem is normally solved by the SoC, so th= at any > +boards that use it will work as normal. But in some cases there are mul= tiple > +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 ens= ure that > +the SPL device tree contains the required nodes (see spl/u-boot-spl.dtb= for > +what it actually contains). > + > +Removing old code > +----------------- > + > +In some cases there may be initialisation code that is no-longer needed= when > +driver model is used, such as setting up the pin muxing, or enabling a = clock. > +Be sure to remove this. > + > +Example patch > +------------- > + > +See this serial_patch_ for iMX7. > + > +.. _serial_patch: https://patchwork.ozlabs.org/project/uboot/patch/2022= 0314232406.1945308-1-festevam@gmail.com/