All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-14 18:57 ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

	Hi Greg, Simon, Magnus, Sato-san,

This patch series contains several patches for the Renesas SCI serial
driver:
  - Clean up the naming of clocks in the driver and its DT bindings,
  - Add support for the optional external clock on (H)SCI(F) and some
    SCIFA, 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.
Using external clocks increases the range and accuracy of supported baud
rates.

This series is an updated version of the core (driver) changes of two
series I sent before:
  - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
    (http://www.spinics.net/lists/linux-serial/msg19762.html)
  - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
    (https://lkml.org/lkml/2015/11/19/550)
To reduce (cross) dependencies, I split off the integration (DTS)
patches into separate series:
  - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
     strings",
  - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
     clock to fck",
  - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
  - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
    pins".
As the SH architecture is orphaned, and the risk of conflicts is small,
I have bundled all SH-specific changes with the core changes.  This
reduces dependencies, too.

Changes compared to previous submission (more detailed information in
the individual patches):
  - Add fallback compatibility strings for R-Car Gen1, Gen2, Gen3, which
    allows the driver to match on (less) family-specific instead of
    (more) SoC-specific compatible values,
  - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
  - Terminate loops over sampling rates on perfect matches,
  - Many comments and clarifications in patch descriptions,
  - Add Acked-by, Reviewed-by.


This series consists of several parts:
  - The first four patches update DT binding documentation.
    The first patch also updates the driver, and is a hard dependency
    for the integration (DTS) patches, and for the SH patches.

    [01/27] serial: sh-sci: Drop the interface clock
    [02/27] serial: sh-sci: Add fallback compatibility strings (NEW)
    [03/27] serial: sh-sci: Update DT binding documentation for external
			    clock input
    [04/27] serial: sh-sci: Update DT binding documentation for BRG
			    support

  - Patches 5-23 update the driver only, and add external clock and BRG
    support.

    [05/27] serial: sh-sci: Drop useless check for zero
    [06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
    [07/27] serial: sh-sci: Use existing local variable in
			    sci_parse_dt() (NEW)
    [08/27] serial: sh-sci: Drop unused frame_len parameter for
			    sci_baud_calc_hscif()
    [09/27] serial: sh-sci: Don't overwrite clock selection in
			    serial_console_write()
    [10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
    [11/27] serial: sh-sci: Make unsigned values in
			    sci_baud_calc_hscif() unsigned
    [12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
    [13/27] serial: sh-sci: Improve bit rate error calculation for
			    HSCIF
    [14/27] serial: sh-sci: Avoid calculating the receive margin for
			    HSCIF
    [15/27] serial: sh-sci: Merge sci_scbrr_calc() and
			    sci_baud_calc_hscif()
    [16/27] serial: sh-sci: Take into account sampling rate for max baud
			    rate
    [17/27] serial: sh-sci: Add BRG register definitions
    [18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype
			    encoding
    [19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
    [20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
    [21/27] serial: sh-sci: Prepare for multiple sampling clock sources
    [22/27] serial: sh-sci: Add support for optional external (H)SCK
			    input
    [23/27] serial: sh-sci: Add support for optional BRG on H)SCIF

  - Patches 24-26 update the SH architecture.
    Patches 24 and 25 have a hard dependency on patch 1.
    Patch 26 has a hard dependency on patch 17.

    [24/27] sh: Rename sci_ick and sci_fck clock to fck
    [25/27] sh: Remove sci_ick clock alias
    [26/27] sh: sh7734: Correct SCIF type for BRG

  - Patch 27 has a hard dependency on patch 24.

    [27/27] serial: sh-sci: Drop the sci_fck clock fallback

Testing:
  - The Baud Rate Generator for External Clock (BRG) was tested on
      - R-Car Gen1 (r8a7778/bockw, r8a7779/marzen, on SCIF),
      - R-Car Gen2 (r8a7791/koelsch, on SCIF and HSCIF),
      - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
  - The external clock input on (H)SCK was tested on
      - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
  - Regression testing was done on Renesas ARM platforms that use SCIFA
    as the console (r8a73a4/ape6evm, r8a7740/armadillo, and
    sh73a0/kzm9g),
  - You can find more testing-related information in the final
    integration series.

Merge strategy:
  - This series applies to v4.4-rc1,
  - It would be good if at least the first 4 patches end up in v4.5, as
    they contain DT bindings, and a hard dependency for some DTS
    updates,
  - If the 3 SH patches 24-26, and patch 27 go in together, this can be
    done in the same release. Else the SH patches may have to wait for
    v4.6, and patch 27 for v4.7.
  - Greg has provided his ack for most patches (minus the SH-specific,
    and the 2 new patches), and is OK for the patches going in through
    another tree, so these could go in through Simon's tree as well,
      - If these patches go in through Greg's tree, the DTS updates with
	a hard dependency on the first patch have to wait for v4.6,
      - If these patches go in through Simon's tree, the DTS updates
	with a hard dependency on the first patch can go in v4.5, too,
  - Note that some of the DTS updates have to wait for v4.6 due to other
    dependencies (pinctrl, more info in the integration series),
  - Note that there are a few unrelated sh-sci fixes floating around.
    I think these should go through Greg's tree anyway (they are
    unrelated, and I don't think these cause conflicts).

Greg/Simon, what do you think?

I've also pushed this series (against v4.4-rc1) to the
topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
repository at
https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git

For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
as it includes the integration part.

Thanks for applying!

Geert Uytterhoeven (23):
  serial: sh-sci: Add fallback compatibility strings
  serial: sh-sci: Update DT binding documentation for external clock
    input
  serial: sh-sci: Update DT binding documentation for BRG support
  serial: sh-sci: Drop useless check for zero sampling_rate
  serial: sh-sci: Grammar s/Get ... for/Get ... from/
  serial: sh-sci: Use existing local variable in sci_parse_dt()
  serial: sh-sci: Drop unused frame_len parameter for
    sci_baud_calc_hscif()
  serial: sh-sci: Don't overwrite clock selection in
    serial_console_write()
  serial: sh-sci: Convert from clk_get() to devm_clk_get()
  serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
  serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
  serial: sh-sci: Improve bit rate error calculation for HSCIF
  serial: sh-sci: Avoid calculating the receive margin for HSCIF
  serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
  serial: sh-sci: Take into account sampling rate for max baud rate
  serial: sh-sci: Add BRG register definitions
  serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
  serial: sh-sci: Correct SCIF type on RZ/A1H
  serial: sh-sci: Correct SCIF type on R-Car for BRG
  serial: sh-sci: Prepare for multiple sampling clock sources
  serial: sh-sci: Add support for optional external (H)SCK input
  serial: sh-sci: Add support for optional BRG on (H)SCIF
  sh: sh7734: Correct SCIF type for BRG

Laurent Pinchart (4):
  serial: sh-sci: Drop the interface clock
  sh: Rename sci_ick and sci_fck clock to fck
  sh: Remove sci_ick clock alias
  serial: sh-sci: Drop the sci_fck clock fallback

 .../bindings/serial/renesas,sci-serial.txt         |  32 +-
 arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
 drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
 drivers/tty/serial/sh-sci.h                        |  10 +
 include/linux/serial_sci.h                         |   1 +
 16 files changed, 500 insertions(+), 212 deletions(-)

-- 
1.9.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

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

* [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-14 18:57 ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

	Hi Greg, Simon, Magnus, Sato-san,

This patch series contains several patches for the Renesas SCI serial
driver:
  - Clean up the naming of clocks in the driver and its DT bindings,
  - Add support for the optional external clock on (H)SCI(F) and some
    SCIFA, 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.
Using external clocks increases the range and accuracy of supported baud
rates.

This series is an updated version of the core (driver) changes of two
series I sent before:
  - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
    (http://www.spinics.net/lists/linux-serial/msg19762.html)
  - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
    (https://lkml.org/lkml/2015/11/19/550)
To reduce (cross) dependencies, I split off the integration (DTS)
patches into separate series:
  - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
     strings",
  - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
     clock to fck",
  - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
  - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
    pins".
As the SH architecture is orphaned, and the risk of conflicts is small,
I have bundled all SH-specific changes with the core changes.  This
reduces dependencies, too.

Changes compared to previous submission (more detailed information in
the individual patches):
  - Add fallback compatibility strings for R-Car Gen1, Gen2, Gen3, which
    allows the driver to match on (less) family-specific instead of
    (more) SoC-specific compatible values,
  - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
  - Terminate loops over sampling rates on perfect matches,
  - Many comments and clarifications in patch descriptions,
  - Add Acked-by, Reviewed-by.


This series consists of several parts:
  - The first four patches update DT binding documentation.
    The first patch also updates the driver, and is a hard dependency
    for the integration (DTS) patches, and for the SH patches.

    [01/27] serial: sh-sci: Drop the interface clock
    [02/27] serial: sh-sci: Add fallback compatibility strings (NEW)
    [03/27] serial: sh-sci: Update DT binding documentation for external
			    clock input
    [04/27] serial: sh-sci: Update DT binding documentation for BRG
			    support

  - Patches 5-23 update the driver only, and add external clock and BRG
    support.

    [05/27] serial: sh-sci: Drop useless check for zero
    [06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
    [07/27] serial: sh-sci: Use existing local variable in
			    sci_parse_dt() (NEW)
    [08/27] serial: sh-sci: Drop unused frame_len parameter for
			    sci_baud_calc_hscif()
    [09/27] serial: sh-sci: Don't overwrite clock selection in
			    serial_console_write()
    [10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
    [11/27] serial: sh-sci: Make unsigned values in
			    sci_baud_calc_hscif() unsigned
    [12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
    [13/27] serial: sh-sci: Improve bit rate error calculation for
			    HSCIF
    [14/27] serial: sh-sci: Avoid calculating the receive margin for
			    HSCIF
    [15/27] serial: sh-sci: Merge sci_scbrr_calc() and
			    sci_baud_calc_hscif()
    [16/27] serial: sh-sci: Take into account sampling rate for max baud
			    rate
    [17/27] serial: sh-sci: Add BRG register definitions
    [18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype
			    encoding
    [19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
    [20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
    [21/27] serial: sh-sci: Prepare for multiple sampling clock sources
    [22/27] serial: sh-sci: Add support for optional external (H)SCK
			    input
    [23/27] serial: sh-sci: Add support for optional BRG on H)SCIF

  - Patches 24-26 update the SH architecture.
    Patches 24 and 25 have a hard dependency on patch 1.
    Patch 26 has a hard dependency on patch 17.

    [24/27] sh: Rename sci_ick and sci_fck clock to fck
    [25/27] sh: Remove sci_ick clock alias
    [26/27] sh: sh7734: Correct SCIF type for BRG

  - Patch 27 has a hard dependency on patch 24.

    [27/27] serial: sh-sci: Drop the sci_fck clock fallback

Testing:
  - The Baud Rate Generator for External Clock (BRG) was tested on
      - R-Car Gen1 (r8a7778/bockw, r8a7779/marzen, on SCIF),
      - R-Car Gen2 (r8a7791/koelsch, on SCIF and HSCIF),
      - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
  - The external clock input on (H)SCK was tested on
      - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
  - Regression testing was done on Renesas ARM platforms that use SCIFA
    as the console (r8a73a4/ape6evm, r8a7740/armadillo, and
    sh73a0/kzm9g),
  - You can find more testing-related information in the final
    integration series.

Merge strategy:
  - This series applies to v4.4-rc1,
  - It would be good if at least the first 4 patches end up in v4.5, as
    they contain DT bindings, and a hard dependency for some DTS
    updates,
  - If the 3 SH patches 24-26, and patch 27 go in together, this can be
    done in the same release. Else the SH patches may have to wait for
    v4.6, and patch 27 for v4.7.
  - Greg has provided his ack for most patches (minus the SH-specific,
    and the 2 new patches), and is OK for the patches going in through
    another tree, so these could go in through Simon's tree as well,
      - If these patches go in through Greg's tree, the DTS updates with
	a hard dependency on the first patch have to wait for v4.6,
      - If these patches go in through Simon's tree, the DTS updates
	with a hard dependency on the first patch can go in v4.5, too,
  - Note that some of the DTS updates have to wait for v4.6 due to other
    dependencies (pinctrl, more info in the integration series),
  - Note that there are a few unrelated sh-sci fixes floating around.
    I think these should go through Greg's tree anyway (they are
    unrelated, and I don't think these cause conflicts).

Greg/Simon, what do you think?

I've also pushed this series (against v4.4-rc1) to the
topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
repository at
https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git

For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
as it includes the integration part.

Thanks for applying!

Geert Uytterhoeven (23):
  serial: sh-sci: Add fallback compatibility strings
  serial: sh-sci: Update DT binding documentation for external clock
    input
  serial: sh-sci: Update DT binding documentation for BRG support
  serial: sh-sci: Drop useless check for zero sampling_rate
  serial: sh-sci: Grammar s/Get ... for/Get ... from/
  serial: sh-sci: Use existing local variable in sci_parse_dt()
  serial: sh-sci: Drop unused frame_len parameter for
    sci_baud_calc_hscif()
  serial: sh-sci: Don't overwrite clock selection in
    serial_console_write()
  serial: sh-sci: Convert from clk_get() to devm_clk_get()
  serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
  serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
  serial: sh-sci: Improve bit rate error calculation for HSCIF
  serial: sh-sci: Avoid calculating the receive margin for HSCIF
  serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
  serial: sh-sci: Take into account sampling rate for max baud rate
  serial: sh-sci: Add BRG register definitions
  serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
  serial: sh-sci: Correct SCIF type on RZ/A1H
  serial: sh-sci: Correct SCIF type on R-Car for BRG
  serial: sh-sci: Prepare for multiple sampling clock sources
  serial: sh-sci: Add support for optional external (H)SCK input
  serial: sh-sci: Add support for optional BRG on (H)SCIF
  sh: sh7734: Correct SCIF type for BRG

Laurent Pinchart (4):
  serial: sh-sci: Drop the interface clock
  sh: Rename sci_ick and sci_fck clock to fck
  sh: Remove sci_ick clock alias
  serial: sh-sci: Drop the sci_fck clock fallback

 .../bindings/serial/renesas,sci-serial.txt         |  32 +-
 arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
 drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
 drivers/tty/serial/sh-sci.h                        |  10 +
 include/linux/serial_sci.h                         |   1 +
 16 files changed, 500 insertions(+), 212 deletions(-)

-- 
1.9.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

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

* [PATCH v3 01/27] serial: sh-sci: Drop the interface clock
       [not found] ` <1450119456-964-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
@ 2015-12-14 18:57     ` Geert Uytterhoeven
  2015-12-14 18:57     ` Geert Uytterhoeven
  1 sibling, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-sh-u79uwXL29TY76Z2rM5mHXA, Laurent Pinchart,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

As no platform defines an interface clock the SCI driver always falls
back to a clock named "peripheral_clk".
  - On SH platforms that clock is the base clock for the SCI functional
    clock and has the same frequency,
  - On ARM platforms that clock doesn't exist, and clk_get() will return
    the default clock for the device.
We can thus make the functional clock mandatory and drop the interface
clock.

EPROBE_DEFER is handled for clocks that may be referenced from DT (i.e.
"fck", and the deprecated "sci_ick").

Cc: devicetree@vger.kernel.org
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
[geert: Handle EPROBE_DEFER, reformat description, break long comment line]
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,

v2:
  - Add Acked-by,
  - Amendment by geert.
---
 .../bindings/serial/renesas,sci-serial.txt         |  4 +-
 drivers/tty/serial/sh-sci.c                        | 64 ++++++++++++++--------
 2 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 73f825e5e6448815..2c9e6b8477e92792 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -42,7 +42,7 @@ Required properties:
 
   - clocks: Must contain a phandle and clock-specifier pair for each entry
     in clock-names.
-  - clock-names: Must contain "sci_ick" for the SCIx UART interface clock.
+  - clock-names: Must contain "fck" for the SCIx UART functional clock.
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
@@ -63,7 +63,7 @@ Example:
 		interrupt-parent = <&gic>;
 		interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&mstp2_clks R8A7790_CLK_SCIFA0>;
-		clock-names = "sci_ick";
+		clock-names = "fck";
 		dmas = <&dmac0 0x21>, <&dmac0 0x22>;
 		dma-names = "tx", "rx";
 	};
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 960e50a97558cff5..cc6fa55231ba3536 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -92,8 +92,6 @@ struct sci_port {
 	struct timer_list	break_timer;
 	int			break_flag;
 
-	/* Interface clock */
-	struct clk		*iclk;
 	/* Function clock */
 	struct clk		*fclk;
 
@@ -457,9 +455,8 @@ static void sci_port_enable(struct sci_port *sci_port)
 
 	pm_runtime_get_sync(sci_port->port.dev);
 
-	clk_prepare_enable(sci_port->iclk);
-	sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
 	clk_prepare_enable(sci_port->fclk);
+	sci_port->port.uartclk = clk_get_rate(sci_port->fclk);
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
@@ -476,7 +473,6 @@ static void sci_port_disable(struct sci_port *sci_port)
 	sci_port->break_flag = 0;
 
 	clk_disable_unprepare(sci_port->fclk);
-	clk_disable_unprepare(sci_port->iclk);
 
 	pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -1622,7 +1618,7 @@ static int sci_notifier(struct notifier_block *self,
 		struct uart_port *port = &sci_port->port;
 
 		spin_lock_irqsave(&port->lock, flags);
-		port->uartclk = clk_get_rate(sci_port->iclk);
+		port->uartclk = clk_get_rate(sci_port->fclk);
 		spin_unlock_irqrestore(&port->lock, flags);
 	}
 
@@ -2241,6 +2237,42 @@ static struct uart_ops sci_uart_ops = {
 #endif
 };
 
+static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
+{
+	/* Get the SCI functional clock. It's called "fck" on ARM. */
+	sci_port->fclk = clk_get(dev, "fck");
+	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/*
+	 * But it used to be called "sci_ick", and we need to maintain DT
+	 * backward compatibility.
+	 */
+	sci_port->fclk = clk_get(dev, "sci_ick");
+	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/* SH has historically named the clock "sci_fck". */
+	sci_port->fclk = clk_get(dev, "sci_fck");
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/*
+	 * Not all SH platforms declare a clock lookup entry for SCI devices,
+	 * in which case we need to get the global "peripheral_clk" clock.
+	 */
+	sci_port->fclk = clk_get(dev, "peripheral_clk");
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	dev_err(dev, "failed to get functional clock\n");
+	return PTR_ERR(sci_port->fclk);
+}
+
 static int sci_init_single(struct platform_device *dev,
 			   struct sci_port *sci_port, unsigned int index,
 			   struct plat_sci_port *p, bool early)
@@ -2333,22 +2365,9 @@ static int sci_init_single(struct platform_device *dev,
 		sci_port->sampling_rate = p->sampling_rate;
 
 	if (!early) {
-		sci_port->iclk = clk_get(&dev->dev, "sci_ick");
-		if (IS_ERR(sci_port->iclk)) {
-			sci_port->iclk = clk_get(&dev->dev, "peripheral_clk");
-			if (IS_ERR(sci_port->iclk)) {
-				dev_err(&dev->dev, "can't get iclk\n");
-				return PTR_ERR(sci_port->iclk);
-			}
-		}
-
-		/*
-		 * The function clock is optional, ignore it if we can't
-		 * find it.
-		 */
-		sci_port->fclk = clk_get(&dev->dev, "sci_fck");
-		if (IS_ERR(sci_port->fclk))
-			sci_port->fclk = NULL;
+		ret = sci_init_clocks(sci_port, &dev->dev);
+		if (ret < 0)
+			return ret;
 
 		port->dev = &dev->dev;
 
@@ -2405,7 +2424,6 @@ static int sci_init_single(struct platform_device *dev,
 
 static void sci_cleanup_single(struct sci_port *port)
 {
-	clk_put(port->iclk);
 	clk_put(port->fclk);
 
 	pm_runtime_disable(port->port.dev);
-- 
1.9.1


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

* [PATCH v3 01/27] serial: sh-sci: Drop the interface clock
@ 2015-12-14 18:57     ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-sh-u79uwXL29TY76Z2rM5mHXA, Laurent Pinchart,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>

As no platform defines an interface clock the SCI driver always falls
back to a clock named "peripheral_clk".
  - On SH platforms that clock is the base clock for the SCI functional
    clock and has the same frequency,
  - On ARM platforms that clock doesn't exist, and clk_get() will return
    the default clock for the device.
We can thus make the functional clock mandatory and drop the interface
clock.

EPROBE_DEFER is handled for clocks that may be referenced from DT (i.e.
"fck", and the deprecated "sci_ick").

Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
Acked-by: Simon Horman <horms+renesas-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org>
[geert: Handle EPROBE_DEFER, reformat description, break long comment line]
Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Acked-by: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
---
v3:
  - Add Acked-by,

v2:
  - Add Acked-by,
  - Amendment by geert.
---
 .../bindings/serial/renesas,sci-serial.txt         |  4 +-
 drivers/tty/serial/sh-sci.c                        | 64 ++++++++++++++--------
 2 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 73f825e5e6448815..2c9e6b8477e92792 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -42,7 +42,7 @@ Required properties:
 
   - clocks: Must contain a phandle and clock-specifier pair for each entry
     in clock-names.
-  - clock-names: Must contain "sci_ick" for the SCIx UART interface clock.
+  - clock-names: Must contain "fck" for the SCIx UART functional clock.
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
@@ -63,7 +63,7 @@ Example:
 		interrupt-parent = <&gic>;
 		interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&mstp2_clks R8A7790_CLK_SCIFA0>;
-		clock-names = "sci_ick";
+		clock-names = "fck";
 		dmas = <&dmac0 0x21>, <&dmac0 0x22>;
 		dma-names = "tx", "rx";
 	};
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 960e50a97558cff5..cc6fa55231ba3536 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -92,8 +92,6 @@ struct sci_port {
 	struct timer_list	break_timer;
 	int			break_flag;
 
-	/* Interface clock */
-	struct clk		*iclk;
 	/* Function clock */
 	struct clk		*fclk;
 
@@ -457,9 +455,8 @@ static void sci_port_enable(struct sci_port *sci_port)
 
 	pm_runtime_get_sync(sci_port->port.dev);
 
-	clk_prepare_enable(sci_port->iclk);
-	sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
 	clk_prepare_enable(sci_port->fclk);
+	sci_port->port.uartclk = clk_get_rate(sci_port->fclk);
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
@@ -476,7 +473,6 @@ static void sci_port_disable(struct sci_port *sci_port)
 	sci_port->break_flag = 0;
 
 	clk_disable_unprepare(sci_port->fclk);
-	clk_disable_unprepare(sci_port->iclk);
 
 	pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -1622,7 +1618,7 @@ static int sci_notifier(struct notifier_block *self,
 		struct uart_port *port = &sci_port->port;
 
 		spin_lock_irqsave(&port->lock, flags);
-		port->uartclk = clk_get_rate(sci_port->iclk);
+		port->uartclk = clk_get_rate(sci_port->fclk);
 		spin_unlock_irqrestore(&port->lock, flags);
 	}
 
@@ -2241,6 +2237,42 @@ static struct uart_ops sci_uart_ops = {
 #endif
 };
 
+static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
+{
+	/* Get the SCI functional clock. It's called "fck" on ARM. */
+	sci_port->fclk = clk_get(dev, "fck");
+	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/*
+	 * But it used to be called "sci_ick", and we need to maintain DT
+	 * backward compatibility.
+	 */
+	sci_port->fclk = clk_get(dev, "sci_ick");
+	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/* SH has historically named the clock "sci_fck". */
+	sci_port->fclk = clk_get(dev, "sci_fck");
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	/*
+	 * Not all SH platforms declare a clock lookup entry for SCI devices,
+	 * in which case we need to get the global "peripheral_clk" clock.
+	 */
+	sci_port->fclk = clk_get(dev, "peripheral_clk");
+	if (!IS_ERR(sci_port->fclk))
+		return 0;
+
+	dev_err(dev, "failed to get functional clock\n");
+	return PTR_ERR(sci_port->fclk);
+}
+
 static int sci_init_single(struct platform_device *dev,
 			   struct sci_port *sci_port, unsigned int index,
 			   struct plat_sci_port *p, bool early)
@@ -2333,22 +2365,9 @@ static int sci_init_single(struct platform_device *dev,
 		sci_port->sampling_rate = p->sampling_rate;
 
 	if (!early) {
-		sci_port->iclk = clk_get(&dev->dev, "sci_ick");
-		if (IS_ERR(sci_port->iclk)) {
-			sci_port->iclk = clk_get(&dev->dev, "peripheral_clk");
-			if (IS_ERR(sci_port->iclk)) {
-				dev_err(&dev->dev, "can't get iclk\n");
-				return PTR_ERR(sci_port->iclk);
-			}
-		}
-
-		/*
-		 * The function clock is optional, ignore it if we can't
-		 * find it.
-		 */
-		sci_port->fclk = clk_get(&dev->dev, "sci_fck");
-		if (IS_ERR(sci_port->fclk))
-			sci_port->fclk = NULL;
+		ret = sci_init_clocks(sci_port, &dev->dev);
+		if (ret < 0)
+			return ret;
 
 		port->dev = &dev->dev;
 
@@ -2405,7 +2424,6 @@ static int sci_init_single(struct platform_device *dev,
 
 static void sci_cleanup_single(struct sci_port *port)
 {
-	clk_put(port->iclk);
 	clk_put(port->fclk);
 
 	pm_runtime_disable(port->port.dev);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v3 02/27] serial: sh-sci: Add fallback compatibility strings
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Add fallback compatibility strings for R-Car Gen1, Gen2, and Gen3.
This is in keeping with the fallback scheme being adopted wherever
appropriate for drivers for Renesas SoCs.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: devicetree@vger.kernel.org
---
v3:
  - New.
---
 .../devicetree/bindings/serial/renesas,sci-serial.txt   | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 2c9e6b8477e92792..7091213f02513cda 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -2,7 +2,7 @@
 
 Required properties:
 
-  - compatible: Must contain one of the following:
+  - compatible: Must contain one or more of the following:
 
     - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART.
     - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART.
@@ -27,6 +27,14 @@ Required properties:
     - "renesas,hscif-r8a7795" for R8A7795 (R-Car H3) HSCIF compatible UART.
     - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART.
     - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART.
+    - "renesas,rcar-gen1-scif" for R-Car Gen1 SCIF compatible UART,
+    - "renesas,rcar-gen2-scif" for R-Car Gen2 SCIF compatible UART,
+    - "renesas,rcar-gen3-scif" for R-Car Gen3 SCIF compatible UART,
+    - "renesas,rcar-gen2-scifa" for R-Car Gen2 SCIFA compatible UART,
+    - "renesas,rcar-gen2-scifb" for R-Car Gen2 SCIFB compatible UART,
+    - "renesas,rcar-gen1-hscif" for R-Car Gen1 HSCIF compatible UART,
+    - "renesas,rcar-gen2-hscif" for R-Car Gen2 HSCIF compatible UART,
+    - "renesas,rcar-gen3-hscif" for R-Car Gen3 HSCIF compatible UART,
     - "renesas,scif" for generic SCIF compatible UART.
     - "renesas,scifa" for generic SCIFA compatible UART.
     - "renesas,scifb" for generic SCIFB compatible UART.
@@ -34,8 +42,8 @@ Required properties:
     - "renesas,sci" for generic SCI compatible UART.
 
     When compatible with the generic version, nodes must list the
-    SoC-specific version corresponding to the platform first followed by the
-    generic version.
+    SoC-specific version corresponding to the platform first, followed by the
+    family-specific and/or generic versions.
 
   - reg: Base address and length of the I/O registers used by the UART.
   - interrupts: Must contain an interrupt-specifier for the SCIx interrupt.
@@ -58,7 +66,8 @@ Example:
 	};
 
 	scifa0: serial@e6c40000 {
-		compatible = "renesas,scifa-r8a7790", "renesas,scifa";
+		compatible = "renesas,scifa-r8a7790",
+			     "renesas,rcar-gen2-scifa", "renesas,scifa";
 		reg = <0 0xe6c40000 0 64>;
 		interrupt-parent = <&gic>;
 		interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
-- 
1.9.1


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

* [PATCH v3 02/27] serial: sh-sci: Add fallback compatibility strings
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Add fallback compatibility strings for R-Car Gen1, Gen2, and Gen3.
This is in keeping with the fallback scheme being adopted wherever
appropriate for drivers for Renesas SoCs.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: devicetree@vger.kernel.org
---
v3:
  - New.
---
 .../devicetree/bindings/serial/renesas,sci-serial.txt   | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 2c9e6b8477e92792..7091213f02513cda 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -2,7 +2,7 @@
 
 Required properties:
 
-  - compatible: Must contain one of the following:
+  - compatible: Must contain one or more of the following:
 
     - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART.
     - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART.
@@ -27,6 +27,14 @@ Required properties:
     - "renesas,hscif-r8a7795" for R8A7795 (R-Car H3) HSCIF compatible UART.
     - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART.
     - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART.
+    - "renesas,rcar-gen1-scif" for R-Car Gen1 SCIF compatible UART,
+    - "renesas,rcar-gen2-scif" for R-Car Gen2 SCIF compatible UART,
+    - "renesas,rcar-gen3-scif" for R-Car Gen3 SCIF compatible UART,
+    - "renesas,rcar-gen2-scifa" for R-Car Gen2 SCIFA compatible UART,
+    - "renesas,rcar-gen2-scifb" for R-Car Gen2 SCIFB compatible UART,
+    - "renesas,rcar-gen1-hscif" for R-Car Gen1 HSCIF compatible UART,
+    - "renesas,rcar-gen2-hscif" for R-Car Gen2 HSCIF compatible UART,
+    - "renesas,rcar-gen3-hscif" for R-Car Gen3 HSCIF compatible UART,
     - "renesas,scif" for generic SCIF compatible UART.
     - "renesas,scifa" for generic SCIFA compatible UART.
     - "renesas,scifb" for generic SCIFB compatible UART.
@@ -34,8 +42,8 @@ Required properties:
     - "renesas,sci" for generic SCI compatible UART.
 
     When compatible with the generic version, nodes must list the
-    SoC-specific version corresponding to the platform first followed by the
-    generic version.
+    SoC-specific version corresponding to the platform first, followed by the
+    family-specific and/or generic versions.
 
   - reg: Base address and length of the I/O registers used by the UART.
   - interrupts: Must contain an interrupt-specifier for the SCIx interrupt.
@@ -58,7 +66,8 @@ Example:
 	};
 
 	scifa0: serial@e6c40000 {
-		compatible = "renesas,scifa-r8a7790", "renesas,scifa";
+		compatible = "renesas,scifa-r8a7790",
+			     "renesas,rcar-gen2-scifa", "renesas,scifa";
 		reg = <0 0xe6c40000 0 64>;
 		interrupt-parent = <&gic>;
 		interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
-- 
1.9.1


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

* [PATCH v3 03/27] serial: sh-sci: Update DT binding documentation for external clock input
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Amend the DT bindings to include the optional external clock on
(H)SCI(F) and some SCIFA, where this pin can serve as a clock input,
depending on board wiring.

Clarify the use of the divided functional clock as a source for the
sampling clock.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devicetree@vger.kernel.org
---
v3:
  - Add Acked-by,
  - Clarify the use of the divided functional clock.
---
 Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 7091213f02513cda..31cc0631ef7ca22d 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -51,6 +51,11 @@ Required properties:
   - clocks: Must contain a phandle and clock-specifier pair for each entry
     in clock-names.
   - clock-names: Must contain "fck" for the SCIx UART functional clock.
+    Apart from the divided functional clock, there may be other possible
+    sources for the sampling clock, depending on SCIx variant.
+    On (H)SCI(F) and some SCIFA, an additional clock may be specified:
+      - "hsck" for the optional external clock input (on HSCIF),
+      - "sck" for the optional external clock input (on other variants).
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
-- 
1.9.1


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

* [PATCH v3 03/27] serial: sh-sci: Update DT binding documentation for external clock input
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Amend the DT bindings to include the optional external clock on
(H)SCI(F) and some SCIFA, where this pin can serve as a clock input,
depending on board wiring.

Clarify the use of the divided functional clock as a source for the
sampling clock.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devicetree@vger.kernel.org
---
v3:
  - Add Acked-by,
  - Clarify the use of the divided functional clock.
---
 Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 7091213f02513cda..31cc0631ef7ca22d 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -51,6 +51,11 @@ Required properties:
   - clocks: Must contain a phandle and clock-specifier pair for each entry
     in clock-names.
   - clock-names: Must contain "fck" for the SCIx UART functional clock.
+    Apart from the divided functional clock, there may be other possible
+    sources for the sampling clock, depending on SCIx variant.
+    On (H)SCI(F) and some SCIFA, an additional clock may be specified:
+      - "hsck" for the optional external clock input (on HSCIF),
+      - "sck" for the optional external clock input (on other variants).
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
-- 
1.9.1


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

* [PATCH v3 04/27] serial: sh-sci: Update DT binding documentation for BRG support
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Amend the DT bindings to include the optional clock sources for the Baud
Rate Generator for External Clock (BRG), as found on some SCIF variants
and on HSCIF.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devicetree@vger.kernel.org
---
v3:
  - Add Acked-by,
  - Rename "int_clk" to "brg_int".
---
 Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 31cc0631ef7ca22d..f4ad30ef1628f8da 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -56,6 +56,12 @@ Required properties:
     On (H)SCI(F) and some SCIFA, an additional clock may be specified:
       - "hsck" for the optional external clock input (on HSCIF),
       - "sck" for the optional external clock input (on other variants).
+    On UARTs equipped with a Baud Rate Generator for External Clock (BRG)
+    (some SCIF and HSCIF), additional clocks may be specified:
+      - "brg_int" for the optional internal clock source for the frequency
+	divider (typically the (AXI or SHwy) bus clock),
+      - "scif_clk" for the optional external clock source for the frequency
+	divider (SCIF_CLK).
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
-- 
1.9.1


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

* [PATCH v3 04/27] serial: sh-sci: Update DT binding documentation for BRG support
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven, devicetree

Amend the DT bindings to include the optional clock sources for the Baud
Rate Generator for External Clock (BRG), as found on some SCIF variants
and on HSCIF.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devicetree@vger.kernel.org
---
v3:
  - Add Acked-by,
  - Rename "int_clk" to "brg_int".
---
 Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index 31cc0631ef7ca22d..f4ad30ef1628f8da 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -56,6 +56,12 @@ Required properties:
     On (H)SCI(F) and some SCIFA, an additional clock may be specified:
       - "hsck" for the optional external clock input (on HSCIF),
       - "sck" for the optional external clock input (on other variants).
+    On UARTs equipped with a Baud Rate Generator for External Clock (BRG)
+    (some SCIF and HSCIF), additional clocks may be specified:
+      - "brg_int" for the optional internal clock source for the frequency
+	divider (typically the (AXI or SHwy) bus clock),
+      - "scif_clk" for the optional external clock source for the frequency
+	divider (SCIF_CLK).
 
 Note: Each enabled SCIx UART should have an alias correctly numbered in the
 "aliases" node.
-- 
1.9.1


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

* [PATCH v3 05/27] serial: sh-sci: Drop useless check for zero sampling_rate
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

sci_port.sampling_rate is always non-zero, except for HSCIF, which uses
sci_baud_calc_hscif() instead of sci_scbrr_calc().

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by,
---
 drivers/tty/serial/sh-sci.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index cc6fa55231ba3536..dfee7a2f51f147d1 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1863,13 +1863,7 @@ static void sci_shutdown(struct uart_port *port)
 static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 				   unsigned long freq)
 {
-	if (s->sampling_rate)
-		return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
-
-	/* Warn, but use a safe default */
-	WARN_ON(1);
-
-	return ((freq + 16 * bps) / (32 * bps) - 1);
+	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
 /* calculate frame length from SMR */
-- 
1.9.1


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

* [PATCH v3 05/27] serial: sh-sci: Drop useless check for zero sampling_rate
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

sci_port.sampling_rate is always non-zero, except for HSCIF, which uses
sci_baud_calc_hscif() instead of sci_scbrr_calc().

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by,
---
 drivers/tty/serial/sh-sci.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index cc6fa55231ba3536..dfee7a2f51f147d1 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1863,13 +1863,7 @@ static void sci_shutdown(struct uart_port *port)
 static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 				   unsigned long freq)
 {
-	if (s->sampling_rate)
-		return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
-
-	/* Warn, but use a safe default */
-	WARN_ON(1);
-
-	return ((freq + 16 * bps) / (32 * bps) - 1);
+	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
 /* calculate frame length from SMR */
-- 
1.9.1


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

* [PATCH v3 06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index dfee7a2f51f147d1..5ec1a70cd2f49ada 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2645,7 +2645,7 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!p)
 		return NULL;
 
-	/* Get the line number for the aliases node. */
+	/* Get the line number from the aliases node. */
 	id = of_alias_get_id(np, "serial");
 	if (id < 0) {
 		dev_err(&pdev->dev, "failed to get alias id (%d)\n", id);
-- 
1.9.1


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

* [PATCH v3 06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index dfee7a2f51f147d1..5ec1a70cd2f49ada 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2645,7 +2645,7 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!p)
 		return NULL;
 
-	/* Get the line number for the aliases node. */
+	/* Get the line number from the aliases node. */
 	id = of_alias_get_id(np, "serial");
 	if (id < 0) {
 		dev_err(&pdev->dev, "failed to get alias id (%d)\n", id);
-- 
1.9.1


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

* [PATCH v3 07/27] serial: sh-sci: Use existing local variable in sci_parse_dt()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - New.
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5ec1a70cd2f49ada..36077193f11168f0 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2635,7 +2635,7 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!IS_ENABLED(CONFIG_OF) || !np)
 		return NULL;
 
-	match = of_match_node(of_sci_match, pdev->dev.of_node);
+	match = of_match_node(of_sci_match, np);
 	if (!match)
 		return NULL;
 
-- 
1.9.1


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

* [PATCH v3 07/27] serial: sh-sci: Use existing local variable in sci_parse_dt()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - New.
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5ec1a70cd2f49ada..36077193f11168f0 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2635,7 +2635,7 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!IS_ENABLED(CONFIG_OF) || !np)
 		return NULL;
 
-	match = of_match_node(of_sci_match, pdev->dev.of_node);
+	match = of_match_node(of_sci_match, np);
 	if (!match)
 		return NULL;
 
-- 
1.9.1


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

* [PATCH v3 08/27] serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

As F is assumed to be zero in the receive margin formula, frame_len is
not used. Remove it, together with the sci_baud_calc_frame_len() helper
function.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 36077193f11168f0..05ac15336e4f918d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1866,26 +1866,9 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
-/* calculate frame length from SMR */
-static int sci_baud_calc_frame_len(unsigned int smr_val)
-{
-	int len = 10;
-
-	if (smr_val & SCSMR_CHR)
-		len--;
-	if (smr_val & SCSMR_PE)
-		len++;
-	if (smr_val & SCSMR_STOP)
-		len++;
-
-	return len;
-}
-
-
 /* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
-				int *brr, unsigned int *srr,
-				unsigned int *cks, int frame_len)
+static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
+				unsigned int *srr, unsigned int *cks)
 {
 	int sr, c, br, err, recv_margin;
 	int min_err = 1000; /* 100% */
@@ -1987,9 +1970,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type = PORT_HSCIF) {
-			int frame_len = sci_baud_calc_frame_len(smr_val);
 			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
-					    &cks, frame_len);
+					    &cks);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
 			for (cks = 0; t >= 256 && cks <= 3; cks++)
-- 
1.9.1


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

* [PATCH v3 08/27] serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

As F is assumed to be zero in the receive margin formula, frame_len is
not used. Remove it, together with the sci_baud_calc_frame_len() helper
function.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 36077193f11168f0..05ac15336e4f918d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1866,26 +1866,9 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
-/* calculate frame length from SMR */
-static int sci_baud_calc_frame_len(unsigned int smr_val)
-{
-	int len = 10;
-
-	if (smr_val & SCSMR_CHR)
-		len--;
-	if (smr_val & SCSMR_PE)
-		len++;
-	if (smr_val & SCSMR_STOP)
-		len++;
-
-	return len;
-}
-
-
 /* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
-				int *brr, unsigned int *srr,
-				unsigned int *cks, int frame_len)
+static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
+				unsigned int *srr, unsigned int *cks)
 {
 	int sr, c, br, err, recv_margin;
 	int min_err = 1000; /* 100% */
@@ -1987,9 +1970,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type == PORT_HSCIF) {
-			int frame_len = sci_baud_calc_frame_len(smr_val);
 			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
-					    &cks, frame_len);
+					    &cks);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
 			for (cks = 0; t >= 256 && cks <= 3; cks++)
-- 
1.9.1


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

* [PATCH v3 09/27] serial: sh-sci: Don't overwrite clock selection in serial_console_write()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Blindly writing the default configuration value into the SCSCR register
may change the clock selection bits, breaking the serial console if the
current driver settings differ from the default settings.

Keep the current clock selection bits to prevent this from happening
on e.g. r8a7791/koelsch when support for the BRG will be added.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 05ac15336e4f918d..136ad2f633413cbc 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2420,7 +2420,7 @@ static void serial_console_write(struct console *co, const char *s,
 {
 	struct sci_port *sci_port = &sci_ports[co->index];
 	struct uart_port *port = &sci_port->port;
-	unsigned short bits, ctrl;
+	unsigned short bits, ctrl, ctrl_temp;
 	unsigned long flags;
 	int locked = 1;
 
@@ -2432,9 +2432,11 @@ static void serial_console_write(struct console *co, const char *s,
 	else
 		spin_lock(&port->lock);
 
-	/* first save the SCSCR then disable the interrupts */
+	/* first save SCSCR then disable interrupts, keep clock source */
 	ctrl = serial_port_in(port, SCSCR);
-	serial_port_out(port, SCSCR, sci_port->cfg->scscr);
+	ctrl_temp = (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) |
+		    (ctrl & (SCSCR_CKE1 | SCSCR_CKE0));
+	serial_port_out(port, SCSCR, ctrl_temp);
 
 	uart_console_write(port, s, count, serial_console_putchar);
 
-- 
1.9.1


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

* [PATCH v3 09/27] serial: sh-sci: Don't overwrite clock selection in serial_console_write()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Blindly writing the default configuration value into the SCSCR register
may change the clock selection bits, breaking the serial console if the
current driver settings differ from the default settings.

Keep the current clock selection bits to prevent this from happening
on e.g. r8a7791/koelsch when support for the BRG will be added.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 05ac15336e4f918d..136ad2f633413cbc 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2420,7 +2420,7 @@ static void serial_console_write(struct console *co, const char *s,
 {
 	struct sci_port *sci_port = &sci_ports[co->index];
 	struct uart_port *port = &sci_port->port;
-	unsigned short bits, ctrl;
+	unsigned short bits, ctrl, ctrl_temp;
 	unsigned long flags;
 	int locked = 1;
 
@@ -2432,9 +2432,11 @@ static void serial_console_write(struct console *co, const char *s,
 	else
 		spin_lock(&port->lock);
 
-	/* first save the SCSCR then disable the interrupts */
+	/* first save SCSCR then disable interrupts, keep clock source */
 	ctrl = serial_port_in(port, SCSCR);
-	serial_port_out(port, SCSCR, sci_port->cfg->scscr);
+	ctrl_temp = (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) |
+		    (ctrl & (SCSCR_CKE1 | SCSCR_CKE0));
+	serial_port_out(port, SCSCR, ctrl_temp);
 
 	uart_console_write(port, s, count, serial_console_putchar);
 
-- 
1.9.1


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

* [PATCH v3 10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Transfer clock cleanup handling to the core device management code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Convert "sci_fck", as its removal has been moved after the BRG
    patches.
---
 drivers/tty/serial/sh-sci.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 136ad2f633413cbc..b9eb4b525c0a7571 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2216,7 +2216,7 @@ static struct uart_ops sci_uart_ops = {
 static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
 	/* Get the SCI functional clock. It's called "fck" on ARM. */
-	sci_port->fclk = clk_get(dev, "fck");
+	sci_port->fclk = devm_clk_get(dev, "fck");
 	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 	if (!IS_ERR(sci_port->fclk))
@@ -2226,14 +2226,14 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	 * But it used to be called "sci_ick", and we need to maintain DT
 	 * backward compatibility.
 	 */
-	sci_port->fclk = clk_get(dev, "sci_ick");
+	sci_port->fclk = devm_clk_get(dev, "sci_ick");
 	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
 	/* SH has historically named the clock "sci_fck". */
-	sci_port->fclk = clk_get(dev, "sci_fck");
+	sci_port->fclk = devm_clk_get(dev, "sci_fck");
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
@@ -2241,7 +2241,7 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	 * Not all SH platforms declare a clock lookup entry for SCI devices,
 	 * in which case we need to get the global "peripheral_clk" clock.
 	 */
-	sci_port->fclk = clk_get(dev, "peripheral_clk");
+	sci_port->fclk = devm_clk_get(dev, "peripheral_clk");
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
@@ -2400,8 +2400,6 @@ static int sci_init_single(struct platform_device *dev,
 
 static void sci_cleanup_single(struct sci_port *port)
 {
-	clk_put(port->fclk);
-
 	pm_runtime_disable(port->port.dev);
 }
 
-- 
1.9.1


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

* [PATCH v3 10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Transfer clock cleanup handling to the core device management code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Convert "sci_fck", as its removal has been moved after the BRG
    patches.
---
 drivers/tty/serial/sh-sci.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 136ad2f633413cbc..b9eb4b525c0a7571 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2216,7 +2216,7 @@ static struct uart_ops sci_uart_ops = {
 static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
 	/* Get the SCI functional clock. It's called "fck" on ARM. */
-	sci_port->fclk = clk_get(dev, "fck");
+	sci_port->fclk = devm_clk_get(dev, "fck");
 	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 	if (!IS_ERR(sci_port->fclk))
@@ -2226,14 +2226,14 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	 * But it used to be called "sci_ick", and we need to maintain DT
 	 * backward compatibility.
 	 */
-	sci_port->fclk = clk_get(dev, "sci_ick");
+	sci_port->fclk = devm_clk_get(dev, "sci_ick");
 	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
 	/* SH has historically named the clock "sci_fck". */
-	sci_port->fclk = clk_get(dev, "sci_fck");
+	sci_port->fclk = devm_clk_get(dev, "sci_fck");
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
@@ -2241,7 +2241,7 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	 * Not all SH platforms declare a clock lookup entry for SCI devices,
 	 * in which case we need to get the global "peripheral_clk" clock.
 	 */
-	sci_port->fclk = clk_get(dev, "peripheral_clk");
+	sci_port->fclk = devm_clk_get(dev, "peripheral_clk");
 	if (!IS_ERR(sci_port->fclk))
 		return 0;
 
@@ -2400,8 +2400,6 @@ static int sci_init_single(struct platform_device *dev,
 
 static void sci_cleanup_single(struct sci_port *port)
 {
-	clk_put(port->fclk);
-
 	pm_runtime_disable(port->port.dev);
 }
 
-- 
1.9.1


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

* [PATCH v3 11/27] serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Move the -1 offset of br to the assignment to *brr, so br cannot become
negative anymore, and update the clamp() call. Now all unsigned values
in sci_baud_calc_hscif() can become unsigned.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by.
---
 drivers/tty/serial/sh-sci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index b9eb4b525c0a7571..77e0a582da44947f 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,8 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
-	int sr, c, br, err, recv_margin;
+	unsigned int sr, br, c;
+	int err, recv_margin;
 	int min_err = 1000; /* 100% */
 	int recv_max_margin = 0;
 
@@ -1880,9 +1881,9 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
 			br = DIV_ROUND_CLOSEST(freq, (sr *
-					      (1 << (2 * c + 1)) * bps)) - 1;
-			br = clamp(br, 0, 255);
-			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
+					      (1 << (2 * c + 1)) * bps));
+			br = clamp(br, 1U, 256U);
+			err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
 			/* Calc recv margin
@@ -1908,7 +1909,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			else
 				continue;
 
-			*brr = br;
+			*brr = br - 1;
 			*srr = sr - 1;
 			*cks = c;
 		}
-- 
1.9.1


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

* [PATCH v3 11/27] serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Move the -1 offset of br to the assignment to *brr, so br cannot become
negative anymore, and update the clamp() call. Now all unsigned values
in sci_baud_calc_hscif() can become unsigned.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by.
---
 drivers/tty/serial/sh-sci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index b9eb4b525c0a7571..77e0a582da44947f 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,8 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
-	int sr, c, br, err, recv_margin;
+	unsigned int sr, br, c;
+	int err, recv_margin;
 	int min_err = 1000; /* 100% */
 	int recv_max_margin = 0;
 
@@ -1880,9 +1881,9 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
 			br = DIV_ROUND_CLOSEST(freq, (sr *
-					      (1 << (2 * c + 1)) * bps)) - 1;
-			br = clamp(br, 0, 255);
-			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
+					      (1 << (2 * c + 1)) * bps));
+			br = clamp(br, 1U, 256U);
+			err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
 			/* Calc recv margin
@@ -1908,7 +1909,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			else
 				continue;
 
-			*brr = br;
+			*brr = br - 1;
 			*srr = sr - 1;
 			*cks = c;
 		}
-- 
1.9.1


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

* [PATCH v3 12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

If bps >= 1048576, the multiplication of the predivider and "bps" will
overflow, and both br and err will contain bogus values.
Skip the current and all higher clock select predividers when overflow
is detected.  Simplify the calculations using intermediates while we're
at it.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rename intermediates to "prediv" and "scrate",
  - Add a comment explaining the calculation and possible overflow.
---
 drivers/tty/serial/sh-sci.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 77e0a582da44947f..c490c51d6032786b 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,7 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
-	unsigned int sr, br, c;
+	unsigned int sr, br, prediv, scrate, c;
 	int err, recv_margin;
 	int min_err = 1000; /* 100% */
 	int recv_max_margin = 0;
@@ -1880,12 +1880,25 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 	for (sr = 8; sr <= 32; sr++) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			br = DIV_ROUND_CLOSEST(freq, (sr *
-					      (1 << (2 * c + 1)) * bps));
+			prediv = sr * (1 << (2 * c + 1));
+
+			/*
+			 * We need to calculate:
+			 *
+			 *     br = freq / (prediv * bps) clamped to [1..256]
+			 *     err = (freq / (br * prediv * bps / 1000)) - 1000
+			 *
+			 * Watch out for overflow when calculating the desired
+			 * sampling clock rate!
+			 */
+			if (bps > UINT_MAX / prediv)
+				break;
+
+			scrate = prediv * bps;
+			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
-			err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
-					       (1 << (2 * c + 1)) / 1000)) -
-					       1000;
+			err = DIV_ROUND_CLOSEST(freq, (br * scrate) / 1000) -
+			      1000;
 			/* Calc recv margin
 			 * M: Receive margin (%)
 			 * N: Ratio of bit rate to clock (N = sampling rate)
-- 
1.9.1


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

* [PATCH v3 12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

If bps >= 1048576, the multiplication of the predivider and "bps" will
overflow, and both br and err will contain bogus values.
Skip the current and all higher clock select predividers when overflow
is detected.  Simplify the calculations using intermediates while we're
at it.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rename intermediates to "prediv" and "scrate",
  - Add a comment explaining the calculation and possible overflow.
---
 drivers/tty/serial/sh-sci.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 77e0a582da44947f..c490c51d6032786b 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,7 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
-	unsigned int sr, br, c;
+	unsigned int sr, br, prediv, scrate, c;
 	int err, recv_margin;
 	int min_err = 1000; /* 100% */
 	int recv_max_margin = 0;
@@ -1880,12 +1880,25 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 	for (sr = 8; sr <= 32; sr++) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			br = DIV_ROUND_CLOSEST(freq, (sr *
-					      (1 << (2 * c + 1)) * bps));
+			prediv = sr * (1 << (2 * c + 1));
+
+			/*
+			 * We need to calculate:
+			 *
+			 *     br = freq / (prediv * bps) clamped to [1..256]
+			 *     err = (freq / (br * prediv * bps / 1000)) - 1000
+			 *
+			 * Watch out for overflow when calculating the desired
+			 * sampling clock rate!
+			 */
+			if (bps > UINT_MAX / prediv)
+				break;
+
+			scrate = prediv * bps;
+			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
-			err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
-					       (1 << (2 * c + 1)) / 1000)) -
-					       1000;
+			err = DIV_ROUND_CLOSEST(freq, (br * scrate) / 1000) -
+			      1000;
 			/* Calc recv margin
 			 * M: Receive margin (%)
 			 * N: Ratio of bit rate to clock (N = sampling rate)
-- 
1.9.1


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

* [PATCH v3 13/27] serial: sh-sci: Improve bit rate error calculation for HSCIF
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The algorithm to find the best parameters for the requested bit rate
calculates the relative bit rate error, using "(br * scrate) / 1000".
For small "br * scrate", this has two problems:
  - The quotient may be zero, leading to a division by zero error,
  - This may introduce a large rounding error.
Switch from relative to absolute bit rate error calculation to fix this.

The default baud rate generator values can be removed, as there will
always be one set of values that gives the smallest absolute error.

Print the best set of values when debugging.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Update for rename of intermediates to "prediv" and "scrate".
---
 drivers/tty/serial/sh-sci.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index c490c51d6032786b..306497ee5c326d19 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1867,12 +1867,13 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 }
 
 /* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
+static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
+				unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
 	unsigned int sr, br, prediv, scrate, c;
 	int err, recv_margin;
-	int min_err = 1000; /* 100% */
+	int min_err = INT_MAX;
 	int recv_max_margin = 0;
 
 	/* Find the combination of sample rate and clock select with the
@@ -1886,7 +1887,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			 * We need to calculate:
 			 *
 			 *     br = freq / (prediv * bps) clamped to [1..256]
-			 *     err = (freq / (br * prediv * bps / 1000)) - 1000
+			 *     err = freq / (br * prediv) - bps
 			 *
 			 * Watch out for overflow when calculating the desired
 			 * sampling clock rate!
@@ -1897,8 +1898,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			scrate = prediv * bps;
 			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
-			err = DIV_ROUND_CLOSEST(freq, (br * scrate) / 1000) -
-			      1000;
+			err = DIV_ROUND_CLOSEST(freq, br * prediv) - bps;
 			/* Calc recv margin
 			 * M: Receive margin (%)
 			 * N: Ratio of bit rate to clock (N = sampling rate)
@@ -1928,13 +1928,8 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 		}
 	}
 
-	if (min_err = 1000) {
-		WARN_ON(1);
-		/* use defaults */
-		*brr = 255;
-		*srr = 15;
-		*cks = 0;
-	}
+	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
+		min_err, *brr, *srr + 1, *cks);
 }
 
 static void sci_reset(struct uart_port *port)
@@ -1984,7 +1979,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type = PORT_HSCIF) {
-			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
+			sci_baud_calc_hscif(s, baud, port->uartclk, &t, &srr,
 					    &cks);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
-- 
1.9.1


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

* [PATCH v3 13/27] serial: sh-sci: Improve bit rate error calculation for HSCIF
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The algorithm to find the best parameters for the requested bit rate
calculates the relative bit rate error, using "(br * scrate) / 1000".
For small "br * scrate", this has two problems:
  - The quotient may be zero, leading to a division by zero error,
  - This may introduce a large rounding error.
Switch from relative to absolute bit rate error calculation to fix this.

The default baud rate generator values can be removed, as there will
always be one set of values that gives the smallest absolute error.

Print the best set of values when debugging.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Update for rename of intermediates to "prediv" and "scrate".
---
 drivers/tty/serial/sh-sci.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index c490c51d6032786b..306497ee5c326d19 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1867,12 +1867,13 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 }
 
 /* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
+static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
+				unsigned long freq, int *brr,
 				unsigned int *srr, unsigned int *cks)
 {
 	unsigned int sr, br, prediv, scrate, c;
 	int err, recv_margin;
-	int min_err = 1000; /* 100% */
+	int min_err = INT_MAX;
 	int recv_max_margin = 0;
 
 	/* Find the combination of sample rate and clock select with the
@@ -1886,7 +1887,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			 * We need to calculate:
 			 *
 			 *     br = freq / (prediv * bps) clamped to [1..256]
-			 *     err = (freq / (br * prediv * bps / 1000)) - 1000
+			 *     err = freq / (br * prediv) - bps
 			 *
 			 * Watch out for overflow when calculating the desired
 			 * sampling clock rate!
@@ -1897,8 +1898,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 			scrate = prediv * bps;
 			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
-			err = DIV_ROUND_CLOSEST(freq, (br * scrate) / 1000) -
-			      1000;
+			err = DIV_ROUND_CLOSEST(freq, br * prediv) - bps;
 			/* Calc recv margin
 			 * M: Receive margin (%)
 			 * N: Ratio of bit rate to clock (N = sampling rate)
@@ -1928,13 +1928,8 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
 		}
 	}
 
-	if (min_err == 1000) {
-		WARN_ON(1);
-		/* use defaults */
-		*brr = 255;
-		*srr = 15;
-		*cks = 0;
-	}
+	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
+		min_err, *brr, *srr + 1, *cks);
 }
 
 static void sci_reset(struct uart_port *port)
@@ -1984,7 +1979,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type == PORT_HSCIF) {
-			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
+			sci_baud_calc_hscif(s, baud, port->uartclk, &t, &srr,
 					    &cks);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
-- 
1.9.1


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

* [PATCH v3 14/27] serial: sh-sci: Avoid calculating the receive margin for HSCIF
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

When assuming D = 0.5 and F = 0, maximizing the receive margin M is
equivalent to maximizing the sample rate N.

Hence there's no need to calculate the receive margin, as we can obtain
the same result by iterating over all possible sample rates in reverse
order, and skipping parameter sets that don't provide a lower bit rate
error.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rebased,
  - Terminate loop over sampling rates on perfect match.
---
 drivers/tty/serial/sh-sci.c | 51 +++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 306497ee5c326d19..c3a193616484a62c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1872,13 +1872,24 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 				unsigned int *srr, unsigned int *cks)
 {
 	unsigned int sr, br, prediv, scrate, c;
-	int err, recv_margin;
-	int min_err = INT_MAX;
-	int recv_max_margin = 0;
+	int err, min_err = INT_MAX;
 
-	/* Find the combination of sample rate and clock select with the
-	   smallest deviation from the desired baud rate. */
-	for (sr = 8; sr <= 32; sr++) {
+	/*
+	 * Find the combination of sample rate and clock select with the
+	 * smallest deviation from the desired baud rate.
+	 * Prefer high sample rates to maximise the receive margin.
+	 *
+	 * M: Receive margin (%)
+	 * N: Ratio of bit rate to clock (N = sampling rate)
+	 * D: Clock duty (D = 0 to 1.0)
+	 * L: Frame length (L = 9 to 12)
+	 * F: Absolute value of clock frequency deviation
+	 *
+	 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
+	 *      (|D - 0.5| / N * (1 + F))|
+	 *  NOTE: Usually, treat D for 0.5, F is 0 by this calculation.
+	 */
+	for (sr = 32; sr >= 8; sr--) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
 			prediv = sr * (1 << (2 * c + 1));
@@ -1898,36 +1909,22 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 			scrate = prediv * bps;
 			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
+
 			err = DIV_ROUND_CLOSEST(freq, br * prediv) - bps;
-			/* Calc recv margin
-			 * M: Receive margin (%)
-			 * N: Ratio of bit rate to clock (N = sampling rate)
-			 * D: Clock duty (D = 0 to 1.0)
-			 * L: Frame length (L = 9 to 12)
-			 * F: Absolute value of clock frequency deviation
-			 *
-			 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
-			 *      (|D - 0.5| / N * (1 + F))|
-			 *  NOTE: Usually, treat D for 0.5, F is 0 by this
-			 *        calculation.
-			 */
-			recv_margin = abs((500 -
-					DIV_ROUND_CLOSEST(1000, sr << 1)) / 10);
-			if (abs(min_err) > abs(err)) {
-				min_err = err;
-				recv_max_margin = recv_margin;
-			} else if ((min_err = err) &&
-				   (recv_margin > recv_max_margin))
-				recv_max_margin = recv_margin;
-			else
+			if (abs(err) >= abs(min_err))
 				continue;
 
+			min_err = err;
 			*brr = br - 1;
 			*srr = sr - 1;
 			*cks = c;
+
+			if (!err)
+				goto found;
 		}
 	}
 
+found:
 	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
 		min_err, *brr, *srr + 1, *cks);
 }
-- 
1.9.1


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

* [PATCH v3 14/27] serial: sh-sci: Avoid calculating the receive margin for HSCIF
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

When assuming D = 0.5 and F = 0, maximizing the receive margin M is
equivalent to maximizing the sample rate N.

Hence there's no need to calculate the receive margin, as we can obtain
the same result by iterating over all possible sample rates in reverse
order, and skipping parameter sets that don't provide a lower bit rate
error.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rebased,
  - Terminate loop over sampling rates on perfect match.
---
 drivers/tty/serial/sh-sci.c | 51 +++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 306497ee5c326d19..c3a193616484a62c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1872,13 +1872,24 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 				unsigned int *srr, unsigned int *cks)
 {
 	unsigned int sr, br, prediv, scrate, c;
-	int err, recv_margin;
-	int min_err = INT_MAX;
-	int recv_max_margin = 0;
+	int err, min_err = INT_MAX;
 
-	/* Find the combination of sample rate and clock select with the
-	   smallest deviation from the desired baud rate. */
-	for (sr = 8; sr <= 32; sr++) {
+	/*
+	 * Find the combination of sample rate and clock select with the
+	 * smallest deviation from the desired baud rate.
+	 * Prefer high sample rates to maximise the receive margin.
+	 *
+	 * M: Receive margin (%)
+	 * N: Ratio of bit rate to clock (N = sampling rate)
+	 * D: Clock duty (D = 0 to 1.0)
+	 * L: Frame length (L = 9 to 12)
+	 * F: Absolute value of clock frequency deviation
+	 *
+	 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
+	 *      (|D - 0.5| / N * (1 + F))|
+	 *  NOTE: Usually, treat D for 0.5, F is 0 by this calculation.
+	 */
+	for (sr = 32; sr >= 8; sr--) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
 			prediv = sr * (1 << (2 * c + 1));
@@ -1898,36 +1909,22 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 			scrate = prediv * bps;
 			br = DIV_ROUND_CLOSEST(freq, scrate);
 			br = clamp(br, 1U, 256U);
+
 			err = DIV_ROUND_CLOSEST(freq, br * prediv) - bps;
-			/* Calc recv margin
-			 * M: Receive margin (%)
-			 * N: Ratio of bit rate to clock (N = sampling rate)
-			 * D: Clock duty (D = 0 to 1.0)
-			 * L: Frame length (L = 9 to 12)
-			 * F: Absolute value of clock frequency deviation
-			 *
-			 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
-			 *      (|D - 0.5| / N * (1 + F))|
-			 *  NOTE: Usually, treat D for 0.5, F is 0 by this
-			 *        calculation.
-			 */
-			recv_margin = abs((500 -
-					DIV_ROUND_CLOSEST(1000, sr << 1)) / 10);
-			if (abs(min_err) > abs(err)) {
-				min_err = err;
-				recv_max_margin = recv_margin;
-			} else if ((min_err == err) &&
-				   (recv_margin > recv_max_margin))
-				recv_max_margin = recv_margin;
-			else
+			if (abs(err) >= abs(min_err))
 				continue;
 
+			min_err = err;
 			*brr = br - 1;
 			*srr = sr - 1;
 			*cks = c;
+
+			if (!err)
+				goto found;
 		}
 	}
 
+found:
 	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
 		min_err, *brr, *srr + 1, *cks);
 }
-- 
1.9.1


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

* [PATCH v3 15/27] serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

For low bit rates, the for-loop that reduces the divider returned by
sci_scbrr_calc() and picks the clock select value may terminate without
finding suitable values, leading to out-of-range divider and clock
select values.
sci_baud_calc_hscif() doesn't suffer from this problem, as it correctly
uses clamp().

Since there are only two relevant differences between HSCIF and other
variants w.r.t. bit rate configuration (fixed vs. variable sample rate,
and an additional factor of two), sci_scbrr_calc() and
sci_baud_calc_hscif() can be merged, fixing the issue with out-of-range
values.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rebased.
---
 drivers/tty/serial/sh-sci.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index c3a193616484a62c..d89d4b7576cf3a15 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1860,20 +1860,24 @@ static void sci_shutdown(struct uart_port *port)
 	sci_free_irq(s);
 }
 
-static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
-				   unsigned long freq)
+/* calculate sample rate, BRR, and clock select */
+static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
+			   unsigned long freq, int *brr, unsigned int *srr,
+			   unsigned int *cks)
 {
-	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
-}
-
-/* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
-				unsigned long freq, int *brr,
-				unsigned int *srr, unsigned int *cks)
-{
-	unsigned int sr, br, prediv, scrate, c;
+	unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c;
 	int err, min_err = INT_MAX;
 
+	if (s->sampling_rate) {
+		min_sr = max_sr = s->sampling_rate;
+		shift = 0;
+	} else {
+		/* HSCIF has a variable sample rate */
+		min_sr = 8;
+		max_sr = 32;
+		shift = 1;
+	}
+
 	/*
 	 * Find the combination of sample rate and clock select with the
 	 * smallest deviation from the desired baud rate.
@@ -1889,10 +1893,10 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 	 *      (|D - 0.5| / N * (1 + F))|
 	 *  NOTE: Usually, treat D for 0.5, F is 0 by this calculation.
 	 */
-	for (sr = 32; sr >= 8; sr--) {
+	for (sr = max_sr; sr >= min_sr; sr--) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			prediv = sr * (1 << (2 * c + 1));
+			prediv = sr * (1 << (2 * c + shift));
 
 			/*
 			 * We need to calculate:
@@ -1974,16 +1978,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	max_baud = port->uartclk ? port->uartclk / 16 : 115200;
 
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
-	if (likely(baud && port->uartclk)) {
-		if (s->cfg->type = PORT_HSCIF) {
-			sci_baud_calc_hscif(s, baud, port->uartclk, &t, &srr,
-					    &cks);
-		} else {
-			t = sci_scbrr_calc(s, baud, port->uartclk);
-			for (cks = 0; t >= 256 && cks <= 3; cks++)
-				t >>= 2;
-		}
-	}
+	if (likely(baud && port->uartclk))
+		sci_scbrr_calc(s, baud, port->uartclk, &t, &srr, &cks);
 
 	sci_port_enable(s);
 
-- 
1.9.1


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

* [PATCH v3 15/27] serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

For low bit rates, the for-loop that reduces the divider returned by
sci_scbrr_calc() and picks the clock select value may terminate without
finding suitable values, leading to out-of-range divider and clock
select values.
sci_baud_calc_hscif() doesn't suffer from this problem, as it correctly
uses clamp().

Since there are only two relevant differences between HSCIF and other
variants w.r.t. bit rate configuration (fixed vs. variable sample rate,
and an additional factor of two), sci_scbrr_calc() and
sci_baud_calc_hscif() can be merged, fixing the issue with out-of-range
values.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Rebased.
---
 drivers/tty/serial/sh-sci.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index c3a193616484a62c..d89d4b7576cf3a15 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1860,20 +1860,24 @@ static void sci_shutdown(struct uart_port *port)
 	sci_free_irq(s);
 }
 
-static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
-				   unsigned long freq)
+/* calculate sample rate, BRR, and clock select */
+static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
+			   unsigned long freq, int *brr, unsigned int *srr,
+			   unsigned int *cks)
 {
-	return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
-}
-
-/* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
-				unsigned long freq, int *brr,
-				unsigned int *srr, unsigned int *cks)
-{
-	unsigned int sr, br, prediv, scrate, c;
+	unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c;
 	int err, min_err = INT_MAX;
 
+	if (s->sampling_rate) {
+		min_sr = max_sr = s->sampling_rate;
+		shift = 0;
+	} else {
+		/* HSCIF has a variable sample rate */
+		min_sr = 8;
+		max_sr = 32;
+		shift = 1;
+	}
+
 	/*
 	 * Find the combination of sample rate and clock select with the
 	 * smallest deviation from the desired baud rate.
@@ -1889,10 +1893,10 @@ static void sci_baud_calc_hscif(struct sci_port *s, unsigned int bps,
 	 *      (|D - 0.5| / N * (1 + F))|
 	 *  NOTE: Usually, treat D for 0.5, F is 0 by this calculation.
 	 */
-	for (sr = 32; sr >= 8; sr--) {
+	for (sr = max_sr; sr >= min_sr; sr--) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			prediv = sr * (1 << (2 * c + 1));
+			prediv = sr * (1 << (2 * c + shift));
 
 			/*
 			 * We need to calculate:
@@ -1974,16 +1978,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	max_baud = port->uartclk ? port->uartclk / 16 : 115200;
 
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
-	if (likely(baud && port->uartclk)) {
-		if (s->cfg->type == PORT_HSCIF) {
-			sci_baud_calc_hscif(s, baud, port->uartclk, &t, &srr,
-					    &cks);
-		} else {
-			t = sci_scbrr_calc(s, baud, port->uartclk);
-			for (cks = 0; t >= 256 && cks <= 3; cks++)
-				t >>= 2;
-		}
-	}
+	if (likely(baud && port->uartclk))
+		sci_scbrr_calc(s, baud, port->uartclk, &t, &srr, &cks);
 
 	sci_port_enable(s);
 
-- 
1.9.1


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

* [PATCH v3 16/27] serial: sh-sci: Take into account sampling rate for max baud rate
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The maximum baud rate depends on the sampling rate.
HSCIF has a variable sampling rate and sets s->sampling_rate to zero,
hence use the minimum sampling rate of 8.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index d89d4b7576cf3a15..5b120757c02a555a 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1975,7 +1975,10 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that the previous boot loader has enabled required clocks and
 	 * setup the baud rate generator hardware for us already.
 	 */
-	max_baud = port->uartclk ? port->uartclk / 16 : 115200;
+	if (port->uartclk)
+		max_baud = port->uartclk / max(s->sampling_rate, 8U);
+	else
+		max_baud = 115200;
 
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk))
-- 
1.9.1


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

* [PATCH v3 16/27] serial: sh-sci: Take into account sampling rate for max baud rate
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The maximum baud rate depends on the sampling rate.
HSCIF has a variable sampling rate and sets s->sampling_rate to zero,
hence use the minimum sampling rate of 8.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index d89d4b7576cf3a15..5b120757c02a555a 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1975,7 +1975,10 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that the previous boot loader has enabled required clocks and
 	 * setup the baud rate generator hardware for us already.
 	 */
-	max_baud = port->uartclk ? port->uartclk / 16 : 115200;
+	if (port->uartclk)
+		max_baud = port->uartclk / max(s->sampling_rate, 8U);
+	else
+		max_baud = 115200;
 
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk))
-- 
1.9.1


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

* [PATCH v3 17/27] serial: sh-sci: Add BRG register definitions
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add register definitions for the Baud Rate Generator for External Clock
(BRG), as found in some SCIF and in HSCIF, including a new regtype for
the "SH-4(A)"-derived SCIF variant with BRG.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add comment clarifying frequency divided SC_CLK vs. undivided
    (H)SCK.
---
 drivers/tty/serial/sh-sci.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/serial/sh-sci.h | 10 ++++++++++
 include/linux/serial_sci.h  |  1 +
 3 files changed, 57 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5b120757c02a555a..fb5eac2e3182304d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -161,6 +161,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -183,6 +185,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -204,6 +208,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= { 0x30, 16 },
 		[SCPDR]		= { 0x34, 16 },
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -225,6 +231,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= { 0x30, 16 },
 		[SCPDR]		= { 0x34, 16 },
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -247,6 +255,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -268,6 +278,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -289,6 +301,32 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
+	},
+
+	/*
+	 * Common SCIF definitions for ports with a Baud Rate Generator for
+	 * External Clock (BRG).
+	 */
+	[SCIx_SH4_SCIF_BRG_REGTYPE] = {
+		[SCSMR]		= { 0x00, 16 },
+		[SCBRR]		= { 0x04,  8 },
+		[SCSCR]		= { 0x08, 16 },
+		[SCxTDR]	= { 0x0c,  8 },
+		[SCxSR]		= { 0x10, 16 },
+		[SCxRDR]	= { 0x14,  8 },
+		[SCFCR]		= { 0x18, 16 },
+		[SCFDR]		= { 0x1c, 16 },
+		[SCTFDR]	= sci_reg_invalid,
+		[SCRFDR]	= sci_reg_invalid,
+		[SCSPTR]	= { 0x20, 16 },
+		[SCLSR]		= { 0x24, 16 },
+		[HSSRR]		= sci_reg_invalid,
+		[SCPCR]		= sci_reg_invalid,
+		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= { 0x30, 16 },
+		[SCCKS]		= { 0x34, 16 },
 	},
 
 	/*
@@ -310,6 +348,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= { 0x40, 16 },
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= { 0x30, 16 },
+		[SCCKS]		= { 0x34, 16 },
 	},
 
 	/*
@@ -332,6 +372,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -354,6 +396,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -376,6 +420,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 };
 
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index bf69bbdcc1f9aa39..fb176025042185c4 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -27,6 +27,8 @@ enum {
 	HSSRR,				/* Sampling Rate Register */
 	SCPCR,				/* Serial Port Control Register */
 	SCPDR,				/* Serial Port Data Register */
+	SCDL,				/* BRG Frequency Division Register */
+	SCCKS,				/* BRG Clock Select Register */
 
 	SCIx_NR_REGS,
 };
@@ -109,6 +111,14 @@ enum {
 #define SCPDR_RTSD	BIT(4)	/* Serial Port RTS Output Pin Data */
 #define SCPDR_CTSD	BIT(3)	/* Serial Port CTS Input Pin Data */
 
+/*
+ * BRG Clock Select Register (Some SCIF and HSCIF)
+ * The Baud Rate Generator for external clock can provide a clock source for
+ * the sampling clock. It outputs either its frequency divided clock, or the
+ * (undivided) (H)SCK external clock.
+ */
+#define SCCKS_CKS	BIT(15)	/* Select (H)SCK (1) or divided SC_CLK (0) */
+#define SCCKS_XIN	BIT(14)	/* SC_CLK uses bus clock (1) or SCIF_CLK (0) */
 
 #define SCxSR_TEND(port)	(((port)->type = PORT_SCI) ? SCI_TEND   : SCIF_TEND)
 #define SCxSR_RDxF(port)	(((port)->type = PORT_SCI) ? SCI_RDRF   : SCIF_RDF)
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index 7c536ac5be05d3aa..9f2bfd0557429ac3 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -32,6 +32,7 @@ enum {
 	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
 	SCIx_SH3_SCIF_REGTYPE,
 	SCIx_SH4_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_BRG_REGTYPE,
 	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
 	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
 	SCIx_SH7705_SCIF_REGTYPE,
-- 
1.9.1


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

* [PATCH v3 17/27] serial: sh-sci: Add BRG register definitions
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add register definitions for the Baud Rate Generator for External Clock
(BRG), as found in some SCIF and in HSCIF, including a new regtype for
the "SH-4(A)"-derived SCIF variant with BRG.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add comment clarifying frequency divided SC_CLK vs. undivided
    (H)SCK.
---
 drivers/tty/serial/sh-sci.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/serial/sh-sci.h | 10 ++++++++++
 include/linux/serial_sci.h  |  1 +
 3 files changed, 57 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5b120757c02a555a..fb5eac2e3182304d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -161,6 +161,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -183,6 +185,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -204,6 +208,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= { 0x30, 16 },
 		[SCPDR]		= { 0x34, 16 },
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -225,6 +231,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= { 0x30, 16 },
 		[SCPDR]		= { 0x34, 16 },
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -247,6 +255,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -268,6 +278,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -289,6 +301,32 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
+	},
+
+	/*
+	 * Common SCIF definitions for ports with a Baud Rate Generator for
+	 * External Clock (BRG).
+	 */
+	[SCIx_SH4_SCIF_BRG_REGTYPE] = {
+		[SCSMR]		= { 0x00, 16 },
+		[SCBRR]		= { 0x04,  8 },
+		[SCSCR]		= { 0x08, 16 },
+		[SCxTDR]	= { 0x0c,  8 },
+		[SCxSR]		= { 0x10, 16 },
+		[SCxRDR]	= { 0x14,  8 },
+		[SCFCR]		= { 0x18, 16 },
+		[SCFDR]		= { 0x1c, 16 },
+		[SCTFDR]	= sci_reg_invalid,
+		[SCRFDR]	= sci_reg_invalid,
+		[SCSPTR]	= { 0x20, 16 },
+		[SCLSR]		= { 0x24, 16 },
+		[HSSRR]		= sci_reg_invalid,
+		[SCPCR]		= sci_reg_invalid,
+		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= { 0x30, 16 },
+		[SCCKS]		= { 0x34, 16 },
 	},
 
 	/*
@@ -310,6 +348,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= { 0x40, 16 },
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= { 0x30, 16 },
+		[SCCKS]		= { 0x34, 16 },
 	},
 
 	/*
@@ -332,6 +372,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -354,6 +396,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 
 	/*
@@ -376,6 +420,8 @@ static const struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
 		[HSSRR]		= sci_reg_invalid,
 		[SCPCR]		= sci_reg_invalid,
 		[SCPDR]		= sci_reg_invalid,
+		[SCDL]		= sci_reg_invalid,
+		[SCCKS]		= sci_reg_invalid,
 	},
 };
 
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index bf69bbdcc1f9aa39..fb176025042185c4 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -27,6 +27,8 @@ enum {
 	HSSRR,				/* Sampling Rate Register */
 	SCPCR,				/* Serial Port Control Register */
 	SCPDR,				/* Serial Port Data Register */
+	SCDL,				/* BRG Frequency Division Register */
+	SCCKS,				/* BRG Clock Select Register */
 
 	SCIx_NR_REGS,
 };
@@ -109,6 +111,14 @@ enum {
 #define SCPDR_RTSD	BIT(4)	/* Serial Port RTS Output Pin Data */
 #define SCPDR_CTSD	BIT(3)	/* Serial Port CTS Input Pin Data */
 
+/*
+ * BRG Clock Select Register (Some SCIF and HSCIF)
+ * The Baud Rate Generator for external clock can provide a clock source for
+ * the sampling clock. It outputs either its frequency divided clock, or the
+ * (undivided) (H)SCK external clock.
+ */
+#define SCCKS_CKS	BIT(15)	/* Select (H)SCK (1) or divided SC_CLK (0) */
+#define SCCKS_XIN	BIT(14)	/* SC_CLK uses bus clock (1) or SCIF_CLK (0) */
 
 #define SCxSR_TEND(port)	(((port)->type == PORT_SCI) ? SCI_TEND   : SCIF_TEND)
 #define SCxSR_RDxF(port)	(((port)->type == PORT_SCI) ? SCI_RDRF   : SCIF_RDF)
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index 7c536ac5be05d3aa..9f2bfd0557429ac3 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -32,6 +32,7 @@ enum {
 	SCIx_SH2_SCIF_FIFODATA_REGTYPE,
 	SCIx_SH3_SCIF_REGTYPE,
 	SCIx_SH4_SCIF_REGTYPE,
+	SCIx_SH4_SCIF_BRG_REGTYPE,
 	SCIx_SH4_SCIF_NO_SCSPTR_REGTYPE,
 	SCIx_SH4_SCIF_FIFODATA_REGTYPE,
 	SCIx_SH7705_SCIF_REGTYPE,
-- 
1.9.1


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

* [PATCH v3 18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Store the encoded port and register types directly in of_device_id.data,
instead of using a pointer to a structure.
This saves memory and simplifies the source code, especially when adding
more compatible entries later.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index fb5eac2e3182304d..13c6abe9d842c0a8 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2614,42 +2614,27 @@ static int sci_remove(struct platform_device *dev)
 	return 0;
 }
 
-struct sci_port_info {
-	unsigned int type;
-	unsigned int regtype;
-};
+
+#define SCI_OF_DATA(type, regtype)	(void *)((type) << 16 | (regtype))
+#define SCI_OF_TYPE(data)		((unsigned long)(data) >> 16)
+#define SCI_OF_REGTYPE(data)		((unsigned long)(data) & 0xffff)
 
 static const struct of_device_id of_sci_match[] = {
 	{
 		.compatible = "renesas,scif",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIF,
-			.regtype = SCIx_SH4_SCIF_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
 	}, {
 		.compatible = "renesas,scifa",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIFA,
-			.regtype = SCIx_SCIFA_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIFA, SCIx_SCIFA_REGTYPE),
 	}, {
 		.compatible = "renesas,scifb",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIFB,
-			.regtype = SCIx_SCIFB_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIFB, SCIx_SCIFB_REGTYPE),
 	}, {
 		.compatible = "renesas,hscif",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_HSCIF,
-			.regtype = SCIx_HSCIF_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_HSCIF, SCIx_HSCIF_REGTYPE),
 	}, {
 		.compatible = "renesas,sci",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCI,
-			.regtype = SCIx_SCI_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCI, SCIx_SCI_REGTYPE),
 	}, {
 		/* Terminator */
 	},
@@ -2661,7 +2646,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 {
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *match;
-	const struct sci_port_info *info;
 	struct plat_sci_port *p;
 	int id;
 
@@ -2672,8 +2656,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!match)
 		return NULL;
 
-	info = match->data;
-
 	p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
 	if (!p)
 		return NULL;
@@ -2688,8 +2670,8 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	*dev_id = id;
 
 	p->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
-	p->type = info->type;
-	p->regtype = info->regtype;
+	p->type = SCI_OF_TYPE(match->data);
+	p->regtype = SCI_OF_REGTYPE(match->data);
 	p->scscr = SCSCR_RE | SCSCR_TE;
 
 	return p;
-- 
1.9.1


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

* [PATCH v3 18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Store the encoded port and register types directly in of_device_id.data,
instead of using a pointer to a structure.
This saves memory and simplifies the source code, especially when adding
more compatible entries later.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index fb5eac2e3182304d..13c6abe9d842c0a8 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2614,42 +2614,27 @@ static int sci_remove(struct platform_device *dev)
 	return 0;
 }
 
-struct sci_port_info {
-	unsigned int type;
-	unsigned int regtype;
-};
+
+#define SCI_OF_DATA(type, regtype)	(void *)((type) << 16 | (regtype))
+#define SCI_OF_TYPE(data)		((unsigned long)(data) >> 16)
+#define SCI_OF_REGTYPE(data)		((unsigned long)(data) & 0xffff)
 
 static const struct of_device_id of_sci_match[] = {
 	{
 		.compatible = "renesas,scif",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIF,
-			.regtype = SCIx_SH4_SCIF_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
 	}, {
 		.compatible = "renesas,scifa",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIFA,
-			.regtype = SCIx_SCIFA_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIFA, SCIx_SCIFA_REGTYPE),
 	}, {
 		.compatible = "renesas,scifb",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCIFB,
-			.regtype = SCIx_SCIFB_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCIFB, SCIx_SCIFB_REGTYPE),
 	}, {
 		.compatible = "renesas,hscif",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_HSCIF,
-			.regtype = SCIx_HSCIF_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_HSCIF, SCIx_HSCIF_REGTYPE),
 	}, {
 		.compatible = "renesas,sci",
-		.data = &(const struct sci_port_info) {
-			.type = PORT_SCI,
-			.regtype = SCIx_SCI_REGTYPE,
-		},
+		.data = SCI_OF_DATA(PORT_SCI, SCIx_SCI_REGTYPE),
 	}, {
 		/* Terminator */
 	},
@@ -2661,7 +2646,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 {
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *match;
-	const struct sci_port_info *info;
 	struct plat_sci_port *p;
 	int id;
 
@@ -2672,8 +2656,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	if (!match)
 		return NULL;
 
-	info = match->data;
-
 	p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
 	if (!p)
 		return NULL;
@@ -2688,8 +2670,8 @@ sci_parse_dt(struct platform_device *pdev, unsigned int *dev_id)
 	*dev_id = id;
 
 	p->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
-	p->type = info->type;
-	p->regtype = info->regtype;
+	p->type = SCI_OF_TYPE(match->data);
+	p->regtype = SCI_OF_REGTYPE(match->data);
 	p->scscr = SCSCR_RE | SCSCR_TE;
 
 	return p;
-- 
1.9.1


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

* [PATCH v3 19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car and RZ families.  However, the
variant used in the RZ family is not the common "SH-4(A)" variant, but
the "SH-2(A) with FIFO data count register" variant, as it has the
"Serial Extension Mode Register" (SCEMR), just like on sh7203, sh7263,
sh7264, and sh7269.

Use the (already documented) SoC-specific "renesas,scif-r7s72100"
compatible value to differentiate.  The "renesas,scif" compatible value
can still be used as a common denominator for SCIF variants with the
"SH-4(A)" register layout (i.e. ignoring the SCEMR register).
Note that currently both variants are treated the same, but this may
change if support for the SCEMR register is ever added.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 13c6abe9d842c0a8..5b8504bfd42e9906 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2620,6 +2620,12 @@ static int sci_remove(struct platform_device *dev)
 #define SCI_OF_REGTYPE(data)		((unsigned long)(data) & 0xffff)
 
 static const struct of_device_id of_sci_match[] = {
+	/* SoC-specific types */
+	{
+		.compatible = "renesas,scif-r7s72100",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
+	},
+	/* Generic types */
 	{
 		.compatible = "renesas,scif",
 		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
-- 
1.9.1


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

* [PATCH v3 19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car and RZ families.  However, the
variant used in the RZ family is not the common "SH-4(A)" variant, but
the "SH-2(A) with FIFO data count register" variant, as it has the
"Serial Extension Mode Register" (SCEMR), just like on sh7203, sh7263,
sh7264, and sh7269.

Use the (already documented) SoC-specific "renesas,scif-r7s72100"
compatible value to differentiate.  The "renesas,scif" compatible value
can still be used as a common denominator for SCIF variants with the
"SH-4(A)" register layout (i.e. ignoring the SCEMR register).
Note that currently both variants are treated the same, but this may
change if support for the SCEMR register is ever added.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Reviewed-by, Acked-by.
---
 drivers/tty/serial/sh-sci.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 13c6abe9d842c0a8..5b8504bfd42e9906 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2620,6 +2620,12 @@ static int sci_remove(struct platform_device *dev)
 #define SCI_OF_REGTYPE(data)		((unsigned long)(data) & 0xffff)
 
 static const struct of_device_id of_sci_match[] = {
+	/* SoC-specific types */
+	{
+		.compatible = "renesas,scif-r7s72100",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
+	},
+	/* Generic types */
 	{
 		.compatible = "renesas,scif",
 		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
-- 
1.9.1


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

* [PATCH v3 20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
       [not found] ` <1450119456-964-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
@ 2015-12-14 18:57     ` Geert Uytterhoeven
  2015-12-14 18:57     ` Geert Uytterhoeven
  1 sibling, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-sh-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven,
	devicetree-u79uwXL29TY76Z2rM5mHXA

The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car family.  However, the variant
used in the R-Car family is not the common "SH-4(A)" variant, but a
derivative with added "Baud Rate Generator for External Clock" (BRG),
which is also present in sh7734.

Use the family-specific SCIF compatible values for R-Car Gen1, Gen2, and
Gen3 SoCs to differentiate.  The "renesas,scif" compatible value can
still be used as a common denominator for SCIF variants with the
"SH-4(A)" register layout (i.e. ignoring the "Serial Extension Mode
Register" (SCEMR) and the new BRG-specific registers).

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devicetree@vger.kernel.org
---
v3:
  - Add Acked-by,
  - Use family-specific instead of SoC-specific compatible values.
---
 drivers/tty/serial/sh-sci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5b8504bfd42e9906..a202e4e40b8adafb 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2625,6 +2625,17 @@ static const struct of_device_id of_sci_match[] = {
 		.compatible = "renesas,scif-r7s72100",
 		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
 	},
+	/* Family-specific types */
+	{
+		.compatible = "renesas,rcar-gen1-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	}, {
+		.compatible = "renesas,rcar-gen2-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	}, {
+		.compatible = "renesas,rcar-gen3-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	},
 	/* Generic types */
 	{
 		.compatible = "renesas,scif",
-- 
1.9.1


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

* [PATCH v3 20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
@ 2015-12-14 18:57     ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-sh-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven,
	devicetree-u79uwXL29TY76Z2rM5mHXA

The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car family.  However, the variant
used in the R-Car family is not the common "SH-4(A)" variant, but a
derivative with added "Baud Rate Generator for External Clock" (BRG),
which is also present in sh7734.

Use the family-specific SCIF compatible values for R-Car Gen1, Gen2, and
Gen3 SoCs to differentiate.  The "renesas,scif" compatible value can
still be used as a common denominator for SCIF variants with the
"SH-4(A)" register layout (i.e. ignoring the "Serial Extension Mode
Register" (SCEMR) and the new BRG-specific registers).

Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
Acked-by: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
v3:
  - Add Acked-by,
  - Use family-specific instead of SoC-specific compatible values.
---
 drivers/tty/serial/sh-sci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5b8504bfd42e9906..a202e4e40b8adafb 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2625,6 +2625,17 @@ static const struct of_device_id of_sci_match[] = {
 		.compatible = "renesas,scif-r7s72100",
 		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
 	},
+	/* Family-specific types */
+	{
+		.compatible = "renesas,rcar-gen1-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	}, {
+		.compatible = "renesas,rcar-gen2-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	}, {
+		.compatible = "renesas,rcar-gen3-scif",
+		.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+	},
 	/* Generic types */
 	{
 		.compatible = "renesas,scif",
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v3 21/27] serial: sh-sci: Prepare for multiple sampling clock sources
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Refactor the clock and baud rate parameter code to ease adding support
for multiple sampling clock sources.
sci_scbrr_calc() now returns the bit rate error, so it can be compared
to the bit rate error using other sampling clock sources.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add dev_dbg() for optional clock failures,
  - Print clk_names[i] instead of hardcoded clock name or numerical
    index,
  - Add comments explaining multiple sampling clock sources and divided
    functional clock,
  - Reword patch description, using multiple sampling clock sources
    instead of multiple clocks and baud rate generators,
  - Handle "sci_fck", as its removal has been moved after the BRG
    patches.
---
 drivers/tty/serial/sh-sci.c | 194 ++++++++++++++++++++++++++++++--------------
 1 file changed, 134 insertions(+), 60 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index a202e4e40b8adafb..fa3fd876105b2252 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2,6 +2,7 @@
  * SuperH on-chip serial module support.  (SCI with no FIFO / with FIFO)
  *
  *  Copyright (C) 2002 - 2011  Paul Mundt
+ *  Copyright (C) 2015 Glider bvba
  *  Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
  *
  * based off of the old drivers/char/sh-sci.c by:
@@ -76,6 +77,11 @@ enum {
 	((port)->irqs[SCIx_ERI_IRQ] &&	\
 	 ((port)->irqs[SCIx_RXI_IRQ] < 0))
 
+enum SCI_CLKS {
+	SCI_FCK,		/* Functional Clock */
+	SCI_NUM_CLKS
+};
+
 struct sci_port {
 	struct uart_port	port;
 
@@ -92,8 +98,9 @@ struct sci_port {
 	struct timer_list	break_timer;
 	int			break_flag;
 
-	/* Function clock */
-	struct clk		*fclk;
+	/* Clocks */
+	struct clk		*clks[SCI_NUM_CLKS];
+	unsigned long		clk_rates[SCI_NUM_CLKS];
 
 	int			irqs[SCIx_NR_IRQS];
 	char			*irqstr[SCIx_NR_IRQS];
@@ -496,17 +503,24 @@ static int sci_probe_regmap(struct plat_sci_port *cfg)
 
 static void sci_port_enable(struct sci_port *sci_port)
 {
+	unsigned int i;
+
 	if (!sci_port->port.dev)
 		return;
 
 	pm_runtime_get_sync(sci_port->port.dev);
 
-	clk_prepare_enable(sci_port->fclk);
-	sci_port->port.uartclk = clk_get_rate(sci_port->fclk);
+	for (i = 0; i < SCI_NUM_CLKS; i++) {
+		clk_prepare_enable(sci_port->clks[i]);
+		sci_port->clk_rates[i] = clk_get_rate(sci_port->clks[i]);
+	}
+	sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK];
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
 {
+	unsigned int i;
+
 	if (!sci_port->port.dev)
 		return;
 
@@ -518,7 +532,8 @@ static void sci_port_disable(struct sci_port *sci_port)
 	del_timer_sync(&sci_port->break_timer);
 	sci_port->break_flag = 0;
 
-	clk_disable_unprepare(sci_port->fclk);
+	for (i = SCI_NUM_CLKS; i-- > 0; )
+		clk_disable_unprepare(sci_port->clks[i]);
 
 	pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -1657,6 +1672,7 @@ static int sci_notifier(struct notifier_block *self,
 {
 	struct sci_port *sci_port;
 	unsigned long flags;
+	unsigned int i;
 
 	sci_port = container_of(self, struct sci_port, freq_transition);
 
@@ -1664,7 +1680,9 @@ static int sci_notifier(struct notifier_block *self,
 		struct uart_port *port = &sci_port->port;
 
 		spin_lock_irqsave(&port->lock, flags);
-		port->uartclk = clk_get_rate(sci_port->fclk);
+		for (i = 0; i < SCI_NUM_CLKS; i++)
+			sci_port->clk_rates[i] +				clk_get_rate(sci_port->clks[i]);
 		spin_unlock_irqrestore(&port->lock, flags);
 	}
 
@@ -1907,11 +1925,12 @@ static void sci_shutdown(struct uart_port *port)
 }
 
 /* calculate sample rate, BRR, and clock select */
-static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
-			   unsigned long freq, int *brr, unsigned int *srr,
-			   unsigned int *cks)
+static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
+			  unsigned int *brr, unsigned int *srr,
+			  unsigned int *cks)
 {
 	unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c;
+	unsigned long freq = s->clk_rates[SCI_FCK];
 	int err, min_err = INT_MAX;
 
 	if (s->sampling_rate) {
@@ -1977,6 +1996,7 @@ static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 found:
 	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
 		min_err, *brr, *srr + 1, *cks);
+	return min_err;
 }
 
 static void sci_reset(struct uart_port *port)
@@ -1998,11 +2018,14 @@ static void sci_reset(struct uart_port *port)
 static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
+	unsigned int baud, smr_val = 0, scr_val = 0, i;
+	unsigned int brr = 255, cks = 0, srr = 15;
+	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
-	unsigned int baud, smr_val = 0, max_baud, cks = 0;
-	int t = -1;
-	unsigned int srr = 15;
+	int min_err = INT_MAX, err;
+	unsigned long max_freq = 0;
+	int best_clk = -1;
 
 	if ((termios->c_cflag & CSIZE) = CS7)
 		smr_val |= SCSMR_CHR;
@@ -2021,35 +2044,64 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that the previous boot loader has enabled required clocks and
 	 * setup the baud rate generator hardware for us already.
 	 */
-	if (port->uartclk)
-		max_baud = port->uartclk / max(s->sampling_rate, 8U);
-	else
-		max_baud = 115200;
+	if (!port->uartclk) {
+		baud = uart_get_baud_rate(port, termios, old, 0, 115200);
+		goto done;
+	}
 
-	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
-	if (likely(baud && port->uartclk))
-		sci_scbrr_calc(s, baud, port->uartclk, &t, &srr, &cks);
+	for (i = 0; i < SCI_NUM_CLKS; i++)
+		max_freq = max(max_freq, s->clk_rates[i]);
+
+	baud = uart_get_baud_rate(port, termios, old, 0,
+				  max_freq / max(s->sampling_rate, 8U));
+	if (!baud)
+		goto done;
+
+	/*
+	 * There can be multiple sources for the sampling clock.  Find the one
+	 * that gives us the smallest deviation from the desired baud rate.
+	 */
+
+	/* Divided Functional Clock using standard Bit Rate Register */
+	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
+	if (abs(err) < abs(min_err)) {
+		best_clk = SCI_FCK;
+		min_err = err;
+		brr = brr1;
+		srr = srr1;
+		cks = cks1;
+	}
+
+done:
+	if (best_clk >= 0)
+		dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
+			s->clks[best_clk], baud, min_err);
 
 	sci_port_enable(s);
 
 	sci_reset(port);
 
-	smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS;
-
 	uart_update_timeout(port, termios->c_cflag, baud);
 
-	dev_dbg(port->dev, "%s: SMR %x, cks %x, t %x, SCSCR %x\n",
-		__func__, smr_val, cks, t, s->cfg->scscr);
-
-	if (t >= 0) {
-		serial_port_out(port, SCSMR, (smr_val & ~SCSMR_CKS) | cks);
-		serial_port_out(port, SCBRR, t);
-		reg = sci_getreg(port, HSSRR);
-		if (reg->size)
+	if (best_clk >= 0) {
+		smr_val |= cks;
+		dev_dbg(port->dev, "SMR 0x%x BRR %u SRR %u\n", smr_val, brr,
+			srr);
+		serial_port_out(port, SCSMR, smr_val);
+		serial_port_out(port, SCBRR, brr);
+		if (sci_getreg(port, HSSRR)->size)
 			serial_port_out(port, HSSRR, srr | HSCIF_SRE);
-		udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
-	} else
+
+		/* Wait one bit interval */
+		udelay((1000000 + (baud - 1)) / baud);
+	} else {
+		/* Don't touch the bit rate configuration */
+		scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0);
+		smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS;
+		dev_dbg(port->dev, "SCR 0x%x SMR 0x%x\n", scr_val, smr_val);
+		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
+	}
 
 	sci_init_pins(port, termios->c_cflag);
 
@@ -2074,7 +2126,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 		serial_port_out(port, SCFCR, ctrl);
 	}
 
-	serial_port_out(port, SCSCR, s->cfg->scscr);
+	scr_val |= s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0);
+	dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val);
+	serial_port_out(port, SCSCR, scr_val);
 
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
 	/*
@@ -2266,38 +2320,58 @@ static struct uart_ops sci_uart_ops = {
 
 static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
-	/* Get the SCI functional clock. It's called "fck" on ARM. */
-	sci_port->fclk = devm_clk_get(dev, "fck");
-	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+	const char *clk_names[] = {
+		[SCI_FCK] = "fck",
+	};
+	struct clk *clk;
+	unsigned int i;
 
-	/*
-	 * But it used to be called "sci_ick", and we need to maintain DT
-	 * backward compatibility.
-	 */
-	sci_port->fclk = devm_clk_get(dev, "sci_ick");
-	if (PTR_ERR(sci_port->fclk) = -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+	for (i = 0; i < SCI_NUM_CLKS; i++) {
+		clk = devm_clk_get(dev, clk_names[i]);
+		if (PTR_ERR(clk) = -EPROBE_DEFER)
+			return -EPROBE_DEFER;
 
-	/* SH has historically named the clock "sci_fck". */
-	sci_port->fclk = devm_clk_get(dev, "sci_fck");
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+		if (IS_ERR(clk) && i = SCI_FCK) {
+			/*
+			 * "fck" used to be called "sci_ick", and we need to
+			 * maintain DT backward compatibility.
+			 */
+			clk = devm_clk_get(dev, "sci_ick");
+			if (PTR_ERR(clk) = -EPROBE_DEFER)
+				return -EPROBE_DEFER;
 
-	/*
-	 * Not all SH platforms declare a clock lookup entry for SCI devices,
-	 * in which case we need to get the global "peripheral_clk" clock.
-	 */
-	sci_port->fclk = devm_clk_get(dev, "peripheral_clk");
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+			if (!IS_ERR(clk))
+				goto found;
 
-	dev_err(dev, "failed to get functional clock\n");
-	return PTR_ERR(sci_port->fclk);
+			/* SH has historically named the clock "sci_fck". */
+			clk = devm_clk_get(dev, "sci_fck");
+			if (!IS_ERR(clk))
+				goto found;
+
+			/*
+			 * Not all SH platforms declare a clock lookup entry
+			 * for SCI devices, in which case we need to get the
+			 * global "peripheral_clk" clock.
+			 */
+			clk = devm_clk_get(dev, "peripheral_clk");
+			if (!IS_ERR(clk))
+				goto found;
+
+			dev_err(dev, "failed to get %s (%ld)\n", clk_names[i],
+				PTR_ERR(clk));
+			return PTR_ERR(clk);
+		}
+
+found:
+		if (IS_ERR(clk))
+			dev_dbg(dev, "failed to get %s (%ld)\n", clk_names[i],
+				PTR_ERR(clk));
+		else
+			dev_dbg(dev, "clk %s is %pC rate %pCr\n", clk_names[i],
+				clk, clk);
+		sci_port->clks[i] = IS_ERR(clk) ? NULL : clk;
+	}
+	return 0;
 }
 
 static int sci_init_single(struct platform_device *dev,
-- 
1.9.1


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

* [PATCH v3 21/27] serial: sh-sci: Prepare for multiple sampling clock sources
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Refactor the clock and baud rate parameter code to ease adding support
for multiple sampling clock sources.
sci_scbrr_calc() now returns the bit rate error, so it can be compared
to the bit rate error using other sampling clock sources.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add dev_dbg() for optional clock failures,
  - Print clk_names[i] instead of hardcoded clock name or numerical
    index,
  - Add comments explaining multiple sampling clock sources and divided
    functional clock,
  - Reword patch description, using multiple sampling clock sources
    instead of multiple clocks and baud rate generators,
  - Handle "sci_fck", as its removal has been moved after the BRG
    patches.
---
 drivers/tty/serial/sh-sci.c | 194 ++++++++++++++++++++++++++++++--------------
 1 file changed, 134 insertions(+), 60 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index a202e4e40b8adafb..fa3fd876105b2252 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2,6 +2,7 @@
  * SuperH on-chip serial module support.  (SCI with no FIFO / with FIFO)
  *
  *  Copyright (C) 2002 - 2011  Paul Mundt
+ *  Copyright (C) 2015 Glider bvba
  *  Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
  *
  * based off of the old drivers/char/sh-sci.c by:
@@ -76,6 +77,11 @@ enum {
 	((port)->irqs[SCIx_ERI_IRQ] &&	\
 	 ((port)->irqs[SCIx_RXI_IRQ] < 0))
 
+enum SCI_CLKS {
+	SCI_FCK,		/* Functional Clock */
+	SCI_NUM_CLKS
+};
+
 struct sci_port {
 	struct uart_port	port;
 
@@ -92,8 +98,9 @@ struct sci_port {
 	struct timer_list	break_timer;
 	int			break_flag;
 
-	/* Function clock */
-	struct clk		*fclk;
+	/* Clocks */
+	struct clk		*clks[SCI_NUM_CLKS];
+	unsigned long		clk_rates[SCI_NUM_CLKS];
 
 	int			irqs[SCIx_NR_IRQS];
 	char			*irqstr[SCIx_NR_IRQS];
@@ -496,17 +503,24 @@ static int sci_probe_regmap(struct plat_sci_port *cfg)
 
 static void sci_port_enable(struct sci_port *sci_port)
 {
+	unsigned int i;
+
 	if (!sci_port->port.dev)
 		return;
 
 	pm_runtime_get_sync(sci_port->port.dev);
 
-	clk_prepare_enable(sci_port->fclk);
-	sci_port->port.uartclk = clk_get_rate(sci_port->fclk);
+	for (i = 0; i < SCI_NUM_CLKS; i++) {
+		clk_prepare_enable(sci_port->clks[i]);
+		sci_port->clk_rates[i] = clk_get_rate(sci_port->clks[i]);
+	}
+	sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK];
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
 {
+	unsigned int i;
+
 	if (!sci_port->port.dev)
 		return;
 
@@ -518,7 +532,8 @@ static void sci_port_disable(struct sci_port *sci_port)
 	del_timer_sync(&sci_port->break_timer);
 	sci_port->break_flag = 0;
 
-	clk_disable_unprepare(sci_port->fclk);
+	for (i = SCI_NUM_CLKS; i-- > 0; )
+		clk_disable_unprepare(sci_port->clks[i]);
 
 	pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -1657,6 +1672,7 @@ static int sci_notifier(struct notifier_block *self,
 {
 	struct sci_port *sci_port;
 	unsigned long flags;
+	unsigned int i;
 
 	sci_port = container_of(self, struct sci_port, freq_transition);
 
@@ -1664,7 +1680,9 @@ static int sci_notifier(struct notifier_block *self,
 		struct uart_port *port = &sci_port->port;
 
 		spin_lock_irqsave(&port->lock, flags);
-		port->uartclk = clk_get_rate(sci_port->fclk);
+		for (i = 0; i < SCI_NUM_CLKS; i++)
+			sci_port->clk_rates[i] =
+				clk_get_rate(sci_port->clks[i]);
 		spin_unlock_irqrestore(&port->lock, flags);
 	}
 
@@ -1907,11 +1925,12 @@ static void sci_shutdown(struct uart_port *port)
 }
 
 /* calculate sample rate, BRR, and clock select */
-static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
-			   unsigned long freq, int *brr, unsigned int *srr,
-			   unsigned int *cks)
+static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
+			  unsigned int *brr, unsigned int *srr,
+			  unsigned int *cks)
 {
 	unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c;
+	unsigned long freq = s->clk_rates[SCI_FCK];
 	int err, min_err = INT_MAX;
 
 	if (s->sampling_rate) {
@@ -1977,6 +1996,7 @@ static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 found:
 	dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
 		min_err, *brr, *srr + 1, *cks);
+	return min_err;
 }
 
 static void sci_reset(struct uart_port *port)
@@ -1998,11 +2018,14 @@ static void sci_reset(struct uart_port *port)
 static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
+	unsigned int baud, smr_val = 0, scr_val = 0, i;
+	unsigned int brr = 255, cks = 0, srr = 15;
+	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
-	unsigned int baud, smr_val = 0, max_baud, cks = 0;
-	int t = -1;
-	unsigned int srr = 15;
+	int min_err = INT_MAX, err;
+	unsigned long max_freq = 0;
+	int best_clk = -1;
 
 	if ((termios->c_cflag & CSIZE) == CS7)
 		smr_val |= SCSMR_CHR;
@@ -2021,35 +2044,64 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that the previous boot loader has enabled required clocks and
 	 * setup the baud rate generator hardware for us already.
 	 */
-	if (port->uartclk)
-		max_baud = port->uartclk / max(s->sampling_rate, 8U);
-	else
-		max_baud = 115200;
+	if (!port->uartclk) {
+		baud = uart_get_baud_rate(port, termios, old, 0, 115200);
+		goto done;
+	}
 
-	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
-	if (likely(baud && port->uartclk))
-		sci_scbrr_calc(s, baud, port->uartclk, &t, &srr, &cks);
+	for (i = 0; i < SCI_NUM_CLKS; i++)
+		max_freq = max(max_freq, s->clk_rates[i]);
+
+	baud = uart_get_baud_rate(port, termios, old, 0,
+				  max_freq / max(s->sampling_rate, 8U));
+	if (!baud)
+		goto done;
+
+	/*
+	 * There can be multiple sources for the sampling clock.  Find the one
+	 * that gives us the smallest deviation from the desired baud rate.
+	 */
+
+	/* Divided Functional Clock using standard Bit Rate Register */
+	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
+	if (abs(err) < abs(min_err)) {
+		best_clk = SCI_FCK;
+		min_err = err;
+		brr = brr1;
+		srr = srr1;
+		cks = cks1;
+	}
+
+done:
+	if (best_clk >= 0)
+		dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
+			s->clks[best_clk], baud, min_err);
 
 	sci_port_enable(s);
 
 	sci_reset(port);
 
-	smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS;
-
 	uart_update_timeout(port, termios->c_cflag, baud);
 
-	dev_dbg(port->dev, "%s: SMR %x, cks %x, t %x, SCSCR %x\n",
-		__func__, smr_val, cks, t, s->cfg->scscr);
-
-	if (t >= 0) {
-		serial_port_out(port, SCSMR, (smr_val & ~SCSMR_CKS) | cks);
-		serial_port_out(port, SCBRR, t);
-		reg = sci_getreg(port, HSSRR);
-		if (reg->size)
+	if (best_clk >= 0) {
+		smr_val |= cks;
+		dev_dbg(port->dev, "SMR 0x%x BRR %u SRR %u\n", smr_val, brr,
+			srr);
+		serial_port_out(port, SCSMR, smr_val);
+		serial_port_out(port, SCBRR, brr);
+		if (sci_getreg(port, HSSRR)->size)
 			serial_port_out(port, HSSRR, srr | HSCIF_SRE);
-		udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
-	} else
+
+		/* Wait one bit interval */
+		udelay((1000000 + (baud - 1)) / baud);
+	} else {
+		/* Don't touch the bit rate configuration */
+		scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0);
+		smr_val |= serial_port_in(port, SCSMR) & SCSMR_CKS;
+		dev_dbg(port->dev, "SCR 0x%x SMR 0x%x\n", scr_val, smr_val);
+		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
+	}
 
 	sci_init_pins(port, termios->c_cflag);
 
@@ -2074,7 +2126,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 		serial_port_out(port, SCFCR, ctrl);
 	}
 
-	serial_port_out(port, SCSCR, s->cfg->scscr);
+	scr_val |= s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0);
+	dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val);
+	serial_port_out(port, SCSCR, scr_val);
 
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
 	/*
@@ -2266,38 +2320,58 @@ static struct uart_ops sci_uart_ops = {
 
 static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
-	/* Get the SCI functional clock. It's called "fck" on ARM. */
-	sci_port->fclk = devm_clk_get(dev, "fck");
-	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+	const char *clk_names[] = {
+		[SCI_FCK] = "fck",
+	};
+	struct clk *clk;
+	unsigned int i;
 
-	/*
-	 * But it used to be called "sci_ick", and we need to maintain DT
-	 * backward compatibility.
-	 */
-	sci_port->fclk = devm_clk_get(dev, "sci_ick");
-	if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+	for (i = 0; i < SCI_NUM_CLKS; i++) {
+		clk = devm_clk_get(dev, clk_names[i]);
+		if (PTR_ERR(clk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
 
-	/* SH has historically named the clock "sci_fck". */
-	sci_port->fclk = devm_clk_get(dev, "sci_fck");
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+		if (IS_ERR(clk) && i == SCI_FCK) {
+			/*
+			 * "fck" used to be called "sci_ick", and we need to
+			 * maintain DT backward compatibility.
+			 */
+			clk = devm_clk_get(dev, "sci_ick");
+			if (PTR_ERR(clk) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;
 
-	/*
-	 * Not all SH platforms declare a clock lookup entry for SCI devices,
-	 * in which case we need to get the global "peripheral_clk" clock.
-	 */
-	sci_port->fclk = devm_clk_get(dev, "peripheral_clk");
-	if (!IS_ERR(sci_port->fclk))
-		return 0;
+			if (!IS_ERR(clk))
+				goto found;
 
-	dev_err(dev, "failed to get functional clock\n");
-	return PTR_ERR(sci_port->fclk);
+			/* SH has historically named the clock "sci_fck". */
+			clk = devm_clk_get(dev, "sci_fck");
+			if (!IS_ERR(clk))
+				goto found;
+
+			/*
+			 * Not all SH platforms declare a clock lookup entry
+			 * for SCI devices, in which case we need to get the
+			 * global "peripheral_clk" clock.
+			 */
+			clk = devm_clk_get(dev, "peripheral_clk");
+			if (!IS_ERR(clk))
+				goto found;
+
+			dev_err(dev, "failed to get %s (%ld)\n", clk_names[i],
+				PTR_ERR(clk));
+			return PTR_ERR(clk);
+		}
+
+found:
+		if (IS_ERR(clk))
+			dev_dbg(dev, "failed to get %s (%ld)\n", clk_names[i],
+				PTR_ERR(clk));
+		else
+			dev_dbg(dev, "clk %s is %pC rate %pCr\n", clk_names[i],
+				clk, clk);
+		sci_port->clks[i] = IS_ERR(clk) ? NULL : clk;
+	}
+	return 0;
 }
 
 static int sci_init_single(struct platform_device *dev,
-- 
1.9.1


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

* [PATCH v3 22/27] serial: sh-sci: Add support for optional external (H)SCK input
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add support for using the SCIx clock pin "(H)SCK" as an external clock
input on (H)SCI(F), providing the sampling clock.

Note that this feature is not yet supported on the select SCIFA variants
that also have it (e.g. sh7723, sh7724, and r8a7740).

On (H)SCIF variants with an External Baud Rate Generator (BRG), the
BRG Clock Select Register must be configured for the external clock.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add comment that (H)SCK is undivided,
  - Add comment about BRG Clock Select Register mux,
  - Terminate loop over sampling rates on perfect match,
  - Reword patch description, using sampling clock source.
---
 drivers/tty/serial/sh-sci.c | 69 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index fa3fd876105b2252..229162481fd67b9d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -79,6 +79,7 @@ enum {
 
 enum SCI_CLKS {
 	SCI_FCK,		/* Functional Clock */
+	SCI_SCK,		/* Optional External Clock */
 	SCI_NUM_CLKS
 };
 
@@ -1924,6 +1925,39 @@ static void sci_shutdown(struct uart_port *port)
 	sci_free_irq(s);
 }
 
+static int sci_sck_calc(struct sci_port *s, unsigned int bps,
+			unsigned int *srr)
+{
+	unsigned long freq = s->clk_rates[SCI_SCK];
+	unsigned int min_sr, max_sr, sr;
+	int err, min_err = INT_MAX;
+
+	if (s->sampling_rate) {
+		/* SCI(F) has a fixed sampling rate */
+		min_sr = max_sr = s->sampling_rate / 2;
+	} else {
+		/* HSCIF has a variable 1/(8..32) sampling rate */
+		min_sr = 8;
+		max_sr = 32;
+	}
+
+	for (sr = max_sr; sr >= min_sr; sr--) {
+		err = DIV_ROUND_CLOSEST(freq, sr) - bps;
+		if (abs(err) >= abs(min_err))
+			continue;
+
+		min_err = err;
+		*srr = sr - 1;
+
+		if (!err)
+			break;
+	}
+
+	dev_dbg(s->port.dev, "SCK: %u%+d bps using SR %u\n", bps, min_err,
+		*srr + 1);
+	return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 			  unsigned int *brr, unsigned int *srr,
@@ -2019,7 +2053,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
 	unsigned int baud, smr_val = 0, scr_val = 0, i;
-	unsigned int brr = 255, cks = 0, srr = 15;
+	unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
 	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
@@ -2062,10 +2096,26 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that gives us the smallest deviation from the desired baud rate.
 	 */
 
+	/* Optional Undivided External Clock */
+	if (s->clk_rates[SCI_SCK] && port->type != PORT_SCIFA &&
+	    port->type != PORT_SCIFB) {
+		err = sci_sck_calc(s, baud, &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_SCK;
+			scr_val = SCSCR_CKE1;
+			sccks = SCCKS_CKS;
+			min_err = err;
+			srr = srr1;
+			if (!err)
+				goto done;
+		}
+	}
+
 	/* Divided Functional Clock using standard Bit Rate Register */
 	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
 	if (abs(err) < abs(min_err)) {
 		best_clk = SCI_FCK;
+		scr_val = 0;
 		min_err = err;
 		brr = brr1;
 		srr = srr1;
@@ -2079,14 +2129,23 @@ done:
 
 	sci_port_enable(s);
 
+	/*
+	 * Program the optional External Baud Rate Generator (BRG) first.
+	 * It controls the mux to select (H)SCK or frequency divided clock.
+	 */
+	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+		serial_port_out(port, SCCKS, sccks);
+
 	sci_reset(port);
 
 	uart_update_timeout(port, termios->c_cflag, baud);
 
 	if (best_clk >= 0) {
 		smr_val |= cks;
-		dev_dbg(port->dev, "SMR 0x%x BRR %u SRR %u\n", smr_val, brr,
-			srr);
+		dev_dbg(port->dev,
+			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
+			 scr_val, smr_val, brr, sccks, srr);
+		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
 		serial_port_out(port, SCBRR, brr);
 		if (sci_getreg(port, HSSRR)->size)
@@ -2322,10 +2381,14 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
 	const char *clk_names[] = {
 		[SCI_FCK] = "fck",
+		[SCI_SCK] = "sck",
 	};
 	struct clk *clk;
 	unsigned int i;
 
+	if (sci_port->cfg->type = PORT_HSCIF)
+		clk_names[SCI_SCK] = "hsck";
+
 	for (i = 0; i < SCI_NUM_CLKS; i++) {
 		clk = devm_clk_get(dev, clk_names[i]);
 		if (PTR_ERR(clk) = -EPROBE_DEFER)
-- 
1.9.1


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

* [PATCH v3 22/27] serial: sh-sci: Add support for optional external (H)SCK input
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add support for using the SCIx clock pin "(H)SCK" as an external clock
input on (H)SCI(F), providing the sampling clock.

Note that this feature is not yet supported on the select SCIFA variants
that also have it (e.g. sh7723, sh7724, and r8a7740).

On (H)SCIF variants with an External Baud Rate Generator (BRG), the
BRG Clock Select Register must be configured for the external clock.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Add comment that (H)SCK is undivided,
  - Add comment about BRG Clock Select Register mux,
  - Terminate loop over sampling rates on perfect match,
  - Reword patch description, using sampling clock source.
---
 drivers/tty/serial/sh-sci.c | 69 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index fa3fd876105b2252..229162481fd67b9d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -79,6 +79,7 @@ enum {
 
 enum SCI_CLKS {
 	SCI_FCK,		/* Functional Clock */
+	SCI_SCK,		/* Optional External Clock */
 	SCI_NUM_CLKS
 };
 
@@ -1924,6 +1925,39 @@ static void sci_shutdown(struct uart_port *port)
 	sci_free_irq(s);
 }
 
+static int sci_sck_calc(struct sci_port *s, unsigned int bps,
+			unsigned int *srr)
+{
+	unsigned long freq = s->clk_rates[SCI_SCK];
+	unsigned int min_sr, max_sr, sr;
+	int err, min_err = INT_MAX;
+
+	if (s->sampling_rate) {
+		/* SCI(F) has a fixed sampling rate */
+		min_sr = max_sr = s->sampling_rate / 2;
+	} else {
+		/* HSCIF has a variable 1/(8..32) sampling rate */
+		min_sr = 8;
+		max_sr = 32;
+	}
+
+	for (sr = max_sr; sr >= min_sr; sr--) {
+		err = DIV_ROUND_CLOSEST(freq, sr) - bps;
+		if (abs(err) >= abs(min_err))
+			continue;
+
+		min_err = err;
+		*srr = sr - 1;
+
+		if (!err)
+			break;
+	}
+
+	dev_dbg(s->port.dev, "SCK: %u%+d bps using SR %u\n", bps, min_err,
+		*srr + 1);
+	return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 			  unsigned int *brr, unsigned int *srr,
@@ -2019,7 +2053,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
 	unsigned int baud, smr_val = 0, scr_val = 0, i;
-	unsigned int brr = 255, cks = 0, srr = 15;
+	unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
 	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
@@ -2062,10 +2096,26 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	 * that gives us the smallest deviation from the desired baud rate.
 	 */
 
+	/* Optional Undivided External Clock */
+	if (s->clk_rates[SCI_SCK] && port->type != PORT_SCIFA &&
+	    port->type != PORT_SCIFB) {
+		err = sci_sck_calc(s, baud, &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_SCK;
+			scr_val = SCSCR_CKE1;
+			sccks = SCCKS_CKS;
+			min_err = err;
+			srr = srr1;
+			if (!err)
+				goto done;
+		}
+	}
+
 	/* Divided Functional Clock using standard Bit Rate Register */
 	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
 	if (abs(err) < abs(min_err)) {
 		best_clk = SCI_FCK;
+		scr_val = 0;
 		min_err = err;
 		brr = brr1;
 		srr = srr1;
@@ -2079,14 +2129,23 @@ done:
 
 	sci_port_enable(s);
 
+	/*
+	 * Program the optional External Baud Rate Generator (BRG) first.
+	 * It controls the mux to select (H)SCK or frequency divided clock.
+	 */
+	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+		serial_port_out(port, SCCKS, sccks);
+
 	sci_reset(port);
 
 	uart_update_timeout(port, termios->c_cflag, baud);
 
 	if (best_clk >= 0) {
 		smr_val |= cks;
-		dev_dbg(port->dev, "SMR 0x%x BRR %u SRR %u\n", smr_val, brr,
-			srr);
+		dev_dbg(port->dev,
+			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
+			 scr_val, smr_val, brr, sccks, srr);
+		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
 		serial_port_out(port, SCBRR, brr);
 		if (sci_getreg(port, HSSRR)->size)
@@ -2322,10 +2381,14 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
 	const char *clk_names[] = {
 		[SCI_FCK] = "fck",
+		[SCI_SCK] = "sck",
 	};
 	struct clk *clk;
 	unsigned int i;
 
+	if (sci_port->cfg->type == PORT_HSCIF)
+		clk_names[SCI_SCK] = "hsck";
+
 	for (i = 0; i < SCI_NUM_CLKS; i++) {
 		clk = devm_clk_get(dev, clk_names[i]);
 		if (PTR_ERR(clk) == -EPROBE_DEFER)
-- 
1.9.1


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

* [PATCH v3 23/27] serial: sh-sci: Add support for optional BRG on (H)SCIF
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add support for using the Baud Rate Generator for External Clock (BRG), as
found on some SCIF and HSCIF variants, to provide the sampling clock.
This can improve baud rate range and accuracy.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Terminate loop over sampling rates on perfect match,
  - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
  - Add comment that the BRG divides the internal/external clock,
  - Reword patch description, using sampling clock source.
---
 drivers/tty/serial/sh-sci.c | 85 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 80 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 229162481fd67b9d..4ff5d0cf812688ff 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -80,6 +80,8 @@ enum {
 enum SCI_CLKS {
 	SCI_FCK,		/* Functional Clock */
 	SCI_SCK,		/* Optional External Clock */
+	SCI_BRG_INT,		/* Optional BRG Internal Clock Source */
+	SCI_SCIF_CLK,		/* Optional BRG External Clock Source */
 	SCI_NUM_CLKS
 };
 
@@ -1958,6 +1960,43 @@ static int sci_sck_calc(struct sci_port *s, unsigned int bps,
 	return min_err;
 }
 
+static int sci_brg_calc(struct sci_port *s, unsigned int bps,
+			unsigned long freq, unsigned int *dlr,
+			unsigned int *srr)
+{
+	unsigned int min_sr, max_sr, sr, dl;
+	int err, min_err = INT_MAX;
+
+	if (s->sampling_rate) {
+		/* SCIF has a fixed sampling rate */
+		min_sr = max_sr = s->sampling_rate / 2;
+	} else {
+		/* HSCIF has a variable 1/(8..32) sampling rate */
+		min_sr = 8;
+		max_sr = 32;
+	}
+
+	for (sr = max_sr; sr >= min_sr; sr--) {
+		dl = DIV_ROUND_CLOSEST(freq, sr * bps);
+		dl = clamp(dl, 1U, 65535U);
+
+		err = DIV_ROUND_CLOSEST(freq, sr * dl) - bps;
+		if (abs(err) >= abs(min_err))
+			continue;
+
+		min_err = err;
+		*dlr = dl;
+		*srr = sr - 1;
+
+		if (!err)
+			break;
+	}
+
+	dev_dbg(s->port.dev, "BRG: %u%+d bps using DL %u SR %u\n", bps,
+		min_err, *dlr, *srr + 1);
+	return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 			  unsigned int *brr, unsigned int *srr,
@@ -2053,8 +2092,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
 	unsigned int baud, smr_val = 0, scr_val = 0, i;
-	unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
-	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
+	unsigned int brr = 255, cks = 0, srr = 15, dl = 0, sccks = 0;
+	unsigned int brr1 = 255, cks1 = 0, srr1 = 15, dl1 = 0;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
 	int min_err = INT_MAX, err;
@@ -2111,6 +2150,38 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 		}
 	}
 
+	/* Optional BRG Frequency Divided External Clock */
+	if (s->clk_rates[SCI_SCIF_CLK] && sci_getreg(port, SCDL)->size) {
+		err = sci_brg_calc(s, baud, s->clk_rates[SCI_SCIF_CLK], &dl1,
+				   &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_SCIF_CLK;
+			scr_val = SCSCR_CKE1;
+			sccks = 0;
+			min_err = err;
+			dl = dl1;
+			srr = srr1;
+			if (!err)
+				goto done;
+		}
+	}
+
+	/* Optional BRG Frequency Divided Internal Clock */
+	if (s->clk_rates[SCI_BRG_INT] && sci_getreg(port, SCDL)->size) {
+		err = sci_brg_calc(s, baud, s->clk_rates[SCI_BRG_INT], &dl1,
+				   &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_BRG_INT;
+			scr_val = SCSCR_CKE1;
+			sccks = SCCKS_XIN;
+			min_err = err;
+			dl = dl1;
+			srr = srr1;
+			if (!min_err)
+				goto done;
+		}
+	}
+
 	/* Divided Functional Clock using standard Bit Rate Register */
 	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
 	if (abs(err) < abs(min_err)) {
@@ -2133,8 +2204,10 @@ done:
 	 * Program the optional External Baud Rate Generator (BRG) first.
 	 * It controls the mux to select (H)SCK or frequency divided clock.
 	 */
-	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) {
+		serial_port_out(port, SCDL, dl);
 		serial_port_out(port, SCCKS, sccks);
+	}
 
 	sci_reset(port);
 
@@ -2143,8 +2216,8 @@ done:
 	if (best_clk >= 0) {
 		smr_val |= cks;
 		dev_dbg(port->dev,
-			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
-			 scr_val, smr_val, brr, sccks, srr);
+			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n",
+			 scr_val, smr_val, brr, sccks, dl, srr);
 		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
 		serial_port_out(port, SCBRR, brr);
@@ -2382,6 +2455,8 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	const char *clk_names[] = {
 		[SCI_FCK] = "fck",
 		[SCI_SCK] = "sck",
+		[SCI_BRG_INT] = "brg_int",
+		[SCI_SCIF_CLK] = "scif_clk",
 	};
 	struct clk *clk;
 	unsigned int i;
-- 
1.9.1


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

* [PATCH v3 23/27] serial: sh-sci: Add support for optional BRG on (H)SCIF
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

Add support for using the Baud Rate Generator for External Clock (BRG), as
found on some SCIF and HSCIF variants, to provide the sampling clock.
This can improve baud rate range and accuracy.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v3:
  - Add Acked-by,
  - Terminate loop over sampling rates on perfect match,
  - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
  - Add comment that the BRG divides the internal/external clock,
  - Reword patch description, using sampling clock source.
---
 drivers/tty/serial/sh-sci.c | 85 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 80 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 229162481fd67b9d..4ff5d0cf812688ff 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -80,6 +80,8 @@ enum {
 enum SCI_CLKS {
 	SCI_FCK,		/* Functional Clock */
 	SCI_SCK,		/* Optional External Clock */
+	SCI_BRG_INT,		/* Optional BRG Internal Clock Source */
+	SCI_SCIF_CLK,		/* Optional BRG External Clock Source */
 	SCI_NUM_CLKS
 };
 
@@ -1958,6 +1960,43 @@ static int sci_sck_calc(struct sci_port *s, unsigned int bps,
 	return min_err;
 }
 
+static int sci_brg_calc(struct sci_port *s, unsigned int bps,
+			unsigned long freq, unsigned int *dlr,
+			unsigned int *srr)
+{
+	unsigned int min_sr, max_sr, sr, dl;
+	int err, min_err = INT_MAX;
+
+	if (s->sampling_rate) {
+		/* SCIF has a fixed sampling rate */
+		min_sr = max_sr = s->sampling_rate / 2;
+	} else {
+		/* HSCIF has a variable 1/(8..32) sampling rate */
+		min_sr = 8;
+		max_sr = 32;
+	}
+
+	for (sr = max_sr; sr >= min_sr; sr--) {
+		dl = DIV_ROUND_CLOSEST(freq, sr * bps);
+		dl = clamp(dl, 1U, 65535U);
+
+		err = DIV_ROUND_CLOSEST(freq, sr * dl) - bps;
+		if (abs(err) >= abs(min_err))
+			continue;
+
+		min_err = err;
+		*dlr = dl;
+		*srr = sr - 1;
+
+		if (!err)
+			break;
+	}
+
+	dev_dbg(s->port.dev, "BRG: %u%+d bps using DL %u SR %u\n", bps,
+		min_err, *dlr, *srr + 1);
+	return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 			  unsigned int *brr, unsigned int *srr,
@@ -2053,8 +2092,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
 	unsigned int baud, smr_val = 0, scr_val = 0, i;
-	unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
-	unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
+	unsigned int brr = 255, cks = 0, srr = 15, dl = 0, sccks = 0;
+	unsigned int brr1 = 255, cks1 = 0, srr1 = 15, dl1 = 0;
 	struct sci_port *s = to_sci_port(port);
 	const struct plat_sci_reg *reg;
 	int min_err = INT_MAX, err;
@@ -2111,6 +2150,38 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 		}
 	}
 
+	/* Optional BRG Frequency Divided External Clock */
+	if (s->clk_rates[SCI_SCIF_CLK] && sci_getreg(port, SCDL)->size) {
+		err = sci_brg_calc(s, baud, s->clk_rates[SCI_SCIF_CLK], &dl1,
+				   &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_SCIF_CLK;
+			scr_val = SCSCR_CKE1;
+			sccks = 0;
+			min_err = err;
+			dl = dl1;
+			srr = srr1;
+			if (!err)
+				goto done;
+		}
+	}
+
+	/* Optional BRG Frequency Divided Internal Clock */
+	if (s->clk_rates[SCI_BRG_INT] && sci_getreg(port, SCDL)->size) {
+		err = sci_brg_calc(s, baud, s->clk_rates[SCI_BRG_INT], &dl1,
+				   &srr1);
+		if (abs(err) < abs(min_err)) {
+			best_clk = SCI_BRG_INT;
+			scr_val = SCSCR_CKE1;
+			sccks = SCCKS_XIN;
+			min_err = err;
+			dl = dl1;
+			srr = srr1;
+			if (!min_err)
+				goto done;
+		}
+	}
+
 	/* Divided Functional Clock using standard Bit Rate Register */
 	err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
 	if (abs(err) < abs(min_err)) {
@@ -2133,8 +2204,10 @@ done:
 	 * Program the optional External Baud Rate Generator (BRG) first.
 	 * It controls the mux to select (H)SCK or frequency divided clock.
 	 */
-	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+	if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) {
+		serial_port_out(port, SCDL, dl);
 		serial_port_out(port, SCCKS, sccks);
+	}
 
 	sci_reset(port);
 
@@ -2143,8 +2216,8 @@ done:
 	if (best_clk >= 0) {
 		smr_val |= cks;
 		dev_dbg(port->dev,
-			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
-			 scr_val, smr_val, brr, sccks, srr);
+			 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n",
+			 scr_val, smr_val, brr, sccks, dl, srr);
 		serial_port_out(port, SCSCR, scr_val);
 		serial_port_out(port, SCSMR, smr_val);
 		serial_port_out(port, SCBRR, brr);
@@ -2382,6 +2455,8 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 	const char *clk_names[] = {
 		[SCI_FCK] = "fck",
 		[SCI_SCK] = "sck",
+		[SCI_BRG_INT] = "brg_int",
+		[SCI_SCIF_CLK] = "scif_clk",
 	};
 	struct clk *clk;
 	unsigned int i;
-- 
1.9.1


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

* [PATCH v3 24/27] sh: Rename sci_ick and sci_fck clock to fck
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

The SCI driver requires a functional clock named "fck" and falls back to
"sci_ick" or "sci_fck" when the "fck" clock doesn't exist. To allow
removal of the fallback code rename the sci_ick and sci_fck clocks to
fck for all SH platforms.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - No changes,

v2:
  - Add Acked-by.
---
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c |  9 ++++++++-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c | 16 ++++++++--------
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c |  8 ++++----
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c |  6 +++---
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c |  6 +++---
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-shx3.c   |  8 ++++----
 10 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7264.c b/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
index 8638fba6cd7fbf08..7e06e39b095864d1 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
@@ -115,7 +115,14 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
 
 	/* MSTP clocks */
-	CLKDEV_CON_ID("sci_ick", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP77]),
 	CLKDEV_CON_ID("vdc3", &mstp_clks[MSTP74]),
 	CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]),
 	CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7269.c b/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
index f8a5c2abdfb3caa1..663a97bed554ec5c 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
@@ -150,14 +150,14 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
 
 	/* MSTP clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP47]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP46]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP45]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP44]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP43]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP42]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.6", &mstp_clks[MSTP41]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.7", &mstp_clks[MSTP40]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP47]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP46]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP45]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP44]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP43]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP42]),
+	CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP41]),
+	CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP40]),
 	CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]),
 	CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
 	CLKDEV_ICK_ID("fck", "sh-mtu2", &mstp_clks[MSTP35]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
index 9edc06c02dcf1b9c..a907ee2388bfce50 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
@@ -232,10 +232,10 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
 	CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP004]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP004]),
 
 	CLKDEV_CON_ID("sio0", &mstp_clks[MSTP003]),
 	CLKDEV_CON_ID("siof0", &mstp_clks[MSTP002]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7366.c b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
index 955b9add78106360..ac9854179dee88f0 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
@@ -230,9 +230,9 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
 	CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),
 
 	CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),
 	CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7723.c b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
index ccbcab550df24efc..fe844222f3f6ae5c 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
@@ -267,12 +267,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[HWBLK_TMU0]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[HWBLK_TMU1]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]),
 
 	CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[HWBLK_LCDC]),
 };
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7734.c b/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
index 7f54bf2f453d7a7b..354dcac5e4cd9938 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
@@ -194,12 +194,12 @@ static struct clk_lookup lookups[] = {
 	/* MSTP32 clocks */
 	CLKDEV_DEV_ID("i2c-sh7734.0", &mstp_clks[MSTP030]),
 	CLKDEV_DEV_ID("i2c-sh7734.1", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP024]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP023]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP022]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP021]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP023]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP022]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP021]),
 	CLKDEV_CON_ID("hscif", &mstp_clks[MSTP019]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP016]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP015]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
index e40ec2c97ad199c9..b10af2ae9f350908 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
@@ -125,9 +125,9 @@ static struct clk_lookup lookups[] = {
 
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP113]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP114]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP112]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP111]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP110]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP112]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP111]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP110]),
 
 	CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP103]),
 	CLKDEV_DEV_ID("renesas_usbhs.0", &mstp_clks[MSTP102]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
index 8eb6e62340c950bd..1aafd5496752f7f1 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
@@ -132,12 +132,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]),
 	CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
index 5e50e7ebeff089b9..ac3dcfe5d303d134 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
@@ -139,12 +139,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("ssi3_fck", &mstp_clks[MSTP023]),
 	CLKDEV_CON_ID("ssi2_fck", &mstp_clks[MSTP022]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-shx3.c b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
index 605221d1448a19a7..b1bdbc3cbc219af8 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-shx3.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
@@ -114,10 +114,10 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("h8ex_fck", &mstp_clks[MSTP003]),
 	CLKDEV_CON_ID("csm_fck", &mstp_clks[MSTP002]),
-- 
1.9.1


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

* [PATCH v3 24/27] sh: Rename sci_ick and sci_fck clock to fck
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

The SCI driver requires a functional clock named "fck" and falls back to
"sci_ick" or "sci_fck" when the "fck" clock doesn't exist. To allow
removal of the fallback code rename the sci_ick and sci_fck clocks to
fck for all SH platforms.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - No changes,

v2:
  - Add Acked-by.
---
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c |  9 ++++++++-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c | 16 ++++++++--------
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c |  8 ++++----
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c |  6 +++---
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c |  6 +++---
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c | 12 ++++++------
 arch/sh/kernel/cpu/sh4a/clock-shx3.c   |  8 ++++----
 10 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7264.c b/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
index 8638fba6cd7fbf08..7e06e39b095864d1 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7264.c
@@ -115,7 +115,14 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
 
 	/* MSTP clocks */
-	CLKDEV_CON_ID("sci_ick", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP77]),
+	CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP77]),
 	CLKDEV_CON_ID("vdc3", &mstp_clks[MSTP74]),
 	CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]),
 	CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7269.c b/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
index f8a5c2abdfb3caa1..663a97bed554ec5c 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7269.c
@@ -150,14 +150,14 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
 
 	/* MSTP clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP47]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP46]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP45]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP44]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP43]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP42]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.6", &mstp_clks[MSTP41]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.7", &mstp_clks[MSTP40]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP47]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP46]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP45]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP44]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP43]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP42]),
+	CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP41]),
+	CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP40]),
 	CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]),
 	CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
 	CLKDEV_ICK_ID("fck", "sh-mtu2", &mstp_clks[MSTP35]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
index 9edc06c02dcf1b9c..a907ee2388bfce50 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
@@ -232,10 +232,10 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
 	CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP004]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP004]),
 
 	CLKDEV_CON_ID("sio0", &mstp_clks[MSTP003]),
 	CLKDEV_CON_ID("siof0", &mstp_clks[MSTP002]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7366.c b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
index 955b9add78106360..ac9854179dee88f0 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
@@ -230,9 +230,9 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
 	CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP007]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP006]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP005]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),
 
 	CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),
 	CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7723.c b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
index ccbcab550df24efc..fe844222f3f6ae5c 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
@@ -267,12 +267,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[HWBLK_TMU0]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[HWBLK_TMU1]),
 
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]),
 
 	CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[HWBLK_LCDC]),
 };
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7734.c b/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
index 7f54bf2f453d7a7b..354dcac5e4cd9938 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
@@ -194,12 +194,12 @@ static struct clk_lookup lookups[] = {
 	/* MSTP32 clocks */
 	CLKDEV_DEV_ID("i2c-sh7734.0", &mstp_clks[MSTP030]),
 	CLKDEV_DEV_ID("i2c-sh7734.1", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP024]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP023]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP022]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP021]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP023]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP022]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP021]),
 	CLKDEV_CON_ID("hscif", &mstp_clks[MSTP019]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP016]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP015]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
index e40ec2c97ad199c9..b10af2ae9f350908 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
@@ -125,9 +125,9 @@ static struct clk_lookup lookups[] = {
 
 	CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP113]),
 	CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP114]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP112]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP111]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP110]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP112]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP111]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP110]),
 
 	CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP103]),
 	CLKDEV_DEV_ID("renesas_usbhs.0", &mstp_clks[MSTP102]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
index 8eb6e62340c950bd..1aafd5496752f7f1 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
@@ -132,12 +132,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]),
 	CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
index 5e50e7ebeff089b9..ac3dcfe5d303d134 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
@@ -139,12 +139,12 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[MSTP029]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[MSTP028]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP029]),
+	CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP028]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("ssi3_fck", &mstp_clks[MSTP023]),
 	CLKDEV_CON_ID("ssi2_fck", &mstp_clks[MSTP022]),
diff --git a/arch/sh/kernel/cpu/sh4a/clock-shx3.c b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
index 605221d1448a19a7..b1bdbc3cbc219af8 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-shx3.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
@@ -114,10 +114,10 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
 
 	/* MSTP32 clocks */
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
-	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
+	CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP027]),
+	CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP026]),
+	CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
+	CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP024]),
 
 	CLKDEV_CON_ID("h8ex_fck", &mstp_clks[MSTP003]),
 	CLKDEV_CON_ID("csm_fck", &mstp_clks[MSTP002]),
-- 
1.9.1


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

* [PATCH v3 25/27] sh: Remove sci_ick clock alias
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

The sh-sci driver falls back to the peripheral clock if the sci_ick
clock doesn't exist. There's thus no need to create an alias for the
peripheral clock named sci_ick.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - No changes,

v2:
  - Add Acked-by.
---
 arch/sh/kernel/cpu/clock-cpg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/sh/kernel/cpu/clock-cpg.c b/arch/sh/kernel/cpu/clock-cpg.c
index 8525a671266fe149..786c0769b4c393b5 100644
--- a/arch/sh/kernel/cpu/clock-cpg.c
+++ b/arch/sh/kernel/cpu/clock-cpg.c
@@ -63,7 +63,6 @@ int __init __deprecated cpg_clk_init(void)
 	clk_add_alias("fck", "sh-mtu2", "peripheral_clk", NULL);
 	clk_add_alias("fck", "sh-cmt-16.0", "peripheral_clk", NULL);
 	clk_add_alias("fck", "sh-cmt-32.0", "peripheral_clk", NULL);
-	clk_add_alias("sci_ick", NULL, "peripheral_clk", NULL);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v3 25/27] sh: Remove sci_ick clock alias
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

The sh-sci driver falls back to the peripheral clock if the sci_ick
clock doesn't exist. There's thus no need to create an alias for the
peripheral clock named sci_ick.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v3:
  - No changes,

v2:
  - Add Acked-by.
---
 arch/sh/kernel/cpu/clock-cpg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/sh/kernel/cpu/clock-cpg.c b/arch/sh/kernel/cpu/clock-cpg.c
index 8525a671266fe149..786c0769b4c393b5 100644
--- a/arch/sh/kernel/cpu/clock-cpg.c
+++ b/arch/sh/kernel/cpu/clock-cpg.c
@@ -63,7 +63,6 @@ int __init __deprecated cpg_clk_init(void)
 	clk_add_alias("fck", "sh-mtu2", "peripheral_clk", NULL);
 	clk_add_alias("fck", "sh-cmt-16.0", "peripheral_clk", NULL);
 	clk_add_alias("fck", "sh-cmt-32.0", "peripheral_clk", NULL);
-	clk_add_alias("sci_ick", NULL, "peripheral_clk", NULL);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v3 26/27] sh: sh7734: Correct SCIF type for BRG
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The SCIF variant in the sh7734 SoC is not the common "SH-4(A)" variant,
but a derivative with added "Baud Rate Generator for External Clock"
(BRG). Correct the regtype value in platform data to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Untested due to lack of hardware.
This shouldn't make any difference until the additional clocks are
provided by the platform.

v3:
  - No changes.
---
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
index f617bcb734dfeb76..69b8a50310d9a23f 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
@@ -28,7 +28,7 @@ static struct plat_sci_port scif0_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif0_resources[] = {
@@ -50,7 +50,7 @@ static struct plat_sci_port scif1_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif1_resources[] = {
@@ -72,7 +72,7 @@ static struct plat_sci_port scif2_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif2_resources[] = {
@@ -94,7 +94,7 @@ static struct plat_sci_port scif3_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE | SCSCR_TOIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif3_resources[] = {
@@ -116,7 +116,7 @@ static struct plat_sci_port scif4_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif4_resources[] = {
@@ -138,7 +138,7 @@ static struct plat_sci_port scif5_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype		= SCIx_SH4_SCIF_REGTYPE,
+	.regtype	= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif5_resources[] = {
-- 
1.9.1


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

* [PATCH v3 26/27] sh: sh7734: Correct SCIF type for BRG
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Geert Uytterhoeven

The SCIF variant in the sh7734 SoC is not the common "SH-4(A)" variant,
but a derivative with added "Baud Rate Generator for External Clock"
(BRG). Correct the regtype value in platform data to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Untested due to lack of hardware.
This shouldn't make any difference until the additional clocks are
provided by the platform.

v3:
  - No changes.
---
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
index f617bcb734dfeb76..69b8a50310d9a23f 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
@@ -28,7 +28,7 @@ static struct plat_sci_port scif0_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif0_resources[] = {
@@ -50,7 +50,7 @@ static struct plat_sci_port scif1_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif1_resources[] = {
@@ -72,7 +72,7 @@ static struct plat_sci_port scif2_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif2_resources[] = {
@@ -94,7 +94,7 @@ static struct plat_sci_port scif3_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE | SCSCR_TOIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif3_resources[] = {
@@ -116,7 +116,7 @@ static struct plat_sci_port scif4_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype        = SCIx_SH4_SCIF_REGTYPE,
+	.regtype        = SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif4_resources[] = {
@@ -138,7 +138,7 @@ static struct plat_sci_port scif5_platform_data = {
 	.flags          = UPF_BOOT_AUTOCONF,
 	.scscr          = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
 	.type           = PORT_SCIF,
-	.regtype		= SCIx_SH4_SCIF_REGTYPE,
+	.regtype	= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif5_resources[] = {
-- 
1.9.1


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

* [PATCH v3 27/27] serial: sh-sci: Drop the sci_fck clock fallback
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

All platforms that used to define an sci_fck clock have now switched to
the fck name. Remove the fallback code.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
Do NOT apply until "sh: Rename sci_ick and sci_fck clock to fck" has
been applied!

v3:
  - Add Acked-by,
  - Moved after BRG sh-sci patches to remove dependency of BRG patches
    on SH patches,

v2:
  - Add Acked-by.
---
 drivers/tty/serial/sh-sci.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4ff5d0cf812688ff..6571f4d944c26297 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2481,11 +2481,6 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 			if (!IS_ERR(clk))
 				goto found;
 
-			/* SH has historically named the clock "sci_fck". */
-			clk = devm_clk_get(dev, "sci_fck");
-			if (!IS_ERR(clk))
-				goto found;
-
 			/*
 			 * Not all SH platforms declare a clock lookup entry
 			 * for SCI devices, in which case we need to get the
-- 
1.9.1


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

* [PATCH v3 27/27] serial: sh-sci: Drop the sci_fck clock fallback
@ 2015-12-14 18:57   ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-14 18:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato
  Cc: linux-serial, linux-sh, Laurent Pinchart, Geert Uytterhoeven

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

All platforms that used to define an sci_fck clock have now switched to
the fck name. Remove the fallback code.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
Do NOT apply until "sh: Rename sci_ick and sci_fck clock to fck" has
been applied!

v3:
  - Add Acked-by,
  - Moved after BRG sh-sci patches to remove dependency of BRG patches
    on SH patches,

v2:
  - Add Acked-by.
---
 drivers/tty/serial/sh-sci.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4ff5d0cf812688ff..6571f4d944c26297 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2481,11 +2481,6 @@ static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 			if (!IS_ERR(clk))
 				goto found;
 
-			/* SH has historically named the clock "sci_fck". */
-			clk = devm_clk_get(dev, "sci_fck");
-			if (!IS_ERR(clk))
-				goto found;
-
 			/*
 			 * Not all SH platforms declare a clock lookup entry
 			 * for SCI devices, in which case we need to get the
-- 
1.9.1


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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
  2015-12-14 18:57 ` Geert Uytterhoeven
@ 2015-12-15  4:53   ` Simon Horman
  -1 siblings, 0 replies; 70+ messages in thread
From: Simon Horman @ 2015-12-15  4:53 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Magnus Damm, Yoshinori Sato, linux-serial, linux-sh

Hi Geert,

thanks for taking care of this, is quite a task!

On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
> 	Hi Greg, Simon, Magnus, Sato-san,
> 
> This patch series contains several patches for the Renesas SCI serial
> driver:
>   - Clean up the naming of clocks in the driver and its DT bindings,
>   - Add support for the optional external clock on (H)SCI(F) and some
>     SCIFA, 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.
> Using external clocks increases the range and accuracy of supported baud
> rates.
> 
> This series is an updated version of the core (driver) changes of two
> series I sent before:
>   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
>     (http://www.spinics.net/lists/linux-serial/msg19762.html)
>   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
>     (https://lkml.org/lkml/2015/11/19/550)
> To reduce (cross) dependencies, I split off the integration (DTS)
> patches into separate series:
>   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
>      strings",
>   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
>      clock to fck",
>   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
>   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
>     pins".
> As the SH architecture is orphaned, and the risk of conflicts is small,
> I have bundled all SH-specific changes with the core changes.  This
> reduces dependencies, too.

At this point I see two ways to move things forwards:

1. Greg can consider taking this series and I can take the
   related integration (DTS) series (noted below) into v4.6.
2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
   and try and queue up this series and the related integration (DTS)
   series (noted below).

As it (perhaps surprisingly) it is late in the merge cycle for me to take
changes for v4.5 that will go though the ARM SoC tree and I am trying to
stabilise things a little. Thus, I favour option 1.

> Changes compared to previous submission (more detailed information in
> the individual patches):
>   - Add fallback compatibility strings for R-Car Gen1, Gen2, Gen3, which
>     allows the driver to match on (less) family-specific instead of
>     (more) SoC-specific compatible values,
>   - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
>   - Terminate loops over sampling rates on perfect matches,
>   - Many comments and clarifications in patch descriptions,
>   - Add Acked-by, Reviewed-by.
> 
> 
> This series consists of several parts:
>   - The first four patches update DT binding documentation.
>     The first patch also updates the driver, and is a hard dependency
>     for the integration (DTS) patches, and for the SH patches.
> 
>     [01/27] serial: sh-sci: Drop the interface clock
>     [02/27] serial: sh-sci: Add fallback compatibility strings (NEW)
>     [03/27] serial: sh-sci: Update DT binding documentation for external
> 			    clock input
>     [04/27] serial: sh-sci: Update DT binding documentation for BRG
> 			    support
> 
>   - Patches 5-23 update the driver only, and add external clock and BRG
>     support.
> 
>     [05/27] serial: sh-sci: Drop useless check for zero
>     [06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
>     [07/27] serial: sh-sci: Use existing local variable in
> 			    sci_parse_dt() (NEW)
>     [08/27] serial: sh-sci: Drop unused frame_len parameter for
> 			    sci_baud_calc_hscif()
>     [09/27] serial: sh-sci: Don't overwrite clock selection in
> 			    serial_console_write()
>     [10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
>     [11/27] serial: sh-sci: Make unsigned values in
> 			    sci_baud_calc_hscif() unsigned
>     [12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>     [13/27] serial: sh-sci: Improve bit rate error calculation for
> 			    HSCIF
>     [14/27] serial: sh-sci: Avoid calculating the receive margin for
> 			    HSCIF
>     [15/27] serial: sh-sci: Merge sci_scbrr_calc() and
> 			    sci_baud_calc_hscif()
>     [16/27] serial: sh-sci: Take into account sampling rate for max baud
> 			    rate
>     [17/27] serial: sh-sci: Add BRG register definitions
>     [18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype
> 			    encoding
>     [19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
>     [20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
>     [21/27] serial: sh-sci: Prepare for multiple sampling clock sources
>     [22/27] serial: sh-sci: Add support for optional external (H)SCK
> 			    input
>     [23/27] serial: sh-sci: Add support for optional BRG on H)SCIF
> 
>   - Patches 24-26 update the SH architecture.
>     Patches 24 and 25 have a hard dependency on patch 1.
>     Patch 26 has a hard dependency on patch 17.
> 
>     [24/27] sh: Rename sci_ick and sci_fck clock to fck
>     [25/27] sh: Remove sci_ick clock alias
>     [26/27] sh: sh7734: Correct SCIF type for BRG
> 
>   - Patch 27 has a hard dependency on patch 24.
> 
>     [27/27] serial: sh-sci: Drop the sci_fck clock fallback
> 
> Testing:
>   - The Baud Rate Generator for External Clock (BRG) was tested on
>       - R-Car Gen1 (r8a7778/bockw, r8a7779/marzen, on SCIF),
>       - R-Car Gen2 (r8a7791/koelsch, on SCIF and HSCIF),
>       - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
>   - The external clock input on (H)SCK was tested on
>       - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
>   - Regression testing was done on Renesas ARM platforms that use SCIFA
>     as the console (r8a73a4/ape6evm, r8a7740/armadillo, and
>     sh73a0/kzm9g),
>   - You can find more testing-related information in the final
>     integration series.
> 
> Merge strategy:
>   - This series applies to v4.4-rc1,
>   - It would be good if at least the first 4 patches end up in v4.5, as
>     they contain DT bindings, and a hard dependency for some DTS
>     updates,
>   - If the 3 SH patches 24-26, and patch 27 go in together, this can be
>     done in the same release. Else the SH patches may have to wait for
>     v4.6, and patch 27 for v4.7.
>   - Greg has provided his ack for most patches (minus the SH-specific,
>     and the 2 new patches), and is OK for the patches going in through
>     another tree, so these could go in through Simon's tree as well,
>       - If these patches go in through Greg's tree, the DTS updates with
> 	a hard dependency on the first patch have to wait for v4.6,
>       - If these patches go in through Simon's tree, the DTS updates
> 	with a hard dependency on the first patch can go in v4.5, too,
>   - Note that some of the DTS updates have to wait for v4.6 due to other
>     dependencies (pinctrl, more info in the integration series),
>   - Note that there are a few unrelated sh-sci fixes floating around.
>     I think these should go through Greg's tree anyway (they are
>     unrelated, and I don't think these cause conflicts).
> 
> Greg/Simon, what do you think?
> 
> I've also pushed this series (against v4.4-rc1) to the
> topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
> repository at
> https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
> 
> For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
> as it includes the integration part.
> 
> Thanks for applying!
> 
> Geert Uytterhoeven (23):
>   serial: sh-sci: Add fallback compatibility strings
>   serial: sh-sci: Update DT binding documentation for external clock
>     input
>   serial: sh-sci: Update DT binding documentation for BRG support
>   serial: sh-sci: Drop useless check for zero sampling_rate
>   serial: sh-sci: Grammar s/Get ... for/Get ... from/
>   serial: sh-sci: Use existing local variable in sci_parse_dt()
>   serial: sh-sci: Drop unused frame_len parameter for
>     sci_baud_calc_hscif()
>   serial: sh-sci: Don't overwrite clock selection in
>     serial_console_write()
>   serial: sh-sci: Convert from clk_get() to devm_clk_get()
>   serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
>   serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>   serial: sh-sci: Improve bit rate error calculation for HSCIF
>   serial: sh-sci: Avoid calculating the receive margin for HSCIF
>   serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
>   serial: sh-sci: Take into account sampling rate for max baud rate
>   serial: sh-sci: Add BRG register definitions
>   serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
>   serial: sh-sci: Correct SCIF type on RZ/A1H
>   serial: sh-sci: Correct SCIF type on R-Car for BRG
>   serial: sh-sci: Prepare for multiple sampling clock sources
>   serial: sh-sci: Add support for optional external (H)SCK input
>   serial: sh-sci: Add support for optional BRG on (H)SCIF
>   sh: sh7734: Correct SCIF type for BRG
> 
> Laurent Pinchart (4):
>   serial: sh-sci: Drop the interface clock
>   sh: Rename sci_ick and sci_fck clock to fck
>   sh: Remove sci_ick clock alias
>   serial: sh-sci: Drop the sci_fck clock fallback
> 
>  .../bindings/serial/renesas,sci-serial.txt         |  32 +-
>  arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
>  arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
>  arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
>  arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
>  drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
>  drivers/tty/serial/sh-sci.h                        |  10 +
>  include/linux/serial_sci.h                         |   1 +
>  16 files changed, 500 insertions(+), 212 deletions(-)
> 
> -- 
> 1.9.1
> 
> Gr{oetje,eeting}s,
> 
> 						Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> 							    -- Linus Torvalds
> 

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-15  4:53   ` Simon Horman
  0 siblings, 0 replies; 70+ messages in thread
From: Simon Horman @ 2015-12-15  4:53 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Magnus Damm, Yoshinori Sato, linux-serial, linux-sh

Hi Geert,

thanks for taking care of this, is quite a task!

On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
> 	Hi Greg, Simon, Magnus, Sato-san,
> 
> This patch series contains several patches for the Renesas SCI serial
> driver:
>   - Clean up the naming of clocks in the driver and its DT bindings,
>   - Add support for the optional external clock on (H)SCI(F) and some
>     SCIFA, 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.
> Using external clocks increases the range and accuracy of supported baud
> rates.
> 
> This series is an updated version of the core (driver) changes of two
> series I sent before:
>   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
>     (http://www.spinics.net/lists/linux-serial/msg19762.html)
>   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
>     (https://lkml.org/lkml/2015/11/19/550)
> To reduce (cross) dependencies, I split off the integration (DTS)
> patches into separate series:
>   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
>      strings",
>   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
>      clock to fck",
>   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
>   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
>     pins".
> As the SH architecture is orphaned, and the risk of conflicts is small,
> I have bundled all SH-specific changes with the core changes.  This
> reduces dependencies, too.

At this point I see two ways to move things forwards:

1. Greg can consider taking this series and I can take the
   related integration (DTS) series (noted below) into v4.6.
2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
   and try and queue up this series and the related integration (DTS)
   series (noted below).

As it (perhaps surprisingly) it is late in the merge cycle for me to take
changes for v4.5 that will go though the ARM SoC tree and I am trying to
stabilise things a little. Thus, I favour option 1.

> Changes compared to previous submission (more detailed information in
> the individual patches):
>   - Add fallback compatibility strings for R-Car Gen1, Gen2, Gen3, which
>     allows the driver to match on (less) family-specific instead of
>     (more) SoC-specific compatible values,
>   - Rename "int_clk" to "brg_int", "SCI_INT_CLK" to "SCI_BRG_INT",
>   - Terminate loops over sampling rates on perfect matches,
>   - Many comments and clarifications in patch descriptions,
>   - Add Acked-by, Reviewed-by.
> 
> 
> This series consists of several parts:
>   - The first four patches update DT binding documentation.
>     The first patch also updates the driver, and is a hard dependency
>     for the integration (DTS) patches, and for the SH patches.
> 
>     [01/27] serial: sh-sci: Drop the interface clock
>     [02/27] serial: sh-sci: Add fallback compatibility strings (NEW)
>     [03/27] serial: sh-sci: Update DT binding documentation for external
> 			    clock input
>     [04/27] serial: sh-sci: Update DT binding documentation for BRG
> 			    support
> 
>   - Patches 5-23 update the driver only, and add external clock and BRG
>     support.
> 
>     [05/27] serial: sh-sci: Drop useless check for zero
>     [06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/
>     [07/27] serial: sh-sci: Use existing local variable in
> 			    sci_parse_dt() (NEW)
>     [08/27] serial: sh-sci: Drop unused frame_len parameter for
> 			    sci_baud_calc_hscif()
>     [09/27] serial: sh-sci: Don't overwrite clock selection in
> 			    serial_console_write()
>     [10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get()
>     [11/27] serial: sh-sci: Make unsigned values in
> 			    sci_baud_calc_hscif() unsigned
>     [12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>     [13/27] serial: sh-sci: Improve bit rate error calculation for
> 			    HSCIF
>     [14/27] serial: sh-sci: Avoid calculating the receive margin for
> 			    HSCIF
>     [15/27] serial: sh-sci: Merge sci_scbrr_calc() and
> 			    sci_baud_calc_hscif()
>     [16/27] serial: sh-sci: Take into account sampling rate for max baud
> 			    rate
>     [17/27] serial: sh-sci: Add BRG register definitions
>     [18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype
> 			    encoding
>     [19/27] serial: sh-sci: Correct SCIF type on RZ/A1H
>     [20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG
>     [21/27] serial: sh-sci: Prepare for multiple sampling clock sources
>     [22/27] serial: sh-sci: Add support for optional external (H)SCK
> 			    input
>     [23/27] serial: sh-sci: Add support for optional BRG on H)SCIF
> 
>   - Patches 24-26 update the SH architecture.
>     Patches 24 and 25 have a hard dependency on patch 1.
>     Patch 26 has a hard dependency on patch 17.
> 
>     [24/27] sh: Rename sci_ick and sci_fck clock to fck
>     [25/27] sh: Remove sci_ick clock alias
>     [26/27] sh: sh7734: Correct SCIF type for BRG
> 
>   - Patch 27 has a hard dependency on patch 24.
> 
>     [27/27] serial: sh-sci: Drop the sci_fck clock fallback
> 
> Testing:
>   - The Baud Rate Generator for External Clock (BRG) was tested on
>       - R-Car Gen1 (r8a7778/bockw, r8a7779/marzen, on SCIF),
>       - R-Car Gen2 (r8a7791/koelsch, on SCIF and HSCIF),
>       - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
>   - The external clock input on (H)SCK was tested on
>       - R-Car Gen3 (r8a7795/salvator-x, on SCIF and HSCIF),
>   - Regression testing was done on Renesas ARM platforms that use SCIFA
>     as the console (r8a73a4/ape6evm, r8a7740/armadillo, and
>     sh73a0/kzm9g),
>   - You can find more testing-related information in the final
>     integration series.
> 
> Merge strategy:
>   - This series applies to v4.4-rc1,
>   - It would be good if at least the first 4 patches end up in v4.5, as
>     they contain DT bindings, and a hard dependency for some DTS
>     updates,
>   - If the 3 SH patches 24-26, and patch 27 go in together, this can be
>     done in the same release. Else the SH patches may have to wait for
>     v4.6, and patch 27 for v4.7.
>   - Greg has provided his ack for most patches (minus the SH-specific,
>     and the 2 new patches), and is OK for the patches going in through
>     another tree, so these could go in through Simon's tree as well,
>       - If these patches go in through Greg's tree, the DTS updates with
> 	a hard dependency on the first patch have to wait for v4.6,
>       - If these patches go in through Simon's tree, the DTS updates
> 	with a hard dependency on the first patch can go in v4.5, too,
>   - Note that some of the DTS updates have to wait for v4.6 due to other
>     dependencies (pinctrl, more info in the integration series),
>   - Note that there are a few unrelated sh-sci fixes floating around.
>     I think these should go through Greg's tree anyway (they are
>     unrelated, and I don't think these cause conflicts).
> 
> Greg/Simon, what do you think?
> 
> I've also pushed this series (against v4.4-rc1) to the
> topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
> repository at
> https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
> 
> For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
> as it includes the integration part.
> 
> Thanks for applying!
> 
> Geert Uytterhoeven (23):
>   serial: sh-sci: Add fallback compatibility strings
>   serial: sh-sci: Update DT binding documentation for external clock
>     input
>   serial: sh-sci: Update DT binding documentation for BRG support
>   serial: sh-sci: Drop useless check for zero sampling_rate
>   serial: sh-sci: Grammar s/Get ... for/Get ... from/
>   serial: sh-sci: Use existing local variable in sci_parse_dt()
>   serial: sh-sci: Drop unused frame_len parameter for
>     sci_baud_calc_hscif()
>   serial: sh-sci: Don't overwrite clock selection in
>     serial_console_write()
>   serial: sh-sci: Convert from clk_get() to devm_clk_get()
>   serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
>   serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>   serial: sh-sci: Improve bit rate error calculation for HSCIF
>   serial: sh-sci: Avoid calculating the receive margin for HSCIF
>   serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
>   serial: sh-sci: Take into account sampling rate for max baud rate
>   serial: sh-sci: Add BRG register definitions
>   serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
>   serial: sh-sci: Correct SCIF type on RZ/A1H
>   serial: sh-sci: Correct SCIF type on R-Car for BRG
>   serial: sh-sci: Prepare for multiple sampling clock sources
>   serial: sh-sci: Add support for optional external (H)SCK input
>   serial: sh-sci: Add support for optional BRG on (H)SCIF
>   sh: sh7734: Correct SCIF type for BRG
> 
> Laurent Pinchart (4):
>   serial: sh-sci: Drop the interface clock
>   sh: Rename sci_ick and sci_fck clock to fck
>   sh: Remove sci_ick clock alias
>   serial: sh-sci: Drop the sci_fck clock fallback
> 
>  .../bindings/serial/renesas,sci-serial.txt         |  32 +-
>  arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
>  arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
>  arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
>  arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
>  drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
>  drivers/tty/serial/sh-sci.h                        |  10 +
>  include/linux/serial_sci.h                         |   1 +
>  16 files changed, 500 insertions(+), 212 deletions(-)
> 
> -- 
> 1.9.1
> 
> Gr{oetje,eeting}s,
> 
> 						Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> 							    -- Linus Torvalds
> 

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
  2015-12-15  4:53   ` Simon Horman
@ 2015-12-15  5:23     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 70+ messages in thread
From: Greg Kroah-Hartman @ 2015-12-15  5:23 UTC (permalink / raw)
  To: Simon Horman
  Cc: Geert Uytterhoeven, Magnus Damm, Yoshinori Sato, linux-serial, linux-sh

On Tue, Dec 15, 2015 at 01:53:51PM +0900, Simon Horman wrote:
> Hi Geert,
> 
> thanks for taking care of this, is quite a task!
> 
> On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
> > 	Hi Greg, Simon, Magnus, Sato-san,
> > 
> > This patch series contains several patches for the Renesas SCI serial
> > driver:
> >   - Clean up the naming of clocks in the driver and its DT bindings,
> >   - Add support for the optional external clock on (H)SCI(F) and some
> >     SCIFA, 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.
> > Using external clocks increases the range and accuracy of supported baud
> > rates.
> > 
> > This series is an updated version of the core (driver) changes of two
> > series I sent before:
> >   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
> >     (http://www.spinics.net/lists/linux-serial/msg19762.html)
> >   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
> >     (https://lkml.org/lkml/2015/11/19/550)
> > To reduce (cross) dependencies, I split off the integration (DTS)
> > patches into separate series:
> >   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
> >      strings",
> >   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
> >      clock to fck",
> >   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
> >   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
> >     pins".
> > As the SH architecture is orphaned, and the risk of conflicts is small,
> > I have bundled all SH-specific changes with the core changes.  This
> > reduces dependencies, too.
> 
> At this point I see two ways to move things forwards:
> 
> 1. Greg can consider taking this series and I can take the
>    related integration (DTS) series (noted below) into v4.6.
> 2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
>    and try and queue up this series and the related integration (DTS)
>    series (noted below).
> 
> As it (perhaps surprisingly) it is late in the merge cycle for me to take
> changes for v4.5 that will go though the ARM SoC tree and I am trying to
> stabilise things a little. Thus, I favour option 1.

I can take them, one question:

> > I've also pushed this series (against v4.4-rc1) to the
> > topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
> > repository at
> > https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
> > 
> > For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
> > as it includes the integration part.

Can I just pull from that tag to get everything?  That would be the
simplest for me...

thanks,

greg k-h

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-15  5:23     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 70+ messages in thread
From: Greg Kroah-Hartman @ 2015-12-15  5:23 UTC (permalink / raw)
  To: Simon Horman
  Cc: Geert Uytterhoeven, Magnus Damm, Yoshinori Sato, linux-serial, linux-sh

On Tue, Dec 15, 2015 at 01:53:51PM +0900, Simon Horman wrote:
> Hi Geert,
> 
> thanks for taking care of this, is quite a task!
> 
> On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
> > 	Hi Greg, Simon, Magnus, Sato-san,
> > 
> > This patch series contains several patches for the Renesas SCI serial
> > driver:
> >   - Clean up the naming of clocks in the driver and its DT bindings,
> >   - Add support for the optional external clock on (H)SCI(F) and some
> >     SCIFA, 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.
> > Using external clocks increases the range and accuracy of supported baud
> > rates.
> > 
> > This series is an updated version of the core (driver) changes of two
> > series I sent before:
> >   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
> >     (http://www.spinics.net/lists/linux-serial/msg19762.html)
> >   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
> >     (https://lkml.org/lkml/2015/11/19/550)
> > To reduce (cross) dependencies, I split off the integration (DTS)
> > patches into separate series:
> >   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
> >      strings",
> >   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
> >      clock to fck",
> >   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
> >   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
> >     pins".
> > As the SH architecture is orphaned, and the risk of conflicts is small,
> > I have bundled all SH-specific changes with the core changes.  This
> > reduces dependencies, too.
> 
> At this point I see two ways to move things forwards:
> 
> 1. Greg can consider taking this series and I can take the
>    related integration (DTS) series (noted below) into v4.6.
> 2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
>    and try and queue up this series and the related integration (DTS)
>    series (noted below).
> 
> As it (perhaps surprisingly) it is late in the merge cycle for me to take
> changes for v4.5 that will go though the ARM SoC tree and I am trying to
> stabilise things a little. Thus, I favour option 1.

I can take them, one question:

> > I've also pushed this series (against v4.4-rc1) to the
> > topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
> > repository at
> > https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
> > 
> > For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
> > as it includes the integration part.

Can I just pull from that tag to get everything?  That would be the
simplest for me...

thanks,

greg k-h

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
  2015-12-15  5:23     ` Greg Kroah-Hartman
@ 2015-12-15 13:54       ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-15 13:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Simon Horman, Geert Uytterhoeven, Magnus Damm, Yoshinori Sato,
	linux-serial, Linux-sh list

Hi Greg,

On Tue, Dec 15, 2015 at 6:23 AM, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Tue, Dec 15, 2015 at 01:53:51PM +0900, Simon Horman wrote:
>> thanks for taking care of this, is quite a task!
>>
>> On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
>> > This patch series contains several patches for the Renesas SCI serial
>> > driver:
>> >   - Clean up the naming of clocks in the driver and its DT bindings,
>> >   - Add support for the optional external clock on (H)SCI(F) and some
>> >     SCIFA, 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.
>> > Using external clocks increases the range and accuracy of supported baud
>> > rates.
>> >
>> > This series is an updated version of the core (driver) changes of two
>> > series I sent before:
>> >   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
>> >     (http://www.spinics.net/lists/linux-serial/msg19762.html)
>> >   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
>> >     (https://lkml.org/lkml/2015/11/19/550)
>> > To reduce (cross) dependencies, I split off the integration (DTS)
>> > patches into separate series:
>> >   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
>> >      strings",
>> >   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
>> >      clock to fck",
>> >   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
>> >   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
>> >     pins".
>> > As the SH architecture is orphaned, and the risk of conflicts is small,
>> > I have bundled all SH-specific changes with the core changes.  This
>> > reduces dependencies, too.
>>
>> At this point I see two ways to move things forwards:
>>
>> 1. Greg can consider taking this series and I can take the
>>    related integration (DTS) series (noted below) into v4.6.
>> 2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
>>    and try and queue up this series and the related integration (DTS)
>>    series (noted below).
>>
>> As it (perhaps surprisingly) it is late in the merge cycle for me to take
>> changes for v4.5 that will go though the ARM SoC tree and I am trying to
>> stabilise things a little. Thus, I favour option 1.
>
> I can take them, one question:
>
>> > I've also pushed this series (against v4.4-rc1) to the
>> > topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
>> > repository at
>> > https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
>> >
>> > For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
>> > as it includes the integration part.
>
> Can I just pull from that tag to get everything?  That would be the
> simplest for me...

Please don't pull the renesas-drivers-2015-12-14-v4.4-rc5 tag, else you'll
import half of linux-next plus some v4.6 stuff ;-)

You can pull the topic/scif-clk-sck-brg-core-v3 branch, though, which is
just this series.

Let's formalize, cfr. below.
Thanks a lot!

From 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <geert+renesas@glider.be>
Date: Tue, 15 Dec 2015 14:43:40 +0100
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [git pull] serial: sh-sci: External Clock Support

Hi Greg,

The following changes since commit 8005c49d9aea74d382f474ce11afbbc7d7130bec:

  Linux 4.4-rc1 (2015-11-15 17:00:27 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
topic/scif-clk-sck-brg-core-v3

for you to fetch changes up to 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e:

  serial: sh-sci: Drop the sci_fck clock fallback (2015-12-14 13:14:43 +0100)

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.

Thanks for pulling!

----------------------------------------------------------------
Geert Uytterhoeven (23):
      serial: sh-sci: Add fallback compatibility strings
      serial: sh-sci: Update DT binding documentation for external clock input
      serial: sh-sci: Update DT binding documentation for BRG support
      serial: sh-sci: Drop useless check for zero sampling_rate
      serial: sh-sci: Grammar s/Get ... for/Get ... from/
      serial: sh-sci: Use existing local variable in sci_parse_dt()
      serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
      serial: sh-sci: Don't overwrite clock selection in serial_console_write()
      serial: sh-sci: Convert from clk_get() to devm_clk_get()
      serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
      serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
      serial: sh-sci: Improve bit rate error calculation for HSCIF
      serial: sh-sci: Avoid calculating the receive margin for HSCIF
      serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
      serial: sh-sci: Take into account sampling rate for max baud rate
      serial: sh-sci: Add BRG register definitions
      serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
      serial: sh-sci: Correct SCIF type on RZ/A1H
      serial: sh-sci: Correct SCIF type on R-Car for BRG
      serial: sh-sci: Prepare for multiple sampling clock sources
      serial: sh-sci: Add support for optional external (H)SCK input
      serial: sh-sci: Add support for optional BRG on (H)SCIF
      sh: sh7734: Correct SCIF type for BRG

Laurent Pinchart (4):
      serial: sh-sci: Drop the interface clock
      sh: Rename sci_ick and sci_fck clock to fck
      sh: Remove sci_ick clock alias
      serial: sh-sci: Drop the sci_fck clock fallback

 .../bindings/serial/renesas,sci-serial.txt         |  32 +-
 arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
 drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
 drivers/tty/serial/sh-sci.h                        |  10 +
 include/linux/serial_sci.h                         |   1 +
 16 files changed, 500 insertions(+), 212 deletions(-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-15 13:54       ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-15 13:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Simon Horman, Geert Uytterhoeven, Magnus Damm, Yoshinori Sato,
	linux-serial, Linux-sh list

Hi Greg,

On Tue, Dec 15, 2015 at 6:23 AM, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Tue, Dec 15, 2015 at 01:53:51PM +0900, Simon Horman wrote:
>> thanks for taking care of this, is quite a task!
>>
>> On Mon, Dec 14, 2015 at 07:57:09PM +0100, Geert Uytterhoeven wrote:
>> > This patch series contains several patches for the Renesas SCI serial
>> > driver:
>> >   - Clean up the naming of clocks in the driver and its DT bindings,
>> >   - Add support for the optional external clock on (H)SCI(F) and some
>> >     SCIFA, 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.
>> > Using external clocks increases the range and accuracy of supported baud
>> > rates.
>> >
>> > This series is an updated version of the core (driver) changes of two
>> > series I sent before:
>> >   - [PATCH v2 00/16] serial: sh-sci: Clock Cleanups
>> >     (http://www.spinics.net/lists/linux-serial/msg19762.html)
>> >   - [PATCH 00/25] serial: sh-sci: Add external clock and BRG Support
>> >     (https://lkml.org/lkml/2015/11/19/550)
>> > To reduce (cross) dependencies, I split off the integration (DTS)
>> > patches into separate series:
>> >   - "[PATCH 0/7] ARM: shmobile: dtsi: Add SCIF fallback compatibility
>> >      strings",
>> >   - "[PATCH v3 00/12] ARM: shmobile: dtsi: Rename the serial port
>> >      clock to fck",
>> >   - "[PATCH v2 0/7] ARM: shmobile: dtsi: Add BRG support for (H)SCIF",
>> >   - "[PATCH v2 0/9] ARM: shmobile: dts: Enable SCIF_CLK frequency and
>> >     pins".
>> > As the SH architecture is orphaned, and the risk of conflicts is small,
>> > I have bundled all SH-specific changes with the core changes.  This
>> > reduces dependencies, too.
>>
>> At this point I see two ways to move things forwards:
>>
>> 1. Greg can consider taking this series and I can take the
>>    related integration (DTS) series (noted below) into v4.6.
>> 2. I can get some missing Acks from Greg (patches 02 and 07 I believe)
>>    and try and queue up this series and the related integration (DTS)
>>    series (noted below).
>>
>> As it (perhaps surprisingly) it is late in the merge cycle for me to take
>> changes for v4.5 that will go though the ARM SoC tree and I am trying to
>> stabilise things a little. Thus, I favour option 1.
>
> I can take them, one question:
>
>> > I've also pushed this series (against v4.4-rc1) to the
>> > topic/scif-clk-sck-brg-core-v3 branch of my renesas-drivers git
>> > repository at
>> > https://git.kernel.org/cgit/linux/kernel/git/geert/renesas-drivers.git
>> >
>> > For testing, you best use the renesas-drivers-2015-12-14-v4.4-rc5 tag,
>> > as it includes the integration part.
>
> Can I just pull from that tag to get everything?  That would be the
> simplest for me...

Please don't pull the renesas-drivers-2015-12-14-v4.4-rc5 tag, else you'll
import half of linux-next plus some v4.6 stuff ;-)

You can pull the topic/scif-clk-sck-brg-core-v3 branch, though, which is
just this series.

Let's formalize, cfr. below.
Thanks a lot!

>From 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <geert+renesas@glider.be>
Date: Tue, 15 Dec 2015 14:43:40 +0100
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [git pull] serial: sh-sci: External Clock Support

Hi Greg,

The following changes since commit 8005c49d9aea74d382f474ce11afbbc7d7130bec:

  Linux 4.4-rc1 (2015-11-15 17:00:27 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
topic/scif-clk-sck-brg-core-v3

for you to fetch changes up to 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e:

  serial: sh-sci: Drop the sci_fck clock fallback (2015-12-14 13:14:43 +0100)

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.

Thanks for pulling!

----------------------------------------------------------------
Geert Uytterhoeven (23):
      serial: sh-sci: Add fallback compatibility strings
      serial: sh-sci: Update DT binding documentation for external clock input
      serial: sh-sci: Update DT binding documentation for BRG support
      serial: sh-sci: Drop useless check for zero sampling_rate
      serial: sh-sci: Grammar s/Get ... for/Get ... from/
      serial: sh-sci: Use existing local variable in sci_parse_dt()
      serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
      serial: sh-sci: Don't overwrite clock selection in serial_console_write()
      serial: sh-sci: Convert from clk_get() to devm_clk_get()
      serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
      serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
      serial: sh-sci: Improve bit rate error calculation for HSCIF
      serial: sh-sci: Avoid calculating the receive margin for HSCIF
      serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
      serial: sh-sci: Take into account sampling rate for max baud rate
      serial: sh-sci: Add BRG register definitions
      serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
      serial: sh-sci: Correct SCIF type on RZ/A1H
      serial: sh-sci: Correct SCIF type on R-Car for BRG
      serial: sh-sci: Prepare for multiple sampling clock sources
      serial: sh-sci: Add support for optional external (H)SCK input
      serial: sh-sci: Add support for optional BRG on (H)SCIF
      sh: sh7734: Correct SCIF type for BRG

Laurent Pinchart (4):
      serial: sh-sci: Drop the interface clock
      sh: Rename sci_ick and sci_fck clock to fck
      sh: Remove sci_ick clock alias
      serial: sh-sci: Drop the sci_fck clock fallback

 .../bindings/serial/renesas,sci-serial.txt         |  32 +-
 arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
 arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
 arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
 arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
 drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
 drivers/tty/serial/sh-sci.h                        |  10 +
 include/linux/serial_sci.h                         |   1 +
 16 files changed, 500 insertions(+), 212 deletions(-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
  2015-12-15 13:54       ` Geert Uytterhoeven
@ 2015-12-17 10:28         ` Geert Uytterhoeven
  -1 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-17 10:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Simon Horman, Geert Uytterhoeven, Magnus Damm, Yoshinori Sato,
	linux-serial, Linux-sh list

Hi Greg,

On Tue, Dec 15, 2015 at 2:54 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> The following changes since commit 8005c49d9aea74d382f474ce11afbbc7d7130bec:
>
>   Linux 4.4-rc1 (2015-11-15 17:00:27 -0800)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
> topic/scif-clk-sck-brg-core-v3

As this branch was meant for email submission, all commits include changelog
information.

I've pushed the stripped versions to a new branch (the end result is identical
to the original), so please pull from

    git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
scif-clk-sck-brg-for-v4.5

instead.

Sorry for the screw up.

Thanks!

> for you to fetch changes up to 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e:

... up to 192d367f218d0cd94aa9b5059992e4aa19ec5b36

>   serial: sh-sci: Drop the sci_fck clock fallback (2015-12-14 13:14:43 +0100)
>
> 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.
>
> Thanks for pulling!
>
> ----------------------------------------------------------------
>
> Geert Uytterhoeven (23):
>       serial: sh-sci: Add fallback compatibility strings
>       serial: sh-sci: Update DT binding documentation for external clock input
>       serial: sh-sci: Update DT binding documentation for BRG support
>       serial: sh-sci: Drop useless check for zero sampling_rate
>       serial: sh-sci: Grammar s/Get ... for/Get ... from/
>       serial: sh-sci: Use existing local variable in sci_parse_dt()
>       serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
>       serial: sh-sci: Don't overwrite clock selection in serial_console_write()
>       serial: sh-sci: Convert from clk_get() to devm_clk_get()
>       serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
>       serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>       serial: sh-sci: Improve bit rate error calculation for HSCIF
>       serial: sh-sci: Avoid calculating the receive margin for HSCIF
>       serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
>       serial: sh-sci: Take into account sampling rate for max baud rate
>       serial: sh-sci: Add BRG register definitions
>       serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
>       serial: sh-sci: Correct SCIF type on RZ/A1H
>       serial: sh-sci: Correct SCIF type on R-Car for BRG
>       serial: sh-sci: Prepare for multiple sampling clock sources
>       serial: sh-sci: Add support for optional external (H)SCK input
>       serial: sh-sci: Add support for optional BRG on (H)SCIF
>       sh: sh7734: Correct SCIF type for BRG
>
> Laurent Pinchart (4):
>       serial: sh-sci: Drop the interface clock
>       sh: Rename sci_ick and sci_fck clock to fck
>       sh: Remove sci_ick clock alias
>       serial: sh-sci: Drop the sci_fck clock fallback
>
>  .../bindings/serial/renesas,sci-serial.txt         |  32 +-
>  arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
>  arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
>  arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
>  arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
>  drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
>  drivers/tty/serial/sh-sci.h                        |  10 +
>  include/linux/serial_sci.h                         |   1 +
>  16 files changed, 500 insertions(+), 212 deletions(-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 00/27] serial: sh-sci: External Clock Support
@ 2015-12-17 10:28         ` Geert Uytterhoeven
  0 siblings, 0 replies; 70+ messages in thread
From: Geert Uytterhoeven @ 2015-12-17 10:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Simon Horman, Geert Uytterhoeven, Magnus Damm, Yoshinori Sato,
	linux-serial, Linux-sh list

Hi Greg,

On Tue, Dec 15, 2015 at 2:54 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> The following changes since commit 8005c49d9aea74d382f474ce11afbbc7d7130bec:
>
>   Linux 4.4-rc1 (2015-11-15 17:00:27 -0800)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
> topic/scif-clk-sck-brg-core-v3

As this branch was meant for email submission, all commits include changelog
information.

I've pushed the stripped versions to a new branch (the end result is identical
to the original), so please pull from

    git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git
scif-clk-sck-brg-for-v4.5

instead.

Sorry for the screw up.

Thanks!

> for you to fetch changes up to 830fe6beabc4ab6e4a0f8a688c5a150af69dd95e:

... up to 192d367f218d0cd94aa9b5059992e4aa19ec5b36

>   serial: sh-sci: Drop the sci_fck clock fallback (2015-12-14 13:14:43 +0100)
>
> 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.
>
> Thanks for pulling!
>
> ----------------------------------------------------------------
>
> Geert Uytterhoeven (23):
>       serial: sh-sci: Add fallback compatibility strings
>       serial: sh-sci: Update DT binding documentation for external clock input
>       serial: sh-sci: Update DT binding documentation for BRG support
>       serial: sh-sci: Drop useless check for zero sampling_rate
>       serial: sh-sci: Grammar s/Get ... for/Get ... from/
>       serial: sh-sci: Use existing local variable in sci_parse_dt()
>       serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()
>       serial: sh-sci: Don't overwrite clock selection in serial_console_write()
>       serial: sh-sci: Convert from clk_get() to devm_clk_get()
>       serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned
>       serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()
>       serial: sh-sci: Improve bit rate error calculation for HSCIF
>       serial: sh-sci: Avoid calculating the receive margin for HSCIF
>       serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif()
>       serial: sh-sci: Take into account sampling rate for max baud rate
>       serial: sh-sci: Add BRG register definitions
>       serial: sh-sci: Replace struct sci_port_info by type/regtype encoding
>       serial: sh-sci: Correct SCIF type on RZ/A1H
>       serial: sh-sci: Correct SCIF type on R-Car for BRG
>       serial: sh-sci: Prepare for multiple sampling clock sources
>       serial: sh-sci: Add support for optional external (H)SCK input
>       serial: sh-sci: Add support for optional BRG on (H)SCIF
>       sh: sh7734: Correct SCIF type for BRG
>
> Laurent Pinchart (4):
>       serial: sh-sci: Drop the interface clock
>       sh: Rename sci_ick and sci_fck clock to fck
>       sh: Remove sci_ick clock alias
>       serial: sh-sci: Drop the sci_fck clock fallback
>
>  .../bindings/serial/renesas,sci-serial.txt         |  32 +-
>  arch/sh/kernel/cpu/clock-cpg.c                     |   1 -
>  arch/sh/kernel/cpu/sh2a/clock-sh7264.c             |   9 +-
>  arch/sh/kernel/cpu/sh2a/clock-sh7269.c             |  16 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7343.c             |   8 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7366.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7723.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7734.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7757.c             |   6 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7785.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-sh7786.c             |  12 +-
>  arch/sh/kernel/cpu/sh4a/clock-shx3.c               |   8 +-
>  arch/sh/kernel/cpu/sh4a/setup-sh7734.c             |  12 +-
>  drivers/tty/serial/sh-sci.c                        | 555 +++++++++++++++------
>  drivers/tty/serial/sh-sci.h                        |  10 +
>  include/linux/serial_sci.h                         |   1 +
>  16 files changed, 500 insertions(+), 212 deletions(-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 03/27] serial: sh-sci: Update DT binding documentation for external clock input
  2015-12-14 18:57   ` Geert Uytterhoeven
@ 2015-12-20  3:39     ` Rob Herring
  -1 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:12PM +0100, Geert Uytterhoeven wrote:
> Amend the DT bindings to include the optional external clock on
> (H)SCI(F) and some SCIFA, where this pin can serve as a clock input,
> depending on board wiring.
> 
> Clarify the use of the divided functional clock as a source for the
> sampling clock.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - Add Acked-by,
>   - Clarify the use of the divided functional clock.
> ---
>  Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 5 +++++
>  1 file changed, 5 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 03/27] serial: sh-sci: Update DT binding documentation for external clock input
@ 2015-12-20  3:39     ` Rob Herring
  0 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:12PM +0100, Geert Uytterhoeven wrote:
> Amend the DT bindings to include the optional external clock on
> (H)SCI(F) and some SCIFA, where this pin can serve as a clock input,
> depending on board wiring.
> 
> Clarify the use of the divided functional clock as a source for the
> sampling clock.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - Add Acked-by,
>   - Clarify the use of the divided functional clock.
> ---
>  Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 5 +++++
>  1 file changed, 5 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 02/27] serial: sh-sci: Add fallback compatibility strings
  2015-12-14 18:57   ` Geert Uytterhoeven
@ 2015-12-20  3:39     ` Rob Herring
  -1 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:11PM +0100, Geert Uytterhoeven wrote:
> Add fallback compatibility strings for R-Car Gen1, Gen2, and Gen3.
> This is in keeping with the fallback scheme being adopted wherever
> appropriate for drivers for Renesas SoCs.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - New.
> ---
>  .../devicetree/bindings/serial/renesas,sci-serial.txt   | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 02/27] serial: sh-sci: Add fallback compatibility strings
@ 2015-12-20  3:39     ` Rob Herring
  0 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:11PM +0100, Geert Uytterhoeven wrote:
> Add fallback compatibility strings for R-Car Gen1, Gen2, and Gen3.
> This is in keeping with the fallback scheme being adopted wherever
> appropriate for drivers for Renesas SoCs.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - New.
> ---
>  .../devicetree/bindings/serial/renesas,sci-serial.txt   | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 04/27] serial: sh-sci: Update DT binding documentation for BRG support
  2015-12-14 18:57   ` Geert Uytterhoeven
@ 2015-12-20  3:39     ` Rob Herring
  -1 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:13PM +0100, Geert Uytterhoeven wrote:
> Amend the DT bindings to include the optional clock sources for the Baud
> Rate Generator for External Clock (BRG), as found on some SCIF variants
> and on HSCIF.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - Add Acked-by,
>   - Rename "int_clk" to "brg_int".
> ---
>  Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 6 ++++++
>  1 file changed, 6 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 04/27] serial: sh-sci: Update DT binding documentation for BRG support
@ 2015-12-20  3:39     ` Rob Herring
  0 siblings, 0 replies; 70+ messages in thread
From: Rob Herring @ 2015-12-20  3:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Simon Horman, Magnus Damm, Yoshinori Sato,
	linux-serial, linux-sh, devicetree

On Mon, Dec 14, 2015 at 07:57:13PM +0100, Geert Uytterhoeven wrote:
> Amend the DT bindings to include the optional clock sources for the Baud
> Rate Generator for External Clock (BRG), as found on some SCIF variants
> and on HSCIF.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: devicetree@vger.kernel.org
> ---
> v3:
>   - Add Acked-by,
>   - Rename "int_clk" to "brg_int".
> ---
>  Documentation/devicetree/bindings/serial/renesas,sci-serial.txt | 6 ++++++
>  1 file changed, 6 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

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

end of thread, other threads:[~2015-12-20  3:39 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-14 18:57 [PATCH v3 00/27] serial: sh-sci: External Clock Support Geert Uytterhoeven
2015-12-14 18:57 ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 02/27] serial: sh-sci: Add fallback compatibility strings Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-20  3:39   ` Rob Herring
2015-12-20  3:39     ` Rob Herring
2015-12-14 18:57 ` [PATCH v3 03/27] serial: sh-sci: Update DT binding documentation for external clock input Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-20  3:39   ` Rob Herring
2015-12-20  3:39     ` Rob Herring
2015-12-14 18:57 ` [PATCH v3 04/27] serial: sh-sci: Update DT binding documentation for BRG support Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-20  3:39   ` Rob Herring
2015-12-20  3:39     ` Rob Herring
2015-12-14 18:57 ` [PATCH v3 05/27] serial: sh-sci: Drop useless check for zero sampling_rate Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 06/27] serial: sh-sci: Grammar s/Get ... for/Get ... from/ Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 07/27] serial: sh-sci: Use existing local variable in sci_parse_dt() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 08/27] serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 09/27] serial: sh-sci: Don't overwrite clock selection in serial_console_write() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 10/27] serial: sh-sci: Convert from clk_get() to devm_clk_get() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 11/27] serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 12/27] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 13/27] serial: sh-sci: Improve bit rate error calculation for HSCIF Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 14/27] serial: sh-sci: Avoid calculating the receive margin " Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 15/27] serial: sh-sci: Merge sci_scbrr_calc() and sci_baud_calc_hscif() Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 16/27] serial: sh-sci: Take into account sampling rate for max baud rate Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 17/27] serial: sh-sci: Add BRG register definitions Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 18/27] serial: sh-sci: Replace struct sci_port_info by type/regtype encoding Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 19/27] serial: sh-sci: Correct SCIF type on RZ/A1H Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
     [not found] ` <1450119456-964-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2015-12-14 18:57   ` [PATCH v3 01/27] serial: sh-sci: Drop the interface clock Geert Uytterhoeven
2015-12-14 18:57     ` Geert Uytterhoeven
2015-12-14 18:57   ` [PATCH v3 20/27] serial: sh-sci: Correct SCIF type on R-Car for BRG Geert Uytterhoeven
2015-12-14 18:57     ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 21/27] serial: sh-sci: Prepare for multiple sampling clock sources Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 22/27] serial: sh-sci: Add support for optional external (H)SCK input Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 23/27] serial: sh-sci: Add support for optional BRG on (H)SCIF Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 24/27] sh: Rename sci_ick and sci_fck clock to fck Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 25/27] sh: Remove sci_ick clock alias Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 26/27] sh: sh7734: Correct SCIF type for BRG Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-14 18:57 ` [PATCH v3 27/27] serial: sh-sci: Drop the sci_fck clock fallback Geert Uytterhoeven
2015-12-14 18:57   ` Geert Uytterhoeven
2015-12-15  4:53 ` [PATCH v3 00/27] serial: sh-sci: External Clock Support Simon Horman
2015-12-15  4:53   ` Simon Horman
2015-12-15  5:23   ` Greg Kroah-Hartman
2015-12-15  5:23     ` Greg Kroah-Hartman
2015-12-15 13:54     ` Geert Uytterhoeven
2015-12-15 13:54       ` Geert Uytterhoeven
2015-12-17 10:28       ` Geert Uytterhoeven
2015-12-17 10:28         ` Geert Uytterhoeven

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.