Message ID | 20230920022644.2712651-1-jcmvbkbc@gmail.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3848488vqi; Tue, 19 Sep 2023 20:31:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMKOr6zNz6Vag1HLbJD3fwooEhumQpqVQLzV0bsaaqIlDp1eZ7LlzThdQgVFj2zPClWxiF X-Received: by 2002:a17:902:d503:b0:1c0:b8fd:9c7 with SMTP id b3-20020a170902d50300b001c0b8fd09c7mr1468486plg.43.1695180716353; Tue, 19 Sep 2023 20:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695180716; cv=none; d=google.com; s=arc-20160816; b=MkqOv8cwYUot/cYblTCl1XYgm9OvIbyWsCTWyt+ek2tqUeo2UkhLnokyxd4OzvBcJw pSZ4w+YbS1Um6lvXrprhDadMsUcY5TC2ZqcYRB2z0vd8AZShWUO8BZfhdRjB8pjTFJHu lN8C6JlGAjLpiHIjp/AG28GUrl5HtXRWajufkoUEZ2N69QaDKzGMguZSp/CCX9rR8Gqe Od0du8sjSRqiJHE/MFizzyzG/Q1KDhjrLLzf5GA/qWq3MBp/TuDzvEpPx74dWoFWcCVn hBU87apMz4r7ESuyi6/rsCcEgcGMCnQjz0BNC6xlMta0Vd95M2Gne2KozLxYfsa7nG25 xkpQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=4TeNOz0+PeBM7BS0zrNE2nATuP8C0d/z2oGULXDhCZQ=; fh=oqMYt5FzSjXDp/dSMFfnsNSIER/pF2eV0abPard7Ac0=; b=djDVwA3oP+EH6zuC01RsYTNmcZYPbg4VB6mRIwf40SN9XrLYEmjS/iw3gwBWe8hURu TKX/H2ZmudYlU4geKfKuyqt+ijqTqw91fYttAUymC8iXLGL9LMc1YX3W0+aAKHxIm0Sh EqoXF5OVeBuWbPS8XprblG1AV6XRdPoDYPFDs/RWMoITK1RSmMprgMSxoMOV3s7vkXQ2 OaXvSTGRtgeC9J9nXJnXuqgXhCwNVlwpW3mnLsAEeq46GJowzGTTKWaScgvFxX5NX8wy HFxyK6kJdmiOUnxmCQJzFH+r/obQ9I8ZHPFKrwNxxBekLkEM4J7RNSL8Owjsrt6x10EO 5jdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BqFKLBpv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c5-20020a170903234500b001bf223b6595si7904645plh.484.2023.09.19.20.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 20:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BqFKLBpv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D9EC480CBDCB; Tue, 19 Sep 2023 19:27:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbjITC1G (ORCPT <rfc822;toshivichauhan@gmail.com> + 26 others); Tue, 19 Sep 2023 22:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjITC1F (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 19 Sep 2023 22:27:05 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA866C5; Tue, 19 Sep 2023 19:26:59 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-690ce3c55f1so865133b3a.0; Tue, 19 Sep 2023 19:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695176819; x=1695781619; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4TeNOz0+PeBM7BS0zrNE2nATuP8C0d/z2oGULXDhCZQ=; b=BqFKLBpvLiycvX+dyOV+UzlLac0xVAzO8/Hqt9ICNk16lziniDUXae6X6Hn0oASf3W +bbwFhAsDbwiOYeigDKKFiRWXBEEnOHYEqd2m+ifyEBVJqY1CQ7sfKdSfFQW2WtKtaZv acn+VpfNZYXoAOfv27S7q4Ym6XwWxOOs62ZkWZdG2NI/6fyXB1PXUYBP9pkJ6HWjhejZ tszmsHWbKDD/UMLsjhDVyBIRcgJejI33VwPJbrOLjvhZXR+ojeM5gDzXKiY59+lTgLro Fj4U7MKYx5CIq6XJmRuIyDHcyj2OPIHGUIBZAx1ONgoHjm7YAWP+VL7KSypeRpeh3Q2L V/hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695176819; x=1695781619; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4TeNOz0+PeBM7BS0zrNE2nATuP8C0d/z2oGULXDhCZQ=; b=oB5C6hz36XXf2RgO5jTDcY/M/UsUKGSXxNrB4GyZ0iWt/ew6OaqJqXkGzWX8x9bZDk 1uA3rBp6VrwEZDOgjBI1K0ViZqCuOVyNgywxTokoi4TtJp40s+wb7OjCaFNQ5+Q2Jzrz PFTeA7ZJSTGowG4b7K4yW7eZjbBbeA8DYHecsCI1quXdL7iAnOHNzpgQrsBfTRqq9gtZ YrUWkejwdA/uczrVvqqYCro3+SHMLlDpTVZgt9J+bpIGDpubnQNo2OrZe/qonFX4pKlE 8BN3VpJJj5pgwhlPwlo5hGTIRL1UlSb5lVk+co9AmM36aYyuK+/5PX/6Dd8gHAaUULEM Al9w== X-Gm-Message-State: AOJu0YxeEEv6FGkr2IIszyVyy+UOtQgW90HgguuqlrqXcYtIDQNU7sDU P2xCTkCGsS7mu46pXzZ3O1ioyq5OyUg= X-Received: by 2002:a05:6a00:21cc:b0:68b:bf33:2957 with SMTP id t12-20020a056a0021cc00b0068bbf332957mr1583146pfj.22.1695176818903; Tue, 19 Sep 2023 19:26:58 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net ([2601:646:a201:19d0:9ca3:318f:421e:68cb]) by smtp.gmail.com with ESMTPSA id p15-20020a62ab0f000000b0067aea93af40sm9224757pff.2.2023.09.19.19.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 19:26:57 -0700 (PDT) From: Max Filippov <jcmvbkbc@gmail.com> To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, devicetree@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com>, Max Filippov <jcmvbkbc@gmail.com> Subject: [PATCH v2 0/5] serial: add drivers for the ESP32xx serial devices Date: Tue, 19 Sep 2023 19:26:39 -0700 Message-Id: <20230920022644.2712651-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 19:27:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777525814601136997 X-GMAIL-MSGID: 1777525814601136997 |
Series |
serial: add drivers for the ESP32xx serial devices
|
|
Message
Max Filippov
Sept. 20, 2023, 2:26 a.m. UTC
Hello, this series adds drivers for the UART and ACM controllers found in the Espressif ESP32 and ESP32S3 SoCs. Changes v1->v2: - address review comments, listed in each patch - add cleanup for the uart_get_baud_rate function Max Filippov (5): serial: core: tidy invalid baudrate handling in uart_get_baud_rate dt-bindings: serial: document esp32-uart drivers/tty/serial: add driver for the ESP32 UART dt-bindings: serial: document esp32s3-acm drivers/tty/serial: add ESP32S3 ACM device driver .../bindings/serial/esp,esp32-acm.yaml | 39 + .../bindings/serial/esp,esp32-uart.yaml | 48 ++ drivers/tty/serial/Kconfig | 27 + drivers/tty/serial/Makefile | 2 + drivers/tty/serial/esp32_acm.c | 458 +++++++++++ drivers/tty/serial/esp32_uart.c | 749 ++++++++++++++++++ drivers/tty/serial/serial_core.c | 5 +- include/uapi/linux/serial_core.h | 6 + 8 files changed, 1331 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/serial/esp,esp32-acm.yaml create mode 100644 Documentation/devicetree/bindings/serial/esp,esp32-uart.yaml create mode 100644 drivers/tty/serial/esp32_acm.c create mode 100644 drivers/tty/serial/esp32_uart.c
Comments
On 20. 09. 23, 4:26, Max Filippov wrote: > Add driver for the UART controllers of the Espressif ESP32 and ESP32S3 > SoCs. Hardware specification is available at the following URLs: ... > +static void esp32_uart_rxint(struct uart_port *port) > +{ > + struct tty_port *tty_port = &port->state->port; > + u32 rx_fifo_cnt = esp32_uart_rx_fifo_cnt(port); > + unsigned long flags; > + u32 i; > + > + if (!rx_fifo_cnt) > + return; > + > + spin_lock_irqsave(&port->lock, flags); > + > + for (i = 0; i < rx_fifo_cnt; ++i) { > + u32 rx = esp32_uart_read(port, UART_FIFO_REG); > + u32 brk = 0; > + > + ++port->icount.rx; Should yuou increment this only in case of insert_flip_char()? > + if (!rx) { > + brk = esp32_uart_read(port, UART_INT_ST_REG) & > + UART_BRK_DET_INT; > + } > + if (brk) { > + esp32_uart_write(port, UART_INT_CLR_REG, brk); > + ++port->icount.brk; > + uart_handle_break(port); > + } else { > + if (uart_handle_sysrq_char(port, (unsigned char)rx)) > + continue; > + tty_insert_flip_char(tty_port, rx, TTY_NORMAL); > + } This is heavy. Is it equivalent to: if (!rx && esp32_uart_read(port, UART_INT_ST_REG) & UART_BRK_DET_INT) { esp32_uart_write(port, UART_INT_CLR_REG, brk); ++port->icount.brk; uart_handle_break(port); continue; } if (uart_handle_sysrq_char(port, (unsigned char)rx)) continue; tty_insert_flip_char(tty_port, rx, TTY_NORMAL); ? > + } > + spin_unlock_irqrestore(&port->lock, flags); > + > + tty_flip_buffer_push(tty_port); > +} ... > +static void esp32_uart_put_char_sync(struct uart_port *port, u8 c) > +{ > + unsigned long timeout; > + > + timeout = jiffies + msecs_to_jiffies(1000); I.e. plus HZ? > + while (esp32_uart_tx_fifo_cnt(port) >= ESP32_UART_TX_FIFO_SIZE) { > + if (time_after(jiffies, timeout)) { > + dev_warn(port->dev, "timeout waiting for TX FIFO\n"); > + return; > + } > + cpu_relax(); > + } > + esp32_uart_put_char(port, c); > +} > + > +static void esp32_uart_transmit_buffer(struct uart_port *port) > +{ > + u32 tx_fifo_used = esp32_uart_tx_fifo_cnt(port); > + > + if (tx_fifo_used < ESP32_UART_TX_FIFO_SIZE) { Invert the condition and return here? > + unsigned int pending; > + u8 ch; > + > + pending = uart_port_tx_limited(port, ch, > + ESP32_UART_TX_FIFO_SIZE - tx_fifo_used, > + true, esp32_uart_put_char(port, ch), > + ({})); > + if (pending) { > + u32 int_ena; > + > + int_ena = esp32_uart_read(port, UART_INT_ENA_REG); > + int_ena |= UART_TXFIFO_EMPTY_INT; > + esp32_uart_write(port, UART_INT_ENA_REG, int_ena); > + } > + } > +} > +static irqreturn_t esp32_uart_int(int irq, void *dev_id) > +{ > + struct uart_port *port = dev_id; > + u32 status; > + > + status = esp32_uart_read(port, UART_INT_ST_REG); > + > + if (status & (UART_RXFIFO_FULL_INT | UART_BRK_DET_INT)) > + esp32_uart_rxint(port); > + if (status & UART_TXFIFO_EMPTY_INT) > + esp32_uart_txint(port); > + > + esp32_uart_write(port, UART_INT_CLR_REG, status); \n here please. > + return IRQ_RETVAL(status); > +} > +static int esp32_uart_startup(struct uart_port *port) > +{ > + int ret = 0; > + unsigned long flags; > + struct esp32_port *sport = container_of(port, struct esp32_port, port); > + > + ret = clk_prepare_enable(sport->clk); > + if (ret) > + return ret; > + > + ret = devm_request_irq(port->dev, port->irq, esp32_uart_int, 0, > + DRIVER_NAME, port); > + if (ret) { > + clk_disable_unprepare(sport->clk); > + return ret; > + } > + > + spin_lock_irqsave(&port->lock, flags); > + esp32_uart_write(port, UART_CONF1_REG, > + (1 << UART_RXFIFO_FULL_THRHD_SHIFT) | BIT() ? > + (1 << port_variant(port)->txfifo_empty_thrhd_shift)); And here? > + esp32_uart_write(port, UART_INT_CLR_REG, UART_RXFIFO_FULL_INT | UART_BRK_DET_INT); > + esp32_uart_write(port, UART_INT_ENA_REG, UART_RXFIFO_FULL_INT | UART_BRK_DET_INT); > + spin_unlock_irqrestore(&port->lock, flags); > + > + pr_debug("%s, conf1 = %08x, int_st = %08x, status = %08x\n", > + __func__, > + esp32_uart_read(port, UART_CONF1_REG), > + esp32_uart_read(port, UART_INT_ST_REG), > + esp32_uart_read(port, UART_STATUS_REG)); \n here. Is this debug printout somehow useful? > + return ret; > +} > + > +static void esp32_uart_shutdown(struct uart_port *port) > +{ > + struct esp32_port *sport = container_of(port, struct esp32_port, port); > + > + esp32_uart_write(port, UART_INT_ENA_REG, 0); > + devm_free_irq(port->dev, port->irq, port); I wonder why to use devm_ after all? > + clk_disable_unprepare(sport->clk); > +} > + > +static bool esp32_uart_set_baud(struct uart_port *port, u32 baud) > +{ > + u32 div = port->uartclk / baud; > + u32 frag = (port->uartclk * 16) / baud - div * 16; > + > + if (div <= port_variant(port)->clkdiv_mask) { > + esp32_uart_write(port, UART_CLKDIV_REG, > + div | FIELD_PREP(UART_CLKDIV_FRAG, frag)); > + return true; > + } \n > + return false; > +} ... > +static int __init esp32s3_uart_early_console_setup(struct earlycon_device *device, > + const char *options) > +{ > + device->port.private_data = (void *)&esp32s3_variant; No need to cast, right? \n > + return esp32xx_uart_early_console_setup(device, options); > +} ... > +static int esp32_uart_probe(struct platform_device *pdev) > +{ > + struct device_node *np = pdev->dev.of_node; > + static const struct of_device_id *match; > + struct uart_port *port; > + struct esp32_port *sport; > + struct resource *res; > + int ret; > + > + match = of_match_device(esp32_uart_dt_ids, &pdev->dev); > + if (!match) > + return -ENODEV; > + > + sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); > + if (!sport) > + return -ENOMEM; > + > + port = &sport->port; > + > + ret = of_alias_get_id(np, "serial"); > + if (ret < 0) { > + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); > + return ret; > + } > + if (ret >= UART_NR) { > + dev_err(&pdev->dev, "driver limited to %d serial ports\n", UART_NR); > + return -ENOMEM; > + } > + > + port->line = ret; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) > + return -ENODEV; > + > + port->mapbase = res->start; > + port->membase = devm_ioremap_resource(&pdev->dev, res); > + if (IS_ERR(port->membase)) > + return PTR_ERR(port->membase); > + > + sport->clk = devm_clk_get(&pdev->dev, NULL); > + if (IS_ERR(sport->clk)) > + return PTR_ERR(sport->clk); > + > + port->uartclk = clk_get_rate(sport->clk); > + port->dev = &pdev->dev; > + port->type = PORT_ESP32UART; > + port->iotype = UPIO_MEM; > + port->irq = platform_get_irq(pdev, 0); > + port->ops = &esp32_uart_pops; > + port->flags = UPF_BOOT_AUTOCONF; > + port->has_sysrq = 1; > + port->fifosize = ESP32_UART_TX_FIFO_SIZE; > + port->private_data = (void *)match->data; No need to cast. > + > + esp32_uart_ports[port->line] = sport; > + > + platform_set_drvdata(pdev, port); > + > + return uart_add_one_port(&esp32_uart_reg, port); > +} regards,
On Wed, Sep 20, 2023 at 12:22 AM Jiri Slaby <jirislaby@kernel.org> wrote: > > On 20. 09. 23, 4:26, Max Filippov wrote: > > Add driver for the UART controllers of the Espressif ESP32 and ESP32S3 > > SoCs. Hardware specification is available at the following URLs: > ... > > +static void esp32_uart_rxint(struct uart_port *port) > > +{ > > + struct tty_port *tty_port = &port->state->port; > > + u32 rx_fifo_cnt = esp32_uart_rx_fifo_cnt(port); > > + unsigned long flags; > > + u32 i; > > + > > + if (!rx_fifo_cnt) > > + return; > > + > > + spin_lock_irqsave(&port->lock, flags); > > + > > + for (i = 0; i < rx_fifo_cnt; ++i) { > > + u32 rx = esp32_uart_read(port, UART_FIFO_REG); > > + u32 brk = 0; > > + > > + ++port->icount.rx; > > Should yuou increment this only in case of insert_flip_char()? I don't know. Does port->icount.rx have clearly defined semantics? I've looked through multiple other serial drivers and there's a lot of examples of similar pattern. > > + if (!rx) { > > + brk = esp32_uart_read(port, UART_INT_ST_REG) & > > + UART_BRK_DET_INT; > > + } > > + if (brk) { > > + esp32_uart_write(port, UART_INT_CLR_REG, brk); > > + ++port->icount.brk; > > + uart_handle_break(port); > > + } else { > > + if (uart_handle_sysrq_char(port, (unsigned char)rx)) > > + continue; > > + tty_insert_flip_char(tty_port, rx, TTY_NORMAL); > > + } > > This is heavy. Is it equivalent to: > if (!rx && esp32_uart_read(port, UART_INT_ST_REG) & > UART_BRK_DET_INT) { > esp32_uart_write(port, UART_INT_CLR_REG, brk); > ++port->icount.brk; > uart_handle_break(port); > continue; > } > > if (uart_handle_sysrq_char(port, (unsigned char)rx)) > continue; > > tty_insert_flip_char(tty_port, rx, TTY_NORMAL); > > ? It is equivalent, but I find the version that I used somewhat easier to read. Maybe this: if (!rx && (esp32_uart_read(port, UART_INT_ST_REG) & UART_BRK_DET_INT)) { esp32_uart_write(port, UART_INT_CLR_REG, brk); ++port->icount.brk; uart_handle_break(port); } else { if (uart_handle_sysrq_char(port, (unsigned char)rx)) continue; tty_insert_flip_char(tty_port, rx, TTY_NORMAL); } ? > > + } > > + spin_unlock_irqrestore(&port->lock, flags); > > + > > + tty_flip_buffer_push(tty_port); > > +} > ... > > +static void esp32_uart_put_char_sync(struct uart_port *port, u8 c) > > +{ > > + unsigned long timeout; > > + > > + timeout = jiffies + msecs_to_jiffies(1000); > > I.e. plus HZ? Yes, ok. > > + while (esp32_uart_tx_fifo_cnt(port) >= ESP32_UART_TX_FIFO_SIZE) { > > + if (time_after(jiffies, timeout)) { > > + dev_warn(port->dev, "timeout waiting for TX FIFO\n"); > > + return; > > + } > > + cpu_relax(); > > + } > > + esp32_uart_put_char(port, c); > > +} > > + > > +static void esp32_uart_transmit_buffer(struct uart_port *port) > > +{ > > + u32 tx_fifo_used = esp32_uart_tx_fifo_cnt(port); > > + > > + if (tx_fifo_used < ESP32_UART_TX_FIFO_SIZE) { > > Invert the condition and return here? Ok. > > + unsigned int pending; > > + u8 ch; > > + > > + pending = uart_port_tx_limited(port, ch, > > + ESP32_UART_TX_FIFO_SIZE - tx_fifo_used, > > + true, esp32_uart_put_char(port, ch), > > + ({})); > > + if (pending) { > > + u32 int_ena; > > + > > + int_ena = esp32_uart_read(port, UART_INT_ENA_REG); > > + int_ena |= UART_TXFIFO_EMPTY_INT; > > + esp32_uart_write(port, UART_INT_ENA_REG, int_ena); > > + } > > + } > > +} > > > > +static irqreturn_t esp32_uart_int(int irq, void *dev_id) > > +{ > > + struct uart_port *port = dev_id; > > + u32 status; > > + > > + status = esp32_uart_read(port, UART_INT_ST_REG); > > + > > + if (status & (UART_RXFIFO_FULL_INT | UART_BRK_DET_INT)) > > + esp32_uart_rxint(port); > > + if (status & UART_TXFIFO_EMPTY_INT) > > + esp32_uart_txint(port); > > + > > + esp32_uart_write(port, UART_INT_CLR_REG, status); > > \n here please. Ok > > + return IRQ_RETVAL(status); > > +} > > > +static int esp32_uart_startup(struct uart_port *port) > > +{ > > + int ret = 0; > > + unsigned long flags; > > + struct esp32_port *sport = container_of(port, struct esp32_port, port); > > + > > + ret = clk_prepare_enable(sport->clk); > > + if (ret) > > + return ret; > > + > > + ret = devm_request_irq(port->dev, port->irq, esp32_uart_int, 0, > > + DRIVER_NAME, port); > > + if (ret) { > > + clk_disable_unprepare(sport->clk); > > + return ret; > > + } > > + > > + spin_lock_irqsave(&port->lock, flags); > > + esp32_uart_write(port, UART_CONF1_REG, > > + (1 << UART_RXFIFO_FULL_THRHD_SHIFT) | > > BIT() ? > > > + (1 << port_variant(port)->txfifo_empty_thrhd_shift)); > > And here? These are not logically bits, in both cases I put value 1 into multiple-bit fields. > > + esp32_uart_write(port, UART_INT_CLR_REG, UART_RXFIFO_FULL_INT | UART_BRK_DET_INT); > > + esp32_uart_write(port, UART_INT_ENA_REG, UART_RXFIFO_FULL_INT | UART_BRK_DET_INT); > > + spin_unlock_irqrestore(&port->lock, flags); > > + > > + pr_debug("%s, conf1 = %08x, int_st = %08x, status = %08x\n", > > + __func__, > > + esp32_uart_read(port, UART_CONF1_REG), > > + esp32_uart_read(port, UART_INT_ST_REG), > > + esp32_uart_read(port, UART_STATUS_REG)); > > \n here. Is this debug printout somehow useful? I'll drop it. > > + return ret; > > +} > > + > > +static void esp32_uart_shutdown(struct uart_port *port) > > +{ > > + struct esp32_port *sport = container_of(port, struct esp32_port, port); > > + > > + esp32_uart_write(port, UART_INT_ENA_REG, 0); > > + devm_free_irq(port->dev, port->irq, port); > > I wonder why to use devm_ after all? I'll switch to non-devm_ version. > > + clk_disable_unprepare(sport->clk); > > +} > > + > > +static bool esp32_uart_set_baud(struct uart_port *port, u32 baud) > > +{ > > + u32 div = port->uartclk / baud; > > + u32 frag = (port->uartclk * 16) / baud - div * 16; > > + > > + if (div <= port_variant(port)->clkdiv_mask) { > > + esp32_uart_write(port, UART_CLKDIV_REG, > > + div | FIELD_PREP(UART_CLKDIV_FRAG, frag)); > > + return true; > > + } > > \n Ok. > > + return false; > > +} > ... > > +static int __init esp32s3_uart_early_console_setup(struct earlycon_device *device, > > + const char *options) > > +{ > > + device->port.private_data = (void *)&esp32s3_variant; > > No need to cast, right? private_data is void *, esp32s3_variant is a constant. > \n Ok. > > + return esp32xx_uart_early_console_setup(device, options); > > +} > ... > > +static int esp32_uart_probe(struct platform_device *pdev) > > +{ > > + struct device_node *np = pdev->dev.of_node; > > + static const struct of_device_id *match; > > + struct uart_port *port; > > + struct esp32_port *sport; > > + struct resource *res; > > + int ret; > > + > > + match = of_match_device(esp32_uart_dt_ids, &pdev->dev); > > + if (!match) > > + return -ENODEV; > > + > > + sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); > > + if (!sport) > > + return -ENOMEM; > > + > > + port = &sport->port; > > + > > + ret = of_alias_get_id(np, "serial"); > > + if (ret < 0) { > > + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); > > + return ret; > > + } > > + if (ret >= UART_NR) { > > + dev_err(&pdev->dev, "driver limited to %d serial ports\n", UART_NR); > > + return -ENOMEM; > > + } > > + > > + port->line = ret; > > + > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + if (!res) > > + return -ENODEV; > > + > > + port->mapbase = res->start; > > + port->membase = devm_ioremap_resource(&pdev->dev, res); > > + if (IS_ERR(port->membase)) > > + return PTR_ERR(port->membase); > > + > > + sport->clk = devm_clk_get(&pdev->dev, NULL); > > + if (IS_ERR(sport->clk)) > > + return PTR_ERR(sport->clk); > > + > > + port->uartclk = clk_get_rate(sport->clk); > > + port->dev = &pdev->dev; > > + port->type = PORT_ESP32UART; > > + port->iotype = UPIO_MEM; > > + port->irq = platform_get_irq(pdev, 0); > > + port->ops = &esp32_uart_pops; > > + port->flags = UPF_BOOT_AUTOCONF; > > + port->has_sysrq = 1; > > + port->fifosize = ESP32_UART_TX_FIFO_SIZE; > > + port->private_data = (void *)match->data; > > No need to cast. This is again a const cast. > > + > > + esp32_uart_ports[port->line] = sport; > > + > > + platform_set_drvdata(pdev, port); > > + > > + return uart_add_one_port(&esp32_uart_reg, port); > > +} > > regards, > -- > js > suse labs >