Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
On 6/13/2018 6:39 AM, Rob Herring wrote: On Tue, Jun 12, 2018 at 01:40:34PM +0800, Songjun Wu wrote: Previous implementation uses platform-dependent API to get the clock. Those functions are not available for other SoC which uses the same IP. The CCF (Common Clock Framework) have an abstraction based APIs for clock. Change to use CCF APIs to get clock and rate. So that different SoCs can use the same driver. Clocks and clock-names are updated in device tree binding. Signed-off-by: Songjun Wu --- .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ Please split bindings to separate patch. Thanks. It will be split to two separate patches, one for bindings, the other for code. drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/lantiq.c| 101 + 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt b/Documentation/devicetree/bindings/serial/lantiq_asc.txt index 3acbd309ab9d..608f0c87a4af 100644 --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt @@ -6,6 +6,10 @@ Required properties: - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier depends on the interrupt-parent interrupt controller. +Optional properties: +- clocks: Should contain frequency clock and gate clock +- clock-names: Should be "freq" and "asc" + Example: asc1: serial@e100c00 { @@ -14,3 +18,14 @@ asc1: serial@e100c00 { interrupt-parent = <>; interrupts = <112 113 114>; }; + +asc0: serial@60 { + compatible = "lantiq,asc"; + reg = <0x60 0x10>; 1MB of address space? That wastes a lot of virtual space on 32-bit systems. Just make the size the actual used range. The size of address space will be updated to the actual used range. + interrupt-parent = <>; + interrupts = , + , + ; + clocks = < SSX4_CLK>, < GATE_URT_CLK>; + clock-names = "freq", "asc"; +};
Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
On 6/13/2018 6:39 AM, Rob Herring wrote: On Tue, Jun 12, 2018 at 01:40:34PM +0800, Songjun Wu wrote: Previous implementation uses platform-dependent API to get the clock. Those functions are not available for other SoC which uses the same IP. The CCF (Common Clock Framework) have an abstraction based APIs for clock. Change to use CCF APIs to get clock and rate. So that different SoCs can use the same driver. Clocks and clock-names are updated in device tree binding. Signed-off-by: Songjun Wu --- .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ Please split bindings to separate patch. Thanks. It will be split to two separate patches, one for bindings, the other for code. drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/lantiq.c| 101 + 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt b/Documentation/devicetree/bindings/serial/lantiq_asc.txt index 3acbd309ab9d..608f0c87a4af 100644 --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt @@ -6,6 +6,10 @@ Required properties: - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier depends on the interrupt-parent interrupt controller. +Optional properties: +- clocks: Should contain frequency clock and gate clock +- clock-names: Should be "freq" and "asc" + Example: asc1: serial@e100c00 { @@ -14,3 +18,14 @@ asc1: serial@e100c00 { interrupt-parent = <>; interrupts = <112 113 114>; }; + +asc0: serial@60 { + compatible = "lantiq,asc"; + reg = <0x60 0x10>; 1MB of address space? That wastes a lot of virtual space on 32-bit systems. Just make the size the actual used range. The size of address space will be updated to the actual used range. + interrupt-parent = <>; + interrupts = , + , + ; + clocks = < SSX4_CLK>, < GATE_URT_CLK>; + clock-names = "freq", "asc"; +};
Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
On Tue, Jun 12, 2018 at 01:40:34PM +0800, Songjun Wu wrote: > Previous implementation uses platform-dependent API to get the clock. > Those functions are not available for other SoC which uses the same IP. > The CCF (Common Clock Framework) have an abstraction based APIs > for clock. > Change to use CCF APIs to get clock and rate. > So that different SoCs can use the same driver. > Clocks and clock-names are updated in device tree binding. > > Signed-off-by: Songjun Wu > > --- > > .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ Please split bindings to separate patch. > drivers/tty/serial/Kconfig | 2 +- > drivers/tty/serial/lantiq.c| 101 > + > 3 files changed, 98 insertions(+), 20 deletions(-) > > diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt > b/Documentation/devicetree/bindings/serial/lantiq_asc.txt > index 3acbd309ab9d..608f0c87a4af 100644 > --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt > +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt > @@ -6,6 +6,10 @@ Required properties: > - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier >depends on the interrupt-parent interrupt controller. > > +Optional properties: > +- clocks: Should contain frequency clock and gate clock > +- clock-names: Should be "freq" and "asc" > + > Example: > > asc1: serial@e100c00 { > @@ -14,3 +18,14 @@ asc1: serial@e100c00 { > interrupt-parent = <>; > interrupts = <112 113 114>; > }; > + > +asc0: serial@60 { > + compatible = "lantiq,asc"; > + reg = <0x60 0x10>; 1MB of address space? That wastes a lot of virtual space on 32-bit systems. Just make the size the actual used range. > + interrupt-parent = <>; > + interrupts = , > + , > + ; > + clocks = < SSX4_CLK>, < GATE_URT_CLK>; > + clock-names = "freq", "asc"; > +};
Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
On Tue, Jun 12, 2018 at 01:40:34PM +0800, Songjun Wu wrote: > Previous implementation uses platform-dependent API to get the clock. > Those functions are not available for other SoC which uses the same IP. > The CCF (Common Clock Framework) have an abstraction based APIs > for clock. > Change to use CCF APIs to get clock and rate. > So that different SoCs can use the same driver. > Clocks and clock-names are updated in device tree binding. > > Signed-off-by: Songjun Wu > > --- > > .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ Please split bindings to separate patch. > drivers/tty/serial/Kconfig | 2 +- > drivers/tty/serial/lantiq.c| 101 > + > 3 files changed, 98 insertions(+), 20 deletions(-) > > diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt > b/Documentation/devicetree/bindings/serial/lantiq_asc.txt > index 3acbd309ab9d..608f0c87a4af 100644 > --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt > +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt > @@ -6,6 +6,10 @@ Required properties: > - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier >depends on the interrupt-parent interrupt controller. > > +Optional properties: > +- clocks: Should contain frequency clock and gate clock > +- clock-names: Should be "freq" and "asc" > + > Example: > > asc1: serial@e100c00 { > @@ -14,3 +18,14 @@ asc1: serial@e100c00 { > interrupt-parent = <>; > interrupts = <112 113 114>; > }; > + > +asc0: serial@60 { > + compatible = "lantiq,asc"; > + reg = <0x60 0x10>; 1MB of address space? That wastes a lot of virtual space on 32-bit systems. Just make the size the actual used range. > + interrupt-parent = <>; > + interrupts = , > + , > + ; > + clocks = < SSX4_CLK>, < GATE_URT_CLK>; > + clock-names = "freq", "asc"; > +};
Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
Hi Songjun, I love your patch! Yet something to improve: [auto build test ERROR on linus/master] [also build test ERROR on v4.17 next-20180612] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Songjun-Wu/MIPS-intel-add-initial-support-for-Intel-MIPS-SoCs/20180612-134457 config: s390-allmodconfig (attached as .config) compiler: s390x-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree GCC_VERSION=7.2.0 make.cross ARCH=s390 All errors (new ones prefixed by >>): >> drivers/tty/serial/lantiq.c:28:10: fatal error: lantiq_soc.h: No such file >> or directory #include ^~ compilation terminated. vim +28 drivers/tty/serial/lantiq.c 2f0fc415 John Crispin 2011-04-05 26 c17405a9 Songjun Wu 2018-06-12 27 #ifndef CONFIG_COMMON_CLK 2f0fc415 John Crispin 2011-04-05 @28 #include c17405a9 Songjun Wu 2018-06-12 29 #endif 2f0fc415 John Crispin 2011-04-05 30 :: The code at line 28 was first introduced by commit :: 2f0fc4159a6abc20b13569522c545150b99485cf SERIAL: Lantiq: Add driver for MIPS Lantiq SOCs. :: TO: John Crispin :: CC: Ralf Baechle --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
Re: [PATCH 7/7] tty: serial: lantiq: Add CCF support
Hi Songjun, I love your patch! Yet something to improve: [auto build test ERROR on linus/master] [also build test ERROR on v4.17 next-20180612] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Songjun-Wu/MIPS-intel-add-initial-support-for-Intel-MIPS-SoCs/20180612-134457 config: s390-allmodconfig (attached as .config) compiler: s390x-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree GCC_VERSION=7.2.0 make.cross ARCH=s390 All errors (new ones prefixed by >>): >> drivers/tty/serial/lantiq.c:28:10: fatal error: lantiq_soc.h: No such file >> or directory #include ^~ compilation terminated. vim +28 drivers/tty/serial/lantiq.c 2f0fc415 John Crispin 2011-04-05 26 c17405a9 Songjun Wu 2018-06-12 27 #ifndef CONFIG_COMMON_CLK 2f0fc415 John Crispin 2011-04-05 @28 #include c17405a9 Songjun Wu 2018-06-12 29 #endif 2f0fc415 John Crispin 2011-04-05 30 :: The code at line 28 was first introduced by commit :: 2f0fc4159a6abc20b13569522c545150b99485cf SERIAL: Lantiq: Add driver for MIPS Lantiq SOCs. :: TO: John Crispin :: CC: Ralf Baechle --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
[PATCH 7/7] tty: serial: lantiq: Add CCF support
Previous implementation uses platform-dependent API to get the clock. Those functions are not available for other SoC which uses the same IP. The CCF (Common Clock Framework) have an abstraction based APIs for clock. Change to use CCF APIs to get clock and rate. So that different SoCs can use the same driver. Clocks and clock-names are updated in device tree binding. Signed-off-by: Songjun Wu --- .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/lantiq.c| 101 + 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt b/Documentation/devicetree/bindings/serial/lantiq_asc.txt index 3acbd309ab9d..608f0c87a4af 100644 --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt @@ -6,6 +6,10 @@ Required properties: - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier depends on the interrupt-parent interrupt controller. +Optional properties: +- clocks: Should contain frequency clock and gate clock +- clock-names: Should be "freq" and "asc" + Example: asc1: serial@e100c00 { @@ -14,3 +18,14 @@ asc1: serial@e100c00 { interrupt-parent = <>; interrupts = <112 113 114>; }; + +asc0: serial@60 { + compatible = "lantiq,asc"; + reg = <0x60 0x10>; + interrupt-parent = <>; + interrupts = , + , + ; + clocks = < SSX4_CLK>, < GATE_URT_CLK>; + clock-names = "freq", "asc"; +}; diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 0f058df0b070..0f8ac5872a54 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -1062,7 +1062,7 @@ config SERIAL_OMAP_CONSOLE config SERIAL_LANTIQ bool "Lantiq serial driver" - depends on LANTIQ + depends on LANTIQ || INTEL_MIPS || COMPILE_TEST select SERIAL_CORE select SERIAL_CORE_CONSOLE select SERIAL_EARLYCON diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c index cc33208c93ac..fd7ba89daaa2 100644 --- a/drivers/tty/serial/lantiq.c +++ b/drivers/tty/serial/lantiq.c @@ -24,7 +24,9 @@ #include #include +#ifndef CONFIG_COMMON_CLK #include +#endif #define PORT_LTQ_ASC 111 #define MAXPORTS 2 @@ -104,7 +106,7 @@ static struct uart_driver lqasc_reg; struct ltq_uart_port { struct uart_portport; /* clock used to derive divider */ - struct clk *fpiclk; + struct clk *freqclk; /* clock gating of the ASC core */ struct clk *clk; unsigned inttx_irq; @@ -120,7 +122,6 @@ static inline struct ltq_uart_port *to_ltq_uart_port(struct uart_port *port) static void lqasc_stop_tx(struct uart_port *port) { - return; } static void lqasc_start_tx(struct uart_port *port) @@ -291,8 +292,7 @@ static unsigned int lqasc_tx_empty(struct uart_port *port) return status ? 0 : TIOCSER_TEMT; } -static unsigned int -lqasc_get_mctrl(struct uart_port *port) +static unsigned int lqasc_get_mctrl(struct uart_port *port) { return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR; } @@ -301,21 +301,65 @@ static void lqasc_set_mctrl(struct uart_port *port, u_int mctrl) { } -static void -lqasc_break_ctl(struct uart_port *port, int break_state) +static void lqasc_break_ctl(struct uart_port *port, int break_state) { } -static int -lqasc_startup(struct uart_port *port) +static void lqasc_fdv_and_reload_get(struct ltq_uart_port *ltq_port, +unsigned int baudrate, unsigned int *fdv, +unsigned int *reload) +{ + unsigned int asc_clk = clk_get_rate(ltq_port->freqclk); + unsigned int baudrate1 = baudrate * 8192; + unsigned long long baudrate2 = (unsigned long long)baudrate * 1000; + unsigned long long fdv_over_bg_fpi; + unsigned long long fdv_over_bg; + unsigned long long difference; + unsigned long long min_difference; + unsigned int bg; + + /* Sanity check first */ + if (baudrate >= (asc_clk >> 4)) { + pr_err("%s current fpi clock %u can't provide baudrate %u!!!\n", + __func__, asc_clk, baudrate); + return; + } + + min_difference = UINT_MAX; + fdv_over_bg_fpi = baudrate1; + + for (bg = 1; bg <= 8192; bg++, fdv_over_bg_fpi += baudrate1) { + fdv_over_bg = fdv_over_bg_fpi + asc_clk / 2; + do_div(fdv_over_bg, asc_clk); + if (fdv_over_bg <= 512) { + difference = fdv_over_bg * asc_clk * 1000; + do_div(difference, 8192 * bg); + if (difference < baudrate2) + difference =
[PATCH 7/7] tty: serial: lantiq: Add CCF support
Previous implementation uses platform-dependent API to get the clock. Those functions are not available for other SoC which uses the same IP. The CCF (Common Clock Framework) have an abstraction based APIs for clock. Change to use CCF APIs to get clock and rate. So that different SoCs can use the same driver. Clocks and clock-names are updated in device tree binding. Signed-off-by: Songjun Wu --- .../devicetree/bindings/serial/lantiq_asc.txt | 15 +++ drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/lantiq.c| 101 + 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/lantiq_asc.txt b/Documentation/devicetree/bindings/serial/lantiq_asc.txt index 3acbd309ab9d..608f0c87a4af 100644 --- a/Documentation/devicetree/bindings/serial/lantiq_asc.txt +++ b/Documentation/devicetree/bindings/serial/lantiq_asc.txt @@ -6,6 +6,10 @@ Required properties: - interrupts: the 3 (tx rx err) interrupt numbers. The interrupt specifier depends on the interrupt-parent interrupt controller. +Optional properties: +- clocks: Should contain frequency clock and gate clock +- clock-names: Should be "freq" and "asc" + Example: asc1: serial@e100c00 { @@ -14,3 +18,14 @@ asc1: serial@e100c00 { interrupt-parent = <>; interrupts = <112 113 114>; }; + +asc0: serial@60 { + compatible = "lantiq,asc"; + reg = <0x60 0x10>; + interrupt-parent = <>; + interrupts = , + , + ; + clocks = < SSX4_CLK>, < GATE_URT_CLK>; + clock-names = "freq", "asc"; +}; diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 0f058df0b070..0f8ac5872a54 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -1062,7 +1062,7 @@ config SERIAL_OMAP_CONSOLE config SERIAL_LANTIQ bool "Lantiq serial driver" - depends on LANTIQ + depends on LANTIQ || INTEL_MIPS || COMPILE_TEST select SERIAL_CORE select SERIAL_CORE_CONSOLE select SERIAL_EARLYCON diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c index cc33208c93ac..fd7ba89daaa2 100644 --- a/drivers/tty/serial/lantiq.c +++ b/drivers/tty/serial/lantiq.c @@ -24,7 +24,9 @@ #include #include +#ifndef CONFIG_COMMON_CLK #include +#endif #define PORT_LTQ_ASC 111 #define MAXPORTS 2 @@ -104,7 +106,7 @@ static struct uart_driver lqasc_reg; struct ltq_uart_port { struct uart_portport; /* clock used to derive divider */ - struct clk *fpiclk; + struct clk *freqclk; /* clock gating of the ASC core */ struct clk *clk; unsigned inttx_irq; @@ -120,7 +122,6 @@ static inline struct ltq_uart_port *to_ltq_uart_port(struct uart_port *port) static void lqasc_stop_tx(struct uart_port *port) { - return; } static void lqasc_start_tx(struct uart_port *port) @@ -291,8 +292,7 @@ static unsigned int lqasc_tx_empty(struct uart_port *port) return status ? 0 : TIOCSER_TEMT; } -static unsigned int -lqasc_get_mctrl(struct uart_port *port) +static unsigned int lqasc_get_mctrl(struct uart_port *port) { return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR; } @@ -301,21 +301,65 @@ static void lqasc_set_mctrl(struct uart_port *port, u_int mctrl) { } -static void -lqasc_break_ctl(struct uart_port *port, int break_state) +static void lqasc_break_ctl(struct uart_port *port, int break_state) { } -static int -lqasc_startup(struct uart_port *port) +static void lqasc_fdv_and_reload_get(struct ltq_uart_port *ltq_port, +unsigned int baudrate, unsigned int *fdv, +unsigned int *reload) +{ + unsigned int asc_clk = clk_get_rate(ltq_port->freqclk); + unsigned int baudrate1 = baudrate * 8192; + unsigned long long baudrate2 = (unsigned long long)baudrate * 1000; + unsigned long long fdv_over_bg_fpi; + unsigned long long fdv_over_bg; + unsigned long long difference; + unsigned long long min_difference; + unsigned int bg; + + /* Sanity check first */ + if (baudrate >= (asc_clk >> 4)) { + pr_err("%s current fpi clock %u can't provide baudrate %u!!!\n", + __func__, asc_clk, baudrate); + return; + } + + min_difference = UINT_MAX; + fdv_over_bg_fpi = baudrate1; + + for (bg = 1; bg <= 8192; bg++, fdv_over_bg_fpi += baudrate1) { + fdv_over_bg = fdv_over_bg_fpi + asc_clk / 2; + do_div(fdv_over_bg, asc_clk); + if (fdv_over_bg <= 512) { + difference = fdv_over_bg * asc_clk * 1000; + do_div(difference, 8192 * bg); + if (difference < baudrate2) + difference =