From 2606deb22b58c8b55426a34dd7d93c703de65974 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 28 Aug 2018 11:44:44 +0200 Subject: sh: sh7724: Drop EDMR macro Drop the macro as it is never used and it collides with sh_eth.h macros. Signed-off-by: Marek Vasut Cc: Nobuhiro Iwamatsu --- arch/sh/include/asm/cpu_sh7724.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'arch') diff --git a/arch/sh/include/asm/cpu_sh7724.h b/arch/sh/include/asm/cpu_sh7724.h index 7a81e1677e..7b217959ed 100644 --- a/arch/sh/include/asm/cpu_sh7724.h +++ b/arch/sh/include/asm/cpu_sh7724.h @@ -203,9 +203,6 @@ #define PYDR 0xA405016A #define PZDR 0xA405016C -/* Ether */ -#define EDMR 0xA4600000 - /* UBC */ /* H-UDI */ -- cgit From d1da5d6cd8d33f777cf8374bf070970c4cca32e1 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:19:15 +0200 Subject: sh: tmu: Clean up CONFIG_SYS_TMU_CLK_DIV This constant is always 4 , for all boards that exist. Define it once in arch/sh/lib/time.c and remove it from the configs. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 1 + 1 file changed, 1 insertion(+) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index eb642969aa..aac79889dc 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -16,6 +16,7 @@ #include #define TCR_TPSC 0x07 +#define CONFIG_SYS_TMU_CLK_DIV 4 static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; -- cgit From eb05dcfea29bbafbc9f8ce3b7894e3e53f35d743 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:20:31 +0200 Subject: sh: tmu: Simplify the tmu_bit math The tmu_bit value evaluates to (ffs(4) >> 1) - 1 = (3 >> 1) - 1 = 0. Just drop the tmu_bit completely as well as CONFIG_SYS_TMU_CLK_DIV. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index aac79889dc..302f6bed83 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -16,14 +16,12 @@ #include #define TCR_TPSC 0x07 -#define CONFIG_SYS_TMU_CLK_DIV 4 static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; unsigned long get_tbclk(void) { - u16 tmu_bit = (ffs(CONFIG_SYS_TMU_CLK_DIV) >> 1) - 1; - return get_tmu0_clk_rate() >> ((tmu_bit + 1) * 2); + return get_tmu0_clk_rate() >> 2; } unsigned long timer_read_counter(void) @@ -47,8 +45,7 @@ static void tmu_timer_stop(unsigned int timer) int timer_init(void) { - u16 tmu_bit = (ffs(CONFIG_SYS_TMU_CLK_DIV) >> 1) - 1; - writew((readw(&tmu->tcr0) & ~TCR_TPSC) | tmu_bit, &tmu->tcr0); + writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0); tmu_timer_stop(0); tmu_timer_start(0); -- cgit From 15f11fc6d72175ff5b7763f03d7b0d502efd24af Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:23:04 +0200 Subject: sh: tmu: Inline tmu_timer_{start,stop}() These functions are always called for timer = 0, so drop the timer check. Since these functions are called from one place only and they are reduced to one line of code, just inline them. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index 302f6bed83..6273f39f21 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -16,6 +16,7 @@ #include #define TCR_TPSC 0x07 +#define TSTR_STR0 BIT(0) static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; @@ -29,26 +30,11 @@ unsigned long timer_read_counter(void) return ~readl(&tmu->tcnt0); } -static void tmu_timer_start(unsigned int timer) -{ - if (timer > 2) - return; - writeb(readb(&tmu->tstr) | (1 << timer), &tmu->tstr); -} - -static void tmu_timer_stop(unsigned int timer) -{ - if (timer > 2) - return; - writeb(readb(&tmu->tstr) & ~(1 << timer), &tmu->tstr); -} - int timer_init(void) { writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0); - - tmu_timer_stop(0); - tmu_timer_start(0); + writeb(readb(&tmu->tstr) & ~TSTR_STR0, &tmu->tstr); + writeb(readb(&tmu->tstr) | TSTR_STR0, &tmu->tstr); return 0; } -- cgit From ae59a9f8f7785d86277149eb37314d2f21392f6f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:29:04 +0200 Subject: sh: tmu: Inline get_tmu0_clk_rate() This function just returns CONFIG_SH_TMU_CLK_FREQ, use the constant directly instead. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index 6273f39f21..0f3127106a 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -22,7 +22,7 @@ static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; unsigned long get_tbclk(void) { - return get_tmu0_clk_rate() >> 2; + return CONFIG_SH_TMU_CLK_FREQ / 4; } unsigned long timer_read_counter(void) -- cgit From ccce3acfe70bdfb4fa8529dc853294f82859b08b Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:34:07 +0200 Subject: sh: tmu: Clean up CONFIG_SH_TMU_CLK_FREQ The R-Car Gen2 feeds the TMU with CONFIG_SYS_CLK_FREQ / 2, while the old SH parts use CONFIG_SYS_CLK_FREQ directly. Just put this into the TMU implementation and drop the CONFIG_SH_TMU_CLK_FREQ config option. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index 0f3127106a..9a1d3fb013 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -22,7 +22,11 @@ static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; unsigned long get_tbclk(void) { - return CONFIG_SH_TMU_CLK_FREQ / 4; +#ifdef CONFIG_RCAR_GEN2 + return CONFIG_SYS_CLK_FREQ / 8; +#else + return CONFIG_SYS_CLK_FREQ / 4; +#endif } unsigned long timer_read_counter(void) -- cgit From 8b39df9e78759c3af07466224c03d9a90d2453ca Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:37:14 +0200 Subject: sh: tmu: Inline sh_tmu.h The header contains only the TMU register layout, just inline it into the TMU timer implementation and drop the header completely. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index 9a1d3fb013..a650c9478c 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -13,7 +13,48 @@ #include #include #include -#include + +#if defined(CONFIG_CPU_SH3) +struct tmu_regs { + u8 tocr; + u8 reserved0; + u8 tstr; + u8 reserved1; + u32 tcor0; + u32 tcnt0; + u16 tcr0; + u16 reserved2; + u32 tcor1; + u32 tcnt1; + u16 tcr1; + u16 reserved3; + u32 tcor2; + u32 tcnt2; + u16 tcr2; + u16 reserved4; + u32 tcpr2; +}; +#endif /* CONFIG_CPU_SH3 */ + +#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_RMOBILE) +struct tmu_regs { + u32 reserved; + u8 tstr; + u8 reserved2[3]; + u32 tcor0; + u32 tcnt0; + u16 tcr0; + u16 reserved3; + u32 tcor1; + u32 tcnt1; + u16 tcr1; + u16 reserved4; + u32 tcor2; + u32 tcnt2; + u16 tcr2; + u16 reserved5; +}; +#endif /* CONFIG_CPU_SH4 */ #define TCR_TPSC 0x07 #define TSTR_STR0 BIT(0) -- cgit From f02c1f695e13ee0ce01f111952ceaac094700de1 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:43:17 +0200 Subject: sh: tmu: Clean up register usage The code uses all in all three TMU registers, drop the massive register layout structures and just define the required timer registers and use them throughout the code. Signed-off-by: Marek Vasut --- arch/sh/lib/time.c | 54 +++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) (limited to 'arch') diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index a650c9478c..d531a4958e 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -15,52 +15,20 @@ #include #if defined(CONFIG_CPU_SH3) -struct tmu_regs { - u8 tocr; - u8 reserved0; - u8 tstr; - u8 reserved1; - u32 tcor0; - u32 tcnt0; - u16 tcr0; - u16 reserved2; - u32 tcor1; - u32 tcnt1; - u16 tcr1; - u16 reserved3; - u32 tcor2; - u32 tcnt2; - u16 tcr2; - u16 reserved4; - u32 tcpr2; -}; +#define TSTR 0x2 +#define TCNT0 0x8 +#define TCR0 0xc #endif /* CONFIG_CPU_SH3 */ #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_RMOBILE) -struct tmu_regs { - u32 reserved; - u8 tstr; - u8 reserved2[3]; - u32 tcor0; - u32 tcnt0; - u16 tcr0; - u16 reserved3; - u32 tcor1; - u32 tcnt1; - u16 tcr1; - u16 reserved4; - u32 tcor2; - u32 tcnt2; - u16 tcr2; - u16 reserved5; -}; +#define TSTR 0x4 +#define TCNT0 0xc +#define TCR0 0x10 #endif /* CONFIG_CPU_SH4 */ -#define TCR_TPSC 0x07 +#define TCR_TPSC 0x07 #define TSTR_STR0 BIT(0) -static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE; - unsigned long get_tbclk(void) { #ifdef CONFIG_RCAR_GEN2 @@ -72,14 +40,14 @@ unsigned long get_tbclk(void) unsigned long timer_read_counter(void) { - return ~readl(&tmu->tcnt0); + return ~readl(TMU_BASE + TCNT0); } int timer_init(void) { - writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0); - writeb(readb(&tmu->tstr) & ~TSTR_STR0, &tmu->tstr); - writeb(readb(&tmu->tstr) | TSTR_STR0, &tmu->tstr); + writew(readw(TMU_BASE + TCR0) & ~TCR_TPSC, TMU_BASE + TCR0); + writeb(readb(TMU_BASE + TSTR) & ~TSTR_STR0, TMU_BASE + TSTR); + writeb(readb(TMU_BASE + TSTR) | TSTR_STR0, TMU_BASE + TSTR); return 0; } -- cgit From 0e286c529f395947dbb96da93081883aca40a57f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 24 Aug 2018 21:52:53 +0200 Subject: sh: tmu: Zap get_tbclk and timer_read_counter Replace those two functions with generic ones by defining the timer macros in include/config/*.h . Signed-off-by: Marek Vasut --- arch/sh/include/asm/config.h | 9 +++++++++ arch/sh/lib/time.c | 16 ---------------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'arch') diff --git a/arch/sh/include/asm/config.h b/arch/sh/include/asm/config.h index bad0026648..d2862df4a5 100644 --- a/arch/sh/include/asm/config.h +++ b/arch/sh/include/asm/config.h @@ -6,4 +6,13 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ +#if !defined(CONFIG_CPU_SH2) +#include + +/* Timer */ +#define CONFIG_SYS_TIMER_COUNTS_DOWN +#define CONFIG_SYS_TIMER_COUNTER (TMU_BASE + 0x8) /* TCNT0 */ +#define CONFIG_SYS_TIMER_RATE (CONFIG_SYS_CLK_FREQ / 4) +#endif + #endif diff --git a/arch/sh/lib/time.c b/arch/sh/lib/time.c index d531a4958e..fb317f95d5 100644 --- a/arch/sh/lib/time.c +++ b/arch/sh/lib/time.c @@ -16,33 +16,17 @@ #if defined(CONFIG_CPU_SH3) #define TSTR 0x2 -#define TCNT0 0x8 #define TCR0 0xc #endif /* CONFIG_CPU_SH3 */ #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_RMOBILE) #define TSTR 0x4 -#define TCNT0 0xc #define TCR0 0x10 #endif /* CONFIG_CPU_SH4 */ #define TCR_TPSC 0x07 #define TSTR_STR0 BIT(0) -unsigned long get_tbclk(void) -{ -#ifdef CONFIG_RCAR_GEN2 - return CONFIG_SYS_CLK_FREQ / 8; -#else - return CONFIG_SYS_CLK_FREQ / 4; -#endif -} - -unsigned long timer_read_counter(void) -{ - return ~readl(TMU_BASE + TCNT0); -} - int timer_init(void) { writew(readw(TMU_BASE + TCR0) & ~TCR_TPSC, TMU_BASE + TCR0); -- cgit