All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] serial: sh-sci: Add OF support
@ 2013-02-25 19:06 ` Bastian Hecht
  0 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 18:07 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

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

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.

changelog v2:
 - Renamed title to "Add OF support"
 - Removed fixed configurations from driver and added the following binding props:
	- renesas,scscr
	- renesas,scbrr-algo-id
	- renesas,autoconf
	- renesas,regtype
	See patch for descriptions

 .../bindings/tty/serial/renesas,sci-serial.txt     |   47 +++++++
 drivers/tty/serial/sh-sci.c                        |  131 +++++++++++++++++++-
 2 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt

diff --git a/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt
new file mode 100644
index 0000000..f9163a3
--- /dev/null
+++ b/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt
@@ -0,0 +1,47 @@
+* 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. Some legacy hardware versions
+  use a non-default register layout. Possible layouts are
+  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
+  1 = SCIx_SH3_SCIF_REGTYPE
+  2 = SCIx_SH4_SCIF_REGTYPE
+  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
+  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
+  5 = 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;
+	};
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 6147756..d183f3a 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2353,6 +2353,117 @@ static int sci_remove(struct platform_device *dev)
 	return 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);
+
+/* This array belongs to the DT binding definition "renesas,regtype" */
+static const char sci_regtype_modes[] = {
+	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
+	SCIx_SH3_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
+	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
+	SCIx_SH7705_SCIF_REGTYPE
+};
+
+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;
+
+	match = of_match_node(of_sci_match, pdev->dev.of_node);
+	if (!match || !match->data) {
+		dev_err(&pdev->dev, "OF match error\n");
+		return NULL;
+	}
+
+	p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
+	if (!p) {
+		dev_err(&pdev->dev, "failed to allocate DT config data\n");
+		return NULL;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "failed to get I/O memory\n");
+		return NULL;
+	}
+	p->mapbase = res->start;
+
+	for (i = 0; i < SCIx_NR_IRQS; i++) {
+		irq = platform_get_irq(pdev, i);
+		if (irq < 0) {
+			dev_err(&pdev->dev, "failed to get irq data %d\n", i);
+			return NULL;
+		}
+		p->irqs[i] = irq;
+	}
+
+	prop = of_get_property(np, "cell-index", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop cell-index missing\n");
+		return NULL;
+	}
+	*dev_id = be32_to_cpup(prop);
+
+	prop = of_get_property(np, "renesas,scscr", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop scscr missing\n");
+		return NULL;
+	}
+	p->scscr = be32_to_cpup(prop);
+
+	prop = of_get_property(np, "renesas,scbrr-algo-id", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop scbrr-algo-id missing\n");
+		return NULL;
+	}
+	p->scbrr_algo_id = be32_to_cpup(prop) - 1;
+
+	p->flags = UPF_IOREMAP;
+	if (of_get_property(np, "renesas,autoconf", NULL))
+		p->flags |= UPF_BOOT_AUTOCONF;
+
+	prop = of_get_property(np, "renesas,regtype", NULL);
+	if (prop) {
+		val = be32_to_cpup(prop);
+		if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
+			dev_err(&pdev->dev, "invalid DT prop regtype\n");
+			return NULL;
+		}
+		p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
+	}
+
+	p->type = (unsigned int)match->data;
+
+	return p;
+}
+#else
+static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
+								int *dev_id)
+{
+	return NULL;
+}
+#endif /* CONFIG_OF */
+
 static int sci_probe_single(struct platform_device *dev,
 				      unsigned int index,
 				      struct plat_sci_port *p,
@@ -2385,9 +2496,9 @@ static int sci_probe_single(struct platform_device *dev,
 
 static int sci_probe(struct platform_device *dev)
 {
-	struct plat_sci_port *p = dev->dev.platform_data;
-	struct sci_port *sp = &sci_ports[dev->id];
-	int ret;
+	struct plat_sci_port *p;
+	struct sci_port *sp;
+	int ret, dev_id = dev->id;
 
 	/*
 	 * If we've come here via earlyprintk initialization, head off to
@@ -2397,9 +2508,20 @@ static int sci_probe(struct platform_device *dev)
 	if (is_early_platform_device(dev))
 		return sci_probe_earlyprintk(dev);
 
+	if (dev->dev.of_node)
+		p = sci_parse_dt(dev, &dev_id);
+	else
+		p = dev->dev.platform_data;
+
+	if (!p) {
+		dev_err(&dev->dev, "no setup data supplied\n");
+		return -EINVAL;
+	}
+
+	sp = &sci_ports[dev_id];
 	platform_set_drvdata(dev, sp);
 
-	ret = sci_probe_single(dev, dev->id, p, sp);
+	ret = sci_probe_single(dev, dev_id, p, sp);
 	if (ret)
 		return ret;
 
@@ -2451,6 +2573,7 @@ static struct platform_driver sci_driver = {
 		.name	= "sh-sci",
 		.owner	= THIS_MODULE,
 		.pm	= &sci_dev_pm_ops,
+		.of_match_table = of_match_ptr(of_sci_match),
 	},
 };
 
-- 
1.7.9.5


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

* [PATCH v2 3/3] ARM: mach-shmobile: r8a7740: Setup the serial devices using DT
  2013-02-25 19:06 ` Bastian Hecht
@ 2013-02-25 19:06   ` Bastian Hecht
  -1 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 18:07 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

We can now use the Device Tree for bringing up our serial devices. We
need to add an alternative early_devices list in setup-r8a7740 without
the serial devices and move them into the Armadillo-reference .dts config file.

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
v2:
 - adjusted compatible lines
 - used new properties

 .../boot/dts/r8a7740-armadillo800eva-reference.dts |   94 ++++++++++++++++++++
 arch/arm/mach-shmobile/setup-r8a7740.c             |   15 +++-
 2 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts b/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
index 1e339cd..52645b6 100644
--- a/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
+++ b/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
@@ -134,6 +134,100 @@
 		renesas,pins = "eth_base";
 		renesas,function = "eth";
 	};
+
+	sci@0xe6c40000 {
+		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@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;
+	};
+
+	sci@0xe6c60000 {
+		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@0xe6c70000 {
+		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@0xe6c80000 {
+		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@0xe6cb0000 {
+		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@0xe6cc0000 {
+		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@0xe6c30000 {
+		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;
+	};
 };
 
 &gpio {
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index 5312aad..5f7597a 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -394,6 +394,13 @@ static struct platform_device *r8a7740_early_devices[] __initdata = {
 	&tmu02_device,
 };
 
+static struct platform_device *r8a7740_early_devices_dt[] __initdata = {
+	&cmt10_device,
+	&tmu00_device,
+	&tmu01_device,
+	&tmu02_device,
+};
+
 /* DMA */
 static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
 	{
@@ -839,8 +846,8 @@ void __init r8a7740_add_early_devices_dt(void)
 {
 	shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
 
-	early_platform_add_devices(r8a7740_early_devices,
-				   ARRAY_SIZE(r8a7740_early_devices));
+	early_platform_add_devices(r8a7740_early_devices_dt,
+				   ARRAY_SIZE(r8a7740_early_devices_dt));
 
 	/* setup early console here as well */
 	shmobile_setup_console();
@@ -852,8 +859,8 @@ static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
 
 void __init r8a7740_add_standard_devices_dt(void)
 {
-	platform_add_devices(r8a7740_early_devices,
-			    ARRAY_SIZE(r8a7740_early_devices));
+	platform_add_devices(r8a7740_early_devices_dt,
+			    ARRAY_SIZE(r8a7740_early_devices_dt));
 
 	of_platform_populate(NULL, of_default_bus_match_table,
 			     r8a7740_auxdata_lookup, NULL);
-- 
1.7.9.5


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

* [PATCH v2 2/3] ARM: mach-shmobile: r8a7740: Add DT names to clock list
  2013-02-25 19:06 ` Bastian Hecht
@ 2013-02-25 19:06   ` Bastian Hecht
  -1 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 18:13 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

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

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
v2: no changes

 arch/arm/mach-shmobile/clock-r8a7740.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7740.c b/arch/arm/mach-shmobile/clock-r8a7740.c
index 71fc400..0f77823 100644
--- a/arch/arm/mach-shmobile/clock-r8a7740.c
+++ b/arch/arm/mach-shmobile/clock-r8a7740.c
@@ -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]),
-- 
1.7.9.5


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

* [PATCH v2 1/3] serial: sh-sci: Add OF support
@ 2013-02-25 19:06 ` Bastian Hecht
  0 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 19:06 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

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

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.

changelog v2:
 - Renamed title to "Add OF support"
 - Removed fixed configurations from driver and added the following binding props:
	- renesas,scscr
	- renesas,scbrr-algo-id
	- renesas,autoconf
	- renesas,regtype
	See patch for descriptions

 .../bindings/tty/serial/renesas,sci-serial.txt     |   47 +++++++
 drivers/tty/serial/sh-sci.c                        |  131 +++++++++++++++++++-
 2 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt

diff --git a/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt
new file mode 100644
index 0000000..f9163a3
--- /dev/null
+++ b/Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt
@@ -0,0 +1,47 @@
+* 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. Some legacy hardware versions
+  use a non-default register layout. Possible layouts are
+  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
+  1 = SCIx_SH3_SCIF_REGTYPE
+  2 = SCIx_SH4_SCIF_REGTYPE
+  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
+  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
+  5 = 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;
+	};
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 6147756..d183f3a 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2353,6 +2353,117 @@ static int sci_remove(struct platform_device *dev)
 	return 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);
+
+/* This array belongs to the DT binding definition "renesas,regtype" */
+static const char sci_regtype_modes[] = {
+	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
+	SCIx_SH3_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
+	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
+	SCIx_SH7705_SCIF_REGTYPE
+};
+
+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;
+
+	match = of_match_node(of_sci_match, pdev->dev.of_node);
+	if (!match || !match->data) {
+		dev_err(&pdev->dev, "OF match error\n");
+		return NULL;
+	}
+
+	p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
+	if (!p) {
+		dev_err(&pdev->dev, "failed to allocate DT config data\n");
+		return NULL;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "failed to get I/O memory\n");
+		return NULL;
+	}
+	p->mapbase = res->start;
+
+	for (i = 0; i < SCIx_NR_IRQS; i++) {
+		irq = platform_get_irq(pdev, i);
+		if (irq < 0) {
+			dev_err(&pdev->dev, "failed to get irq data %d\n", i);
+			return NULL;
+		}
+		p->irqs[i] = irq;
+	}
+
+	prop = of_get_property(np, "cell-index", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop cell-index missing\n");
+		return NULL;
+	}
+	*dev_id = be32_to_cpup(prop);
+
+	prop = of_get_property(np, "renesas,scscr", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop scscr missing\n");
+		return NULL;
+	}
+	p->scscr = be32_to_cpup(prop);
+
+	prop = of_get_property(np, "renesas,scbrr-algo-id", NULL);
+	if (!prop) {
+		dev_err(&pdev->dev, "required DT prop scbrr-algo-id missing\n");
+		return NULL;
+	}
+	p->scbrr_algo_id = be32_to_cpup(prop) - 1;
+
+	p->flags = UPF_IOREMAP;
+	if (of_get_property(np, "renesas,autoconf", NULL))
+		p->flags |= UPF_BOOT_AUTOCONF;
+
+	prop = of_get_property(np, "renesas,regtype", NULL);
+	if (prop) {
+		val = be32_to_cpup(prop);
+		if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
+			dev_err(&pdev->dev, "invalid DT prop regtype\n");
+			return NULL;
+		}
+		p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
+	}
+
+	p->type = (unsigned int)match->data;
+
+	return p;
+}
+#else
+static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
+								int *dev_id)
+{
+	return NULL;
+}
+#endif /* CONFIG_OF */
+
 static int sci_probe_single(struct platform_device *dev,
 				      unsigned int index,
 				      struct plat_sci_port *p,
@@ -2385,9 +2496,9 @@ static int sci_probe_single(struct platform_device *dev,
 
 static int sci_probe(struct platform_device *dev)
 {
-	struct plat_sci_port *p = dev->dev.platform_data;
-	struct sci_port *sp = &sci_ports[dev->id];
-	int ret;
+	struct plat_sci_port *p;
+	struct sci_port *sp;
+	int ret, dev_id = dev->id;
 
 	/*
 	 * If we've come here via earlyprintk initialization, head off to
@@ -2397,9 +2508,20 @@ static int sci_probe(struct platform_device *dev)
 	if (is_early_platform_device(dev))
 		return sci_probe_earlyprintk(dev);
 
+	if (dev->dev.of_node)
+		p = sci_parse_dt(dev, &dev_id);
+	else
+		p = dev->dev.platform_data;
+
+	if (!p) {
+		dev_err(&dev->dev, "no setup data supplied\n");
+		return -EINVAL;
+	}
+
+	sp = &sci_ports[dev_id];
 	platform_set_drvdata(dev, sp);
 
-	ret = sci_probe_single(dev, dev->id, p, sp);
+	ret = sci_probe_single(dev, dev_id, p, sp);
 	if (ret)
 		return ret;
 
@@ -2451,6 +2573,7 @@ static struct platform_driver sci_driver = {
 		.name	= "sh-sci",
 		.owner	= THIS_MODULE,
 		.pm	= &sci_dev_pm_ops,
+		.of_match_table = of_match_ptr(of_sci_match),
 	},
 };
 
-- 
1.7.9.5


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

* [PATCH v2 2/3] ARM: mach-shmobile: r8a7740: Add DT names to clock list
@ 2013-02-25 19:06   ` Bastian Hecht
  0 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 19:06 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

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

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
v2: no changes

 arch/arm/mach-shmobile/clock-r8a7740.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7740.c b/arch/arm/mach-shmobile/clock-r8a7740.c
index 71fc400..0f77823 100644
--- a/arch/arm/mach-shmobile/clock-r8a7740.c
+++ b/arch/arm/mach-shmobile/clock-r8a7740.c
@@ -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]),
-- 
1.7.9.5


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

* [PATCH v2 3/3] ARM: mach-shmobile: r8a7740: Setup the serial devices using DT
@ 2013-02-25 19:06   ` Bastian Hecht
  0 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-25 19:06 UTC (permalink / raw)
  To: linux-sh; +Cc: Magnus Damm, Paul Mundt, linux-serial

We can now use the Device Tree for bringing up our serial devices. We
need to add an alternative early_devices list in setup-r8a7740 without
the serial devices and move them into the Armadillo-reference .dts config file.

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
---
v2:
 - adjusted compatible lines
 - used new properties

 .../boot/dts/r8a7740-armadillo800eva-reference.dts |   94 ++++++++++++++++++++
 arch/arm/mach-shmobile/setup-r8a7740.c             |   15 +++-
 2 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts b/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
index 1e339cd..52645b6 100644
--- a/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
+++ b/arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts
@@ -134,6 +134,100 @@
 		renesas,pins = "eth_base";
 		renesas,function = "eth";
 	};
+
+	sci@0xe6c40000 {
+		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@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;
+	};
+
+	sci@0xe6c60000 {
+		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@0xe6c70000 {
+		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@0xe6c80000 {
+		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@0xe6cb0000 {
+		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@0xe6cc0000 {
+		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@0xe6c30000 {
+		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;
+	};
 };
 
 &gpio {
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index 5312aad..5f7597a 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -394,6 +394,13 @@ static struct platform_device *r8a7740_early_devices[] __initdata = {
 	&tmu02_device,
 };
 
+static struct platform_device *r8a7740_early_devices_dt[] __initdata = {
+	&cmt10_device,
+	&tmu00_device,
+	&tmu01_device,
+	&tmu02_device,
+};
+
 /* DMA */
 static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
 	{
@@ -839,8 +846,8 @@ void __init r8a7740_add_early_devices_dt(void)
 {
 	shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
 
-	early_platform_add_devices(r8a7740_early_devices,
-				   ARRAY_SIZE(r8a7740_early_devices));
+	early_platform_add_devices(r8a7740_early_devices_dt,
+				   ARRAY_SIZE(r8a7740_early_devices_dt));
 
 	/* setup early console here as well */
 	shmobile_setup_console();
@@ -852,8 +859,8 @@ static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
 
 void __init r8a7740_add_standard_devices_dt(void)
 {
-	platform_add_devices(r8a7740_early_devices,
-			    ARRAY_SIZE(r8a7740_early_devices));
+	platform_add_devices(r8a7740_early_devices_dt,
+			    ARRAY_SIZE(r8a7740_early_devices_dt));
 
 	of_platform_populate(NULL, of_default_bus_match_table,
 			     r8a7740_auxdata_lookup, NULL);
-- 
1.7.9.5


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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
  2013-02-25 19:06 ` Bastian Hecht
@ 2013-02-25 20:35   ` Paul Mundt
  -1 siblings, 0 replies; 12+ messages in thread
From: Paul Mundt @ 2013-02-25 20:35 UTC (permalink / raw)
  To: Bastian Hecht; +Cc: linux-sh, Magnus Damm, linux-serial

On Mon, Feb 25, 2013 at 01:06:53PM -0600, Bastian Hecht wrote:
> We add the capabilty to probe Renesas SCI devices using Device Tree setup.
> 
> Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
> ---
> Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.
> 
> changelog v2:
>  - Renamed title to "Add OF support"
>  - Removed fixed configurations from driver and added the following binding props:
> 	- renesas,scscr
> 	- renesas,scbrr-algo-id
> 	- renesas,autoconf
> 	- renesas,regtype
> 	See patch for descriptions
> 
This looks much better, only a few minor nits.

> +Optional properties:
> +- renesas,autoconf : Set if device is capable of auto configuration
> +- renesas,regtype : Overwrite the register layout. Some legacy hardware versions
> +  use a non-default register layout. Possible layouts are
> +  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
> +  1 = SCIx_SH3_SCIF_REGTYPE
> +  2 = SCIx_SH4_SCIF_REGTYPE
> +  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
> +  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
> +  5 = SCIx_SH7705_SCIF_REGTYPE
> +
Here I would still opt to provide the full regtype set, even for the
"standard" layouts, as it's quite possible that newer port-types will use
older layouts.

In this case you could keep 0 as the probe type (which would be the
default anyways, so effectively a no-op), and then do the upper bounding
via SCIx_NR_REGTYPES.

> +/* This array belongs to the DT binding definition "renesas,regtype" */
> +static const char sci_regtype_modes[] = {
> +	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
> +	SCIx_SH3_SCIF_REGTYPE,
> +	SCIx_SH4_SCIF_REGTYPE,
> +	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
> +	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
> +	SCIx_SH7705_SCIF_REGTYPE
> +};
> +
At which point all of this can go away.

> +static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
> +								int *dev_id)
> +{
..
> +	prop = of_get_property(np, "renesas,regtype", NULL);
> +	if (prop) {
> +		val = be32_to_cpup(prop);
> +		if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
> +			dev_err(&pdev->dev, "invalid DT prop regtype\n");
> +			return NULL;
> +		}
> +		p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
> +	}
> +
You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
assign p->regtype the be32_to_cpup() value directly. Which will also make
it trivial to add new regtypes in the future, we would only need to
update the binding documentation.

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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
@ 2013-02-25 20:35   ` Paul Mundt
  0 siblings, 0 replies; 12+ messages in thread
From: Paul Mundt @ 2013-02-25 20:35 UTC (permalink / raw)
  To: Bastian Hecht; +Cc: linux-sh, Magnus Damm, linux-serial

On Mon, Feb 25, 2013 at 01:06:53PM -0600, Bastian Hecht wrote:
> We add the capabilty to probe Renesas SCI devices using Device Tree setup.
> 
> Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
> ---
> Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.
> 
> changelog v2:
>  - Renamed title to "Add OF support"
>  - Removed fixed configurations from driver and added the following binding props:
> 	- renesas,scscr
> 	- renesas,scbrr-algo-id
> 	- renesas,autoconf
> 	- renesas,regtype
> 	See patch for descriptions
> 
This looks much better, only a few minor nits.

> +Optional properties:
> +- renesas,autoconf : Set if device is capable of auto configuration
> +- renesas,regtype : Overwrite the register layout. Some legacy hardware versions
> +  use a non-default register layout. Possible layouts are
> +  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
> +  1 = SCIx_SH3_SCIF_REGTYPE
> +  2 = SCIx_SH4_SCIF_REGTYPE
> +  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
> +  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
> +  5 = SCIx_SH7705_SCIF_REGTYPE
> +
Here I would still opt to provide the full regtype set, even for the
"standard" layouts, as it's quite possible that newer port-types will use
older layouts.

In this case you could keep 0 as the probe type (which would be the
default anyways, so effectively a no-op), and then do the upper bounding
via SCIx_NR_REGTYPES.

> +/* This array belongs to the DT binding definition "renesas,regtype" */
> +static const char sci_regtype_modes[] = {
> +	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
> +	SCIx_SH3_SCIF_REGTYPE,
> +	SCIx_SH4_SCIF_REGTYPE,
> +	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
> +	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
> +	SCIx_SH7705_SCIF_REGTYPE
> +};
> +
At which point all of this can go away.

> +static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
> +								int *dev_id)
> +{
..
> +	prop = of_get_property(np, "renesas,regtype", NULL);
> +	if (prop) {
> +		val = be32_to_cpup(prop);
> +		if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
> +			dev_err(&pdev->dev, "invalid DT prop regtype\n");
> +			return NULL;
> +		}
> +		p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
> +	}
> +
You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
assign p->regtype the be32_to_cpup() value directly. Which will also make
it trivial to add new regtypes in the future, we would only need to
update the binding documentation.

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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
  2013-02-25 20:35   ` Paul Mundt
@ 2013-02-26 15:09     ` Bastian Hecht
  -1 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-26 15:09 UTC (permalink / raw)
  To: Paul Mundt; +Cc: linux-sh, Magnus Damm, linux-serial

Hi Paul,

2013/2/25 Paul Mundt <lethal@linux-sh.org>:
> On Mon, Feb 25, 2013 at 01:06:53PM -0600, Bastian Hecht wrote:
>> We add the capabilty to probe Renesas SCI devices using Device Tree setup.
>>
>> Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
>> ---
>> Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.
>>
>> changelog v2:
>>  - Renamed title to "Add OF support"
>>  - Removed fixed configurations from driver and added the following binding props:
>>       - renesas,scscr
>>       - renesas,scbrr-algo-id
>>       - renesas,autoconf
>>       - renesas,regtype
>>       See patch for descriptions
>>
> This looks much better, only a few minor nits.
>
>> +Optional properties:
>> +- renesas,autoconf : Set if device is capable of auto configuration
>> +- renesas,regtype : Overwrite the register layout. Some legacy hardware versions
>> +  use a non-default register layout. Possible layouts are
>> +  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
>> +  1 = SCIx_SH3_SCIF_REGTYPE
>> +  2 = SCIx_SH4_SCIF_REGTYPE
>> +  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
>> +  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
>> +  5 = SCIx_SH7705_SCIF_REGTYPE
>> +
> Here I would still opt to provide the full regtype set, even for the
> "standard" layouts, as it's quite possible that newer port-types will use
> older layouts.
>
> In this case you could keep 0 as the probe type (which would be the
> default anyways, so effectively a no-op), and then do the upper bounding
> via SCIx_NR_REGTYPES.
>
>> +/* This array belongs to the DT binding definition "renesas,regtype" */
>> +static const char sci_regtype_modes[] = {
>> +     SCIx_SH2_SCIF_FIFODATA_REGTYPE,
>> +     SCIx_SH3_SCIF_REGTYPE,
>> +     SCIx_SH4_SCIF_REGTYPE,
>> +     SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
>> +     SCIx_SH4_SCIF_FIFODATA_REGTYPE,
>> +     SCIx_SH7705_SCIF_REGTYPE
>> +};
>> +
> At which point all of this can go away.
>
>> +static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
>> +                                                             int *dev_id)
>> +{
> ..
>> +     prop = of_get_property(np, "renesas,regtype", NULL);
>> +     if (prop) {
>> +             val = be32_to_cpup(prop);
>> +             if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
>> +                     dev_err(&pdev->dev, "invalid DT prop regtype\n");
>> +                     return NULL;
>> +             }
>> +             p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
>> +     }
>> +
> You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
> assign p->regtype the be32_to_cpup() value directly. Which will also make
> it trivial to add new regtypes in the future, we would only need to
> update the binding documentation.

Ok, I slightly disliked that portion anyway in the code as we have the
full mapping from the SCBRR algo ID and only the partial mapping from
the register set. Additionally I wonder if I should add something like

enum {
+     SCBRR_ALGO_INVALID,
       SCBRR_ALGO_1,
       SCBRR_ALGO_2,
       SCBRR_ALGO_3,
       SCBRR_ALGO_4,
       SCBRR_ALGO_5,
};
...
-p->scbrr_algo_id = be32_to_cpup(prop) - 1;
+p->scbrr_algo_id = be32_to_cpup(prop);

to have a straight mapping.

Thanks,

 Bastian

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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
@ 2013-02-26 15:09     ` Bastian Hecht
  0 siblings, 0 replies; 12+ messages in thread
From: Bastian Hecht @ 2013-02-26 15:09 UTC (permalink / raw)
  To: Paul Mundt; +Cc: linux-sh, Magnus Damm, linux-serial

Hi Paul,

2013/2/25 Paul Mundt <lethal@linux-sh.org>:
> On Mon, Feb 25, 2013 at 01:06:53PM -0600, Bastian Hecht wrote:
>> We add the capabilty to probe Renesas SCI devices using Device Tree setup.
>>
>> Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
>> ---
>> Based on the topic/all+next branch from the 17th Feb. I couldn't rebase it on the current HEAD as the armadillo-reference code currently isn't in.
>>
>> changelog v2:
>>  - Renamed title to "Add OF support"
>>  - Removed fixed configurations from driver and added the following binding props:
>>       - renesas,scscr
>>       - renesas,scbrr-algo-id
>>       - renesas,autoconf
>>       - renesas,regtype
>>       See patch for descriptions
>>
> This looks much better, only a few minor nits.
>
>> +Optional properties:
>> +- renesas,autoconf : Set if device is capable of auto configuration
>> +- renesas,regtype : Overwrite the register layout. Some legacy hardware versions
>> +  use a non-default register layout. Possible layouts are
>> +  0 = SCIx_SH2_SCIF_FIFODATA_REGTYPE
>> +  1 = SCIx_SH3_SCIF_REGTYPE
>> +  2 = SCIx_SH4_SCIF_REGTYPE
>> +  3 = SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE
>> +  4 = SCIx_SH4_SCIF_FIFODATA_REGTYPE
>> +  5 = SCIx_SH7705_SCIF_REGTYPE
>> +
> Here I would still opt to provide the full regtype set, even for the
> "standard" layouts, as it's quite possible that newer port-types will use
> older layouts.
>
> In this case you could keep 0 as the probe type (which would be the
> default anyways, so effectively a no-op), and then do the upper bounding
> via SCIx_NR_REGTYPES.
>
>> +/* This array belongs to the DT binding definition "renesas,regtype" */
>> +static const char sci_regtype_modes[] = {
>> +     SCIx_SH2_SCIF_FIFODATA_REGTYPE,
>> +     SCIx_SH3_SCIF_REGTYPE,
>> +     SCIx_SH4_SCIF_REGTYPE,
>> +     SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
>> +     SCIx_SH4_SCIF_FIFODATA_REGTYPE,
>> +     SCIx_SH7705_SCIF_REGTYPE
>> +};
>> +
> At which point all of this can go away.
>
>> +static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
>> +                                                             int *dev_id)
>> +{
> ..
>> +     prop = of_get_property(np, "renesas,regtype", NULL);
>> +     if (prop) {
>> +             val = be32_to_cpup(prop);
>> +             if (val <= 0 || val >= ARRAY_SIZE(sci_regtype_modes)) {
>> +                     dev_err(&pdev->dev, "invalid DT prop regtype\n");
>> +                     return NULL;
>> +             }
>> +             p->regtype = sci_regtype_modes[be32_to_cpup(prop)];
>> +     }
>> +
> You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
> assign p->regtype the be32_to_cpup() value directly. Which will also make
> it trivial to add new regtypes in the future, we would only need to
> update the binding documentation.

Ok, I slightly disliked that portion anyway in the code as we have the
full mapping from the SCBRR algo ID and only the partial mapping from
the register set. Additionally I wonder if I should add something like

enum {
+     SCBRR_ALGO_INVALID,
       SCBRR_ALGO_1,
       SCBRR_ALGO_2,
       SCBRR_ALGO_3,
       SCBRR_ALGO_4,
       SCBRR_ALGO_5,
};
...
-p->scbrr_algo_id = be32_to_cpup(prop) - 1;
+p->scbrr_algo_id = be32_to_cpup(prop);

to have a straight mapping.

Thanks,

 Bastian

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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
  2013-02-26 15:09     ` Bastian Hecht
@ 2013-02-27  8:04       ` Paul Mundt
  -1 siblings, 0 replies; 12+ messages in thread
From: Paul Mundt @ 2013-02-27  8:04 UTC (permalink / raw)
  To: Bastian Hecht; +Cc: linux-sh, Magnus Damm, linux-serial

On Tue, Feb 26, 2013 at 09:09:52AM -0600, Bastian Hecht wrote:
> 2013/2/25 Paul Mundt <lethal@linux-sh.org>:
> > You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
> > assign p->regtype the be32_to_cpup() value directly. Which will also make
> > it trivial to add new regtypes in the future, we would only need to
> > update the binding documentation.
> 
> Ok, I slightly disliked that portion anyway in the code as we have the
> full mapping from the SCBRR algo ID and only the partial mapping from
> the register set. Additionally I wonder if I should add something like
> 
> enum {
> +     SCBRR_ALGO_INVALID,
>        SCBRR_ALGO_1,
>        SCBRR_ALGO_2,
>        SCBRR_ALGO_3,
>        SCBRR_ALGO_4,
>        SCBRR_ALGO_5,
> };
> ...
> -p->scbrr_algo_id = be32_to_cpup(prop) - 1;
> +p->scbrr_algo_id = be32_to_cpup(prop);
> 
> to have a straight mapping.

Yes, that would be my preferred option as well. I was going to comment on
the - 1 thing previously, but figured it was just some DT oddity.

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

* Re: [PATCH v2 1/3] serial: sh-sci: Add OF support
@ 2013-02-27  8:04       ` Paul Mundt
  0 siblings, 0 replies; 12+ messages in thread
From: Paul Mundt @ 2013-02-27  8:04 UTC (permalink / raw)
  To: Bastian Hecht; +Cc: linux-sh, Magnus Damm, linux-serial

On Tue, Feb 26, 2013 at 09:09:52AM -0600, Bastian Hecht wrote:
> 2013/2/25 Paul Mundt <lethal@linux-sh.org>:
> > You can then compare against SCIx_PROBE_REGTYPE and SCIx_NR_REGTYPES, and
> > assign p->regtype the be32_to_cpup() value directly. Which will also make
> > it trivial to add new regtypes in the future, we would only need to
> > update the binding documentation.
> 
> Ok, I slightly disliked that portion anyway in the code as we have the
> full mapping from the SCBRR algo ID and only the partial mapping from
> the register set. Additionally I wonder if I should add something like
> 
> enum {
> +     SCBRR_ALGO_INVALID,
>        SCBRR_ALGO_1,
>        SCBRR_ALGO_2,
>        SCBRR_ALGO_3,
>        SCBRR_ALGO_4,
>        SCBRR_ALGO_5,
> };
> ...
> -p->scbrr_algo_id = be32_to_cpup(prop) - 1;
> +p->scbrr_algo_id = be32_to_cpup(prop);
> 
> to have a straight mapping.

Yes, that would be my preferred option as well. I was going to comment on
the - 1 thing previously, but figured it was just some DT oddity.

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

end of thread, other threads:[~2013-02-27  8:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-25 18:07 [PATCH v2 1/3] serial: sh-sci: Add OF support Bastian Hecht
2013-02-25 19:06 ` Bastian Hecht
2013-02-25 18:07 ` [PATCH v2 3/3] ARM: mach-shmobile: r8a7740: Setup the serial devices using DT Bastian Hecht
2013-02-25 19:06   ` Bastian Hecht
2013-02-25 18:13 ` [PATCH v2 2/3] ARM: mach-shmobile: r8a7740: Add DT names to clock list Bastian Hecht
2013-02-25 19:06   ` Bastian Hecht
2013-02-25 20:35 ` [PATCH v2 1/3] serial: sh-sci: Add OF support Paul Mundt
2013-02-25 20:35   ` Paul Mundt
2013-02-26 15:09   ` Bastian Hecht
2013-02-26 15:09     ` Bastian Hecht
2013-02-27  8:04     ` Paul Mundt
2013-02-27  8:04       ` Paul Mundt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.