From nobody Wed Jul 1 13:24:54 2026 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 0A93EC433F5 for ; Tue, 21 Dec 2021 07:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235276AbhLUHcL (ORCPT ); Tue, 21 Dec 2021 02:32:11 -0500 Received: from mail-sh.amlogic.com ([58.32.228.43]:61697 "EHLO mail-sh.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbhLUHcH (ORCPT ); Tue, 21 Dec 2021 02:32:07 -0500 X-Greylist: delayed 902 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Dec 2021 02:32:04 EST Received: from droid06.amlogic.com (10.18.11.248) by mail-sh.amlogic.com (10.18.11.5) with Microsoft SMTP Server id 15.1.2176.14; Tue, 21 Dec 2021 15:17:01 +0800 From: Yu Tu To: , , , CC: Greg Kroah-Hartman , Jiri Slaby , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yu Tu Subject: [PATCH 1/3] tty: serial: meson: modify request_irq and free_irq Date: Tue, 21 Dec 2021 15:16:32 +0800 Message-ID: <20211221071634.25980-2-yu.tu@amlogic.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221071634.25980-1-yu.tu@amlogic.com> References: <20211221071634.25980-1-yu.tu@amlogic.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.18.11.248] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Change request_irq to devm_request_irq and free_irq to devm_free_irq. It's better to change the code this way. The IRQF_SHARED interrupt flag was added because an interrupt error was detected when the serial port was opened twice in a row on the project. Signed-off-by: Yu Tu --- drivers/tty/serial/meson_uart.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uar= t.c index d2c08b760f83..02fafb8229d2 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -121,7 +121,7 @@ static void meson_uart_shutdown(struct uart_port *port) unsigned long flags; u32 val; =20 - free_irq(port->irq, port); + devm_free_irq(port->dev, port->irq, port); =20 spin_lock_irqsave(&port->lock, flags); =20 @@ -287,8 +287,8 @@ static int meson_uart_startup(struct uart_port *port) val =3D (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); writel(val, port->membase + AML_UART_MISC); =20 - ret =3D request_irq(port->irq, meson_uart_interrupt, 0, - port->name, port); + ret =3D devm_request_irq(port->dev, port->irq, meson_uart_interrupt, + IRQF_SHARED, port->name, port); =20 return ret; } --=20 2.33.1 From nobody Wed Jul 1 13:24:54 2026 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 C189EC433F5 for ; Tue, 21 Dec 2021 07:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235286AbhLUHcO (ORCPT ); Tue, 21 Dec 2021 02:32:14 -0500 Received: from mail-sh.amlogic.com ([58.32.228.43]:61697 "EHLO mail-sh.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235257AbhLUHcL (ORCPT ); Tue, 21 Dec 2021 02:32:11 -0500 X-Greylist: delayed 902 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Dec 2021 02:32:04 EST Received: from droid06.amlogic.com (10.18.11.248) by mail-sh.amlogic.com (10.18.11.5) with Microsoft SMTP Server id 15.1.2176.14; Tue, 21 Dec 2021 15:17:02 +0800 From: Yu Tu To: , , , CC: Greg Kroah-Hartman , Jiri Slaby , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yu Tu Subject: [PATCH 2/3] tty: serial: meson: meson_uart_shutdown omit clear AML_UART_TX_EN bit Date: Tue, 21 Dec 2021 15:16:33 +0800 Message-ID: <20211221071634.25980-3-yu.tu@amlogic.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221071634.25980-1-yu.tu@amlogic.com> References: <20211221071634.25980-1-yu.tu@amlogic.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.18.11.248] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The meson_uart_shutdown function should have the opposite operation to the meson_uart_startup function, so the shutdown of AML_UART_TX_EN is logically missing. Signed-off-by: Yu Tu --- drivers/tty/serial/meson_uart.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uar= t.c index 02fafb8229d2..69450a461c48 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -126,8 +126,7 @@ static void meson_uart_shutdown(struct uart_port *port) spin_lock_irqsave(&port->lock, flags); =20 val =3D readl(port->membase + AML_UART_CONTROL); - val &=3D ~AML_UART_RX_EN; - val &=3D ~(AML_UART_RX_INT_EN | AML_UART_TX_INT_EN); + val &=3D ~(AML_UART_RX_EN | AML_UART_TX_EN); writel(val, port->membase + AML_UART_CONTROL); =20 spin_unlock_irqrestore(&port->lock, flags); --=20 2.33.1 From nobody Wed Jul 1 13:24:54 2026 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 81923C433EF for ; Tue, 21 Dec 2021 07:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235291AbhLUHcQ (ORCPT ); Tue, 21 Dec 2021 02:32:16 -0500 Received: from mail-sh.amlogic.com ([58.32.228.43]:61697 "EHLO mail-sh.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235258AbhLUHcP (ORCPT ); Tue, 21 Dec 2021 02:32:15 -0500 X-Greylist: delayed 902 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Dec 2021 02:32:04 EST Received: from droid06.amlogic.com (10.18.11.248) by mail-sh.amlogic.com (10.18.11.5) with Microsoft SMTP Server id 15.1.2176.14; Tue, 21 Dec 2021 15:17:03 +0800 From: Yu Tu To: , , , CC: Greg Kroah-Hartman , Jiri Slaby , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yu Tu Subject: [PATCH 3/3] tty: serial: meson: add UART driver compatible with S4 SoC on-chip Date: Tue, 21 Dec 2021 15:16:34 +0800 Message-ID: <20211221071634.25980-4-yu.tu@amlogic.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221071634.25980-1-yu.tu@amlogic.com> References: <20211221071634.25980-1-yu.tu@amlogic.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.18.11.248] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The S4 SoC on-chip UART uses a 12M clock as the clock source for calculating the baud rate of the UART. But previously, chips used 24M or other clock sources. So add this change. The specific clock source is determined by chip design. Signed-off-by: Yu Tu --- drivers/tty/serial/meson_uart.c | 62 +++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uar= t.c index 69450a461c48..557c24d954a2 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 /* Register offsets */ #define AML_UART_WFIFO 0x00 @@ -68,6 +69,8 @@ #define AML_UART_BAUD_MASK 0x7fffff #define AML_UART_BAUD_USE BIT(23) #define AML_UART_BAUD_XTAL BIT(24) +#define AML_UART_BAUD_XTAL_TICK BIT(26) +#define AML_UART_BAUD_XTAL_DIV2 BIT(27) =20 #define AML_UART_PORT_NUM 12 #define AML_UART_PORT_OFFSET 6 @@ -80,6 +83,11 @@ static struct uart_driver meson_uart_driver; =20 static struct uart_port *meson_ports[AML_UART_PORT_NUM]; =20 +struct meson_uart_data { + /*A clock source that calculates baud rates*/ + unsigned int xtal_tick_en; +}; + static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctr= l) { } @@ -294,16 +302,29 @@ static int meson_uart_startup(struct uart_port *port) =20 static void meson_uart_change_speed(struct uart_port *port, unsigned long = baud) { + struct meson_uart_data *uart_data =3D port->private_data; u32 val; =20 while (!meson_uart_tx_empty(port)) cpu_relax(); =20 + val =3D readl_relaxed(port->membase + AML_UART_REG5); + val &=3D ~AML_UART_BAUD_MASK; + if (port->uartclk =3D=3D 24000000) { - val =3D ((port->uartclk / 3) / baud) - 1; - val |=3D AML_UART_BAUD_XTAL; + if (uart_data->xtal_tick_en) { + val =3D (port->uartclk / 2 + baud / 2) / baud - 1; + val |=3D (AML_UART_BAUD_XTAL | AML_UART_BAUD_XTAL_DIV2); + } else { + val =3D ((port->uartclk / 3) + baud / 2) / baud - 1; + val &=3D (~(AML_UART_BAUD_XTAL_TICK | + AML_UART_BAUD_XTAL_DIV2)); + val |=3D AML_UART_BAUD_XTAL; + } } else { val =3D ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1; + val &=3D (~(AML_UART_BAUD_XTAL | AML_UART_BAUD_XTAL_TICK | + AML_UART_BAUD_XTAL_DIV2)); } val |=3D AML_UART_BAUD_USE; writel(val, port->membase + AML_UART_REG5); @@ -714,6 +735,7 @@ static int meson_uart_probe(struct platform_device *pde= v) { struct resource *res_mem, *res_irq; struct uart_port *port; + struct meson_uart_data *uart_data; int ret =3D 0; int id =3D -1; =20 @@ -729,6 +751,10 @@ static int meson_uart_probe(struct platform_device *pd= ev) } } =20 + uart_data =3D of_device_get_match_data(&pdev->dev); + if (!uart_data) + return -EINVAL; + if (pdev->id < 0 || pdev->id >=3D AML_UART_PORT_NUM) return -EINVAL; =20 @@ -770,6 +796,7 @@ static int meson_uart_probe(struct platform_device *pde= v) port->x_char =3D 0; port->ops =3D &meson_uart_ops; port->fifosize =3D 64; + port->private_data =3D uart_data; =20 meson_ports[pdev->id] =3D port; platform_set_drvdata(pdev, port); @@ -798,14 +825,35 @@ static int meson_uart_remove(struct platform_device *= pdev) return 0; } =20 +static const struct meson_uart_data meson_uart_data =3D { + .xtal_tick_en =3D 0, +}; + +static const struct meson_uart_data s4_meson_uart_data =3D { + .xtal_tick_en =3D 1, +}; + static const struct of_device_id meson_uart_dt_match[] =3D { /* Legacy bindings, should be removed when no more used */ - { .compatible =3D "amlogic,meson-uart" }, + { .compatible =3D "amlogic,meson-uart", + .data =3D &meson_uart_data + }, /* Stable bindings */ - { .compatible =3D "amlogic,meson6-uart" }, - { .compatible =3D "amlogic,meson8-uart" }, - { .compatible =3D "amlogic,meson8b-uart" }, - { .compatible =3D "amlogic,meson-gx-uart" }, + { .compatible =3D "amlogic,meson6-uart", + .data =3D &meson_uart_data + }, + { .compatible =3D "amlogic,meson8-uart", + .data =3D &meson_uart_data + }, + { .compatible =3D "amlogic,meson8b-uart", + .data =3D &meson_uart_data + }, + { .compatible =3D "amlogic,meson-gx-uart", + .data =3D &meson_uart_data + }, + { .compatible =3D "amlogic,meson-s4-uart", + .data =3D &s4_meson_uart_data + }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, meson_uart_dt_match); --=20 2.33.1