Skip to contentSkip to conversation

davinci: da850: move input frequency to board specific files.

PATCH Superseded Christian Riesch 4 participants 17 messages May 25, 2011 – Jul 6, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 davinci: da850: move input frequency to board specific files.

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

This patch moves the definition of the input frequency to the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

---
 arch/arm/mach-davinci/board-da850-evm.c     |    4 +++-
 arch/arm/mach-davinci/board-mityomapl138.c  |    4 +++-
 arch/arm/mach-davinci/board-omapl138-hawk.c |    4 +++-
 arch/arm/mach-davinci/da850.c               |    7 +++----
 arch/arm/mach-davinci/include/mach/da8xx.h  |    2 +-
 5 files changed, 13 insertions(+), 8 deletions(-)
arch/arm/mach-davinci/board-da850-evm.c +3 -1
index a7b41bf..8984096 100644
@@ -42,6 +42,8 @@
 #include <mach/aemif.h>
 #include <mach/spi.h>
 
+#define DA850_EVM_REF_FREQ		24000000
+
 #define DA850_EVM_PHY_ID		"0:00"
 #define DA850_LCD_PWR_PIN		GPIO_TO_PIN(2, 8)
 #define DA850_LCD_BL_PIN		GPIO_TO_PIN(2, 15)
@@ -1252,7 +1254,7 @@ console_initcall(da850_evm_console_init);
 
 static void __init da850_evm_map_io(void)
 {
-	da850_init();
+	da850_init(DA850_EVM_REF_FREQ);
 }
 
 MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138/AM18x EVM")
arch/arm/mach-davinci/board-mityomapl138.c +3 -1
index 606a6f2..58fdabb 100644
@@ -29,6 +29,8 @@
 #include <mach/mux.h>
 #include <mach/spi.h>
 
+#define MITYOMAPL138_REF_FREQ	24000000
+
 #define MITYOMAPL138_PHY_ID		""
 
 #define FACTORY_CONFIG_MAGIC	0x012C0138
@@ -561,7 +563,7 @@ console_initcall(mityomapl138_console_init);
 
 static void __init mityomapl138_map_io(void)
 {
-	da850_init();
+	da850_init(MITYOMAPL138_REF_FREQ);
 }
 
 MACHINE_START(MITYOMAPL138, "MityDSP-L138/MityARM-1808")
arch/arm/mach-davinci/board-omapl138-hawk.c +3 -1
index 67c38d0..27dd43c 100644
@@ -21,6 +21,8 @@
 #include <mach/da8xx.h>
 #include <mach/mux.h>
 
+#define HAWKBOARD_REF_FREQ		24000000
+
 #define HAWKBOARD_PHY_ID		"0:07"
 #define DA850_HAWK_MMCSD_CD_PIN		GPIO_TO_PIN(3, 12)
 #define DA850_HAWK_MMCSD_WP_PIN		GPIO_TO_PIN(3, 13)
@@ -334,7 +336,7 @@ console_initcall(omapl138_hawk_console_init);
 
 static void __init omapl138_hawk_map_io(void)
 {
-	da850_init();
+	da850_init(HAWKBOARD_REF_FREQ);
 }
 
 MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
arch/arm/mach-davinci/da850.c +3 -4
index 133aac4..0bcdc34 100644
@@ -39,8 +39,6 @@
 #define DA850_TIMER64P2_BASE	0x01f0c000
 #define DA850_TIMER64P3_BASE	0x01f0d000
 
-#define DA850_REF_FREQ		24000000
-
 #define CFGCHIP3_ASYNC3_CLKSRC	BIT(4)
 #define CFGCHIP3_PLL1_MASTER_LOCK	BIT(5)
 #define CFGCHIP0_PLL_MASTER_LOCK	BIT(4)
@@ -57,7 +55,6 @@ static struct pll_data pll0_data = {
 
 static struct clk ref_clk = {
 	.name		= "ref_clk",
-	.rate		= DA850_REF_FREQ,
 };
 
 static struct clk pll0_clk = {
@@ -1104,10 +1101,12 @@ static struct davinci_soc_info davinci_soc_info_da850 = {
 	.reset_device		= &da8xx_wdt_device,
 };
 
-void __init da850_init(void)
+void __init da850_init(unsigned long ref_clk_rate)
 {
 	unsigned int v;
 
+	ref_clk.rate = ref_clk_rate;
+
 	davinci_common_init(&davinci_soc_info_da850);
 
 	da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
arch/arm/mach-davinci/include/mach/da8xx.h +1 -1
index ad64da7..e8e704e 100644
@@ -70,7 +70,7 @@ extern unsigned int da850_max_speed;
 #define DA8XX_ARM_RAM_BASE	0xffff0000
 
 void __init da830_init(void);
-void __init da850_init(void);
+void __init da850_init(unsigned long ref_clk_rate);
 
 int da830_register_edma(struct edma_rsv_info *rsv);
 int da850_register_edma(struct edma_rsv_info *rsv[2]);
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

---

Hi,
in private email Bob Dunlop suggested to pass a pointer to a small structure instead of the frequency value to allow future expansions, e.g., for the OPP list. Therefore I submit his patch as V2. Christian

 arch/arm/mach-davinci/board-da850-evm.c     |    2 +-
 arch/arm/mach-davinci/board-mityomapl138.c  |    2 +-
 arch/arm/mach-davinci/board-omapl138-hawk.c |    2 +-
 arch/arm/mach-davinci/da850.c               |    5 ++++-
 arch/arm/mach-davinci/include/mach/da8xx.h  |    6 +++++-
 5 files changed, 12 insertions(+), 5 deletions(-)
arch/arm/mach-davinci/board-da850-evm.c +1 -1
index a7b41bf..231ff87 100644
@@ -1252,7 +1252,7 @@ console_initcall(da850_evm_console_init);
 
 static void __init da850_evm_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138/AM18x EVM")
arch/arm/mach-davinci/board-mityomapl138.c +1 -1
index 606a6f2..362770c 100644
@@ -561,7 +561,7 @@ console_initcall(mityomapl138_console_init);
 
 static void __init mityomapl138_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(MITYOMAPL138, "MityDSP-L138/MityARM-1808")
arch/arm/mach-davinci/board-omapl138-hawk.c +1 -1
index 67c38d0..c43a6c3 100644
@@ -334,7 +334,7 @@ console_initcall(omapl138_hawk_console_init);
 
 static void __init omapl138_hawk_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
arch/arm/mach-davinci/da850.c +4 -1
index 133aac4..ebd0603 100644
@@ -1104,10 +1104,13 @@ static struct davinci_soc_info davinci_soc_info_da850 = {
 	.reset_device		= &da8xx_wdt_device,
 };
 
-void __init da850_init(void)
+void __init da850_init(struct da850_init_board_info *board)
 {
 	unsigned int v;
 
+	if (board && board->ref_clk_rate)
+		ref_clk.rate = board->ref_clk_rate;
+
 	davinci_common_init(&davinci_soc_info_da850);
 
 	da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
arch/arm/mach-davinci/include/mach/da8xx.h +5 -1
index ad64da7..66efc5d 100644
@@ -69,8 +69,12 @@ extern unsigned int da850_max_speed;
 #define DA8XX_AEMIF_CTL_BASE	0x68000000
 #define DA8XX_ARM_RAM_BASE	0xffff0000
 
+struct da850_init_board_info {
+	unsigned long ref_clk_rate;
+};
+
 void __init da830_init(void);
-void __init da850_init(void);
+void __init da850_init(struct da850_init_board_info *board);
 
 int da830_register_edma(struct edma_rsv_info *rsv);
 int da850_register_edma(struct edma_rsv_info *rsv[2]);
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Quoted 10 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Curious question: have you considered Documentation/power/opp.txt? Not entirely sure if that will help, but I am curious to know if there are reasons why it did not scale for you

Regards,
Nishanth Menon

Quoted 103 lines

---

Hi,
in private email Bob Dunlop suggested to pass a pointer to a small structure instead of the frequency value to allow future expansions, e.g., for the OPP list. Therefore I submit his patch as V2. Christian

?arch/arm/mach-davinci/board-da850-evm.c ? ? | ? ?2 +-
?arch/arm/mach-davinci/board-mityomapl138.c ?| ? ?2 +-
?arch/arm/mach-davinci/board-omapl138-hawk.c | ? ?2 +-
?arch/arm/mach-davinci/da850.c ? ? ? ? ? ? ? | ? ?5 ++++-
?arch/arm/mach-davinci/include/mach/da8xx.h ?| ? ?6 +++++-

?5 files changed, 12 insertions(+), 5 deletions(-)

arch/arm/mach-davinci/board-da850-evm.c +1 -1
index a7b41bf..231ff87 100644
@@ -1252,7 +1252,7 @@ console_initcall(da850_evm_console_init);
 
 ?static void __init da850_evm_map_io(void)
 ?{
- ? ? ? da850_init();
+ ? ? ? da850_init(NULL);
 ?}
 
 ?MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138/AM18x EVM")
arch/arm/mach-davinci/board-mityomapl138.c +1 -1
index 606a6f2..362770c 100644
@@ -561,7 +561,7 @@ console_initcall(mityomapl138_console_init);
 
 ?static void __init mityomapl138_map_io(void)
 ?{
- ? ? ? da850_init();
+ ? ? ? da850_init(NULL);
 ?}
 
 ?MACHINE_START(MITYOMAPL138, "MityDSP-L138/MityARM-1808")
arch/arm/mach-davinci/board-omapl138-hawk.c +1 -1
index 67c38d0..c43a6c3 100644
@@ -334,7 +334,7 @@ console_initcall(omapl138_hawk_console_init);
 
 ?static void __init omapl138_hawk_map_io(void)
 ?{
- ? ? ? da850_init();
+ ? ? ? da850_init(NULL);
 ?}
 
 ?MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
arch/arm/mach-davinci/da850.c +4 -1
index 133aac4..ebd0603 100644
@@ -1104,10 +1104,13 @@ static struct davinci_soc_info davinci_soc_info_da850 = {
 ? ? ? ?.reset_device ? ? ? ? ? = &da8xx_wdt_device,
 ?};
 
-void __init da850_init(void)
+void __init da850_init(struct da850_init_board_info *board)
 ?{
 ? ? ? ?unsigned int v;
 
+ ? ? ? if (board && board->ref_clk_rate)
+ ? ? ? ? ? ? ? ref_clk.rate = board->ref_clk_rate;
+
 ? ? ? ?davinci_common_init(&davinci_soc_info_da850);
 
 ? ? ? ?da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
arch/arm/mach-davinci/include/mach/da8xx.h +0 -0
index ad64da7..66efc5d 100644
@@ -69,8 +69,12 @@ extern unsigned int da850_max_speed;

?#define DA8XX_AEMIF_CTL_BASE ? 0x68000000
?#define DA8XX_ARM_RAM_BASE ? ? 0xffff0000

arch/arm/mach-davinci/include/mach/da8xx.h +4 -0
+struct da850_init_board_info {
+ ? ? ? unsigned long ref_clk_rate;
+};
+

?void __init da830_init(void);

arch/arm/mach-davinci/include/mach/da8xx.h +1 -1
-void __init da850_init(void);
+void __init da850_init(struct da850_init_board_info *board);

?int da830_register_edma(struct edma_rsv_info *rsv); ?int da850_register_edma(struct edma_rsv_info *rsv[2]); --
1.7.0.4

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Quoted 10 lines

From Menon, Nishanth [mailto:nm at ti.com]

Quoted 7 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

Quoted 6 lines
Quoted 3 lines

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Curious question: have you considered Documentation/power/opp.txt? Not entirely sure if that will help, but I am curious to know if there are reasons why it did not scale for you

I took a look at it but I got the impression that the code in mach-davinci does not use your OPP library. Instead the structs that are used for the OPPs are defined locally in arch/arm/mach-davinci/da850.c. The frequency multiplier and divider values are hardcoded there and do not scale with the input clock frequency.

Christian

#4 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

In reply to Christian Riesch
Quoted 6 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

The same problem was fixed for dm6467/T EVMs with a different approach.

This solution is much better than what was done for dm6467/T. So I am working on converting the dm6467/T code to this approach and should be able to post the updated patchset by tomorrow.

Thanks,
Sekhar

#5 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

In reply to Christian Riesch
Quoted 7 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

Quoted 6 lines

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Why not allow board code to just do a clk_set_rate()?

Currently the ref_clk struct clk does not have a .set_rate method implemented, but that should be easy enough to add.

Then the default ref_clk.rate would stay the 24MHz, but any boards that want to override that simply use clk_get(), clk_set_rate(), clk_put()

Kevin

Quoted 91 lines

---

Hi,
in private email Bob Dunlop suggested to pass a pointer to a small structure instead of the frequency value to allow future expansions, e.g., for the OPP list. Therefore I submit his patch as V2. Christian

 arch/arm/mach-davinci/board-da850-evm.c     |    2 +-
 arch/arm/mach-davinci/board-mityomapl138.c  |    2 +-
 arch/arm/mach-davinci/board-omapl138-hawk.c |    2 +-
 arch/arm/mach-davinci/da850.c               |    5 ++++-
 arch/arm/mach-davinci/include/mach/da8xx.h  |    6 +++++-
 5 files changed, 12 insertions(+), 5 deletions(-)
arch/arm/mach-davinci/board-da850-evm.c +1 -1
index a7b41bf..231ff87 100644
@@ -1252,7 +1252,7 @@ console_initcall(da850_evm_console_init);
 
 static void __init da850_evm_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138/AM18x EVM")
arch/arm/mach-davinci/board-mityomapl138.c +1 -1
index 606a6f2..362770c 100644
@@ -561,7 +561,7 @@ console_initcall(mityomapl138_console_init);
 
 static void __init mityomapl138_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(MITYOMAPL138, "MityDSP-L138/MityARM-1808")
arch/arm/mach-davinci/board-omapl138-hawk.c +1 -1
index 67c38d0..c43a6c3 100644
@@ -334,7 +334,7 @@ console_initcall(omapl138_hawk_console_init);
 
 static void __init omapl138_hawk_map_io(void)
 {
-	da850_init();
+	da850_init(NULL);
 }
 
 MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
arch/arm/mach-davinci/da850.c +4 -1
index 133aac4..ebd0603 100644
@@ -1104,10 +1104,13 @@ static struct davinci_soc_info davinci_soc_info_da850 = {
 	.reset_device		= &da8xx_wdt_device,
 };
 
-void __init da850_init(void)
+void __init da850_init(struct da850_init_board_info *board)
 {
 	unsigned int v;
 
+	if (board && board->ref_clk_rate)
+		ref_clk.rate = board->ref_clk_rate;
+
 	davinci_common_init(&davinci_soc_info_da850);
 
 	da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
arch/arm/mach-davinci/include/mach/da8xx.h +5 -1
index ad64da7..66efc5d 100644
@@ -69,8 +69,12 @@ extern unsigned int da850_max_speed;
 #define DA8XX_AEMIF_CTL_BASE	0x68000000
 #define DA8XX_ARM_RAM_BASE	0xffff0000
 
+struct da850_init_board_info {
+	unsigned long ref_clk_rate;
+};
+
 void __init da830_init(void);
-void __init da850_init(void);
+void __init da850_init(struct da850_init_board_info *board);
 
 int da830_register_edma(struct edma_rsv_info *rsv);
 int da850_register_edma(struct edma_rsv_info *rsv[2]);
#6 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Hi Kevin,

Quoted 16 lines · Kevin
Quoted 7 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

Quoted 6 lines

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Quoted 7 lines

Why not allow board code to just do a clk_set_rate()?

Currently the ref_clk struct clk does not have a .set_rate method implemented, but that should be easy enough to add.

Then the default ref_clk.rate would stay the 24MHz, but any boards that want to override that simply use clk_get(), clk_set_rate(), clk_put()

That's certainly much more elegant, but this would mean the whole clock tree is traversed again on each boot.

I am doing some measurements to see if there is any big difference in boot-time if this is done. Will get back with results.

Thanks,
Sekhar

#7 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Quoted 24 lines · Sekhar

Hi Kevin,

Quoted 21 lines · Kevin
Quoted 7 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

Quoted 6 lines

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Why not allow board code to just do a clk_set_rate()?

Currently the ref_clk struct clk does not have a .set_rate method implemented, but that should be easy enough to add.

Quoted 8 lines
Quoted 2 lines

Then the default ref_clk.rate would stay the 24MHz, but any boards that want to override that simply use clk_get(), clk_set_rate(), clk_put()

That's certainly much more elegant, but this would mean the whole clock tree is traversed again on each boot.

I am doing some measurements to see if there is any big difference in boot-time if this is done. Will get back with results.

I don't expect this to be a big boot-time impact.

However, some of the clock.c assumptions might need to be updated as it currently is written from the perspective that the PLL clocks are the "root" clocks.

Setting (and propagating) clock rates is what the clock framework is for, so adding a new interface to set a custom clock rate just doesn't seem right. I understand that the reference oscillator might be considered a special case, but if this can be done with the clock framework, it is much preferred.

Kevin

#8 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Quoted 1 line · Kevin

I don't expect this to be a big boot-time impact.

You are right. Using PRINTK_TIME on DM365 I saw no noticeable boot-time change. When I profiled the code using do_gettimeofday(), I saw it was taking ~95 usecs to complete the propagation. I was mainly worried about all the recursion and reading of PLL and sysclk registers. Seems its not so bad.

Quoted 3 lines

However, some of the clock.c assumptions might need to be updated as it currently is written from the perspective that the PLL clocks are the "root" clocks.

Hmm, just calling clk_set_rate() on refclk propagated the rate nicely across the tree. It seems DaVinci clock code is not in such a bad shape :) Or did I miss the concern?

Quoted 5 lines

Setting (and propagating) clock rates is what the clock framework is for, so adding a new interface to set a custom clock rate just doesn't seem right. I understand that the reference oscillator might be considered a special case, but if this can be done with the clock framework, it is much preferred.

Okay. Will modify the DM6467/T EVM code to use this method instead.

Thanks,
Sekhar

#9 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Quoted 18 lines · Sekhar
Quoted 1 line · Kevin

I don't expect this to be a big boot-time impact.

You are right. Using PRINTK_TIME on DM365 I saw no noticeable boot-time change. When I profiled the code using do_gettimeofday(), I saw it was taking ~95 usecs to complete the propagation. I was mainly worried about all the recursion and reading of PLL and sysclk registers. Seems its not so bad.

Quoted 3 lines

However, some of the clock.c assumptions might need to be updated as it currently is written from the perspective that the PLL clocks are the "root" clocks.

Hmm, just calling clk_set_rate() on refclk propagated the rate nicely across the tree. It seems DaVinci clock code is not in such a bad shape :) Or did I miss the concern?

Quoted 8 lines
Quoted 5 lines

Setting (and propagating) clock rates is what the clock framework is for, so adding a new interface to set a custom clock rate just doesn't seem right. I understand that the reference oscillator might be considered a special case, but if this can be done with the clock framework, it is much preferred.

Okay. Will modify the DM6467/T EVM code to use this method instead.

So, here is the patch. I suspect reference clock information should come from devicetree data when available. I hope it is OK to take this approach till that time?

Thanks,
Sekhar

-----8<------------
From: Sekhar Nori <[email protected]>
Date: Thu, 2 Jun 2011 14:10:50 +0530
Subject: [PATCH 1/1] davinci: dm6467/T EVM: fix setting up of reference clock rate

The DM6467 and DM6467T EVMs use different reference clock frequencies. This difference is currently supported by having the SoC code call a public board routine which sets up the reference clock frequency. This does not scale as more boards are added.

Instead, use the clk_set_rate() API to setup the reference clock frequency to a different value from the board file.

---
 arch/arm/mach-davinci/board-dm646x-evm.c    |   17 ++++--------
 arch/arm/mach-davinci/clock.c               |   38 +++++++++++++++++++++++++++
 arch/arm/mach-davinci/clock.h               |    2 +
 arch/arm/mach-davinci/dm646x.c              |    4 ++-
 arch/arm/mach-davinci/include/mach/dm646x.h |    2 -
 5 files changed, 49 insertions(+), 14 deletions(-)
arch/arm/mach-davinci/board-dm646x-evm.c +6 -11
index f6ac9ba..9db9838 100644
@@ -719,9 +719,15 @@ static void __init cdce_clk_init(void)
 	}
 }
 
+#define DM6467T_EVM_REF_FREQ		33000000
+
 static void __init davinci_map_io(void)
 {
 	dm646x_init();
+
+	if (machine_is_davinci_dm6467tevm())
+		davinci_set_refclk_rate(DM6467T_EVM_REF_FREQ);
+
 	cdce_clk_init();
 }
 
@@ -785,17 +791,6 @@ static __init void evm_init(void)
 	soc_info->emac_pdata->phy_id = DM646X_EVM_PHY_ID;
 }
 
-#define DM646X_EVM_REF_FREQ		27000000
-#define DM6467T_EVM_REF_FREQ		33000000
-
-void __init dm646x_board_setup_refclk(struct clk *clk)
-{
-	if (machine_is_davinci_dm6467tevm())
-		clk->rate = DM6467T_EVM_REF_FREQ;
-	else
-		clk->rate = DM646X_EVM_REF_FREQ;
-}
-
 MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
 	.boot_params  = (0x80000100),
 	.map_io       = davinci_map_io,
arch/arm/mach-davinci/clock.c +38 -0
index e4e3af1..ae65319 100644
@@ -368,6 +368,12 @@ static unsigned long clk_leafclk_recalc(struct clk *clk)
 	return clk->parent->rate;
 }
 
+int davinci_simple_set_rate(struct clk *clk, unsigned long rate)
+{
+	clk->rate = rate;
+	return 0;
+}
+
 static unsigned long clk_pllclk_recalc(struct clk *clk)
 {
 	u32 ctrl, mult = 1, prediv = 1, postdiv = 1;
@@ -506,6 +512,38 @@ int davinci_set_pllrate(struct pll_data *pll, unsigned int prediv,
 }
 EXPORT_SYMBOL(davinci_set_pllrate);
 
+/**
+ * davinci_set_refclk_rate() - Set the reference clock rate
+ * @rate:	The new rate.
+ *
+ * Sets the reference clock rate to a given value. This will most likely
+ * result in the entire clock tree getting updated.
+ *
+ * This is used to support boards which use a reference clock different
+ * than that used by default in <soc>.c file. The reference clock rate
+ * should be updated early in the boot process; ideally soon after the
+ * clock tree has been initialized once with the default reference clock
+ * rate (davinci_common_init()).
+ *
+ * Returns 0 on success, error otherwise.
+ */
+int davinci_set_refclk_rate(unsigned long rate)
+{
+	struct clk *refclk;
+
+	refclk = clk_get(NULL, "ref");
+	if (IS_ERR(refclk)) {
+		pr_err("%s: failed to get reference clock.\n", __func__);
+		return PTR_ERR(refclk);
+	}
+
+	clk_set_rate(refclk, rate);
+
+	clk_put(refclk);
+
+	return 0;
+}
+
 int __init davinci_clk_init(struct clk_lookup *clocks)
   {
 	struct clk_lookup *c;
arch/arm/mach-davinci/clock.h +2 -0
index 0dd2203..50b2482 100644
@@ -123,6 +123,8 @@ int davinci_clk_init(struct clk_lookup *clocks);
 int davinci_set_pllrate(struct pll_data *pll, unsigned int prediv,
 				unsigned int mult, unsigned int postdiv);
 int davinci_set_sysclk_rate(struct clk *clk, unsigned long rate);
+int davinci_set_refclk_rate(unsigned long rate);
+int davinci_simple_set_rate(struct clk *clk, unsigned long rate);
 
 extern struct platform_device davinci_wdt_device;
 extern void davinci_watchdog_reset(struct platform_device *);
arch/arm/mach-davinci/dm646x.c +3 -1
index 1e0f809..46739c9 100644
@@ -42,6 +42,7 @@
 /*
  * Device specific clocks
  */
+#define DM646X_REF_FREQ		27000000
 #define DM646X_AUX_FREQ		24000000
 
 static struct pll_data pll1_data = {
@@ -56,6 +57,8 @@ static struct pll_data pll2_data = {
 
 static struct clk ref_clk = {
 	.name = "ref_clk",
+	.rate = DM646X_REF_FREQ,
+	.set_rate = davinci_simple_set_rate,
 };
 
 static struct clk aux_clkin = {
@@ -901,7 +904,6 @@ int __init dm646x_init_edma(struct edma_rsv_info *rsv)
 
 void __init dm646x_init(void)
 {
-	dm646x_board_setup_refclk(&ref_clk);
 	davinci_common_init(&davinci_soc_info_dm646x);
 }
 
arch/arm/mach-davinci/include/mach/dm646x.h +0 -2
index 7a27f3f..2a00fe5 100644
@@ -15,7 +15,6 @@
 #include <mach/asp.h>
 #include <linux/i2c.h>
 #include <linux/videodev2.h>
-#include <linux/clk.h>
 #include <linux/davinci_emac.h>
 
 #define DM646X_EMAC_BASE		(0x01C80000)
@@ -31,7 +30,6 @@
 void __init dm646x_init(void);
 void __init dm646x_init_mcasp0(struct snd_platform_data *pdata);
 void __init dm646x_init_mcasp1(struct snd_platform_data *pdata);
-void __init dm646x_board_setup_refclk(struct clk *clk);
 int __init dm646x_init_edma(struct edma_rsv_info *rsv);
 
 void dm646x_video_init(void);
Signature · 1 line
1.7.3.2
#10 lore raw

PATCH 1/1 davinci: da850: add a .set_rate method to ref_clk

This patch allows setting the input clock frequency of the SoC from the board specific using the davinci_set_refclk_rate function.

---

This patch applies on top of Sekhar's patch.
Best regards, Christian

 arch/arm/mach-davinci/da850.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/da850.c +1 -0
index 133aac4..27fe3ac 100644
@@ -58,6 +58,7 @@ static struct pll_data pll0_data = {
 static struct clk ref_clk = {
 	.name		= "ref_clk",
 	.rate		= DA850_REF_FREQ,
+	.set_rate       = davinci_simple_set_rate,
 };
 
 static struct clk pll0_clk = {
Signature · 1 line
1.7.0.4
#11 lore raw

PATCH 1/1 davinci: da850: add a .set_rate method to ref_clk

Hi Christian,

Quoted 2 lines · Christian Riesch

This patch allows setting the input clock frequency of the SoC from the board specific using the davinci_set_refclk_rate function.

"board specific code"

Quoted 17 lines

---

This patch applies on top of Sekhar's patch.
Best regards, Christian

 arch/arm/mach-davinci/da850.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/da850.c +0 -0
index 133aac4..27fe3ac 100644

arch/arm/mach-davinci/da850.c static struct pll_data pll0_data = { · line 61

Quoted 4 lines
arch/arm/mach-davinci/da850.c +1 -0
@@ -58,6 +58,7 @@ static struct pll_data pll0_data = {
 static struct clk ref_clk = {
 	.name		= "ref_clk",
 	.rate		= DA850_REF_FREQ,
+	.set_rate       = davinci_simple_set_rate,

Please use tabs for indentation.

Thanks,
Sekhar

#12 lore raw

PATCH v2 1/1 davinci: da850: add a .set_rate method to ref_clk

This patch allows setting the input clock frequency of the SoC from the board specific code using the davinci_set_refclk_rate function.

---

v2: fixed the commit message and indentation.
Regards, Christian

 arch/arm/mach-davinci/da850.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/da850.c +1 -0
index 133aac4..27fe3ac 100644
@@ -58,6 +58,7 @@ static struct pll_data pll0_data = {
 static struct clk ref_clk = {
 	.name		= "ref_clk",
 	.rate		= DA850_REF_FREQ,
+	.set_rate	= davinci_simple_set_rate,
 };
 
 static struct clk pll0_clk = {
Signature · 1 line
1.7.0.4
#13 lore raw

PATCH v2 1/1 davinci: da850: add a .set_rate method to ref_clk

Hi Christian,

Quoted 18 lines · Christian Riesch

This patch allows setting the input clock frequency of the SoC from the board specific code using the davinci_set_refclk_rate function.

---

v2: fixed the commit message and indentation.
Regards, Christian

 arch/arm/mach-davinci/da850.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/da850.c +0 -0
index 133aac4..27fe3ac 100644

arch/arm/mach-davinci/da850.c static struct pll_data pll0_data = { · line 64

Quoted 7 lines
arch/arm/mach-davinci/da850.c +1 -0
@@ -58,6 +58,7 @@ static struct pll_data pll0_data = {
 static struct clk ref_clk = {
 	.name		= "ref_clk",
 	.rate		= DA850_REF_FREQ,
+	.set_rate	= davinci_simple_set_rate,
 };
 
 static struct clk pll0_clk = {

Thanks, will queue this as a 'feature' for
next merge window.

Thanks,
Sekhar

#14 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

In reply to Nori, Sekhar
Quoted 45 lines · Sekhar
Quoted 18 lines · Sekhar
Quoted 1 line · Kevin

I don't expect this to be a big boot-time impact.

You are right. Using PRINTK_TIME on DM365 I saw no noticeable boot-time change. When I profiled the code using do_gettimeofday(), I saw it was taking ~95 usecs to complete the propagation. I was mainly worried about all the recursion and reading of PLL and sysclk registers. Seems its not so bad.

Quoted 3 lines

However, some of the clock.c assumptions might need to be updated as it currently is written from the perspective that the PLL clocks are the "root" clocks.

Hmm, just calling clk_set_rate() on refclk propagated the rate nicely across the tree. It seems DaVinci clock code is not in such a bad shape :) Or did I miss the concern?

Quoted 8 lines
Quoted 5 lines

Setting (and propagating) clock rates is what the clock framework is for, so adding a new interface to set a custom clock rate just doesn't seem right. I understand that the reference oscillator might be considered a special case, but if this can be done with the clock framework, it is much preferred.

Okay. Will modify the DM6467/T EVM code to use this method instead.

So, here is the patch. I suspect reference clock information should come from devicetree data when available. I hope it is OK to take this approach till that time?

Thanks,
Sekhar

-----8<------------
From: Sekhar Nori <[email protected]>
Date: Thu, 2 Jun 2011 14:10:50 +0530
Subject: [PATCH 1/1] davinci: dm6467/T EVM: fix setting up of reference clock rate

The DM6467 and DM6467T EVMs use different reference clock frequencies. This difference is currently supported by having the SoC code call a public board routine which sets up the reference clock frequency. This does not scale as more boards are added.

Quoted 5 lines

Instead, use the clk_set_rate() API to setup the reference clock frequency to a different value from the board file.

#15 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

In reply to Kevin Hilman

Hi Kevin,

Quoted 9 lines · Kevin Hilman
Quoted 7 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

Quoted 8 lines
Quoted 6 lines

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Why not allow board code to just do a clk_set_rate()?

I'm fine with this method (In fact it was the first thing that I tried, I added a .set_rate method to ref_clk, it worked well for me). However I wonder whether first initializing the clock with the wrong value (24 MHz) and later correcting it via clk_set_rate() would break something. In the meantime, the data in the clock tree do not reflect the actual frequencies that are present on the SoC.

Christian

#16 lore raw

PATCH v2 1/1 davinci: da850: move input frequency to board specific files

Hi Christian,

Quoted 19 lines · Christian Riesch

Hi Kevin,

Quoted 16 lines · Kevin Hilman
Quoted 13 lines · Christian Riesch

From: Bob Dunlop <[email protected]>

Currently the input frequency of the SoC is hardcoded in the SoC specific da850.c file to 24 MHz. Since the SoC accepts input frequencies in a wide range from 12 to 50 MHz, boards with different oscillator/crystal frequencies may be built.

This patch allows setting a different input frequency in the board specific files to support boards with oscillator/crystal frequencies other than 24 MHz.

Quoted 8 lines
Quoted 1 line

Why not allow board code to just do a clk_set_rate()?

I'm fine with this method (In fact it was the first thing that I tried, I added a .set_rate method to ref_clk, it worked well for me). However I wonder whether first initializing the clock with the wrong value (24 MHz) and later correcting it via clk_set_rate() would break something. In the meantime, the data in the clock tree do not reflect the actual frequencies that are present on the SoC.

Doing this right after <soc>_init() should be safe. The board should not assume clocks to be setup before this call is made.

Thanks,
Sekhar