Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'scif-clk-sck-brg-for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers into tty-next

Geert writes:

Summary:
- Clean up the naming of clocks in the sh-sci driver and its DT bindings,
- Add support for the optional external clock on (H)SCI(F), where this pin
can serve as a clock input,
- Add support for the optional clock sources for the Baud Rate
Generator for External Clock (BRG), as found on some SCIF variants
and on HSCIF.

+500 -212
+26 -6
Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
··· 2 2 3 3 Required properties: 4 4 5 - - compatible: Must contain one of the following: 5 + - compatible: Must contain one or more of the following: 6 6 7 7 - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART. 8 8 - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART. ··· 31 31 - "renesas,hscif-r8a7795" for R8A7795 (R-Car H3) HSCIF compatible UART. 32 32 - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART. 33 33 - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART. 34 + - "renesas,rcar-gen1-scif" for R-Car Gen1 SCIF compatible UART, 35 + - "renesas,rcar-gen2-scif" for R-Car Gen2 SCIF compatible UART, 36 + - "renesas,rcar-gen3-scif" for R-Car Gen3 SCIF compatible UART, 37 + - "renesas,rcar-gen2-scifa" for R-Car Gen2 SCIFA compatible UART, 38 + - "renesas,rcar-gen2-scifb" for R-Car Gen2 SCIFB compatible UART, 39 + - "renesas,rcar-gen1-hscif" for R-Car Gen1 HSCIF compatible UART, 40 + - "renesas,rcar-gen2-hscif" for R-Car Gen2 HSCIF compatible UART, 41 + - "renesas,rcar-gen3-hscif" for R-Car Gen3 HSCIF compatible UART, 34 42 - "renesas,scif" for generic SCIF compatible UART. 35 43 - "renesas,scifa" for generic SCIFA compatible UART. 36 44 - "renesas,scifb" for generic SCIFB compatible UART. ··· 46 38 - "renesas,sci" for generic SCI compatible UART. 47 39 48 40 When compatible with the generic version, nodes must list the 49 - SoC-specific version corresponding to the platform first followed by the 50 - generic version. 41 + SoC-specific version corresponding to the platform first, followed by the 42 + family-specific and/or generic versions. 51 43 52 44 - reg: Base address and length of the I/O registers used by the UART. 53 45 - interrupts: Must contain an interrupt-specifier for the SCIx interrupt. 54 46 55 47 - clocks: Must contain a phandle and clock-specifier pair for each entry 56 48 in clock-names. 57 - - clock-names: Must contain "sci_ick" for the SCIx UART interface clock. 49 + - clock-names: Must contain "fck" for the SCIx UART functional clock. 50 + Apart from the divided functional clock, there may be other possible 51 + sources for the sampling clock, depending on SCIx variant. 52 + On (H)SCI(F) and some SCIFA, an additional clock may be specified: 53 + - "hsck" for the optional external clock input (on HSCIF), 54 + - "sck" for the optional external clock input (on other variants). 55 + On UARTs equipped with a Baud Rate Generator for External Clock (BRG) 56 + (some SCIF and HSCIF), additional clocks may be specified: 57 + - "brg_int" for the optional internal clock source for the frequency 58 + divider (typically the (AXI or SHwy) bus clock), 59 + - "scif_clk" for the optional external clock source for the frequency 60 + divider (SCIF_CLK). 58 61 59 62 Note: Each enabled SCIx UART should have an alias correctly numbered in the 60 63 "aliases" node. ··· 81 62 }; 82 63 83 64 scifa0: serial@e6c40000 { 84 - compatible = "renesas,scifa-r8a7790", "renesas,scifa"; 65 + compatible = "renesas,scifa-r8a7790", 66 + "renesas,rcar-gen2-scifa", "renesas,scifa"; 85 67 reg = <0 0xe6c40000 0 64>; 86 68 interrupt-parent = <&gic>; 87 69 interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>; 88 70 clocks = <&mstp2_clks R8A7790_CLK_SCIFA0>; 89 - clock-names = "sci_ick"; 71 + clock-names = "fck"; 90 72 dmas = <&dmac0 0x21>, <&dmac0 0x22>; 91 73 dma-names = "tx", "rx"; 92 74 };
-1
arch/sh/kernel/cpu/clock-cpg.c
··· 63 63 clk_add_alias("fck", "sh-mtu2", "peripheral_clk", NULL); 64 64 clk_add_alias("fck", "sh-cmt-16.0", "peripheral_clk", NULL); 65 65 clk_add_alias("fck", "sh-cmt-32.0", "peripheral_clk", NULL); 66 - clk_add_alias("sci_ick", NULL, "peripheral_clk", NULL); 67 66 68 67 return ret; 69 68 }
+8 -1
arch/sh/kernel/cpu/sh2a/clock-sh7264.c
··· 115 115 CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]), 116 116 117 117 /* MSTP clocks */ 118 - CLKDEV_CON_ID("sci_ick", &mstp_clks[MSTP77]), 118 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP77]), 119 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP77]), 120 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP77]), 121 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP77]), 122 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP77]), 123 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP77]), 124 + CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP77]), 125 + CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP77]), 119 126 CLKDEV_CON_ID("vdc3", &mstp_clks[MSTP74]), 120 127 CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]), 121 128 CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
+8 -8
arch/sh/kernel/cpu/sh2a/clock-sh7269.c
··· 150 150 CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]), 151 151 152 152 /* MSTP clocks */ 153 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP47]), 154 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP46]), 155 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP45]), 156 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP44]), 157 - CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP43]), 158 - CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP42]), 159 - CLKDEV_ICK_ID("sci_fck", "sh-sci.6", &mstp_clks[MSTP41]), 160 - CLKDEV_ICK_ID("sci_fck", "sh-sci.7", &mstp_clks[MSTP40]), 153 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP47]), 154 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP46]), 155 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP45]), 156 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP44]), 157 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP43]), 158 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP42]), 159 + CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP41]), 160 + CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP40]), 161 161 CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]), 162 162 CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]), 163 163 CLKDEV_ICK_ID("fck", "sh-mtu2", &mstp_clks[MSTP35]),
+4 -4
arch/sh/kernel/cpu/sh4a/clock-sh7343.c
··· 232 232 CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]), 233 233 CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]), 234 234 235 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]), 236 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]), 237 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]), 238 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP004]), 235 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]), 236 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]), 237 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]), 238 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP004]), 239 239 240 240 CLKDEV_CON_ID("sio0", &mstp_clks[MSTP003]), 241 241 CLKDEV_CON_ID("siof0", &mstp_clks[MSTP002]),
+3 -3
arch/sh/kernel/cpu/sh4a/clock-sh7366.c
··· 230 230 CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]), 231 231 CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]), 232 232 233 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]), 234 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]), 235 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]), 233 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]), 234 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]), 235 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]), 236 236 237 237 CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]), 238 238 CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),
+6 -6
arch/sh/kernel/cpu/sh4a/clock-sh7723.c
··· 267 267 CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[HWBLK_TMU0]), 268 268 CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[HWBLK_TMU1]), 269 269 270 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]), 271 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]), 272 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]), 273 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]), 274 - CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]), 275 - CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]), 270 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]), 271 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]), 272 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]), 273 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]), 274 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]), 275 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]), 276 276 277 277 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[HWBLK_LCDC]), 278 278 };
+6 -6
arch/sh/kernel/cpu/sh4a/clock-sh7734.c
··· 194 194 /* MSTP32 clocks */ 195 195 CLKDEV_DEV_ID("i2c-sh7734.0", &mstp_clks[MSTP030]), 196 196 CLKDEV_DEV_ID("i2c-sh7734.1", &mstp_clks[MSTP029]), 197 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP026]), 198 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]), 199 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP024]), 200 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP023]), 201 - CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP022]), 202 - CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP021]), 197 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP026]), 198 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]), 199 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP024]), 200 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP023]), 201 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP022]), 202 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP021]), 203 203 CLKDEV_CON_ID("hscif", &mstp_clks[MSTP019]), 204 204 CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP016]), 205 205 CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP015]),
+3 -3
arch/sh/kernel/cpu/sh4a/clock-sh7757.c
··· 125 125 126 126 CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP113]), 127 127 CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP114]), 128 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP112]), 129 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP111]), 130 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP110]), 128 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP112]), 129 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP111]), 130 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP110]), 131 131 132 132 CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP103]), 133 133 CLKDEV_DEV_ID("renesas_usbhs.0", &mstp_clks[MSTP102]),
+6 -6
arch/sh/kernel/cpu/sh4a/clock-sh7785.c
··· 132 132 CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]), 133 133 134 134 /* MSTP32 clocks */ 135 - CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]), 136 - CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]), 137 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]), 138 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]), 139 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]), 140 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]), 135 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]), 136 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]), 137 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]), 138 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]), 139 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]), 140 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]), 141 141 142 142 CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]), 143 143 CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),
+6 -6
arch/sh/kernel/cpu/sh4a/clock-sh7786.c
··· 139 139 CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]), 140 140 141 141 /* MSTP32 clocks */ 142 - CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]), 143 - CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]), 144 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]), 145 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]), 146 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]), 147 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]), 142 + CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]), 143 + CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]), 144 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]), 145 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]), 146 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]), 147 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]), 148 148 149 149 CLKDEV_CON_ID("ssi3_fck", &mstp_clks[MSTP023]), 150 150 CLKDEV_CON_ID("ssi2_fck", &mstp_clks[MSTP022]),
+4 -4
arch/sh/kernel/cpu/sh4a/clock-shx3.c
··· 114 114 CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]), 115 115 116 116 /* MSTP32 clocks */ 117 - CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]), 118 - CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]), 119 - CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]), 120 - CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]), 117 + CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]), 118 + CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]), 119 + CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]), 120 + CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]), 121 121 122 122 CLKDEV_CON_ID("h8ex_fck", &mstp_clks[MSTP003]), 123 123 CLKDEV_CON_ID("csm_fck", &mstp_clks[MSTP002]),
+6 -6
arch/sh/kernel/cpu/sh4a/setup-sh7734.c
··· 28 28 .flags = UPF_BOOT_AUTOCONF, 29 29 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE, 30 30 .type = PORT_SCIF, 31 - .regtype = SCIx_SH4_SCIF_REGTYPE, 31 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 32 32 }; 33 33 34 34 static struct resource scif0_resources[] = { ··· 50 50 .flags = UPF_BOOT_AUTOCONF, 51 51 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE, 52 52 .type = PORT_SCIF, 53 - .regtype = SCIx_SH4_SCIF_REGTYPE, 53 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 54 54 }; 55 55 56 56 static struct resource scif1_resources[] = { ··· 72 72 .flags = UPF_BOOT_AUTOCONF, 73 73 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE, 74 74 .type = PORT_SCIF, 75 - .regtype = SCIx_SH4_SCIF_REGTYPE, 75 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 76 76 }; 77 77 78 78 static struct resource scif2_resources[] = { ··· 94 94 .flags = UPF_BOOT_AUTOCONF, 95 95 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE | SCSCR_TOIE, 96 96 .type = PORT_SCIF, 97 - .regtype = SCIx_SH4_SCIF_REGTYPE, 97 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 98 98 }; 99 99 100 100 static struct resource scif3_resources[] = { ··· 116 116 .flags = UPF_BOOT_AUTOCONF, 117 117 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE, 118 118 .type = PORT_SCIF, 119 - .regtype = SCIx_SH4_SCIF_REGTYPE, 119 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 120 120 }; 121 121 122 122 static struct resource scif4_resources[] = { ··· 138 138 .flags = UPF_BOOT_AUTOCONF, 139 139 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_REIE, 140 140 .type = PORT_SCIF, 141 - .regtype = SCIx_SH4_SCIF_REGTYPE, 141 + .regtype = SCIx_SH4_SCIF_BRG_REGTYPE, 142 142 }; 143 143 144 144 static struct resource scif5_resources[] = {
+403 -152
drivers/tty/serial/sh-sci.c
··· 2 2 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO) 3 3 * 4 4 * Copyright (C) 2002 - 2011 Paul Mundt 5 + * Copyright (C) 2015 Glider bvba 5 6 * Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007). 6 7 * 7 8 * based off of the old drivers/char/sh-sci.c by: ··· 77 76 ((port)->irqs[SCIx_ERI_IRQ] && \ 78 77 ((port)->irqs[SCIx_RXI_IRQ] < 0)) 79 78 79 + enum SCI_CLKS { 80 + SCI_FCK, /* Functional Clock */ 81 + SCI_SCK, /* Optional External Clock */ 82 + SCI_BRG_INT, /* Optional BRG Internal Clock Source */ 83 + SCI_SCIF_CLK, /* Optional BRG External Clock Source */ 84 + SCI_NUM_CLKS 85 + }; 86 + 80 87 struct sci_port { 81 88 struct uart_port port; 82 89 ··· 101 92 struct timer_list break_timer; 102 93 int break_flag; 103 94 104 - /* Interface clock */ 105 - struct clk *iclk; 106 - /* Function clock */ 107 - struct clk *fclk; 95 + /* Clocks */ 96 + struct clk *clks[SCI_NUM_CLKS]; 97 + unsigned long clk_rates[SCI_NUM_CLKS]; 108 98 109 99 int irqs[SCIx_NR_IRQS]; 110 100 char *irqstr[SCIx_NR_IRQS]; ··· 171 163 [HSSRR] = sci_reg_invalid, 172 164 [SCPCR] = sci_reg_invalid, 173 165 [SCPDR] = sci_reg_invalid, 166 + [SCDL] = sci_reg_invalid, 167 + [SCCKS] = sci_reg_invalid, 174 168 }, 175 169 176 170 /* ··· 195 185 [HSSRR] = sci_reg_invalid, 196 186 [SCPCR] = sci_reg_invalid, 197 187 [SCPDR] = sci_reg_invalid, 188 + [SCDL] = sci_reg_invalid, 189 + [SCCKS] = sci_reg_invalid, 198 190 }, 199 191 200 192 /* ··· 218 206 [HSSRR] = sci_reg_invalid, 219 207 [SCPCR] = { 0x30, 16 }, 220 208 [SCPDR] = { 0x34, 16 }, 209 + [SCDL] = sci_reg_invalid, 210 + [SCCKS] = sci_reg_invalid, 221 211 }, 222 212 223 213 /* ··· 241 227 [HSSRR] = sci_reg_invalid, 242 228 [SCPCR] = { 0x30, 16 }, 243 229 [SCPDR] = { 0x34, 16 }, 230 + [SCDL] = sci_reg_invalid, 231 + [SCCKS] = sci_reg_invalid, 244 232 }, 245 233 246 234 /* ··· 265 249 [HSSRR] = sci_reg_invalid, 266 250 [SCPCR] = sci_reg_invalid, 267 251 [SCPDR] = sci_reg_invalid, 252 + [SCDL] = sci_reg_invalid, 253 + [SCCKS] = sci_reg_invalid, 268 254 }, 269 255 270 256 /* ··· 288 270 [HSSRR] = sci_reg_invalid, 289 271 [SCPCR] = sci_reg_invalid, 290 272 [SCPDR] = sci_reg_invalid, 273 + [SCDL] = sci_reg_invalid, 274 + [SCCKS] = sci_reg_invalid, 291 275 }, 292 276 293 277 /* ··· 311 291 [HSSRR] = sci_reg_invalid, 312 292 [SCPCR] = sci_reg_invalid, 313 293 [SCPDR] = sci_reg_invalid, 294 + [SCDL] = sci_reg_invalid, 295 + [SCCKS] = sci_reg_invalid, 296 + }, 297 + 298 + /* 299 + * Common SCIF definitions for ports with a Baud Rate Generator for 300 + * External Clock (BRG). 301 + */ 302 + [SCIx_SH4_SCIF_BRG_REGTYPE] = { 303 + [SCSMR] = { 0x00, 16 }, 304 + [SCBRR] = { 0x04, 8 }, 305 + [SCSCR] = { 0x08, 16 }, 306 + [SCxTDR] = { 0x0c, 8 }, 307 + [SCxSR] = { 0x10, 16 }, 308 + [SCxRDR] = { 0x14, 8 }, 309 + [SCFCR] = { 0x18, 16 }, 310 + [SCFDR] = { 0x1c, 16 }, 311 + [SCTFDR] = sci_reg_invalid, 312 + [SCRFDR] = sci_reg_invalid, 313 + [SCSPTR] = { 0x20, 16 }, 314 + [SCLSR] = { 0x24, 16 }, 315 + [HSSRR] = sci_reg_invalid, 316 + [SCPCR] = sci_reg_invalid, 317 + [SCPDR] = sci_reg_invalid, 318 + [SCDL] = { 0x30, 16 }, 319 + [SCCKS] = { 0x34, 16 }, 314 320 }, 315 321 316 322 /* ··· 358 312 [HSSRR] = { 0x40, 16 }, 359 313 [SCPCR] = sci_reg_invalid, 360 314 [SCPDR] = sci_reg_invalid, 315 + [SCDL] = { 0x30, 16 }, 316 + [SCCKS] = { 0x34, 16 }, 361 317 }, 362 318 363 319 /* ··· 382 334 [HSSRR] = sci_reg_invalid, 383 335 [SCPCR] = sci_reg_invalid, 384 336 [SCPDR] = sci_reg_invalid, 337 + [SCDL] = sci_reg_invalid, 338 + [SCCKS] = sci_reg_invalid, 385 339 }, 386 340 387 341 /* ··· 406 356 [HSSRR] = sci_reg_invalid, 407 357 [SCPCR] = sci_reg_invalid, 408 358 [SCPDR] = sci_reg_invalid, 359 + [SCDL] = sci_reg_invalid, 360 + [SCCKS] = sci_reg_invalid, 409 361 }, 410 362 411 363 /* ··· 430 378 [HSSRR] = sci_reg_invalid, 431 379 [SCPCR] = sci_reg_invalid, 432 380 [SCPDR] = sci_reg_invalid, 381 + [SCDL] = sci_reg_invalid, 382 + [SCCKS] = sci_reg_invalid, 433 383 }, 434 384 }; 435 385 ··· 506 452 507 453 static void sci_port_enable(struct sci_port *sci_port) 508 454 { 455 + unsigned int i; 456 + 509 457 if (!sci_port->port.dev) 510 458 return; 511 459 512 460 pm_runtime_get_sync(sci_port->port.dev); 513 461 514 - clk_prepare_enable(sci_port->iclk); 515 - sci_port->port.uartclk = clk_get_rate(sci_port->iclk); 516 - clk_prepare_enable(sci_port->fclk); 462 + for (i = 0; i < SCI_NUM_CLKS; i++) { 463 + clk_prepare_enable(sci_port->clks[i]); 464 + sci_port->clk_rates[i] = clk_get_rate(sci_port->clks[i]); 465 + } 466 + sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK]; 517 467 } 518 468 519 469 static void sci_port_disable(struct sci_port *sci_port) 520 470 { 471 + unsigned int i; 472 + 521 473 if (!sci_port->port.dev) 522 474 return; 523 475 ··· 535 475 del_timer_sync(&sci_port->break_timer); 536 476 sci_port->break_flag = 0; 537 477 538 - clk_disable_unprepare(sci_port->fclk); 539 - clk_disable_unprepare(sci_port->iclk); 478 + for (i = SCI_NUM_CLKS; i-- > 0; ) 479 + clk_disable_unprepare(sci_port->clks[i]); 540 480 541 481 pm_runtime_put_sync(sci_port->port.dev); 542 482 } ··· 1675 1615 { 1676 1616 struct sci_port *sci_port; 1677 1617 unsigned long flags; 1618 + unsigned int i; 1678 1619 1679 1620 sci_port = container_of(self, struct sci_port, freq_transition); 1680 1621 ··· 1683 1622 struct uart_port *port = &sci_port->port; 1684 1623 1685 1624 spin_lock_irqsave(&port->lock, flags); 1686 - port->uartclk = clk_get_rate(sci_port->iclk); 1625 + for (i = 0; i < SCI_NUM_CLKS; i++) 1626 + sci_port->clk_rates[i] = 1627 + clk_get_rate(sci_port->clks[i]); 1687 1628 spin_unlock_irqrestore(&port->lock, flags); 1688 1629 } 1689 1630 ··· 1927 1864 sci_free_irq(s); 1928 1865 } 1929 1866 1930 - static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps, 1931 - unsigned long freq) 1867 + static int sci_sck_calc(struct sci_port *s, unsigned int bps, 1868 + unsigned int *srr) 1932 1869 { 1933 - if (s->sampling_rate) 1934 - return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1; 1870 + unsigned long freq = s->clk_rates[SCI_SCK]; 1871 + unsigned int min_sr, max_sr, sr; 1872 + int err, min_err = INT_MAX; 1935 1873 1936 - /* Warn, but use a safe default */ 1937 - WARN_ON(1); 1874 + if (s->sampling_rate) { 1875 + /* SCI(F) has a fixed sampling rate */ 1876 + min_sr = max_sr = s->sampling_rate / 2; 1877 + } else { 1878 + /* HSCIF has a variable 1/(8..32) sampling rate */ 1879 + min_sr = 8; 1880 + max_sr = 32; 1881 + } 1938 1882 1939 - return ((freq + 16 * bps) / (32 * bps) - 1); 1883 + for (sr = max_sr; sr >= min_sr; sr--) { 1884 + err = DIV_ROUND_CLOSEST(freq, sr) - bps; 1885 + if (abs(err) >= abs(min_err)) 1886 + continue; 1887 + 1888 + min_err = err; 1889 + *srr = sr - 1; 1890 + 1891 + if (!err) 1892 + break; 1893 + } 1894 + 1895 + dev_dbg(s->port.dev, "SCK: %u%+d bps using SR %u\n", bps, min_err, 1896 + *srr + 1); 1897 + return min_err; 1940 1898 } 1941 1899 1942 - /* calculate frame length from SMR */ 1943 - static int sci_baud_calc_frame_len(unsigned int smr_val) 1900 + static int sci_brg_calc(struct sci_port *s, unsigned int bps, 1901 + unsigned long freq, unsigned int *dlr, 1902 + unsigned int *srr) 1944 1903 { 1945 - int len = 10; 1904 + unsigned int min_sr, max_sr, sr, dl; 1905 + int err, min_err = INT_MAX; 1946 1906 1947 - if (smr_val & SCSMR_CHR) 1948 - len--; 1949 - if (smr_val & SCSMR_PE) 1950 - len++; 1951 - if (smr_val & SCSMR_STOP) 1952 - len++; 1907 + if (s->sampling_rate) { 1908 + /* SCIF has a fixed sampling rate */ 1909 + min_sr = max_sr = s->sampling_rate / 2; 1910 + } else { 1911 + /* HSCIF has a variable 1/(8..32) sampling rate */ 1912 + min_sr = 8; 1913 + max_sr = 32; 1914 + } 1953 1915 1954 - return len; 1916 + for (sr = max_sr; sr >= min_sr; sr--) { 1917 + dl = DIV_ROUND_CLOSEST(freq, sr * bps); 1918 + dl = clamp(dl, 1U, 65535U); 1919 + 1920 + err = DIV_ROUND_CLOSEST(freq, sr * dl) - bps; 1921 + if (abs(err) >= abs(min_err)) 1922 + continue; 1923 + 1924 + min_err = err; 1925 + *dlr = dl; 1926 + *srr = sr - 1; 1927 + 1928 + if (!err) 1929 + break; 1930 + } 1931 + 1932 + dev_dbg(s->port.dev, "BRG: %u%+d bps using DL %u SR %u\n", bps, 1933 + min_err, *dlr, *srr + 1); 1934 + return min_err; 1955 1935 } 1956 1936 1957 - 1958 - /* calculate sample rate, BRR, and clock select for HSCIF */ 1959 - static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, 1960 - int *brr, unsigned int *srr, 1961 - unsigned int *cks, int frame_len) 1937 + /* calculate sample rate, BRR, and clock select */ 1938 + static int sci_scbrr_calc(struct sci_port *s, unsigned int bps, 1939 + unsigned int *brr, unsigned int *srr, 1940 + unsigned int *cks) 1962 1941 { 1963 - int sr, c, br, err, recv_margin; 1964 - int min_err = 1000; /* 100% */ 1965 - int recv_max_margin = 0; 1942 + unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c; 1943 + unsigned long freq = s->clk_rates[SCI_FCK]; 1944 + int err, min_err = INT_MAX; 1966 1945 1967 - /* Find the combination of sample rate and clock select with the 1968 - smallest deviation from the desired baud rate. */ 1969 - for (sr = 8; sr <= 32; sr++) { 1946 + if (s->sampling_rate) { 1947 + min_sr = max_sr = s->sampling_rate; 1948 + shift = 0; 1949 + } else { 1950 + /* HSCIF has a variable sample rate */ 1951 + min_sr = 8; 1952 + max_sr = 32; 1953 + shift = 1; 1954 + } 1955 + 1956 + /* 1957 + * Find the combination of sample rate and clock select with the 1958 + * smallest deviation from the desired baud rate. 1959 + * Prefer high sample rates to maximise the receive margin. 1960 + * 1961 + * M: Receive margin (%) 1962 + * N: Ratio of bit rate to clock (N = sampling rate) 1963 + * D: Clock duty (D = 0 to 1.0) 1964 + * L: Frame length (L = 9 to 12) 1965 + * F: Absolute value of clock frequency deviation 1966 + * 1967 + * M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) - 1968 + * (|D - 0.5| / N * (1 + F))| 1969 + * NOTE: Usually, treat D for 0.5, F is 0 by this calculation. 1970 + */ 1971 + for (sr = max_sr; sr >= min_sr; sr--) { 1970 1972 for (c = 0; c <= 3; c++) { 1971 1973 /* integerized formulas from HSCIF documentation */ 1972 - br = DIV_ROUND_CLOSEST(freq, (sr * 1973 - (1 << (2 * c + 1)) * bps)) - 1; 1974 - br = clamp(br, 0, 255); 1975 - err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr * 1976 - (1 << (2 * c + 1)) / 1000)) - 1977 - 1000; 1978 - /* Calc recv margin 1979 - * M: Receive margin (%) 1980 - * N: Ratio of bit rate to clock (N = sampling rate) 1981 - * D: Clock duty (D = 0 to 1.0) 1982 - * L: Frame length (L = 9 to 12) 1983 - * F: Absolute value of clock frequency deviation 1974 + prediv = sr * (1 << (2 * c + shift)); 1975 + 1976 + /* 1977 + * We need to calculate: 1984 1978 * 1985 - * M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) - 1986 - * (|D - 0.5| / N * (1 + F))| 1987 - * NOTE: Usually, treat D for 0.5, F is 0 by this 1988 - * calculation. 1979 + * br = freq / (prediv * bps) clamped to [1..256] 1980 + * err = freq / (br * prediv) - bps 1981 + * 1982 + * Watch out for overflow when calculating the desired 1983 + * sampling clock rate! 1989 1984 */ 1990 - recv_margin = abs((500 - 1991 - DIV_ROUND_CLOSEST(1000, sr << 1)) / 10); 1992 - if (abs(min_err) > abs(err)) { 1993 - min_err = err; 1994 - recv_max_margin = recv_margin; 1995 - } else if ((min_err == err) && 1996 - (recv_margin > recv_max_margin)) 1997 - recv_max_margin = recv_margin; 1998 - else 1985 + if (bps > UINT_MAX / prediv) 1986 + break; 1987 + 1988 + scrate = prediv * bps; 1989 + br = DIV_ROUND_CLOSEST(freq, scrate); 1990 + br = clamp(br, 1U, 256U); 1991 + 1992 + err = DIV_ROUND_CLOSEST(freq, br * prediv) - bps; 1993 + if (abs(err) >= abs(min_err)) 1999 1994 continue; 2000 1995 2001 - *brr = br; 1996 + min_err = err; 1997 + *brr = br - 1; 2002 1998 *srr = sr - 1; 2003 1999 *cks = c; 2000 + 2001 + if (!err) 2002 + goto found; 2004 2003 } 2005 2004 } 2006 2005 2007 - if (min_err == 1000) { 2008 - WARN_ON(1); 2009 - /* use defaults */ 2010 - *brr = 255; 2011 - *srr = 15; 2012 - *cks = 0; 2013 - } 2006 + found: 2007 + dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps, 2008 + min_err, *brr, *srr + 1, *cks); 2009 + return min_err; 2014 2010 } 2015 2011 2016 2012 static void sci_reset(struct uart_port *port) ··· 2091 1969 static void sci_set_termios(struct uart_port *port, struct ktermios *termios, 2092 1970 struct ktermios *old) 2093 1971 { 1972 + unsigned int baud, smr_val = 0, scr_val = 0, i; 1973 + unsigned int brr = 255, cks = 0, srr = 15, dl = 0, sccks = 0; 1974 + unsigned int brr1 = 255, cks1 = 0, srr1 = 15, dl1 = 0; 2094 1975 struct sci_port *s = to_sci_port(port); 2095 1976 const struct plat_sci_reg *reg; 2096 - unsigned int baud, smr_val = 0, max_baud, cks = 0; 2097 - int t = -1; 2098 - unsigned int srr = 15; 1977 + int min_err = INT_MAX, err; 1978 + unsigned long max_freq = 0; 1979 + int best_clk = -1; 2099 1980 2100 1981 if ((termios->c_cflag & CSIZE) == CS7) 2101 1982 smr_val |= SCSMR_CHR; ··· 2117 1992 * that the previous boot loader has enabled required clocks and 2118 1993 * setup the baud rate generator hardware for us already. 2119 1994 */ 2120 - max_baud = port->uartclk ? port->uartclk / 16 : 115200; 1995 + if (!port->uartclk) { 1996 + baud = uart_get_baud_rate(port, termios, old, 0, 115200); 1997 + goto done; 1998 + } 2121 1999 2122 - baud = uart_get_baud_rate(port, termios, old, 0, max_baud); 2123 - if (likely(baud && port->uartclk)) { 2124 - if (s->cfg->type == PORT_HSCIF) { 2125 - int frame_len = sci_baud_calc_frame_len(smr_val); 2126 - sci_baud_calc_hscif(baud, port->uartclk, &t, &srr, 2127 - &cks, frame_len); 2128 - } else { 2129 - t = sci_scbrr_calc(s, baud, port->uartclk); 2130 - for (cks = 0; t >= 256 && cks <= 3; cks++) 2131 - t >>= 2; 2000 + for (i = 0; i < SCI_NUM_CLKS; i++) 2001 + max_freq = max(max_freq, s->clk_rates[i]); 2002 + 2003 + baud = uart_get_baud_rate(port, termios, old, 0, 2004 + max_freq / max(s->sampling_rate, 8U)); 2005 + if (!baud) 2006 + goto done; 2007 + 2008 + /* 2009 + * There can be multiple sources for the sampling clock. Find the one 2010 + * that gives us the smallest deviation from the desired baud rate. 2011 + */ 2012 + 2013 + /* Optional Undivided External Clock */ 2014 + if (s->clk_rates[SCI_SCK] && port->type != PORT_SCIFA && 2015 + port->type != PORT_SCIFB) { 2016 + err = sci_sck_calc(s, baud, &srr1); 2017 + if (abs(err) < abs(min_err)) { 2018 + best_clk = SCI_SCK; 2019 + scr_val = SCSCR_CKE1; 2020 + sccks = SCCKS_CKS; 2021 + min_err = err; 2022 + srr = srr1; 2023 + if (!err) 2024 + goto done; 2132 2025 } 2133 2026 } 2134 2027 2028 + /* Optional BRG Frequency Divided External Clock */ 2029 + if (s->clk_rates[SCI_SCIF_CLK] && sci_getreg(port, SCDL)->size) { 2030 + err = sci_brg_calc(s, baud, s->clk_rates[SCI_SCIF_CLK], &dl1, 2031 + &srr1); 2032 + if (abs(err) < abs(min_err)) { 2033 + best_clk = SCI_SCIF_CLK; 2034 + scr_val = SCSCR_CKE1; 2035 + sccks = 0; 2036 + min_err = err; 2037 + dl = dl1; 2038 + srr = srr1; 2039 + if (!err) 2040 + goto done; 2041 + } 2042 + } 2043 + 2044 + /* Optional BRG Frequency Divided Internal Clock */ 2045 + if (s->clk_rates[SCI_BRG_INT] && sci_getreg(port, SCDL)->size) { 2046 + err = sci_brg_calc(s, baud, s->clk_rates[SCI_BRG_INT], &dl1, 2047 + &srr1); 2048 + if (abs(err) < abs(min_err)) { 2049 + best_clk = SCI_BRG_INT; 2050 + scr_val = SCSCR_CKE1; 2051 + sccks = SCCKS_XIN; 2052 + min_err = err; 2053 + dl = dl1; 2054 + srr = srr1; 2055 + if (!min_err) 2056 + goto done; 2057 + } 2058 + } 2059 + 2060 + /* Divided Functional Clock using standard Bit Rate Register */ 2061 + err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1); 2062 + if (abs(err) < abs(min_err)) { 2063 + best_clk = SCI_FCK; 2064 + scr_val = 0; 2065 + min_err = err; 2066 + brr = brr1; 2067 + srr = srr1; 2068 + cks = cks1; 2069 + } 2070 + 2071 + done: 2072 + if (best_clk >= 0) 2073 + dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n", 2074 + s->clks[best_clk], baud, min_err); 2075 + 2135 2076 sci_port_enable(s); 2077 + 2078 + /* 2079 + * Program the optional External Baud Rate Generator (BRG) first. 2080 + * It controls the mux to select (H)SCK or frequency divided clock. 2081 + */ 2082 + if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) { 2083 + serial_port_out(port, SCDL, dl); 2084 + serial_port_out(port, SCCKS, sccks); 2085 + } 2136 2086 2137 2087 sci_reset(port); 2138 2088 2139 - smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS; 2140 - 2141 2089 uart_update_timeout(port, termios->c_cflag, baud); 2142 2090 2143 - dev_dbg(port->dev, "%s: SMR %x, cks %x, t %x, SCSCR %x\n", 2144 - __func__, smr_val, cks, t, s->cfg->scscr); 2145 - 2146 - if (t >= 0) { 2147 - serial_port_out(port, SCSMR, (smr_val & ~SCSMR_CKS) | cks); 2148 - serial_port_out(port, SCBRR, t); 2149 - reg = sci_getreg(port, HSSRR); 2150 - if (reg->size) 2151 - serial_port_out(port, HSSRR, srr | HSCIF_SRE); 2152 - udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ 2153 - } else 2091 + if (best_clk >= 0) { 2092 + smr_val |= cks; 2093 + dev_dbg(port->dev, 2094 + "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n", 2095 + scr_val, smr_val, brr, sccks, dl, srr); 2096 + serial_port_out(port, SCSCR, scr_val); 2154 2097 serial_port_out(port, SCSMR, smr_val); 2098 + serial_port_out(port, SCBRR, brr); 2099 + if (sci_getreg(port, HSSRR)->size) 2100 + serial_port_out(port, HSSRR, srr | HSCIF_SRE); 2101 + 2102 + /* Wait one bit interval */ 2103 + udelay((1000000 + (baud - 1)) / baud); 2104 + } else { 2105 + /* Don't touch the bit rate configuration */ 2106 + scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0); 2107 + smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS; 2108 + dev_dbg(port->dev, "SCR 0x%x SMR 0x%x\n", scr_val, smr_val); 2109 + serial_port_out(port, SCSCR, scr_val); 2110 + serial_port_out(port, SCSMR, smr_val); 2111 + } 2155 2112 2156 2113 sci_init_pins(port, termios->c_cflag); 2157 2114 ··· 2258 2051 serial_port_out(port, SCFCR, ctrl); 2259 2052 } 2260 2053 2261 - serial_port_out(port, SCSCR, s->cfg->scscr); 2054 + scr_val |= s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0); 2055 + dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val); 2056 + serial_port_out(port, SCSCR, scr_val); 2262 2057 2263 2058 #ifdef CONFIG_SERIAL_SH_SCI_DMA 2264 2059 /* ··· 2450 2241 #endif 2451 2242 }; 2452 2243 2244 + static int sci_init_clocks(struct sci_port *sci_port, struct device *dev) 2245 + { 2246 + const char *clk_names[] = { 2247 + [SCI_FCK] = "fck", 2248 + [SCI_SCK] = "sck", 2249 + [SCI_BRG_INT] = "brg_int", 2250 + [SCI_SCIF_CLK] = "scif_clk", 2251 + }; 2252 + struct clk *clk; 2253 + unsigned int i; 2254 + 2255 + if (sci_port->cfg->type == PORT_HSCIF) 2256 + clk_names[SCI_SCK] = "hsck"; 2257 + 2258 + for (i = 0; i < SCI_NUM_CLKS; i++) { 2259 + clk = devm_clk_get(dev, clk_names[i]); 2260 + if (PTR_ERR(clk) == -EPROBE_DEFER) 2261 + return -EPROBE_DEFER; 2262 + 2263 + if (IS_ERR(clk) && i == SCI_FCK) { 2264 + /* 2265 + * "fck" used to be called "sci_ick", and we need to 2266 + * maintain DT backward compatibility. 2267 + */ 2268 + clk = devm_clk_get(dev, "sci_ick"); 2269 + if (PTR_ERR(clk) == -EPROBE_DEFER) 2270 + return -EPROBE_DEFER; 2271 + 2272 + if (!IS_ERR(clk)) 2273 + goto found; 2274 + 2275 + /* 2276 + * Not all SH platforms declare a clock lookup entry 2277 + * for SCI devices, in which case we need to get the 2278 + * global "peripheral_clk" clock. 2279 + */ 2280 + clk = devm_clk_get(dev, "peripheral_clk"); 2281 + if (!IS_ERR(clk)) 2282 + goto found; 2283 + 2284 + dev_err(dev, "failed to get %s (%ld)\n", clk_names[i], 2285 + PTR_ERR(clk)); 2286 + return PTR_ERR(clk); 2287 + } 2288 + 2289 + found: 2290 + if (IS_ERR(clk)) 2291 + dev_dbg(dev, "failed to get %s (%ld)\n", clk_names[i], 2292 + PTR_ERR(clk)); 2293 + else 2294 + dev_dbg(dev, "clk %s is %pC rate %pCr\n", clk_names[i], 2295 + clk, clk); 2296 + sci_port->clks[i] = IS_ERR(clk) ? NULL : clk; 2297 + } 2298 + return 0; 2299 + } 2300 + 2453 2301 static int sci_init_single(struct platform_device *dev, 2454 2302 struct sci_port *sci_port, unsigned int index, 2455 2303 struct plat_sci_port *p, bool early) ··· 2599 2333 sci_port->sampling_rate = p->sampling_rate; 2600 2334 2601 2335 if (!early) { 2602 - sci_port->iclk = clk_get(&dev->dev, "sci_ick"); 2603 - if (IS_ERR(sci_port->iclk)) { 2604 - sci_port->iclk = clk_get(&dev->dev, "peripheral_clk"); 2605 - if (IS_ERR(sci_port->iclk)) { 2606 - dev_err(&dev->dev, "can't get iclk\n"); 2607 - return PTR_ERR(sci_port->iclk); 2608 - } 2609 - } 2610 - 2611 - /* 2612 - * The function clock is optional, ignore it if we can't 2613 - * find it. 2614 - */ 2615 - sci_port->fclk = clk_get(&dev->dev, "sci_fck"); 2616 - if (IS_ERR(sci_port->fclk)) 2617 - sci_port->fclk = NULL; 2336 + ret = sci_init_clocks(sci_port, &dev->dev); 2337 + if (ret < 0) 2338 + return ret; 2618 2339 2619 2340 port->dev = &dev->dev; 2620 2341 ··· 2658 2405 2659 2406 static void sci_cleanup_single(struct sci_port *port) 2660 2407 { 2661 - clk_put(port->iclk); 2662 - clk_put(port->fclk); 2663 - 2664 2408 pm_runtime_disable(port->port.dev); 2665 2409 } 2666 2410 ··· 2676 2426 { 2677 2427 struct sci_port *sci_port = &sci_ports[co->index]; 2678 2428 struct uart_port *port = &sci_port->port; 2679 - unsigned short bits, ctrl; 2429 + unsigned short bits, ctrl, ctrl_temp; 2680 2430 unsigned long flags; 2681 2431 int locked = 1; 2682 2432 ··· 2688 2438 else 2689 2439 spin_lock(&port->lock); 2690 2440 2691 - /* first save the SCSCR then disable the interrupts */ 2441 + /* first save SCSCR then disable interrupts, keep clock source */ 2692 2442 ctrl = serial_port_in(port, SCSCR); 2693 - serial_port_out(port, SCSCR, sci_port->cfg->scscr); 2443 + ctrl_temp = (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) | 2444 + (ctrl & (SCSCR_CKE1 | SCSCR_CKE0)); 2445 + serial_port_out(port, SCSCR, ctrl_temp); 2694 2446 2695 2447 uart_console_write(port, s, count, serial_console_putchar); 2696 2448 ··· 2821 2569 return 0; 2822 2570 } 2823 2571 2824 - struct sci_port_info { 2825 - unsigned int type; 2826 - unsigned int regtype; 2827 - }; 2572 + 2573 + #define SCI_OF_DATA(type, regtype) (void *)((type) << 16 | (regtype)) 2574 + #define SCI_OF_TYPE(data) ((unsigned long)(data) >> 16) 2575 + #define SCI_OF_REGTYPE(data) ((unsigned long)(data) & 0xffff) 2828 2576 2829 2577 static const struct of_device_id of_sci_match[] = { 2578 + /* SoC-specific types */ 2579 + { 2580 + .compatible = "renesas,scif-r7s72100", 2581 + .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE), 2582 + }, 2583 + /* Family-specific types */ 2584 + { 2585 + .compatible = "renesas,rcar-gen1-scif", 2586 + .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE), 2587 + }, { 2588 + .compatible = "renesas,rcar-gen2-scif", 2589 + .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE), 2590 + }, { 2591 + .compatible = "renesas,rcar-gen3-scif", 2592 + .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE), 2593 + }, 2594 + /* Generic types */ 2830 2595 { 2831 2596 .compatible = "renesas,scif", 2832 - .data = &(const struct sci_port_info) { 2833 - .type = PORT_SCIF, 2834 - .regtype = SCIx_SH4_SCIF_REGTYPE, 2835 - }, 2597 + .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE), 2836 2598 }, { 2837 2599 .compatible = "renesas,scifa", 2838 - .data = &(const struct sci_port_info) { 2839 - .type = PORT_SCIFA, 2840 - .regtype = SCIx_SCIFA_REGTYPE, 2841 - }, 2600 + .data = SCI_OF_DATA(PORT_SCIFA, SCIx_SCIFA_REGTYPE), 2842 2601 }, { 2843 2602 .compatible = "renesas,scifb", 2844 - .data = &(const struct sci_port_info) { 2845 - .type = PORT_SCIFB, 2846 - .regtype = SCIx_SCIFB_REGTYPE, 2847 - }, 2603 + .data = SCI_OF_DATA(PORT_SCIFB, SCIx_SCIFB_REGTYPE), 2848 2604 }, { 2849 2605 .compatible = "renesas,hscif", 2850 - .data = &(const struct sci_port_info) { 2851 - .type = PORT_HSCIF, 2852 - .regtype = SCIx_HSCIF_REGTYPE, 2853 - }, 2606 + .data = SCI_OF_DATA(PORT_HSCIF, SCIx_HSCIF_REGTYPE), 2854 2607 }, { 2855 2608 .compatible = "renesas,sci", 2856 - .data = &(const struct sci_port_info) { 2857 - .type = PORT_SCI, 2858 - .regtype = SCIx_SCI_REGTYPE, 2859 - }, 2609 + .data = SCI_OF_DATA(PORT_SCI, SCIx_SCI_REGTYPE), 2860 2610 }, { 2861 2611 /* Terminator */ 2862 2612 }, ··· 2870 2616 { 2871 2617 struct device_node *np = pdev->dev.of_node; 2872 2618 const struct of_device_id *match; 2873 - const struct sci_port_info *info; 2874 2619 struct plat_sci_port *p; 2875 2620 int id; 2876 2621 2877 2622 if (!IS_ENABLED(CONFIG_OF) || !np) 2878 2623 return NULL; 2879 2624 2880 - match = of_match_node(of_sci_match, pdev->dev.of_node); 2625 + match = of_match_node(of_sci_match, np); 2881 2626 if (!match) 2882 2627 return NULL; 2883 - 2884 - info = match->data; 2885 2628 2886 2629 p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL); 2887 2630 if (!p) 2888 2631 return NULL; 2889 2632 2890 - /* Get the line number for the aliases node. */ 2633 + /* Get the line number from the aliases node. */ 2891 2634 id = of_alias_get_id(np, "serial"); 2892 2635 if (id < 0) { 2893 2636 dev_err(&pdev->dev, "failed to get alias id (%d)\n", id); ··· 2894 2643 *dev_id = id; 2895 2644 2896 2645 p->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 2897 - p->type = info->type; 2898 - p->regtype = info->regtype; 2646 + p->type = SCI_OF_TYPE(match->data); 2647 + p->regtype = SCI_OF_REGTYPE(match->data); 2899 2648 p->scscr = SCSCR_RE | SCSCR_TE; 2900 2649 2901 2650 return p;
+10
drivers/tty/serial/sh-sci.h
··· 27 27 HSSRR, /* Sampling Rate Register */ 28 28 SCPCR, /* Serial Port Control Register */ 29 29 SCPDR, /* Serial Port Data Register */ 30 + SCDL, /* BRG Frequency Division Register */ 31 + SCCKS, /* BRG Clock Select Register */ 30 32 31 33 SCIx_NR_REGS, 32 34 }; ··· 111 109 #define SCPDR_RTSD BIT(4) /* Serial Port RTS Output Pin Data */ 112 110 #define SCPDR_CTSD BIT(3) /* Serial Port CTS Input Pin Data */ 113 111 112 + /* 113 + * BRG Clock Select Register (Some SCIF and HSCIF) 114 + * The Baud Rate Generator for external clock can provide a clock source for 115 + * the sampling clock. It outputs either its frequency divided clock, or the 116 + * (undivided) (H)SCK external clock. 117 + */ 118 + #define SCCKS_CKS BIT(15) /* Select (H)SCK (1) or divided SC_CLK (0) */ 119 + #define SCCKS_XIN BIT(14) /* SC_CLK uses bus clock (1) or SCIF_CLK (0) */ 114 120 115 121 #define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND) 116 122 #define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
+1
include/linux/serial_sci.h
··· 32 32 SCIx_SH2_SCIF_FIFODATA_REGTYPE, 33 33 SCIx_SH3_SCIF_REGTYPE, 34 34 SCIx_SH4_SCIF_REGTYPE, 35 + SCIx_SH4_SCIF_BRG_REGTYPE, 35 36 SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE, 36 37 SCIx_SH4_SCIF_FIFODATA_REGTYPE, 37 38 SCIx_SH7705_SCIF_REGTYPE,