All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup
@ 2022-05-09  5:29 Samuel Holland
  2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
                   ` (9 more replies)
  0 siblings, 10 replies; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

This series fixes an issue with out-of-bounds access to the gate array
(patches 1-2), uses the rearranged array size information to remove a
bunch of duplicate code (patches 3-4), and then simplifies how the reset
driver is bound (patches 5-7).

The original motivation for these changes was adding a driver for the
legacy A31/A23/A33 PRCM binding (which I will send separately), and
trying to use OF_PLATDATA in SPL (which did not work out). But I think
at least some of the cleanup is worth applying on its own.

Patch 4 is generally the same change I made between v1 and v2 of the
pinctrl series, using some #ifdefs to share a U_BOOT_DRIVER. It's not
quite as clean as the pinctrl case, because here the SoC-specific parts
are in different files, so all of the CCU descriptors have to be global.


Samuel Holland (7):
  clk: sunxi: Store the array sizes in the CCU descriptor
  clk: sunxi: Prevent out-of-bounds gate array access
  reset: sunxi: Get the reset count from the CCU descriptor
  clk: sunxi: Use a single driver for all variants
  clk: sunxi: Convert driver private data to platform data
  reset: sunxi: Convert driver private data to platform data
  reset: sunxi: Reuse the platform data from the clock driver

 drivers/clk/sunxi/clk_a10.c   |  27 +-----
 drivers/clk/sunxi/clk_a10s.c  |  27 +-----
 drivers/clk/sunxi/clk_a23.c   |  27 +-----
 drivers/clk/sunxi/clk_a31.c   |  25 +----
 drivers/clk/sunxi/clk_a31_r.c |  29 +-----
 drivers/clk/sunxi/clk_a64.c   |  25 +----
 drivers/clk/sunxi/clk_a80.c   |  36 ++------
 drivers/clk/sunxi/clk_a83t.c  |  25 +----
 drivers/clk/sunxi/clk_h3.c    |  27 +-----
 drivers/clk/sunxi/clk_h6.c    |  25 +----
 drivers/clk/sunxi/clk_h616.c  |  25 +----
 drivers/clk/sunxi/clk_h6_r.c  |  27 +-----
 drivers/clk/sunxi/clk_r40.c   |  25 +----
 drivers/clk/sunxi/clk_sunxi.c | 168 ++++++++++++++++++++++++++++++----
 drivers/clk/sunxi/clk_v3s.c   |  27 +-----
 drivers/reset/reset-sunxi.c   |  55 ++---------
 include/clk/sunxi.h           |  21 +----
 17 files changed, 208 insertions(+), 413 deletions(-)

-- 
2.35.1


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

* [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-25 17:10   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access Samuel Holland
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

The reset array size is currently used for bounds checking in the reset
driver. The same bounds check should really be done in the clock driver.

Currently, the array size is provided to the reset driver separately
from the CCU descriptor, which is a bit strange. Let's do this the usual
way, with the array sizes next to the arrays themselves.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_a10.c   | 2 ++
 drivers/clk/sunxi/clk_a10s.c  | 2 ++
 drivers/clk/sunxi/clk_a23.c   | 2 ++
 drivers/clk/sunxi/clk_a31.c   | 2 ++
 drivers/clk/sunxi/clk_a31_r.c | 2 ++
 drivers/clk/sunxi/clk_a64.c   | 2 ++
 drivers/clk/sunxi/clk_a80.c   | 4 ++++
 drivers/clk/sunxi/clk_a83t.c  | 2 ++
 drivers/clk/sunxi/clk_h3.c    | 2 ++
 drivers/clk/sunxi/clk_h6.c    | 2 ++
 drivers/clk/sunxi/clk_h616.c  | 2 ++
 drivers/clk/sunxi/clk_h6_r.c  | 2 ++
 drivers/clk/sunxi/clk_r40.c   | 2 ++
 drivers/clk/sunxi/clk_v3s.c   | 2 ++
 include/clk/sunxi.h           | 2 ++
 15 files changed, 32 insertions(+)

diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
index 90b929d3d3..6b58cffc8a 100644
--- a/drivers/clk/sunxi/clk_a10.c
+++ b/drivers/clk/sunxi/clk_a10.c
@@ -65,6 +65,8 @@ static struct ccu_reset a10_resets[] = {
 static const struct ccu_desc a10_ccu_desc = {
 	.gates = a10_gates,
 	.resets = a10_resets,
+	.num_gates = ARRAY_SIZE(a10_gates),
+	.num_resets = ARRAY_SIZE(a10_resets),
 };
 
 static int a10_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
index addf4f4d5c..81b146ce1e 100644
--- a/drivers/clk/sunxi/clk_a10s.c
+++ b/drivers/clk/sunxi/clk_a10s.c
@@ -50,6 +50,8 @@ static struct ccu_reset a10s_resets[] = {
 static const struct ccu_desc a10s_ccu_desc = {
 	.gates = a10s_gates,
 	.resets = a10s_resets,
+	.num_gates = ARRAY_SIZE(a10s_gates),
+	.num_resets = ARRAY_SIZE(a10s_resets),
 };
 
 static int a10s_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
index c45d2c3529..c7c78bc7d8 100644
--- a/drivers/clk/sunxi/clk_a23.c
+++ b/drivers/clk/sunxi/clk_a23.c
@@ -69,6 +69,8 @@ static struct ccu_reset a23_resets[] = {
 static const struct ccu_desc a23_ccu_desc = {
 	.gates = a23_gates,
 	.resets = a23_resets,
+	.num_gates = ARRAY_SIZE(a23_gates),
+	.num_resets = ARRAY_SIZE(a23_resets),
 };
 
 static int a23_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
index 251fc3b705..c8c7f4ecf5 100644
--- a/drivers/clk/sunxi/clk_a31.c
+++ b/drivers/clk/sunxi/clk_a31.c
@@ -90,6 +90,8 @@ static struct ccu_reset a31_resets[] = {
 static const struct ccu_desc a31_ccu_desc = {
 	.gates = a31_gates,
 	.resets = a31_resets,
+	.num_gates = ARRAY_SIZE(a31_gates),
+	.num_resets = ARRAY_SIZE(a31_resets),
 };
 
 static int a31_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
index 1f08ea956f..7bf1c4578c 100644
--- a/drivers/clk/sunxi/clk_a31_r.c
+++ b/drivers/clk/sunxi/clk_a31_r.c
@@ -31,6 +31,8 @@ static struct ccu_reset a31_r_resets[] = {
 static const struct ccu_desc a31_r_ccu_desc = {
 	.gates = a31_r_gates,
 	.resets = a31_r_resets,
+	.num_gates = ARRAY_SIZE(a31_r_gates),
+	.num_resets = ARRAY_SIZE(a31_r_resets),
 };
 
 static int a31_r_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
index 1004a79503..6da861ddc1 100644
--- a/drivers/clk/sunxi/clk_a64.c
+++ b/drivers/clk/sunxi/clk_a64.c
@@ -76,6 +76,8 @@ static const struct ccu_reset a64_resets[] = {
 static const struct ccu_desc a64_ccu_desc = {
 	.gates = a64_gates,
 	.resets = a64_resets,
+	.num_gates = ARRAY_SIZE(a64_gates),
+	.num_resets = ARRAY_SIZE(a64_resets),
 };
 
 static int a64_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
index 8a0834d83a..7025d3cbe6 100644
--- a/drivers/clk/sunxi/clk_a80.c
+++ b/drivers/clk/sunxi/clk_a80.c
@@ -75,11 +75,15 @@ static const struct ccu_reset a80_mmc_resets[] = {
 static const struct ccu_desc a80_ccu_desc = {
 	.gates = a80_gates,
 	.resets = a80_resets,
+	.num_gates = ARRAY_SIZE(a80_gates),
+	.num_resets = ARRAY_SIZE(a80_resets),
 };
 
 static const struct ccu_desc a80_mmc_clk_desc = {
 	.gates = a80_mmc_gates,
 	.resets = a80_mmc_resets,
+	.num_gates = ARRAY_SIZE(a80_mmc_gates),
+	.num_resets = ARRAY_SIZE(a80_mmc_resets),
 };
 
 static int a80_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
index 8c6043f51e..c50d253f84 100644
--- a/drivers/clk/sunxi/clk_a83t.c
+++ b/drivers/clk/sunxi/clk_a83t.c
@@ -73,6 +73,8 @@ static struct ccu_reset a83t_resets[] = {
 static const struct ccu_desc a83t_ccu_desc = {
 	.gates = a83t_gates,
 	.resets = a83t_resets,
+	.num_gates = ARRAY_SIZE(a83t_gates),
+	.num_resets = ARRAY_SIZE(a83t_resets),
 };
 
 static int a83t_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
index 59afba53ee..22c2b236a8 100644
--- a/drivers/clk/sunxi/clk_h3.c
+++ b/drivers/clk/sunxi/clk_h3.c
@@ -89,6 +89,8 @@ static struct ccu_reset h3_resets[] = {
 static const struct ccu_desc h3_ccu_desc = {
 	.gates = h3_gates,
 	.resets = h3_resets,
+	.num_gates = ARRAY_SIZE(h3_gates),
+	.num_resets = ARRAY_SIZE(h3_resets),
 };
 
 static int h3_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
index 4a53788352..6521811215 100644
--- a/drivers/clk/sunxi/clk_h6.c
+++ b/drivers/clk/sunxi/clk_h6.c
@@ -90,6 +90,8 @@ static struct ccu_reset h6_resets[] = {
 static const struct ccu_desc h6_ccu_desc = {
 	.gates = h6_gates,
 	.resets = h6_resets,
+	.num_gates = ARRAY_SIZE(h6_gates),
+	.num_resets = ARRAY_SIZE(h6_resets),
 };
 
 static int h6_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
index af97d3bb9f..26f74c0fa0 100644
--- a/drivers/clk/sunxi/clk_h616.c
+++ b/drivers/clk/sunxi/clk_h616.c
@@ -108,6 +108,8 @@ static struct ccu_reset h616_resets[] = {
 static const struct ccu_desc h616_ccu_desc = {
 	.gates = h616_gates,
 	.resets = h616_resets,
+	.num_gates = ARRAY_SIZE(h616_gates),
+	.num_resets = ARRAY_SIZE(h616_resets),
 };
 
 static int h616_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
index b9e527e16a..fee9604551 100644
--- a/drivers/clk/sunxi/clk_h6_r.c
+++ b/drivers/clk/sunxi/clk_h6_r.c
@@ -35,6 +35,8 @@ static struct ccu_reset h6_r_resets[] = {
 static const struct ccu_desc h6_r_ccu_desc = {
 	.gates = h6_r_gates,
 	.resets = h6_r_resets,
+	.num_gates = ARRAY_SIZE(h6_r_gates),
+	.num_resets = ARRAY_SIZE(h6_r_resets),
 };
 
 static int h6_r_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
index 4d5b69a976..456a38a159 100644
--- a/drivers/clk/sunxi/clk_r40.c
+++ b/drivers/clk/sunxi/clk_r40.c
@@ -100,6 +100,8 @@ static struct ccu_reset r40_resets[] = {
 static const struct ccu_desc r40_ccu_desc = {
 	.gates = r40_gates,
 	.resets = r40_resets,
+	.num_gates = ARRAY_SIZE(r40_gates),
+	.num_resets = ARRAY_SIZE(r40_resets),
 };
 
 static int r40_clk_bind(struct udevice *dev)
diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
index cce5c658ca..ab21cd791b 100644
--- a/drivers/clk/sunxi/clk_v3s.c
+++ b/drivers/clk/sunxi/clk_v3s.c
@@ -50,6 +50,8 @@ static struct ccu_reset v3s_resets[] = {
 static const struct ccu_desc v3s_ccu_desc = {
 	.gates = v3s_gates,
 	.resets = v3s_resets,
+	.num_gates = ARRAY_SIZE(v3s_gates),
+	.num_resets = ARRAY_SIZE(v3s_resets),
 };
 
 static int v3s_clk_bind(struct udevice *dev)
diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
index a2239b990b..5471b9c831 100644
--- a/include/clk/sunxi.h
+++ b/include/clk/sunxi.h
@@ -65,6 +65,8 @@ struct ccu_reset {
 struct ccu_desc {
 	const struct ccu_clk_gate *gates;
 	const struct ccu_reset *resets;
+	u8 num_gates;
+	u8 num_resets;
 };
 
 /**
-- 
2.35.1


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

* [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
  2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-26 10:43   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor Samuel Holland
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

Because the gate arrays are not given explicit sizes, the arrays are
only as large as the highest-numbered gate described in the driver.
However, only a subset of the CCU clocks are needed by U-Boot. So there
are valid clock specifiers with indexes greater than the size of the
arrays. Referencing any of these clocks causes out-of-bounds access.
Fix this by checking the identifier against the size of the array.

Fixes: 0d47bc705651 ("clk: Add Allwinner A64 CLK driver")
Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_sunxi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
index 9673b58a49..3108e5b66d 100644
--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -18,6 +18,9 @@
 static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
 					       unsigned long id)
 {
+	if (id >= priv->desc->num_gates)
+		return NULL;
+
 	return &priv->desc->gates[id];
 }
 
@@ -27,7 +30,7 @@ static int sunxi_set_gate(struct clk *clk, bool on)
 	const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
 	u32 reg;
 
-	if (!(gate->flags & CCU_CLK_F_IS_VALID)) {
+	if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
 		printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id);
 		return 0;
 	}
-- 
2.35.1


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

* [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
  2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
  2022-05-09  5:29 ` [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-26 10:51   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 4/7] clk: sunxi: Use a single driver for all variants Samuel Holland
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

This allows all of the clock drivers to use a common bind function.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_a10.c   |  7 +------
 drivers/clk/sunxi/clk_a10s.c  |  7 +------
 drivers/clk/sunxi/clk_a23.c   |  7 +------
 drivers/clk/sunxi/clk_a31.c   |  7 +------
 drivers/clk/sunxi/clk_a31_r.c |  7 +------
 drivers/clk/sunxi/clk_a64.c   |  7 +------
 drivers/clk/sunxi/clk_a80.c   | 12 +-----------
 drivers/clk/sunxi/clk_a83t.c  |  7 +------
 drivers/clk/sunxi/clk_h3.c    |  7 +------
 drivers/clk/sunxi/clk_h6.c    |  7 +------
 drivers/clk/sunxi/clk_h616.c  |  7 +------
 drivers/clk/sunxi/clk_h6_r.c  |  7 +------
 drivers/clk/sunxi/clk_r40.c   |  7 +------
 drivers/clk/sunxi/clk_sunxi.c |  5 +++++
 drivers/clk/sunxi/clk_v3s.c   |  7 +------
 drivers/reset/reset-sunxi.c   |  6 ++----
 include/clk/sunxi.h           |  9 +++++++--
 17 files changed, 28 insertions(+), 95 deletions(-)

diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
index 6b58cffc8a..e5374f6cf0 100644
--- a/drivers/clk/sunxi/clk_a10.c
+++ b/drivers/clk/sunxi/clk_a10.c
@@ -69,11 +69,6 @@ static const struct ccu_desc a10_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a10_resets),
 };
 
-static int a10_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a10_resets));
-}
-
 static const struct udevice_id a10_ccu_ids[] = {
 	{ .compatible = "allwinner,sun4i-a10-ccu",
 	  .data = (ulong)&a10_ccu_desc },
@@ -89,5 +84,5 @@ U_BOOT_DRIVER(clk_sun4i_a10) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a10_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
index 81b146ce1e..07d518c121 100644
--- a/drivers/clk/sunxi/clk_a10s.c
+++ b/drivers/clk/sunxi/clk_a10s.c
@@ -54,11 +54,6 @@ static const struct ccu_desc a10s_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a10s_resets),
 };
 
-static int a10s_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a10s_resets));
-}
-
 static const struct udevice_id a10s_ccu_ids[] = {
 	{ .compatible = "allwinner,sun5i-a10s-ccu",
 	  .data = (ulong)&a10s_ccu_desc },
@@ -74,5 +69,5 @@ U_BOOT_DRIVER(clk_sun5i_a10s) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a10s_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
index c7c78bc7d8..9c0e5db07c 100644
--- a/drivers/clk/sunxi/clk_a23.c
+++ b/drivers/clk/sunxi/clk_a23.c
@@ -73,11 +73,6 @@ static const struct ccu_desc a23_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a23_resets),
 };
 
-static int a23_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a23_resets));
-}
-
 static const struct udevice_id a23_clk_ids[] = {
 	{ .compatible = "allwinner,sun8i-a23-ccu",
 	  .data = (ulong)&a23_ccu_desc },
@@ -93,5 +88,5 @@ U_BOOT_DRIVER(clk_sun8i_a23) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a23_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
index c8c7f4ecf5..3d0767e290 100644
--- a/drivers/clk/sunxi/clk_a31.c
+++ b/drivers/clk/sunxi/clk_a31.c
@@ -94,11 +94,6 @@ static const struct ccu_desc a31_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a31_resets),
 };
 
-static int a31_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a31_resets));
-}
-
 static const struct udevice_id a31_clk_ids[] = {
 	{ .compatible = "allwinner,sun6i-a31-ccu",
 	  .data = (ulong)&a31_ccu_desc },
@@ -112,5 +107,5 @@ U_BOOT_DRIVER(clk_sun6i_a31) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a31_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
index 7bf1c4578c..04c238204d 100644
--- a/drivers/clk/sunxi/clk_a31_r.c
+++ b/drivers/clk/sunxi/clk_a31_r.c
@@ -35,11 +35,6 @@ static const struct ccu_desc a31_r_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a31_r_resets),
 };
 
-static int a31_r_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a31_r_resets));
-}
-
 static const struct udevice_id a31_r_clk_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
 	  .data = (ulong)&a31_r_ccu_desc },
@@ -57,5 +52,5 @@ U_BOOT_DRIVER(clk_sun6i_a31_r) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a31_r_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
index 6da861ddc1..b41260cbe6 100644
--- a/drivers/clk/sunxi/clk_a64.c
+++ b/drivers/clk/sunxi/clk_a64.c
@@ -80,11 +80,6 @@ static const struct ccu_desc a64_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a64_resets),
 };
 
-static int a64_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a64_resets));
-}
-
 static const struct udevice_id a64_ccu_ids[] = {
 	{ .compatible = "allwinner,sun50i-a64-ccu",
 	  .data = (ulong)&a64_ccu_desc },
@@ -98,5 +93,5 @@ U_BOOT_DRIVER(clk_sun50i_a64) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a64_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
index 7025d3cbe6..a3ad3b7804 100644
--- a/drivers/clk/sunxi/clk_a80.c
+++ b/drivers/clk/sunxi/clk_a80.c
@@ -86,16 +86,6 @@ static const struct ccu_desc a80_mmc_clk_desc = {
 	.num_resets = ARRAY_SIZE(a80_mmc_resets),
 };
 
-static int a80_clk_bind(struct udevice *dev)
-{
-	ulong count = ARRAY_SIZE(a80_resets);
-
-	if (device_is_compatible(dev, "allwinner,sun9i-a80-mmc-config-clk"))
-		count = ARRAY_SIZE(a80_mmc_resets);
-
-	return sunxi_reset_bind(dev, count);
-}
-
 static const struct udevice_id a80_ccu_ids[] = {
 	{ .compatible = "allwinner,sun9i-a80-ccu",
 	  .data = (ulong)&a80_ccu_desc },
@@ -111,5 +101,5 @@ U_BOOT_DRIVER(clk_sun9i_a80) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a80_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
index c50d253f84..cad5b484cf 100644
--- a/drivers/clk/sunxi/clk_a83t.c
+++ b/drivers/clk/sunxi/clk_a83t.c
@@ -77,11 +77,6 @@ static const struct ccu_desc a83t_ccu_desc = {
 	.num_resets = ARRAY_SIZE(a83t_resets),
 };
 
-static int a83t_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(a83t_resets));
-}
-
 static const struct udevice_id a83t_clk_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-ccu",
 	  .data = (ulong)&a83t_ccu_desc },
@@ -95,5 +90,5 @@ U_BOOT_DRIVER(clk_sun8i_a83t) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= a83t_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
index 22c2b236a8..3b4e9af111 100644
--- a/drivers/clk/sunxi/clk_h3.c
+++ b/drivers/clk/sunxi/clk_h3.c
@@ -93,11 +93,6 @@ static const struct ccu_desc h3_ccu_desc = {
 	.num_resets = ARRAY_SIZE(h3_resets),
 };
 
-static int h3_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(h3_resets));
-}
-
 static const struct udevice_id h3_ccu_ids[] = {
 	{ .compatible = "allwinner,sun8i-h3-ccu",
 	  .data = (ulong)&h3_ccu_desc },
@@ -113,5 +108,5 @@ U_BOOT_DRIVER(clk_sun8i_h3) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= h3_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
index 6521811215..93343b090d 100644
--- a/drivers/clk/sunxi/clk_h6.c
+++ b/drivers/clk/sunxi/clk_h6.c
@@ -94,11 +94,6 @@ static const struct ccu_desc h6_ccu_desc = {
 	.num_resets = ARRAY_SIZE(h6_resets),
 };
 
-static int h6_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(h6_resets));
-}
-
 static const struct udevice_id h6_ccu_ids[] = {
 	{ .compatible = "allwinner,sun50i-h6-ccu",
 	  .data = (ulong)&h6_ccu_desc },
@@ -112,5 +107,5 @@ U_BOOT_DRIVER(clk_sun50i_h6) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= h6_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
index 26f74c0fa0..e791736093 100644
--- a/drivers/clk/sunxi/clk_h616.c
+++ b/drivers/clk/sunxi/clk_h616.c
@@ -112,11 +112,6 @@ static const struct ccu_desc h616_ccu_desc = {
 	.num_resets = ARRAY_SIZE(h616_resets),
 };
 
-static int h616_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(h616_resets));
-}
-
 static const struct udevice_id h616_ccu_ids[] = {
 	{ .compatible = "allwinner,sun50i-h616-ccu",
 	  .data = (ulong)&h616_ccu_desc },
@@ -130,5 +125,5 @@ U_BOOT_DRIVER(clk_sun50i_h616) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= h616_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
index fee9604551..0f5cefd687 100644
--- a/drivers/clk/sunxi/clk_h6_r.c
+++ b/drivers/clk/sunxi/clk_h6_r.c
@@ -39,11 +39,6 @@ static const struct ccu_desc h6_r_ccu_desc = {
 	.num_resets = ARRAY_SIZE(h6_r_resets),
 };
 
-static int h6_r_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(h6_r_resets));
-}
-
 static const struct udevice_id h6_r_clk_ids[] = {
 	{ .compatible = "allwinner,sun50i-h6-r-ccu",
 	  .data = (ulong)&h6_r_ccu_desc },
@@ -59,5 +54,5 @@ U_BOOT_DRIVER(clk_sun6i_h6_r) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= h6_r_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
index 456a38a159..a59ac06975 100644
--- a/drivers/clk/sunxi/clk_r40.c
+++ b/drivers/clk/sunxi/clk_r40.c
@@ -104,11 +104,6 @@ static const struct ccu_desc r40_ccu_desc = {
 	.num_resets = ARRAY_SIZE(r40_resets),
 };
 
-static int r40_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(r40_resets));
-}
-
 static const struct udevice_id r40_clk_ids[] = {
 	{ .compatible = "allwinner,sun8i-r40-ccu",
 	  .data = (ulong)&r40_ccu_desc },
@@ -122,5 +117,5 @@ U_BOOT_DRIVER(clk_sun8i_r40) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= r40_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
index 3108e5b66d..e1129f6ccf 100644
--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -64,6 +64,11 @@ struct clk_ops sunxi_clk_ops = {
 	.disable = sunxi_clk_disable,
 };
 
+int sunxi_clk_bind(struct udevice *dev)
+{
+	return sunxi_reset_bind(dev);
+}
+
 int sunxi_clk_probe(struct udevice *dev)
 {
 	struct ccu_priv *priv = dev_get_priv(dev);
diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
index ab21cd791b..c6a17b4535 100644
--- a/drivers/clk/sunxi/clk_v3s.c
+++ b/drivers/clk/sunxi/clk_v3s.c
@@ -54,11 +54,6 @@ static const struct ccu_desc v3s_ccu_desc = {
 	.num_resets = ARRAY_SIZE(v3s_resets),
 };
 
-static int v3s_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(v3s_resets));
-}
-
 static const struct udevice_id v3s_clk_ids[] = {
 	{ .compatible = "allwinner,sun8i-v3s-ccu",
 	  .data = (ulong)&v3s_ccu_desc },
@@ -74,5 +69,5 @@ U_BOOT_DRIVER(clk_sun8i_v3s) = {
 	.priv_auto	= sizeof(struct ccu_priv),
 	.ops		= &sunxi_clk_ops,
 	.probe		= sunxi_clk_probe,
-	.bind		= v3s_clk_bind,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
index 8b95938dfe..4d02d02834 100644
--- a/drivers/reset/reset-sunxi.c
+++ b/drivers/reset/reset-sunxi.c
@@ -19,7 +19,6 @@
 
 struct sunxi_reset_priv {
 	void *base;
-	ulong count;
 	const struct ccu_desc *desc;
 };
 
@@ -35,7 +34,7 @@ static int sunxi_reset_request(struct reset_ctl *reset_ctl)
 
 	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
 
-	if (reset_ctl->id >= priv->count)
+	if (reset_ctl->id >= priv->desc->num_resets)
 		return -EINVAL;
 
 	return 0;
@@ -99,7 +98,7 @@ static int sunxi_reset_probe(struct udevice *dev)
 	return 0;
 }
 
-int sunxi_reset_bind(struct udevice *dev, ulong count)
+int sunxi_reset_bind(struct udevice *dev)
 {
 	struct udevice *rst_dev;
 	struct sunxi_reset_priv *priv;
@@ -112,7 +111,6 @@ int sunxi_reset_bind(struct udevice *dev, ulong count)
 		return ret;
 	}
 	priv = malloc(sizeof(struct sunxi_reset_priv));
-	priv->count = count;
 	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
 	dev_set_priv(rst_dev, priv);
 
diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
index 5471b9c831..c798c226f5 100644
--- a/include/clk/sunxi.h
+++ b/include/clk/sunxi.h
@@ -80,6 +80,12 @@ struct ccu_priv {
 	const struct ccu_desc *desc;
 };
 
+/**
+ * sunxi_clk_bind - common sunxi clock bind
+ * @dev:	clock device
+ */
+int sunxi_clk_bind(struct udevice *dev);
+
 /**
  * sunxi_clk_probe - common sunxi clock probe
  * @dev:	clock device
@@ -92,9 +98,8 @@ extern struct clk_ops sunxi_clk_ops;
  * sunxi_reset_bind() - reset binding
  *
  * @dev:       reset device
- * @count:     reset count
  * Return: 0 success, or error value
  */
-int sunxi_reset_bind(struct udevice *dev, ulong count);
+int sunxi_reset_bind(struct udevice *dev);
 
 #endif /* _CLK_SUNXI_H */
-- 
2.35.1


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

* [PATCH 4/7] clk: sunxi: Use a single driver for all variants
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (2 preceding siblings ...)
  2022-05-09  5:29 ` [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-27  0:43   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 5/7] clk: sunxi: Convert driver private data to platform data Samuel Holland
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

Now that all of the variants use the same bind/probe functions and ops,
there is no need to have a separate driver for each variant. Since most
SoCs contain two variants (the main CCU and PRCM CCU), this saves a bit
of firmware size and RAM.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_a10.c   |  20 +-----
 drivers/clk/sunxi/clk_a10s.c  |  20 +-----
 drivers/clk/sunxi/clk_a23.c   |  20 +-----
 drivers/clk/sunxi/clk_a31.c   |  18 +-----
 drivers/clk/sunxi/clk_a31_r.c |  22 +------
 drivers/clk/sunxi/clk_a64.c   |  18 +-----
 drivers/clk/sunxi/clk_a80.c   |  22 +------
 drivers/clk/sunxi/clk_a83t.c  |  18 +-----
 drivers/clk/sunxi/clk_h3.c    |  20 +-----
 drivers/clk/sunxi/clk_h6.c    |  18 +-----
 drivers/clk/sunxi/clk_h616.c  |  18 +-----
 drivers/clk/sunxi/clk_h6_r.c  |  20 +-----
 drivers/clk/sunxi/clk_r40.c   |  18 +-----
 drivers/clk/sunxi/clk_sunxi.c | 118 +++++++++++++++++++++++++++++++++-
 drivers/clk/sunxi/clk_v3s.c   |  20 +-----
 include/clk/sunxi.h           |  12 ----
 16 files changed, 131 insertions(+), 271 deletions(-)

diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
index e5374f6cf0..4752a1167b 100644
--- a/drivers/clk/sunxi/clk_a10.c
+++ b/drivers/clk/sunxi/clk_a10.c
@@ -62,27 +62,9 @@ static struct ccu_reset a10_resets[] = {
 	[RST_USB_PHY2]		= RESET(0x0cc, BIT(2)),
 };
 
-static const struct ccu_desc a10_ccu_desc = {
+const struct ccu_desc a10_ccu_desc = {
 	.gates = a10_gates,
 	.resets = a10_resets,
 	.num_gates = ARRAY_SIZE(a10_gates),
 	.num_resets = ARRAY_SIZE(a10_resets),
 };
-
-static const struct udevice_id a10_ccu_ids[] = {
-	{ .compatible = "allwinner,sun4i-a10-ccu",
-	  .data = (ulong)&a10_ccu_desc },
-	{ .compatible = "allwinner,sun7i-a20-ccu",
-	  .data = (ulong)&a10_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun4i_a10) = {
-	.name		= "sun4i_a10_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a10_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
index 07d518c121..9619c5f935 100644
--- a/drivers/clk/sunxi/clk_a10s.c
+++ b/drivers/clk/sunxi/clk_a10s.c
@@ -47,27 +47,9 @@ static struct ccu_reset a10s_resets[] = {
 	[RST_USB_PHY1]		= RESET(0x0cc, BIT(1)),
 };
 
-static const struct ccu_desc a10s_ccu_desc = {
+const struct ccu_desc a10s_ccu_desc = {
 	.gates = a10s_gates,
 	.resets = a10s_resets,
 	.num_gates = ARRAY_SIZE(a10s_gates),
 	.num_resets = ARRAY_SIZE(a10s_resets),
 };
-
-static const struct udevice_id a10s_ccu_ids[] = {
-	{ .compatible = "allwinner,sun5i-a10s-ccu",
-	  .data = (ulong)&a10s_ccu_desc },
-	{ .compatible = "allwinner,sun5i-a13-ccu",
-	  .data = (ulong)&a10s_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun5i_a10s) = {
-	.name		= "sun5i_a10s_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a10s_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
index 9c0e5db07c..5e19c11c23 100644
--- a/drivers/clk/sunxi/clk_a23.c
+++ b/drivers/clk/sunxi/clk_a23.c
@@ -66,27 +66,9 @@ static struct ccu_reset a23_resets[] = {
 	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
 };
 
-static const struct ccu_desc a23_ccu_desc = {
+const struct ccu_desc a23_ccu_desc = {
 	.gates = a23_gates,
 	.resets = a23_resets,
 	.num_gates = ARRAY_SIZE(a23_gates),
 	.num_resets = ARRAY_SIZE(a23_resets),
 };
-
-static const struct udevice_id a23_clk_ids[] = {
-	{ .compatible = "allwinner,sun8i-a23-ccu",
-	  .data = (ulong)&a23_ccu_desc },
-	{ .compatible = "allwinner,sun8i-a33-ccu",
-	  .data = (ulong)&a23_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun8i_a23) = {
-	.name		= "sun8i_a23_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a23_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
index 3d0767e290..0aaaaf58ea 100644
--- a/drivers/clk/sunxi/clk_a31.c
+++ b/drivers/clk/sunxi/clk_a31.c
@@ -87,25 +87,9 @@ static struct ccu_reset a31_resets[] = {
 	[RST_APB2_UART5]	= RESET(0x2d8, BIT(21)),
 };
 
-static const struct ccu_desc a31_ccu_desc = {
+const struct ccu_desc a31_ccu_desc = {
 	.gates = a31_gates,
 	.resets = a31_resets,
 	.num_gates = ARRAY_SIZE(a31_gates),
 	.num_resets = ARRAY_SIZE(a31_resets),
 };
-
-static const struct udevice_id a31_clk_ids[] = {
-	{ .compatible = "allwinner,sun6i-a31-ccu",
-	  .data = (ulong)&a31_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun6i_a31) = {
-	.name		= "sun6i_a31_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a31_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
index 04c238204d..fa6887fa75 100644
--- a/drivers/clk/sunxi/clk_a31_r.c
+++ b/drivers/clk/sunxi/clk_a31_r.c
@@ -28,29 +28,9 @@ static struct ccu_reset a31_r_resets[] = {
 	[RST_APB0_I2C]		= RESET(0x0b0, BIT(6)),
 };
 
-static const struct ccu_desc a31_r_ccu_desc = {
+const struct ccu_desc a31_r_ccu_desc = {
 	.gates = a31_r_gates,
 	.resets = a31_r_resets,
 	.num_gates = ARRAY_SIZE(a31_r_gates),
 	.num_resets = ARRAY_SIZE(a31_r_resets),
 };
-
-static const struct udevice_id a31_r_clk_ids[] = {
-	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
-	  .data = (ulong)&a31_r_ccu_desc },
-	{ .compatible = "allwinner,sun8i-h3-r-ccu",
-	  .data = (ulong)&a31_r_ccu_desc },
-	{ .compatible = "allwinner,sun50i-a64-r-ccu",
-	  .data = (ulong)&a31_r_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun6i_a31_r) = {
-	.name		= "sun6i_a31_r_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a31_r_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
index b41260cbe6..bd50cd4dda 100644
--- a/drivers/clk/sunxi/clk_a64.c
+++ b/drivers/clk/sunxi/clk_a64.c
@@ -73,25 +73,9 @@ static const struct ccu_reset a64_resets[] = {
 	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
 };
 
-static const struct ccu_desc a64_ccu_desc = {
+const struct ccu_desc a64_ccu_desc = {
 	.gates = a64_gates,
 	.resets = a64_resets,
 	.num_gates = ARRAY_SIZE(a64_gates),
 	.num_resets = ARRAY_SIZE(a64_resets),
 };
-
-static const struct udevice_id a64_ccu_ids[] = {
-	{ .compatible = "allwinner,sun50i-a64-ccu",
-	  .data = (ulong)&a64_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun50i_a64) = {
-	.name		= "sun50i_a64_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a64_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
index a3ad3b7804..561380c817 100644
--- a/drivers/clk/sunxi/clk_a80.c
+++ b/drivers/clk/sunxi/clk_a80.c
@@ -72,34 +72,16 @@ static const struct ccu_reset a80_mmc_resets[] = {
 	[3]			= GATE(0xc, BIT(18)),
 };
 
-static const struct ccu_desc a80_ccu_desc = {
+const struct ccu_desc a80_ccu_desc = {
 	.gates = a80_gates,
 	.resets = a80_resets,
 	.num_gates = ARRAY_SIZE(a80_gates),
 	.num_resets = ARRAY_SIZE(a80_resets),
 };
 
-static const struct ccu_desc a80_mmc_clk_desc = {
+const struct ccu_desc a80_mmc_clk_desc = {
 	.gates = a80_mmc_gates,
 	.resets = a80_mmc_resets,
 	.num_gates = ARRAY_SIZE(a80_mmc_gates),
 	.num_resets = ARRAY_SIZE(a80_mmc_resets),
 };
-
-static const struct udevice_id a80_ccu_ids[] = {
-	{ .compatible = "allwinner,sun9i-a80-ccu",
-	  .data = (ulong)&a80_ccu_desc },
-	{ .compatible = "allwinner,sun9i-a80-mmc-config-clk",
-	  .data = (ulong)&a80_mmc_clk_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun9i_a80) = {
-	.name		= "sun9i_a80_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a80_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
index cad5b484cf..e246437af2 100644
--- a/drivers/clk/sunxi/clk_a83t.c
+++ b/drivers/clk/sunxi/clk_a83t.c
@@ -70,25 +70,9 @@ static struct ccu_reset a83t_resets[] = {
 	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
 };
 
-static const struct ccu_desc a83t_ccu_desc = {
+const struct ccu_desc a83t_ccu_desc = {
 	.gates = a83t_gates,
 	.resets = a83t_resets,
 	.num_gates = ARRAY_SIZE(a83t_gates),
 	.num_resets = ARRAY_SIZE(a83t_resets),
 };
-
-static const struct udevice_id a83t_clk_ids[] = {
-	{ .compatible = "allwinner,sun8i-a83t-ccu",
-	  .data = (ulong)&a83t_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun8i_a83t) = {
-	.name		= "sun8i_a83t_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= a83t_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
index 3b4e9af111..5d2a53185e 100644
--- a/drivers/clk/sunxi/clk_h3.c
+++ b/drivers/clk/sunxi/clk_h3.c
@@ -86,27 +86,9 @@ static struct ccu_reset h3_resets[] = {
 	[RST_BUS_UART3]		= RESET(0x2d8, BIT(19)),
 };
 
-static const struct ccu_desc h3_ccu_desc = {
+const struct ccu_desc h3_ccu_desc = {
 	.gates = h3_gates,
 	.resets = h3_resets,
 	.num_gates = ARRAY_SIZE(h3_gates),
 	.num_resets = ARRAY_SIZE(h3_resets),
 };
-
-static const struct udevice_id h3_ccu_ids[] = {
-	{ .compatible = "allwinner,sun8i-h3-ccu",
-	  .data = (ulong)&h3_ccu_desc },
-	{ .compatible = "allwinner,sun50i-h5-ccu",
-	  .data = (ulong)&h3_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun8i_h3) = {
-	.name		= "sun8i_h3_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= h3_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
index 93343b090d..02ba07bdaf 100644
--- a/drivers/clk/sunxi/clk_h6.c
+++ b/drivers/clk/sunxi/clk_h6.c
@@ -87,25 +87,9 @@ static struct ccu_reset h6_resets[] = {
 	[RST_BUS_OTG]		= RESET(0xa8c, BIT(24)),
 };
 
-static const struct ccu_desc h6_ccu_desc = {
+const struct ccu_desc h6_ccu_desc = {
 	.gates = h6_gates,
 	.resets = h6_resets,
 	.num_gates = ARRAY_SIZE(h6_gates),
 	.num_resets = ARRAY_SIZE(h6_resets),
 };
-
-static const struct udevice_id h6_ccu_ids[] = {
-	{ .compatible = "allwinner,sun50i-h6-ccu",
-	  .data = (ulong)&h6_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun50i_h6) = {
-	.name		= "sun50i_h6_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= h6_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
index e791736093..abcc6fc264 100644
--- a/drivers/clk/sunxi/clk_h616.c
+++ b/drivers/clk/sunxi/clk_h616.c
@@ -105,25 +105,9 @@ static struct ccu_reset h616_resets[] = {
 	[RST_BUS_OTG]		= RESET(0xa8c, BIT(24)),
 };
 
-static const struct ccu_desc h616_ccu_desc = {
+const struct ccu_desc h616_ccu_desc = {
 	.gates = h616_gates,
 	.resets = h616_resets,
 	.num_gates = ARRAY_SIZE(h616_gates),
 	.num_resets = ARRAY_SIZE(h616_resets),
 };
-
-static const struct udevice_id h616_ccu_ids[] = {
-	{ .compatible = "allwinner,sun50i-h616-ccu",
-	  .data = (ulong)&h616_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun50i_h616) = {
-	.name		= "sun50i_h616_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= h616_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
index 0f5cefd687..d82f791e79 100644
--- a/drivers/clk/sunxi/clk_h6_r.c
+++ b/drivers/clk/sunxi/clk_h6_r.c
@@ -32,27 +32,9 @@ static struct ccu_reset h6_r_resets[] = {
 	[RST_R_APB1_W1]		= RESET(0x1ec, BIT(16)),
 };
 
-static const struct ccu_desc h6_r_ccu_desc = {
+const struct ccu_desc h6_r_ccu_desc = {
 	.gates = h6_r_gates,
 	.resets = h6_r_resets,
 	.num_gates = ARRAY_SIZE(h6_r_gates),
 	.num_resets = ARRAY_SIZE(h6_r_resets),
 };
-
-static const struct udevice_id h6_r_clk_ids[] = {
-	{ .compatible = "allwinner,sun50i-h6-r-ccu",
-	  .data = (ulong)&h6_r_ccu_desc },
-	{ .compatible = "allwinner,sun50i-h616-r-ccu",
-	  .data = (ulong)&h6_r_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun6i_h6_r) = {
-	.name		= "sun6i_h6_r_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= h6_r_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
index a59ac06975..a5b756be40 100644
--- a/drivers/clk/sunxi/clk_r40.c
+++ b/drivers/clk/sunxi/clk_r40.c
@@ -97,25 +97,9 @@ static struct ccu_reset r40_resets[] = {
 	[RST_BUS_UART7]		= RESET(0x2d8, BIT(23)),
 };
 
-static const struct ccu_desc r40_ccu_desc = {
+const struct ccu_desc r40_ccu_desc = {
 	.gates = r40_gates,
 	.resets = r40_resets,
 	.num_gates = ARRAY_SIZE(r40_gates),
 	.num_resets = ARRAY_SIZE(r40_resets),
 };
-
-static const struct udevice_id r40_clk_ids[] = {
-	{ .compatible = "allwinner,sun8i-r40-ccu",
-	  .data = (ulong)&r40_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun8i_r40) = {
-	.name		= "sun8i_r40_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= r40_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
index e1129f6ccf..7d9e6029ff 100644
--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -64,12 +64,12 @@ struct clk_ops sunxi_clk_ops = {
 	.disable = sunxi_clk_disable,
 };
 
-int sunxi_clk_bind(struct udevice *dev)
+static int sunxi_clk_bind(struct udevice *dev)
 {
 	return sunxi_reset_bind(dev);
 }
 
-int sunxi_clk_probe(struct udevice *dev)
+static int sunxi_clk_probe(struct udevice *dev)
 {
 	struct ccu_priv *priv = dev_get_priv(dev);
 	struct clk_bulk clk_bulk;
@@ -94,3 +94,117 @@ int sunxi_clk_probe(struct udevice *dev)
 
 	return 0;
 }
+
+extern const struct ccu_desc a10_ccu_desc;
+extern const struct ccu_desc a10s_ccu_desc;
+extern const struct ccu_desc a23_ccu_desc;
+extern const struct ccu_desc a31_ccu_desc;
+extern const struct ccu_desc a31_r_ccu_desc;
+extern const struct ccu_desc a64_ccu_desc;
+extern const struct ccu_desc a80_ccu_desc;
+extern const struct ccu_desc a80_mmc_clk_desc;
+extern const struct ccu_desc a83t_ccu_desc;
+extern const struct ccu_desc h3_ccu_desc;
+extern const struct ccu_desc h6_ccu_desc;
+extern const struct ccu_desc h616_ccu_desc;
+extern const struct ccu_desc h6_r_ccu_desc;
+extern const struct ccu_desc r40_ccu_desc;
+extern const struct ccu_desc v3s_ccu_desc;
+
+static const struct udevice_id sunxi_clk_ids[] = {
+#ifdef CONFIG_CLK_SUN4I_A10
+	{ .compatible = "allwinner,sun4i-a10-ccu",
+	  .data = (ulong)&a10_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN5I_A10S
+	{ .compatible = "allwinner,sun5i-a10s-ccu",
+	  .data = (ulong)&a10s_ccu_desc },
+	{ .compatible = "allwinner,sun5i-a13-ccu",
+	  .data = (ulong)&a10s_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN6I_A31
+	{ .compatible = "allwinner,sun6i-a31-ccu",
+	  .data = (ulong)&a31_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN4I_A10
+	{ .compatible = "allwinner,sun7i-a20-ccu",
+	  .data = (ulong)&a10_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_A23
+	{ .compatible = "allwinner,sun8i-a23-ccu",
+	  .data = (ulong)&a23_ccu_desc },
+	{ .compatible = "allwinner,sun8i-a33-ccu",
+	  .data = (ulong)&a23_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_A83T
+	{ .compatible = "allwinner,sun8i-a83t-ccu",
+	  .data = (ulong)&a83t_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN6I_A31_R
+	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
+	  .data = (ulong)&a31_r_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_H3
+	{ .compatible = "allwinner,sun8i-h3-ccu",
+	  .data = (ulong)&h3_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN6I_A31_R
+	{ .compatible = "allwinner,sun8i-h3-r-ccu",
+	  .data = (ulong)&a31_r_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_R40
+	{ .compatible = "allwinner,sun8i-r40-ccu",
+	  .data = (ulong)&r40_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_V3S
+	{ .compatible = "allwinner,sun8i-v3-ccu",
+	  .data = (ulong)&v3s_ccu_desc },
+	{ .compatible = "allwinner,sun8i-v3s-ccu",
+	  .data = (ulong)&v3s_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN9I_A80
+	{ .compatible = "allwinner,sun9i-a80-ccu",
+	  .data = (ulong)&a80_ccu_desc },
+	{ .compatible = "allwinner,sun9i-a80-mmc-config-clk",
+	  .data = (ulong)&a80_mmc_clk_desc },
+#endif
+#ifdef CONFIG_CLK_SUN50I_A64
+	{ .compatible = "allwinner,sun50i-a64-ccu",
+	  .data = (ulong)&a64_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN6I_A31_R
+	{ .compatible = "allwinner,sun50i-a64-r-ccu",
+	  .data = (ulong)&a31_r_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN8I_H3
+	{ .compatible = "allwinner,sun50i-h5-ccu",
+	  .data = (ulong)&h3_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN50I_H6
+	{ .compatible = "allwinner,sun50i-h6-ccu",
+	  .data = (ulong)&h6_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN50I_H6_R
+	{ .compatible = "allwinner,sun50i-h6-r-ccu",
+	  .data = (ulong)&h6_r_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN50I_H616
+	{ .compatible = "allwinner,sun50i-h616-ccu",
+	  .data = (ulong)&h616_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN50I_H6_R
+	{ .compatible = "allwinner,sun50i-h616-r-ccu",
+	  .data = (ulong)&h6_r_ccu_desc },
+#endif
+	{ }
+};
+
+U_BOOT_DRIVER(sunxi_clk) = {
+	.name		= "sunxi_clk",
+	.id		= UCLASS_CLK,
+	.of_match	= sunxi_clk_ids,
+	.bind		= sunxi_clk_bind,
+	.probe		= sunxi_clk_probe,
+	.priv_auto	= sizeof(struct ccu_priv),
+	.ops		= &sunxi_clk_ops,
+};
diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
index c6a17b4535..e632afc083 100644
--- a/drivers/clk/sunxi/clk_v3s.c
+++ b/drivers/clk/sunxi/clk_v3s.c
@@ -47,27 +47,9 @@ static struct ccu_reset v3s_resets[] = {
 	[RST_BUS_UART2]		= RESET(0x2d8, BIT(18)),
 };
 
-static const struct ccu_desc v3s_ccu_desc = {
+const struct ccu_desc v3s_ccu_desc = {
 	.gates = v3s_gates,
 	.resets = v3s_resets,
 	.num_gates = ARRAY_SIZE(v3s_gates),
 	.num_resets = ARRAY_SIZE(v3s_resets),
 };
-
-static const struct udevice_id v3s_clk_ids[] = {
-	{ .compatible = "allwinner,sun8i-v3s-ccu",
-	  .data = (ulong)&v3s_ccu_desc },
-	{ .compatible = "allwinner,sun8i-v3-ccu",
-	  .data = (ulong)&v3s_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun8i_v3s) = {
-	.name		= "sun8i_v3s_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= v3s_clk_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= sunxi_clk_bind,
-};
diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
index c798c226f5..11caf12b17 100644
--- a/include/clk/sunxi.h
+++ b/include/clk/sunxi.h
@@ -80,18 +80,6 @@ struct ccu_priv {
 	const struct ccu_desc *desc;
 };
 
-/**
- * sunxi_clk_bind - common sunxi clock bind
- * @dev:	clock device
- */
-int sunxi_clk_bind(struct udevice *dev);
-
-/**
- * sunxi_clk_probe - common sunxi clock probe
- * @dev:	clock device
- */
-int sunxi_clk_probe(struct udevice *dev);
-
 extern struct clk_ops sunxi_clk_ops;
 
 /**
-- 
2.35.1


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

* [PATCH 5/7] clk: sunxi: Convert driver private data to platform data
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (3 preceding siblings ...)
  2022-05-09  5:29 ` [PATCH 4/7] clk: sunxi: Use a single driver for all variants Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-27 19:34   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 6/7] reset: " Samuel Holland
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

All of the driver private data should really be platform data since it
is determined statically (selected by the compatible string or extracted
from the devicetree). Move everything to platform data, so it can be
provided when binding the driver. This is useful for SPL, or for
instantiating the driver as part of an MFD.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_sunxi.c | 41 ++++++++++++++++++++---------------
 include/clk/sunxi.h           |  4 ++--
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
index 7d9e6029ff..cadfca767b 100644
--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -15,19 +15,19 @@
 #include <linux/bitops.h>
 #include <linux/log2.h>
 
-static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
+static const struct ccu_clk_gate *plat_to_gate(struct ccu_plat *plat,
 					       unsigned long id)
 {
-	if (id >= priv->desc->num_gates)
+	if (id >= plat->desc->num_gates)
 		return NULL;
 
-	return &priv->desc->gates[id];
+	return &plat->desc->gates[id];
 }
 
 static int sunxi_set_gate(struct clk *clk, bool on)
 {
-	struct ccu_priv *priv = dev_get_priv(clk->dev);
-	const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
+	struct ccu_plat *plat = dev_get_plat(clk->dev);
+	const struct ccu_clk_gate *gate = plat_to_gate(plat, clk->id);
 	u32 reg;
 
 	if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
@@ -38,13 +38,13 @@ static int sunxi_set_gate(struct clk *clk, bool on)
 	debug("%s: (CLK#%ld) off#0x%x, BIT(%d)\n", __func__,
 	      clk->id, gate->off, ilog2(gate->bit));
 
-	reg = readl(priv->base + gate->off);
+	reg = readl(plat->base + gate->off);
 	if (on)
 		reg |= gate->bit;
 	else
 		reg &= ~gate->bit;
 
-	writel(reg, priv->base + gate->off);
+	writel(reg, plat->base + gate->off);
 
 	return 0;
 }
@@ -71,19 +71,10 @@ static int sunxi_clk_bind(struct udevice *dev)
 
 static int sunxi_clk_probe(struct udevice *dev)
 {
-	struct ccu_priv *priv = dev_get_priv(dev);
 	struct clk_bulk clk_bulk;
 	struct reset_ctl_bulk rst_bulk;
 	int ret;
 
-	priv->base = dev_read_addr_ptr(dev);
-	if (!priv->base)
-		return -ENOMEM;
-
-	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
-	if (!priv->desc)
-		return -EINVAL;
-
 	ret = clk_get_bulk(dev, &clk_bulk);
 	if (!ret)
 		clk_enable_bulk(&clk_bulk);
@@ -95,6 +86,21 @@ static int sunxi_clk_probe(struct udevice *dev)
 	return 0;
 }
 
+static int sunxi_clk_of_to_plat(struct udevice *dev)
+{
+	struct ccu_plat *plat = dev_get_plat(dev);
+
+	plat->base = dev_read_addr_ptr(dev);
+	if (!plat->base)
+		return -ENOMEM;
+
+	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
+	if (!plat->desc)
+		return -EINVAL;
+
+	return 0;
+}
+
 extern const struct ccu_desc a10_ccu_desc;
 extern const struct ccu_desc a10s_ccu_desc;
 extern const struct ccu_desc a23_ccu_desc;
@@ -205,6 +211,7 @@ U_BOOT_DRIVER(sunxi_clk) = {
 	.of_match	= sunxi_clk_ids,
 	.bind		= sunxi_clk_bind,
 	.probe		= sunxi_clk_probe,
-	.priv_auto	= sizeof(struct ccu_priv),
+	.of_to_plat	= sunxi_clk_of_to_plat,
+	.plat_auto	= sizeof(struct ccu_plat),
 	.ops		= &sunxi_clk_ops,
 };
diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
index 11caf12b17..e90e078972 100644
--- a/include/clk/sunxi.h
+++ b/include/clk/sunxi.h
@@ -70,12 +70,12 @@ struct ccu_desc {
 };
 
 /**
- * struct ccu_priv - sunxi clock control unit
+ * struct ccu_plat - sunxi clock control unit platform data
  *
  * @base:	base address
  * @desc:	ccu descriptor
  */
-struct ccu_priv {
+struct ccu_plat {
 	void *base;
 	const struct ccu_desc *desc;
 };
-- 
2.35.1


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

* [PATCH 6/7] reset: sunxi: Convert driver private data to platform data
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (4 preceding siblings ...)
  2022-05-09  5:29 ` [PATCH 5/7] clk: sunxi: Convert driver private data to platform data Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-27 19:41   ` Andre Przywara
  2022-05-09  5:29 ` [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver Samuel Holland
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

The reason here is the same as the reason for changing the clock driver:
platform data can be provided when binding the driver.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/reset/reset-sunxi.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
index 4d02d02834..b060d7f5ed 100644
--- a/drivers/reset/reset-sunxi.c
+++ b/drivers/reset/reset-sunxi.c
@@ -17,24 +17,24 @@
 #include <linux/bitops.h>
 #include <linux/log2.h>
 
-struct sunxi_reset_priv {
+struct sunxi_reset_plat {
 	void *base;
 	const struct ccu_desc *desc;
 };
 
-static const struct ccu_reset *priv_to_reset(struct sunxi_reset_priv *priv,
+static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
 					     unsigned long id)
 {
-	return	&priv->desc->resets[id];
+	return	&plat->desc->resets[id];
 }
 
 static int sunxi_reset_request(struct reset_ctl *reset_ctl)
 {
-	struct sunxi_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
 
 	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
 
-	if (reset_ctl->id >= priv->desc->num_resets)
+	if (reset_ctl->id >= plat->desc->num_resets)
 		return -EINVAL;
 
 	return 0;
@@ -49,8 +49,8 @@ static int sunxi_reset_free(struct reset_ctl *reset_ctl)
 
 static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
 {
-	struct sunxi_reset_priv *priv = dev_get_priv(reset_ctl->dev);
-	const struct ccu_reset *reset = priv_to_reset(priv, reset_ctl->id);
+	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
+	const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
 	u32 reg;
 
 	if (!(reset->flags & CCU_RST_F_IS_VALID)) {
@@ -61,13 +61,13 @@ static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
 	debug("%s: (RST#%ld) off#0x%x, BIT(%d)\n", __func__,
 	      reset_ctl->id, reset->off, ilog2(reset->bit));
 
-	reg = readl(priv->base + reset->off);
+	reg = readl(plat->base + reset->off);
 	if (on)
 		reg |= reset->bit;
 	else
 		reg &= ~reset->bit;
 
-	writel(reg, priv->base + reset->off);
+	writel(reg, plat->base + reset->off);
 
 	return 0;
 }
@@ -89,11 +89,11 @@ struct reset_ops sunxi_reset_ops = {
 	.rst_deassert = sunxi_reset_deassert,
 };
 
-static int sunxi_reset_probe(struct udevice *dev)
+static int sunxi_reset_of_to_plat(struct udevice *dev)
 {
-	struct sunxi_reset_priv *priv = dev_get_priv(dev);
+	struct sunxi_reset_plat *plat = dev_get_plat(dev);
 
-	priv->base = dev_read_addr_ptr(dev);
+	plat->base = dev_read_addr_ptr(dev);
 
 	return 0;
 }
@@ -101,7 +101,7 @@ static int sunxi_reset_probe(struct udevice *dev)
 int sunxi_reset_bind(struct udevice *dev)
 {
 	struct udevice *rst_dev;
-	struct sunxi_reset_priv *priv;
+	struct sunxi_reset_plat *plat;
 	int ret;
 
 	ret = device_bind_driver_to_node(dev, "sunxi_reset", "reset",
@@ -110,9 +110,9 @@ int sunxi_reset_bind(struct udevice *dev)
 		debug("failed to bind sunxi_reset driver (ret=%d)\n", ret);
 		return ret;
 	}
-	priv = malloc(sizeof(struct sunxi_reset_priv));
-	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
-	dev_set_priv(rst_dev, priv);
+	plat = malloc(sizeof(struct sunxi_reset_plat));
+	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
+	dev_set_plat(rst_dev, plat);
 
 	return 0;
 }
@@ -121,6 +121,6 @@ U_BOOT_DRIVER(sunxi_reset) = {
 	.name		= "sunxi_reset",
 	.id		= UCLASS_RESET,
 	.ops		= &sunxi_reset_ops,
-	.probe		= sunxi_reset_probe,
-	.priv_auto	= sizeof(struct sunxi_reset_priv),
+	.of_to_plat	= sunxi_reset_of_to_plat,
+	.plat_auto	= sizeof(struct sunxi_reset_plat),
 };
-- 
2.35.1


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

* [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (5 preceding siblings ...)
  2022-05-09  5:29 ` [PATCH 6/7] reset: " Samuel Holland
@ 2022-05-09  5:29 ` Samuel Holland
  2022-06-27 23:45   ` Andre Przywara
  2022-05-10 23:24 ` [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Andre Przywara
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Samuel Holland @ 2022-05-09  5:29 UTC (permalink / raw)
  To: u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski, Sean Anderson
  Cc: Samuel Holland, Bin Meng, Heinrich Schuchardt, Maxime Ripard

The clock and reset drivers use the exact same platform data. Simplify
them by sharing the object. This is safe because the parent device
(the clock device) always gets its driver model callbacks run first.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi/clk_sunxi.c |  7 +++++-
 drivers/reset/reset-sunxi.c   | 43 +++--------------------------------
 include/clk/sunxi.h           |  8 -------
 3 files changed, 9 insertions(+), 49 deletions(-)

diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
index cadfca767b..10c5d2f4b6 100644
--- a/drivers/clk/sunxi/clk_sunxi.c
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -12,9 +12,12 @@
 #include <reset.h>
 #include <asm/io.h>
 #include <clk/sunxi.h>
+#include <dm/device-internal.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
 
+extern U_BOOT_DRIVER(sunxi_reset);
+
 static const struct ccu_clk_gate *plat_to_gate(struct ccu_plat *plat,
 					       unsigned long id)
 {
@@ -66,7 +69,9 @@ struct clk_ops sunxi_clk_ops = {
 
 static int sunxi_clk_bind(struct udevice *dev)
 {
-	return sunxi_reset_bind(dev);
+	/* Reuse the platform data for the reset driver. */
+	return device_bind(dev, DM_DRIVER_REF(sunxi_reset), "reset",
+			   dev_get_plat(dev), dev_ofnode(dev), NULL);
 }
 
 static int sunxi_clk_probe(struct udevice *dev)
diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
index b060d7f5ed..5d4b8dc92f 100644
--- a/drivers/reset/reset-sunxi.c
+++ b/drivers/reset/reset-sunxi.c
@@ -12,17 +12,10 @@
 #include <reset-uclass.h>
 #include <asm/io.h>
 #include <clk/sunxi.h>
-#include <dm/device-internal.h>
-#include <dm/lists.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
 
-struct sunxi_reset_plat {
-	void *base;
-	const struct ccu_desc *desc;
-};
-
-static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
+static const struct ccu_reset *plat_to_reset(struct ccu_plat *plat,
 					     unsigned long id)
 {
 	return	&plat->desc->resets[id];
@@ -30,7 +23,7 @@ static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
 
 static int sunxi_reset_request(struct reset_ctl *reset_ctl)
 {
-	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
+	struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
 
 	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
 
@@ -49,7 +42,7 @@ static int sunxi_reset_free(struct reset_ctl *reset_ctl)
 
 static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
 {
-	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
+	struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
 	const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
 	u32 reg;
 
@@ -89,38 +82,8 @@ struct reset_ops sunxi_reset_ops = {
 	.rst_deassert = sunxi_reset_deassert,
 };
 
-static int sunxi_reset_of_to_plat(struct udevice *dev)
-{
-	struct sunxi_reset_plat *plat = dev_get_plat(dev);
-
-	plat->base = dev_read_addr_ptr(dev);
-
-	return 0;
-}
-
-int sunxi_reset_bind(struct udevice *dev)
-{
-	struct udevice *rst_dev;
-	struct sunxi_reset_plat *plat;
-	int ret;
-
-	ret = device_bind_driver_to_node(dev, "sunxi_reset", "reset",
-					 dev_ofnode(dev), &rst_dev);
-	if (ret) {
-		debug("failed to bind sunxi_reset driver (ret=%d)\n", ret);
-		return ret;
-	}
-	plat = malloc(sizeof(struct sunxi_reset_plat));
-	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
-	dev_set_plat(rst_dev, plat);
-
-	return 0;
-}
-
 U_BOOT_DRIVER(sunxi_reset) = {
 	.name		= "sunxi_reset",
 	.id		= UCLASS_RESET,
 	.ops		= &sunxi_reset_ops,
-	.of_to_plat	= sunxi_reset_of_to_plat,
-	.plat_auto	= sizeof(struct sunxi_reset_plat),
 };
diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
index e90e078972..b9587050d9 100644
--- a/include/clk/sunxi.h
+++ b/include/clk/sunxi.h
@@ -82,12 +82,4 @@ struct ccu_plat {
 
 extern struct clk_ops sunxi_clk_ops;
 
-/**
- * sunxi_reset_bind() - reset binding
- *
- * @dev:       reset device
- * Return: 0 success, or error value
- */
-int sunxi_reset_bind(struct udevice *dev);
-
 #endif /* _CLK_SUNXI_H */
-- 
2.35.1


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

* Re: [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (6 preceding siblings ...)
  2022-05-09  5:29 ` [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver Samuel Holland
@ 2022-05-10 23:24 ` Andre Przywara
  2022-05-11 15:48 ` Sean Anderson
  2022-06-28  0:40 ` Andre Przywara
  9 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-05-10 23:24 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:30 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi Samuel,

> This series fixes an issue with out-of-bounds access to the gate array
> (patches 1-2), uses the rearranged array size information to remove a
> bunch of duplicate code (patches 3-4), and then simplifies how the reset
> driver is bound (patches 5-7).
> 
> The original motivation for these changes was adding a driver for the
> legacy A31/A23/A33 PRCM binding (which I will send separately), and
> trying to use OF_PLATDATA in SPL (which did not work out). But I think
> at least some of the cleanup is worth applying on its own.
> 
> Patch 4 is generally the same change I made between v1 and v2 of the
> pinctrl series, using some #ifdefs to share a U_BOOT_DRIVER. It's not
> quite as clean as the pinctrl case, because here the SoC-specific parts
> are in different files, so all of the CCU descriptors have to be global.

so I skimmed over the series and quite like it: the negative diffstat
speaks for itself ;-)
I need to go over each individual patch with more scrutiny (unless
someone beats me to it), but assuming no issues, I am planning on taking
this for the next merge window.

You mention out-of-bounds accesses: did you actually encounter one
with the old or new DTs, that would need fixing now?

Cheers,
Andre

> Samuel Holland (7):
>   clk: sunxi: Store the array sizes in the CCU descriptor
>   clk: sunxi: Prevent out-of-bounds gate array access
>   reset: sunxi: Get the reset count from the CCU descriptor
>   clk: sunxi: Use a single driver for all variants
>   clk: sunxi: Convert driver private data to platform data
>   reset: sunxi: Convert driver private data to platform data
>   reset: sunxi: Reuse the platform data from the clock driver
> 
>  drivers/clk/sunxi/clk_a10.c   |  27 +-----
>  drivers/clk/sunxi/clk_a10s.c  |  27 +-----
>  drivers/clk/sunxi/clk_a23.c   |  27 +-----
>  drivers/clk/sunxi/clk_a31.c   |  25 +----
>  drivers/clk/sunxi/clk_a31_r.c |  29 +-----
>  drivers/clk/sunxi/clk_a64.c   |  25 +----
>  drivers/clk/sunxi/clk_a80.c   |  36 ++------
>  drivers/clk/sunxi/clk_a83t.c  |  25 +----
>  drivers/clk/sunxi/clk_h3.c    |  27 +-----
>  drivers/clk/sunxi/clk_h6.c    |  25 +----
>  drivers/clk/sunxi/clk_h616.c  |  25 +----
>  drivers/clk/sunxi/clk_h6_r.c  |  27 +-----
>  drivers/clk/sunxi/clk_r40.c   |  25 +----
>  drivers/clk/sunxi/clk_sunxi.c | 168 ++++++++++++++++++++++++++++++----
>  drivers/clk/sunxi/clk_v3s.c   |  27 +-----
>  drivers/reset/reset-sunxi.c   |  55 ++---------
>  include/clk/sunxi.h           |  21 +----
>  17 files changed, 208 insertions(+), 413 deletions(-)
> 


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

* Re: [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (7 preceding siblings ...)
  2022-05-10 23:24 ` [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Andre Przywara
@ 2022-05-11 15:48 ` Sean Anderson
  2022-06-28  0:40 ` Andre Przywara
  9 siblings, 0 replies; 19+ messages in thread
From: Sean Anderson @ 2022-05-11 15:48 UTC (permalink / raw)
  To: Samuel Holland, u-boot, Jagan Teki, Andre Przywara, Lukasz Majewski
  Cc: Bin Meng, Heinrich Schuchardt, Maxime Ripard

On 5/9/22 1:29 AM, Samuel Holland wrote:
> This series fixes an issue with out-of-bounds access to the gate array
> (patches 1-2), uses the rearranged array size information to remove a
> bunch of duplicate code (patches 3-4), and then simplifies how the reset
> driver is bound (patches 5-7).
> 
> The original motivation for these changes was adding a driver for the
> legacy A31/A23/A33 PRCM binding (which I will send separately), and
> trying to use OF_PLATDATA in SPL (which did not work out). But I think
> at least some of the cleanup is worth applying on its own.
> 
> Patch 4 is generally the same change I made between v1 and v2 of the
> pinctrl series, using some #ifdefs to share a U_BOOT_DRIVER. It's not
> quite as clean as the pinctrl case, because here the SoC-specific parts
> are in different files, so all of the CCU descriptors have to be global.
> 
> 
> Samuel Holland (7):
>    clk: sunxi: Store the array sizes in the CCU descriptor
>    clk: sunxi: Prevent out-of-bounds gate array access
>    reset: sunxi: Get the reset count from the CCU descriptor
>    clk: sunxi: Use a single driver for all variants
>    clk: sunxi: Convert driver private data to platform data
>    reset: sunxi: Convert driver private data to platform data
>    reset: sunxi: Reuse the platform data from the clock driver
> 
>   drivers/clk/sunxi/clk_a10.c   |  27 +-----
>   drivers/clk/sunxi/clk_a10s.c  |  27 +-----
>   drivers/clk/sunxi/clk_a23.c   |  27 +-----
>   drivers/clk/sunxi/clk_a31.c   |  25 +----
>   drivers/clk/sunxi/clk_a31_r.c |  29 +-----
>   drivers/clk/sunxi/clk_a64.c   |  25 +----
>   drivers/clk/sunxi/clk_a80.c   |  36 ++------
>   drivers/clk/sunxi/clk_a83t.c  |  25 +----
>   drivers/clk/sunxi/clk_h3.c    |  27 +-----
>   drivers/clk/sunxi/clk_h6.c    |  25 +----
>   drivers/clk/sunxi/clk_h616.c  |  25 +----
>   drivers/clk/sunxi/clk_h6_r.c  |  27 +-----
>   drivers/clk/sunxi/clk_r40.c   |  25 +----
>   drivers/clk/sunxi/clk_sunxi.c | 168 ++++++++++++++++++++++++++++++----
>   drivers/clk/sunxi/clk_v3s.c   |  27 +-----
>   drivers/reset/reset-sunxi.c   |  55 ++---------
>   include/clk/sunxi.h           |  21 +----
>   17 files changed, 208 insertions(+), 413 deletions(-)
> 

For this series:

Acked-by: Sean Anderson <seanga2@gmail.com>

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

* Re: [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor
  2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
@ 2022-06-25 17:10   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-25 17:10 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:31 -0500
Samuel Holland <samuel@sholland.org> wrote:

> The reset array size is currently used for bounds checking in the reset
> driver. The same bounds check should really be done in the clock driver.
> 
> Currently, the array size is provided to the reset driver separately
> from the CCU descriptor, which is a bit strange. Let's do this the usual
> way, with the array sizes next to the arrays themselves.

Checked for typos, all fine. Added the F1C100s on the way.

> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Thanks,
Andre

> ---
> 
>  drivers/clk/sunxi/clk_a10.c   | 2 ++
>  drivers/clk/sunxi/clk_a10s.c  | 2 ++
>  drivers/clk/sunxi/clk_a23.c   | 2 ++
>  drivers/clk/sunxi/clk_a31.c   | 2 ++
>  drivers/clk/sunxi/clk_a31_r.c | 2 ++
>  drivers/clk/sunxi/clk_a64.c   | 2 ++
>  drivers/clk/sunxi/clk_a80.c   | 4 ++++
>  drivers/clk/sunxi/clk_a83t.c  | 2 ++
>  drivers/clk/sunxi/clk_h3.c    | 2 ++
>  drivers/clk/sunxi/clk_h6.c    | 2 ++
>  drivers/clk/sunxi/clk_h616.c  | 2 ++
>  drivers/clk/sunxi/clk_h6_r.c  | 2 ++
>  drivers/clk/sunxi/clk_r40.c   | 2 ++
>  drivers/clk/sunxi/clk_v3s.c   | 2 ++
>  include/clk/sunxi.h           | 2 ++
>  15 files changed, 32 insertions(+)
> 
> diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
> index 90b929d3d3..6b58cffc8a 100644
> --- a/drivers/clk/sunxi/clk_a10.c
> +++ b/drivers/clk/sunxi/clk_a10.c
> @@ -65,6 +65,8 @@ static struct ccu_reset a10_resets[] = {
>  static const struct ccu_desc a10_ccu_desc = {
>  	.gates = a10_gates,
>  	.resets = a10_resets,
> +	.num_gates = ARRAY_SIZE(a10_gates),
> +	.num_resets = ARRAY_SIZE(a10_resets),
>  };
>  
>  static int a10_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
> index addf4f4d5c..81b146ce1e 100644
> --- a/drivers/clk/sunxi/clk_a10s.c
> +++ b/drivers/clk/sunxi/clk_a10s.c
> @@ -50,6 +50,8 @@ static struct ccu_reset a10s_resets[] = {
>  static const struct ccu_desc a10s_ccu_desc = {
>  	.gates = a10s_gates,
>  	.resets = a10s_resets,
> +	.num_gates = ARRAY_SIZE(a10s_gates),
> +	.num_resets = ARRAY_SIZE(a10s_resets),
>  };
>  
>  static int a10s_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
> index c45d2c3529..c7c78bc7d8 100644
> --- a/drivers/clk/sunxi/clk_a23.c
> +++ b/drivers/clk/sunxi/clk_a23.c
> @@ -69,6 +69,8 @@ static struct ccu_reset a23_resets[] = {
>  static const struct ccu_desc a23_ccu_desc = {
>  	.gates = a23_gates,
>  	.resets = a23_resets,
> +	.num_gates = ARRAY_SIZE(a23_gates),
> +	.num_resets = ARRAY_SIZE(a23_resets),
>  };
>  
>  static int a23_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
> index 251fc3b705..c8c7f4ecf5 100644
> --- a/drivers/clk/sunxi/clk_a31.c
> +++ b/drivers/clk/sunxi/clk_a31.c
> @@ -90,6 +90,8 @@ static struct ccu_reset a31_resets[] = {
>  static const struct ccu_desc a31_ccu_desc = {
>  	.gates = a31_gates,
>  	.resets = a31_resets,
> +	.num_gates = ARRAY_SIZE(a31_gates),
> +	.num_resets = ARRAY_SIZE(a31_resets),
>  };
>  
>  static int a31_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
> index 1f08ea956f..7bf1c4578c 100644
> --- a/drivers/clk/sunxi/clk_a31_r.c
> +++ b/drivers/clk/sunxi/clk_a31_r.c
> @@ -31,6 +31,8 @@ static struct ccu_reset a31_r_resets[] = {
>  static const struct ccu_desc a31_r_ccu_desc = {
>  	.gates = a31_r_gates,
>  	.resets = a31_r_resets,
> +	.num_gates = ARRAY_SIZE(a31_r_gates),
> +	.num_resets = ARRAY_SIZE(a31_r_resets),
>  };
>  
>  static int a31_r_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
> index 1004a79503..6da861ddc1 100644
> --- a/drivers/clk/sunxi/clk_a64.c
> +++ b/drivers/clk/sunxi/clk_a64.c
> @@ -76,6 +76,8 @@ static const struct ccu_reset a64_resets[] = {
>  static const struct ccu_desc a64_ccu_desc = {
>  	.gates = a64_gates,
>  	.resets = a64_resets,
> +	.num_gates = ARRAY_SIZE(a64_gates),
> +	.num_resets = ARRAY_SIZE(a64_resets),
>  };
>  
>  static int a64_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
> index 8a0834d83a..7025d3cbe6 100644
> --- a/drivers/clk/sunxi/clk_a80.c
> +++ b/drivers/clk/sunxi/clk_a80.c
> @@ -75,11 +75,15 @@ static const struct ccu_reset a80_mmc_resets[] = {
>  static const struct ccu_desc a80_ccu_desc = {
>  	.gates = a80_gates,
>  	.resets = a80_resets,
> +	.num_gates = ARRAY_SIZE(a80_gates),
> +	.num_resets = ARRAY_SIZE(a80_resets),
>  };
>  
>  static const struct ccu_desc a80_mmc_clk_desc = {
>  	.gates = a80_mmc_gates,
>  	.resets = a80_mmc_resets,
> +	.num_gates = ARRAY_SIZE(a80_mmc_gates),
> +	.num_resets = ARRAY_SIZE(a80_mmc_resets),
>  };
>  
>  static int a80_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
> index 8c6043f51e..c50d253f84 100644
> --- a/drivers/clk/sunxi/clk_a83t.c
> +++ b/drivers/clk/sunxi/clk_a83t.c
> @@ -73,6 +73,8 @@ static struct ccu_reset a83t_resets[] = {
>  static const struct ccu_desc a83t_ccu_desc = {
>  	.gates = a83t_gates,
>  	.resets = a83t_resets,
> +	.num_gates = ARRAY_SIZE(a83t_gates),
> +	.num_resets = ARRAY_SIZE(a83t_resets),
>  };
>  
>  static int a83t_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
> index 59afba53ee..22c2b236a8 100644
> --- a/drivers/clk/sunxi/clk_h3.c
> +++ b/drivers/clk/sunxi/clk_h3.c
> @@ -89,6 +89,8 @@ static struct ccu_reset h3_resets[] = {
>  static const struct ccu_desc h3_ccu_desc = {
>  	.gates = h3_gates,
>  	.resets = h3_resets,
> +	.num_gates = ARRAY_SIZE(h3_gates),
> +	.num_resets = ARRAY_SIZE(h3_resets),
>  };
>  
>  static int h3_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
> index 4a53788352..6521811215 100644
> --- a/drivers/clk/sunxi/clk_h6.c
> +++ b/drivers/clk/sunxi/clk_h6.c
> @@ -90,6 +90,8 @@ static struct ccu_reset h6_resets[] = {
>  static const struct ccu_desc h6_ccu_desc = {
>  	.gates = h6_gates,
>  	.resets = h6_resets,
> +	.num_gates = ARRAY_SIZE(h6_gates),
> +	.num_resets = ARRAY_SIZE(h6_resets),
>  };
>  
>  static int h6_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
> index af97d3bb9f..26f74c0fa0 100644
> --- a/drivers/clk/sunxi/clk_h616.c
> +++ b/drivers/clk/sunxi/clk_h616.c
> @@ -108,6 +108,8 @@ static struct ccu_reset h616_resets[] = {
>  static const struct ccu_desc h616_ccu_desc = {
>  	.gates = h616_gates,
>  	.resets = h616_resets,
> +	.num_gates = ARRAY_SIZE(h616_gates),
> +	.num_resets = ARRAY_SIZE(h616_resets),
>  };
>  
>  static int h616_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
> index b9e527e16a..fee9604551 100644
> --- a/drivers/clk/sunxi/clk_h6_r.c
> +++ b/drivers/clk/sunxi/clk_h6_r.c
> @@ -35,6 +35,8 @@ static struct ccu_reset h6_r_resets[] = {
>  static const struct ccu_desc h6_r_ccu_desc = {
>  	.gates = h6_r_gates,
>  	.resets = h6_r_resets,
> +	.num_gates = ARRAY_SIZE(h6_r_gates),
> +	.num_resets = ARRAY_SIZE(h6_r_resets),
>  };
>  
>  static int h6_r_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
> index 4d5b69a976..456a38a159 100644
> --- a/drivers/clk/sunxi/clk_r40.c
> +++ b/drivers/clk/sunxi/clk_r40.c
> @@ -100,6 +100,8 @@ static struct ccu_reset r40_resets[] = {
>  static const struct ccu_desc r40_ccu_desc = {
>  	.gates = r40_gates,
>  	.resets = r40_resets,
> +	.num_gates = ARRAY_SIZE(r40_gates),
> +	.num_resets = ARRAY_SIZE(r40_resets),
>  };
>  
>  static int r40_clk_bind(struct udevice *dev)
> diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
> index cce5c658ca..ab21cd791b 100644
> --- a/drivers/clk/sunxi/clk_v3s.c
> +++ b/drivers/clk/sunxi/clk_v3s.c
> @@ -50,6 +50,8 @@ static struct ccu_reset v3s_resets[] = {
>  static const struct ccu_desc v3s_ccu_desc = {
>  	.gates = v3s_gates,
>  	.resets = v3s_resets,
> +	.num_gates = ARRAY_SIZE(v3s_gates),
> +	.num_resets = ARRAY_SIZE(v3s_resets),
>  };
>  
>  static int v3s_clk_bind(struct udevice *dev)
> diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
> index a2239b990b..5471b9c831 100644
> --- a/include/clk/sunxi.h
> +++ b/include/clk/sunxi.h
> @@ -65,6 +65,8 @@ struct ccu_reset {
>  struct ccu_desc {
>  	const struct ccu_clk_gate *gates;
>  	const struct ccu_reset *resets;
> +	u8 num_gates;
> +	u8 num_resets;
>  };
>  
>  /**


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

* Re: [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access
  2022-05-09  5:29 ` [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access Samuel Holland
@ 2022-06-26 10:43   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-26 10:43 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:32 -0500
Samuel Holland <samuel@sholland.org> wrote:

> Because the gate arrays are not given explicit sizes, the arrays are
> only as large as the highest-numbered gate described in the driver.
> However, only a subset of the CCU clocks are needed by U-Boot. So there
> are valid clock specifiers with indexes greater than the size of the
> arrays. Referencing any of these clocks causes out-of-bounds access.
> Fix this by checking the identifier against the size of the array.
> 
> Fixes: 0d47bc705651 ("clk: Add Allwinner A64 CLK driver")
> Signed-off-by: Samuel Holland <samuel@sholland.org>

That's a good addition! Amended the patch to cover CCU_CLK_F_DUMMY_GATE.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
> 
>  drivers/clk/sunxi/clk_sunxi.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index 9673b58a49..3108e5b66d 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -18,6 +18,9 @@
>  static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
>  					       unsigned long id)
>  {
> +	if (id >= priv->desc->num_gates)
> +		return NULL;
> +
>  	return &priv->desc->gates[id];
>  }
>  
> @@ -27,7 +30,7 @@ static int sunxi_set_gate(struct clk *clk, bool on)
>  	const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
>  	u32 reg;
>  
> -	if (!(gate->flags & CCU_CLK_F_IS_VALID)) {
> +	if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
>  		printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id);
>  		return 0;
>  	}


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

* Re: [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor
  2022-05-09  5:29 ` [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor Samuel Holland
@ 2022-06-26 10:51   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-26 10:51 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:33 -0500
Samuel Holland <samuel@sholland.org> wrote:

> This allows all of the clock drivers to use a common bind function.

Looks good, and a nice cleanup. Added the F1C100s on the way.

> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Thanks,
Andre

> ---
> 
>  drivers/clk/sunxi/clk_a10.c   |  7 +------
>  drivers/clk/sunxi/clk_a10s.c  |  7 +------
>  drivers/clk/sunxi/clk_a23.c   |  7 +------
>  drivers/clk/sunxi/clk_a31.c   |  7 +------
>  drivers/clk/sunxi/clk_a31_r.c |  7 +------
>  drivers/clk/sunxi/clk_a64.c   |  7 +------
>  drivers/clk/sunxi/clk_a80.c   | 12 +-----------
>  drivers/clk/sunxi/clk_a83t.c  |  7 +------
>  drivers/clk/sunxi/clk_h3.c    |  7 +------
>  drivers/clk/sunxi/clk_h6.c    |  7 +------
>  drivers/clk/sunxi/clk_h616.c  |  7 +------
>  drivers/clk/sunxi/clk_h6_r.c  |  7 +------
>  drivers/clk/sunxi/clk_r40.c   |  7 +------
>  drivers/clk/sunxi/clk_sunxi.c |  5 +++++
>  drivers/clk/sunxi/clk_v3s.c   |  7 +------
>  drivers/reset/reset-sunxi.c   |  6 ++----
>  include/clk/sunxi.h           |  9 +++++++--
>  17 files changed, 28 insertions(+), 95 deletions(-)
> 
> diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
> index 6b58cffc8a..e5374f6cf0 100644
> --- a/drivers/clk/sunxi/clk_a10.c
> +++ b/drivers/clk/sunxi/clk_a10.c
> @@ -69,11 +69,6 @@ static const struct ccu_desc a10_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a10_resets),
>  };
>  
> -static int a10_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a10_resets));
> -}
> -
>  static const struct udevice_id a10_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun4i-a10-ccu",
>  	  .data = (ulong)&a10_ccu_desc },
> @@ -89,5 +84,5 @@ U_BOOT_DRIVER(clk_sun4i_a10) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a10_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
> index 81b146ce1e..07d518c121 100644
> --- a/drivers/clk/sunxi/clk_a10s.c
> +++ b/drivers/clk/sunxi/clk_a10s.c
> @@ -54,11 +54,6 @@ static const struct ccu_desc a10s_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a10s_resets),
>  };
>  
> -static int a10s_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a10s_resets));
> -}
> -
>  static const struct udevice_id a10s_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun5i-a10s-ccu",
>  	  .data = (ulong)&a10s_ccu_desc },
> @@ -74,5 +69,5 @@ U_BOOT_DRIVER(clk_sun5i_a10s) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a10s_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
> index c7c78bc7d8..9c0e5db07c 100644
> --- a/drivers/clk/sunxi/clk_a23.c
> +++ b/drivers/clk/sunxi/clk_a23.c
> @@ -73,11 +73,6 @@ static const struct ccu_desc a23_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a23_resets),
>  };
>  
> -static int a23_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a23_resets));
> -}
> -
>  static const struct udevice_id a23_clk_ids[] = {
>  	{ .compatible = "allwinner,sun8i-a23-ccu",
>  	  .data = (ulong)&a23_ccu_desc },
> @@ -93,5 +88,5 @@ U_BOOT_DRIVER(clk_sun8i_a23) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a23_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
> index c8c7f4ecf5..3d0767e290 100644
> --- a/drivers/clk/sunxi/clk_a31.c
> +++ b/drivers/clk/sunxi/clk_a31.c
> @@ -94,11 +94,6 @@ static const struct ccu_desc a31_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a31_resets),
>  };
>  
> -static int a31_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a31_resets));
> -}
> -
>  static const struct udevice_id a31_clk_ids[] = {
>  	{ .compatible = "allwinner,sun6i-a31-ccu",
>  	  .data = (ulong)&a31_ccu_desc },
> @@ -112,5 +107,5 @@ U_BOOT_DRIVER(clk_sun6i_a31) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a31_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
> index 7bf1c4578c..04c238204d 100644
> --- a/drivers/clk/sunxi/clk_a31_r.c
> +++ b/drivers/clk/sunxi/clk_a31_r.c
> @@ -35,11 +35,6 @@ static const struct ccu_desc a31_r_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a31_r_resets),
>  };
>  
> -static int a31_r_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a31_r_resets));
> -}
> -
>  static const struct udevice_id a31_r_clk_ids[] = {
>  	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
>  	  .data = (ulong)&a31_r_ccu_desc },
> @@ -57,5 +52,5 @@ U_BOOT_DRIVER(clk_sun6i_a31_r) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a31_r_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
> index 6da861ddc1..b41260cbe6 100644
> --- a/drivers/clk/sunxi/clk_a64.c
> +++ b/drivers/clk/sunxi/clk_a64.c
> @@ -80,11 +80,6 @@ static const struct ccu_desc a64_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a64_resets),
>  };
>  
> -static int a64_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a64_resets));
> -}
> -
>  static const struct udevice_id a64_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun50i-a64-ccu",
>  	  .data = (ulong)&a64_ccu_desc },
> @@ -98,5 +93,5 @@ U_BOOT_DRIVER(clk_sun50i_a64) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a64_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
> index 7025d3cbe6..a3ad3b7804 100644
> --- a/drivers/clk/sunxi/clk_a80.c
> +++ b/drivers/clk/sunxi/clk_a80.c
> @@ -86,16 +86,6 @@ static const struct ccu_desc a80_mmc_clk_desc = {
>  	.num_resets = ARRAY_SIZE(a80_mmc_resets),
>  };
>  
> -static int a80_clk_bind(struct udevice *dev)
> -{
> -	ulong count = ARRAY_SIZE(a80_resets);
> -
> -	if (device_is_compatible(dev, "allwinner,sun9i-a80-mmc-config-clk"))
> -		count = ARRAY_SIZE(a80_mmc_resets);
> -
> -	return sunxi_reset_bind(dev, count);
> -}
> -
>  static const struct udevice_id a80_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun9i-a80-ccu",
>  	  .data = (ulong)&a80_ccu_desc },
> @@ -111,5 +101,5 @@ U_BOOT_DRIVER(clk_sun9i_a80) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a80_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
> index c50d253f84..cad5b484cf 100644
> --- a/drivers/clk/sunxi/clk_a83t.c
> +++ b/drivers/clk/sunxi/clk_a83t.c
> @@ -77,11 +77,6 @@ static const struct ccu_desc a83t_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(a83t_resets),
>  };
>  
> -static int a83t_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(a83t_resets));
> -}
> -
>  static const struct udevice_id a83t_clk_ids[] = {
>  	{ .compatible = "allwinner,sun8i-a83t-ccu",
>  	  .data = (ulong)&a83t_ccu_desc },
> @@ -95,5 +90,5 @@ U_BOOT_DRIVER(clk_sun8i_a83t) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= a83t_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
> index 22c2b236a8..3b4e9af111 100644
> --- a/drivers/clk/sunxi/clk_h3.c
> +++ b/drivers/clk/sunxi/clk_h3.c
> @@ -93,11 +93,6 @@ static const struct ccu_desc h3_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(h3_resets),
>  };
>  
> -static int h3_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(h3_resets));
> -}
> -
>  static const struct udevice_id h3_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun8i-h3-ccu",
>  	  .data = (ulong)&h3_ccu_desc },
> @@ -113,5 +108,5 @@ U_BOOT_DRIVER(clk_sun8i_h3) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= h3_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
> index 6521811215..93343b090d 100644
> --- a/drivers/clk/sunxi/clk_h6.c
> +++ b/drivers/clk/sunxi/clk_h6.c
> @@ -94,11 +94,6 @@ static const struct ccu_desc h6_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(h6_resets),
>  };
>  
> -static int h6_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(h6_resets));
> -}
> -
>  static const struct udevice_id h6_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun50i-h6-ccu",
>  	  .data = (ulong)&h6_ccu_desc },
> @@ -112,5 +107,5 @@ U_BOOT_DRIVER(clk_sun50i_h6) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= h6_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
> index 26f74c0fa0..e791736093 100644
> --- a/drivers/clk/sunxi/clk_h616.c
> +++ b/drivers/clk/sunxi/clk_h616.c
> @@ -112,11 +112,6 @@ static const struct ccu_desc h616_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(h616_resets),
>  };
>  
> -static int h616_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(h616_resets));
> -}
> -
>  static const struct udevice_id h616_ccu_ids[] = {
>  	{ .compatible = "allwinner,sun50i-h616-ccu",
>  	  .data = (ulong)&h616_ccu_desc },
> @@ -130,5 +125,5 @@ U_BOOT_DRIVER(clk_sun50i_h616) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= h616_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
> index fee9604551..0f5cefd687 100644
> --- a/drivers/clk/sunxi/clk_h6_r.c
> +++ b/drivers/clk/sunxi/clk_h6_r.c
> @@ -39,11 +39,6 @@ static const struct ccu_desc h6_r_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(h6_r_resets),
>  };
>  
> -static int h6_r_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(h6_r_resets));
> -}
> -
>  static const struct udevice_id h6_r_clk_ids[] = {
>  	{ .compatible = "allwinner,sun50i-h6-r-ccu",
>  	  .data = (ulong)&h6_r_ccu_desc },
> @@ -59,5 +54,5 @@ U_BOOT_DRIVER(clk_sun6i_h6_r) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= h6_r_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
> index 456a38a159..a59ac06975 100644
> --- a/drivers/clk/sunxi/clk_r40.c
> +++ b/drivers/clk/sunxi/clk_r40.c
> @@ -104,11 +104,6 @@ static const struct ccu_desc r40_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(r40_resets),
>  };
>  
> -static int r40_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(r40_resets));
> -}
> -
>  static const struct udevice_id r40_clk_ids[] = {
>  	{ .compatible = "allwinner,sun8i-r40-ccu",
>  	  .data = (ulong)&r40_ccu_desc },
> @@ -122,5 +117,5 @@ U_BOOT_DRIVER(clk_sun8i_r40) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= r40_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index 3108e5b66d..e1129f6ccf 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -64,6 +64,11 @@ struct clk_ops sunxi_clk_ops = {
>  	.disable = sunxi_clk_disable,
>  };
>  
> +int sunxi_clk_bind(struct udevice *dev)
> +{
> +	return sunxi_reset_bind(dev);
> +}
> +
>  int sunxi_clk_probe(struct udevice *dev)
>  {
>  	struct ccu_priv *priv = dev_get_priv(dev);
> diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
> index ab21cd791b..c6a17b4535 100644
> --- a/drivers/clk/sunxi/clk_v3s.c
> +++ b/drivers/clk/sunxi/clk_v3s.c
> @@ -54,11 +54,6 @@ static const struct ccu_desc v3s_ccu_desc = {
>  	.num_resets = ARRAY_SIZE(v3s_resets),
>  };
>  
> -static int v3s_clk_bind(struct udevice *dev)
> -{
> -	return sunxi_reset_bind(dev, ARRAY_SIZE(v3s_resets));
> -}
> -
>  static const struct udevice_id v3s_clk_ids[] = {
>  	{ .compatible = "allwinner,sun8i-v3s-ccu",
>  	  .data = (ulong)&v3s_ccu_desc },
> @@ -74,5 +69,5 @@ U_BOOT_DRIVER(clk_sun8i_v3s) = {
>  	.priv_auto	= sizeof(struct ccu_priv),
>  	.ops		= &sunxi_clk_ops,
>  	.probe		= sunxi_clk_probe,
> -	.bind		= v3s_clk_bind,
> +	.bind		= sunxi_clk_bind,
>  };
> diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
> index 8b95938dfe..4d02d02834 100644
> --- a/drivers/reset/reset-sunxi.c
> +++ b/drivers/reset/reset-sunxi.c
> @@ -19,7 +19,6 @@
>  
>  struct sunxi_reset_priv {
>  	void *base;
> -	ulong count;
>  	const struct ccu_desc *desc;
>  };
>  
> @@ -35,7 +34,7 @@ static int sunxi_reset_request(struct reset_ctl *reset_ctl)
>  
>  	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
>  
> -	if (reset_ctl->id >= priv->count)
> +	if (reset_ctl->id >= priv->desc->num_resets)
>  		return -EINVAL;
>  
>  	return 0;
> @@ -99,7 +98,7 @@ static int sunxi_reset_probe(struct udevice *dev)
>  	return 0;
>  }
>  
> -int sunxi_reset_bind(struct udevice *dev, ulong count)
> +int sunxi_reset_bind(struct udevice *dev)
>  {
>  	struct udevice *rst_dev;
>  	struct sunxi_reset_priv *priv;
> @@ -112,7 +111,6 @@ int sunxi_reset_bind(struct udevice *dev, ulong count)
>  		return ret;
>  	}
>  	priv = malloc(sizeof(struct sunxi_reset_priv));
> -	priv->count = count;
>  	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
>  	dev_set_priv(rst_dev, priv);
>  
> diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
> index 5471b9c831..c798c226f5 100644
> --- a/include/clk/sunxi.h
> +++ b/include/clk/sunxi.h
> @@ -80,6 +80,12 @@ struct ccu_priv {
>  	const struct ccu_desc *desc;
>  };
>  
> +/**
> + * sunxi_clk_bind - common sunxi clock bind
> + * @dev:	clock device
> + */
> +int sunxi_clk_bind(struct udevice *dev);
> +
>  /**
>   * sunxi_clk_probe - common sunxi clock probe
>   * @dev:	clock device
> @@ -92,9 +98,8 @@ extern struct clk_ops sunxi_clk_ops;
>   * sunxi_reset_bind() - reset binding
>   *
>   * @dev:       reset device
> - * @count:     reset count
>   * Return: 0 success, or error value
>   */
> -int sunxi_reset_bind(struct udevice *dev, ulong count);
> +int sunxi_reset_bind(struct udevice *dev);
>  
>  #endif /* _CLK_SUNXI_H */


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

* Re: [PATCH 4/7] clk: sunxi: Use a single driver for all variants
  2022-05-09  5:29 ` [PATCH 4/7] clk: sunxi: Use a single driver for all variants Samuel Holland
@ 2022-06-27  0:43   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-27  0:43 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:34 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi,

> Now that all of the variants use the same bind/probe functions and ops,
> there is no need to have a separate driver for each variant. Since most
> SoCs contain two variants (the main CCU and PRCM CCU), this saves a bit
> of firmware size and RAM.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Nice one, I like that cleanup. Again I added support for the F1C100s.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
> 
>  drivers/clk/sunxi/clk_a10.c   |  20 +-----
>  drivers/clk/sunxi/clk_a10s.c  |  20 +-----
>  drivers/clk/sunxi/clk_a23.c   |  20 +-----
>  drivers/clk/sunxi/clk_a31.c   |  18 +-----
>  drivers/clk/sunxi/clk_a31_r.c |  22 +------
>  drivers/clk/sunxi/clk_a64.c   |  18 +-----
>  drivers/clk/sunxi/clk_a80.c   |  22 +------
>  drivers/clk/sunxi/clk_a83t.c  |  18 +-----
>  drivers/clk/sunxi/clk_h3.c    |  20 +-----
>  drivers/clk/sunxi/clk_h6.c    |  18 +-----
>  drivers/clk/sunxi/clk_h616.c  |  18 +-----
>  drivers/clk/sunxi/clk_h6_r.c  |  20 +-----
>  drivers/clk/sunxi/clk_r40.c   |  18 +-----
>  drivers/clk/sunxi/clk_sunxi.c | 118 +++++++++++++++++++++++++++++++++-
>  drivers/clk/sunxi/clk_v3s.c   |  20 +-----
>  include/clk/sunxi.h           |  12 ----
>  16 files changed, 131 insertions(+), 271 deletions(-)
> 
> diff --git a/drivers/clk/sunxi/clk_a10.c b/drivers/clk/sunxi/clk_a10.c
> index e5374f6cf0..4752a1167b 100644
> --- a/drivers/clk/sunxi/clk_a10.c
> +++ b/drivers/clk/sunxi/clk_a10.c
> @@ -62,27 +62,9 @@ static struct ccu_reset a10_resets[] = {
>  	[RST_USB_PHY2]		= RESET(0x0cc, BIT(2)),
>  };
>  
> -static const struct ccu_desc a10_ccu_desc = {
> +const struct ccu_desc a10_ccu_desc = {
>  	.gates = a10_gates,
>  	.resets = a10_resets,
>  	.num_gates = ARRAY_SIZE(a10_gates),
>  	.num_resets = ARRAY_SIZE(a10_resets),
>  };
> -
> -static const struct udevice_id a10_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun4i-a10-ccu",
> -	  .data = (ulong)&a10_ccu_desc },
> -	{ .compatible = "allwinner,sun7i-a20-ccu",
> -	  .data = (ulong)&a10_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun4i_a10) = {
> -	.name		= "sun4i_a10_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a10_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a10s.c b/drivers/clk/sunxi/clk_a10s.c
> index 07d518c121..9619c5f935 100644
> --- a/drivers/clk/sunxi/clk_a10s.c
> +++ b/drivers/clk/sunxi/clk_a10s.c
> @@ -47,27 +47,9 @@ static struct ccu_reset a10s_resets[] = {
>  	[RST_USB_PHY1]		= RESET(0x0cc, BIT(1)),
>  };
>  
> -static const struct ccu_desc a10s_ccu_desc = {
> +const struct ccu_desc a10s_ccu_desc = {
>  	.gates = a10s_gates,
>  	.resets = a10s_resets,
>  	.num_gates = ARRAY_SIZE(a10s_gates),
>  	.num_resets = ARRAY_SIZE(a10s_resets),
>  };
> -
> -static const struct udevice_id a10s_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun5i-a10s-ccu",
> -	  .data = (ulong)&a10s_ccu_desc },
> -	{ .compatible = "allwinner,sun5i-a13-ccu",
> -	  .data = (ulong)&a10s_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun5i_a10s) = {
> -	.name		= "sun5i_a10s_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a10s_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a23.c b/drivers/clk/sunxi/clk_a23.c
> index 9c0e5db07c..5e19c11c23 100644
> --- a/drivers/clk/sunxi/clk_a23.c
> +++ b/drivers/clk/sunxi/clk_a23.c
> @@ -66,27 +66,9 @@ static struct ccu_reset a23_resets[] = {
>  	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
>  };
>  
> -static const struct ccu_desc a23_ccu_desc = {
> +const struct ccu_desc a23_ccu_desc = {
>  	.gates = a23_gates,
>  	.resets = a23_resets,
>  	.num_gates = ARRAY_SIZE(a23_gates),
>  	.num_resets = ARRAY_SIZE(a23_resets),
>  };
> -
> -static const struct udevice_id a23_clk_ids[] = {
> -	{ .compatible = "allwinner,sun8i-a23-ccu",
> -	  .data = (ulong)&a23_ccu_desc },
> -	{ .compatible = "allwinner,sun8i-a33-ccu",
> -	  .data = (ulong)&a23_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun8i_a23) = {
> -	.name		= "sun8i_a23_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a23_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a31.c b/drivers/clk/sunxi/clk_a31.c
> index 3d0767e290..0aaaaf58ea 100644
> --- a/drivers/clk/sunxi/clk_a31.c
> +++ b/drivers/clk/sunxi/clk_a31.c
> @@ -87,25 +87,9 @@ static struct ccu_reset a31_resets[] = {
>  	[RST_APB2_UART5]	= RESET(0x2d8, BIT(21)),
>  };
>  
> -static const struct ccu_desc a31_ccu_desc = {
> +const struct ccu_desc a31_ccu_desc = {
>  	.gates = a31_gates,
>  	.resets = a31_resets,
>  	.num_gates = ARRAY_SIZE(a31_gates),
>  	.num_resets = ARRAY_SIZE(a31_resets),
>  };
> -
> -static const struct udevice_id a31_clk_ids[] = {
> -	{ .compatible = "allwinner,sun6i-a31-ccu",
> -	  .data = (ulong)&a31_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun6i_a31) = {
> -	.name		= "sun6i_a31_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a31_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a31_r.c b/drivers/clk/sunxi/clk_a31_r.c
> index 04c238204d..fa6887fa75 100644
> --- a/drivers/clk/sunxi/clk_a31_r.c
> +++ b/drivers/clk/sunxi/clk_a31_r.c
> @@ -28,29 +28,9 @@ static struct ccu_reset a31_r_resets[] = {
>  	[RST_APB0_I2C]		= RESET(0x0b0, BIT(6)),
>  };
>  
> -static const struct ccu_desc a31_r_ccu_desc = {
> +const struct ccu_desc a31_r_ccu_desc = {
>  	.gates = a31_r_gates,
>  	.resets = a31_r_resets,
>  	.num_gates = ARRAY_SIZE(a31_r_gates),
>  	.num_resets = ARRAY_SIZE(a31_r_resets),
>  };
> -
> -static const struct udevice_id a31_r_clk_ids[] = {
> -	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
> -	  .data = (ulong)&a31_r_ccu_desc },
> -	{ .compatible = "allwinner,sun8i-h3-r-ccu",
> -	  .data = (ulong)&a31_r_ccu_desc },
> -	{ .compatible = "allwinner,sun50i-a64-r-ccu",
> -	  .data = (ulong)&a31_r_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun6i_a31_r) = {
> -	.name		= "sun6i_a31_r_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a31_r_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
> index b41260cbe6..bd50cd4dda 100644
> --- a/drivers/clk/sunxi/clk_a64.c
> +++ b/drivers/clk/sunxi/clk_a64.c
> @@ -73,25 +73,9 @@ static const struct ccu_reset a64_resets[] = {
>  	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
>  };
>  
> -static const struct ccu_desc a64_ccu_desc = {
> +const struct ccu_desc a64_ccu_desc = {
>  	.gates = a64_gates,
>  	.resets = a64_resets,
>  	.num_gates = ARRAY_SIZE(a64_gates),
>  	.num_resets = ARRAY_SIZE(a64_resets),
>  };
> -
> -static const struct udevice_id a64_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun50i-a64-ccu",
> -	  .data = (ulong)&a64_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun50i_a64) = {
> -	.name		= "sun50i_a64_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a64_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a80.c b/drivers/clk/sunxi/clk_a80.c
> index a3ad3b7804..561380c817 100644
> --- a/drivers/clk/sunxi/clk_a80.c
> +++ b/drivers/clk/sunxi/clk_a80.c
> @@ -72,34 +72,16 @@ static const struct ccu_reset a80_mmc_resets[] = {
>  	[3]			= GATE(0xc, BIT(18)),
>  };
>  
> -static const struct ccu_desc a80_ccu_desc = {
> +const struct ccu_desc a80_ccu_desc = {
>  	.gates = a80_gates,
>  	.resets = a80_resets,
>  	.num_gates = ARRAY_SIZE(a80_gates),
>  	.num_resets = ARRAY_SIZE(a80_resets),
>  };
>  
> -static const struct ccu_desc a80_mmc_clk_desc = {
> +const struct ccu_desc a80_mmc_clk_desc = {
>  	.gates = a80_mmc_gates,
>  	.resets = a80_mmc_resets,
>  	.num_gates = ARRAY_SIZE(a80_mmc_gates),
>  	.num_resets = ARRAY_SIZE(a80_mmc_resets),
>  };
> -
> -static const struct udevice_id a80_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun9i-a80-ccu",
> -	  .data = (ulong)&a80_ccu_desc },
> -	{ .compatible = "allwinner,sun9i-a80-mmc-config-clk",
> -	  .data = (ulong)&a80_mmc_clk_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun9i_a80) = {
> -	.name		= "sun9i_a80_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a80_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_a83t.c b/drivers/clk/sunxi/clk_a83t.c
> index cad5b484cf..e246437af2 100644
> --- a/drivers/clk/sunxi/clk_a83t.c
> +++ b/drivers/clk/sunxi/clk_a83t.c
> @@ -70,25 +70,9 @@ static struct ccu_reset a83t_resets[] = {
>  	[RST_BUS_UART4]		= RESET(0x2d8, BIT(20)),
>  };
>  
> -static const struct ccu_desc a83t_ccu_desc = {
> +const struct ccu_desc a83t_ccu_desc = {
>  	.gates = a83t_gates,
>  	.resets = a83t_resets,
>  	.num_gates = ARRAY_SIZE(a83t_gates),
>  	.num_resets = ARRAY_SIZE(a83t_resets),
>  };
> -
> -static const struct udevice_id a83t_clk_ids[] = {
> -	{ .compatible = "allwinner,sun8i-a83t-ccu",
> -	  .data = (ulong)&a83t_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun8i_a83t) = {
> -	.name		= "sun8i_a83t_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= a83t_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
> index 3b4e9af111..5d2a53185e 100644
> --- a/drivers/clk/sunxi/clk_h3.c
> +++ b/drivers/clk/sunxi/clk_h3.c
> @@ -86,27 +86,9 @@ static struct ccu_reset h3_resets[] = {
>  	[RST_BUS_UART3]		= RESET(0x2d8, BIT(19)),
>  };
>  
> -static const struct ccu_desc h3_ccu_desc = {
> +const struct ccu_desc h3_ccu_desc = {
>  	.gates = h3_gates,
>  	.resets = h3_resets,
>  	.num_gates = ARRAY_SIZE(h3_gates),
>  	.num_resets = ARRAY_SIZE(h3_resets),
>  };
> -
> -static const struct udevice_id h3_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun8i-h3-ccu",
> -	  .data = (ulong)&h3_ccu_desc },
> -	{ .compatible = "allwinner,sun50i-h5-ccu",
> -	  .data = (ulong)&h3_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun8i_h3) = {
> -	.name		= "sun8i_h3_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= h3_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_h6.c b/drivers/clk/sunxi/clk_h6.c
> index 93343b090d..02ba07bdaf 100644
> --- a/drivers/clk/sunxi/clk_h6.c
> +++ b/drivers/clk/sunxi/clk_h6.c
> @@ -87,25 +87,9 @@ static struct ccu_reset h6_resets[] = {
>  	[RST_BUS_OTG]		= RESET(0xa8c, BIT(24)),
>  };
>  
> -static const struct ccu_desc h6_ccu_desc = {
> +const struct ccu_desc h6_ccu_desc = {
>  	.gates = h6_gates,
>  	.resets = h6_resets,
>  	.num_gates = ARRAY_SIZE(h6_gates),
>  	.num_resets = ARRAY_SIZE(h6_resets),
>  };
> -
> -static const struct udevice_id h6_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun50i-h6-ccu",
> -	  .data = (ulong)&h6_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun50i_h6) = {
> -	.name		= "sun50i_h6_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= h6_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
> index e791736093..abcc6fc264 100644
> --- a/drivers/clk/sunxi/clk_h616.c
> +++ b/drivers/clk/sunxi/clk_h616.c
> @@ -105,25 +105,9 @@ static struct ccu_reset h616_resets[] = {
>  	[RST_BUS_OTG]		= RESET(0xa8c, BIT(24)),
>  };
>  
> -static const struct ccu_desc h616_ccu_desc = {
> +const struct ccu_desc h616_ccu_desc = {
>  	.gates = h616_gates,
>  	.resets = h616_resets,
>  	.num_gates = ARRAY_SIZE(h616_gates),
>  	.num_resets = ARRAY_SIZE(h616_resets),
>  };
> -
> -static const struct udevice_id h616_ccu_ids[] = {
> -	{ .compatible = "allwinner,sun50i-h616-ccu",
> -	  .data = (ulong)&h616_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun50i_h616) = {
> -	.name		= "sun50i_h616_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= h616_ccu_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_h6_r.c b/drivers/clk/sunxi/clk_h6_r.c
> index 0f5cefd687..d82f791e79 100644
> --- a/drivers/clk/sunxi/clk_h6_r.c
> +++ b/drivers/clk/sunxi/clk_h6_r.c
> @@ -32,27 +32,9 @@ static struct ccu_reset h6_r_resets[] = {
>  	[RST_R_APB1_W1]		= RESET(0x1ec, BIT(16)),
>  };
>  
> -static const struct ccu_desc h6_r_ccu_desc = {
> +const struct ccu_desc h6_r_ccu_desc = {
>  	.gates = h6_r_gates,
>  	.resets = h6_r_resets,
>  	.num_gates = ARRAY_SIZE(h6_r_gates),
>  	.num_resets = ARRAY_SIZE(h6_r_resets),
>  };
> -
> -static const struct udevice_id h6_r_clk_ids[] = {
> -	{ .compatible = "allwinner,sun50i-h6-r-ccu",
> -	  .data = (ulong)&h6_r_ccu_desc },
> -	{ .compatible = "allwinner,sun50i-h616-r-ccu",
> -	  .data = (ulong)&h6_r_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun6i_h6_r) = {
> -	.name		= "sun6i_h6_r_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= h6_r_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_r40.c b/drivers/clk/sunxi/clk_r40.c
> index a59ac06975..a5b756be40 100644
> --- a/drivers/clk/sunxi/clk_r40.c
> +++ b/drivers/clk/sunxi/clk_r40.c
> @@ -97,25 +97,9 @@ static struct ccu_reset r40_resets[] = {
>  	[RST_BUS_UART7]		= RESET(0x2d8, BIT(23)),
>  };
>  
> -static const struct ccu_desc r40_ccu_desc = {
> +const struct ccu_desc r40_ccu_desc = {
>  	.gates = r40_gates,
>  	.resets = r40_resets,
>  	.num_gates = ARRAY_SIZE(r40_gates),
>  	.num_resets = ARRAY_SIZE(r40_resets),
>  };
> -
> -static const struct udevice_id r40_clk_ids[] = {
> -	{ .compatible = "allwinner,sun8i-r40-ccu",
> -	  .data = (ulong)&r40_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun8i_r40) = {
> -	.name		= "sun8i_r40_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= r40_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index e1129f6ccf..7d9e6029ff 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -64,12 +64,12 @@ struct clk_ops sunxi_clk_ops = {
>  	.disable = sunxi_clk_disable,
>  };
>  
> -int sunxi_clk_bind(struct udevice *dev)
> +static int sunxi_clk_bind(struct udevice *dev)
>  {
>  	return sunxi_reset_bind(dev);
>  }
>  
> -int sunxi_clk_probe(struct udevice *dev)
> +static int sunxi_clk_probe(struct udevice *dev)
>  {
>  	struct ccu_priv *priv = dev_get_priv(dev);
>  	struct clk_bulk clk_bulk;
> @@ -94,3 +94,117 @@ int sunxi_clk_probe(struct udevice *dev)
>  
>  	return 0;
>  }
> +
> +extern const struct ccu_desc a10_ccu_desc;
> +extern const struct ccu_desc a10s_ccu_desc;
> +extern const struct ccu_desc a23_ccu_desc;
> +extern const struct ccu_desc a31_ccu_desc;
> +extern const struct ccu_desc a31_r_ccu_desc;
> +extern const struct ccu_desc a64_ccu_desc;
> +extern const struct ccu_desc a80_ccu_desc;
> +extern const struct ccu_desc a80_mmc_clk_desc;
> +extern const struct ccu_desc a83t_ccu_desc;
> +extern const struct ccu_desc h3_ccu_desc;
> +extern const struct ccu_desc h6_ccu_desc;
> +extern const struct ccu_desc h616_ccu_desc;
> +extern const struct ccu_desc h6_r_ccu_desc;
> +extern const struct ccu_desc r40_ccu_desc;
> +extern const struct ccu_desc v3s_ccu_desc;
> +
> +static const struct udevice_id sunxi_clk_ids[] = {
> +#ifdef CONFIG_CLK_SUN4I_A10
> +	{ .compatible = "allwinner,sun4i-a10-ccu",
> +	  .data = (ulong)&a10_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN5I_A10S
> +	{ .compatible = "allwinner,sun5i-a10s-ccu",
> +	  .data = (ulong)&a10s_ccu_desc },
> +	{ .compatible = "allwinner,sun5i-a13-ccu",
> +	  .data = (ulong)&a10s_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN6I_A31
> +	{ .compatible = "allwinner,sun6i-a31-ccu",
> +	  .data = (ulong)&a31_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN4I_A10
> +	{ .compatible = "allwinner,sun7i-a20-ccu",
> +	  .data = (ulong)&a10_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_A23
> +	{ .compatible = "allwinner,sun8i-a23-ccu",
> +	  .data = (ulong)&a23_ccu_desc },
> +	{ .compatible = "allwinner,sun8i-a33-ccu",
> +	  .data = (ulong)&a23_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_A83T
> +	{ .compatible = "allwinner,sun8i-a83t-ccu",
> +	  .data = (ulong)&a83t_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN6I_A31_R
> +	{ .compatible = "allwinner,sun8i-a83t-r-ccu",
> +	  .data = (ulong)&a31_r_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_H3
> +	{ .compatible = "allwinner,sun8i-h3-ccu",
> +	  .data = (ulong)&h3_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN6I_A31_R
> +	{ .compatible = "allwinner,sun8i-h3-r-ccu",
> +	  .data = (ulong)&a31_r_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_R40
> +	{ .compatible = "allwinner,sun8i-r40-ccu",
> +	  .data = (ulong)&r40_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_V3S
> +	{ .compatible = "allwinner,sun8i-v3-ccu",
> +	  .data = (ulong)&v3s_ccu_desc },
> +	{ .compatible = "allwinner,sun8i-v3s-ccu",
> +	  .data = (ulong)&v3s_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN9I_A80
> +	{ .compatible = "allwinner,sun9i-a80-ccu",
> +	  .data = (ulong)&a80_ccu_desc },
> +	{ .compatible = "allwinner,sun9i-a80-mmc-config-clk",
> +	  .data = (ulong)&a80_mmc_clk_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN50I_A64
> +	{ .compatible = "allwinner,sun50i-a64-ccu",
> +	  .data = (ulong)&a64_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN6I_A31_R
> +	{ .compatible = "allwinner,sun50i-a64-r-ccu",
> +	  .data = (ulong)&a31_r_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN8I_H3
> +	{ .compatible = "allwinner,sun50i-h5-ccu",
> +	  .data = (ulong)&h3_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN50I_H6
> +	{ .compatible = "allwinner,sun50i-h6-ccu",
> +	  .data = (ulong)&h6_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN50I_H6_R
> +	{ .compatible = "allwinner,sun50i-h6-r-ccu",
> +	  .data = (ulong)&h6_r_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN50I_H616
> +	{ .compatible = "allwinner,sun50i-h616-ccu",
> +	  .data = (ulong)&h616_ccu_desc },
> +#endif
> +#ifdef CONFIG_CLK_SUN50I_H6_R
> +	{ .compatible = "allwinner,sun50i-h616-r-ccu",
> +	  .data = (ulong)&h6_r_ccu_desc },
> +#endif
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(sunxi_clk) = {
> +	.name		= "sunxi_clk",
> +	.id		= UCLASS_CLK,
> +	.of_match	= sunxi_clk_ids,
> +	.bind		= sunxi_clk_bind,
> +	.probe		= sunxi_clk_probe,
> +	.priv_auto	= sizeof(struct ccu_priv),
> +	.ops		= &sunxi_clk_ops,
> +};
> diff --git a/drivers/clk/sunxi/clk_v3s.c b/drivers/clk/sunxi/clk_v3s.c
> index c6a17b4535..e632afc083 100644
> --- a/drivers/clk/sunxi/clk_v3s.c
> +++ b/drivers/clk/sunxi/clk_v3s.c
> @@ -47,27 +47,9 @@ static struct ccu_reset v3s_resets[] = {
>  	[RST_BUS_UART2]		= RESET(0x2d8, BIT(18)),
>  };
>  
> -static const struct ccu_desc v3s_ccu_desc = {
> +const struct ccu_desc v3s_ccu_desc = {
>  	.gates = v3s_gates,
>  	.resets = v3s_resets,
>  	.num_gates = ARRAY_SIZE(v3s_gates),
>  	.num_resets = ARRAY_SIZE(v3s_resets),
>  };
> -
> -static const struct udevice_id v3s_clk_ids[] = {
> -	{ .compatible = "allwinner,sun8i-v3s-ccu",
> -	  .data = (ulong)&v3s_ccu_desc },
> -	{ .compatible = "allwinner,sun8i-v3-ccu",
> -	  .data = (ulong)&v3s_ccu_desc },
> -	{ }
> -};
> -
> -U_BOOT_DRIVER(clk_sun8i_v3s) = {
> -	.name		= "sun8i_v3s_ccu",
> -	.id		= UCLASS_CLK,
> -	.of_match	= v3s_clk_ids,
> -	.priv_auto	= sizeof(struct ccu_priv),
> -	.ops		= &sunxi_clk_ops,
> -	.probe		= sunxi_clk_probe,
> -	.bind		= sunxi_clk_bind,
> -};
> diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
> index c798c226f5..11caf12b17 100644
> --- a/include/clk/sunxi.h
> +++ b/include/clk/sunxi.h
> @@ -80,18 +80,6 @@ struct ccu_priv {
>  	const struct ccu_desc *desc;
>  };
>  
> -/**
> - * sunxi_clk_bind - common sunxi clock bind
> - * @dev:	clock device
> - */
> -int sunxi_clk_bind(struct udevice *dev);
> -
> -/**
> - * sunxi_clk_probe - common sunxi clock probe
> - * @dev:	clock device
> - */
> -int sunxi_clk_probe(struct udevice *dev);
> -
>  extern struct clk_ops sunxi_clk_ops;
>  
>  /**


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

* Re: [PATCH 5/7] clk: sunxi: Convert driver private data to platform data
  2022-05-09  5:29 ` [PATCH 5/7] clk: sunxi: Convert driver private data to platform data Samuel Holland
@ 2022-06-27 19:34   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-27 19:34 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:35 -0500
Samuel Holland <samuel@sholland.org> wrote:

> All of the driver private data should really be platform data since it
> is determined statically (selected by the compatible string or extracted
> from the devicetree). Move everything to platform data, so it can be
> provided when binding the driver. This is useful for SPL, or for
> instantiating the driver as part of an MFD.

Indeed, nothing in struct ccu_priv is private to the instance (of where
there is really only one anyway).
Confirmed to be mostly s/priv/plat/, the rest looks fine as well.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  drivers/clk/sunxi/clk_sunxi.c | 41 ++++++++++++++++++++---------------
>  include/clk/sunxi.h           |  4 ++--
>  2 files changed, 26 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index 7d9e6029ff..cadfca767b 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -15,19 +15,19 @@
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
>  
> -static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
> +static const struct ccu_clk_gate *plat_to_gate(struct ccu_plat *plat,
>  					       unsigned long id)
>  {
> -	if (id >= priv->desc->num_gates)
> +	if (id >= plat->desc->num_gates)
>  		return NULL;
>  
> -	return &priv->desc->gates[id];
> +	return &plat->desc->gates[id];
>  }
>  
>  static int sunxi_set_gate(struct clk *clk, bool on)
>  {
> -	struct ccu_priv *priv = dev_get_priv(clk->dev);
> -	const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
> +	struct ccu_plat *plat = dev_get_plat(clk->dev);
> +	const struct ccu_clk_gate *gate = plat_to_gate(plat, clk->id);
>  	u32 reg;
>  
>  	if (!gate || !(gate->flags & CCU_CLK_F_IS_VALID)) {
> @@ -38,13 +38,13 @@ static int sunxi_set_gate(struct clk *clk, bool on)
>  	debug("%s: (CLK#%ld) off#0x%x, BIT(%d)\n", __func__,
>  	      clk->id, gate->off, ilog2(gate->bit));
>  
> -	reg = readl(priv->base + gate->off);
> +	reg = readl(plat->base + gate->off);
>  	if (on)
>  		reg |= gate->bit;
>  	else
>  		reg &= ~gate->bit;
>  
> -	writel(reg, priv->base + gate->off);
> +	writel(reg, plat->base + gate->off);
>  
>  	return 0;
>  }
> @@ -71,19 +71,10 @@ static int sunxi_clk_bind(struct udevice *dev)
>  
>  static int sunxi_clk_probe(struct udevice *dev)
>  {
> -	struct ccu_priv *priv = dev_get_priv(dev);
>  	struct clk_bulk clk_bulk;
>  	struct reset_ctl_bulk rst_bulk;
>  	int ret;
>  
> -	priv->base = dev_read_addr_ptr(dev);
> -	if (!priv->base)
> -		return -ENOMEM;
> -
> -	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
> -	if (!priv->desc)
> -		return -EINVAL;
> -
>  	ret = clk_get_bulk(dev, &clk_bulk);
>  	if (!ret)
>  		clk_enable_bulk(&clk_bulk);
> @@ -95,6 +86,21 @@ static int sunxi_clk_probe(struct udevice *dev)
>  	return 0;
>  }
>  
> +static int sunxi_clk_of_to_plat(struct udevice *dev)
> +{
> +	struct ccu_plat *plat = dev_get_plat(dev);
> +
> +	plat->base = dev_read_addr_ptr(dev);
> +	if (!plat->base)
> +		return -ENOMEM;
> +
> +	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
> +	if (!plat->desc)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
>  extern const struct ccu_desc a10_ccu_desc;
>  extern const struct ccu_desc a10s_ccu_desc;
>  extern const struct ccu_desc a23_ccu_desc;
> @@ -205,6 +211,7 @@ U_BOOT_DRIVER(sunxi_clk) = {
>  	.of_match	= sunxi_clk_ids,
>  	.bind		= sunxi_clk_bind,
>  	.probe		= sunxi_clk_probe,
> -	.priv_auto	= sizeof(struct ccu_priv),
> +	.of_to_plat	= sunxi_clk_of_to_plat,
> +	.plat_auto	= sizeof(struct ccu_plat),
>  	.ops		= &sunxi_clk_ops,
>  };
> diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
> index 11caf12b17..e90e078972 100644
> --- a/include/clk/sunxi.h
> +++ b/include/clk/sunxi.h
> @@ -70,12 +70,12 @@ struct ccu_desc {
>  };
>  
>  /**
> - * struct ccu_priv - sunxi clock control unit
> + * struct ccu_plat - sunxi clock control unit platform data
>   *
>   * @base:	base address
>   * @desc:	ccu descriptor
>   */
> -struct ccu_priv {
> +struct ccu_plat {
>  	void *base;
>  	const struct ccu_desc *desc;
>  };


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

* Re: [PATCH 6/7] reset: sunxi: Convert driver private data to platform data
  2022-05-09  5:29 ` [PATCH 6/7] reset: " Samuel Holland
@ 2022-06-27 19:41   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-27 19:41 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:36 -0500
Samuel Holland <samuel@sholland.org> wrote:

> The reason here is the same as the reason for changing the clock driver:
> platform data can be provided when binding the driver.

Yes, that's right. Confirmed to be almost completely s/priv/plat/.

> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
> 
>  drivers/reset/reset-sunxi.c | 36 ++++++++++++++++++------------------
>  1 file changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
> index 4d02d02834..b060d7f5ed 100644
> --- a/drivers/reset/reset-sunxi.c
> +++ b/drivers/reset/reset-sunxi.c
> @@ -17,24 +17,24 @@
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
>  
> -struct sunxi_reset_priv {
> +struct sunxi_reset_plat {
>  	void *base;
>  	const struct ccu_desc *desc;
>  };
>  
> -static const struct ccu_reset *priv_to_reset(struct sunxi_reset_priv *priv,
> +static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
>  					     unsigned long id)
>  {
> -	return	&priv->desc->resets[id];
> +	return	&plat->desc->resets[id];
>  }
>  
>  static int sunxi_reset_request(struct reset_ctl *reset_ctl)
>  {
> -	struct sunxi_reset_priv *priv = dev_get_priv(reset_ctl->dev);
> +	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
>  
>  	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
>  
> -	if (reset_ctl->id >= priv->desc->num_resets)
> +	if (reset_ctl->id >= plat->desc->num_resets)
>  		return -EINVAL;
>  
>  	return 0;
> @@ -49,8 +49,8 @@ static int sunxi_reset_free(struct reset_ctl *reset_ctl)
>  
>  static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
>  {
> -	struct sunxi_reset_priv *priv = dev_get_priv(reset_ctl->dev);
> -	const struct ccu_reset *reset = priv_to_reset(priv, reset_ctl->id);
> +	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
> +	const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
>  	u32 reg;
>  
>  	if (!(reset->flags & CCU_RST_F_IS_VALID)) {
> @@ -61,13 +61,13 @@ static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
>  	debug("%s: (RST#%ld) off#0x%x, BIT(%d)\n", __func__,
>  	      reset_ctl->id, reset->off, ilog2(reset->bit));
>  
> -	reg = readl(priv->base + reset->off);
> +	reg = readl(plat->base + reset->off);
>  	if (on)
>  		reg |= reset->bit;
>  	else
>  		reg &= ~reset->bit;
>  
> -	writel(reg, priv->base + reset->off);
> +	writel(reg, plat->base + reset->off);
>  
>  	return 0;
>  }
> @@ -89,11 +89,11 @@ struct reset_ops sunxi_reset_ops = {
>  	.rst_deassert = sunxi_reset_deassert,
>  };
>  
> -static int sunxi_reset_probe(struct udevice *dev)
> +static int sunxi_reset_of_to_plat(struct udevice *dev)
>  {
> -	struct sunxi_reset_priv *priv = dev_get_priv(dev);
> +	struct sunxi_reset_plat *plat = dev_get_plat(dev);
>  
> -	priv->base = dev_read_addr_ptr(dev);
> +	plat->base = dev_read_addr_ptr(dev);
>  
>  	return 0;
>  }
> @@ -101,7 +101,7 @@ static int sunxi_reset_probe(struct udevice *dev)
>  int sunxi_reset_bind(struct udevice *dev)
>  {
>  	struct udevice *rst_dev;
> -	struct sunxi_reset_priv *priv;
> +	struct sunxi_reset_plat *plat;
>  	int ret;
>  
>  	ret = device_bind_driver_to_node(dev, "sunxi_reset", "reset",
> @@ -110,9 +110,9 @@ int sunxi_reset_bind(struct udevice *dev)
>  		debug("failed to bind sunxi_reset driver (ret=%d)\n", ret);
>  		return ret;
>  	}
> -	priv = malloc(sizeof(struct sunxi_reset_priv));
> -	priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
> -	dev_set_priv(rst_dev, priv);
> +	plat = malloc(sizeof(struct sunxi_reset_plat));
> +	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
> +	dev_set_plat(rst_dev, plat);
>  
>  	return 0;
>  }
> @@ -121,6 +121,6 @@ U_BOOT_DRIVER(sunxi_reset) = {
>  	.name		= "sunxi_reset",
>  	.id		= UCLASS_RESET,
>  	.ops		= &sunxi_reset_ops,
> -	.probe		= sunxi_reset_probe,
> -	.priv_auto	= sizeof(struct sunxi_reset_priv),
> +	.of_to_plat	= sunxi_reset_of_to_plat,
> +	.plat_auto	= sizeof(struct sunxi_reset_plat),
>  };


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

* Re: [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver
  2022-05-09  5:29 ` [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver Samuel Holland
@ 2022-06-27 23:45   ` Andre Przywara
  0 siblings, 0 replies; 19+ messages in thread
From: Andre Przywara @ 2022-06-27 23:45 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:37 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi,

> The clock and reset drivers use the exact same platform data. Simplify
> them by sharing the object. This is safe because the parent device
> (the clock device) always gets its driver model callbacks run first.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

I am not too familiar with U-Boot's DM internals (device_bind()), but
the idea is certainly good, and it seems to work, so I am happy with
that.

Acked-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre


> ---
> 
>  drivers/clk/sunxi/clk_sunxi.c |  7 +++++-
>  drivers/reset/reset-sunxi.c   | 43 +++--------------------------------
>  include/clk/sunxi.h           |  8 -------
>  3 files changed, 9 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
> index cadfca767b..10c5d2f4b6 100644
> --- a/drivers/clk/sunxi/clk_sunxi.c
> +++ b/drivers/clk/sunxi/clk_sunxi.c
> @@ -12,9 +12,12 @@
>  #include <reset.h>
>  #include <asm/io.h>
>  #include <clk/sunxi.h>
> +#include <dm/device-internal.h>
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
>  
> +extern U_BOOT_DRIVER(sunxi_reset);
> +
>  static const struct ccu_clk_gate *plat_to_gate(struct ccu_plat *plat,
>  					       unsigned long id)
>  {
> @@ -66,7 +69,9 @@ struct clk_ops sunxi_clk_ops = {
>  
>  static int sunxi_clk_bind(struct udevice *dev)
>  {
> -	return sunxi_reset_bind(dev);
> +	/* Reuse the platform data for the reset driver. */
> +	return device_bind(dev, DM_DRIVER_REF(sunxi_reset), "reset",
> +			   dev_get_plat(dev), dev_ofnode(dev), NULL);
>  }
>  
>  static int sunxi_clk_probe(struct udevice *dev)
> diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
> index b060d7f5ed..5d4b8dc92f 100644
> --- a/drivers/reset/reset-sunxi.c
> +++ b/drivers/reset/reset-sunxi.c
> @@ -12,17 +12,10 @@
>  #include <reset-uclass.h>
>  #include <asm/io.h>
>  #include <clk/sunxi.h>
> -#include <dm/device-internal.h>
> -#include <dm/lists.h>
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
>  
> -struct sunxi_reset_plat {
> -	void *base;
> -	const struct ccu_desc *desc;
> -};
> -
> -static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
> +static const struct ccu_reset *plat_to_reset(struct ccu_plat *plat,
>  					     unsigned long id)
>  {
>  	return	&plat->desc->resets[id];
> @@ -30,7 +23,7 @@ static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
>  
>  static int sunxi_reset_request(struct reset_ctl *reset_ctl)
>  {
> -	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
> +	struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
>  
>  	debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
>  
> @@ -49,7 +42,7 @@ static int sunxi_reset_free(struct reset_ctl *reset_ctl)
>  
>  static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
>  {
> -	struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
> +	struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
>  	const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
>  	u32 reg;
>  
> @@ -89,38 +82,8 @@ struct reset_ops sunxi_reset_ops = {
>  	.rst_deassert = sunxi_reset_deassert,
>  };
>  
> -static int sunxi_reset_of_to_plat(struct udevice *dev)
> -{
> -	struct sunxi_reset_plat *plat = dev_get_plat(dev);
> -
> -	plat->base = dev_read_addr_ptr(dev);
> -
> -	return 0;
> -}
> -
> -int sunxi_reset_bind(struct udevice *dev)
> -{
> -	struct udevice *rst_dev;
> -	struct sunxi_reset_plat *plat;
> -	int ret;
> -
> -	ret = device_bind_driver_to_node(dev, "sunxi_reset", "reset",
> -					 dev_ofnode(dev), &rst_dev);
> -	if (ret) {
> -		debug("failed to bind sunxi_reset driver (ret=%d)\n", ret);
> -		return ret;
> -	}
> -	plat = malloc(sizeof(struct sunxi_reset_plat));
> -	plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
> -	dev_set_plat(rst_dev, plat);
> -
> -	return 0;
> -}
> -
>  U_BOOT_DRIVER(sunxi_reset) = {
>  	.name		= "sunxi_reset",
>  	.id		= UCLASS_RESET,
>  	.ops		= &sunxi_reset_ops,
> -	.of_to_plat	= sunxi_reset_of_to_plat,
> -	.plat_auto	= sizeof(struct sunxi_reset_plat),
>  };
> diff --git a/include/clk/sunxi.h b/include/clk/sunxi.h
> index e90e078972..b9587050d9 100644
> --- a/include/clk/sunxi.h
> +++ b/include/clk/sunxi.h
> @@ -82,12 +82,4 @@ struct ccu_plat {
>  
>  extern struct clk_ops sunxi_clk_ops;
>  
> -/**
> - * sunxi_reset_bind() - reset binding
> - *
> - * @dev:       reset device
> - * Return: 0 success, or error value
> - */
> -int sunxi_reset_bind(struct udevice *dev);
> -
>  #endif /* _CLK_SUNXI_H */


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

* Re: [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup
  2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
                   ` (8 preceding siblings ...)
  2022-05-11 15:48 ` Sean Anderson
@ 2022-06-28  0:40 ` Andre Przywara
  2022-06-28  2:45   ` Samuel Holland
  9 siblings, 1 reply; 19+ messages in thread
From: Andre Przywara @ 2022-06-28  0:40 UTC (permalink / raw)
  To: Samuel Holland
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

On Mon,  9 May 2022 00:29:30 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi Samuel,

> This series fixes an issue with out-of-bounds access to the gate array
> (patches 1-2), uses the rearranged array size information to remove a
> bunch of duplicate code (patches 3-4), and then simplifies how the reset
> driver is bound (patches 5-7).
> 
> The original motivation for these changes was adding a driver for the
> legacy A31/A23/A33 PRCM binding (which I will send separately), and
> trying to use OF_PLATDATA in SPL (which did not work out). But I think
> at least some of the cleanup is worth applying on its own.
> 
> Patch 4 is generally the same change I made between v1 and v2 of the
> pinctrl series, using some #ifdefs to share a U_BOOT_DRIVER. It's not
> quite as clean as the pinctrl case, because here the SoC-specific parts
> are in different files, so all of the CCU descriptors have to be global.

Many thanks for your work on this!
So I am done with reviewing this series, and as mentioned quite like it
and am fine with it. I added F1C100s support, which got added in U-Boot
meanwhile, and pushed that to sunxi/next:
https://source.denx.de/u-boot/custodians/u-boot-sunxi/-/commits/next/

Can you please have a look and confirm that this is fine? I will then
send the PR in about two weeks time, if nothing breaks.

Cheers,
Andre

> Samuel Holland (7):
>   clk: sunxi: Store the array sizes in the CCU descriptor
>   clk: sunxi: Prevent out-of-bounds gate array access
>   reset: sunxi: Get the reset count from the CCU descriptor
>   clk: sunxi: Use a single driver for all variants
>   clk: sunxi: Convert driver private data to platform data
>   reset: sunxi: Convert driver private data to platform data
>   reset: sunxi: Reuse the platform data from the clock driver
> 
>  drivers/clk/sunxi/clk_a10.c   |  27 +-----
>  drivers/clk/sunxi/clk_a10s.c  |  27 +-----
>  drivers/clk/sunxi/clk_a23.c   |  27 +-----
>  drivers/clk/sunxi/clk_a31.c   |  25 +----
>  drivers/clk/sunxi/clk_a31_r.c |  29 +-----
>  drivers/clk/sunxi/clk_a64.c   |  25 +----
>  drivers/clk/sunxi/clk_a80.c   |  36 ++------
>  drivers/clk/sunxi/clk_a83t.c  |  25 +----
>  drivers/clk/sunxi/clk_h3.c    |  27 +-----
>  drivers/clk/sunxi/clk_h6.c    |  25 +----
>  drivers/clk/sunxi/clk_h616.c  |  25 +----
>  drivers/clk/sunxi/clk_h6_r.c  |  27 +-----
>  drivers/clk/sunxi/clk_r40.c   |  25 +----
>  drivers/clk/sunxi/clk_sunxi.c | 168 ++++++++++++++++++++++++++++++----
>  drivers/clk/sunxi/clk_v3s.c   |  27 +-----
>  drivers/reset/reset-sunxi.c   |  55 ++---------
>  include/clk/sunxi.h           |  21 +----
>  17 files changed, 208 insertions(+), 413 deletions(-)
> 


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

* Re: [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup
  2022-06-28  0:40 ` Andre Przywara
@ 2022-06-28  2:45   ` Samuel Holland
  0 siblings, 0 replies; 19+ messages in thread
From: Samuel Holland @ 2022-06-28  2:45 UTC (permalink / raw)
  To: Andre Przywara
  Cc: u-boot, Jagan Teki, Lukasz Majewski, Sean Anderson, Bin Meng,
	Heinrich Schuchardt, Maxime Ripard

Hi Andre,

On 6/27/22 7:40 PM, Andre Przywara wrote:
> On Mon,  9 May 2022 00:29:30 -0500
> Samuel Holland <samuel@sholland.org> wrote:
> 
> Hi Samuel,
> 
>> This series fixes an issue with out-of-bounds access to the gate array
>> (patches 1-2), uses the rearranged array size information to remove a
>> bunch of duplicate code (patches 3-4), and then simplifies how the reset
>> driver is bound (patches 5-7).
>>
>> The original motivation for these changes was adding a driver for the
>> legacy A31/A23/A33 PRCM binding (which I will send separately), and
>> trying to use OF_PLATDATA in SPL (which did not work out). But I think
>> at least some of the cleanup is worth applying on its own.
>>
>> Patch 4 is generally the same change I made between v1 and v2 of the
>> pinctrl series, using some #ifdefs to share a U_BOOT_DRIVER. It's not
>> quite as clean as the pinctrl case, because here the SoC-specific parts
>> are in different files, so all of the CCU descriptors have to be global.
> 
> Many thanks for your work on this!
> So I am done with reviewing this series, and as mentioned quite like it
> and am fine with it. I added F1C100s support, which got added in U-Boot
> meanwhile, and pushed that to sunxi/next:
> https://source.denx.de/u-boot/custodians/u-boot-sunxi/-/commits/next/
> 
> Can you please have a look and confirm that this is fine? I will then
> send the PR in about two weeks time, if nothing breaks.

Looks good to me, and thanks for taking care of F1C100s. My only trivial comment
is that you left out Sean's ack.

Regards,
Samuel

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

end of thread, other threads:[~2022-06-28  2:45 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  5:29 [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Samuel Holland
2022-05-09  5:29 ` [PATCH 1/7] clk: sunxi: Store the array sizes in the CCU descriptor Samuel Holland
2022-06-25 17:10   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 2/7] clk: sunxi: Prevent out-of-bounds gate array access Samuel Holland
2022-06-26 10:43   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 3/7] reset: sunxi: Get the reset count from the CCU descriptor Samuel Holland
2022-06-26 10:51   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 4/7] clk: sunxi: Use a single driver for all variants Samuel Holland
2022-06-27  0:43   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 5/7] clk: sunxi: Convert driver private data to platform data Samuel Holland
2022-06-27 19:34   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 6/7] reset: " Samuel Holland
2022-06-27 19:41   ` Andre Przywara
2022-05-09  5:29 ` [PATCH 7/7] reset: sunxi: Reuse the platform data from the clock driver Samuel Holland
2022-06-27 23:45   ` Andre Przywara
2022-05-10 23:24 ` [PATCH 0/7] clk: sunxi: Out-of-bounds access fix and driver cleanup Andre Przywara
2022-05-11 15:48 ` Sean Anderson
2022-06-28  0:40 ` Andre Przywara
2022-06-28  2:45   ` Samuel Holland

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.