Skip to contentSkip to conversation

clk: shrink struct clk_fractional_divider

PATCH Applied Christophe JAILLET 4 participants 14 messages Apr 2, 2023 – Apr 5, 2023

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

v2 cover clk: shrink struct clk_fractional_divider

This serie removes 2 fields from struct clk_fractional_divider and shrinks it from 72 to 56 bytes.

Instead of been pre-computed, thse fields are now computed when needed.

The first patch makes the [mn]mask fields useless.
Patch 2 and 3 make some needed modification in 2 drivers that where using these fields.
Finally, patch 4 removes the now used fields.

This is a another approach of what was proposed in v1. (i.e. just moving a field to shrink from 72 ro 64 bytes)

Compared to v1, all 4 patches are new.

v1:
https://lore.kernel.org/linux-kernel/d1874eb8848d5f97f87337011188640a1463a666.1676649335.git.christophe.jaillet@wanadoo.fr/

Christophe JAILLET (4):
clk: Compute masks for fractional_divider clk when needed.
clk: imx: Remove values for mmask and nmask in struct
clk_fractional_divider
clk: rockchip: Remove values for mmask and nmask in struct
clk_fractional_divider
clk: Remove mmask and nmask fields in struct clk_fractional_divider

 drivers/clk/clk-fractional-divider.c | 16 +++++++++++-----
 drivers/clk/imx/clk-composite-7ulp.c |  4 ----
 drivers/clk/rockchip/clk.c           |  2 --
 include/linux/clk-provider.h         |  2 --
 4 files changed, 11 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/4 clk: Compute masks for fractional_divider clk when needed.

There is no real need to pre-compute mmask and nmask when handling fractional_divider clk.

They can be computed when needed.

---
 drivers/clk/clk-fractional-divider.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/clk/clk-fractional-divider.c +11 -5
index 6affe3565025..479297763e70 100644
@@ -71,6 +71,7 @@ static void clk_fd_get_div(struct clk_hw *hw, struct u32_fract *fract)
 	struct clk_fractional_divider *fd = to_clk_fd(hw);
 	unsigned long flags = 0;
 	unsigned long m, n;
+	u32 mmask, nmask;
 	u32 val;
 
 	if (fd->lock)
@@ -85,8 +86,11 @@ static void clk_fd_get_div(struct clk_hw *hw, struct u32_fract *fract)
 	else
 		__release(fd->lock);
 
-	m = (val & fd->mmask) >> fd->mshift;
-	n = (val & fd->nmask) >> fd->nshift;
+	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
+	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
+
+	m = (val & mmask) >> fd->mshift;
+	n = (val & nmask) >> fd->nshift;
 
 	if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) {
 		m++;
@@ -166,6 +170,7 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
 	struct clk_fractional_divider *fd = to_clk_fd(hw);
 	unsigned long flags = 0;
 	unsigned long m, n;
+	u32 mmask, nmask;
 	u32 val;
 
 	rational_best_approximation(rate, parent_rate,
@@ -182,8 +187,11 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
 	else
 		__acquire(fd->lock);
 
+	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
+	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
+
 	val = clk_fd_readl(fd);
-	val &= ~(fd->mmask | fd->nmask);
+	val &= ~(mmask | nmask);
 	val |= (m << fd->mshift) | (n << fd->nshift);
 	clk_fd_writel(fd, val);
 
@@ -260,10 +268,8 @@ struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
 	fd->reg = reg;
 	fd->mshift = mshift;
 	fd->mwidth = mwidth;
-	fd->mmask = GENMASK(mwidth - 1, 0) << mshift;
 	fd->nshift = nshift;
 	fd->nwidth = nwidth;
-	fd->nmask = GENMASK(nwidth - 1, 0) << nshift;
 	fd->flags = clk_divider_flags;
 	fd->lock = lock;
 	fd->hw.init = &init;
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 2/4 clk: imx: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

---
 drivers/clk/imx/clk-composite-7ulp.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/clk/imx/clk-composite-7ulp.c +0 -4
index 4eedd45dbaa8..e208ddc51133 100644
@@ -19,10 +19,8 @@
 #define PCG_CGC_SHIFT	30
 #define PCG_FRAC_SHIFT	3
 #define PCG_FRAC_WIDTH	1
-#define PCG_FRAC_MASK	BIT(3)
 #define PCG_PCD_SHIFT	0
 #define PCG_PCD_WIDTH	3
-#define PCG_PCD_MASK	0x7
 
 #define SW_RST		BIT(28)
 
@@ -102,10 +100,8 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name,
 		fd->reg = reg;
 		fd->mshift = PCG_FRAC_SHIFT;
 		fd->mwidth = PCG_FRAC_WIDTH;
-		fd->mmask  = PCG_FRAC_MASK;
 		fd->nshift = PCG_PCD_SHIFT;
 		fd->nwidth = PCG_PCD_WIDTH;
-		fd->nmask = PCG_PCD_MASK;
 		fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
 		if (has_swrst)
 			fd->lock = &imx_ccm_lock;
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 3/4 clk: rockchip: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

---
 drivers/clk/rockchip/clk.c | 2 --
 1 file changed, 2 deletions(-)
drivers/clk/rockchip/clk.c +0 -2
index a8646794575a..4059d9365ae6 100644
@@ -244,10 +244,8 @@ static struct clk *rockchip_clk_register_frac_branch(
 	div->reg = base + muxdiv_offset;
 	div->mshift = 16;
 	div->mwidth = 16;
-	div->mmask = GENMASK(div->mwidth - 1, 0) << div->mshift;
 	div->nshift = 0;
 	div->nwidth = 16;
-	div->nmask = GENMASK(div->nwidth - 1, 0) << div->nshift;
 	div->lock = lock;
 	div->approximation = rockchip_fractional_approximation;
 	div_ops = &clk_fractional_divider_ops;
Signature · 1 line
2.34.1
#11 lore raw

PATCH v2 4/4 clk: Remove mmask and nmask fields in struct clk_fractional_divider

In reply to Christophe JAILLET

All users of these fields have been removed.
They are now computed when needed with [mn]shift and [mn]width.

This shrinks the size of struct clk_fractional_divider from 72 to 56 bytes.

---
 include/linux/clk-provider.h | 2 --
 1 file changed, 2 deletions(-)
include/linux/clk-provider.h +0 -2
index faad3cdc1e48..eb6930ae550f 100644
@@ -1154,10 +1154,8 @@ struct clk_fractional_divider {
 	void __iomem	*reg;
 	u8		mshift;
 	u8		mwidth;
-	u32		mmask;
 	u8		nshift;
 	u8		nwidth;
-	u32		nmask;
 	u8		flags;
 	void		(*approximation)(struct clk_hw *hw,
 				unsigned long rate, unsigned long *parent_rate,
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH v2 1/4] clk: Compute masks for fractional_divider clk when needed.

In reply to Christophe JAILLET

Am Sonntag, 2. April 2023, 11:42:04 CEST schrieb Christophe JAILLET:

Quoted 6 lines

There is no real need to pre-compute mmask and nmask when handling fractional_divider clk.

They can be computed when needed.

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer Reviewed-by on v2 3/4
#9 lore raw

Re: [PATCH v2 3/4] clk: rockchip: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET

Am Sonntag, 2. April 2023, 11:42:06 CEST schrieb Christophe JAILLET:

Quoted 4 lines

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

maintainer Reviewed-by on v2 4/4
#12 lore raw

Re: [PATCH v2 4/4] clk: Remove mmask and nmask fields in struct clk_fractional_divider

In reply to Christophe JAILLET

Am Sonntag, 2. April 2023, 11:42:07 CEST schrieb Christophe JAILLET:

Quoted 6 lines

All users of these fields have been removed.
They are now computed when needed with [mn]shift and [mn]width.

This shrinks the size of struct clk_fractional_divider from 72 to 56 bytes.

Reviewed-by on v2 2/4
#6 lore raw

Re: [PATCH v2 2/4] clk: imx: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET
Quoted 4 lines · Christophe JAILLET

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

Quoted 33 lines
---
 drivers/clk/imx/clk-composite-7ulp.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/clk/imx/clk-composite-7ulp.c +0 -4
index 4eedd45dbaa8..e208ddc51133 100644
@@ -19,10 +19,8 @@
 #define PCG_CGC_SHIFT	30
 #define PCG_FRAC_SHIFT	3
 #define PCG_FRAC_WIDTH	1
-#define PCG_FRAC_MASK	BIT(3)
 #define PCG_PCD_SHIFT	0
 #define PCG_PCD_WIDTH	3
-#define PCG_PCD_MASK	0x7
 
 #define SW_RST		BIT(28)
 
@@ -102,10 +100,8 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name,
 		fd->reg = reg;
 		fd->mshift = PCG_FRAC_SHIFT;
 		fd->mwidth = PCG_FRAC_WIDTH;
-		fd->mmask  = PCG_FRAC_MASK;
 		fd->nshift = PCG_PCD_SHIFT;
 		fd->nwidth = PCG_PCD_WIDTH;
-		fd->nmask = PCG_PCD_MASK;
 		fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
 		if (has_swrst)
 			fd->lock = &imx_ccm_lock;
Signature · 1 line
2.34.1
maintainer Applied
#13 lore raw

Re: [PATCH v2 4/4] clk: Remove mmask and nmask fields in struct clk_fractional_divider

In reply to Christophe JAILLET

Quoting Christophe JAILLET (2023-04-02 02:42:07)

Quoted 7 lines

All users of these fields have been removed.
They are now computed when needed with [mn]shift and [mn]width.

This shrinks the size of struct clk_fractional_divider from 72 to 56 bytes.

---

Applied to clk-next

maintainer Applied
#10 lore raw

Re: [PATCH v2 3/4] clk: rockchip: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET

Quoting Christophe JAILLET (2023-04-02 02:42:06)

Quoted 5 lines

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

---

Applied to clk-next

maintainer Applied
#7 lore raw

Re: [PATCH v2 2/4] clk: imx: Remove values for mmask and nmask in struct clk_fractional_divider

In reply to Christophe JAILLET

Quoting Christophe JAILLET (2023-04-02 02:42:05)

Quoted 5 lines

Now that fractional_divider clk computes mmask and nmask when needed, there is no more need to provide them explicitly anymore.

---

Applied to clk-next