serial: sh-sci: Add OF support
Subsystems (6)
PATCH v2 1/3 serial: sh-sci: Add OF support
We add the capabilty to probe Renesas SCI devices using Device Tree setup.
---
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
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +47 -0
@@ -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; + };
drivers/tty/serial/sh-sci.c +127 -4
157 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 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.
---
v2: no changes
arch/arm/mach-shmobile/clock-r8a7740.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/mach-shmobile/clock-r8a7740.c +9 -0
@@ -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
PATCH v2 3/3 ARM: mach-shmobile: r8a7740: Setup the serial devices using DT
In reply to Bastian HechtWe 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.
---
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(-)
arch/arm/boot/dts/r8a7740-armadillo800eva-reference.dts +94 -0
@@ -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 {
arch/arm/mach-shmobile/setup-r8a7740.c +11 -4
@@ -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 );
Signature · 1 line
1.7.9.5
Quoted 6 lines · Bastian Hecht
We add the capabilty to probe Renesas SCI devices using Device Tree setup.
Signed-off-by Bastian Hecht <[email protected]>---
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.
Quoted 9 lines
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.
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 35
Quoted 11 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +11
-0+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.
drivers/tty/serial/sh-sci.c static int sci_remove(struct platform_device *dev) · line 2381
Quoted 10 lines
drivers/tty/serial/sh-sci.c +10
-0+/* 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.
Quoted 3 lines
drivers/tty/serial/sh-sci.c +3
-0+static struct plat_sci_port *sci_parse_dt (struct platform_device *pdev, +int *dev_id) +{
..
drivers/tty/serial/sh-sci.c static int sci_remove(struct platform_device *dev) · line 2454
Quoted 10 lines
drivers/tty/serial/sh-sci.c +10
-0+ 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.
Hi Paul,
2013/2/25 Paul Mundt <[email protected]>:
Quoted 63 lines · Bastian Hecht
Quoted 6 lines
We add the capabilty to probe Renesas SCI devices using Device Tree setup.
Signed-off-by Bastian Hecht <[email protected]>---
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.Quoted 9 lines
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 descriptionsThis looks much better, only a few minor nits.
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt line 35
Quoted 11 lines
Documentation/devicetree/bindings/tty/serial/renesas,sci-serial.txt new file +11
-0+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.drivers/tty/serial/sh-sci.c static int sci_remove(struct platform_device *dev) · line 2381
Quoted 10 lines
drivers/tty/serial/sh-sci.c +10
-0+/* 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.
Quoted 3 lines
drivers/tty/serial/sh-sci.c +3
-0+static struct plat_sci_port *sci_parse_dt (struct platform_device *pdev, +int *dev_id) +{..
drivers/tty/serial/sh-sci.c static int sci_remove(struct platform_device *dev) · line 2454
Quoted 10 lines
drivers/tty/serial/sh-sci.c +10
-0+ 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)]; + } +
Quoted 4 lines
You can then compare against
SCIx_PROBE_REGTYPEandSCIx_NR_REGTYPES, and assignp->regtypethebe32_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
Quoted 22 lines · Bastian Hecht
2013/2/25 Paul Mundt <[email protected]>:
Quoted 4 lines
You can then compare against
SCIx_PROBE_REGTYPEandSCIx_NR_REGTYPES, and assignp->regtypethebe32_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, };...
(quoted diff) +1
-1-p->scbrr_algo_id = be32_to_cpup(prop) - 1; +p->scbrr_algo_id = be32_to_cpup(prop);
Quoted 1 line
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.