diff mbox series

[v5,2/8] soc: mediatek: pm-domains: Move bools to a flags field

Message ID 20230619085344.2885311-3-msp@baylibre.com (mailing list archive)
State New, archived
Headers show
Series soc: mediatek: MT8365 power support | expand

Commit Message

Markus Schneider-Pargmann June 19, 2023, 8:53 a.m. UTC
To simplify the macros, use a flags field for simple bools. This is in
preparation for more flags.

Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
 drivers/soc/mediatek/mtk-pm-domains.c |  6 +++---
 drivers/soc/mediatek/mtk-pm-domains.h | 19 +++++++++++--------
 2 files changed, 14 insertions(+), 11 deletions(-)

Comments

AngeloGioacchino Del Regno June 19, 2023, 9:32 a.m. UTC | #1
Il 19/06/23 10:53, Markus Schneider-Pargmann ha scritto:
> To simplify the macros, use a flags field for simple bools. This is in
> preparation for more flags.
> 
> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> ---
>   drivers/soc/mediatek/mtk-pm-domains.c |  6 +++---
>   drivers/soc/mediatek/mtk-pm-domains.h | 19 +++++++++++--------
>   2 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
> index 354249cc1b12..aa9ab413479e 100644
> --- a/drivers/soc/mediatek/mtk-pm-domains.c
> +++ b/drivers/soc/mediatek/mtk-pm-domains.c
> @@ -128,7 +128,7 @@ static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, st
>   		if (!mask)
>   			break;
>   
> -		if (bpd[i].bus_prot_reg_update)
> +		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
>   			regmap_set_bits(regmap, bpd[i].bus_prot_set, mask);
>   		else
>   			regmap_write(regmap, bpd[i].bus_prot_set, mask);
> @@ -165,12 +165,12 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
>   		if (!mask)
>   			continue;
>   
> -		if (bpd[i].bus_prot_reg_update)
> +		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
>   			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, mask);
>   		else
>   			regmap_write(regmap, bpd[i].bus_prot_clr, mask);
>   
> -		if (bpd[i].ignore_clr_ack)
> +		if (bpd[i].flags & BUS_PROT_IGNORE_CLR_ACK)
>   			continue;
>   
>   		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h
> index 5ec53ee073c4..e26c8c317a6b 100644
> --- a/drivers/soc/mediatek/mtk-pm-domains.h
> +++ b/drivers/soc/mediatek/mtk-pm-domains.h
> @@ -42,23 +42,27 @@
>   
>   #define SPM_MAX_BUS_PROT_DATA		6
>   
> -#define _BUS_PROT(_mask, _set, _clr, _sta, _update, _ignore) {	\
> +enum scpsys_bus_prot_flags {
> +	BUS_PROT_REG_UPDATE = BIT(1),
> +	BUS_PROT_IGNORE_CLR_ACK = BIT(2),
> +};
> +
> +#define _BUS_PROT(_mask, _set, _clr, _sta, _flags) {		\
>   		.bus_prot_mask = (_mask),			\
>   		.bus_prot_set = _set,				\
>   		.bus_prot_clr = _clr,				\
>   		.bus_prot_sta = _sta,				\
> -		.bus_prot_reg_update = _update,			\
> -		.ignore_clr_ack = _ignore,			\
> +		.flags = _flags					\
>   	}
>   
>   #define BUS_PROT_WR(_mask, _set, _clr, _sta)			\
> -		_BUS_PROT(_mask, _set, _clr, _sta, false, false)
> +		_BUS_PROT(_mask, _set, _clr, _sta, 0)
>   
>   #define BUS_PROT_WR_IGN(_mask, _set, _clr, _sta)		\
> -		_BUS_PROT(_mask, _set, _clr, _sta, false, true)
> +		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_IGNORE_CLR_ACK)
>   
>   #define BUS_PROT_UPDATE(_mask, _set, _clr, _sta)		\
> -		_BUS_PROT(_mask, _set, _clr, _sta, true, false)
> +		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_REG_UPDATE)
>   
>   #define BUS_PROT_UPDATE_TOPAXI(_mask)				\
>   		BUS_PROT_UPDATE(_mask,				\
> @@ -71,8 +75,7 @@ struct scpsys_bus_prot_data {
>   	u32 bus_prot_set;
>   	u32 bus_prot_clr;
>   	u32 bus_prot_sta;
> -	bool bus_prot_reg_update;
> -	bool ignore_clr_ack;
> +	u32 flags;

As far as I understand, we don't expect more than six bits to be populated as bus
protection flags, so we can save some memory by changing that to u8...

...after which:

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Regards,
Angelo
Markus Schneider-Pargmann June 22, 2023, 8:28 a.m. UTC | #2
Hi Angelo,

On Mon, Jun 19, 2023 at 11:32:18AM +0200, AngeloGioacchino Del Regno wrote:
> Il 19/06/23 10:53, Markus Schneider-Pargmann ha scritto:
> > To simplify the macros, use a flags field for simple bools. This is in
> > preparation for more flags.
> > 
> > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> > ---
> >   drivers/soc/mediatek/mtk-pm-domains.c |  6 +++---
> >   drivers/soc/mediatek/mtk-pm-domains.h | 19 +++++++++++--------
> >   2 files changed, 14 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
> > index 354249cc1b12..aa9ab413479e 100644
> > --- a/drivers/soc/mediatek/mtk-pm-domains.c
> > +++ b/drivers/soc/mediatek/mtk-pm-domains.c
> > @@ -128,7 +128,7 @@ static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, st
> >   		if (!mask)
> >   			break;
> > -		if (bpd[i].bus_prot_reg_update)
> > +		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
> >   			regmap_set_bits(regmap, bpd[i].bus_prot_set, mask);
> >   		else
> >   			regmap_write(regmap, bpd[i].bus_prot_set, mask);
> > @@ -165,12 +165,12 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
> >   		if (!mask)
> >   			continue;
> > -		if (bpd[i].bus_prot_reg_update)
> > +		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
> >   			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, mask);
> >   		else
> >   			regmap_write(regmap, bpd[i].bus_prot_clr, mask);
> > -		if (bpd[i].ignore_clr_ack)
> > +		if (bpd[i].flags & BUS_PROT_IGNORE_CLR_ACK)
> >   			continue;
> >   		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
> > diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h
> > index 5ec53ee073c4..e26c8c317a6b 100644
> > --- a/drivers/soc/mediatek/mtk-pm-domains.h
> > +++ b/drivers/soc/mediatek/mtk-pm-domains.h
> > @@ -42,23 +42,27 @@
> >   #define SPM_MAX_BUS_PROT_DATA		6
> > -#define _BUS_PROT(_mask, _set, _clr, _sta, _update, _ignore) {	\
> > +enum scpsys_bus_prot_flags {
> > +	BUS_PROT_REG_UPDATE = BIT(1),
> > +	BUS_PROT_IGNORE_CLR_ACK = BIT(2),
> > +};
> > +
> > +#define _BUS_PROT(_mask, _set, _clr, _sta, _flags) {		\
> >   		.bus_prot_mask = (_mask),			\
> >   		.bus_prot_set = _set,				\
> >   		.bus_prot_clr = _clr,				\
> >   		.bus_prot_sta = _sta,				\
> > -		.bus_prot_reg_update = _update,			\
> > -		.ignore_clr_ack = _ignore,			\
> > +		.flags = _flags					\
> >   	}
> >   #define BUS_PROT_WR(_mask, _set, _clr, _sta)			\
> > -		_BUS_PROT(_mask, _set, _clr, _sta, false, false)
> > +		_BUS_PROT(_mask, _set, _clr, _sta, 0)
> >   #define BUS_PROT_WR_IGN(_mask, _set, _clr, _sta)		\
> > -		_BUS_PROT(_mask, _set, _clr, _sta, false, true)
> > +		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_IGNORE_CLR_ACK)
> >   #define BUS_PROT_UPDATE(_mask, _set, _clr, _sta)		\
> > -		_BUS_PROT(_mask, _set, _clr, _sta, true, false)
> > +		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_REG_UPDATE)
> >   #define BUS_PROT_UPDATE_TOPAXI(_mask)				\
> >   		BUS_PROT_UPDATE(_mask,				\
> > @@ -71,8 +75,7 @@ struct scpsys_bus_prot_data {
> >   	u32 bus_prot_set;
> >   	u32 bus_prot_clr;
> >   	u32 bus_prot_sta;
> > -	bool bus_prot_reg_update;
> > -	bool ignore_clr_ack;
> > +	u32 flags;
> 
> As far as I understand, we don't expect more than six bits to be populated as bus
> protection flags, so we can save some memory by changing that to u8...

Thank you. Yes, also we can change it later if we need more flags at
some point. I will change it. But I guess it won't save any memory as
the compiler probably aligns the struct.

Best,
Markus

> 
> ...after which:
> 
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> 
> Regards,
> Angelo
diff mbox series

Patch

diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
index 354249cc1b12..aa9ab413479e 100644
--- a/drivers/soc/mediatek/mtk-pm-domains.c
+++ b/drivers/soc/mediatek/mtk-pm-domains.c
@@ -128,7 +128,7 @@  static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, st
 		if (!mask)
 			break;
 
-		if (bpd[i].bus_prot_reg_update)
+		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
 			regmap_set_bits(regmap, bpd[i].bus_prot_set, mask);
 		else
 			regmap_write(regmap, bpd[i].bus_prot_set, mask);
@@ -165,12 +165,12 @@  static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd,
 		if (!mask)
 			continue;
 
-		if (bpd[i].bus_prot_reg_update)
+		if (bpd[i].flags & BUS_PROT_REG_UPDATE)
 			regmap_clear_bits(regmap, bpd[i].bus_prot_clr, mask);
 		else
 			regmap_write(regmap, bpd[i].bus_prot_clr, mask);
 
-		if (bpd[i].ignore_clr_ack)
+		if (bpd[i].flags & BUS_PROT_IGNORE_CLR_ACK)
 			continue;
 
 		ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta,
diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h
index 5ec53ee073c4..e26c8c317a6b 100644
--- a/drivers/soc/mediatek/mtk-pm-domains.h
+++ b/drivers/soc/mediatek/mtk-pm-domains.h
@@ -42,23 +42,27 @@ 
 
 #define SPM_MAX_BUS_PROT_DATA		6
 
-#define _BUS_PROT(_mask, _set, _clr, _sta, _update, _ignore) {	\
+enum scpsys_bus_prot_flags {
+	BUS_PROT_REG_UPDATE = BIT(1),
+	BUS_PROT_IGNORE_CLR_ACK = BIT(2),
+};
+
+#define _BUS_PROT(_mask, _set, _clr, _sta, _flags) {		\
 		.bus_prot_mask = (_mask),			\
 		.bus_prot_set = _set,				\
 		.bus_prot_clr = _clr,				\
 		.bus_prot_sta = _sta,				\
-		.bus_prot_reg_update = _update,			\
-		.ignore_clr_ack = _ignore,			\
+		.flags = _flags					\
 	}
 
 #define BUS_PROT_WR(_mask, _set, _clr, _sta)			\
-		_BUS_PROT(_mask, _set, _clr, _sta, false, false)
+		_BUS_PROT(_mask, _set, _clr, _sta, 0)
 
 #define BUS_PROT_WR_IGN(_mask, _set, _clr, _sta)		\
-		_BUS_PROT(_mask, _set, _clr, _sta, false, true)
+		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_IGNORE_CLR_ACK)
 
 #define BUS_PROT_UPDATE(_mask, _set, _clr, _sta)		\
-		_BUS_PROT(_mask, _set, _clr, _sta, true, false)
+		_BUS_PROT(_mask, _set, _clr, _sta, BUS_PROT_REG_UPDATE)
 
 #define BUS_PROT_UPDATE_TOPAXI(_mask)				\
 		BUS_PROT_UPDATE(_mask,				\
@@ -71,8 +75,7 @@  struct scpsys_bus_prot_data {
 	u32 bus_prot_set;
 	u32 bus_prot_clr;
 	u32 bus_prot_sta;
-	bool bus_prot_reg_update;
-	bool ignore_clr_ack;
+	u32 flags;
 };
 
 /**