From patchwork Tue Mar 14 08:46:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Abbarapu, Venkatesh" X-Patchwork-Id: 1756885 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=x3fSXPI2; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PbYyS3MF0z1yWr for ; Wed, 15 Mar 2023 00:19:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9ECAA854C8; Tue, 14 Mar 2023 14:18:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com 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=amd.com header.i=@amd.com header.b="x3fSXPI2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3D29585B3F; Tue, 14 Mar 2023 09:46:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::60a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 109F685813 for ; Tue, 14 Mar 2023 09:46:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=venkatesh.abbarapu@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GiTkouEJgygq4zUXw/r2RVyi1S0/bwGJgu42Ero77VYbsQ5d0G4BxtxZKvLyM/yegI6npIaOv9iVeEvJ1Kfh+pV479G35Bc01jL97/2CH4FOjcifD2kIGFj1O7X8q5grocxbJO99bjxE3qFq7koOdyyUJg/fswsy5Uq4KjB0MYNnycdgmut/3TICwCdzzgXmaZwsq7w1vFCk6qgIBPgmaqGSqyqvT9I8bq3teI9h6aI889jKyYh0p8Se3e5bgGvNJKd9fzHYFi3WbB+tBJL2/e3lnDIRZmNi6YLu7w/UeMbe1SfTwmWTxoXs909xUMUR8xtMid3yJHt/6omhsZovzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Rc6vms3deonCBP+DGQa/Qtch4dPwfL3NpdIgrRjlqRM=; b=ekPHITzhuiMUs0jFSS4GGRIqzl5nm4YV2/71HYsdIRNdHUgCxnsmFAqX+O9UqzyWjW3KD9WGJNlBdas8Jk4zas2MvR34XA2jXdDniLdbrDWYWFlmFkHEyk23kTZzjuP5zs4mf9e1uOvCUdTwYheMxjLUXNAb13kW8QlKKVW3AZTWHe5hs0++kk7SGIwF+IT0cAPxO6eHyBHOoU93F2RGgAc2baoNdZtFgf2GzlyUKSEu710IzbLaI2eN0kJ2QKd/lEAYwBmZBJU3LoK0eh+Gysrj+0Dcz+Skn5ZKz3CuylQE8wYh5Rkra8VvBpwDeNTswjFhSA6+Lq69Y8Nz41CUOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.denx.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rc6vms3deonCBP+DGQa/Qtch4dPwfL3NpdIgrRjlqRM=; b=x3fSXPI2l0zSpxZRk+G6P1g//EU7sGNyeivhsin7MHWGtCUM28pNVuQs6bVe22d41PwVzy53UOwTBqW2HkAzBhSPaAjbp2kTLXf3aVczQoe8aC6bwtaLFgYMzUPCaa7SMdWcbrSKHc3YNHUvZD7/cMXwbcZN0O6a9OL0a1XfW2U= Received: from CY5PR15CA0144.namprd15.prod.outlook.com (2603:10b6:930:67::11) by CY8PR12MB7292.namprd12.prod.outlook.com (2603:10b6:930:53::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Tue, 14 Mar 2023 08:46:37 +0000 Received: from CY4PEPF0000C968.namprd02.prod.outlook.com (2603:10b6:930:67:cafe::c) by CY5PR15CA0144.outlook.office365.com (2603:10b6:930:67::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26 via Frontend Transport; Tue, 14 Mar 2023 08:46:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000C968.mail.protection.outlook.com (10.167.241.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.12 via Frontend Transport; Tue, 14 Mar 2023 08:46:36 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 14 Mar 2023 03:46:36 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 14 Mar 2023 01:46:35 -0700 Received: from xhdvabbarap40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 14 Mar 2023 03:46:34 -0500 From: Venkatesh Yadav Abbarapu To: CC: , , , "Algapally Santosh Sagar" Subject: [PATCH] serial: zynqmp: Fetch baudrate from dtb and update Date: Tue, 14 Mar 2023 14:16:27 +0530 Message-ID: <20230314084627.26358-1-venkatesh.abbarapu@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C968:EE_|CY8PR12MB7292:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bfce7b0-b8f0-47c4-f9e1-08db24689f1a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RJXFWXgOW4SKNNmoAi95umIBuS22s/atW5eZ8sWyN9DlQT5ya0bRWma1C4UZbxgHvLVaJA+vz42Evh4yTw4/4QPealKXh2UKXtVSGDbwZpT2In9MZeoCuFnJNNff46Ai7cSEf0ZBOOEqeIJwm7mInzRKliJg/T2z/zODv4FpB/QPTUN/pg1uvWn8eKnQ4/E9wU/f04cCtqyRvE0OUaiH3glpICefrsXkVrvCqNBKeVg7xFyebjOfAhAR6ousoPc/KhNmymh0H6xP4OjjvE2J52v3p4MsrJgXeP6vEYMYlQsP/nh3tvX2nWUW83XQ7pkvX8nGlG0e6CQEZuQzoHr++YVK9Y9qZluLzIVEtjzd3Cjn7YpWN+Zb5xq3l10qvBdSf+g55U6Tu57O+Zxt2QGmdd62aDewK35A+4Iupi8WAn1dMY21S1LHzcp83e2GUa39qkVd8tqzBAJPZEa+3ZVSaPAGr6rAiLkiWBX1pxFJ0qo6vjMh+2WE7vyLhinv1WO1bWyLXNFmW5Tk46tiXYTeccZtFDr10aO8SnkEhDvHv3WjIFYLNyeLVjZDZHYaO7EW2cUQjnCXszaOm8WWe+XIQnuJhGEf002l7ltmyb6PpBUBV7KaLQ2HFXf5o7mqLn7Fc3I576xsQKLuZioRs/yQ0tlF7IUrWcetacvVjbiXo6s6Hf2PMzx8RJJsFK88GJ/kv8honyADv0dEdOxDmYZSjwfhNOTf5Yhbi702npa986E= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199018)(46966006)(40470700004)(36840700001)(8936002)(36756003)(478600001)(54906003)(316002)(70586007)(70206006)(8676002)(4326008)(15650500001)(41300700001)(6916009)(2906002)(5660300002)(86362001)(356005)(40460700003)(336012)(26005)(82740400003)(81166007)(40480700001)(1076003)(6666004)(186003)(47076005)(426003)(2616005)(82310400005)(83380400001)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2023 08:46:36.6663 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bfce7b0-b8f0-47c4-f9e1-08db24689f1a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000C968.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7292 X-Mailman-Approved-At: Tue, 14 Mar 2023 14:18:51 +0100 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.8 at phobos.denx.de X-Virus-Status: Clean From: Algapally Santosh Sagar The baudrate configured in .config is taken by default by serial. If change of baudrate is required then the .config needs to changed and u-boot recompilation is required or the u-boot environment needs to be updated. To avoid this, support is added to fetch the baudrate directly from the device tree file and update. The serial, prints the log with the configured baudrate in the dtb. The commit c4df0f6f315c ("arm: mvebu: Espressobin: Set default value for $fdtfile env variable") is taken as reference for changing the default environment variable. The default environment stores the default baudrate value, When default baudrate and dtb baudrate are not same glitches are seen on the serial. So, the environment also needs to be updated with the dtb baudrate to avoid the glitches on the serial. Signed-off-by: Algapally Santosh Sagar Signed-off-by: Venkatesh Yadav Abbarapu --- drivers/serial/Kconfig | 8 +++++++ drivers/serial/serial-uclass.c | 32 ++++++++++++++++++++++++++ include/configs/xilinx_zynqmp.h | 10 ++++++++- include/fdtdec.h | 8 +++++++ include/serial.h | 1 + lib/fdtdec.c | 40 +++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index bb5083201b..0a1bcd63d5 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -24,6 +24,14 @@ config BAUDRATE in the SPL stage (most drivers) or for choosing a default baudrate in the absence of an environment setting (serial_mxc.c). +config SERIAL_DT_BAUD + bool "Fetch serial baudrate from device tree" + depends on DM_SERIAL + help + Select this to enable fetching and setting of the baudrate + configured in the DT. Replace the default baudrate with the DT + baudrate and also set it to the environment. + config REQUIRE_SERIAL_CONSOLE bool "Require a serial port for console" # Running without a serial console is not supported by the diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 77d3f37372..e41cccfdc2 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -158,12 +158,44 @@ static void serial_find_console_or_panic(void) } #endif /* CONFIG_SERIAL_PRESENT */ +#if CONFIG_IS_ENABLED(SERIAL_DT_BAUD) +int serial_get_valid_baudrate(int baud) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { + if (baud == baudrate_table[i]) + return 0; + } + + return -EINVAL; +} +#endif + /* Called prior to relocation */ int serial_init(void) { #if CONFIG_IS_ENABLED(SERIAL_PRESENT) serial_find_console_or_panic(); gd->flags |= GD_FLG_SERIAL_READY; +#if CONFIG_IS_ENABLED(SERIAL_DT_BAUD) + int ret = 0; + char *ptr = &default_environment[0]; + + /* + * Fetch the baudrate from the dtb and update the value in the + * default environment. + */ + ret = fdtdec_get_baud_from_dtb(gd->fdt_blob); + if (ret != -EINVAL && ret != -EFAULT) { + gd->baudrate = ret; + + while (*ptr != '\0' && *(ptr + 1) != '\0') + ptr++; + ptr += 2; + sprintf(ptr, "baudrate=%d", gd->baudrate); + } +#endif serial_setbrg(); #endif diff --git a/include/configs/xilinx_zynqmp.h b/include/configs/xilinx_zynqmp.h index 011f0034c5..79d0a2a214 100644 --- a/include/configs/xilinx_zynqmp.h +++ b/include/configs/xilinx_zynqmp.h @@ -15,6 +15,13 @@ #define GICC_BASE 0xF9020000 /* Serial setup */ +#if CONFIG_IS_ENABLED(SERIAL_DT_BAUD) +#define DEFAULT_ENV_IS_RW +#define ENV_RW_FILLER "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +#else +#define ENV_RW_FILLER +#endif + #define CFG_SYS_BAUDRATE_TABLE \ { 4800, 9600, 19200, 38400, 57600, 115200 } @@ -176,7 +183,8 @@ #ifndef CFG_EXTRA_ENV_SETTINGS #define CFG_EXTRA_ENV_SETTINGS \ ENV_MEM_LAYOUT_SETTINGS \ - BOOTENV + BOOTENV \ + ENV_RW_FILLER #endif /* SPL can't handle all huge variables - define just DFU */ diff --git a/include/fdtdec.h b/include/fdtdec.h index aa61a0fca1..48937a7a46 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -657,6 +657,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int node, */ int fdtdec_get_alias_highest_id(const void *blob, const char *base); +/** + * Get baudrate from the dtb + * + * @param blob Device tree blob (if NULL, then error is returned) + * @return Baud rate value, or -ve error . + */ +int fdtdec_get_baud_from_dtb(const void *blob); + /** * Get a property from the /chosen node * diff --git a/include/serial.h b/include/serial.h index 42bdf3759c..48834b517c 100644 --- a/include/serial.h +++ b/include/serial.h @@ -337,6 +337,7 @@ int serial_setconfig(struct udevice *dev, uint config); */ int serial_getinfo(struct udevice *dev, struct serial_device_info *info); +int serial_get_valid_baudrate(int baud); void atmel_serial_initialize(void); void mcf_serial_initialize(void); void mpc85xx_serial_initialize(void); diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 0827e16859..fa24659b32 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -570,6 +570,46 @@ int fdtdec_get_alias_highest_id(const void *blob, const char *base) return max; } +#if CONFIG_IS_ENABLED(SERIAL_DT_BAUD) +int fdtdec_get_baud_from_dtb(const void *blob) +{ + const char *str, *p, *baud_start; + u32 baud; + + if (!blob) + return -EFAULT; + + str = fdtdec_get_chosen_prop(blob, "stdout-path"); + if (!str) + return -EINVAL; + + p = strchr(str, ':'); + if (!p) + return -EINVAL; + + baud = 0; + baud_start = p + 1; + while (*baud_start != '\0') { + /* + * Uart binding is {{{...}}} + * So the baudrate either is the whole string, or + * ends in the parity characters. + */ + if (*baud_start == 'n' || *baud_start == 'o' || + *baud_start == 'e') + break; + + baud = baud * 10 + (*baud_start - '0'); + baud_start++; + } + + if (serial_get_valid_baudrate(baud) == -EINVAL) + return -EINVAL; + + return baud; +} +#endif + const char *fdtdec_get_chosen_prop(const void *blob, const char *name) { int chosen_node;