Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp16689pxh; Thu, 7 Apr 2022 12:34:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDzOw5ppNoo1OgEqQcD/rfOGfUSbizIyvNUg0EYsID5rvErqpT2sWGVna3s+HdcqLFpgKb X-Received: by 2002:a17:90b:3b4c:b0:1c6:d91f:fbf5 with SMTP id ot12-20020a17090b3b4c00b001c6d91ffbf5mr17519126pjb.81.1649360068228; Thu, 07 Apr 2022 12:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649360068; cv=none; d=google.com; s=arc-20160816; b=tw1k1gR3YW4Lqfdnlk2qwmkutz8QUq+J9BLGg9ofKbPHvypuyv4aPvgcNuAaJZk0MV WsjQhOIr4dSBivcyGBBvuIqlnFb53TNXLZ2JtkNx22VM9iOlTlIIK2ooChIDxiBqe3ZF md+Mt+NbU7CCY8FhHqMJe/SawZwjo8M7BCENcA0lB/8g1X2eoC2r0CKwZQOFrwT7+SK9 zUudPEN/T4lAzEL2MU7TsUL+Se7mUBRYQMYs1TCX9oyOlebiEezmdRLvLgAJ5hF+hV42 orJPcwLQGfBCN0tMurahKeu3b1tH5L9HnDK4gbf5gsPNbGCv5cJG3X1En6uoAFgq2M8Z F7fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RkFXAMUowl44G0ueDYkkdPxY3P5C7zGyMGGVecJva2Y=; b=tKb6y+uu/BsCORjFGbIctKf0hallf4fI/Vgw8AuEUGT/wznldH8+/RTSUHforMJf9U qz1oLjQZd1TexNN5g/l3QUuyRCLVil8myVbtY7bNqiWfUB/UJMQZpPocS4fAGmuCrhWO 293VyeAv3/9IiOsZAWPELWb7IEloLR/epvcOr1hay5zD2SH/keoHZVX9/VizYaQQFgpC P1D9z4QWhVtzBzX7z36Twgt0zv2og/s/+/axRszz0QFX6WU9L7uT0eJesqFm2vbJkuS+ mgYz4DEjZlAHfiHYPeyIGxlwPAM3j5Z35hwLtNgJ6HoxLldlq7wadoMIUsStZBxluT8b yr9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=qJPsPhDZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t123-20020a632d81000000b003816043eef5si19676475pgt.234.2022.04.07.12.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 12:34:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=qJPsPhDZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F5D6234051; Thu, 7 Apr 2022 12:11:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245143AbiDGMd4 (ORCPT + 99 others); Thu, 7 Apr 2022 08:33:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242882AbiDGMdw (ORCPT ); Thu, 7 Apr 2022 08:33:52 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84A27111DD9; Thu, 7 Apr 2022 05:31:52 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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) { -- 2.25.1