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 B35C7C433EF for ; Tue, 15 Mar 2022 05:53:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17F578399B; Tue, 15 Mar 2022 06:53:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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; unprotected) header.d=chromium.org header.i=@chromium.org header.b="USUrQDQm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3557A8398D; Tue, 15 Mar 2022 06:53:51 +0100 (CET) Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B4C0D8399B for ; Tue, 15 Mar 2022 06:53:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-pj1-x1035.google.com with SMTP id b8so16850041pjb.4 for ; Mon, 14 Mar 2022 22:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=K4a11NX6T7TWjJoCj1dst6cI93a00GuZDceBOSVkRfw=; b=USUrQDQmg8trT50fSkt6j7lEFnY1vAl5EmxjUEPU7CMkXEybBzj1OxL3gzAiOapYM6 kKWjuZVvlmuq32Cop6Ni4uTCNPbN1ok4bNbqUl9v7FBN3Qon6sAPi5m/mHRZAeacJ54x ShgI0lXTO2a9fAAdsPxn4gkd+TDbCOH+976CA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=K4a11NX6T7TWjJoCj1dst6cI93a00GuZDceBOSVkRfw=; b=dQFSW0LrgPxPK/G0oYxpSFDRJaYkRUKHyl8rLN0EBhPZTZcK9k+C6g38bpT2iuteD0 5MqaJj5WnF62SuXB8faIf/3MajdX9ZNF/MaYcwf3NEaJSxReITaWVdZN2IeTU7nGwv/x xhk9YO1erLKFCwlwxwsCfgG55DxaR5UcvcGcxkZfoYMunBEWe5WZY/YkFRzlw48FijIm ENMZ80/WZEeIdioIC0vOOPYzkzDNVNsTFIoyQK+9FWKsvIqh1wPNgeOOJnoLur9K9er7 71GN/avmdrFQoL16oy/bW7N3cOoSnFYyLFe5rgH9ShvILHx5upz3KJD7dfgkgoiCvq0i ETaA== X-Gm-Message-State: AOAM531KnMbBcFM8O7+QUwExQF1aZUXt1eHlDGat4uUcrUUduWGRcS8X shyLyw/8MJ+Zqs8WeYdsANrW+a/KY0xDPBKI X-Google-Smtp-Source: ABdhPJzvUxEn04iOuB88ej/0C8FMzullWN4OU/Y6VqH1Tio4C3cFDP2/ydZzhM2iqN9rhyMa8wISfw== X-Received: by 2002:a17:902:e848:b0:151:e3a5:b609 with SMTP id t8-20020a170902e84800b00151e3a5b609mr26373269plg.137.1647323624443; Mon, 14 Mar 2022 22:53:44 -0700 (PDT) Received: from localhost.localdomain (118-93-105-181.dsl.dyn.ihug.co.nz. [118.93.105.181]) by smtp.gmail.com with ESMTPSA id f6-20020a654006000000b00346193b405fsm18227507pgp.44.2022.03.14.22.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 22:53:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Marek Vasut , Soeren Moch , Simon Glass , Pavel Herrmann Subject: [PATCH] dm: Add docs to explain how to enable DM_SERIAL for a board Date: Mon, 14 Mar 2022 23:53:35 -0600 Message-Id: <20220315055335.859537-1-sjg@chromium.org> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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