Skip to contentSkip to conversation

serial: sh-sci: Add OF support

PATCH Superseded Bastian Hecht 4 participants 14 messages Mar 4, 2013 – Mar 6, 2013

Subsystems (6)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

We add the capabilty to probe Renesas SCI devices using Device Tree setup.

---
v4:
Added missing OF header

 .../bindings/tty/serial/renesas,sci-serial.txt     |   53 ++++++++
 drivers/tty/serial/sh-sci.c                        |  127 +++++++++++++++++++-
 include/linux/serial_sci.h                         |    4 +
 3 files changed, 180 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +53 -0
new file mode 100644
index 0000000..6ad1adf
@@ -0,0 +1,53 @@
+* Renesas SH-Mobile Serial Communication Interface
+
+Required properties:
+- compatible : Should be "renesas,sci-<port type>-uart", where <port type> may be
+  SCI, SCIF, IRDA, SCIFA or SCIFB.
+- reg : Address and length of the register set for the device
+- interrupts : Should contain the following IRQs: ERI, RXI, TXI and BRI.
+- cell-index : The device id.
+- renesas,scscr : Should contain a bitfield used by the Serial Control Register.
+  b7 = SCSCR_TIE
+  b6 = SCSCR_RIE
+  b5 = SCSCR_TE
+  b4 = SCSCR_RE
+  b3 = SCSCR_REIE
+  b2 = SCSCR_TOIE
+  b1 = SCSCR_CKE1
+  b0 = SCSCR_CKE0
+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)
+
+Optional properties:
+- renesas,autoconf : Set if device is capable of auto configuration
+- renesas,regtype : Overwrite the register layout. In most cases you can rely
+  on auto-probing (omit this property or set to 0) but some legacy devices
+  use a non-default register layout. Possible layouts are
+  0 = SCIx_PROBE_REGTYPE (default)
+  1 = SCIx_SCI_REGTYPE
+  2 = SCIx_IRDA_REGTYPE
+  3 = SCIx_SCIFA_REGTYPE
+  4 = SCIx_SCIFB_REGTYPE
+  5 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
+  6 = SCIx_SH3_SCIF_REGTYPE
+  7 = SCIx_SH4_SCIF_REGTYPE
+  8 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
+  9 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
+ 10 = SCIx_SH7705_SCIF_REGTYPE
+
+
+Example:
+	sci@0xe6c50000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c50000 0x100>;
+		interrupts = <0x0c20>, <0x0c20>, <0x0c20>, <0x0c20>;
+		cell-index = <1>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
drivers/tty/serial/sh-sci.c +123 -4

159 lines not on this page · raw message

include/linux/serial_sci.h +4 -0
index eb763ad..857eec4 100644
@@ -11,11 +11,15 @@
 #define SCIx_NOT_SUPPORTED	(-1)
 
 enum {
+	SCBRR_ALGO_INVALID,
+
 	SCBRR_ALGO_1,		/* ((clk + 16 * bps) / (16 * bps) - 1) */
 	SCBRR_ALGO_2,		/* ((clk + 16 * bps) / (32 * bps) - 1) */
 	SCBRR_ALGO_3,		/* (((clk * 2) + 16 * bps) / (16 * bps) - 1) */
 	SCBRR_ALGO_4,		/* (((clk * 2) + 16 * bps) / (32 * bps) - 1) */
 	SCBRR_ALGO_5,		/* (((clk * 1000 / 32) / bps) - 1) */
+
+	SCBRR_NR_ALGOS,
 };
 
 #define SCSCR_TIE	(1 << 7)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 2/3 ARM: mach-shmobile: r8a7740: Add DT names to clock list

This adds temporarily the alternative device names to the clock list that are used when booting via Device Tree setup.

---
v4: no changes

 arch/arm/mach-shmobile/clock-r8a7740.c |    9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/mach-shmobile/clock-r8a7740.c +9 -0
index 71fc400..0f77823 100644
@@ -593,18 +593,27 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_DEV_ID("sh_mobile_ceu.1",	&mstp_clks[MSTP128]),
 
 	CLKDEV_DEV_ID("sh-sci.4",		&mstp_clks[MSTP200]),
+	CLKDEV_DEV_ID("e6c80000.sci",		&mstp_clks[MSTP200]),
 	CLKDEV_DEV_ID("sh-sci.3",		&mstp_clks[MSTP201]),
+	CLKDEV_DEV_ID("e6c70000.sci",		&mstp_clks[MSTP201]),
 	CLKDEV_DEV_ID("sh-sci.2",		&mstp_clks[MSTP202]),
+	CLKDEV_DEV_ID("e6c60000.sci",		&mstp_clks[MSTP202]),
 	CLKDEV_DEV_ID("sh-sci.1",		&mstp_clks[MSTP203]),
+	CLKDEV_DEV_ID("e6c50000.sci",		&mstp_clks[MSTP203]),
 	CLKDEV_DEV_ID("sh-sci.0",		&mstp_clks[MSTP204]),
+	CLKDEV_DEV_ID("e6c40000.sci",		&mstp_clks[MSTP204]),
 	CLKDEV_DEV_ID("sh-sci.8",		&mstp_clks[MSTP206]),
+	CLKDEV_DEV_ID("e6c30000.sci",		&mstp_clks[MSTP206]),
 	CLKDEV_DEV_ID("sh-sci.5",		&mstp_clks[MSTP207]),
+	CLKDEV_DEV_ID("e6cb0000.sci",		&mstp_clks[MSTP207]),
 	CLKDEV_DEV_ID("sh-dma-engine.3",	&mstp_clks[MSTP214]),
 	CLKDEV_DEV_ID("sh-dma-engine.2",	&mstp_clks[MSTP216]),
 	CLKDEV_DEV_ID("sh-dma-engine.1",	&mstp_clks[MSTP217]),
 	CLKDEV_DEV_ID("sh-dma-engine.0",	&mstp_clks[MSTP218]),
 	CLKDEV_DEV_ID("sh-sci.7",		&mstp_clks[MSTP222]),
+	CLKDEV_DEV_ID("e6cd0000.sci",		&mstp_clks[MSTP222]),
 	CLKDEV_DEV_ID("sh-sci.6",		&mstp_clks[MSTP230]),
+	CLKDEV_DEV_ID("e6cc0000.sci",		&mstp_clks[MSTP230]),
 
 	CLKDEV_DEV_ID("sh_cmt.10",		&mstp_clks[MSTP329]),
 	CLKDEV_DEV_ID("sh_fsi2",		&mstp_clks[MSTP328]),
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

In reply to Bastian Hecht

We can now use the Device Tree for bringing up our serial devices on the SoC r8a7740.

We remove the power domain association. We will move the info into the DT setup as soon as we have support for it. For now this is fine as we use the power domain governor "pm_domain_always_on_gov" for A3SP.

---
v4:
We don't move the DT into the r8a7740-armadillo800eva-reference.dts, but r8a7740.dtsi as the serial device setups are not dependent on any board confguration.

Renamed sci@0xe6c40000 to sci@e6c40000

 arch/arm/boot/dts/r8a7740.dtsi         |   99 ++++++++++++++++++
 arch/arm/mach-shmobile/setup-r8a7740.c |  180 --------------------------------
 2 files changed, 99 insertions(+), 180 deletions(-)
arch/arm/boot/dts/r8a7740.dtsi +99 -0
index 82faf52..ecbc237 100644
@@ -767,4 +767,103 @@
 		gpio-controller;
 		#gpio-cells = <2>;
 	};
+
+	sci@e6c40000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c40000 0x100>;
+		interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+		cell-index = <0>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6c50000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c50000 0x100>;
+		interrupts = <0x0c20>, <0x0c20>, <0x0c20>, <0x0c20>;
+		cell-index = <1>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6c60000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c60000 0x100>;
+		interrupts = <0x0c40>, <0x0c40>, <0x0c40>, <0x0c40>;
+		cell-index = <2>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6c70000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c70000 0x100>;
+		interrupts = <0x0c60>, <0x0c60>, <0x0c60>, <0x0c60>;
+		cell-index = <3>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6c80000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c80000 0x100>;
+		interrupts = <0x0d20>, <0x0d20>, <0x0d20>, <0x0d20>;
+		cell-index = <4>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6cb0000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6cb0000 0x100>;
+		interrupts = <0x0d40>, <0x0d40>, <0x0d40>, <0x0d40>;
+		cell-index = <5>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6cc0000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6cc0000 0x100>;
+		interrupts = <0x04c0>, <0x04c0>, <0x04c0>, <0x04c0>;
+		cell-index = <6>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@0xe6cd0000 {
+		compatible = "renesas,sci-SCIFA-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6cd0000 0x100>;
+		interrupts = <0x04e0>, <0x04e0>, <0x04e0>, <0x04e0>;
+		cell-index = <7>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
+
+	sci@e6c30000 {
+		compatible = "renesas,sci-SCIFB-uart";
+		interrupt-parent = <&intca>;
+		reg = <0xe6c30000 0x100>;
+		interrupts = <0x0d60>, <0x0d60>, <0x0d60>, <0x0d60>;
+		cell-index = <8>;
+		renesas,scscr = <0x30>;
+		renesas,scbrr-algo-id = <4>;
+		renesas,autoconf;
+	};
 };
arch/arm/mach-shmobile/setup-r8a7740.c +0 -180

198 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

arch/arm/boot/dts/r8a7740.dtsi line 780

Quoted 11 lines · On Monday 04 March 2013 17:20:54 Bastian Hecht wrote:
arch/arm/boot/dts/r8a7740.dtsi +10 -0
+       sci at e6c40000 {
+               compatible = "renesas,sci-SCIFA-uart";
+               interrupt-parent = <&intca>;
+               reg = <0xe6c40000 0x100>;
+               interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+               cell-index = <0>;
+               renesas,scscr = <0x30>;
+               renesas,scbrr-algo-id = <4>;
+               renesas,autoconf;
+       };

The default name for a uart is "serial", I would recommend sticking to that by convention. You may also want to add an "aliases" node somewhere, to define which port should get which logical device number on a given board.

Arnd

#4 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

Hi Arnd,

2013/3/4 Arnd Bergmann <[email protected]>:

Quoted 13 lines · On Monday 04 March 2013 17:20:54 Bastian Hecht wrote:

arch/arm/boot/dts/r8a7740.dtsi line 780

Quoted 11 lines
arch/arm/boot/dts/r8a7740.dtsi +10 -0
+       sci at e6c40000 {
+               compatible = "renesas,sci-SCIFA-uart";
+               interrupt-parent = <&intca>;
+               reg = <0xe6c40000 0x100>;
+               interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+               cell-index = <0>;
+               renesas,scscr = <0x30>;
+               renesas,scbrr-algo-id = <4>;
+               renesas,autoconf;
+       };
Quoted 4 lines

The default name for a uart is "serial", I would recommend sticking to that by convention. You may also want to add an "aliases" node somewhere, to define which port should get which logical device number on a given board.

Switched to "...-serial".
About the aliases: Would I need to add that now, or can we postpone that?

Thanks,

Bastian

Quoted 1 line

Arnd

#5 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

Hello.

Quoted 11 lines · Bastian Hecht
Quoted 11 lines
Quoted 10 lines
arch/arm/boot/dts/r8a7740.dtsi +10 -0
+       sci at e6c40000 {
+               compatible = "renesas,sci-SCIFA-uart";
+               interrupt-parent = <&intca>;
+               reg = <0xe6c40000 0x100>;
+               interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+               cell-index = <0>;
+               renesas,scscr = <0x30>;
+               renesas,scbrr-algo-id = <4>;
+               renesas,autoconf;
+       };
Quoted 6 lines
Quoted 4 lines

The default name for a uart is "serial", I would recommend sticking to that by convention. You may also want to add an "aliases" node somewhere, to define which port should get which logical device number on a given board.

Switched to "...-serial".

I think he was talking about the node name, not "compatible" property.

WBR, Sergei

#6 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

2013/3/5 Sergei Shtylyov <[email protected]>:

Quoted 23 lines

Hello.

Quoted 16 lines · Bastian Hecht
Quoted 16 lines

arch/arm/boot/dts/r8a7740.dtsi line 780

Quoted 10 lines
arch/arm/boot/dts/r8a7740.dtsi +10 -0
+       sci at e6c40000 {
+               compatible = "renesas,sci-SCIFA-uart";
+               interrupt-parent = <&intca>;
+               reg = <0xe6c40000 0x100>;
+               interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+               cell-index = <0>;
+               renesas,scscr = <0x30>;
+               renesas,scbrr-algo-id = <4>;
+               renesas,autoconf;
+       };

The default name for a uart is "serial", I would recommend sticking to that by convention. You may also want to add an "aliases" node somewhere, to define which port should get which logical device number on a given board.

Quoted 4 lines
Quoted 1 line

Switched to "...-serial".

I think he was talking about the node name, not "compatible" property.

Ah sure! I'll wait for responses to v5 and will change it around in v6.

Thanks,

Bastian

Quoted 2 lines

WBR, Sergei

#7 lore raw

PATCH v4 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT

In reply to Bastian Hecht
Quoted 14 lines · Bastian Hecht

2013/3/4 Arnd Bergmann <[email protected]>:

Quoted 13 lines · On Monday 04 March 2013 17:20:54 Bastian Hecht wrote:
Quoted 11 lines
arch/arm/boot/dts/r8a7740.dtsi +10 -0
+       sci at e6c40000 {
+               compatible = "renesas,sci-SCIFA-uart";
+               interrupt-parent = <&intca>;
+               reg = <0xe6c40000 0x100>;
+               interrupts = <0x0c00>, <0x0c00>, <0x0c00>, <0x0c00>;
+               cell-index = <0>;
+               renesas,scscr = <0x30>;
+               renesas,scbrr-algo-id = <4>;
+               renesas,autoconf;
+       };
Quoted 6 lines
Quoted 4 lines

The default name for a uart is "serial", I would recommend sticking to that by convention. You may also want to add an "aliases" node somewhere, to define which port should get which logical device number on a given board.

Switched to "...-serial".

I actually meant the name, not the "compatible" value. For compatible, either version is fine with me. What I think you should change though is renaming "sci at e6c40000" to "serial at e6c40000".

Quoted 2 lines

About the aliases: Would I need to add that now, or can we postpone that?

No hurry for that. It's just a feature that comes in very handy, but not all platforms implement it.

Arnd

#8 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

In reply to Bastian Hecht

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 5

Quoted 11 lines · On Monday 04 March 2013 17:20:52 Bastian Hecht wrote:
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +5 -0
new file mode 100644
index 0000000..6ad1adf
@@ -0,0 +1,53 @@
+* Renesas SH-Mobile Serial Communication Interface
+
+Required properties:
+- compatible : Should be "renesas,sci-<port type>-uart", where <port type> may be
+  SCI, SCIF, IRDA, SCIFA or SCIFB.

Why capital letters here? Maybe just list

	"renesas,sci-uart", "renesas,scif-uart", ...

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 7

Quoted 2 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +2 -0
+- reg : Address and length of the register set for the device
+- interrupts : Should contain the following IRQs: ERI, RXI, TXI and BRI.

You probably want to require the "interrupt-names" property as well then.

Quoted 6 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +6 -0
+- cell-index : The device id.
+- renesas,scscr : Should contain a bitfield used by the Serial Control Register.
+  b7 = SCSCR_TIE
+  b6 = SCSCR_RIE
+  b5 = SCSCR_TE
+  b4 = SCSCR_RE

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+  b3 = SCSCR_REIE
+  b2 = SCSCR_TOIE
+  b1 = SCSCR_CKE1
+  b0 = SCSCR_CKE0
+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)

Maybe replace this with a "clock-frequency" property? This may be what the registers contain, but it is not very readable.

Quoted 6 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +6 -0
+Optional properties:
+- renesas,autoconf : Set if device is capable of auto configuration
+- renesas,regtype : Overwrite the register layout. In most cases you can rely
+  on auto-probing (omit this property or set to 0) but some legacy devices
+  use a non-default register layout. Possible layouts are
+  0 = SCIx_PROBE_REGTYPE (default)

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 40

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+  1 = SCIx_SCI_REGTYPE
+  2 = SCIx_IRDA_REGTYPE
+  3 = SCIx_SCIFA_REGTYPE
+  4 = SCIx_SCIFB_REGTYPE
+  5 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
+  6 = SCIx_SH3_SCIF_REGTYPE
+  7 = SCIx_SH4_SCIF_REGTYPE
+  8 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
+  9 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
+ 10 = SCIx_SH7705_SCIF_REGTYPE

Why do you keep these separate from the "compatible" property? By definition, the register layout is already determined by "compatible".

Quoted 16 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +16 -0
+#ifdef CONFIG_OF
+static const struct of_device_id of_sci_match[] = {
+	{ .compatible = "renesas,sci-SCI-uart",
+		.data = (void *)PORT_SCI },
+	{ .compatible = "renesas,sci-SCIF-uart",
+		.data = (void *)PORT_SCIF },
+	{ .compatible = "renesas,sci-IRDA-uart",
+		.data = (void *)PORT_IRDA },
+	{ .compatible = "renesas,sci-SCIFA-uart",
+		.data = (void *)PORT_SCIFA },
+	{ .compatible = "renesas,sci-SCIFB-uart",
+		.data = (void *)PORT_SCIFB },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_sci_match);
+

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
+								int *dev_id)
+{
+	struct plat_sci_port *p;
+	struct device_node *np = pdev->dev.of_node;
+	const struct of_device_id *match;
+	struct resource *res;
+	const __be32 *prop;
+	int i, irq, val;
+

You can remove the #ifdef by replacing it with

	if (!IS_ENABLED(CONFIG_OF) || !np)
		return NULL;

here. This gives better compile time coverage and more readable code.

Otherwise looks very nice!

Arnd

#9 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

Hi Arnd,

thanks for having a look at it.

2013/3/4 Arnd Bergmann <[email protected]>:

Quoted 15 lines · On Monday 04 March 2013 17:20:52 Bastian Hecht wrote:

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 5

Quoted 11 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +5 -0
new file mode 100644
index 0000000..6ad1adf
@@ -0,0 +1,53 @@
+* Renesas SH-Mobile Serial Communication Interface
+
+Required properties:
+- compatible : Should be "renesas,sci-<port type>-uart", where <port type> may be
+  SCI, SCIF, IRDA, SCIFA or SCIFB.

Why capital letters here? Maybe just list

Quoted 1 line
        "renesas,sci-uart", "renesas,scif-uart", ...

Yes - changed.

Quoted 5 lines

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 7

Quoted 2 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +2 -0
+- reg : Address and length of the register set for the device
+- interrupts : Should contain the following IRQs: ERI, RXI, TXI and BRI.

You probably want to require the "interrupt-names" property as well then.

I added the interrupt-names property but still enforce the ordering in the binding specs.
Don't know if we want the extra overhead to scan for strings or just take a certain order for granted.
If we want to change it to parsing, it would be better to switch completely to platform_get_irq_byname() and change all the current platform code, else we will produce code overhead.

Quoted 17 lines
Quoted 6 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +6 -0
+- cell-index : The device id.
+- renesas,scscr : Should contain a bitfield used by the Serial Control Register.
+  b7 = SCSCR_TIE
+  b6 = SCSCR_RIE
+  b5 = SCSCR_TE
+  b4 = SCSCR_RE

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+  b3 = SCSCR_REIE
+  b2 = SCSCR_TOIE
+  b1 = SCSCR_CKE1
+  b0 = SCSCR_CKE0
+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)
Quoted 2 lines

Maybe replace this with a "clock-frequency" property? This may be what the registers contain, but it is not very readable.

Hmm... do you want a frequency in absolute terms? And then calculate the best SCBRR value for it?
I'm unsure about this, either you must exactly hit it or accept tolerances? As something in between I renamed the property to "renesas,clock-algorithm", but I don't know if this is what you want.

Quoted 17 lines
Quoted 6 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +6 -0
+Optional properties:
+- renesas,autoconf : Set if device is capable of auto configuration
+- renesas,regtype : Overwrite the register layout. In most cases you can rely
+  on auto-probing (omit this property or set to 0) but some legacy devices
+  use a non-default register layout. Possible layouts are
+  0 = SCIx_PROBE_REGTYPE (default)

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 40

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+  1 = SCIx_SCI_REGTYPE
+  2 = SCIx_IRDA_REGTYPE
+  3 = SCIx_SCIFA_REGTYPE
+  4 = SCIx_SCIFB_REGTYPE
+  5 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
+  6 = SCIx_SH3_SCIF_REGTYPE
+  7 = SCIx_SH4_SCIF_REGTYPE
+  8 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
+  9 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
+ 10 = SCIx_SH7705_SCIF_REGTYPE
Quoted 3 lines

Why do you keep these separate from the "compatible" property? By definition, the register layout is already determined by "compatible".

Ok, I've melted the register type and port type (defined in include/uapi/linux/serial_core.h) definition into the compatible property. Looks good!

Quoted 29 lines
Quoted 16 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +16 -0
+#ifdef CONFIG_OF
+static const struct of_device_id of_sci_match[] = {
+     { .compatible = "renesas,sci-SCI-uart",
+             .data = (void *)PORT_SCI },
+     { .compatible = "renesas,sci-SCIF-uart",
+             .data = (void *)PORT_SCIF },
+     { .compatible = "renesas,sci-IRDA-uart",
+             .data = (void *)PORT_IRDA },
+     { .compatible = "renesas,sci-SCIFA-uart",
+             .data = (void *)PORT_SCIFA },
+     { .compatible = "renesas,sci-SCIFB-uart",
+             .data = (void *)PORT_SCIFB },
+     {},
+};
+MODULE_DEVICE_TABLE(of, of_sci_match);
+

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt

Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +10 -0
+static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
+                                                             int *dev_id)
+{
+     struct plat_sci_port *p;
+     struct device_node *np = pdev->dev.of_node;
+     const struct of_device_id *match;
+     struct resource *res;
+     const __be32 *prop;
+     int i, irq, val;
+

You can remove the #ifdef by replacing it with

Quoted 4 lines
        if (!IS_ENABLED(CONFIG_OF) || !np)
                return NULL;

here. This gives better compile time coverage and more readable code.

Alright, done!

Quoted 1 line

Otherwise looks very nice!

Cheers!

Bastian

Quoted 1 line

Arnd

#10 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

Quoted 10 lines · Bastian Hecht

2013/3/4 Arnd Bergmann <[email protected]>:

Quoted 6 lines · On Monday 04 March 2013 17:20:52 Bastian Hecht wrote:
Quoted 2 lines
+- reg : Address and length of the register set for the device
+- interrupts : Should contain the following IRQs: ERI, RXI, TXI and BRI.

You probably want to require the "interrupt-names" property as well then.

I added the interrupt-names property but still enforce the ordering in the binding specs.

Yes, that is the correct approach.

Quoted 5 lines

Don't know if we want the extra overhead to scan for strings or just take a certain order for granted.
If we want to change it to parsing, it would be better to switch completely to platform_get_irq_byname() and change all the current platform code, else we will produce code overhead.

Right, there is no need to change the code for that, but I think it makes sense to do the binding the way you describe, in case someone later wants to move to platform_get_irq_byname. A lot of people prefer that for some reason, although I think the traditional numbering is just as good.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +5 -0
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)
Quoted 8 lines
Quoted 2 lines

Maybe replace this with a "clock-frequency" property? This may be what the registers contain, but it is not very readable.

Hmm... do you want a frequency in absolute terms? And then calculate the best SCBRR value for it?
I'm unsure about this, either you must exactly hit it or accept tolerances? As something in between I renamed the property to "renesas,clock-algorithm", but I don't know if this is what you want.

I meant the absolute frequency in HZ, since that is what we do for the 8250 uart and other devices, but only if that is sufficient for your device.

Arnd

#11 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

Quoted 17 lines · Arnd Bergmann
Quoted 7 lines · Bastian Hecht
Quoted 7 lines
Quoted 6 lines

+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +5 -0
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)
Quoted 8 lines
Quoted 2 lines

Maybe replace this with a "clock-frequency" property? This may be what the registers contain, but it is not very readable.

Hmm... do you want a frequency in absolute terms? And then calculate the best SCBRR value for it?
I'm unsure about this, either you must exactly hit it or accept tolerances? As something in between I renamed the property to "renesas,clock-algorithm", but I don't know if this is what you want.

Quoted 4 lines

I meant the absolute frequency in HZ, since that is what we do for the 8250 uart and other devices, but only if that is sufficient for your device.

No, we still need to figure out how to generate that baud rate, whether it needs an internal or external clock for driving the rate, etc. The frequency in and of itself doesn't provide this information, and various parts use different algorithms for factoring the baud rate generator, even varying across otherwise identical ports. It's unfortunately not possible to infer anything about the SCBRR algorithm from port type or specified baud rate.

The algorithm IDs here are wholly arbitrary anyways, but are the variations I came up with from roughly 60-70 different CPUs.

#12 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

Hi all,

2013/3/6 Paul Mundt <[email protected]>:

Quoted 30 lines · Arnd Bergmann
Quoted 17 lines · Bastian Hecht
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

+- renesas,scbrr-algo-id : Algorithm ID for the Bit Rate Register

Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +5 -0
+  1 = SCBRR_ALGO_1 ((clk + 16 * bps) / (16 * bps) - 1)
+  2 = SCBRR_ALGO_2 ((clk + 16 * bps) / (32 * bps) - 1)
+  3 = SCBRR_ALGO_3 (((clk * 2) + 16 * bps) / (16 * bps) - 1)
+  4 = SCBRR_ALGO_4 (((clk * 2) + 16 * bps) / (32 * bps) - 1)
+  5 = SCBRR_ALGO_5 (((clk * 1000 / 32) / bps) - 1)
Quoted 8 lines
Quoted 2 lines

Maybe replace this with a "clock-frequency" property? This may be what the registers contain, but it is not very readable.

Hmm... do you want a frequency in absolute terms? And then calculate the best SCBRR value for it?
I'm unsure about this, either you must exactly hit it or accept tolerances? As something in between I renamed the property to "renesas,clock-algorithm", but I don't know if this is what you want.

Quoted 4 lines

I meant the absolute frequency in HZ, since that is what we do for the 8250 uart and other devices, but only if that is sufficient for your device.

No, we still need to figure out how to generate that baud rate, whether it needs an internal or external clock for driving the rate, etc. The frequency in and of itself doesn't provide this information, and various parts use different algorithms for factoring the baud rate generator, even varying across otherwise identical ports. It's unfortunately not possible to infer anything about the SCBRR algorithm from port type or specified baud rate.

Quoted 2 lines

The algorithm IDs here are wholly arbitrary anyways, but are the variations I came up with from roughly 60-70 different CPUs.

So if we stick with the notion of the algrithm ID everything is settled now.

I will prepare a v6 that I will post as the whole patchset and an additional incremental patch 1/3 from v3 to v6 for Paul's repo. Then we can see if the SCBRR thing needs further discussion and if the rest of the patchset is final.

Thanks to you all,

Bastian

#13 lore raw

PATCH v4 1/3 serial: sh-sci: Add OF support

Quoted 11 lines · Bastian Hecht

2013/3/6 Paul Mundt <[email protected]>:

Quoted 10 lines

No, we still need to figure out how to generate that baud rate, whether it needs an internal or external clock for driving the rate, etc. The frequency in and of itself doesn't provide this information, and various parts use different algorithms for factoring the baud rate generator, even varying across otherwise identical ports. It's unfortunately not possible to infer anything about the SCBRR algorithm from port type or specified baud rate.

The algorithm IDs here are wholly arbitrary anyways, but are the variations I came up with from roughly 60-70 different CPUs.

Ok, I see.

Quoted 6 lines

So if we stick with the notion of the algrithm ID everything is settled now.

I will prepare a v6 that I will post as the whole patchset and an additional incremental patch 1/3 from v3 to v6 for Paul's repo. Then we can see if the SCBRR thing needs further discussion and if the rest of the patchset is final.

I can't think of anything better either, so let's stick to putting the algorithm ID into the DT binding.

Arnd