public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Siarhei Volkau <lis8215@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Siarhei Volkau <lis8215@gmail.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Vinod Koul <vkoul@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Paul Cercueil <paul@crapouillou.net>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	linux-serial@vger.kernel.org, linux-mips@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: [PATCH 7/8] serial: 8250/ingenic: Add support for the JZ4750/JZ4755 SoCs
Date: Sun,  9 Oct 2022 21:13:36 +0300	[thread overview]
Message-ID: <20221009181338.2896660-8-lis8215@gmail.com> (raw)
In-Reply-To: <20221009181338.2896660-1-lis8215@gmail.com>

These SoCs are close to others but they have a clock divisor /2 for low
clock peripherals, thus to set up a proper baud rate we need to take
this into account.

The divisor bit is located in CGU area, unfortunately the clk framework
can't be used at early boot steps, so it's checked by direct readl()
call.

Signed-off-by: Siarhei Volkau <lis8215@gmail.com>
---
 drivers/tty/serial/8250/8250_ingenic.c | 39 ++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_ingenic.c b/drivers/tty/serial/8250/8250_ingenic.c
index 2b2f5d8d2..f2662720d 100644
--- a/drivers/tty/serial/8250/8250_ingenic.c
+++ b/drivers/tty/serial/8250/8250_ingenic.c
@@ -70,7 +70,8 @@ static void ingenic_early_console_write(struct console *console,
 			   ingenic_early_console_putc);
 }
 
-static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev)
+static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev,
+						     int clkdiv)
 {
 	void *fdt = initial_boot_params;
 	const __be32 *prop;
@@ -84,11 +85,11 @@ static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev
 	if (!prop)
 		return;
 
-	dev->port.uartclk = be32_to_cpup(prop);
+	dev->port.uartclk = be32_to_cpup(prop) / clkdiv;
 }
 
-static int __init ingenic_early_console_setup(struct earlycon_device *dev,
-					      const char *opt)
+static int __init ingenic_earlycon_setup_common(struct earlycon_device *dev,
+						const char *opt, int clkdiv)
 {
 	struct uart_port *port = &dev->port;
 	unsigned int divisor;
@@ -103,7 +104,7 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev,
 		uart_parse_options(opt, &baud, &parity, &bits, &flow);
 	}
 
-	ingenic_early_console_setup_clock(dev);
+	ingenic_early_console_setup_clock(dev, clkdiv);
 
 	if (dev->baud)
 		baud = dev->baud;
@@ -129,9 +130,31 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev,
 	return 0;
 }
 
+static int __init ingenic_early_console_setup(struct earlycon_device *dev,
+					      const char *opt)
+{
+	return ingenic_earlycon_setup_common(dev, opt, 1);
+}
+
+static int __init jz4750_early_console_setup(struct earlycon_device *dev,
+					     const char *opt)
+{
+#define CGU_REG_CPCCR	((void *)CKSEG1ADDR(0x10000000))
+#define CPCCR_ECS	BIT(30)
+	u32 cpccr = readl(CGU_REG_CPCCR);
+	int clk_div = (cpccr & CPCCR_ECS) ? 2 : 1;
+#undef CGU_REG_CPCCR
+#undef CPCCR_ECS
+
+	return ingenic_earlycon_setup_common(dev, opt, clk_div);
+}
+
 OF_EARLYCON_DECLARE(jz4740_uart, "ingenic,jz4740-uart",
 		    ingenic_early_console_setup);
 
+OF_EARLYCON_DECLARE(jz4750_uart, "ingenic,jz4750-uart",
+		    jz4750_early_console_setup);
+
 OF_EARLYCON_DECLARE(jz4770_uart, "ingenic,jz4770-uart",
 		    ingenic_early_console_setup);
 
@@ -311,6 +334,11 @@ static const struct ingenic_uart_config jz4740_uart_config = {
 	.fifosize = 16,
 };
 
+static const struct ingenic_uart_config jz4750_uart_config = {
+	.tx_loadsz = 16,
+	.fifosize = 32,
+};
+
 static const struct ingenic_uart_config jz4760_uart_config = {
 	.tx_loadsz = 16,
 	.fifosize = 32,
@@ -328,6 +356,7 @@ static const struct ingenic_uart_config x1000_uart_config = {
 
 static const struct of_device_id of_match[] = {
 	{ .compatible = "ingenic,jz4740-uart", .data = &jz4740_uart_config },
+	{ .compatible = "ingenic,jz4750-uart", .data = &jz4750_uart_config },
 	{ .compatible = "ingenic,jz4760-uart", .data = &jz4760_uart_config },
 	{ .compatible = "ingenic,jz4770-uart", .data = &jz4760_uart_config },
 	{ .compatible = "ingenic,jz4775-uart", .data = &jz4760_uart_config },
-- 
2.36.1


  parent reply	other threads:[~2022-10-09 18:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-09 18:13 [PATCH 0/8] MIPS: ingenic: Add support for the JZ4755 SoC Siarhei Volkau
2022-10-09 18:13 ` [PATCH 1/8] dt-bindings: " Siarhei Volkau
2022-10-10 14:53   ` Krzysztof Kozlowski
2022-10-10 20:18     ` Siarhei Volkau
2022-10-11 12:08       ` Krzysztof Kozlowski
2022-10-13  9:03       ` Paul Cercueil
2022-10-09 18:13 ` [PATCH 2/8] MIPS: ingenic: add new machine type MACH_JZ4755 Siarhei Volkau
2022-10-09 18:13 ` [PATCH 3/8] dt-bindings: clock: Add Ingenic JZ4755 CGU header Siarhei Volkau
2022-10-10 13:05   ` Rob Herring
2022-10-09 18:13 ` [PATCH 4/8] clk: Add Ingenic JZ4755 CGU driver Siarhei Volkau
2022-10-09 18:13 ` [PATCH 5/8] pinctrl: ingenic: JZ4755 minor bug fixes Siarhei Volkau
2022-10-17  9:46   ` Linus Walleij
2022-10-09 18:13 ` [PATCH 6/8] dmaengine: JZ4780: Add support for the JZ4755 Siarhei Volkau
2022-10-09 18:13 ` Siarhei Volkau [this message]
2022-10-10 20:20   ` [PATCH 7/8] serial: 8250/ingenic: Add support for the JZ4750/JZ4755 SoCs Greg Kroah-Hartman
2022-10-11 18:38     ` Siarhei Volkau
     [not found]   ` <202210100607.YdxoR0tD-lkp@intel.com>
2022-10-13  6:37     ` Siarhei Volkau
2022-10-13  6:46       ` Arnd Bergmann
2022-10-13  9:17         ` Paul Cercueil
2022-10-13 18:56           ` Siarhei Volkau
2022-10-16 18:39             ` Siarhei Volkau
2022-10-17  9:31               ` Paul Cercueil
2022-10-19 15:19                 ` Siarhei Volkau
2022-10-09 18:13 ` [PATCH 8/8] MIPS: DTS: Ingenic: Add support for the JZ4755 SoC Siarhei Volkau
2022-10-10 14:54   ` Krzysztof Kozlowski
2022-10-10 20:00     ` Siarhei Volkau
2022-10-11 12:09       ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221009181338.2896660-8-lis8215@gmail.com \
    --to=lis8215@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=paul@crapouillou.net \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox