From patchwork Thu Apr 7 12:31:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Valentin Caron X-Patchwork-Id: 12805163 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39DD0C433FE for ; Thu, 7 Apr 2022 12:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=im0prCsc7YSqKc2UhvwnBZFckDubZbJfQiki0wXReB0=; b=KfBNfcsTDoz0dY 3J6c5DjBA/ofwbjG4XfcGWsel5mkziG8U77TKfVr05bEo39ibqaeUEHh1DEPRhDgEtYd+M4DJfA5d pk2kE94ZcEuaxQij6gfaU753CrmKUTkMahcywc6Ec5zFbqyWlng1wCkbABefJzSg0UI86rFsGyWCS xBElrL569V290tNuckiJ/0NZqbTDasRnEy5hspzPTDsl3pkEMeCBQA0KRT5njvuOWjHFqnCAFiEul sdVkR0Gy8vl3NYlzqgRRlndz9uOARHopXKYh7BZV/1BI96GFZbFCfdkMSnF36OU0n9aHiRysBJgHJ /VFqsWahU8VCr3t+ypOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRIt-00BraT-MH; Thu, 07 Apr 2022 12:31:59 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRIo-00BrX7-Vq for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 12:31:56 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 237ApwOU022051; Thu, 7 Apr 2022 14:31:22 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=selector1; bh=OzzsSeRZXTJPRZje9ui1T8+kROrim9zZTezfZrmqwVA=; b=RHV+xEWvG+cC0j9k6+66x8UD+84FpPc/RKoKwBCKJ2RUj/7ACDKSt2eZ2aHU13e6cgFh +xSihihv9nG3l19cDC7LJR7BPwC53f+ILSvmUWE5i3r7x5Ikck3WkZJzZeprXoFcOq3L DdHPalcKI5R1Vqcu4wBI1ILovAIUIiqke4z2pxOta0ihE+3veVw/OPYlu3+DKP1J9NUK E1mgymvNfnmQcqbY/BvcJZbmc0TpWqa4y7YEjTy0hMf6KMuEuLv4AXE3cJpu9ZxiwMh9 nlvh37p2nmwnOvDNSB0cun/LjSdpvgNrzena1G3I8yku7vMvVyK129qHzPkU/VDJBzzg ew== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3f8x9gkwb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 14:31:22 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D74A4100034; Thu, 7 Apr 2022 14:31:21 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id D005621A223; Thu, 7 Apr 2022 14:31:21 +0200 (CEST) Received: from localhost (10.75.127.49) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 7 Apr 2022 14:31:21 +0200 From: Valentin Caron To: Greg Kroah-Hartman , Jonathan Corbet CC: Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , Valentin Caron , , , , , Subject: [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function Date: Thu, 7 Apr 2022 14:31:07 +0200 Message-ID: <20220407123109.132035-2-valentin.caron@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407123109.132035-1-valentin.caron@foss.st.com> References: <20220407123109.132035-1-valentin.caron@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-07_01,2022-04-07_01,2022-02-23_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_053155_353765_EE79DE1A X-CRM114-Status: GOOD ( 18.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rework stm32_usart_console_putchar() function in order to anticipate the case where the character can never be sent. Signed-off-by: Valentin Caron --- drivers/tty/serial/stm32-usart.c | 12 +++++++++--- drivers/tty/serial/stm32-usart.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 87b5cd4c9743..83895da84891 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -1645,10 +1645,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch { struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + u32 isr; + int ret; - while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) - cpu_relax(); - + ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr, + (isr & USART_SR_TXE), 100, + STM32_USART_TIMEOUT_USEC); + if (ret != 0) { + dev_err(port->dev, "Error while sending data in UART TX : %d\n", ret); + return; + } writel_relaxed(ch, port->membase + ofs->tdr); } diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h index feab952aec16..d734c4a5fd24 100644 --- a/drivers/tty/serial/stm32-usart.h +++ b/drivers/tty/serial/stm32-usart.h @@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = { #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */ #define TX_BUF_L RX_BUF_L /* dma tx buffer length */ +#define STM32_USART_TIMEOUT_USEC USEC_PER_SEC /* 1s timeout in µs */ + struct stm32_port { struct uart_port port; struct clk *clk; From patchwork Thu Apr 7 12:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Caron X-Patchwork-Id: 12805161 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E35BEC433EF for ; Thu, 7 Apr 2022 12:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jKxztsnqnKfy1Tlj/st006gIgSzRl73yyACUmCPhYqQ=; b=u8rggrKRmpDdWg T1NSaunvNYlta93yneMq47Cl4LQqi8HJkHV2q/haMzZeMWYogXrtB2iSk+dk6M3BXDcOpC0oDtuKK 1ILmdYYkC5ZKtcf6WelzNtw7HEUhsPsTcaIA7VVJHDSqdegxyTmB55dc0E0EHdv3+r4MHtaeM+OUC OqY9QzE2tX5gcvra0uVGMSDXMHa2ZCr4pUWALGT1V8h49bHOukGZhf0AwIqlfSX6K6QgN6l8YrfCs IQ5pZugUUjxL6+eEXMVR02AmzaZQ8L5ljUOqhj+rV4Ge787BjIT8xKxp75wNpnB9cfXPvLXDkMnFl 1FZxrO44mJMGX312JVdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRIj-00BrYF-N9; Thu, 07 Apr 2022 12:31:49 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRIf-00BrXB-G1 for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 12:31:47 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 237Apxw5009451; Thu, 7 Apr 2022 14:31:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=RkFXAMUowl44G0ueDYkkdPxY3P5C7zGyMGGVecJva2Y=; b=qJPsPhDZNG7ILBg3j48jtq6ErUELDESuHXm8DHNK8PBe/l67FlCniqBVRqsdv4SN28RJ D3rJheR7BVVq0p76whC2zhZ1hK8lvaFDrrp1q0epEIeRAXDNLWqdyh/Ua/Pw7kKQOLDO /Bbw2aMHu1Fm1C4wbvfBqp3R969k50EN9BKcijzI/9NwW+FwbvSK3zV9Gizu//WHmIZ+ Pr/OnX4NEaCCX105iMnOydeqq3iqLl7Iumb/XeY75IxYmu0XAViHW1BiIWZeMr1xJUVx KyMoHVxk+wRmdcpM9YgHR6N6Ew1D69ViTlh9xFHjo1h5q5GhIBxrBoAKgHTNiDPZhX8s 7A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3f8x4rkxq4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 14:31:24 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id AA063100034; Thu, 7 Apr 2022 14:31:23 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A1A8A21A23E; Thu, 7 Apr 2022 14:31:23 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 7 Apr 2022 14:31:23 +0200 From: Valentin Caron To: Greg Kroah-Hartman , Jonathan Corbet CC: Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , Valentin Caron , , , , , Subject: [PATCH 2/3] serial: stm32: add KGDB support Date: Thu, 7 Apr 2022 14:31:08 +0200 Message-ID: <20220407123109.132035-3-valentin.caron@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407123109.132035-1-valentin.caron@foss.st.com> References: <20220407123109.132035-1-valentin.caron@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-07_01,2022-04-07_01,2022-02-23_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_053146_227907_E7977A74 X-CRM114-Status: GOOD ( 18.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for KGDB in stm32 serial driver by implementing characters polling callbacks (poll_init, poll_get_char and poll_put_char). Signed-off-by: Erwan Le Ray Signed-off-by: Jean Philippe Romain Signed-off-by: Valentin Caron --- drivers/tty/serial/stm32-usart.c | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 83895da84891..d2cf789c7997 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -37,6 +37,7 @@ static void stm32_usart_stop_tx(struct uart_port *port); static void stm32_usart_transmit_chars(struct uart_port *port); +static void __maybe_unused stm32_usart_console_putchar(struct uart_port *port, unsigned char ch); static inline struct stm32_port *to_stm32_port(struct uart_port *port) { @@ -1222,6 +1223,34 @@ static void stm32_usart_pm(struct uart_port *port, unsigned int state, } } +#if defined(CONFIG_CONSOLE_POLL) + + /* Callbacks for characters polling in debug context (i.e. KGDB). */ +static int stm32_usart_poll_init(struct uart_port *port) +{ + struct stm32_port *stm32_port = to_stm32_port(port); + + return clk_prepare_enable(stm32_port->clk); +} + +static int stm32_usart_poll_get_char(struct uart_port *port) +{ + struct stm32_port *stm32_port = to_stm32_port(port); + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + unsigned int ret; + + if (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_RXNE)) + return NO_POLL_CHAR; + + return readl_relaxed(port->membase + ofs->rdr) & stm32_port->rdr_mask; +} + +static void stm32_usart_poll_put_char(struct uart_port *port, unsigned char ch) +{ + stm32_usart_console_putchar(port, ch); +} +#endif /* CONFIG_CONSOLE_POLL */ + static const struct uart_ops stm32_uart_ops = { .tx_empty = stm32_usart_tx_empty, .set_mctrl = stm32_usart_set_mctrl, @@ -1243,6 +1272,11 @@ static const struct uart_ops stm32_uart_ops = { .request_port = stm32_usart_request_port, .config_port = stm32_usart_config_port, .verify_port = stm32_usart_verify_port, +#if defined(CONFIG_CONSOLE_POLL) + .poll_init = stm32_usart_poll_init, + .poll_get_char = stm32_usart_poll_get_char, + .poll_put_char = stm32_usart_poll_put_char, +#endif /* CONFIG_CONSOLE_POLL */ }; /* @@ -1640,8 +1674,7 @@ static int stm32_usart_serial_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_SERIAL_STM32_CONSOLE -static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch) +static void __maybe_unused stm32_usart_console_putchar(struct uart_port *port, unsigned char ch) { struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; @@ -1658,6 +1691,7 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch writel_relaxed(ch, port->membase + ofs->tdr); } +#ifdef CONFIG_SERIAL_STM32_CONSOLE static void stm32_usart_console_write(struct console *co, const char *s, unsigned int cnt) { From patchwork Thu Apr 7 12:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Caron X-Patchwork-Id: 12805164 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D596C433F5 for ; Thu, 7 Apr 2022 12:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=01PBCCkpvfJLnip4HUVryEf62l3nZWUeTwVWft1MV6U=; b=31tN/GYCZRieBh +hKZWSYQq56sm1CoN9F1Z0Zg24iqOGGpGutIW22RfS9xfaWZarxlgMbOVfhmbU5+4obti6fDavMDu za5fYW8Vu8k5IlS6SrMcwGao4fwrwcik0f8tLuP2faBQkPHijk2UtRXtZ3Hki4bYHDiKImHNKvKSc kjd7C4yScs8V84G8NADp8QShEXn4//Sc+06rkHqW62eSRUFGE/iBLRluwN+U4dgCw+i5nHE6RVTx6 CFZ+R8iRouM3CQ5qorW95fa9RkPxddXOuCgzgN9A7VB65WAAWH0s18kgItRhFZkW18Z3t1jF2WScb MylC/X1/fZP0gGcbU+Tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRJH-00Brj0-1N; Thu, 07 Apr 2022 12:32:23 +0000 Received: from mx07-00178001.pphosted.com ([185.132.182.106]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncRIr-00BrYS-8D for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 12:32:00 +0000 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 237Aq3N5030696; Thu, 7 Apr 2022 14:31:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=76SYHV/KtKEG+X8D1Pons/IwXN4U2N6uF+AI+Dz58us=; b=5Bx2FHIgAJs3ebrtDjtwx1qrcK+TvTxgsJtwTC2Bm2TNJMBP7odiE3VIgMQChCBLmifw z1P847sk7fz4WLZBEedK9rEqD/GELssipSxQ1hFmZAs7Oig45GrtAThvrOjJ6byXWJOL xV8gjXxIzpPIQBpg6Y1qsP+8/ABs0D1sfZtJm4DKL6ErjaTznrB7L7zQLSfYmd9IDppt chM8h20HIPrnp+5psjWg8ST1C8+8fvgmhNot/+aPA1xK+oPsXaWXfRy+V1nG0T+8AVph cNYSZG3V0BS3zmSkDIa3xZVmfPKab23UBet8Q7y2AK8cillGT/epVnnq+WNzzYU0uWZg Eg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3f6du14vyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Apr 2022 14:31:42 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 583FF100034; Thu, 7 Apr 2022 14:31:26 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 5092821A23C; Thu, 7 Apr 2022 14:31:26 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 7 Apr 2022 14:31:25 +0200 From: Valentin Caron To: Greg Kroah-Hartman , Jonathan Corbet CC: Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , Valentin Caron , , , , , Subject: [PATCH 3/3] serial: stm32: add earlycon support Date: Thu, 7 Apr 2022 14:31:09 +0200 Message-ID: <20220407123109.132035-4-valentin.caron@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407123109.132035-1-valentin.caron@foss.st.com> References: <20220407123109.132035-1-valentin.caron@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-07_01,2022-04-07_01,2022-02-23_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_053157_659054_A7DA166E X-CRM114-Status: GOOD ( 17.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add early console support in stm32 uart driver. Signed-off-by: Alexandre Torgue Signed-off-by: Valentin Caron --- .../admin-guide/kernel-parameters.txt | 6 +++ drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/stm32-usart.c | 51 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 3f1cc5e317ed..e941c3351c7a 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1264,6 +1264,12 @@ address must be provided, and the serial port must already be setup and configured. + stm32, + Use early console provided by ST Microelectronics + serial driver for STM32 SoCs. A valid base address + must be provided, and the serial port must already + be setup and configured. + earlyprintk= [X86,SH,ARM,M68k,S390] earlyprintk=vga earlyprintk=sclp diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 6949e883ffab..ed59de8d2e11 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -1443,6 +1443,7 @@ config SERIAL_STM32_CONSOLE bool "Support for console on STM32" depends on SERIAL_STM32=y select SERIAL_CORE_CONSOLE + select SERIAL_EARLYCON config SERIAL_MVEBU_UART bool "Marvell EBU serial port support" diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index d2cf789c7997..b6852a5a9143 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -1767,6 +1767,57 @@ static struct console stm32_console = { #define STM32_SERIAL_CONSOLE NULL #endif /* CONFIG_SERIAL_STM32_CONSOLE */ +#ifdef CONFIG_SERIAL_EARLYCON +static void early_stm32_usart_console_putchar(struct uart_port *port, unsigned char ch) +{ + struct stm32_usart_info *info = port->private_data; + + while (!(readl_relaxed(port->membase + info->ofs.isr) & USART_SR_TXE)) + cpu_relax(); + + writel_relaxed(ch, port->membase + info->ofs.tdr); +} + +static void early_stm32_serial_write(struct console *console, const char *s, unsigned int count) +{ + struct earlycon_device *device = console->data; + struct uart_port *port = &device->port; + + uart_console_write(port, s, count, early_stm32_usart_console_putchar); +} + +static int __init early_stm32_h7_serial_setup(struct earlycon_device *device, const char *options) +{ + if (!(device->port.membase || device->port.iobase)) + return -ENODEV; + device->port.private_data = &stm32h7_info; + device->con->write = early_stm32_serial_write; + return 0; +} + +static int __init early_stm32_f7_serial_setup(struct earlycon_device *device, const char *options) +{ + if (!(device->port.membase || device->port.iobase)) + return -ENODEV; + device->port.private_data = &stm32f7_info; + device->con->write = early_stm32_serial_write; + return 0; +} + +static int __init early_stm32_f4_serial_setup(struct earlycon_device *device, const char *options) +{ + if (!(device->port.membase || device->port.iobase)) + return -ENODEV; + device->port.private_data = &stm32f4_info; + device->con->write = early_stm32_serial_write; + return 0; +} + +OF_EARLYCON_DECLARE(stm32, "st,stm32h7-uart", early_stm32_h7_serial_setup); +OF_EARLYCON_DECLARE(stm32, "st,stm32f7-uart", early_stm32_f7_serial_setup); +OF_EARLYCON_DECLARE(stm32, "st,stm32-uart", early_stm32_f4_serial_setup); +#endif /* CONFIG_SERIAL_EARLYCON */ + static struct uart_driver stm32_usart_driver = { .driver_name = DRIVER_NAME, .dev_name = STM32_SERIAL_NAME,