arm: at91: clock: Add the generated clock support
PATCH 1/1 arm: at91: clock: Add the generated clock support
Some peripherals may need a second clock source that may be different from the system clock. This second clock is the generated clock (GCK) and is managed by the PMC via PMC_PCR.
For simplicity, the source of the GCK is fixed to PLLA_CLK.
---
arch/arm/mach-at91/armv7/clock.c | 57 ++++++++++++++++++++++++++++ arch/arm/mach-at91/include/mach/at91_pmc.h | 13 +++++++ arch/arm/mach-at91/include/mach/clk.h | 3 ++ 3 files changed, 73 insertions(+)
arch/arm/mach-at91/armv7/clock.c +57 -0
@@ -5,6 +5,7 @@* Copyright (C) 2005 Ivan Kokshaysky * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> * Copyright (C) 2013 Bo Shen <[email protected]> +* Copyright (C) 2015 Wenyou Yang <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ */
@@ -173,3 +174,59 @@ void at91_periph_clk_disable(int id)writel (regval, &pmc->pcr); } + +void at91_enable_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ; + regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (1 ) | +AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ; +} + +u32 at91_get_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval, clk_source, div; +u32 freq =0 ; + +if (id >AT91_PMC_PCR_PID_MASK ) +return 0 ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + + clk_source = regval &AT91_PMC_PCR_GCKCSS ; +switch (clk_source) { +case AT91_PMC_PCR_GCKCSS_SLOW_CLK : + freq =CONFIG_SYS_AT91_SLOW_CLOCK ; +break ; +case AT91_PMC_PCR_GCKCSS_MAIN_CLK : + freq = gd->arch.main_clk_rate_hz; +break ; +case AT91_PMC_PCR_GCKCSS_PLLA_CLK : + freq = gd->arch.plla_rate_hz; +break ; +default : +break ; + } + + div = ((regval &AT91_PMC_PCR_GCKDIV ) >>AT91_PMC_PCR_GCKDIV_OFFSET ); + div +=1 ; + +return freq / div; +}
arch/arm/mach-at91/include/mach/at91_pmc.h +13 -0
@@ -153,8 +153,20 @@ typedef struct at91_pmc {#define AT91_PMC_IXR_MOSCSELS 0x00010000#define AT91_PMC_PCR_PID_MASK (0x3f) +#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8) +#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8) +#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8) +#define AT91_PMC_PCR_GCKCSS_UPLL_CLK (0x3 << 8) +#define AT91_PMC_PCR_GCKCSS_MCK_CLK (0x4 << 8) +#define AT91_PMC_PCR_GCKCSS_AUDIO_CLK (0x5 << 8)#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12) +#define AT91_PMC_PCR_DIV (0x3 << 16) +#define AT91_PMC_PCR_GCKDIV (0xff << 20) +#define AT91_PMC_PCR_GCKDIV_ (x) ((x) << 20) +#define AT91_PMC_PCR_GCKDIV_OFFSET 20#define AT91_PMC_PCR_EN (0x1 << 28) +#define AT91_PMC_PCR_GCKEN (0x1 << 29)#define AT91_PMC_PCK (1 << 0)/* Processor Clock */ #define AT91RM9200_PMC_UDP (1 << 1)/* USB Devcice Port Clock [AT91RM9200 only] */
@@ -236,6 +248,7 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_GCKRDY (1 << 24)#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ #endif
arch/arm/mach-at91/include/mach/clk.h +3 -0
@@ -119,4 +119,7 @@ static inline unsigned long get_pit_clk_rate(void)int at91_clock_init (unsigned long main_clock);void at91_periph_clk_enable (int id);void at91_periph_clk_disable (int id); +void at91_enable_periph_generated_clk (u32 id); +u32 at91_get_periph_generated_clk (u32 id); +#endif /* __ASM_ARM_ARCH_CLK_H__ */
Signature · 1 line
1.7.9.5
PATCH 1/1 arm: at91: clock: Add the generated clock support
Hi Wenyou,
Quoted 42 lines · Wenyou Yang
Some peripherals may need a second clock source that may be different from the system clock. This second clock is the generated clock (GCK) and is managed by the PMC via
PMC_PCR.For simplicity, the source of the GCK is fixed to
PLLA_CLK.Signed-off-by Wenyou Yang <[email protected]>---
arch/arm/mach-at91/armv7/clock.c | 57 ++++++++++++++++++++++++++++ arch/arm/mach-at91/include/mach/at91_pmc.h | 13 +++++++ arch/arm/mach-at91/include/mach/clk.h | 3 ++ 3 files changed, 73 insertions(+)arch/arm/mach-at91/armv7/clock.c +13
-0@@ -5,6 +5,7 @@* Copyright (C) 2005 Ivan Kokshaysky * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> * Copyright (C) 2013 Bo Shen <[email protected]> +* Copyright (C) 2015 Wenyou Yang <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ */ @@ -173,3 +174,59 @@ void at91_periph_clk_disable(int id)writel (regval, &pmc->pcr); } + +void at91_enable_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ;
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 198
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+ regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (1 ) | +AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;
Here, do we need to hang the whole system?
Quoted 17 lines
arch/arm/mach-at91/armv7/clock.c +17
-0+} + +u32 at91_get_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval, clk_source, div; +u32 freq =0 ; + +if (id >AT91_PMC_PCR_PID_MASK ) +return 0 ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + + clk_source = regval &AT91_PMC_PCR_GCKCSS ; +switch (clk_source) { +case AT91_PMC_PCR_GCKCSS_SLOW_CLK :
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 225
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+ freq =CONFIG_SYS_AT91_SLOW_CLOCK ; +break ; +case AT91_PMC_PCR_GCKCSS_MAIN_CLK : + freq = gd->arch.main_clk_rate_hz; +break ; +case AT91_PMC_PCR_GCKCSS_PLLA_CLK : + freq = gd->arch.plla_rate_hz; +break ; +default : +break ;
For the default, is it valuable to add error information? Or return an invalid value?
Quoted 16 lines
arch/arm/mach-at91/armv7/clock.c +7
-0+ } + + div = ((regval &AT91_PMC_PCR_GCKDIV ) >>AT91_PMC_PCR_GCKDIV_OFFSET ); + div +=1 ; + +return freq / div; +}arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0@@ -153,8 +153,20 @@ typedef struct at91_pmc {#define AT91_PMC_IXR_MOSCSELS 0x00010000#define AT91_PMC_PCR_PID_MASK (0x3f) +#define AT91_PMC_PCR_GCKCSS (0x7 << 8)
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 166
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +9
-0+#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8) +#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8) +#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8) +#define AT91_PMC_PCR_GCKCSS_UPLL_CLK (0x3 << 8) +#define AT91_PMC_PCR_GCKCSS_MCK_CLK (0x4 << 8) +#define AT91_PMC_PCR_GCKCSS_AUDIO_CLK (0x5 << 8)#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12) +#define AT91_PMC_PCR_DIV (0x3 << 16) +#define AT91_PMC_PCR_GCKDIV (0xff << 20) +#define AT91_PMC_PCR_GCKDIV_ (x) ((x) << 20)
It is dangerous here, if "x = 0xfff", then what will happen?
Quoted 20 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +3
-0+#define AT91_PMC_PCR_GCKDIV_OFFSET 20#define AT91_PMC_PCR_EN (0x1 << 28) +#define AT91_PMC_PCR_GCKEN (0x1 << 29)#define AT91_PMC_PCK (1 << 0)/* Processor Clock */ #define AT91RM9200_PMC_UDP (1 << 1)/* USB Devcice Port Clock [AT91RM9200 only] */ @@ -236,6 +248,7 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_GCKRDY (1 << 24)#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ #endif arch/arm/mach-at91/include/mach/clk.h +0
-0
arch/arm/mach-at91/include/mach/clk.h static inline unsigned long get_pit_clk_rate(void) · line 125
Quoted 7 lines
arch/arm/mach-at91/include/mach/clk.h +3
-0@@ -119,4 +119,7 @@ static inline unsigned long get_pit_clk_rate(void)int at91_clock_init (unsigned long main_clock);void at91_periph_clk_enable (int id);void at91_periph_clk_disable (int id); +void at91_enable_periph_generated_clk (u32 id); +u32 at91_get_periph_generated_clk (u32 id); +#endif /* __ASM_ARM_ARCH_CLK_H__ */
Best Regards,
Bo Shen
Yang
PATCH 1/1 arm: at91: clock: Add the generated clock support
Hi Bo Shen,
Thank you for your review.
Quoted 57 lines
-----Original Message-----
From: Bo Shen [mailto:voice.shen at gmail.com]
Sent: 2015?9?10? 6:51
To: Yang, Wenyou; U-Boot Mailing List
Subject: Re: [U-Boot] [PATCH] arm: at91: clock: Add the generated clock supportHi Wenyou,
Quoted 10 lines · Wenyou Yang
Some peripherals may need a second clock source that may be different from the system clock. This second clock is the generated clock (GCK) and is managed by the PMC via
PMC_PCR.For simplicity, the source of the GCK is fixed to
PLLA_CLK.Signed-off-by Wenyou Yang <[email protected]>---
arch/arm/mach-at91/armv7/clock.c | 57++++++++++++++++++++++++++++
arch/arm/mach-at91/armv7/clock.c line 6
Quoted 12 lines
arch/arm/mach-at91/include/mach/at91_pmc.h | 13 +++++++ arch/arm/mach-at91/include/mach/clk.h | 3 ++ 3 files changed, 73 insertions(+)arch/arm/mach-at91/armv7/clock.c +0
-0@@ -5,6 +5,7 @@* Copyright (C) 2005 Ivan Kokshaysky * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD Quoted 24 lines
arch/arm/mach-at91/armv7/clock.c +16
-0* Copyright (C) 2013 Bo Shen <[email protected]> +* Copyright (C) 2015 Wenyou Yang <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ */ @@ -173,3 +174,59 @@ void at91_periph_clk_disable(int id)writel (regval, &pmc->pcr); } + +void at91_enable_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ; + regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | + AT91_PMC_PCR_GCKDIV_(1) |
Quoted 8 lines
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 198
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c +6
-0+AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;Here, do we need to hang the whole system?
Do you mean, add the timeout to while()?
But we think if the clock can't reach to a stable state, the system must be in wrong condition. So, I don't think this timeout is necessary.
Thanks.
Quoted 21 lines
Quoted 21 lines
arch/arm/mach-at91/armv7/clock.c +20
-0+} + +u32 at91_get_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval, clk_source, div; +u32 freq =0 ; + +if (id >AT91_PMC_PCR_PID_MASK ) +return 0 ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + + clk_source = regval &AT91_PMC_PCR_GCKCSS ; +switch (clk_source) { +case AT91_PMC_PCR_GCKCSS_SLOW_CLK : + freq =CONFIG_SYS_AT91_SLOW_CLOCK ; +break ; +case AT91_PMC_PCR_GCKCSS_MAIN_CLK : + freq = gd->arch.main_clk_rate_hz;
Quoted 8 lines
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 225
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c +6
-0+break ; +case AT91_PMC_PCR_GCKCSS_PLLA_CLK : + freq = gd->arch.plla_rate_hz; +break ; +default : +break ;For the default, is it valuable to add error information? Or return an invalid value?
Error information is useful, it will be added in next version. Thanks
If reach to default, "freq" will use the initial value(i.e, 0), it can be as an invalid value.
Quoted 17 lines
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id)
Quoted 4 lines
arch/arm/mach-at91/armv7/clock.c +3
-0+ } + + div = ((regval & AT91_PMC_PCR_GCKDIV) >>
AT91_PMC_PCR_GCKDIV_OFFSET);Quoted 12 lines
arch/arm/mach-at91/armv7/clock.c +4
-0+ div +=1 ; + +return freq / div; +}arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0@@ -153,8 +153,20 @@ typedef struct at91_pmc {#define AT91_PMC_IXR_MOSCSELS 0x00010000
Quoted 14 lines
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 166
Quoted 12 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +10
-0#define AT91_PMC_PCR_PID_MASK (0x3f) +#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8) +#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8) +#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8) +#define AT91_PMC_PCR_GCKCSS_UPLL_CLK (0x3 << 8) +#define AT91_PMC_PCR_GCKCSS_MCK_CLK (0x4 << 8) +#define AT91_PMC_PCR_GCKCSS_AUDIO_CLK (0x5 << 8)#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12) +#define AT91_PMC_PCR_DIV (0x3 << 16) +#define AT91_PMC_PCR_GCKDIV (0xff << 20) +#define AT91_PMC_PCR_GCKDIV_ (x) ((x) << 20)It is dangerous here, if "x =
0xfff", then what will happen?
You mean add "& 0xff" after (x). it will added in next version.
Thanks.
Quoted 30 lines
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc {
Quoted 6 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +2
-0+#define AT91_PMC_PCR_GCKDIV_OFFSET 20#define AT91_PMC_PCR_EN (0x1 << 28) +#define AT91_PMC_PCR_GCKEN (0x1 << 29)#define AT91_PMC_PCK (1 << 0)/* Processor Clock */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 172
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91RM9200_PMC_UDP (1 << 1)/* USB Devcice Port Clock [AT91RM9200 only] */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 248
Quoted 2 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0@@ -236,6 +248,7 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 249
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 250
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc {
Quoted 3 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0+#define AT91_PMC_GCKRDY (1 << 24)#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#endif arch/arm/mach-at91/include/mach/clk.h +0
-0@@ -119,4 +119,7 @@ static inline unsigned long get_pit_clk_rate(void)int at91_clock_init (unsigned long main_clock);void at91_periph_clk_enable (int id);void at91_periph_clk_disable (int id);
Quoted 8 lines
arch/arm/mach-at91/include/mach/clk.h static inline unsigned long get_pit_clk_rate(void) · line 125
Quoted 5 lines
arch/arm/mach-at91/include/mach/clk.h +3
-0+void at91_enable_periph_generated_clk (u32 id); +u32 at91_get_periph_generated_clk (u32 id); +#endif /* __ASM_ARM_ARCH_CLK_H__ */ Best Regards,
Bo Shen
Wenyou Yang
PATCH 1/1 arm: at91: clock: Add the generated clock support
Hi Wenyou,
Quoted 23 lines · Wenyou
Quoted 15 lines
Quoted 15 lines
+
Quoted 14 lines
Quoted 14 lines
arch/arm/mach-at91/armv7/clock.c +14
-0+void at91_enable_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ; + regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | + AT91_PMC_PCR_GCKDIV_(1) |Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 198
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c +6
-0+AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;Here, do we need to hang the whole system?
Quoted 1 line
Do you mean, add the timeout to
while()?
Yes, something like that.
Quoted 2 lines
But we think if the clock can't reach to a stable state, the system must be in wrong condition. So, I don't think this timeout is necessary.
As no datasheet for this. According to the code, the clock is for the peripheral which want to use the generated clock. So, it only affect this peripheral while not whole system, am I right?
Best Regards,
Bo Shen
Yang
PATCH 1/1 arm: at91: clock: Add the generated clock support
Hi Bo Shen,
Quoted 36 lines
-----Original Message-----
From: Bo Shen [mailto:voice.shen at gmail.com]
Sent: 2015?9?12? 5:48
To: Yang, Wenyou; U-Boot Mailing List
Subject: Re: [U-Boot] [PATCH] arm: at91: clock: Add the generated clock supportHi Wenyou,
Quoted 23 lines · Wenyou
Quoted 15 lines
Quoted 15 lines
+
Quoted 14 lines
Quoted 14 lines
arch/arm/mach-at91/armv7/clock.c +14
-0+void at91_enable_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ; + regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | + AT91_PMC_PCR_GCKDIV_(1) |Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 198
Quoted 6 lines
arch/arm/mach-at91/armv7/clock.c +6
-0+AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;Here, do we need to hang the whole system?
Quoted 1 line
Do you mean, add the timeout to
while()?Yes, something like that.
Quoted 7 lines
Quoted 1 line
But we think if the clock can't reach to a stable state, the system must be in
wrong condition.
Quoted 1 line
So, I don't think this timeout is necessary.
As no datasheet for this. According to the code, the clock is for the peripheral which want to use the generated clock. So, it only affect this peripheral while not whole system, am I right?
Yes, you are right.
It is introduced by D2. Because it is not formally launch now, its datasheet can't be available outside, it should be available soon.
Thank.
Best Regards,
Wenyou Yang
PATCH 1/1 arm: at91: clock: Add the generated clock support
In reply to Wenyou YangDear Wenyou Yang,
Quoted 42 lines · Wenyou Yang
Some peripherals may need a second clock source that may be different from the system clock. This second clock is the generated clock (GCK) and is managed by the PMC via
PMC_PCR.For simplicity, the source of the GCK is fixed to
PLLA_CLK.Signed-off-by Wenyou Yang <[email protected]>---
arch/arm/mach-at91/armv7/clock.c | 57 ++++++++++++++++++++++++++++ arch/arm/mach-at91/include/mach/at91_pmc.h | 13 +++++++ arch/arm/mach-at91/include/mach/clk.h | 3 ++ 3 files changed, 73 insertions(+)arch/arm/mach-at91/armv7/clock.c +13
-0@@ -5,6 +5,7 @@* Copyright (C) 2005 Ivan Kokshaysky * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> * Copyright (C) 2013 Bo Shen <[email protected]> +* Copyright (C) 2015 Wenyou Yang <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ */ @@ -173,3 +174,59 @@ void at91_periph_clk_disable(int id)writel (regval, &pmc->pcr); } + +void at91_enable_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ;
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 198
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+ regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (1 ) | +AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;
as I understand the other mails by Bo and you here we could have a working system but a defective peripheral, am I right? If so a timeout and warning would be appreciated.
Quoted 16 lines
arch/arm/mach-at91/armv7/clock.c +16
-0+} + +u32 at91_get_periph_generated_clk (u32 id) +{ +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval, clk_source, div; +u32 freq =0 ; + +if (id >AT91_PMC_PCR_PID_MASK ) +return 0 ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + + clk_source = regval &AT91_PMC_PCR_GCKCSS ; +switch (clk_source) {
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 224
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+case AT91_PMC_PCR_GCKCSS_SLOW_CLK : + freq =CONFIG_SYS_AT91_SLOW_CLOCK ; +break ; +case AT91_PMC_PCR_GCKCSS_MAIN_CLK : + freq = gd->arch.main_clk_rate_hz; +break ; +case AT91_PMC_PCR_GCKCSS_PLLA_CLK : + freq = gd->arch.plla_rate_hz; +break ; +default :
A printout with not understood value would be good here (as Bo proposed).
Quoted 17 lines
arch/arm/mach-at91/armv7/clock.c +8
-0+break ; + } + + div = ((regval &AT91_PMC_PCR_GCKDIV ) >>AT91_PMC_PCR_GCKDIV_OFFSET ); + div +=1 ; + +return freq / div; +}arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0@@ -153,8 +153,20 @@ typedef struct at91_pmc {#define AT91_PMC_IXR_MOSCSELS 0x00010000#define AT91_PMC_PCR_PID_MASK (0x3f) +#define AT91_PMC_PCR_GCKCSS (0x7 << 8)
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 166
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +9
-0+#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8) +#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8) +#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8) +#define AT91_PMC_PCR_GCKCSS_UPLL_CLK (0x3 << 8) +#define AT91_PMC_PCR_GCKCSS_MCK_CLK (0x4 << 8) +#define AT91_PMC_PCR_GCKCSS_AUDIO_CLK (0x5 << 8)#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12) +#define AT91_PMC_PCR_DIV (0x3 << 16) +#define AT91_PMC_PCR_GCKDIV (0xff << 20) +#define AT91_PMC_PCR_GCKDIV_ (x) ((x) << 20)
Also here Bo's advice should be followed.
Could you please provide a v2?
Andreas
Quoted 27 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +3
-0+#define AT91_PMC_PCR_GCKDIV_OFFSET 20#define AT91_PMC_PCR_EN (0x1 << 28) +#define AT91_PMC_PCR_GCKEN (0x1 << 29)#define AT91_PMC_PCK (1 << 0)/* Processor Clock */ #define AT91RM9200_PMC_UDP (1 << 1)/* USB Devcice Port Clock [AT91RM9200 only] */ @@ -236,6 +248,7 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_GCKRDY (1 << 24)#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ #endif arch/arm/mach-at91/include/mach/clk.h +3
-0@@ -119,4 +119,7 @@ static inline unsigned long get_pit_clk_rate(void)int at91_clock_init (unsigned long main_clock);void at91_periph_clk_enable (int id);void at91_periph_clk_disable (int id); +void at91_enable_periph_generated_clk (u32 id); +u32 at91_get_periph_generated_clk (u32 id); +#endif /* __ASM_ARM_ARCH_CLK_H__ */
Yang
PATCH 1/1 arm: at91: clock: Add the generated clock support
Hi Andreas,
Thank you for your review.
The new version has been sent for review.
Quoted 151 lines
-----Original Message-----
From: Andreas Bie?mann [mailto:andreas.devel at googlemail.com]
Sent: 2015?10?24? 5:01
To: Yang, Wenyou; U-Boot Mailing List
Subject: Re: [PATCH] arm: at91: clock: Add the generated clock supportDear Wenyou Yang,
Quoted 10 lines · Wenyou Yang
Some peripherals may need a second clock source that may be different from the system clock. This second clock is the generated clock (GCK) and is managed by the PMC via
PMC_PCR.For simplicity, the source of the GCK is fixed to
PLLA_CLK.Signed-off-by Wenyou Yang <[email protected]>---
arch/arm/mach-at91/armv7/clock.c | 57++++++++++++++++++++++++++++
arch/arm/mach-at91/armv7/clock.c line 6
Quoted 12 lines
arch/arm/mach-at91/include/mach/at91_pmc.h | 13 +++++++ arch/arm/mach-at91/include/mach/clk.h | 3 ++ 3 files changed, 73 insertions(+)arch/arm/mach-at91/armv7/clock.c +0
-0@@ -5,6 +5,7 @@* Copyright (C) 2005 Ivan Kokshaysky * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD Quoted 20 lines
arch/arm/mach-at91/armv7/clock.c +12
-0* Copyright (C) 2013 Bo Shen <[email protected]> +* Copyright (C) 2015 Wenyou Yang <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ */ @@ -173,3 +174,59 @@ void at91_periph_clk_disable(int id)writel (regval, &pmc->pcr); } + +void at91_enable_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval; + +if (id >AT91_PMC_PCR_PID_MASK ) +return ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + regval &= ~AT91_PMC_PCR_GCKCSS ;arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 197
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+ regval &= ~AT91_PMC_PCR_GCKDIV ; + regval |=AT91_PMC_PCR_GCKCSS_PLLA_CLK | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (1 ) | +AT91_PMC_PCR_GCKEN ; + +writel (regval, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ;as I understand the other mails by Bo and you here we could have a working system but a defective peripheral, am I right?
If so a timeout and warning would be appreciated.Quoted 15 lines
arch/arm/mach-at91/armv7/clock.c +15
-0+} + +u32 at91_get_periph_generated_clk (u32 id) { +struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC ; +u32 regval, clk_source, div; +u32 freq =0 ; + +if (id >AT91_PMC_PCR_PID_MASK ) +return 0 ; + +writel (id, &pmc->pcr); + regval =readl (&pmc->pcr); + + clk_source = regval &AT91_PMC_PCR_GCKCSS ; +switch (clk_source) {arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id) · line 224
Quoted 10 lines
arch/arm/mach-at91/armv7/clock.c +10
-0+case AT91_PMC_PCR_GCKCSS_SLOW_CLK : + freq =CONFIG_SYS_AT91_SLOW_CLOCK ; +break ; +case AT91_PMC_PCR_GCKCSS_MAIN_CLK : + freq = gd->arch.main_clk_rate_hz; +break ; +case AT91_PMC_PCR_GCKCSS_PLLA_CLK : + freq = gd->arch.plla_rate_hz; +break ; +default :A printout with not understood value would be good here (as Bo proposed).
arch/arm/mach-at91/armv7/clock.c void at91_periph_clk_disable(int id)
Quoted 4 lines
arch/arm/mach-at91/armv7/clock.c +4
-0+break ; + } + + div = ((regval & AT91_PMC_PCR_GCKDIV) >>
AT91_PMC_PCR_GCKDIV_OFFSET);Quoted 14 lines
arch/arm/mach-at91/armv7/clock.c +4
-0+ div +=1 ; + +return freq / div; +}arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0@@ -153,8 +153,20 @@ typedef struct at91_pmc {#define AT91_PMC_IXR_MOSCSELS 0x00010000#define AT91_PMC_PCR_PID_MASK (0x3f) +#define AT91_PMC_PCR_GCKCSS (0x7 << 8)arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 166
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +9
-0+#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8) +#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8) +#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8) +#define AT91_PMC_PCR_GCKCSS_UPLL_CLK (0x3 << 8) +#define AT91_PMC_PCR_GCKCSS_MCK_CLK (0x4 << 8) +#define AT91_PMC_PCR_GCKCSS_AUDIO_CLK (0x5 << 8)#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12) +#define AT91_PMC_PCR_DIV (0x3 << 16) +#define AT91_PMC_PCR_GCKDIV (0xff << 20) +#define AT91_PMC_PCR_GCKDIV_ (x) ((x) << 20)Also here Bo's advice should be followed.
Could you please provide a v2?
Andreas
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc {
Quoted 5 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +2
-0+#define AT91_PMC_PCR_GCKDIV_OFFSET 20#define AT91_PMC_PCR_EN (0x1 << 28) +#define AT91_PMC_PCR_GCKEN (0x1 << 29)#define AT91_PMC_PCK (1 << 0)/* Processor Clock */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 172
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91RM9200_PMC_UDP (1 << 1)/* USB Devcice Port Clock [AT91RM9200 only] */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 248
Quoted 2 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0@@ -236,6 +248,7 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 249
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 250
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc {
Quoted 3 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0+#define AT91_PMC_GCKRDY (1 << 24)#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */
Quoted 14 lines
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#endif arch/arm/mach-at91/include/mach/clk.h +0
-0@@ -119,4 +119,7 @@ static inline unsigned long get_pit_clk_rate(void)int
at91_clock_init(unsigned long main_clock); voidat91_periph_clk_enable(int id); voidat91_periph_clk_disable(int id);arch/arm/mach-at91/include/mach/clk.h static inline unsigned long get_pit_clk_rate(void) · line 125
Quoted 4 lines
arch/arm/mach-at91/include/mach/clk.h +3
-0+void at91_enable_periph_generated_clk (u32 id); +u32 at91_get_periph_generated_clk (u32 id); +#endif /* __ASM_ARM_ARCH_CLK_H__ */
Best Regards,
Wenyou Yang