* [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields
@ 2015-06-17 12:40 ` Nicolas Ferre
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Ferre @ 2015-06-17 12:40 UTC (permalink / raw
To: Boris BREZILLON
Cc: Alexandre Belloni, Ludovic Desroches, Josh Wu, linux-arm-kernel,
linux-kernel, mturquette, Nicolas Ferre
Add _MASK and _OFFSET values and cleanup register fields layout.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/clk/at91/clk-peripheral.c | 8 ++++----
include/linux/clk/at91_pmc.h | 14 ++++++--------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
index 597fed423d7d..61d0adda7088 100644
--- a/drivers/clk/at91/clk-peripheral.c
+++ b/drivers/clk/at91/clk-peripheral.c
@@ -165,7 +165,7 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
if (periph->id < PERIPHERAL_ID_MIN)
return 0;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
AT91_PMC_PCR_CMD |
AT91_PMC_PCR_DIV(periph->div) |
AT91_PMC_PCR_EN);
@@ -180,7 +180,7 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
if (periph->id < PERIPHERAL_ID_MIN)
return;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
AT91_PMC_PCR_CMD);
}
@@ -194,7 +194,7 @@ static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
return 1;
pmc_lock(pmc);
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN);
pmc_unlock(pmc);
@@ -213,7 +213,7 @@ clk_sam9x5_peripheral_recalc_rate(struct clk_hw *hw,
return parent_rate;
pmc_lock(pmc);
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
tmp = pmc_read(pmc, AT91_PMC_PCR);
pmc_unlock(pmc);
diff --git a/include/linux/clk/at91_pmc.h b/include/linux/clk/at91_pmc.h
index 7669f7618f39..dfc59e2b64fb 100644
--- a/include/linux/clk/at91_pmc.h
+++ b/include/linux/clk/at91_pmc.h
@@ -182,13 +182,11 @@ extern void __iomem *at91_pmc_base;
#define AT91_PMC_PCSR1 0x108 /* Peripheral Clock Enable Register 1 */
#define AT91_PMC_PCR 0x10c /* Peripheral Control Register [some SAM9 and SAMA5] */
-#define AT91_PMC_PCR_PID (0x3f << 0) /* Peripheral ID */
-#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
-#define AT91_PMC_PCR_DIV(n) ((n) << 16) /* Divisor Value */
-#define AT91_PMC_PCR_DIV0 0x0 /* Peripheral clock is MCK */
-#define AT91_PMC_PCR_DIV2 0x1 /* Peripheral clock is MCK/2 */
-#define AT91_PMC_PCR_DIV4 0x2 /* Peripheral clock is MCK/4 */
-#define AT91_PMC_PCR_DIV8 0x3 /* Peripheral clock is MCK/8 */
-#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
+#define AT91_PMC_PCR_PID_MASK 0x3f
+#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
+#define AT91_PMC_PCR_DIV_OFFSET 16
+#define AT91_PMC_PCR_DIV_MASK (0x3 << AT91_PMC_PCR_DIV_OFFSET)
+#define AT91_PMC_PCR_DIV(n) ((n) << AT91_PMC_PCR_DIV_OFFSET) /* Divisor Value */
+#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
#endif
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields
@ 2015-06-17 12:40 ` Nicolas Ferre
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Ferre @ 2015-06-17 12:40 UTC (permalink / raw
To: linux-arm-kernel
Add _MASK and _OFFSET values and cleanup register fields layout.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/clk/at91/clk-peripheral.c | 8 ++++----
include/linux/clk/at91_pmc.h | 14 ++++++--------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
index 597fed423d7d..61d0adda7088 100644
--- a/drivers/clk/at91/clk-peripheral.c
+++ b/drivers/clk/at91/clk-peripheral.c
@@ -165,7 +165,7 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
if (periph->id < PERIPHERAL_ID_MIN)
return 0;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
AT91_PMC_PCR_CMD |
AT91_PMC_PCR_DIV(periph->div) |
AT91_PMC_PCR_EN);
@@ -180,7 +180,7 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
if (periph->id < PERIPHERAL_ID_MIN)
return;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
AT91_PMC_PCR_CMD);
}
@@ -194,7 +194,7 @@ static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
return 1;
pmc_lock(pmc);
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN);
pmc_unlock(pmc);
@@ -213,7 +213,7 @@ clk_sam9x5_peripheral_recalc_rate(struct clk_hw *hw,
return parent_rate;
pmc_lock(pmc);
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
tmp = pmc_read(pmc, AT91_PMC_PCR);
pmc_unlock(pmc);
diff --git a/include/linux/clk/at91_pmc.h b/include/linux/clk/at91_pmc.h
index 7669f7618f39..dfc59e2b64fb 100644
--- a/include/linux/clk/at91_pmc.h
+++ b/include/linux/clk/at91_pmc.h
@@ -182,13 +182,11 @@ extern void __iomem *at91_pmc_base;
#define AT91_PMC_PCSR1 0x108 /* Peripheral Clock Enable Register 1 */
#define AT91_PMC_PCR 0x10c /* Peripheral Control Register [some SAM9 and SAMA5] */
-#define AT91_PMC_PCR_PID (0x3f << 0) /* Peripheral ID */
-#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
-#define AT91_PMC_PCR_DIV(n) ((n) << 16) /* Divisor Value */
-#define AT91_PMC_PCR_DIV0 0x0 /* Peripheral clock is MCK */
-#define AT91_PMC_PCR_DIV2 0x1 /* Peripheral clock is MCK/2 */
-#define AT91_PMC_PCR_DIV4 0x2 /* Peripheral clock is MCK/4 */
-#define AT91_PMC_PCR_DIV8 0x3 /* Peripheral clock is MCK/8 */
-#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
+#define AT91_PMC_PCR_PID_MASK 0x3f
+#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
+#define AT91_PMC_PCR_DIV_OFFSET 16
+#define AT91_PMC_PCR_DIV_MASK (0x3 << AT91_PMC_PCR_DIV_OFFSET)
+#define AT91_PMC_PCR_DIV(n) ((n) << AT91_PMC_PCR_DIV_OFFSET) /* Divisor Value */
+#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
#endif
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] clk: at91: modify PMC peripheral clock to deal with newer register layout
2015-06-17 12:40 ` Nicolas Ferre
@ 2015-06-17 12:40 ` Nicolas Ferre
-1 siblings, 0 replies; 8+ messages in thread
From: Nicolas Ferre @ 2015-06-17 12:40 UTC (permalink / raw
To: Boris BREZILLON
Cc: Alexandre Belloni, Ludovic Desroches, Josh Wu, linux-arm-kernel,
linux-kernel, mturquette, Nicolas Ferre
As some more information is added to the PCR register, we'd better use
a copy of its content and modify just the peripheral-related bits.
Implement a read-modify-write for the enable() and disable() callbacks.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
v2: - modify header file beforehand so that we can use consistent field naming
drivers/clk/at91/clk-peripheral.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
index 61d0adda7088..1e7dcc57925a 100644
--- a/drivers/clk/at91/clk-peripheral.c
+++ b/drivers/clk/at91/clk-peripheral.c
@@ -161,14 +161,18 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
{
struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
+ u32 tmp;
if (periph->id < PERIPHERAL_ID_MIN)
return 0;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
- AT91_PMC_PCR_CMD |
- AT91_PMC_PCR_DIV(periph->div) |
- AT91_PMC_PCR_EN);
+ pmc_lock(pmc);
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
+ tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK;
+ pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div)
+ | AT91_PMC_PCR_CMD
+ | AT91_PMC_PCR_EN);
+ pmc_unlock(pmc);
return 0;
}
@@ -176,12 +180,16 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
{
struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
+ u32 tmp;
if (periph->id < PERIPHERAL_ID_MIN)
return;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
- AT91_PMC_PCR_CMD);
+ pmc_lock(pmc);
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
+ tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN;
+ pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
+ pmc_unlock(pmc);
}
static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] clk: at91: modify PMC peripheral clock to deal with newer register layout
@ 2015-06-17 12:40 ` Nicolas Ferre
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Ferre @ 2015-06-17 12:40 UTC (permalink / raw
To: linux-arm-kernel
As some more information is added to the PCR register, we'd better use
a copy of its content and modify just the peripheral-related bits.
Implement a read-modify-write for the enable() and disable() callbacks.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
v2: - modify header file beforehand so that we can use consistent field naming
drivers/clk/at91/clk-peripheral.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
index 61d0adda7088..1e7dcc57925a 100644
--- a/drivers/clk/at91/clk-peripheral.c
+++ b/drivers/clk/at91/clk-peripheral.c
@@ -161,14 +161,18 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
{
struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
+ u32 tmp;
if (periph->id < PERIPHERAL_ID_MIN)
return 0;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
- AT91_PMC_PCR_CMD |
- AT91_PMC_PCR_DIV(periph->div) |
- AT91_PMC_PCR_EN);
+ pmc_lock(pmc);
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
+ tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK;
+ pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div)
+ | AT91_PMC_PCR_CMD
+ | AT91_PMC_PCR_EN);
+ pmc_unlock(pmc);
return 0;
}
@@ -176,12 +180,16 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
{
struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
+ u32 tmp;
if (periph->id < PERIPHERAL_ID_MIN)
return;
- pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
- AT91_PMC_PCR_CMD);
+ pmc_lock(pmc);
+ pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
+ tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN;
+ pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
+ pmc_unlock(pmc);
}
static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
--
2.1.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields
2015-06-17 12:40 ` Nicolas Ferre
@ 2015-06-17 14:37 ` Boris Brezillon
-1 siblings, 0 replies; 8+ messages in thread
From: Boris Brezillon @ 2015-06-17 14:37 UTC (permalink / raw
To: Nicolas Ferre
Cc: Alexandre Belloni, Ludovic Desroches, Josh Wu, linux-arm-kernel,
linux-kernel, mturquette
On Wed, 17 Jun 2015 14:40:38 +0200
Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> Add _MASK and _OFFSET values and cleanup register fields layout.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> drivers/clk/at91/clk-peripheral.c | 8 ++++----
> include/linux/clk/at91_pmc.h | 14 ++++++--------
> 2 files changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
> index 597fed423d7d..61d0adda7088 100644
> --- a/drivers/clk/at91/clk-peripheral.c
> +++ b/drivers/clk/at91/clk-peripheral.c
> @@ -165,7 +165,7 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
> if (periph->id < PERIPHERAL_ID_MIN)
> return 0;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> AT91_PMC_PCR_CMD |
> AT91_PMC_PCR_DIV(periph->div) |
> AT91_PMC_PCR_EN);
> @@ -180,7 +180,7 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
> if (periph->id < PERIPHERAL_ID_MIN)
> return;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> AT91_PMC_PCR_CMD);
> }
>
> @@ -194,7 +194,7 @@ static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
> return 1;
>
> pmc_lock(pmc);
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN);
> pmc_unlock(pmc);
>
> @@ -213,7 +213,7 @@ clk_sam9x5_peripheral_recalc_rate(struct clk_hw *hw,
> return parent_rate;
>
> pmc_lock(pmc);
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> tmp = pmc_read(pmc, AT91_PMC_PCR);
> pmc_unlock(pmc);
>
> diff --git a/include/linux/clk/at91_pmc.h b/include/linux/clk/at91_pmc.h
> index 7669f7618f39..dfc59e2b64fb 100644
> --- a/include/linux/clk/at91_pmc.h
> +++ b/include/linux/clk/at91_pmc.h
> @@ -182,13 +182,11 @@ extern void __iomem *at91_pmc_base;
> #define AT91_PMC_PCSR1 0x108 /* Peripheral Clock Enable Register 1 */
>
> #define AT91_PMC_PCR 0x10c /* Peripheral Control Register [some SAM9 and SAMA5] */
> -#define AT91_PMC_PCR_PID (0x3f << 0) /* Peripheral ID */
> -#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
> -#define AT91_PMC_PCR_DIV(n) ((n) << 16) /* Divisor Value */
> -#define AT91_PMC_PCR_DIV0 0x0 /* Peripheral clock is MCK */
> -#define AT91_PMC_PCR_DIV2 0x1 /* Peripheral clock is MCK/2 */
> -#define AT91_PMC_PCR_DIV4 0x2 /* Peripheral clock is MCK/4 */
> -#define AT91_PMC_PCR_DIV8 0x3 /* Peripheral clock is MCK/8 */
> -#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
> +#define AT91_PMC_PCR_PID_MASK 0x3f
> +#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
> +#define AT91_PMC_PCR_DIV_OFFSET 16
> +#define AT91_PMC_PCR_DIV_MASK (0x3 << AT91_PMC_PCR_DIV_OFFSET)
> +#define AT91_PMC_PCR_DIV(n) ((n) << AT91_PMC_PCR_DIV_OFFSET) /* Divisor Value */
> +#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
>
> #endif
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields
@ 2015-06-17 14:37 ` Boris Brezillon
0 siblings, 0 replies; 8+ messages in thread
From: Boris Brezillon @ 2015-06-17 14:37 UTC (permalink / raw
To: linux-arm-kernel
On Wed, 17 Jun 2015 14:40:38 +0200
Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> Add _MASK and _OFFSET values and cleanup register fields layout.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> drivers/clk/at91/clk-peripheral.c | 8 ++++----
> include/linux/clk/at91_pmc.h | 14 ++++++--------
> 2 files changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
> index 597fed423d7d..61d0adda7088 100644
> --- a/drivers/clk/at91/clk-peripheral.c
> +++ b/drivers/clk/at91/clk-peripheral.c
> @@ -165,7 +165,7 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
> if (periph->id < PERIPHERAL_ID_MIN)
> return 0;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> AT91_PMC_PCR_CMD |
> AT91_PMC_PCR_DIV(periph->div) |
> AT91_PMC_PCR_EN);
> @@ -180,7 +180,7 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
> if (periph->id < PERIPHERAL_ID_MIN)
> return;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID) |
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> AT91_PMC_PCR_CMD);
> }
>
> @@ -194,7 +194,7 @@ static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
> return 1;
>
> pmc_lock(pmc);
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN);
> pmc_unlock(pmc);
>
> @@ -213,7 +213,7 @@ clk_sam9x5_peripheral_recalc_rate(struct clk_hw *hw,
> return parent_rate;
>
> pmc_lock(pmc);
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID));
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> tmp = pmc_read(pmc, AT91_PMC_PCR);
> pmc_unlock(pmc);
>
> diff --git a/include/linux/clk/at91_pmc.h b/include/linux/clk/at91_pmc.h
> index 7669f7618f39..dfc59e2b64fb 100644
> --- a/include/linux/clk/at91_pmc.h
> +++ b/include/linux/clk/at91_pmc.h
> @@ -182,13 +182,11 @@ extern void __iomem *at91_pmc_base;
> #define AT91_PMC_PCSR1 0x108 /* Peripheral Clock Enable Register 1 */
>
> #define AT91_PMC_PCR 0x10c /* Peripheral Control Register [some SAM9 and SAMA5] */
> -#define AT91_PMC_PCR_PID (0x3f << 0) /* Peripheral ID */
> -#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
> -#define AT91_PMC_PCR_DIV(n) ((n) << 16) /* Divisor Value */
> -#define AT91_PMC_PCR_DIV0 0x0 /* Peripheral clock is MCK */
> -#define AT91_PMC_PCR_DIV2 0x1 /* Peripheral clock is MCK/2 */
> -#define AT91_PMC_PCR_DIV4 0x2 /* Peripheral clock is MCK/4 */
> -#define AT91_PMC_PCR_DIV8 0x3 /* Peripheral clock is MCK/8 */
> -#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
> +#define AT91_PMC_PCR_PID_MASK 0x3f
> +#define AT91_PMC_PCR_CMD (0x1 << 12) /* Command (read=0, write=1) */
> +#define AT91_PMC_PCR_DIV_OFFSET 16
> +#define AT91_PMC_PCR_DIV_MASK (0x3 << AT91_PMC_PCR_DIV_OFFSET)
> +#define AT91_PMC_PCR_DIV(n) ((n) << AT91_PMC_PCR_DIV_OFFSET) /* Divisor Value */
> +#define AT91_PMC_PCR_EN (0x1 << 28) /* Enable */
>
> #endif
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] clk: at91: modify PMC peripheral clock to deal with newer register layout
2015-06-17 12:40 ` Nicolas Ferre
@ 2015-06-17 14:39 ` Boris Brezillon
-1 siblings, 0 replies; 8+ messages in thread
From: Boris Brezillon @ 2015-06-17 14:39 UTC (permalink / raw
To: Nicolas Ferre
Cc: Alexandre Belloni, Ludovic Desroches, Josh Wu, linux-arm-kernel,
linux-kernel, mturquette
On Wed, 17 Jun 2015 14:40:39 +0200
Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> As some more information is added to the PCR register, we'd better use
> a copy of its content and modify just the peripheral-related bits.
> Implement a read-modify-write for the enable() and disable() callbacks.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> v2: - modify header file beforehand so that we can use consistent field naming
>
>
> drivers/clk/at91/clk-peripheral.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
> index 61d0adda7088..1e7dcc57925a 100644
> --- a/drivers/clk/at91/clk-peripheral.c
> +++ b/drivers/clk/at91/clk-peripheral.c
> @@ -161,14 +161,18 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
> {
> struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
> struct at91_pmc *pmc = periph->pmc;
> + u32 tmp;
>
> if (periph->id < PERIPHERAL_ID_MIN)
> return 0;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> - AT91_PMC_PCR_CMD |
> - AT91_PMC_PCR_DIV(periph->div) |
> - AT91_PMC_PCR_EN);
> + pmc_lock(pmc);
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> + tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK;
> + pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div)
> + | AT91_PMC_PCR_CMD
> + | AT91_PMC_PCR_EN);
> + pmc_unlock(pmc);
> return 0;
> }
>
> @@ -176,12 +180,16 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
> {
> struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
> struct at91_pmc *pmc = periph->pmc;
> + u32 tmp;
>
> if (periph->id < PERIPHERAL_ID_MIN)
> return;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> - AT91_PMC_PCR_CMD);
> + pmc_lock(pmc);
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> + tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN;
> + pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
> + pmc_unlock(pmc);
> }
>
> static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] clk: at91: modify PMC peripheral clock to deal with newer register layout
@ 2015-06-17 14:39 ` Boris Brezillon
0 siblings, 0 replies; 8+ messages in thread
From: Boris Brezillon @ 2015-06-17 14:39 UTC (permalink / raw
To: linux-arm-kernel
On Wed, 17 Jun 2015 14:40:39 +0200
Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> As some more information is added to the PCR register, we'd better use
> a copy of its content and modify just the peripheral-related bits.
> Implement a read-modify-write for the enable() and disable() callbacks.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> v2: - modify header file beforehand so that we can use consistent field naming
>
>
> drivers/clk/at91/clk-peripheral.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
> index 61d0adda7088..1e7dcc57925a 100644
> --- a/drivers/clk/at91/clk-peripheral.c
> +++ b/drivers/clk/at91/clk-peripheral.c
> @@ -161,14 +161,18 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
> {
> struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
> struct at91_pmc *pmc = periph->pmc;
> + u32 tmp;
>
> if (periph->id < PERIPHERAL_ID_MIN)
> return 0;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> - AT91_PMC_PCR_CMD |
> - AT91_PMC_PCR_DIV(periph->div) |
> - AT91_PMC_PCR_EN);
> + pmc_lock(pmc);
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> + tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK;
> + pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div)
> + | AT91_PMC_PCR_CMD
> + | AT91_PMC_PCR_EN);
> + pmc_unlock(pmc);
> return 0;
> }
>
> @@ -176,12 +180,16 @@ static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
> {
> struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
> struct at91_pmc *pmc = periph->pmc;
> + u32 tmp;
>
> if (periph->id < PERIPHERAL_ID_MIN)
> return;
>
> - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK) |
> - AT91_PMC_PCR_CMD);
> + pmc_lock(pmc);
> + pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
> + tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN;
> + pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
> + pmc_unlock(pmc);
> }
>
> static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-06-17 14:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-17 12:40 [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields Nicolas Ferre
2015-06-17 12:40 ` Nicolas Ferre
2015-06-17 12:40 ` [PATCH v2 2/2] clk: at91: modify PMC peripheral clock to deal with newer register layout Nicolas Ferre
2015-06-17 12:40 ` Nicolas Ferre
2015-06-17 14:39 ` Boris Brezillon
2015-06-17 14:39 ` Boris Brezillon
2015-06-17 14:37 ` [PATCH v2 1/2] clk: at91: cleanup PMC header file for PCR register fields Boris Brezillon
2015-06-17 14:37 ` Boris Brezillon
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.