[3/8] soc: mediatek: pm-domains: Create bus protection operation functions

Message ID 20230105170735.1637416-4-msp@baylibre.com
State New
Headers
Series soc: mediatek: MT8365 power support |

Commit Message

Markus Schneider-Pargmann Jan. 5, 2023, 5:07 p.m. UTC
  Separate the register access used for bus protection enable/disable into
their own functions. These will be used later for WAY_EN bits.

Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
 drivers/soc/mediatek/mtk-pm-domains.c | 68 +++++++++++++++------------
 1 file changed, 39 insertions(+), 29 deletions(-)
  

Comments

Matthias Brugger Feb. 3, 2023, 12:32 p.m. UTC | #1
On 05/01/2023 18:07, Markus Schneider-Pargmann wrote:
> Separate the register access used for bus protection enable/disable into
> their own functions. These will be used later for WAY_EN bits.
> 
> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> ---
>   drivers/soc/mediatek/mtk-pm-domains.c | 68 +++++++++++++++------------
>   1 file changed, 39 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
> index 4333cd297405..999e1f6c86b0 100644
> --- a/drivers/soc/mediatek/mtk-pm-domains.c
> +++ b/drivers/soc/mediatek/mtk-pm-domains.c
> @@ -117,26 +117,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
>   					MTK_POLL_TIMEOUT);
>   }
>   
> +static int scpsys_bus_protect_clear(const struct scpsys_bus_prot_data *bpd,
> +				    struct regmap *regmap)
> +{
> +	u32 val;
> +	u32 sta_mask = bpd->bus_prot_sta_mask;
> +
> +	if (bpd->bus_prot_reg_update)
> +		regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
> +	else
> +		regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
> +
> +	if (bpd->ignore_clr_ack)
> +		return 0;
> +
> +	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
> +					val, !(val & sta_mask),
> +					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> +}
> +

NIT: please move this function below
static int scpsys_bus_protect_enable(struct scpsys_domain *pd) {...}

This allows for better readability.

> +static int scpsys_bus_protect_set(const struct scpsys_bus_prot_data *bpd,
> +				  struct regmap *regmap)
> +{
> +	u32 val;
> +	u32 sta_mask = bpd->bus_prot_sta_mask;
> +
> +	if (bpd->bus_prot_reg_update)
> +		regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
> +	else
> +		regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
> +
> +	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
> +					val, (val & sta_mask) == sta_mask,
> +					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> +}
> +
>   static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
>   {
>   	int i, ret;
>   
>   	for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
> -		u32 val;
> -		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
> -		u32 sta_mask = bpd[i].bus_prot_sta_mask;
> -
> -		if (!set_clr_mask)
> +		if (!bpd[i].bus_prot_set_clr_mask)
>   			break;
>   
> -		if (bpd[i].bus_prot_reg_update)
> -			regmap_set_bits(regmap, bpd[i].bus_prot_set, set_clr_mask);
> -		else
> -			regmap_write(regmap, bpd[i].bus_prot_set, set_clr_mask);
> -
> -		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> -					       val, (val & sta_mask) == sta_mask,
> -					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> +		ret = scpsys_bus_protect_set(&bpd[i], regmap);
>   		if (ret)
>   			return ret;
>   	}
> @@ -161,24 +185,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
>   	int i, ret;
>   
>   	for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
> -		u32 val;
> -		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
> -		u32 sta_mask = bpd[i].bus_prot_sta_mask;
> -
> -		if (!set_clr_mask)
> -			continue;
> -
> -		if (bpd[i].bus_prot_reg_update)
> -			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, set_clr_mask);
> -		else
> -			regmap_write(regmap, bpd[i].bus_prot_clr, set_clr_mask);
> -
> -		if (bpd[i].ignore_clr_ack)
> +		if (!bpd[i].bus_prot_set_clr_mask)
>   			continue;
>   
> -		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> -					       val, !(val & sta_mask),
> -					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> +		ret = scpsys_bus_protect_clear(&bpd[i], regmap);
>   		if (ret)
>   			return ret;
>   	}
  
Markus Schneider-Pargmann March 13, 2023, 11:49 a.m. UTC | #2
Hi Matthias,

On Fri, Feb 03, 2023 at 01:32:11PM +0100, Matthias Brugger wrote:
> 
> 
> On 05/01/2023 18:07, Markus Schneider-Pargmann wrote:
> > Separate the register access used for bus protection enable/disable into
> > their own functions. These will be used later for WAY_EN bits.
> > 
> > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> > ---
> >   drivers/soc/mediatek/mtk-pm-domains.c | 68 +++++++++++++++------------
> >   1 file changed, 39 insertions(+), 29 deletions(-)
> > 
> > diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
> > index 4333cd297405..999e1f6c86b0 100644
> > --- a/drivers/soc/mediatek/mtk-pm-domains.c
> > +++ b/drivers/soc/mediatek/mtk-pm-domains.c
> > @@ -117,26 +117,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd)
> >   					MTK_POLL_TIMEOUT);
> >   }
> > +static int scpsys_bus_protect_clear(const struct scpsys_bus_prot_data *bpd,
> > +				    struct regmap *regmap)
> > +{
> > +	u32 val;
> > +	u32 sta_mask = bpd->bus_prot_sta_mask;
> > +
> > +	if (bpd->bus_prot_reg_update)
> > +		regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
> > +	else
> > +		regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
> > +
> > +	if (bpd->ignore_clr_ack)
> > +		return 0;
> > +
> > +	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
> > +					val, !(val & sta_mask),
> > +					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> > +}
> > +
> 
> NIT: please move this function below
> static int scpsys_bus_protect_enable(struct scpsys_domain *pd) {...}
> 
> This allows for better readability.

With the WAY_EN patch later in this series scpsys_bus_protect_enable()
is going to use scpsys_bus_protect_clear(). So I would need to add a
signature in that patch for scpsys_bus_protect_clear() or move it back
up. I would prefer to avoid adding a signature or moving so I added it
above these functions here. I could swap scpsys_bus_protect_set() and
scpscpsys_bus_protect_clear() if that helps readability.

Thank you,
Markus

> 
> > +static int scpsys_bus_protect_set(const struct scpsys_bus_prot_data *bpd,
> > +				  struct regmap *regmap)
> > +{
> > +	u32 val;
> > +	u32 sta_mask = bpd->bus_prot_sta_mask;
> > +
> > +	if (bpd->bus_prot_reg_update)
> > +		regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
> > +	else
> > +		regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
> > +
> > +	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
> > +					val, (val & sta_mask) == sta_mask,
> > +					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> > +}
> > +
> >   static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
> >   {
> >   	int i, ret;
> >   	for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
> > -		u32 val;
> > -		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
> > -		u32 sta_mask = bpd[i].bus_prot_sta_mask;
> > -
> > -		if (!set_clr_mask)
> > +		if (!bpd[i].bus_prot_set_clr_mask)
> >   			break;
> > -		if (bpd[i].bus_prot_reg_update)
> > -			regmap_set_bits(regmap, bpd[i].bus_prot_set, set_clr_mask);
> > -		else
> > -			regmap_write(regmap, bpd[i].bus_prot_set, set_clr_mask);
> > -
> > -		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> > -					       val, (val & sta_mask) == sta_mask,
> > -					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> > +		ret = scpsys_bus_protect_set(&bpd[i], regmap);
> >   		if (ret)
> >   			return ret;
> >   	}
> > @@ -161,24 +185,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
> >   	int i, ret;
> >   	for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
> > -		u32 val;
> > -		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
> > -		u32 sta_mask = bpd[i].bus_prot_sta_mask;
> > -
> > -		if (!set_clr_mask)
> > -			continue;
> > -
> > -		if (bpd[i].bus_prot_reg_update)
> > -			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, set_clr_mask);
> > -		else
> > -			regmap_write(regmap, bpd[i].bus_prot_clr, set_clr_mask);
> > -
> > -		if (bpd[i].ignore_clr_ack)
> > +		if (!bpd[i].bus_prot_set_clr_mask)
> >   			continue;
> > -		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> > -					       val, !(val & sta_mask),
> > -					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
> > +		ret = scpsys_bus_protect_clear(&bpd[i], regmap);
> >   		if (ret)
> >   			return ret;
> >   	}
  

Patch

diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
index 4333cd297405..999e1f6c86b0 100644
--- a/drivers/soc/mediatek/mtk-pm-domains.c
+++ b/drivers/soc/mediatek/mtk-pm-domains.c
@@ -117,26 +117,50 @@  static int scpsys_sram_disable(struct scpsys_domain *pd)
 					MTK_POLL_TIMEOUT);
 }
 
+static int scpsys_bus_protect_clear(const struct scpsys_bus_prot_data *bpd,
+				    struct regmap *regmap)
+{
+	u32 val;
+	u32 sta_mask = bpd->bus_prot_sta_mask;
+
+	if (bpd->bus_prot_reg_update)
+		regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
+	else
+		regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask);
+
+	if (bpd->ignore_clr_ack)
+		return 0;
+
+	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
+					val, !(val & sta_mask),
+					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+}
+
+static int scpsys_bus_protect_set(const struct scpsys_bus_prot_data *bpd,
+				  struct regmap *regmap)
+{
+	u32 val;
+	u32 sta_mask = bpd->bus_prot_sta_mask;
+
+	if (bpd->bus_prot_reg_update)
+		regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
+	else
+		regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask);
+
+	return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta,
+					val, (val & sta_mask) == sta_mask,
+					MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+}
+
 static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap)
 {
 	int i, ret;
 
 	for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) {
-		u32 val;
-		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
-		u32 sta_mask = bpd[i].bus_prot_sta_mask;
-
-		if (!set_clr_mask)
+		if (!bpd[i].bus_prot_set_clr_mask)
 			break;
 
-		if (bpd[i].bus_prot_reg_update)
-			regmap_set_bits(regmap, bpd[i].bus_prot_set, set_clr_mask);
-		else
-			regmap_write(regmap, bpd[i].bus_prot_set, set_clr_mask);
-
-		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
-					       val, (val & sta_mask) == sta_mask,
-					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+		ret = scpsys_bus_protect_set(&bpd[i], regmap);
 		if (ret)
 			return ret;
 	}
@@ -161,24 +185,10 @@  static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
 	int i, ret;
 
 	for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) {
-		u32 val;
-		u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask;
-		u32 sta_mask = bpd[i].bus_prot_sta_mask;
-
-		if (!set_clr_mask)
-			continue;
-
-		if (bpd[i].bus_prot_reg_update)
-			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, set_clr_mask);
-		else
-			regmap_write(regmap, bpd[i].bus_prot_clr, set_clr_mask);
-
-		if (bpd[i].ignore_clr_ack)
+		if (!bpd[i].bus_prot_set_clr_mask)
 			continue;
 
-		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
-					       val, !(val & sta_mask),
-					       MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
+		ret = scpsys_bus_protect_clear(&bpd[i], regmap);
 		if (ret)
 			return ret;
 	}