Skip to contentSkip to conversation

clk: npcm7xx: Mark the dividers read-only

PATCH In review William A. Kennington III 2 participants 3 messages Nov 30

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

PATCH 1/1 clk: npcm7xx: Mark the dividers read-only

From: Tomer Maimon <[email protected]>

The NPCM7xx clock dividers are programmed by the boot firmware. The driver registers them as ordinary dividers, so a consumer that calls clk_set_rate() reprograms them.

Register the dividers with CLK_DIVIDER_READ_ONLY, so that the kernel keeps what the firmware has set up. clk-npcm8xx already registers most of its dividers this way. The SPI3 divider stays writable.

The one in-tree consumer that sets the rate of these clocks is spi-npcm-fiu, which asks for the maximum frequency of the flash on each transfer. FIU0 and FIUX are clocked from the SPI0 and SPIX dividers, so they now stay at the rate the firmware chose and clk_set_rate() on them succeeds without changing anything. FIU3 is clocked from the SPI3 divider and is not affected.

[[email protected]: add the flag in place, rewrite the commit message]
---
 drivers/clk/clk-npcm7xx.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/clk/clk-npcm7xx.c +19 -19
index 562d2d406d7a..cb206d22e0f7 100644
@@ -335,66 +335,66 @@ static const struct npcm7xx_clk_mux_data npcm7xx_muxes[] __initconst = {
 /* configurable dividers: */
 static const struct npcm7xx_clk_div_data npcm7xx_divs[] __initconst = {
 	{NPCM7XX_CLKDIV1, 28, 3, NPCM7XX_CLK_S_ADC,
-	NPCM7XX_CLK_S_TIMER, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_ADC},
+	NPCM7XX_CLK_S_TIMER, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_ADC},
 	/*30-28 ADCCKDIV*/
 	{NPCM7XX_CLKDIV1, 26, 2, NPCM7XX_CLK_S_AHB,
-	NPCM7XX_CLK_S_AXI, 0, CLK_IS_CRITICAL, NPCM7XX_CLK_AHB},
+	NPCM7XX_CLK_S_AXI, CLK_DIVIDER_READ_ONLY, CLK_IS_CRITICA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X_CLK_AXI},/*0 CLK2DIV*/
 
 	{NPCM7XX_CLKDIV2, 30, 2, NPCM7XX_CLK_S_APB4,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB4},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB4},
 	/*31-30 APB4CKDIV*/
 	{NPCM7XX_CLKDIV2, 28, 2, NPCM7XX_CLK_S_APB3,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB3},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB3},
 	/*29-28 APB3CKDIV*/
 	{NPCM7XX_CLKDIV2, 26, 2, NPCM7XX_CLK_S_APB2,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB2},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB2},
 	/*27-26 APB2CKDIV*/
 	{NPCM7XX_CLKDIV2, 24, 2, NPCM7XX_CLK_S_APB1,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB1},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB1},
 	/*25-24 APB1CKDIV*/
 	{NPCM7XX_CLKDIV2, 22, 2, NPCM7XX_CLK_S_APB5,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB5},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0, NPCM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AHB, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SPI0},
 	/*10-6 SPI0CKDV*/
 	{NPCM7XX_CLKDIV3, 1, 5, NPCM7XX_CLK_S_SPIX,
-	NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPIX},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SPIX},
 	/*5-1 SPIXCKDV*/
 
 };
#1 lore raw
Quoted 9 lines · William A. Kennington III

From: Tomer Maimon <[email protected]>

The NPCM7xx clock dividers are programmed by the boot firmware. The driver registers them as ordinary dividers, so a consumer that calls clk_set_rate() reprograms them.

Register the dividers with CLK_DIVIDER_READ_ONLY, so that the kernel keeps what the firmware has set up. clk-npcm8xx already registers most of its dividers this way. The SPI3 divider stays writable.

You are explaining what you are doing, not really why you are doing it. You've got a boot firmware that gives an initial state. This is fairly usual and we don't lock all the clock controllers down based ont that.

Why should the kernel be unable to to touch these clocks now ?

Signature · 1 line
Jerome
#2 lore raw
Quoted 5 lines · Jerome Brunet

You are explaining what you are doing, not really why you are doing it. You've got a boot firmware that gives an initial state. This is fairly usual and we don't lock all the clock controllers down based ont that.

Why should the kernel be unable to to touch these clocks now ?

My bad, we have been carrying this a while and when I first glanced at it I thought it would be a good idea to just send as-is. You are right, I don't see a good reason to keep it.

Unless Tomer knows of a hardware constraint I missed, let's drop this patch. Thanks for the review.

William