All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: at91: clk-main: update key before writing AT91_CKGR_MOR
@ 2020-07-30  9:03 ` Claudiu Beznea
  0 siblings, 0 replies; 4+ messages in thread
From: Claudiu Beznea @ 2020-07-30  9:03 UTC (permalink / raw)
  To: mturquette, sboyd, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, mturquette, bbrezillon
  Cc: linux-clk, linux-arm-kernel, linux-kernel, Claudiu Beznea

SAMA5D2 datasheet specifies on chapter 33.22.8 (PMC Clock Generator
Main Oscillator Register) that writing any value other than
0x37 on KEY field aborts the write operation. Use the key when
selecting main clock parent.

Fixes: 27cb1c2083373 ("clk: at91: rework main clk implementation")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/clk/at91/clk-main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
index 5c83e899084f..cfae2f59df66 100644
--- a/drivers/clk/at91/clk-main.c
+++ b/drivers/clk/at91/clk-main.c
@@ -437,12 +437,17 @@ static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
 		return -EINVAL;
 
 	regmap_read(regmap, AT91_CKGR_MOR, &tmp);
-	tmp &= ~MOR_KEY_MASK;
 
 	if (index && !(tmp & AT91_PMC_MOSCSEL))
-		regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
+		tmp = AT91_PMC_MOSCSEL;
 	else if (!index && (tmp & AT91_PMC_MOSCSEL))
-		regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
+		tmp = 0;
+	else
+		return 0;
+
+	regmap_update_bits(regmap, AT91_CKGR_MOR,
+			   AT91_PMC_MOSCSEL | MOR_KEY_MASK,
+			   tmp | AT91_PMC_KEY);
 
 	while (!clk_sam9x5_main_ready(regmap))
 		cpu_relax();
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] clk: at91: clk-main: update key before writing AT91_CKGR_MOR
@ 2020-07-30  9:03 ` Claudiu Beznea
  0 siblings, 0 replies; 4+ messages in thread
From: Claudiu Beznea @ 2020-07-30  9:03 UTC (permalink / raw)
  To: mturquette, sboyd, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, mturquette, bbrezillon
  Cc: Claudiu Beznea, linux-clk, linux-arm-kernel, linux-kernel

SAMA5D2 datasheet specifies on chapter 33.22.8 (PMC Clock Generator
Main Oscillator Register) that writing any value other than
0x37 on KEY field aborts the write operation. Use the key when
selecting main clock parent.

Fixes: 27cb1c2083373 ("clk: at91: rework main clk implementation")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/clk/at91/clk-main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
index 5c83e899084f..cfae2f59df66 100644
--- a/drivers/clk/at91/clk-main.c
+++ b/drivers/clk/at91/clk-main.c
@@ -437,12 +437,17 @@ static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
 		return -EINVAL;
 
 	regmap_read(regmap, AT91_CKGR_MOR, &tmp);
-	tmp &= ~MOR_KEY_MASK;
 
 	if (index && !(tmp & AT91_PMC_MOSCSEL))
-		regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
+		tmp = AT91_PMC_MOSCSEL;
 	else if (!index && (tmp & AT91_PMC_MOSCSEL))
-		regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
+		tmp = 0;
+	else
+		return 0;
+
+	regmap_update_bits(regmap, AT91_CKGR_MOR,
+			   AT91_PMC_MOSCSEL | MOR_KEY_MASK,
+			   tmp | AT91_PMC_KEY);
 
 	while (!clk_sam9x5_main_ready(regmap))
 		cpu_relax();
-- 
2.7.4


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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] clk: at91: clk-main: update key before writing AT91_CKGR_MOR
  2020-07-30  9:03 ` Claudiu Beznea
@ 2020-08-04 16:00   ` Alexandre Belloni
  -1 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2020-08-04 16:00 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: mturquette, sboyd, nicolas.ferre, ludovic.desroches, mturquette,
	bbrezillon, linux-clk, linux-arm-kernel, linux-kernel

On 30/07/2020 12:03:23+0300, Claudiu Beznea wrote:
> SAMA5D2 datasheet specifies on chapter 33.22.8 (PMC Clock Generator
> Main Oscillator Register) that writing any value other than
> 0x37 on KEY field aborts the write operation. Use the key when
> selecting main clock parent.
> 
> Fixes: 27cb1c2083373 ("clk: at91: rework main clk implementation")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/clk/at91/clk-main.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
> index 5c83e899084f..cfae2f59df66 100644
> --- a/drivers/clk/at91/clk-main.c
> +++ b/drivers/clk/at91/clk-main.c
> @@ -437,12 +437,17 @@ static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
>  		return -EINVAL;
>  
>  	regmap_read(regmap, AT91_CKGR_MOR, &tmp);
> -	tmp &= ~MOR_KEY_MASK;
>  
>  	if (index && !(tmp & AT91_PMC_MOSCSEL))
> -		regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
> +		tmp = AT91_PMC_MOSCSEL;
>  	else if (!index && (tmp & AT91_PMC_MOSCSEL))
> -		regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
> +		tmp = 0;
> +	else
> +		return 0;
> +
> +	regmap_update_bits(regmap, AT91_CKGR_MOR,
> +			   AT91_PMC_MOSCSEL | MOR_KEY_MASK,
> +			   tmp | AT91_PMC_KEY);
>  
>  	while (!clk_sam9x5_main_ready(regmap))
>  		cpu_relax();
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clk: at91: clk-main: update key before writing AT91_CKGR_MOR
@ 2020-08-04 16:00   ` Alexandre Belloni
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2020-08-04 16:00 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: mturquette, bbrezillon, sboyd, mturquette, linux-kernel,
	ludovic.desroches, linux-clk, linux-arm-kernel

On 30/07/2020 12:03:23+0300, Claudiu Beznea wrote:
> SAMA5D2 datasheet specifies on chapter 33.22.8 (PMC Clock Generator
> Main Oscillator Register) that writing any value other than
> 0x37 on KEY field aborts the write operation. Use the key when
> selecting main clock parent.
> 
> Fixes: 27cb1c2083373 ("clk: at91: rework main clk implementation")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/clk/at91/clk-main.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
> index 5c83e899084f..cfae2f59df66 100644
> --- a/drivers/clk/at91/clk-main.c
> +++ b/drivers/clk/at91/clk-main.c
> @@ -437,12 +437,17 @@ static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
>  		return -EINVAL;
>  
>  	regmap_read(regmap, AT91_CKGR_MOR, &tmp);
> -	tmp &= ~MOR_KEY_MASK;
>  
>  	if (index && !(tmp & AT91_PMC_MOSCSEL))
> -		regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
> +		tmp = AT91_PMC_MOSCSEL;
>  	else if (!index && (tmp & AT91_PMC_MOSCSEL))
> -		regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
> +		tmp = 0;
> +	else
> +		return 0;
> +
> +	regmap_update_bits(regmap, AT91_CKGR_MOR,
> +			   AT91_PMC_MOSCSEL | MOR_KEY_MASK,
> +			   tmp | AT91_PMC_KEY);
>  
>  	while (!clk_sam9x5_main_ready(regmap))
>  		cpu_relax();
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-04 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30  9:03 [PATCH] clk: at91: clk-main: update key before writing AT91_CKGR_MOR Claudiu Beznea
2020-07-30  9:03 ` Claudiu Beznea
2020-08-04 16:00 ` Alexandre Belloni
2020-08-04 16:00   ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.