From patchwork Wed Mar 22 22:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arend van Spriel X-Patchwork-Id: 666080 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2985C6FD1C for ; Wed, 22 Mar 2023 22:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229484AbjCVWkE (ORCPT ); Wed, 22 Mar 2023 18:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjCVWkE (ORCPT ); Wed, 22 Mar 2023 18:40:04 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62EC827D61 for ; Wed, 22 Mar 2023 15:40:03 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id o44so10240985qvo.4 for ; Wed, 22 Mar 2023 15:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1679524802; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=YXOqEKZr2B5o6lVtgaQ8oXcgjjhSK3hFg539VLGwYtU=; b=DJ1OnJnS2nzDaqnUo4hbb41n5bwTV6gXoRF+PN2jOACxAFdthymy5HXYY09g1iJ+jO 0iurDM/jBOhLxfgR/+qTG/93mdx3XIke24ufOMmiGoI6ri4UBl/Qtotpqv+8PFW6SfQd U3qnStam6pf7PH7wH5rR4eUsdClMXSXH1cW+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679524802; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YXOqEKZr2B5o6lVtgaQ8oXcgjjhSK3hFg539VLGwYtU=; b=ijD3rv9mcO9yycuHgdyJ4GjWtqzt+M1bFAu92t8gOUmM5dzF3lbOJtEuE7t9ozlJKu +uvza12Ky0hlDP40LbXL6qTKmBDjK62qvsR+E8S7j3KX1BtOQJZeMkcIGzgs2VZ3qLI8 +952IZ7mfdUE+yyiz9cHkJ7yihNXamY1iZKXprnAuS7LFah6Ih/s23dU/onSVdhp2SqP /n6se7WwXHm+LLRL4kfodi5sLDlLFVQw7XdWVcdhg4UexDx7AMqW4cjR4aA8inVZQdYG TOfPqcgbklWWPY5XZGddjUA5D0rbVUqb0ZNIsj3qZmRSoww1/9MqGRxSZeYfMf8N2i+V hTHw== X-Gm-Message-State: AO0yUKVhSCvf8joOeKAQBIZ/yEDN/0VQUh5Fm7638Oo24Mrleh3HDsPa TzTD8p2XvWdAPmqMf7pnMQkNpmyuPSmAyLmJQTFETK44WHI= X-Google-Smtp-Source: AK7set9+rBUzAvuTOZ9K8oMMcRMDA3IJ/cOUilQQFAPhh8t7H0vP9GxqKtM0kG0OApkU5spDzd2abA== X-Received: by 2002:a05:6214:240c:b0:5a7:a434:c303 with SMTP id fv12-20020a056214240c00b005a7a434c303mr9080765qvb.25.1679524802525; Wed, 22 Mar 2023 15:40:02 -0700 (PDT) Received: from bld-bun-02.bun.broadcom.com ([192.19.148.250]) by smtp.gmail.com with ESMTPSA id x128-20020a376386000000b00746803d7e8dsm7563903qkb.113.2023.03.22.15.40.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2023 15:40:02 -0700 (PDT) From: Arend van Spriel To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Arend van Spriel Subject: [PATCH] serial: bcm63xx-uart: add polling support Date: Wed, 22 Mar 2023 23:39:56 +0100 Message-Id: <20230322223956.84647-1-arend.vanspriel@broadcom.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The tty framework can support polling console to allow operation in situations where interrupts are turned off. Adding polling mode support allows using KGDB over serial console, Signed-off-by: Arend van Spriel --- drivers/tty/serial/bcm63xx_uart.c | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c index 62bc7244dc67..55e82d0bf92d 100644 --- a/drivers/tty/serial/bcm63xx_uart.c +++ b/drivers/tty/serial/bcm63xx_uart.c @@ -596,6 +596,40 @@ static int bcm_uart_verify_port(struct uart_port *port, return 0; } +#ifdef CONFIG_CONSOLE_POLL +/* + * return true when outstanding tx equals fifo size + */ +static bool bcm_uart_tx_full(struct uart_port *port) +{ + unsigned int val; + + val = bcm_uart_readl(port, UART_MCTL_REG); + val = (val & UART_MCTL_TXFIFOFILL_MASK) >> UART_MCTL_TXFIFOFILL_SHIFT; + return !(port->fifosize - val); +} + +static int bcm_uart_poll_get_char(struct uart_port *port) +{ + unsigned int iestat; + + iestat = bcm_uart_readl(port, UART_IR_REG); + if (!(iestat & UART_IR_STAT(UART_IR_RXNOTEMPTY))) + return NO_POLL_CHAR; + + return bcm_uart_readl(port, UART_FIFO_REG); +} + +static void bcm_uart_poll_put_char(struct uart_port *port, unsigned char c) +{ + while (bcm_uart_tx_full(port)) { + cpu_relax(); + } + + bcm_uart_writel(port, c, UART_FIFO_REG); +} +#endif + /* serial core callbacks */ static const struct uart_ops bcm_uart_ops = { .tx_empty = bcm_uart_tx_empty, @@ -614,6 +648,10 @@ static const struct uart_ops bcm_uart_ops = { .request_port = bcm_uart_request_port, .config_port = bcm_uart_config_port, .verify_port = bcm_uart_verify_port, +#ifdef CONFIG_CONSOLE_POLL + .poll_get_char = bcm_uart_poll_get_char, + .poll_put_char = bcm_uart_poll_put_char, +#endif };