mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/8] Raspberry Pi miniuart support
@ 2018-12-13  7:44 Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c Rouven Czerwinski
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

This patch series adds support for the raspberry pi miniuart (also called
aux-uart) to barebox.
With this series the miniuart overlay is no longer necessary to start barebox on
Raspberry Pi 3.

v2:
- Move console clock initialization into board core
- Retrieve the core clock frequency for the miniuart from the firmware
- Double the clock frequency in the ns16550 rpi init function instead of
  during initialization
from Lucas Stach

Rouven Czerwinski (8):
  ARM: rpi: fix typo in rpi-common.c
  ARM: rpi: move clks into board specific rpi-common
  ARM: rpi: retrieve miniuart clock from firmware
  serial_ns16550: handle default reg-io-width
  serial_ns16550: add raspberry pi compatible and init
  ARM: rpi: add NS16550 support
  ARM: rpi: choose miniuart as stdout
  doc: bcm283x: remove miniuart overlay instruction

 Documentation/boards/bcm2835.rst          |  1 -
 arch/arm/boards/raspberry-pi/rpi-common.c | 30 +++++++++-
 arch/arm/configs/rpi_defconfig            |  1 +
 arch/arm/dts/bcm2837-rpi-3.dts            |  7 +--
 arch/arm/mach-bcm283x/core.c              | 19 ------
 drivers/serial/serial_ns16550.c           | 71 +++++++++++++++--------
 6 files changed, 78 insertions(+), 51 deletions(-)

-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 2/8] ARM: rpi: move clks into board specific rpi-common Rouven Czerwinski
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index 650b26ce7..840f525bb 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -73,7 +73,7 @@ static int rpi_get_arm_mem(u32 *size)
 	return 0;
 }
 
-static struct clk *rpi_register_firmare_clock(u32 clock_id, const char *name)
+static struct clk *rpi_register_firmware_clock(u32 clock_id, const char *name)
 {
 	BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg);
 	int ret;
@@ -286,7 +286,7 @@ static int rpi_clock_init(void)
 {
 	struct clk *clk;
 
-	clk = rpi_register_firmare_clock(BCM2835_MBOX_CLOCK_ID_EMMC,
+	clk = rpi_register_firmware_clock(BCM2835_MBOX_CLOCK_ID_EMMC,
 					 "bcm2835_mci0");
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 2/8] ARM: rpi: move clks into board specific rpi-common
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 3/8] ARM: rpi: retrieve miniuart clock from firmware Rouven Czerwinski
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

We don't know if the firmware running on the raspberry pi is the same firmware
which is running on all bcm283x devices.
Therefore move the console clock initialization into the rpi-common.c board file.
A future commit will use this function to retrieve the miniuart clock from the
raspberry pi firmware.
No functional changes.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 19 +++++++++++++++++++
 arch/arm/mach-bcm283x/core.c              | 19 -------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index 840f525bb..887f096f7 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -298,6 +298,25 @@ static int rpi_clock_init(void)
 }
 postconsole_initcall(rpi_clock_init);
 
+static int rpi_console_clock_init(void)
+{
+	struct clk *clk;
+
+	clk = clk_fixed("apb_pclk", 0);
+	clk_register_clkdev(clk, "apb_pclk", NULL);
+
+	clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000);
+	clk_register_clkdev(clk, NULL, "uart0-pl0110");
+	clkdev_add_physbase(clk, 0x20201000, NULL);
+	clkdev_add_physbase(clk, 0x3f201000, NULL);
+
+	clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
+	clk_register_clkdev(clk, NULL, "bcm2835-cs");
+
+	return 0;
+}
+postcore_initcall(rpi_console_clock_init);
+
 static int rpi_env_init(void)
 {
 	struct stat s;
diff --git a/arch/arm/mach-bcm283x/core.c b/arch/arm/mach-bcm283x/core.c
index f1dcda86f..f2528cf1f 100644
--- a/arch/arm/mach-bcm283x/core.c
+++ b/arch/arm/mach-bcm283x/core.c
@@ -31,25 +31,6 @@
 #include <mach/core.h>
 #include <linux/amba/bus.h>
 
-static int bcm2835_clk_init(void)
-{
-	struct clk *clk;
-
-	clk = clk_fixed("apb_pclk", 0);
-	clk_register_clkdev(clk, "apb_pclk", NULL);
-
-	clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000);
-	clk_register_clkdev(clk, NULL, "uart0-pl0110");
-	clkdev_add_physbase(clk, 0x20201000, NULL);
-	clkdev_add_physbase(clk, 0x3f201000, NULL);
-
-	clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
-	clk_register_clkdev(clk, NULL, "bcm2835-cs");
-
-	return 0;
-}
-postcore_initcall(bcm2835_clk_init);
-
 void bcm2835_add_device_sdram(u32 size)
 {
 	if (!size)
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 3/8] ARM: rpi: retrieve miniuart clock from firmware
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 2/8] ARM: rpi: move clks into board specific rpi-common Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 4/8] serial_ns16550: handle default reg-io-width Rouven Czerwinski
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

The miniuart uses the core clock as the clock source. This clock is fixed by the
firmware to 250Mhz if enable_uart=1 is set in the config.txt file.
However a user could still choose to overclock the core frequency,
which would result in wrong baudrates computed by barebox.
Retrieve the core clock frequency from the firmware to allow all potential
firmware configurations to work with barebox.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index 887f096f7..f22239c7c 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -310,6 +310,13 @@ static int rpi_console_clock_init(void)
 	clkdev_add_physbase(clk, 0x20201000, NULL);
 	clkdev_add_physbase(clk, 0x3f201000, NULL);
 
+	clk = rpi_register_firmware_clock(BCM2835_MBOX_CLOCK_ID_CORE,
+					  "uart1-8250");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	clkdev_add_physbase(clk, 0x3f215040, NULL);
+
 	clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
 	clk_register_clkdev(clk, NULL, "bcm2835-cs");
 
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 4/8] serial_ns16550: handle default reg-io-width
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
                   ` (2 preceding siblings ...)
  2018-12-13  7:44 ` [PATCH v2 3/8] ARM: rpi: retrieve miniuart clock from firmware Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13 15:56   ` Oleksij Rempel
  2018-12-13  7:44 ` [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init Rouven Czerwinski
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

According to the device tree bindings for 8250, width is an optional property.
Default to 1 which is the same default value as used by the kernel.
Before this change the driver would not work for device trees which do not
include the optional binding.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 drivers/serial/serial_ns16550.c | 46 ++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 4d73ea8b8..8ddcfdbef 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -297,36 +297,36 @@ static int ns16550_tstc(struct console_device *cdev)
 static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv)
 {
 	struct device_node *np = dev->device_node;
-	u32 width;
+	u32 width = 1;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE))
 		return;
 
 	of_property_read_u32(np, "clock-frequency", &priv->plat.clock);
 	of_property_read_u32(np, "reg-shift", &priv->plat.shift);
-	if (!of_property_read_u32(np, "reg-io-width", &width))
-		switch (width) {
-		case 1:
-			priv->read_reg = ns16550_read_reg_mmio_8;
-			priv->write_reg = ns16550_write_reg_mmio_8;
-			break;
-		case 2:
-			priv->read_reg = ns16550_read_reg_mmio_16;
-			priv->write_reg = ns16550_write_reg_mmio_16;
-			break;
-		case 4:
-			if (of_device_is_big_endian(np)) {
-				priv->read_reg = ns16550_read_reg_mmio_32be;
-				priv->write_reg = ns16550_write_reg_mmio_32be;
-			} else {
-				priv->read_reg = ns16550_read_reg_mmio_32;
-				priv->write_reg = ns16550_write_reg_mmio_32;
-			}
-			break;
-		default:
-			dev_err(dev, "unsupported reg-io-width (%d)\n",
-				width);
+	of_property_read_u32(np, "reg-io-width", &width);
+	switch (width) {
+	case 1:
+		priv->read_reg = ns16550_read_reg_mmio_8;
+		priv->write_reg = ns16550_write_reg_mmio_8;
+		break;
+	case 2:
+		priv->read_reg = ns16550_read_reg_mmio_16;
+		priv->write_reg = ns16550_write_reg_mmio_16;
+		break;
+	case 4:
+		if (of_device_is_big_endian(np)) {
+			priv->read_reg = ns16550_read_reg_mmio_32be;
+			priv->write_reg = ns16550_write_reg_mmio_32be;
+		} else {
+			priv->read_reg = ns16550_read_reg_mmio_32;
+			priv->write_reg = ns16550_write_reg_mmio_32;
 		}
+		break;
+	default:
+		dev_err(dev, "unsupported reg-io-width (%d)\n",
+			width);
+	}
 }
 
 static struct ns16550_drvdata ns16450_drvdata = {
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
                   ` (3 preceding siblings ...)
  2018-12-13  7:44 ` [PATCH v2 4/8] serial_ns16550: handle default reg-io-width Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13 15:53   ` Oleksij Rempel
  2018-12-13  7:44 ` [PATCH v2 6/8] ARM: rpi: add NS16550 support Rouven Czerwinski
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Add the compatible for the Raspberry Pi AUX UART and an init function which
enables it via the aux register and configures the correct shift value.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 drivers/serial/serial_ns16550.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 8ddcfdbef..7a4054a67 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -253,6 +253,20 @@ static void ns16550_jz_init_port(struct console_device *cdev)
 	ns16550_serial_init_port(cdev);
 }
 
+static void rpi_init_port(struct console_device *cdev)
+{
+  struct ns16550_priv *priv = to_ns16550_priv(cdev);
+
+  writeb(0x01, 0x3f215004);
+  priv->plat.shift = 2;
+  /*
+   * We double the clock rate since the 16550 will divide by 16
+   * (instead of 8 required by the BCM2835 peripheral manual)
+   */
+  priv->plat.clock = priv->plat.clock*2;
+  ns16550_serial_init_port(cdev);
+}
+
 /*********** Exposed Functions **********************************/
 
 /**
@@ -353,6 +367,11 @@ static __maybe_unused struct ns16550_drvdata tegra_drvdata = {
 	.linux_console_name = "ttyS",
 };
 
+static struct ns16550_drvdata rpi_drvdata = {
+  .init_port = rpi_init_port,
+  .linux_console_name = "ttyS",
+};
+
 static int ns16550_init_iomem(struct device_d *dev, struct ns16550_priv *priv)
 {
 	struct resource *iores;
@@ -527,6 +546,12 @@ static struct of_device_id ns16550_serial_dt_ids[] = {
 		.compatible = "ingenic,jz4740-uart",
 		.data = &jz_drvdata,
 	},
+#endif
+#if IS_ENABLED(CONFIG_MACH_RPI_COMMON)
+	{
+	  .compatible = "brcm,bcm2835-aux-uart",
+	  .data = &rpi_drvdata,
+	},
 #endif
 	{
 		/* sentinel */
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 6/8] ARM: rpi: add NS16550 support
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
                   ` (4 preceding siblings ...)
  2018-12-13  7:44 ` [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 7/8] ARM: rpi: choose miniuart as stdout Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 8/8] doc: bcm283x: remove miniuart overlay instruction Rouven Czerwinski
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Since the 16550 driver now supports the RPI3 miniuart, enable it in the default
config.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/configs/rpi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig
index 2bb615849..dc5ab1fe1 100644
--- a/arch/arm/configs/rpi_defconfig
+++ b/arch/arm/configs/rpi_defconfig
@@ -63,6 +63,7 @@ CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
 CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_MCI=y
 CONFIG_MCI_BCM283X=y
 CONFIG_LED=y
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 7/8] ARM: rpi: choose miniuart as stdout
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
                   ` (5 preceding siblings ...)
  2018-12-13  7:44 ` [PATCH v2 6/8] ARM: rpi: add NS16550 support Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  2018-12-13  7:44 ` [PATCH v2 8/8] doc: bcm283x: remove miniuart overlay instruction Rouven Czerwinski
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Since we now support the miniuart, enable it as the default stdout port.
With this change the device tree overlay to switch the miniuart to bluetooth is
no longer necessary.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 arch/arm/dts/bcm2837-rpi-3.dts | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/arm/dts/bcm2837-rpi-3.dts b/arch/arm/dts/bcm2837-rpi-3.dts
index d6ffc3691..194b41c23 100644
--- a/arch/arm/dts/bcm2837-rpi-3.dts
+++ b/arch/arm/dts/bcm2837-rpi-3.dts
@@ -2,15 +2,10 @@
 
 / {
 	chosen {
-		stdout-path = &uart0;
+		stdout-path = &uart1;
 	};
 
 	memory {
 		reg = <0x0 0x0>;
 	};
 };
-
-&uart0 {
-	status = "okay";
-	/delete-node/ bluetooth;
-};
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 8/8] doc: bcm283x: remove miniuart overlay instruction
  2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
                   ` (6 preceding siblings ...)
  2018-12-13  7:44 ` [PATCH v2 7/8] ARM: rpi: choose miniuart as stdout Rouven Czerwinski
@ 2018-12-13  7:44 ` Rouven Czerwinski
  7 siblings, 0 replies; 12+ messages in thread
From: Rouven Czerwinski @ 2018-12-13  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Since we now use the miniuart on the raspberry pi 3, the miniuart overlay is no
longer needed.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 Documentation/boards/bcm2835.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Documentation/boards/bcm2835.rst b/Documentation/boards/bcm2835.rst
index 79ea0ff7a..ea80d5834 100644
--- a/Documentation/boards/bcm2835.rst
+++ b/Documentation/boards/bcm2835.rst
@@ -22,7 +22,6 @@ Raspberry Pi
 
          kernel=barebox.img
          enable_uart=1
-         dtoverlay=pi3-miniuart-bt
 
      (For more information, refer to the `documentation for config.txt`_.)
 
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init
  2018-12-13  7:44 ` [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init Rouven Czerwinski
@ 2018-12-13 15:53   ` Oleksij Rempel
  0 siblings, 0 replies; 12+ messages in thread
From: Oleksij Rempel @ 2018-12-13 15:53 UTC (permalink / raw)
  To: Rouven Czerwinski, barebox


[-- Attachment #1.1.1: Type: text/plain, Size: 2130 bytes --]

Hi Rouven,

Am 13.12.18 um 08:44 schrieb Rouven Czerwinski:
> Add the compatible for the Raspberry Pi AUX UART and an init function which
> enables it via the aux register and configures the correct shift value.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  drivers/serial/serial_ns16550.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
> index 8ddcfdbef..7a4054a67 100644
> --- a/drivers/serial/serial_ns16550.c
> +++ b/drivers/serial/serial_ns16550.c
> @@ -253,6 +253,20 @@ static void ns16550_jz_init_port(struct console_device *cdev)
>  	ns16550_serial_init_port(cdev);
>  }
>  
> +static void rpi_init_port(struct console_device *cdev)
> +{
> +  struct ns16550_priv *priv = to_ns16550_priv(cdev);
> +
> +  writeb(0x01, 0x3f215004);
> +  priv->plat.shift = 2;
> +  /*
> +   * We double the clock rate since the 16550 will divide by 16
> +   * (instead of 8 required by the BCM2835 peripheral manual)
> +   */
> +  priv->plat.clock = priv->plat.clock*2;
> +  ns16550_serial_init_port(cdev);
> +}

Formatting is broken here, you are using spaces instead of tabs.
Probably using checkpatch will show it.

>  /*********** Exposed Functions **********************************/
>  
>  /**
> @@ -353,6 +367,11 @@ static __maybe_unused struct ns16550_drvdata tegra_drvdata = {
>  	.linux_console_name = "ttyS",
>  };
>  
> +static struct ns16550_drvdata rpi_drvdata = {
> +  .init_port = rpi_init_port,
> +  .linux_console_name = "ttyS",
> +};

same here.

>  static int ns16550_init_iomem(struct device_d *dev, struct ns16550_priv *priv)
>  {
>  	struct resource *iores;
> @@ -527,6 +546,12 @@ static struct of_device_id ns16550_serial_dt_ids[] = {
>  		.compatible = "ingenic,jz4740-uart",
>  		.data = &jz_drvdata,
>  	},
> +#endif
> +#if IS_ENABLED(CONFIG_MACH_RPI_COMMON)
> +	{
> +	  .compatible = "brcm,bcm2835-aux-uart",
> +	  .data = &rpi_drvdata,
> +	},
>  #endif
>  	{
>  		/* sentinel */
> 


-- 
Regards,
Oleksij


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 4/8] serial_ns16550: handle default reg-io-width
  2018-12-13  7:44 ` [PATCH v2 4/8] serial_ns16550: handle default reg-io-width Rouven Czerwinski
@ 2018-12-13 15:56   ` Oleksij Rempel
  2018-12-14 10:58     ` Sascha Hauer
  0 siblings, 1 reply; 12+ messages in thread
From: Oleksij Rempel @ 2018-12-13 15:56 UTC (permalink / raw)
  To: Rouven Czerwinski, barebox


[-- Attachment #1.1.1: Type: text/plain, Size: 3222 bytes --]

Am 13.12.18 um 08:44 schrieb Rouven Czerwinski:
> According to the device tree bindings for 8250, width is an optional property.
> Default to 1 which is the same default value as used by the kernel.
> Before this change the driver would not work for device trees which do not
> include the optional binding.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  drivers/serial/serial_ns16550.c | 46 ++++++++++++++++-----------------
>  1 file changed, 23 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
> index 4d73ea8b8..8ddcfdbef 100644
> --- a/drivers/serial/serial_ns16550.c
> +++ b/drivers/serial/serial_ns16550.c
> @@ -297,36 +297,36 @@ static int ns16550_tstc(struct console_device *cdev)
>  static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv)
>  {
>  	struct device_node *np = dev->device_node;
> -	u32 width;
> +	u32 width = 1;
>  
>  	if (!IS_ENABLED(CONFIG_OFDEVICE))
>  		return;
>  
>  	of_property_read_u32(np, "clock-frequency", &priv->plat.clock);
>  	of_property_read_u32(np, "reg-shift", &priv->plat.shift);
> -	if (!of_property_read_u32(np, "reg-io-width", &width))
> -		switch (width) {
> -		case 1:
> -			priv->read_reg = ns16550_read_reg_mmio_8;
> -			priv->write_reg = ns16550_write_reg_mmio_8;
> -			break;
> -		case 2:
> -			priv->read_reg = ns16550_read_reg_mmio_16;
> -			priv->write_reg = ns16550_write_reg_mmio_16;
> -			break;
> -		case 4:
> -			if (of_device_is_big_endian(np)) {
> -				priv->read_reg = ns16550_read_reg_mmio_32be;
> -				priv->write_reg = ns16550_write_reg_mmio_32be;
> -			} else {
> -				priv->read_reg = ns16550_read_reg_mmio_32;
> -				priv->write_reg = ns16550_write_reg_mmio_32;
> -			}
> -			break;
> -		default:
> -			dev_err(dev, "unsupported reg-io-width (%d)\n",
> -				width);
> +	of_property_read_u32(np, "reg-io-width", &width);

i think it is not good to drop error handling completely. We may fail in
different ways:
static const void *of_find_property_value_of_size(const struct
device_node *np,
			const char *propname, u32 len)
{
	struct property *prop = of_find_property(np, propname, NULL);
	const void *value;

	if (!prop)
		return ERR_PTR(-EINVAL);
	value = of_property_get_value(prop);
	if (!value)
		return ERR_PTR(-ENODATA);
	if (len > prop->length)
		return ERR_PTR(-EOVERFLOW);

	return value;
}


> +	switch (width) {
> +	case 1:
> +		priv->read_reg = ns16550_read_reg_mmio_8;
> +		priv->write_reg = ns16550_write_reg_mmio_8;
> +		break;
> +	case 2:
> +		priv->read_reg = ns16550_read_reg_mmio_16;
> +		priv->write_reg = ns16550_write_reg_mmio_16;
> +		break;
> +	case 4:
> +		if (of_device_is_big_endian(np)) {
> +			priv->read_reg = ns16550_read_reg_mmio_32be;
> +			priv->write_reg = ns16550_write_reg_mmio_32be;
> +		} else {
> +			priv->read_reg = ns16550_read_reg_mmio_32;
> +			priv->write_reg = ns16550_write_reg_mmio_32;
>  		}
> +		break;
> +	default:
> +		dev_err(dev, "unsupported reg-io-width (%d)\n",
> +			width);
> +	}
>  }
>  
>  static struct ns16550_drvdata ns16450_drvdata = {
> 


-- 
Regards,
Oleksij


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 4/8] serial_ns16550: handle default reg-io-width
  2018-12-13 15:56   ` Oleksij Rempel
@ 2018-12-14 10:58     ` Sascha Hauer
  0 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2018-12-14 10:58 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox, Rouven Czerwinski

On Thu, Dec 13, 2018 at 04:56:46PM +0100, Oleksij Rempel wrote:
> Am 13.12.18 um 08:44 schrieb Rouven Czerwinski:
> > -	if (!of_property_read_u32(np, "reg-io-width", &width))
> > -		switch (width) {
> > -		case 1:
> > -			priv->read_reg = ns16550_read_reg_mmio_8;
> > -			priv->write_reg = ns16550_write_reg_mmio_8;
> > -			break;
> > -		case 2:
> > -			priv->read_reg = ns16550_read_reg_mmio_16;
> > -			priv->write_reg = ns16550_write_reg_mmio_16;
> > -			break;
> > -		case 4:
> > -			if (of_device_is_big_endian(np)) {
> > -				priv->read_reg = ns16550_read_reg_mmio_32be;
> > -				priv->write_reg = ns16550_write_reg_mmio_32be;
> > -			} else {
> > -				priv->read_reg = ns16550_read_reg_mmio_32;
> > -				priv->write_reg = ns16550_write_reg_mmio_32;
> > -			}
> > -			break;
> > -		default:
> > -			dev_err(dev, "unsupported reg-io-width (%d)\n",
> > -				width);
> > +	of_property_read_u32(np, "reg-io-width", &width);
> 
> i think it is not good to drop error handling completely. We may fail in
> different ways:
> static const void *of_find_property_value_of_size(const struct
> device_node *np,
> 			const char *propname, u32 len)
> {
> 	struct property *prop = of_find_property(np, propname, NULL);
> 	const void *value;
> 
> 	if (!prop)
> 		return ERR_PTR(-EINVAL);
> 	value = of_property_get_value(prop);
> 	if (!value)
> 		return ERR_PTR(-ENODATA);
> 	if (len > prop->length)
> 		return ERR_PTR(-EOVERFLOW);

Although we could differenciate between these different values and
return an error I think initializing a variable with a default and let
of_property_read_* overwrite it without further error checking is common
sense now, you can find hundreds of hits in the Linux Kernel.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-12-14 10:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 2/8] ARM: rpi: move clks into board specific rpi-common Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 3/8] ARM: rpi: retrieve miniuart clock from firmware Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 4/8] serial_ns16550: handle default reg-io-width Rouven Czerwinski
2018-12-13 15:56   ` Oleksij Rempel
2018-12-14 10:58     ` Sascha Hauer
2018-12-13  7:44 ` [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init Rouven Czerwinski
2018-12-13 15:53   ` Oleksij Rempel
2018-12-13  7:44 ` [PATCH v2 6/8] ARM: rpi: add NS16550 support Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 7/8] ARM: rpi: choose miniuart as stdout Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 8/8] doc: bcm283x: remove miniuart overlay instruction Rouven Czerwinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox