All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes
@ 2022-06-24 14:18 Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Folks! It has been over four months since the first series submission for
review. Please merge it in.

Short summary regarding this patchset. The series starts from fixing a
wrong semantic of the device managed optional exclusive bulk reset control
getter. Then we suggest a fix of the clocks glitching cause by the Renesas
5P49V6901 chip in some circumstances. Afterwards a few more modifications
are introduced to finally finish the Baikal-T1 CCU unit support up and
prepare the code before adding the Baikal-T1 PCIe/xGMAC support. First of
all it turned out I specified wrong DW xGMAC PTP reference clock divider
in my initial patches. It must be 8, not 10. Secondly I was wrong to add a
joint xGMAC Ref and PTP clock instead of having them separately defined.
The SoC manual describes these clocks as separate fixed clock wrappers.
Finally in order to close the SoC clock/reset support up we need to add
the DDR and PCIe interfaces reset controls support. It's done in two
steps. First I've moved the reset-controls-related code into a dedicated
module. Then the DDR/PCIe reset-control functionality is added. As the
series finalization we've decided to convert the Baikal-T1 clock/reset
source drivers to mainly being the platform device driver and
pre-initialize the basic clocks only at the early kernel boot stages.

Link: https://lore.kernel.org/linux-pci/20220324010905.15589-1-Sergey.Semin@baikalelectronics.ru/
Changelog v2:
- Resubmit the series with adding @Philipp to the list of the recipients.

Link: https://lore.kernel.org/linux-pci/20220330144320.27039-1-Sergey.Semin@baikalelectronics.ru/
Changelog v3:
- No comments. Just resend the series.
- Rebased from v5.17 onto v5.18-rc3.

Link: https://lore.kernel.org/linux-clk/20220503205722.24755-1-Sergey.Semin@baikalelectronics.ru/
Changelog v4:
- Completely split the CCU Dividers and Resets functionality up. (@Stephen)
- Add a new fixes patch: "clk: baikal-t1: Actually enable SATA internal
  ref clock".
- Add a new fixes patch: "reset: Fix devm bulk optional exclusive control
  getter".
- Add a new fixes patch: "clk: vc5: Fix 5P49V6901 outputs disabling when
  enabling FOD".
- Add a new feagure patch: "clk: baikal-t1: Convert to platform device
  driver".
- Change the internal clock ID to the XGMAC-referred name.
- Rebase onto the kernel v5.18.

Link: https://lore.kernel.org/lkml/20220610072124.8714-1-Sergey.Semin@baikalelectronics.ru/
Changelog v5:
- Just resend.
- Rebase onto the kernel v5.19-rcX.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Cc: Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>
Cc: Pavel Parkhomenko <Pavel.Parkhomenko@baikalelectronics.ru>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-clk@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Serge Semin (8):
  reset: Fix devm bulk optional exclusive control getter
  clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD
  clk: baikal-t1: Fix invalid xGMAC PTP clock divider
  clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent
  clk: baikal-t1: Add SATA internal ref clock buffer
  clk: baikal-t1: Move reset-controls code into a dedicated module
  clk: baikal-t1: Add DDR/PCIe directly controlled resets support
  clk: baikal-t1: Convert to platform device driver

 drivers/clk/baikal-t1/Kconfig       |  12 +-
 drivers/clk/baikal-t1/Makefile      |   1 +
 drivers/clk/baikal-t1/ccu-div.c     |  84 +++++++--
 drivers/clk/baikal-t1/ccu-div.h     |  17 +-
 drivers/clk/baikal-t1/ccu-pll.h     |   8 +
 drivers/clk/baikal-t1/ccu-rst.c     |  99 ++++++++++
 drivers/clk/baikal-t1/ccu-rst.h     |  79 ++++++++
 drivers/clk/baikal-t1/clk-ccu-div.c | 272 +++++++++++++++++-----------
 drivers/clk/baikal-t1/clk-ccu-pll.c | 128 ++++++++++---
 drivers/clk/baikal-t1/clk-ccu-rst.c | 257 ++++++++++++++++++++++++++
 drivers/clk/clk-versaclock5.c       |   2 +-
 include/dt-bindings/reset/bt1-ccu.h |   9 +
 include/linux/reset.h               |   2 +-
 13 files changed, 814 insertions(+), 156 deletions(-)
 create mode 100644 drivers/clk/baikal-t1/ccu-rst.c
 create mode 100644 drivers/clk/baikal-t1/ccu-rst.h
 create mode 100644 drivers/clk/baikal-t1/clk-ccu-rst.c

-- 
2.35.1


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

* [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-26 22:35   ` Dmitry Osipenko
  2022-06-29 14:02   ` Philipp Zabel
  2022-06-24 14:18 ` [PATCH RESEND v5 2/8] clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD Serge Semin
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette, Dmitry Osipenko,
	Mark Brown
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Most likely due to copy-paste mistake the device managed version of the
denoted reset control getter has been implemented with invalid semantic,
which can be immediately spotted by having "WARN_ON(shared && acquired)"
warning in the system log as soon as the method is called. Anyway let's
fix it by altering the boolean arguments passed to the
__devm_reset_control_bulk_get() method from
- shared = true, optional = false, acquired = true
to
+ shared = false, optional = true, acquired = true
That's what they were supposed to be in the first place (see the non-devm
version of the same method: reset_control_bulk_get_optional_exclusive()).

Fixes: 48d71395896d ("reset: Add reset_control_bulk API")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

---

Changelog v4:
- This is a new patch added on v4 lap of the series.
---
 include/linux/reset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/reset.h b/include/linux/reset.h
index 8a21b5756c3e..514ddf003efc 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -731,7 +731,7 @@ static inline int __must_check
 devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
 					       struct reset_control_bulk_data *rstcs)
 {
-	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, true);
+	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
 }
 
 /**
-- 
2.35.1


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

* [PATCH RESEND v5 2/8] clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 3/8] clk: baikal-t1: Fix invalid xGMAC PTP clock divider Serge Semin
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette, Luca Ceresoli,
	Marek Vasut
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel,
	Stephen Boyd

We have discovered random glitches during the system boot up procedure.
The problem investigation led us to the weird outcomes: when none of the
Renesas 5P49V6901 ports are explicitly enabled by the kernel driver, the
glitches disappeared. It was a mystery since the SoC external clock
domains were fed with different 5P49V6901 outputs. The driver code didn't
seem like bogus either. We almost despaired to find out a root cause when
the solution has been found for a more modern revision of the chip. It
turned out the 5P49V6901 clock generator stopped its output for a short
period of time during the VC5_OUT_DIV_CONTROL register writing. The same
problem was found for the 5P49V6965 revision of the chip and was
successfully fixed in commit fc336ae622df ("clk: vc5: fix output disabling
when enabling a FOD") by enabling the "bypass_sync" flag hidden inside
"Unused Factory Reserved Register". Even though the 5P49V6901 registers
description and programming guide doesn't provide any intel regarding that
flag, setting it up anyway in the officially unused register completely
eliminated the denoted glitches. Thus let's activate the functionality
submitted in commit fc336ae622df ("clk: vc5: fix output disabling when
enabling a FOD") for the Renesas 5P49V6901 chip too in order to remove the
ports implicit inter-dependency.

Fixes: dbf6b16f5683 ("clk: vc5: Add support for IDT VersaClock 5P49V6901")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>

---

Changelog v4:
- This is a new patch added on v4 lap of the series.

Changelog v5:
- Fix some grammar mistakes in the commit log. (@Sergey Shtylyov)
---
 drivers/clk/clk-versaclock5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c
index e7be3e54b9be..03cfef494b49 100644
--- a/drivers/clk/clk-versaclock5.c
+++ b/drivers/clk/clk-versaclock5.c
@@ -1204,7 +1204,7 @@ static const struct vc5_chip_info idt_5p49v6901_info = {
 	.model = IDT_VC6_5P49V6901,
 	.clk_fod_cnt = 4,
 	.clk_out_cnt = 5,
-	.flags = VC5_HAS_PFD_FREQ_DBL,
+	.flags = VC5_HAS_PFD_FREQ_DBL | VC5_HAS_BYPASS_SYNC_BIT,
 };
 
 static const struct vc5_chip_info idt_5p49v6965_info = {
-- 
2.35.1


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

* [PATCH RESEND v5 3/8] clk: baikal-t1: Fix invalid xGMAC PTP clock divider
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 2/8] clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 4/8] clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent Serge Semin
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Most likely due to copy-paste mistake the divider has been set to 10 while
according to the SoC reference manual it's supposed to be 8 thus having
PTP clock frequency of 156.25 MHz.

Fixes: 353afa3a8d2e ("clk: Add Baikal-T1 CCU Dividers driver")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
---
 drivers/clk/baikal-t1/clk-ccu-div.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/baikal-t1/clk-ccu-div.c b/drivers/clk/baikal-t1/clk-ccu-div.c
index f141fda12b09..ea77eec40ddd 100644
--- a/drivers/clk/baikal-t1/clk-ccu-div.c
+++ b/drivers/clk/baikal-t1/clk-ccu-div.c
@@ -207,7 +207,7 @@ static const struct ccu_div_info sys_info[] = {
 	CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk",
 			  "eth_clk", CCU_SYS_XGMAC_BASE, 8),
 	CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_PTP_CLK, "sys_xgmac_ptp_clk",
-			   "eth_clk", 10),
+			   "eth_clk", 8),
 	CCU_DIV_GATE_INFO(CCU_SYS_USB_CLK, "sys_usb_clk",
 			  "eth_clk", CCU_SYS_USB_BASE, 10),
 	CCU_DIV_VAR_INFO(CCU_SYS_PVT_CLK, "sys_pvt_clk",
-- 
2.35.1


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

* [PATCH RESEND v5 4/8] clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
                   ` (2 preceding siblings ...)
  2022-06-24 14:18 ` [PATCH RESEND v5 3/8] clk: baikal-t1: Fix invalid xGMAC PTP clock divider Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 5/8] clk: baikal-t1: Add SATA internal ref clock buffer Serge Semin
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Baikal-T1 CCU reference manual says that both xGMAC reference and xGMAC
PTP clocks are generated by two different wrappers with the same constant
divider thus each producing a 156.25 MHz signal. But for some reason both
of these clock sources are gated by a single switch-flag in the CCU
registers space - CCU_SYS_XGMAC_BASE.BIT(0). In order to make the clocks
handled independently we need to define a shared parental gate so the base
clock signal would be switched off only if both of the child-clocks are
disabled.

Note the ID is intentionally set to -2 since we are going to add a one
more internal clock identifier in the next commit.

Fixes: 353afa3a8d2e ("clk: Add Baikal-T1 CCU Dividers driver")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

---

Changelog v4:
- Change the ID macro name to the more descriptive CCU_SYS_XGMAC_CLK.
---
 drivers/clk/baikal-t1/ccu-div.c     | 1 +
 drivers/clk/baikal-t1/ccu-div.h     | 6 ++++++
 drivers/clk/baikal-t1/clk-ccu-div.c | 8 +++++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/baikal-t1/ccu-div.c b/drivers/clk/baikal-t1/ccu-div.c
index 4062092d67f9..bbfa3526ee10 100644
--- a/drivers/clk/baikal-t1/ccu-div.c
+++ b/drivers/clk/baikal-t1/ccu-div.c
@@ -579,6 +579,7 @@ struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *div_init)
 		goto err_free_div;
 	}
 	parent_data.fw_name = div_init->parent_name;
+	parent_data.name = div_init->parent_name;
 	hw_init.parent_data = &parent_data;
 	hw_init.num_parents = 1;
 
diff --git a/drivers/clk/baikal-t1/ccu-div.h b/drivers/clk/baikal-t1/ccu-div.h
index 795665caefbd..b6a9c8e45318 100644
--- a/drivers/clk/baikal-t1/ccu-div.h
+++ b/drivers/clk/baikal-t1/ccu-div.h
@@ -13,6 +13,12 @@
 #include <linux/bits.h>
 #include <linux/of.h>
 
+/*
+ * CCU Divider private clock IDs
+ * @CCU_SYS_XGMAC_CLK: CCU XGMAC internal clock
+ */
+#define CCU_SYS_XGMAC_CLK		-2
+
 /*
  * CCU Divider private flags
  * @CCU_DIV_SKIP_ONE: Due to some reason divider can't be set to 1.
diff --git a/drivers/clk/baikal-t1/clk-ccu-div.c b/drivers/clk/baikal-t1/clk-ccu-div.c
index ea77eec40ddd..3953ae5664be 100644
--- a/drivers/clk/baikal-t1/clk-ccu-div.c
+++ b/drivers/clk/baikal-t1/clk-ccu-div.c
@@ -204,10 +204,12 @@ static const struct ccu_div_info sys_info[] = {
 			  "eth_clk", CCU_SYS_GMAC1_BASE, 5),
 	CCU_DIV_FIXED_INFO(CCU_SYS_GMAC1_PTP_CLK, "sys_gmac1_ptp_clk",
 			   "eth_clk", 10),
-	CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk",
-			  "eth_clk", CCU_SYS_XGMAC_BASE, 8),
+	CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_CLK, "sys_xgmac_clk",
+			  "eth_clk", CCU_SYS_XGMAC_BASE, 1),
+	CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk",
+			   "sys_xgmac_clk", 8),
 	CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_PTP_CLK, "sys_xgmac_ptp_clk",
-			   "eth_clk", 8),
+			   "sys_xgmac_clk", 8),
 	CCU_DIV_GATE_INFO(CCU_SYS_USB_CLK, "sys_usb_clk",
 			  "eth_clk", CCU_SYS_USB_BASE, 10),
 	CCU_DIV_VAR_INFO(CCU_SYS_PVT_CLK, "sys_pvt_clk",
-- 
2.35.1


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

* [PATCH RESEND v5 5/8] clk: baikal-t1: Add SATA internal ref clock buffer
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
                   ` (3 preceding siblings ...)
  2022-06-24 14:18 ` [PATCH RESEND v5 4/8] clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module Serge Semin
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

It turns out the internal SATA reference clock signal will stay
unavailable for the SATA interface consumer until the buffer on it's way
is ungated. So aside with having the actual clock divider enabled we need
to ungate a buffer placed on the signal way to the SATA controller (most
likely some rudiment from the initial SoC release). Seeing the switch flag
is placed in the same register as the SATA-ref clock divider at a
non-standard ffset, let's implement it as a separate clock controller with
the set-rate propagation to the parental clock divider wrapper. As such
we'll be able to disable/enable and still change the original clock source
rate.

Fixes: 353afa3a8d2e ("clk: Add Baikal-T1 CCU Dividers driver")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

---

Changelog v4:
- This is a new patch created on v4 lap of the series.
---
 drivers/clk/baikal-t1/ccu-div.c     | 64 +++++++++++++++++++++++++++++
 drivers/clk/baikal-t1/ccu-div.h     |  4 ++
 drivers/clk/baikal-t1/clk-ccu-div.c | 18 +++++++-
 3 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/baikal-t1/ccu-div.c b/drivers/clk/baikal-t1/ccu-div.c
index bbfa3526ee10..a6642f3d33d4 100644
--- a/drivers/clk/baikal-t1/ccu-div.c
+++ b/drivers/clk/baikal-t1/ccu-div.c
@@ -34,6 +34,7 @@
 #define CCU_DIV_CTL_CLKDIV_MASK(_width) \
 	GENMASK((_width) + CCU_DIV_CTL_CLKDIV_FLD - 1, CCU_DIV_CTL_CLKDIV_FLD)
 #define CCU_DIV_CTL_LOCK_SHIFTED	BIT(27)
+#define CCU_DIV_CTL_GATE_REF_BUF	BIT(28)
 #define CCU_DIV_CTL_LOCK_NORMAL		BIT(31)
 
 #define CCU_DIV_RST_DELAY_US		1
@@ -170,6 +171,40 @@ static int ccu_div_gate_is_enabled(struct clk_hw *hw)
 	return !!(val & CCU_DIV_CTL_EN);
 }
 
+static int ccu_div_buf_enable(struct clk_hw *hw)
+{
+	struct ccu_div *div = to_ccu_div(hw);
+	unsigned long flags;
+
+	spin_lock_irqsave(&div->lock, flags);
+	regmap_update_bits(div->sys_regs, div->reg_ctl,
+			   CCU_DIV_CTL_GATE_REF_BUF, 0);
+	spin_unlock_irqrestore(&div->lock, flags);
+
+	return 0;
+}
+
+static void ccu_div_buf_disable(struct clk_hw *hw)
+{
+	struct ccu_div *div = to_ccu_div(hw);
+	unsigned long flags;
+
+	spin_lock_irqsave(&div->lock, flags);
+	regmap_update_bits(div->sys_regs, div->reg_ctl,
+			   CCU_DIV_CTL_GATE_REF_BUF, CCU_DIV_CTL_GATE_REF_BUF);
+	spin_unlock_irqrestore(&div->lock, flags);
+}
+
+static int ccu_div_buf_is_enabled(struct clk_hw *hw)
+{
+	struct ccu_div *div = to_ccu_div(hw);
+	u32 val = 0;
+
+	regmap_read(div->sys_regs, div->reg_ctl, &val);
+
+	return !(val & CCU_DIV_CTL_GATE_REF_BUF);
+}
+
 static unsigned long ccu_div_var_recalc_rate(struct clk_hw *hw,
 					     unsigned long parent_rate)
 {
@@ -323,6 +358,7 @@ static const struct ccu_div_dbgfs_bit ccu_div_bits[] = {
 	CCU_DIV_DBGFS_BIT_ATTR("div_en", CCU_DIV_CTL_EN),
 	CCU_DIV_DBGFS_BIT_ATTR("div_rst", CCU_DIV_CTL_RST),
 	CCU_DIV_DBGFS_BIT_ATTR("div_bypass", CCU_DIV_CTL_SET_CLKDIV),
+	CCU_DIV_DBGFS_BIT_ATTR("div_buf", CCU_DIV_CTL_GATE_REF_BUF),
 	CCU_DIV_DBGFS_BIT_ATTR("div_lock", CCU_DIV_CTL_LOCK_NORMAL)
 };
 
@@ -441,6 +477,9 @@ static void ccu_div_var_debug_init(struct clk_hw *hw, struct dentry *dentry)
 			continue;
 		}
 
+		if (!strcmp("div_buf", name))
+			continue;
+
 		bits[didx] = ccu_div_bits[bidx];
 		bits[didx].div = div;
 
@@ -477,6 +516,21 @@ static void ccu_div_gate_debug_init(struct clk_hw *hw, struct dentry *dentry)
 				   &ccu_div_dbgfs_fixed_clkdiv_fops);
 }
 
+static void ccu_div_buf_debug_init(struct clk_hw *hw, struct dentry *dentry)
+{
+	struct ccu_div *div = to_ccu_div(hw);
+	struct ccu_div_dbgfs_bit *bit;
+
+	bit = kmalloc(sizeof(*bit), GFP_KERNEL);
+	if (!bit)
+		return;
+
+	*bit = ccu_div_bits[3];
+	bit->div = div;
+	debugfs_create_file_unsafe(bit->name, ccu_div_dbgfs_mode, dentry, bit,
+				   &ccu_div_dbgfs_bit_fops);
+}
+
 static void ccu_div_fixed_debug_init(struct clk_hw *hw, struct dentry *dentry)
 {
 	struct ccu_div *div = to_ccu_div(hw);
@@ -489,6 +543,7 @@ static void ccu_div_fixed_debug_init(struct clk_hw *hw, struct dentry *dentry)
 
 #define ccu_div_var_debug_init NULL
 #define ccu_div_gate_debug_init NULL
+#define ccu_div_buf_debug_init NULL
 #define ccu_div_fixed_debug_init NULL
 
 #endif /* !CONFIG_DEBUG_FS */
@@ -520,6 +575,13 @@ static const struct clk_ops ccu_div_gate_ops = {
 	.debug_init = ccu_div_gate_debug_init
 };
 
+static const struct clk_ops ccu_div_buf_ops = {
+	.enable = ccu_div_buf_enable,
+	.disable = ccu_div_buf_disable,
+	.is_enabled = ccu_div_buf_is_enabled,
+	.debug_init = ccu_div_buf_debug_init
+};
+
 static const struct clk_ops ccu_div_fixed_ops = {
 	.recalc_rate = ccu_div_fixed_recalc_rate,
 	.round_rate = ccu_div_fixed_round_rate,
@@ -566,6 +628,8 @@ struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *div_init)
 	} else if (div_init->type == CCU_DIV_GATE) {
 		hw_init.ops = &ccu_div_gate_ops;
 		div->divider = div_init->divider;
+	} else if (div_init->type == CCU_DIV_BUF) {
+		hw_init.ops = &ccu_div_buf_ops;
 	} else if (div_init->type == CCU_DIV_FIXED) {
 		hw_init.ops = &ccu_div_fixed_ops;
 		div->divider = div_init->divider;
diff --git a/drivers/clk/baikal-t1/ccu-div.h b/drivers/clk/baikal-t1/ccu-div.h
index b6a9c8e45318..4eb49ff4803c 100644
--- a/drivers/clk/baikal-t1/ccu-div.h
+++ b/drivers/clk/baikal-t1/ccu-div.h
@@ -15,8 +15,10 @@
 
 /*
  * CCU Divider private clock IDs
+ * @CCU_SYS_SATA_CLK: CCU SATA internal clock
  * @CCU_SYS_XGMAC_CLK: CCU XGMAC internal clock
  */
+#define CCU_SYS_SATA_CLK		-1
 #define CCU_SYS_XGMAC_CLK		-2
 
 /*
@@ -37,11 +39,13 @@
  * enum ccu_div_type - CCU Divider types
  * @CCU_DIV_VAR: Clocks gate with variable divider.
  * @CCU_DIV_GATE: Clocks gate with fixed divider.
+ * @CCU_DIV_BUF: Clock gate with no divider.
  * @CCU_DIV_FIXED: Ungateable clock with fixed divider.
  */
 enum ccu_div_type {
 	CCU_DIV_VAR,
 	CCU_DIV_GATE,
+	CCU_DIV_BUF,
 	CCU_DIV_FIXED
 };
 
diff --git a/drivers/clk/baikal-t1/clk-ccu-div.c b/drivers/clk/baikal-t1/clk-ccu-div.c
index 3953ae5664be..90f4fda406ee 100644
--- a/drivers/clk/baikal-t1/clk-ccu-div.c
+++ b/drivers/clk/baikal-t1/clk-ccu-div.c
@@ -76,6 +76,16 @@
 		.divider = _divider				\
 	}
 
+#define CCU_DIV_BUF_INFO(_id, _name, _pname, _base, _flags)	\
+	{							\
+		.id = _id,					\
+		.name = _name,					\
+		.parent_name = _pname,				\
+		.base = _base,					\
+		.type = CCU_DIV_BUF,				\
+		.flags = _flags					\
+	}
+
 #define CCU_DIV_FIXED_INFO(_id, _name, _pname, _divider)	\
 	{							\
 		.id = _id,					\
@@ -188,11 +198,14 @@ static const struct ccu_div_rst_map axi_rst_map[] = {
  * for the SoC devices registers IO-operations.
  */
 static const struct ccu_div_info sys_info[] = {
-	CCU_DIV_VAR_INFO(CCU_SYS_SATA_REF_CLK, "sys_sata_ref_clk",
+	CCU_DIV_VAR_INFO(CCU_SYS_SATA_CLK, "sys_sata_clk",
 			 "sata_clk", CCU_SYS_SATA_REF_BASE, 4,
 			 CLK_SET_RATE_GATE,
 			 CCU_DIV_SKIP_ONE | CCU_DIV_LOCK_SHIFTED |
 			 CCU_DIV_RESET_DOMAIN),
+	CCU_DIV_BUF_INFO(CCU_SYS_SATA_REF_CLK, "sys_sata_ref_clk",
+			 "sys_sata_clk", CCU_SYS_SATA_REF_BASE,
+			 CLK_SET_RATE_PARENT),
 	CCU_DIV_VAR_INFO(CCU_SYS_APB_CLK, "sys_apb_clk",
 			 "pcie_clk", CCU_SYS_APB_BASE, 5,
 			 CLK_IS_CRITICAL, CCU_DIV_RESET_DOMAIN),
@@ -398,6 +411,9 @@ static int ccu_div_clk_register(struct ccu_div_data *data)
 			init.base = info->base;
 			init.sys_regs = data->sys_regs;
 			init.divider = info->divider;
+		} else if (init.type == CCU_DIV_BUF) {
+			init.base = info->base;
+			init.sys_regs = data->sys_regs;
 		} else {
 			init.divider = info->divider;
 		}
-- 
2.35.1


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

* [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
                   ` (4 preceding siblings ...)
  2022-06-24 14:18 ` [PATCH RESEND v5 5/8] clk: baikal-t1: Add SATA internal ref clock buffer Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-29 15:12   ` Philipp Zabel
  2022-06-24 14:18 ` [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support Serge Semin
  2022-06-24 14:18 ` [PATCH RESEND v5 8/8] clk: baikal-t1: Convert to platform device driver Serge Semin
  7 siblings, 1 reply; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Before adding the directly controlled resets support it's reasonable to
move the existing resets control functionality into a dedicated object for
the sake of the CCU dividers clock driver simplification. After the new
functionality was added clk-ccu-div.c would have got to a mixture of the
weakly dependent clocks and resets methods. Splitting the methods up into
the two objects will make the code easier to read and maintain. It shall
also improve the code scalability (though hopefully we won't need this
part that much in the future).

As it was done for the CCU PLLs and Dividers the reset control
functionality in its turn has been split up into two sub-modules:
hw-interface and generic reset device description. This commit doesn't
provide any change in the CCU reset module semantics. As before it
supports the trigger-like CCU resets only, which are responsible for the
AXI-bus, APB-bus and SATA-ref blocks reset. The assert/de-assert-capable
reset controls support will be added in the next commit.

Note the CCU Clock dividers and resets functionality split up was possible
due to not having any side-effects (at least we didn't found ones) of the
regmap-based concurrent access of the common CCU dividers/reset CSRs.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

---

Changelog v4:
- Completely split CCU Dividers and Resets functionality. (@Stephen)
---
 drivers/clk/baikal-t1/Kconfig       |  12 +-
 drivers/clk/baikal-t1/Makefile      |   1 +
 drivers/clk/baikal-t1/ccu-div.c     |  19 ---
 drivers/clk/baikal-t1/ccu-div.h     |   4 +-
 drivers/clk/baikal-t1/ccu-rst.c     |  43 +++++
 drivers/clk/baikal-t1/ccu-rst.h     |  67 ++++++++
 drivers/clk/baikal-t1/clk-ccu-div.c | 101 +++---------
 drivers/clk/baikal-t1/clk-ccu-rst.c | 236 ++++++++++++++++++++++++++++
 8 files changed, 384 insertions(+), 99 deletions(-)
 create mode 100644 drivers/clk/baikal-t1/ccu-rst.c
 create mode 100644 drivers/clk/baikal-t1/ccu-rst.h
 create mode 100644 drivers/clk/baikal-t1/clk-ccu-rst.c

diff --git a/drivers/clk/baikal-t1/Kconfig b/drivers/clk/baikal-t1/Kconfig
index 03102f1094bc..56a4ff1d8bf0 100644
--- a/drivers/clk/baikal-t1/Kconfig
+++ b/drivers/clk/baikal-t1/Kconfig
@@ -29,7 +29,6 @@ config CLK_BT1_CCU_PLL
 
 config CLK_BT1_CCU_DIV
 	bool "Baikal-T1 CCU Dividers support"
-	select RESET_CONTROLLER
 	select MFD_SYSCON
 	default MIPS_BAIKAL_T1
 	help
@@ -39,4 +38,15 @@ config CLK_BT1_CCU_DIV
 	  either gateable or ungateable. Some of the CCU dividers can be as well
 	  used to reset the domains they're supplying clock to.
 
+config CLK_BT1_CCU_RST
+	bool "Baikal-T1 CCU Resets support"
+	select RESET_CONTROLLER
+	select MFD_SYSCON
+	default MIPS_BAIKAL_T1
+	help
+	  Enable this to support the CCU reset blocks responsible for the
+	  AXI-bus and some subsystems reset. These are mainly the
+	  sef-deasserted reset controls but there are several lines which
+	  can be directly asserted/de-asserted (PCIe and DDR sub-domains).
+
 endif
diff --git a/drivers/clk/baikal-t1/Makefile b/drivers/clk/baikal-t1/Makefile
index b3b9590b95ed..99e97f168417 100644
--- a/drivers/clk/baikal-t1/Makefile
+++ b/drivers/clk/baikal-t1/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_CLK_BT1_CCU_PLL) += ccu-pll.o clk-ccu-pll.o
 obj-$(CONFIG_CLK_BT1_CCU_DIV) += ccu-div.o clk-ccu-div.o
+obj-$(CONFIG_CLK_BT1_CCU_RST) += ccu-rst.o clk-ccu-rst.o
diff --git a/drivers/clk/baikal-t1/ccu-div.c b/drivers/clk/baikal-t1/ccu-div.c
index a6642f3d33d4..8d5fc7158f33 100644
--- a/drivers/clk/baikal-t1/ccu-div.c
+++ b/drivers/clk/baikal-t1/ccu-div.c
@@ -37,7 +37,6 @@
 #define CCU_DIV_CTL_GATE_REF_BUF	BIT(28)
 #define CCU_DIV_CTL_LOCK_NORMAL		BIT(31)
 
-#define CCU_DIV_RST_DELAY_US		1
 #define CCU_DIV_LOCK_CHECK_RETRIES	50
 
 #define CCU_DIV_CLKDIV_MIN		0
@@ -323,24 +322,6 @@ static int ccu_div_fixed_set_rate(struct clk_hw *hw, unsigned long rate,
 	return 0;
 }
 
-int ccu_div_reset_domain(struct ccu_div *div)
-{
-	unsigned long flags;
-
-	if (!div || !(div->features & CCU_DIV_RESET_DOMAIN))
-		return -EINVAL;
-
-	spin_lock_irqsave(&div->lock, flags);
-	regmap_update_bits(div->sys_regs, div->reg_ctl,
-			   CCU_DIV_CTL_RST, CCU_DIV_CTL_RST);
-	spin_unlock_irqrestore(&div->lock, flags);
-
-	/* The next delay must be enough to cover all the resets. */
-	udelay(CCU_DIV_RST_DELAY_US);
-
-	return 0;
-}
-
 #ifdef CONFIG_DEBUG_FS
 
 struct ccu_div_dbgfs_bit {
diff --git a/drivers/clk/baikal-t1/ccu-div.h b/drivers/clk/baikal-t1/ccu-div.h
index 4eb49ff4803c..ff97bb30fcc3 100644
--- a/drivers/clk/baikal-t1/ccu-div.h
+++ b/drivers/clk/baikal-t1/ccu-div.h
@@ -28,7 +28,7 @@
  * @CCU_DIV_SKIP_ONE_TO_THREE: For some reason divider can't be within [1,3].
  *			       It can be either 0 or greater than 3.
  * @CCU_DIV_LOCK_SHIFTED: Find lock-bit at non-standard position.
- * @CCU_DIV_RESET_DOMAIN: Provide reset clock domain method.
+ * @CCU_DIV_RESET_DOMAIN: There is a clock domain reset handle.
  */
 #define CCU_DIV_SKIP_ONE		BIT(1)
 #define CCU_DIV_SKIP_ONE_TO_THREE	BIT(2)
@@ -115,6 +115,4 @@ struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *init);
 
 void ccu_div_hw_unregister(struct ccu_div *div);
 
-int ccu_div_reset_domain(struct ccu_div *div);
-
 #endif /* __CLK_BT1_CCU_DIV_H__ */
diff --git a/drivers/clk/baikal-t1/ccu-rst.c b/drivers/clk/baikal-t1/ccu-rst.c
new file mode 100644
index 000000000000..b355bf0b399a
--- /dev/null
+++ b/drivers/clk/baikal-t1/ccu-rst.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
+ *
+ * Authors:
+ *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
+ *
+ * Baikal-T1 CCU Resets interface driver
+ */
+
+#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
+
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+#include "ccu-rst.h"
+
+#define CCU_RST_DELAY_US		1
+
+static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx)
+{
+	struct ccu_rst *rst;
+
+	rst = ccu_rst_get_desc(rcdev, idx);
+	if (IS_ERR(rst)) {
+		pr_err("Invalid reset index %lu specified\n", idx);
+		return PTR_ERR(rst);
+	}
+
+	regmap_update_bits(rst->sys_regs, rst->reg_ctl, rst->mask, rst->mask);
+
+	/* The next delay must be enough to cover all the resets. */
+	udelay(CCU_RST_DELAY_US);
+
+	return 0;
+}
+
+const struct reset_control_ops ccu_rst_ops = {
+	.reset = ccu_rst_reset,
+};
diff --git a/drivers/clk/baikal-t1/ccu-rst.h b/drivers/clk/baikal-t1/ccu-rst.h
new file mode 100644
index 000000000000..d03bae4b7a05
--- /dev/null
+++ b/drivers/clk/baikal-t1/ccu-rst.h
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
+ *
+ * Baikal-T1 CCU Resets interface driver
+ */
+#ifndef __CLK_BT1_CCU_RST_H__
+#define __CLK_BT1_CCU_RST_H__
+
+#include <linux/of.h>
+#include <linux/regmap.h>
+
+struct ccu_rst_data;
+
+/*
+ * struct ccu_rst_init_data - CCU Resets initialization data
+ * @sys_regs: Baikal-T1 System Controller registers map.
+ * @np: Pointer to the node with the System CCU block.
+ */
+struct ccu_rst_init_data {
+	struct regmap *sys_regs;
+	struct device_node *np;
+};
+
+/*
+ * struct ccu_rst - CCU Reset descriptor
+ * @id: Reset identifier.
+ * @reg_ctl: Reset control register base address.
+ * @sys_regs: Baikal-T1 System Controller registers map.
+ * @mask: Reset bitmask (normally it's just a single bit flag).
+ */
+struct ccu_rst {
+	unsigned int id;
+	unsigned int reg_ctl;
+	struct regmap *sys_regs;
+	u32 mask;
+};
+
+#ifdef CONFIG_CLK_BT1_CCU_RST
+
+extern const struct reset_control_ops ccu_rst_ops;
+
+struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx);
+
+struct ccu_rst_data *ccu_rst_hw_register(const struct ccu_rst_init_data *init);
+
+void ccu_rst_hw_unregister(struct ccu_rst_data *rcd);
+
+#else
+
+static inline
+struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx)
+{
+	return -EINVAL;
+}
+
+static inline
+struct ccu_rst_data *ccu_rst_hw_register(const struct ccu_rst_init_data *init)
+{
+	return NULL;
+}
+
+static inline void ccu_rst_hw_unregister(struct ccu_rst_data *rcd) {}
+
+#endif
+
+#endif /* __CLK_BT1_CCU_RST_H__ */
diff --git a/drivers/clk/baikal-t1/clk-ccu-div.c b/drivers/clk/baikal-t1/clk-ccu-div.c
index 90f4fda406ee..71e563e28f86 100644
--- a/drivers/clk/baikal-t1/clk-ccu-div.c
+++ b/drivers/clk/baikal-t1/clk-ccu-div.c
@@ -24,9 +24,9 @@
 #include <linux/regmap.h>
 
 #include <dt-bindings/clock/bt1-ccu.h>
-#include <dt-bindings/reset/bt1-ccu.h>
 
 #include "ccu-div.h"
+#include "ccu-rst.h"
 
 #define CCU_AXI_MAIN_BASE		0x030
 #define CCU_AXI_DDR_BASE		0x034
@@ -95,6 +95,21 @@
 		.divider = _divider				\
 	}
 
+#define CCU_DIV_REPAR_INFO(_id, _name, _p0name, _p1name, _base, _divider, _features) \
+	{								\
+		.id = _id,						\
+		.name = _name,						\
+		.pnames = {						\
+			[CCU_DIV_PAR_INT] = _p0name,			\
+			[CCU_DIV_PAR_EXT] = _p1name,			\
+		},							\
+		.base = _base,						\
+		.type = CCU_DIV_REPAR,					\
+		.divider = _divider,					\
+		.flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, \
+		.features = _features,					\
+	}
+
 #define CCU_DIV_RST_MAP(_rst_id, _clk_id)	\
 	{					\
 		.rst_id = _rst_id,		\
@@ -115,11 +130,6 @@ struct ccu_div_info {
 	unsigned long features;
 };
 
-struct ccu_div_rst_map {
-	unsigned int rst_id;
-	unsigned int clk_id;
-};
-
 struct ccu_div_data {
 	struct device_node *np;
 	struct regmap *sys_regs;
@@ -128,11 +138,8 @@ struct ccu_div_data {
 	const struct ccu_div_info *divs_info;
 	struct ccu_div **divs;
 
-	unsigned int rst_num;
-	const struct ccu_div_rst_map *rst_map;
-	struct reset_controller_dev rcdev;
+	struct ccu_rst_data *crd;
 };
-#define to_ccu_div_data(_rcdev) container_of(_rcdev, struct ccu_div_data, rcdev)
 
 /*
  * AXI Main Interconnect (axi_main_clk) and DDR AXI-bus (axi_ddr_clk) clocks
@@ -179,20 +186,6 @@ static const struct ccu_div_info axi_info[] = {
 			 CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN)
 };
 
-static const struct ccu_div_rst_map axi_rst_map[] = {
-	CCU_DIV_RST_MAP(CCU_AXI_MAIN_RST, CCU_AXI_MAIN_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_DDR_RST, CCU_AXI_DDR_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_SATA_RST, CCU_AXI_SATA_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_GMAC0_RST, CCU_AXI_GMAC0_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_GMAC1_RST, CCU_AXI_GMAC1_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_XGMAC_RST, CCU_AXI_XGMAC_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_PCIE_M_RST, CCU_AXI_PCIE_M_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_PCIE_S_RST, CCU_AXI_PCIE_S_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_USB_RST, CCU_AXI_USB_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_HWA_RST, CCU_AXI_HWA_CLK),
-	CCU_DIV_RST_MAP(CCU_AXI_SRAM_RST, CCU_AXI_SRAM_CLK)
-};
-
 /*
  * APB-bus clock is marked as critical since it's a main communication bus
  * for the SoC devices registers IO-operations.
@@ -254,11 +247,6 @@ static const struct ccu_div_info sys_info[] = {
 			 CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE_TO_THREE)
 };
 
-static const struct ccu_div_rst_map sys_rst_map[] = {
-	CCU_DIV_RST_MAP(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_CLK),
-	CCU_DIV_RST_MAP(CCU_SYS_APB_RST, CCU_SYS_APB_CLK),
-};
-
 static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data,
 					 unsigned int clk_id)
 {
@@ -274,42 +262,6 @@ static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data,
 	return ERR_PTR(-EINVAL);
 }
 
-static int ccu_div_reset(struct reset_controller_dev *rcdev,
-			 unsigned long rst_id)
-{
-	struct ccu_div_data *data = to_ccu_div_data(rcdev);
-	const struct ccu_div_rst_map *map;
-	struct ccu_div *div;
-	int idx, ret;
-
-	for (idx = 0, map = data->rst_map; idx < data->rst_num; ++idx, ++map) {
-		if (map->rst_id == rst_id)
-			break;
-	}
-	if (idx == data->rst_num) {
-		pr_err("Invalid reset ID %lu specified\n", rst_id);
-		return -EINVAL;
-	}
-
-	div = ccu_div_find_desc(data, map->clk_id);
-	if (IS_ERR(div)) {
-		pr_err("Invalid clock ID %d in mapping\n", map->clk_id);
-		return PTR_ERR(div);
-	}
-
-	ret = ccu_div_reset_domain(div);
-	if (ret) {
-		pr_err("Reset isn't supported by divider %s\n",
-			clk_hw_get_name(ccu_div_get_clk_hw(div)));
-	}
-
-	return ret;
-}
-
-static const struct reset_control_ops ccu_div_rst_ops = {
-	.reset = ccu_div_reset,
-};
-
 static struct ccu_div_data *ccu_div_create_data(struct device_node *np)
 {
 	struct ccu_div_data *data;
@@ -323,13 +275,9 @@ static struct ccu_div_data *ccu_div_create_data(struct device_node *np)
 	if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) {
 		data->divs_num = ARRAY_SIZE(axi_info);
 		data->divs_info = axi_info;
-		data->rst_num = ARRAY_SIZE(axi_rst_map);
-		data->rst_map = axi_rst_map;
 	} else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) {
 		data->divs_num = ARRAY_SIZE(sys_info);
 		data->divs_info = sys_info;
-		data->rst_num = ARRAY_SIZE(sys_rst_map);
-		data->rst_map = sys_rst_map;
 	} else {
 		pr_err("Incompatible DT node '%s' specified\n",
 			of_node_full_name(np));
@@ -455,18 +403,19 @@ static void ccu_div_clk_unregister(struct ccu_div_data *data)
 
 static int ccu_div_rst_register(struct ccu_div_data *data)
 {
-	int ret;
+	struct ccu_rst_init_data init = {0};
 
-	data->rcdev.ops = &ccu_div_rst_ops;
-	data->rcdev.of_node = data->np;
-	data->rcdev.nr_resets = data->rst_num;
+	init.sys_regs = data->sys_regs;
+	init.np = data->np;
 
-	ret = reset_controller_register(&data->rcdev);
-	if (ret)
+	data->crd = ccu_rst_hw_register(&init);
+	if (IS_ERR(data->crd)) {
 		pr_err("Couldn't register divider '%s' reset controller\n",
 			of_node_full_name(data->np));
+		return PTR_ERR(data->crd);
+	}
 
-	return ret;
+	return 0;
 }
 
 static void ccu_div_init(struct device_node *np)
diff --git a/drivers/clk/baikal-t1/clk-ccu-rst.c b/drivers/clk/baikal-t1/clk-ccu-rst.c
new file mode 100644
index 000000000000..b10857f48b8b
--- /dev/null
+++ b/drivers/clk/baikal-t1/clk-ccu-rst.c
@@ -0,0 +1,236 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
+ *
+ * Authors:
+ *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
+ *
+ * Baikal-T1 CCU Resets domain driver
+ */
+#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
+
+#include <linux/bits.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/printk.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>
+
+#include <dt-bindings/reset/bt1-ccu.h>
+
+#include "ccu-rst.h"
+
+#define CCU_AXI_MAIN_BASE		0x030
+#define CCU_AXI_DDR_BASE		0x034
+#define CCU_AXI_SATA_BASE		0x038
+#define CCU_AXI_GMAC0_BASE		0x03C
+#define CCU_AXI_GMAC1_BASE		0x040
+#define CCU_AXI_XGMAC_BASE		0x044
+#define CCU_AXI_PCIE_M_BASE		0x048
+#define CCU_AXI_PCIE_S_BASE		0x04C
+#define CCU_AXI_USB_BASE		0x050
+#define CCU_AXI_HWA_BASE		0x054
+#define CCU_AXI_SRAM_BASE		0x058
+
+#define CCU_SYS_SATA_REF_BASE		0x060
+#define CCU_SYS_APB_BASE		0x064
+
+#define CCU_RST_TRIG(_id, _base, _ofs)		\
+	{					\
+		.id = _id,			\
+		.base = _base,			\
+		.mask = BIT(_ofs),		\
+	}
+
+struct ccu_rst_info {
+	unsigned int id;
+	unsigned int base;
+	unsigned int mask;
+};
+
+struct ccu_rst_data {
+	struct device_node *np;
+	struct regmap *sys_regs;
+
+	unsigned int rsts_num;
+	const struct ccu_rst_info *rsts_info;
+	struct ccu_rst *rsts;
+
+	struct reset_controller_dev rcdev;
+};
+#define to_ccu_rst_data(_rcdev) container_of(_rcdev, struct ccu_rst_data, rcdev)
+
+/*
+ * Each AXI-bus clock divider is equipped with the corresponding clock-consumer
+ * domain reset (it's self-deasserted reset control).
+ */
+static const struct ccu_rst_info axi_rst_info[] = {
+	CCU_RST_TRIG(CCU_AXI_MAIN_RST, CCU_AXI_MAIN_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_DDR_RST, CCU_AXI_DDR_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_SATA_RST, CCU_AXI_SATA_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_GMAC0_RST, CCU_AXI_GMAC0_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_GMAC1_RST, CCU_AXI_GMAC1_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_XGMAC_RST, CCU_AXI_XGMAC_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_PCIE_M_RST, CCU_AXI_PCIE_M_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_PCIE_S_RST, CCU_AXI_PCIE_S_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_USB_RST, CCU_AXI_USB_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_HWA_RST, CCU_AXI_HWA_BASE, 1),
+	CCU_RST_TRIG(CCU_AXI_SRAM_RST, CCU_AXI_SRAM_BASE, 1),
+};
+
+/*
+ * SATA reference clock domain and APB-bus domain are connected with the
+ * sefl-deasserted reset control, which can be activated via the corresponding
+ * clock divider register. DDR and PCIe sub-domains can be reset with directly
+ * controlled reset signals. Resetting the DDR controller though won't end up
+ * well while the Linux kernel is working.
+ */
+static const struct ccu_rst_info sys_rst_info[] = {
+	CCU_RST_TRIG(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_BASE, 1),
+	CCU_RST_TRIG(CCU_SYS_APB_RST, CCU_SYS_APB_BASE, 1),
+};
+
+struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx)
+{
+	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
+
+	if (idx >= data->rsts_num)
+		return ERR_PTR(-EINVAL);
+
+	return &data->rsts[idx];
+}
+
+static int ccu_rst_of_idx_get(struct reset_controller_dev *rcdev,
+			      const struct of_phandle_args *rstspec)
+{
+	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
+	unsigned int id, idx;
+
+	id = rstspec->args[0];
+	for (idx = 0; idx < data->rsts_num; ++idx) {
+		if (data->rsts[idx].id == id)
+			break;
+	}
+	if (idx == data->rsts_num) {
+		pr_err("Invalid reset ID %u specified\n", id);
+		return -EINVAL;
+	}
+
+	return idx;
+}
+
+static struct ccu_rst_data *ccu_rst_create_data(const struct ccu_rst_init_data *rst_init)
+{
+	struct ccu_rst_data *data;
+	int ret;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+
+	data->np = rst_init->np;
+	data->sys_regs = rst_init->sys_regs;
+	if (of_device_is_compatible(data->np, "baikal,bt1-ccu-axi")) {
+		data->rsts_num = ARRAY_SIZE(axi_rst_info);
+		data->rsts_info = axi_rst_info;
+	} else if (of_device_is_compatible(data->np, "baikal,bt1-ccu-sys")) {
+		data->rsts_num = ARRAY_SIZE(sys_rst_info);
+		data->rsts_info = sys_rst_info;
+	} else {
+		pr_err("Incompatible DT node '%s' specified\n",
+			of_node_full_name(data->np));
+		ret = -EINVAL;
+		goto err_kfree_data;
+	}
+
+	data->rsts = kcalloc(data->rsts_num, sizeof(*data->rsts), GFP_KERNEL);
+	if (!data->rsts) {
+		ret = -ENOMEM;
+		goto err_kfree_data;
+	}
+
+	return data;
+
+err_kfree_data:
+	kfree(data);
+
+	return ERR_PTR(ret);
+}
+
+static void ccu_rst_free_data(struct ccu_rst_data *data)
+{
+	kfree(data->rsts);
+
+	kfree(data);
+}
+
+static void ccu_rst_init_desc(struct ccu_rst_data *data)
+{
+	struct ccu_rst *rst = data->rsts;
+	unsigned int idx;
+
+	for (idx = 0; idx < data->rsts_num; ++idx, ++rst) {
+		const struct ccu_rst_info *info = &data->rsts_info[idx];
+
+		rst->id = info->id;
+		rst->type = info->type;
+		rst->reg_ctl = info->base;
+		rst->sys_regs = data->sys_regs;
+		rst->mask = info->mask;
+	}
+}
+
+static int ccu_rst_dev_register(struct ccu_rst_data *data)
+{
+	int ret;
+
+	data->rcdev.ops = &ccu_rst_ops;
+	data->rcdev.of_node = data->np;
+	data->rcdev.nr_resets = data->rsts_num;
+	data->rcdev.of_reset_n_cells = 1;
+	data->rcdev.of_xlate = ccu_rst_of_idx_get;
+
+	ret = reset_controller_register(&data->rcdev);
+	if (ret) {
+		pr_err("Couldn't register '%s' reset controller\n",
+			of_node_full_name(data->np));
+	}
+
+	return ret;
+}
+
+static void ccu_rst_dev_unregister(struct ccu_rst_data *data)
+{
+	reset_controller_unregister(&data->rcdev);
+}
+
+struct ccu_rst_data *ccu_rst_hw_register(const struct ccu_rst_init_data *rst_init)
+{
+	struct ccu_rst_data *data;
+	int ret;
+
+	data = ccu_rst_create_data(rst_init);
+	if (IS_ERR(data))
+		return data;
+
+	ccu_rst_init_desc(data);
+
+	ret = ccu_rst_dev_register(data);
+	if (ret)
+		goto err_free_data;
+
+	return data;
+
+err_free_data:
+	ccu_rst_free_data(data);
+
+	return ERR_PTR(ret);
+}
+
+void ccu_rst_hw_unregister(struct ccu_rst_data *data)
+{
+	ccu_rst_dev_unregister(data);
+
+	ccu_rst_free_data(data);
+}
-- 
2.35.1


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

* [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
                   ` (5 preceding siblings ...)
  2022-06-24 14:18 ` [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  2022-06-29 15:16   ` Philipp Zabel
  2022-06-24 14:18 ` [PATCH RESEND v5 8/8] clk: baikal-t1: Convert to platform device driver Serge Semin
  7 siblings, 1 reply; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette, Rob Herring,
	Krzysztof Kozlowski
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel,
	devicetree

Aside with a set of the trigger-like resets Baikal-T1 CCU provides two
additional blocks with directly controlled reset signals. In particular it
concerns DDR full and initial resets and various PCIe sub-domains resets.
Let's add the direct reset assertion/de-assertion of the corresponding
flags support into the Baikal-T1 CCU driver then. It will be required at
least for the PCIe platform driver. Obviously the DDR controller isn't
supposed to be fully reset in the kernel, so the corresponding controls
are added just for the sake of the interface implementation completeness.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
---
 drivers/clk/baikal-t1/ccu-rst.c     | 56 +++++++++++++++++++++++++++++
 drivers/clk/baikal-t1/ccu-rst.h     | 12 +++++++
 drivers/clk/baikal-t1/clk-ccu-rst.c | 21 +++++++++++
 include/dt-bindings/reset/bt1-ccu.h |  9 +++++
 4 files changed, 98 insertions(+)

diff --git a/drivers/clk/baikal-t1/ccu-rst.c b/drivers/clk/baikal-t1/ccu-rst.c
index b355bf0b399a..a3b41cbe6230 100644
--- a/drivers/clk/baikal-t1/ccu-rst.c
+++ b/drivers/clk/baikal-t1/ccu-rst.c
@@ -30,6 +30,9 @@ static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx)
 		return PTR_ERR(rst);
 	}
 
+	if (rst->type != CCU_RST_TRIG)
+		return -EOPNOTSUPP;
+
 	regmap_update_bits(rst->sys_regs, rst->reg_ctl, rst->mask, rst->mask);
 
 	/* The next delay must be enough to cover all the resets. */
@@ -38,6 +41,59 @@ static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx)
 	return 0;
 }
 
+static int ccu_rst_set(struct reset_controller_dev *rcdev,
+		       unsigned long idx, bool high)
+{
+	struct ccu_rst *rst;
+
+	rst = ccu_rst_get_desc(rcdev, idx);
+	if (IS_ERR(rst)) {
+		pr_err("Invalid reset index %lu specified\n", idx);
+		return PTR_ERR(rst);
+	}
+
+	if (rst->type != CCU_RST_DIR)
+		return high ? -EOPNOTSUPP : 0;
+
+	return regmap_update_bits(rst->sys_regs, rst->reg_ctl,
+				  rst->mask, high ? rst->mask : 0);
+}
+
+static int ccu_rst_assert(struct reset_controller_dev *rcdev,
+			  unsigned long idx)
+{
+	return ccu_rst_set(rcdev, idx, true);
+}
+
+static int ccu_rst_deassert(struct reset_controller_dev *rcdev,
+			    unsigned long idx)
+{
+	return ccu_rst_set(rcdev, idx, false);
+}
+
+static int ccu_rst_status(struct reset_controller_dev *rcdev,
+			  unsigned long idx)
+{
+	struct ccu_rst *rst;
+	u32 val;
+
+	rst = ccu_rst_get_desc(rcdev, idx);
+	if (IS_ERR(rst)) {
+		pr_err("Invalid reset index %lu specified\n", idx);
+		return PTR_ERR(rst);
+	}
+
+	if (rst->type != CCU_RST_DIR)
+		return -EOPNOTSUPP;
+
+	regmap_read(rst->sys_regs, rst->reg_ctl, &val);
+
+	return !!(val & rst->mask);
+}
+
 const struct reset_control_ops ccu_rst_ops = {
 	.reset = ccu_rst_reset,
+	.assert = ccu_rst_assert,
+	.deassert = ccu_rst_deassert,
+	.status = ccu_rst_status,
 };
diff --git a/drivers/clk/baikal-t1/ccu-rst.h b/drivers/clk/baikal-t1/ccu-rst.h
index d03bae4b7a05..7b9b9c81f5c9 100644
--- a/drivers/clk/baikal-t1/ccu-rst.h
+++ b/drivers/clk/baikal-t1/ccu-rst.h
@@ -12,6 +12,16 @@
 
 struct ccu_rst_data;
 
+/*
+ * enum ccu_rst_type - CCU Reset types
+ * @CCU_RST_TRIG: Self-deasserted reset signal.
+ * @CCU_RST_DIR: Directly controlled reset signal.
+ */
+enum ccu_rst_type {
+	CCU_RST_TRIG,
+	CCU_RST_DIR,
+};
+
 /*
  * struct ccu_rst_init_data - CCU Resets initialization data
  * @sys_regs: Baikal-T1 System Controller registers map.
@@ -25,12 +35,14 @@ struct ccu_rst_init_data {
 /*
  * struct ccu_rst - CCU Reset descriptor
  * @id: Reset identifier.
+ * @type: Reset control type.
  * @reg_ctl: Reset control register base address.
  * @sys_regs: Baikal-T1 System Controller registers map.
  * @mask: Reset bitmask (normally it's just a single bit flag).
  */
 struct ccu_rst {
 	unsigned int id;
+	enum ccu_rst_type type;
 	unsigned int reg_ctl;
 	struct regmap *sys_regs;
 	u32 mask;
diff --git a/drivers/clk/baikal-t1/clk-ccu-rst.c b/drivers/clk/baikal-t1/clk-ccu-rst.c
index b10857f48b8b..592a95308c62 100644
--- a/drivers/clk/baikal-t1/clk-ccu-rst.c
+++ b/drivers/clk/baikal-t1/clk-ccu-rst.c
@@ -33,18 +33,30 @@
 #define CCU_AXI_HWA_BASE		0x054
 #define CCU_AXI_SRAM_BASE		0x058
 
+#define CCU_SYS_DDR_BASE		0x02c
 #define CCU_SYS_SATA_REF_BASE		0x060
 #define CCU_SYS_APB_BASE		0x064
+#define CCU_SYS_PCIE_BASE		0x144
 
 #define CCU_RST_TRIG(_id, _base, _ofs)		\
 	{					\
 		.id = _id,			\
+		.type = CCU_RST_TRIG,		\
+		.base = _base,			\
+		.mask = BIT(_ofs),		\
+	}
+
+#define CCU_RST_DIR(_id, _base, _ofs)		\
+	{					\
+		.id = _id,			\
+		.type = CCU_RST_DIR,		\
 		.base = _base,			\
 		.mask = BIT(_ofs),		\
 	}
 
 struct ccu_rst_info {
 	unsigned int id;
+	enum ccu_rst_type type;
 	unsigned int base;
 	unsigned int mask;
 };
@@ -89,6 +101,15 @@ static const struct ccu_rst_info axi_rst_info[] = {
 static const struct ccu_rst_info sys_rst_info[] = {
 	CCU_RST_TRIG(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_BASE, 1),
 	CCU_RST_TRIG(CCU_SYS_APB_RST, CCU_SYS_APB_BASE, 1),
+	CCU_RST_DIR(CCU_SYS_DDR_FULL_RST, CCU_SYS_DDR_BASE, 1),
+	CCU_RST_DIR(CCU_SYS_DDR_INIT_RST, CCU_SYS_DDR_BASE, 2),
+	CCU_RST_DIR(CCU_SYS_PCIE_PCS_PHY_RST, CCU_SYS_PCIE_BASE, 0),
+	CCU_RST_DIR(CCU_SYS_PCIE_PIPE0_RST, CCU_SYS_PCIE_BASE, 4),
+	CCU_RST_DIR(CCU_SYS_PCIE_CORE_RST, CCU_SYS_PCIE_BASE, 8),
+	CCU_RST_DIR(CCU_SYS_PCIE_PWR_RST, CCU_SYS_PCIE_BASE, 9),
+	CCU_RST_DIR(CCU_SYS_PCIE_STICKY_RST, CCU_SYS_PCIE_BASE, 10),
+	CCU_RST_DIR(CCU_SYS_PCIE_NSTICKY_RST, CCU_SYS_PCIE_BASE, 11),
+	CCU_RST_DIR(CCU_SYS_PCIE_HOT_RST, CCU_SYS_PCIE_BASE, 12),
 };
 
 struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx)
diff --git a/include/dt-bindings/reset/bt1-ccu.h b/include/dt-bindings/reset/bt1-ccu.h
index 3578e83026bc..c691efaa678f 100644
--- a/include/dt-bindings/reset/bt1-ccu.h
+++ b/include/dt-bindings/reset/bt1-ccu.h
@@ -21,5 +21,14 @@
 
 #define CCU_SYS_SATA_REF_RST		0
 #define CCU_SYS_APB_RST			1
+#define CCU_SYS_DDR_FULL_RST		2
+#define CCU_SYS_DDR_INIT_RST		3
+#define CCU_SYS_PCIE_PCS_PHY_RST	4
+#define CCU_SYS_PCIE_PIPE0_RST		5
+#define CCU_SYS_PCIE_CORE_RST		6
+#define CCU_SYS_PCIE_PWR_RST		7
+#define CCU_SYS_PCIE_STICKY_RST		8
+#define CCU_SYS_PCIE_NSTICKY_RST	9
+#define CCU_SYS_PCIE_HOT_RST		10
 
 #endif /* __DT_BINDINGS_RESET_BT1_CCU_H */
-- 
2.35.1


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

* [PATCH RESEND v5 8/8] clk: baikal-t1: Convert to platform device driver
  2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
                   ` (6 preceding siblings ...)
  2022-06-24 14:18 ` [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support Serge Semin
@ 2022-06-24 14:18 ` Serge Semin
  7 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-24 14:18 UTC (permalink / raw)
  To: Stephen Boyd, Philipp Zabel, Michael Turquette
  Cc: Serge Semin, Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

In accordance with the way the MIPS platform is normally design there are
only six clock sources which need to be available on the kernel start in
order to one end up booting correctly:
+ CPU PLL: needed by the r4k and MIPS GIC timer drivers. The former one is
  initialized by the arch code, while the later one is implemented in the
  mips-gic-timer.c driver as the OF-declared timer.
+ PCIe PLL: required as a parental clock source for the APB/timer domains.
+ APB clock: needed in order to access all the SoC CSRs at least for the
  timer OF-declared drivers.
+ APB Timer{0-2} clocks: these are the DW APB timers which drivers
  dw_apb_timer_of.c are implemented as the OF-declared timers.

So as long as the clocks above are available early the kernel will
normally work. Let's convert the Baikal-T1 CCU drivers to the platform
device drivers keeping that in mind.

Generally speaking the conversion isn't that complicated since the driver
infrastructure has been designed as flexible enough for that. First we
need to add a new PLL/Divider clock features flag which indicates the
corresponding clock source as a basic one and that clock sources will be
available on the kernel early boot stages. Second the internal PLL/Divider
descriptors need to be initialized with -EPROBE_DEFER value as the
corresponding clock source is unavailable at the early stages. They will
be allocated and initialized on the Baikal-T1 clock platform driver probe
procedure. Finally the already available PLL/Divider init functions need
to be split up into two ones: init procedure performed in the framework of
the OF-declared clock initialization (of_clk_init()), and the probe
procedure called by the platform devices bus driver. Note the later method
will just continue the system clocks initialization started in the former
one.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

---

Changelog v4:
- This is a new patch created on v4 lap of the series to make @Stephen
  a bit more happy about this series.)
---
 drivers/clk/baikal-t1/ccu-div.h     |   3 +
 drivers/clk/baikal-t1/ccu-pll.h     |   8 ++
 drivers/clk/baikal-t1/clk-ccu-div.c | 149 +++++++++++++++++++++++-----
 drivers/clk/baikal-t1/clk-ccu-pll.c | 128 +++++++++++++++++++-----
 4 files changed, 235 insertions(+), 53 deletions(-)

diff --git a/drivers/clk/baikal-t1/ccu-div.h b/drivers/clk/baikal-t1/ccu-div.h
index ff97bb30fcc3..76d8ee44d415 100644
--- a/drivers/clk/baikal-t1/ccu-div.h
+++ b/drivers/clk/baikal-t1/ccu-div.h
@@ -23,6 +23,8 @@
 
 /*
  * CCU Divider private flags
+ * @CCU_DIV_BASIC: Basic divider clock required by the kernel as early as
+ *		   possible.
  * @CCU_DIV_SKIP_ONE: Due to some reason divider can't be set to 1.
  *		      It can be 0 though, which is functionally the same.
  * @CCU_DIV_SKIP_ONE_TO_THREE: For some reason divider can't be within [1,3].
@@ -30,6 +32,7 @@
  * @CCU_DIV_LOCK_SHIFTED: Find lock-bit at non-standard position.
  * @CCU_DIV_RESET_DOMAIN: There is a clock domain reset handle.
  */
+#define CCU_DIV_BASIC			BIT(0)
 #define CCU_DIV_SKIP_ONE		BIT(1)
 #define CCU_DIV_SKIP_ONE_TO_THREE	BIT(2)
 #define CCU_DIV_LOCK_SHIFTED		BIT(3)
diff --git a/drivers/clk/baikal-t1/ccu-pll.h b/drivers/clk/baikal-t1/ccu-pll.h
index 76cd9132a219..a71bfd7b90ec 100644
--- a/drivers/clk/baikal-t1/ccu-pll.h
+++ b/drivers/clk/baikal-t1/ccu-pll.h
@@ -13,6 +13,12 @@
 #include <linux/bits.h>
 #include <linux/of.h>
 
+/*
+ * CCU PLL private flags
+ * @CCU_PLL_BASIC: Basic PLL required by the kernel as early as possible.
+ */
+#define CCU_PLL_BASIC		BIT(0)
+
 /*
  * struct ccu_pll_init_data - CCU PLL initialization data
  * @id: Clock private identifier.
@@ -22,6 +28,7 @@
  * @sys_regs: Baikal-T1 System Controller registers map.
  * @np: Pointer to the node describing the CCU PLLs.
  * @flags: PLL clock flags.
+ * @features: PLL private features.
  */
 struct ccu_pll_init_data {
 	unsigned int id;
@@ -31,6 +38,7 @@ struct ccu_pll_init_data {
 	struct regmap *sys_regs;
 	struct device_node *np;
 	unsigned long flags;
+	unsigned long features;
 };
 
 /*
diff --git a/drivers/clk/baikal-t1/clk-ccu-div.c b/drivers/clk/baikal-t1/clk-ccu-div.c
index 71e563e28f86..9713ea71cfda 100644
--- a/drivers/clk/baikal-t1/clk-ccu-div.c
+++ b/drivers/clk/baikal-t1/clk-ccu-div.c
@@ -12,6 +12,7 @@
 #define pr_fmt(fmt) "bt1-ccu-div: " fmt
 
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 #include <linux/printk.h>
 #include <linux/slab.h>
 #include <linux/clk-provider.h>
@@ -201,7 +202,7 @@ static const struct ccu_div_info sys_info[] = {
 			 CLK_SET_RATE_PARENT),
 	CCU_DIV_VAR_INFO(CCU_SYS_APB_CLK, "sys_apb_clk",
 			 "pcie_clk", CCU_SYS_APB_BASE, 5,
-			 CLK_IS_CRITICAL, CCU_DIV_RESET_DOMAIN),
+			 CLK_IS_CRITICAL, CCU_DIV_BASIC | CCU_DIV_RESET_DOMAIN),
 	CCU_DIV_GATE_INFO(CCU_SYS_GMAC0_TX_CLK, "sys_gmac0_tx_clk",
 			  "eth_clk", CCU_SYS_GMAC0_BASE, 5),
 	CCU_DIV_FIXED_INFO(CCU_SYS_GMAC0_PTP_CLK, "sys_gmac0_ptp_clk",
@@ -235,28 +236,53 @@ static const struct ccu_div_info sys_info[] = {
 			   "ref_clk", 25),
 	CCU_DIV_VAR_INFO(CCU_SYS_TIMER0_CLK, "sys_timer0_clk",
 			 "ref_clk", CCU_SYS_TIMER0_BASE, 17,
-			 CLK_SET_RATE_GATE, 0),
+			 CLK_SET_RATE_GATE, CCU_DIV_BASIC),
 	CCU_DIV_VAR_INFO(CCU_SYS_TIMER1_CLK, "sys_timer1_clk",
 			 "ref_clk", CCU_SYS_TIMER1_BASE, 17,
-			 CLK_SET_RATE_GATE, 0),
+			 CLK_SET_RATE_GATE, CCU_DIV_BASIC),
 	CCU_DIV_VAR_INFO(CCU_SYS_TIMER2_CLK, "sys_timer2_clk",
 			 "ref_clk", CCU_SYS_TIMER2_BASE, 17,
-			 CLK_SET_RATE_GATE, 0),
+			 CLK_SET_RATE_GATE, CCU_DIV_BASIC),
 	CCU_DIV_VAR_INFO(CCU_SYS_WDT_CLK, "sys_wdt_clk",
 			 "eth_clk", CCU_SYS_WDT_BASE, 17,
 			 CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE_TO_THREE)
 };
 
+static struct ccu_div_data *axi_data;
+static struct ccu_div_data *sys_data;
+
+static void ccu_div_set_data(struct ccu_div_data *data)
+{
+	struct device_node *np = data->np;
+
+	if (of_device_is_compatible(np, "baikal,bt1-ccu-axi"))
+		axi_data = data;
+	else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys"))
+		sys_data = data;
+	else
+		pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np));
+}
+
+static struct ccu_div_data *ccu_div_get_data(struct device_node *np)
+{
+	if (of_device_is_compatible(np, "baikal,bt1-ccu-axi"))
+		return axi_data;
+	else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys"))
+		return sys_data;
+
+	pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np));
+
+	return NULL;
+}
+
 static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data,
 					 unsigned int clk_id)
 {
-	struct ccu_div *div;
 	int idx;
 
 	for (idx = 0; idx < data->divs_num; ++idx) {
-		div = data->divs[idx];
-		if (div && div->id == clk_id)
-			return div;
+		if (data->divs_info[idx].id == clk_id)
+			return data->divs[idx];
 	}
 
 	return ERR_PTR(-EINVAL);
@@ -328,14 +354,16 @@ static struct clk_hw *ccu_div_of_clk_hw_get(struct of_phandle_args *clkspec,
 	clk_id = clkspec->args[0];
 	div = ccu_div_find_desc(data, clk_id);
 	if (IS_ERR(div)) {
-		pr_info("Invalid clock ID %d specified\n", clk_id);
+		if (div != ERR_PTR(-EPROBE_DEFER))
+			pr_info("Invalid clock ID %d specified\n", clk_id);
+
 		return ERR_CAST(div);
 	}
 
 	return ccu_div_get_clk_hw(div);
 }
 
-static int ccu_div_clk_register(struct ccu_div_data *data)
+static int ccu_div_clk_register(struct ccu_div_data *data, bool defer)
 {
 	int idx, ret;
 
@@ -343,6 +371,13 @@ static int ccu_div_clk_register(struct ccu_div_data *data)
 		const struct ccu_div_info *info = &data->divs_info[idx];
 		struct ccu_div_init_data init = {0};
 
+		if (!!(info->features & CCU_DIV_BASIC) ^ defer) {
+			if (!data->divs[idx])
+				data->divs[idx] = ERR_PTR(-EPROBE_DEFER);
+
+			continue;
+		}
+
 		init.id = info->id;
 		init.name = info->name;
 		init.parent_name = info->parent_name;
@@ -375,30 +410,43 @@ static int ccu_div_clk_register(struct ccu_div_data *data)
 		}
 	}
 
-	ret = of_clk_add_hw_provider(data->np, ccu_div_of_clk_hw_get, data);
-	if (ret) {
-		pr_err("Couldn't register dividers '%s' clock provider\n",
-			of_node_full_name(data->np));
-		goto err_hw_unregister;
-	}
-
 	return 0;
 
 err_hw_unregister:
-	for (--idx; idx >= 0; --idx)
+	for (--idx; idx >= 0; --idx) {
+		if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer)
+			continue;
+
 		ccu_div_hw_unregister(data->divs[idx]);
+	}
 
 	return ret;
 }
 
-static void ccu_div_clk_unregister(struct ccu_div_data *data)
+static void ccu_div_clk_unregister(struct ccu_div_data *data, bool defer)
 {
 	int idx;
 
-	of_clk_del_provider(data->np);
+	/* Uninstall only the clocks registered on the specfied stage */
+	for (idx = 0; idx < data->divs_num; ++idx) {
+		if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer)
+			continue;
 
-	for (idx = 0; idx < data->divs_num; ++idx)
 		ccu_div_hw_unregister(data->divs[idx]);
+	}
+}
+
+static int ccu_div_of_register(struct ccu_div_data *data)
+{
+	int ret;
+
+	ret = of_clk_add_hw_provider(data->np, ccu_div_of_clk_hw_get, data);
+	if (ret) {
+		pr_err("Couldn't register dividers '%s' clock provider\n",
+			of_node_full_name(data->np));
+	}
+
+	return ret;
 }
 
 static int ccu_div_rst_register(struct ccu_div_data *data)
@@ -418,7 +466,49 @@ static int ccu_div_rst_register(struct ccu_div_data *data)
 	return 0;
 }
 
-static void ccu_div_init(struct device_node *np)
+static int ccu_div_probe(struct platform_device *pdev)
+{
+	struct ccu_div_data *data;
+	int ret;
+
+	data = ccu_div_get_data(dev_of_node(&pdev->dev));
+	if (!data)
+		return -EINVAL;
+
+	ret = ccu_div_clk_register(data, false);
+	if (ret)
+		return ret;
+
+	ret = ccu_div_rst_register(data);
+	if (ret)
+		goto err_clk_unregister;
+
+	return 0;
+
+err_clk_unregister:
+	ccu_div_clk_unregister(data, false);
+
+	return ret;
+}
+
+static const struct of_device_id ccu_div_of_match[] = {
+	{ .compatible = "baikal,bt1-ccu-axi" },
+	{ .compatible = "baikal,bt1-ccu-sys" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ccu_div_of_match);
+
+static struct platform_driver ccu_div_driver = {
+	.probe  = ccu_div_probe,
+	.driver = {
+		.name = "clk-ccu-div",
+		.of_match_table = ccu_div_of_match,
+		.suppress_bind_attrs = true,
+	},
+};
+builtin_platform_driver(ccu_div_driver);
+
+static __init void ccu_div_init(struct device_node *np)
 {
 	struct ccu_div_data *data;
 	int ret;
@@ -431,22 +521,27 @@ static void ccu_div_init(struct device_node *np)
 	if (ret)
 		goto err_free_data;
 
-	ret = ccu_div_clk_register(data);
+	ret = ccu_div_clk_register(data, true);
 	if (ret)
 		goto err_free_data;
 
-	ret = ccu_div_rst_register(data);
+	ret = ccu_div_of_register(data);
 	if (ret)
 		goto err_clk_unregister;
 
+	ccu_div_set_data(data);
+
 	return;
 
 err_clk_unregister:
-	ccu_div_clk_unregister(data);
+	ccu_div_clk_unregister(data, true);
 
 err_free_data:
 	ccu_div_free_data(data);
 }
+CLK_OF_DECLARE_DRIVER(ccu_axi, "baikal,bt1-ccu-axi", ccu_div_init);
+CLK_OF_DECLARE_DRIVER(ccu_sys, "baikal,bt1-ccu-sys", ccu_div_init);
 
-CLK_OF_DECLARE(ccu_axi, "baikal,bt1-ccu-axi", ccu_div_init);
-CLK_OF_DECLARE(ccu_sys, "baikal,bt1-ccu-sys", ccu_div_init);
+MODULE_AUTHOR("Serge Semin <Sergey.Semin@baikalelectronics.ru>");
+MODULE_DESCRIPTION("Baikal-T1 CCU Dividers clock driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/clk/baikal-t1/clk-ccu-pll.c b/drivers/clk/baikal-t1/clk-ccu-pll.c
index 2445d4b12baf..ad420c6477ee 100644
--- a/drivers/clk/baikal-t1/clk-ccu-pll.c
+++ b/drivers/clk/baikal-t1/clk-ccu-pll.c
@@ -12,6 +12,7 @@
 #define pr_fmt(fmt) "bt1-ccu-pll: " fmt
 
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 #include <linux/printk.h>
 #include <linux/slab.h>
 #include <linux/clk-provider.h>
@@ -31,13 +32,14 @@
 #define CCU_PCIE_PLL_BASE		0x018
 #define CCU_ETH_PLL_BASE		0x020
 
-#define CCU_PLL_INFO(_id, _name, _pname, _base, _flags)	\
-	{						\
-		.id = _id,				\
-		.name = _name,				\
-		.parent_name = _pname,			\
-		.base = _base,				\
-		.flags = _flags				\
+#define CCU_PLL_INFO(_id, _name, _pname, _base, _flags, _features)	\
+	{								\
+		.id = _id,						\
+		.name = _name,						\
+		.parent_name = _pname,					\
+		.base = _base,						\
+		.flags = _flags,					\
+		.features = _features,					\
 	}
 
 #define CCU_PLL_NUM			ARRAY_SIZE(pll_info)
@@ -48,6 +50,7 @@ struct ccu_pll_info {
 	const char *parent_name;
 	unsigned int base;
 	unsigned long flags;
+	unsigned long features;
 };
 
 /*
@@ -61,15 +64,15 @@ struct ccu_pll_info {
  */
 static const struct ccu_pll_info pll_info[] = {
 	CCU_PLL_INFO(CCU_CPU_PLL, "cpu_pll", "ref_clk", CCU_CPU_PLL_BASE,
-		     CLK_IS_CRITICAL),
+		     CLK_IS_CRITICAL, CCU_PLL_BASIC),
 	CCU_PLL_INFO(CCU_SATA_PLL, "sata_pll", "ref_clk", CCU_SATA_PLL_BASE,
-		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE),
+		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0),
 	CCU_PLL_INFO(CCU_DDR_PLL, "ddr_pll", "ref_clk", CCU_DDR_PLL_BASE,
-		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE),
+		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0),
 	CCU_PLL_INFO(CCU_PCIE_PLL, "pcie_pll", "ref_clk", CCU_PCIE_PLL_BASE,
-		     CLK_IS_CRITICAL),
+		     CLK_IS_CRITICAL, CCU_PLL_BASIC),
 	CCU_PLL_INFO(CCU_ETH_PLL, "eth_pll", "ref_clk", CCU_ETH_PLL_BASE,
-		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE)
+		     CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0)
 };
 
 struct ccu_pll_data {
@@ -78,16 +81,16 @@ struct ccu_pll_data {
 	struct ccu_pll *plls[CCU_PLL_NUM];
 };
 
+static struct ccu_pll_data *pll_data;
+
 static struct ccu_pll *ccu_pll_find_desc(struct ccu_pll_data *data,
 					 unsigned int clk_id)
 {
-	struct ccu_pll *pll;
 	int idx;
 
 	for (idx = 0; idx < CCU_PLL_NUM; ++idx) {
-		pll = data->plls[idx];
-		if (pll && pll->id == clk_id)
-			return pll;
+		if (pll_info[idx].id == clk_id)
+			return data->plls[idx];
 	}
 
 	return ERR_PTR(-EINVAL);
@@ -133,14 +136,16 @@ static struct clk_hw *ccu_pll_of_clk_hw_get(struct of_phandle_args *clkspec,
 	clk_id = clkspec->args[0];
 	pll = ccu_pll_find_desc(data, clk_id);
 	if (IS_ERR(pll)) {
-		pr_info("Invalid PLL clock ID %d specified\n", clk_id);
+		if (pll != ERR_PTR(-EPROBE_DEFER))
+			pr_info("Invalid PLL clock ID %d specified\n", clk_id);
+
 		return ERR_CAST(pll);
 	}
 
 	return ccu_pll_get_clk_hw(pll);
 }
 
-static int ccu_pll_clk_register(struct ccu_pll_data *data)
+static int ccu_pll_clk_register(struct ccu_pll_data *data, bool defer)
 {
 	int idx, ret;
 
@@ -148,6 +153,14 @@ static int ccu_pll_clk_register(struct ccu_pll_data *data)
 		const struct ccu_pll_info *info = &pll_info[idx];
 		struct ccu_pll_init_data init = {0};
 
+		/* Defer non-basic PLLs allocation for the probe stage */
+		if (!!(info->features & CCU_PLL_BASIC) ^ defer) {
+			if (!data->plls[idx])
+				data->plls[idx] = ERR_PTR(-EPROBE_DEFER);
+
+			continue;
+		}
+
 		init.id = info->id;
 		init.name = info->name;
 		init.parent_name = info->parent_name;
@@ -155,6 +168,7 @@ static int ccu_pll_clk_register(struct ccu_pll_data *data)
 		init.sys_regs = data->sys_regs;
 		init.np = data->np;
 		init.flags = info->flags;
+		init.features = info->features;
 
 		data->plls[idx] = ccu_pll_hw_register(&init);
 		if (IS_ERR(data->plls[idx])) {
@@ -165,22 +179,71 @@ static int ccu_pll_clk_register(struct ccu_pll_data *data)
 		}
 	}
 
+	return 0;
+
+err_hw_unregister:
+	for (--idx; idx >= 0; --idx) {
+		if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer)
+			continue;
+
+		ccu_pll_hw_unregister(data->plls[idx]);
+	}
+
+	return ret;
+}
+
+static void ccu_pll_clk_unregister(struct ccu_pll_data *data, bool defer)
+{
+	int idx;
+
+	/* Uninstall only the clocks registered on the specfied stage */
+	for (idx = 0; idx < CCU_PLL_NUM; ++idx) {
+		if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer)
+			continue;
+
+		ccu_pll_hw_unregister(data->plls[idx]);
+	}
+}
+
+static int ccu_pll_of_register(struct ccu_pll_data *data)
+{
+	int ret;
+
 	ret = of_clk_add_hw_provider(data->np, ccu_pll_of_clk_hw_get, data);
 	if (ret) {
 		pr_err("Couldn't register PLL provider of '%s'\n",
 			of_node_full_name(data->np));
-		goto err_hw_unregister;
 	}
 
-	return 0;
+	return ret;
+}
 
-err_hw_unregister:
-	for (--idx; idx >= 0; --idx)
-		ccu_pll_hw_unregister(data->plls[idx]);
+static int ccu_pll_probe(struct platform_device *pdev)
+{
+	struct ccu_pll_data *data = pll_data;
 
-	return ret;
+	if (!data)
+		return -EINVAL;
+
+	return ccu_pll_clk_register(data, false);
 }
 
+static const struct of_device_id ccu_pll_of_match[] = {
+	{ .compatible = "baikal,bt1-ccu-pll" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ccu_pll_of_match);
+
+static struct platform_driver ccu_pll_driver = {
+	.probe  = ccu_pll_probe,
+	.driver = {
+		.name = "clk-ccu-pll",
+		.of_match_table = ccu_pll_of_match,
+		.suppress_bind_attrs = true,
+	},
+};
+builtin_platform_driver(ccu_pll_driver);
+
 static __init void ccu_pll_init(struct device_node *np)
 {
 	struct ccu_pll_data *data;
@@ -194,13 +257,26 @@ static __init void ccu_pll_init(struct device_node *np)
 	if (ret)
 		goto err_free_data;
 
-	ret = ccu_pll_clk_register(data);
+	ret = ccu_pll_clk_register(data, true);
 	if (ret)
 		goto err_free_data;
 
+	ret = ccu_pll_of_register(data);
+	if (ret)
+		goto err_clk_unregister;
+
+	pll_data = data;
+
 	return;
 
+err_clk_unregister:
+	ccu_pll_clk_unregister(data, true);
+
 err_free_data:
 	ccu_pll_free_data(data);
 }
-CLK_OF_DECLARE(ccu_pll, "baikal,bt1-ccu-pll", ccu_pll_init);
+CLK_OF_DECLARE_DRIVER(ccu_pll, "baikal,bt1-ccu-pll", ccu_pll_init);
+
+MODULE_AUTHOR("Serge Semin <Sergey.Semin@baikalelectronics.ru>");
+MODULE_DESCRIPTION("Baikal-T1 CCU PLL clock driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


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

* Re: [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter
  2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
@ 2022-06-26 22:35   ` Dmitry Osipenko
  2022-06-27 22:20     ` Serge Semin
  2022-06-29 14:02   ` Philipp Zabel
  1 sibling, 1 reply; 20+ messages in thread
From: Dmitry Osipenko @ 2022-06-26 22:35 UTC (permalink / raw)
  To: Serge Semin, Stephen Boyd, Philipp Zabel, Michael Turquette,
	Dmitry Osipenko, Mark Brown
  Cc: Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

On 6/24/22 17:18, Serge Semin wrote:
> Most likely due to copy-paste mistake the device managed version of the
> denoted reset control getter has been implemented with invalid semantic,
> which can be immediately spotted by having "WARN_ON(shared && acquired)"
> warning in the system log as soon as the method is called. Anyway let's
> fix it by altering the boolean arguments passed to the
> __devm_reset_control_bulk_get() method from
> - shared = true, optional = false, acquired = true
> to
> + shared = false, optional = true, acquired = true
> That's what they were supposed to be in the first place (see the non-devm
> version of the same method: reset_control_bulk_get_optional_exclusive()).
> 
> Fixes: 48d71395896d ("reset: Add reset_control_bulk API")
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> 
> ---
> 
> Changelog v4:
> - This is a new patch added on v4 lap of the series.
> ---
>  include/linux/reset.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/reset.h b/include/linux/reset.h
> index 8a21b5756c3e..514ddf003efc 100644
> --- a/include/linux/reset.h
> +++ b/include/linux/reset.h
> @@ -731,7 +731,7 @@ static inline int __must_check
>  devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
>  					       struct reset_control_bulk_data *rstcs)
>  {
> -	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, true);
> +	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
>  }
>  
>  /**

Good catch,

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

Although, this patch should be sent as standalone since it's unrelated
to the rest of the clk patches.

-- 
Best regards,
Dmitry

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

* Re: [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter
  2022-06-26 22:35   ` Dmitry Osipenko
@ 2022-06-27 22:20     ` Serge Semin
  0 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-27 22:20 UTC (permalink / raw)
  To: Dmitry Osipenko, Stephen Boyd, Philipp Zabel
  Cc: Serge Semin, Michael Turquette, Dmitry Osipenko, Mark Brown,
	Alexey Malahov, Pavel Parkhomenko, Thomas Bogendoerfer,
	linux-clk, linux-mips, linux-kernel

On Mon, Jun 27, 2022 at 01:35:28AM +0300, Dmitry Osipenko wrote:
> On 6/24/22 17:18, Serge Semin wrote:
> > Most likely due to copy-paste mistake the device managed version of the
> > denoted reset control getter has been implemented with invalid semantic,
> > which can be immediately spotted by having "WARN_ON(shared && acquired)"
> > warning in the system log as soon as the method is called. Anyway let's
> > fix it by altering the boolean arguments passed to the
> > __devm_reset_control_bulk_get() method from
> > - shared = true, optional = false, acquired = true
> > to
> > + shared = false, optional = true, acquired = true
> > That's what they were supposed to be in the first place (see the non-devm
> > version of the same method: reset_control_bulk_get_optional_exclusive()).
> > 
> > Fixes: 48d71395896d ("reset: Add reset_control_bulk API")
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > 
> > ---
> > 
> > Changelog v4:
> > - This is a new patch added on v4 lap of the series.
> > ---
> >  include/linux/reset.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/reset.h b/include/linux/reset.h
> > index 8a21b5756c3e..514ddf003efc 100644
> > --- a/include/linux/reset.h
> > +++ b/include/linux/reset.h
> > @@ -731,7 +731,7 @@ static inline int __must_check
> >  devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
> >  					       struct reset_control_bulk_data *rstcs)
> >  {
> > -	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, true);
> > +	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
> >  }
> >  
> >  /**
> 

> Good catch,
> 
> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

Thanks.

> 
> Although, this patch should be sent as standalone since it's unrelated
> to the rest of the clk patches.

Mainly you are right, but I've discovered the problem in the framework
of this patchset development. So it was more suitable for me to submit
the patch in the framework of it.

There is an implicit context too. Due to the patchset containing the
reset-control-related patches I has been trying to attract the
Philipp' attention for about four months now, but with no luck.
Having the kernel API fix-patch in the series was supposed to
implicitly raise the patchset valuability for him. I don't know what
else to do, but Stephen said he wanted to see what Philipp thought of
the reset-part of the series.

-Sergey

> 
> -- 
> Best regards,
> Dmitry

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

* Re: [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter
  2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
  2022-06-26 22:35   ` Dmitry Osipenko
@ 2022-06-29 14:02   ` Philipp Zabel
  2022-06-29 15:06     ` Serge Semin
  1 sibling, 1 reply; 20+ messages in thread
From: Philipp Zabel @ 2022-06-29 14:02 UTC (permalink / raw)
  To: Serge Semin, Stephen Boyd, Michael Turquette, Dmitry Osipenko,
	Mark Brown
  Cc: Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Hi Serge,

On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> Most likely due to copy-paste mistake the device managed version of the
> denoted reset control getter has been implemented with invalid semantic,
> which can be immediately spotted by having "WARN_ON(shared && acquired)"
> warning in the system log as soon as the method is called. Anyway let's
> fix it by altering the boolean arguments passed to the
> __devm_reset_control_bulk_get() method from
> - shared = true, optional = false, acquired = true
> to
> + shared = false, optional = true, acquired = true
> That's what they were supposed to be in the first place (see the non-devm
> version of the same method: reset_control_bulk_get_optional_exclusive()).
> 
> Fixes: 48d71395896d ("reset: Add reset_control_bulk API")
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> 
> ---
> 
> Changelog v4:
> - This is a new patch added on v4 lap of the series.
> ---
>  include/linux/reset.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/reset.h b/include/linux/reset.h
> index 8a21b5756c3e..514ddf003efc 100644
> --- a/include/linux/reset.h
> +++ b/include/linux/reset.h
> @@ -731,7 +731,7 @@ static inline int __must_check
>  devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
>  					       struct reset_control_bulk_data *rstcs)
>  {
> -	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, true);
> +	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
>  }

You are right, thank you. I'll take this as a sign that the internal
functions should probably switch from collecting ever more boolean
arguments to a flags parameter, similar to enum gpiod_flags.

I'll pick this up separately into the reset/fixes branch.

regards
Philipp

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

* Re: [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter
  2022-06-29 14:02   ` Philipp Zabel
@ 2022-06-29 15:06     ` Serge Semin
  0 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-06-29 15:06 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Dmitry Osipenko,
	Mark Brown, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

On Wed, Jun 29, 2022 at 04:02:43PM +0200, Philipp Zabel wrote:
> Hi Serge,
> 
> On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> > Most likely due to copy-paste mistake the device managed version of the
> > denoted reset control getter has been implemented with invalid semantic,
> > which can be immediately spotted by having "WARN_ON(shared && acquired)"
> > warning in the system log as soon as the method is called. Anyway let's
> > fix it by altering the boolean arguments passed to the
> > __devm_reset_control_bulk_get() method from
> > - shared = true, optional = false, acquired = true
> > to
> > + shared = false, optional = true, acquired = true
> > That's what they were supposed to be in the first place (see the non-devm
> > version of the same method: reset_control_bulk_get_optional_exclusive()).
> > 
> > Fixes: 48d71395896d ("reset: Add reset_control_bulk API")
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > 
> > ---
> > 
> > Changelog v4:
> > - This is a new patch added on v4 lap of the series.
> > ---
> >  include/linux/reset.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/reset.h b/include/linux/reset.h
> > index 8a21b5756c3e..514ddf003efc 100644
> > --- a/include/linux/reset.h
> > +++ b/include/linux/reset.h
> > @@ -731,7 +731,7 @@ static inline int __must_check
> >  devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
> >  					       struct reset_control_bulk_data *rstcs)
> >  {
> > -	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, true);
> > +	return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
> >  }
> 

> You are right, thank you. I'll take this as a sign that the internal
> functions should probably switch from collecting ever more boolean
> arguments to a flags parameter, similar to enum gpiod_flags.
> 
> I'll pick this up separately into the reset/fixes branch.

Ok. Thanks. Meanwhile could you please take a look at the rest of the
reset-related patches of the series? They concern the reset-control
functionality updates of the Baikal-T1 CCU common-clock driver.

[PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
Link: https://lore.kernel.org/linux-clk/20220624141853.7417-7-Sergey.Semin@baikalelectronics.ru/
[PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support
Link: https://lore.kernel.org/linux-clk/20220624141853.7417-8-Sergey.Semin@baikalelectronics.ru/

The functionality has been placed in the clocks subsystem because the
reset-control is tightly coupled with the clock-control part of CCU.
It's a normal approach for the SoC CCU/RCU devices, which normally
have both clocks and reset controls intermixed. Anyway the main goal
of the series was to add the directly controlled resets of the
DDR and PCIe SoC sub-domains provided in the framework of the patch
7/8. Please see the patches log for details.

-Sergey

> 
> regards
> Philipp

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

* Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-06-24 14:18 ` [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module Serge Semin
@ 2022-06-29 15:12   ` Philipp Zabel
  2022-07-05 22:07     ` Serge Semin
  0 siblings, 1 reply; 20+ messages in thread
From: Philipp Zabel @ 2022-06-29 15:12 UTC (permalink / raw)
  To: Serge Semin, Stephen Boyd, Michael Turquette
  Cc: Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel

Hi Serge,

On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> Before adding the directly controlled resets support it's reasonable to
> move the existing resets control functionality into a dedicated object for
> the sake of the CCU dividers clock driver simplification. After the new
> functionality was added clk-ccu-div.c would have got to a mixture of the
> weakly dependent clocks and resets methods. Splitting the methods up into
> the two objects will make the code easier to read and maintain. It shall
> also improve the code scalability (though hopefully we won't need this
> part that much in the future).
> 
> As it was done for the CCU PLLs and Dividers the reset control
> functionality in its turn has been split up into two sub-modules:
> hw-interface and generic reset device description. This commit doesn't
> provide any change in the CCU reset module semantics. As before it
> supports the trigger-like CCU resets only, which are responsible for the
> AXI-bus, APB-bus and SATA-ref blocks reset. The assert/de-assert-capable
> reset controls support will be added in the next commit.
> 
> Note the CCU Clock dividers and resets functionality split up was possible
> due to not having any side-effects (at least we didn't found ones) of the
> regmap-based concurrent access of the common CCU dividers/reset CSRs.
> 
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> 
> ---
> 
> Changelog v4:
> - Completely split CCU Dividers and Resets functionality. (@Stephen)
> ---
>  drivers/clk/baikal-t1/Kconfig       |  12 +-
>  drivers/clk/baikal-t1/Makefile      |   1 +
>  drivers/clk/baikal-t1/ccu-div.c     |  19 ---
>  drivers/clk/baikal-t1/ccu-div.h     |   4 +-
>  drivers/clk/baikal-t1/ccu-rst.c     |  43 +++++
>  drivers/clk/baikal-t1/ccu-rst.h     |  67 ++++++++
>  drivers/clk/baikal-t1/clk-ccu-div.c | 101 +++---------
>  drivers/clk/baikal-t1/clk-ccu-rst.c | 236 ++++++++++++++++++++++++++++

What is the reason for separating ccu-rst.c and clk-ccu-rst.c?

I expect implementing the reset ops and registering the reset
controller in the same compilation unit would be easier.

> diff --git a/drivers/clk/baikal-t1/ccu-rst.c b/drivers/clk/baikal-t1/ccu-rst.c
> new file mode 100644
> index 000000000000..b355bf0b399a
> --- /dev/null
> +++ b/drivers/clk/baikal-t1/ccu-rst.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> + *
> + * Authors:
> + *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
> + *
> + * Baikal-T1 CCU Resets interface driver
> + */
> +
> +#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
> +
> +#include <linux/delay.h>
> +#include <linux/kernel.h>
> +#include <linux/printk.h>
> +#include <linux/regmap.h>
> +#include <linux/reset-controller.h>
> +
> +#include "ccu-rst.h"
> +
> +#define CCU_RST_DELAY_US		1
> +
> +static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx)
> +{
> +	struct ccu_rst *rst;
> +
> +	rst = ccu_rst_get_desc(rcdev, idx);
> +	if (IS_ERR(rst)) {
> +		pr_err("Invalid reset index %lu specified\n", idx);
> +		return PTR_ERR(rst);
> +	}

I don't think this is necessary, see my comments below. Since the reset
ids are contiguous, just setting nr_resets and using the default
.of_xlate should be enough to make sure this is never called with an
invalid id.

> +
> +	regmap_update_bits(rst->sys_regs, rst->reg_ctl, rst->mask, rst->mask);

I would expect this to get sys_regs from data, which can be obtained
from rcdev via container_of. The reg_ctl and mask could then be
obtained from the ccu_rst_info array, data->rsts_info[idx].

> +
> +	/* The next delay must be enough to cover all the resets. */
> +	udelay(CCU_RST_DELAY_US);
> +
> +	return 0;
> +}
[...]
> +
> +const struct reset_control_ops ccu_rst_ops = {

With ops and controller registration in the same .c file this could be
static.

> +	.reset = ccu_rst_reset,
> +};
> diff --git a/drivers/clk/baikal-t1/ccu-rst.h b/drivers/clk/baikal-t1/ccu-rst.h
> new file mode 100644
> index 000000000000..d03bae4b7a05
> --- /dev/null
> +++ b/drivers/clk/baikal-t1/ccu-rst.h
> @@ -0,0 +1,67 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> + *
> + * Baikal-T1 CCU Resets interface driver
> + */
> +#ifndef __CLK_BT1_CCU_RST_H__
> +#define __CLK_BT1_CCU_RST_H__
> +
> +#include <linux/of.h>
> +#include <linux/regmap.h>
> +
> +struct ccu_rst_data;
> +
> +/*
> + * struct ccu_rst_init_data - CCU Resets initialization data
> + * @sys_regs: Baikal-T1 System Controller registers map.
> + * @np: Pointer to the node with the System CCU block.
> + */
> +struct ccu_rst_init_data {
> +	struct regmap *sys_regs;
> +	struct device_node *np;
> +};
> +
> +/*
> + * struct ccu_rst - CCU Reset descriptor
> + * @id: Reset identifier.
> + * @reg_ctl: Reset control register base address.
> + * @sys_regs: Baikal-T1 System Controller registers map.
> + * @mask: Reset bitmask (normally it's just a single bit flag).
> + */
> +struct ccu_rst {
> +	unsigned int id;

I'm not convinced this structure is necessary.
It is just a copy of struct ccu_rst_info, but with an added regmap
pointer per entry, which seems excessive since the regmap is the same
for all resets.

[...]
> diff --git a/drivers/clk/baikal-t1/clk-ccu-rst.c b/drivers/clk/baikal-t1/clk-ccu-rst.c
> new file mode 100644
> index 000000000000..b10857f48b8b
> --- /dev/null
> +++ b/drivers/clk/baikal-t1/clk-ccu-rst.c
> @@ -0,0 +1,236 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> + *
> + * Authors:
> + *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
> + *
> + * Baikal-T1 CCU Resets domain driver
> + */
> +#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
> +
> +#include <linux/bits.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/printk.h>
> +#include <linux/regmap.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
> +
> +#include <dt-bindings/reset/bt1-ccu.h>
> +
> +#include "ccu-rst.h"
> +
> +#define CCU_AXI_MAIN_BASE		0x030
> +#define CCU_AXI_DDR_BASE		0x034
> +#define CCU_AXI_SATA_BASE		0x038
> +#define CCU_AXI_GMAC0_BASE		0x03C
> +#define CCU_AXI_GMAC1_BASE		0x040
> +#define CCU_AXI_XGMAC_BASE		0x044
> +#define CCU_AXI_PCIE_M_BASE		0x048
> +#define CCU_AXI_PCIE_S_BASE		0x04C
> +#define CCU_AXI_USB_BASE		0x050
> +#define CCU_AXI_HWA_BASE		0x054
> +#define CCU_AXI_SRAM_BASE		0x058
> +
> +#define CCU_SYS_SATA_REF_BASE		0x060
> +#define CCU_SYS_APB_BASE		0x064
> +
> +#define CCU_RST_TRIG(_id, _base, _ofs)		\
> +	{					\
> +		.id = _id,			\

I think the _id parameter and id field could be dropped.

> +		.base = _base,			\
> +		.mask = BIT(_ofs),		\
> +	}
> +
> +struct ccu_rst_info {
> +	unsigned int id;

This could be dropped.

> +	unsigned int base;
> +	unsigned int mask;

Are there actually resets that require setting/clearing multiple bits,
or is this theoretical?

> +};
> +
> +struct ccu_rst_data {
> +	struct device_node *np;

This is already in rcdev.of_node, no need to carry a copy.

> +	struct regmap *sys_regs;
> +
> +	unsigned int rsts_num;

Same as above, this is already in rcdev.nr_resets.

> +	const struct ccu_rst_info *rsts_info;
> +	struct ccu_rst *rsts;

This is not neccessary if you use sys_regs and rsts_info in the reset
ops.

> +
> +	struct reset_controller_dev rcdev;
> +};
> +#define to_ccu_rst_data(_rcdev) container_of(_rcdev, struct ccu_rst_data, rcdev)
> +
> +/*
> + * Each AXI-bus clock divider is equipped with the corresponding clock-consumer
> + * domain reset (it's self-deasserted reset control).
> + */
> +static const struct ccu_rst_info axi_rst_info[] = {
> +	CCU_RST_TRIG(CCU_AXI_MAIN_RST, CCU_AXI_MAIN_BASE, 1),

This could be:

	[CCU_AXI_MAIN_RST] = CCU_RST_TRIG(CCU_AXI_MAIN_BASE, 1),

> +	CCU_RST_TRIG(CCU_AXI_DDR_RST, CCU_AXI_DDR_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_SATA_RST, CCU_AXI_SATA_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_GMAC0_RST, CCU_AXI_GMAC0_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_GMAC1_RST, CCU_AXI_GMAC1_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_XGMAC_RST, CCU_AXI_XGMAC_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_PCIE_M_RST, CCU_AXI_PCIE_M_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_PCIE_S_RST, CCU_AXI_PCIE_S_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_USB_RST, CCU_AXI_USB_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_HWA_RST, CCU_AXI_HWA_BASE, 1),
> +	CCU_RST_TRIG(CCU_AXI_SRAM_RST, CCU_AXI_SRAM_BASE, 1),
> +};
> +
> +/*
> + * SATA reference clock domain and APB-bus domain are connected with the
> + * sefl-deasserted reset control, which can be activated via the corresponding
> + * clock divider register. DDR and PCIe sub-domains can be reset with directly
> + * controlled reset signals. Resetting the DDR controller though won't end up
> + * well while the Linux kernel is working.
> + */
> +static const struct ccu_rst_info sys_rst_info[] = {
> +	CCU_RST_TRIG(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_BASE, 1),

Same as above.

> +	CCU_RST_TRIG(CCU_SYS_APB_RST, CCU_SYS_APB_BASE, 1),
> +};
> +
> +struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx)
> +{
> +	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
> +
> +	if (idx >= data->rsts_num)
> +		return ERR_PTR(-EINVAL);
> +
> +	return &data->rsts[idx];
> +}

This is not necessary if you just use the reset id as an index into the
ccu_rst_info array.

> +
> +static int ccu_rst_of_idx_get(struct reset_controller_dev *rcdev,
> +			      const struct of_phandle_args *rstspec)
> +{
> +	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
> +	unsigned int id, idx;
> +
> +	id = rstspec->args[0];
> +	for (idx = 0; idx < data->rsts_num; ++idx) {
> +		if (data->rsts[idx].id == id)
> +			break;
> +	}
> +	if (idx == data->rsts_num) {
> +		pr_err("Invalid reset ID %u specified\n", id);
> +		return -EINVAL;
> +	}
> +
> +	return idx;
> +}

Unless I'm mistaken, id == idx for all resets, and this is not
necessary at all. You should be able to use the default .of_xlate.

> +
> +static struct ccu_rst_data *ccu_rst_create_data(const struct ccu_rst_init_data *rst_init)
> +{
> +	struct ccu_rst_data *data;
> +	int ret;
> +
> +	data = kzalloc(sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return ERR_PTR(-ENOMEM);
> +
> +	data->np = rst_init->np;

No reason to store data->np only to copy it to data->rcdev.of_node
later.

> +	data->sys_regs = rst_init->sys_regs;
> +	if (of_device_is_compatible(data->np, "baikal,bt1-ccu-axi")) {
> +		data->rsts_num = ARRAY_SIZE(axi_rst_info);

You could store the number of resets directly into
data->rcdev.nr_resets.

> +		data->rsts_info = axi_rst_info;
> +	} else if (of_device_is_compatible(data->np, "baikal,bt1-ccu-sys")) {
> +		data->rsts_num = ARRAY_SIZE(sys_rst_info);
> +		data->rsts_info = sys_rst_info;
> +	} else {
> +		pr_err("Incompatible DT node '%s' specified\n",
> +			of_node_full_name(data->np));
> +		ret = -EINVAL;
> +		goto err_kfree_data;
> +	}
> +
> +	data->rsts = kcalloc(data->rsts_num, sizeof(*data->rsts), GFP_KERNEL);
> +	if (!data->rsts) {
> +		ret = -ENOMEM;
> +		goto err_kfree_data;
> +	}

I think data->rsts is not required.

> +
> +	return data;
> +
> +err_kfree_data:
> +	kfree(data);
> +
> +	return ERR_PTR(ret);
> +}
> +
> +static void ccu_rst_free_data(struct ccu_rst_data *data)
> +{
> +	kfree(data->rsts);
>
Not necessary.

> +	kfree(data);
> +}

I would fold this into ccu_rst_hw_unregister().

> +
> +static void ccu_rst_init_desc(struct ccu_rst_data *data)
> +{
> +	struct ccu_rst *rst = data->rsts;
> +	unsigned int idx;
> +
> +	for (idx = 0; idx < data->rsts_num; ++idx, ++rst) {
> +		const struct ccu_rst_info *info = &data->rsts_info[idx];
> +
> +		rst->id = info->id;
> +		rst->type = info->type;
> +		rst->reg_ctl = info->base;
> +		rst->sys_regs = data->sys_regs;
> +		rst->mask = info->mask;
> +	}
> +}

Not necessary.

> +static int ccu_rst_dev_register(struct ccu_rst_data *data)
> +{
> +	int ret;
> +
> +	data->rcdev.ops = &ccu_rst_ops;
> +	data->rcdev.of_node = data->np;
> +	data->rcdev.nr_resets = data->rsts_num;
> +	data->rcdev.of_reset_n_cells = 1;
> +	data->rcdev.of_xlate = ccu_rst_of_idx_get;
> +
> +	ret = reset_controller_register(&data->rcdev);
> +	if (ret) {
> +		pr_err("Couldn't register '%s' reset controller\n",
> +			of_node_full_name(data->np));
> +	}
> +
> +	return ret;
> +}
> +
> +static void ccu_rst_dev_unregister(struct ccu_rst_data *data)
> +{
> +	reset_controller_unregister(&data->rcdev);
> +}

I would fold this into ccu_rst_hw_unregister().

> +struct ccu_rst_data *ccu_rst_hw_register(const struct ccu_rst_init_data *rst_init)
> +{
> +	struct ccu_rst_data *data;
> +	int ret;
> +
> +	data = ccu_rst_create_data(rst_init);
> +	if (IS_ERR(data))
> +		return data;
> +
> +	ccu_rst_init_desc(data);

Not necessary.

> +
> +	ret = ccu_rst_dev_register(data);
> +	if (ret)
> +		goto err_free_data;
> +
> +	return data;
> +
> +err_free_data:
> +	ccu_rst_free_data(data);
> +
> +	return ERR_PTR(ret);
> +}
> +
> +void ccu_rst_hw_unregister(struct ccu_rst_data *data)
> +{
> +	ccu_rst_dev_unregister(data);
> +
> +	ccu_rst_free_data(data);
> +}

To me it looks like you could avoid a few unnecessary complications and
copied data if you merged ccu-rst.c and clk-ccu-rst.c and made use of
the contiguous reset ids instead of the custom of_xlate and the copied
ccu_rst descriptors.

regards
Philipp

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

* Re: [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support
  2022-06-24 14:18 ` [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support Serge Semin
@ 2022-06-29 15:16   ` Philipp Zabel
  2022-07-05 22:11     ` Serge Semin
  0 siblings, 1 reply; 20+ messages in thread
From: Philipp Zabel @ 2022-06-29 15:16 UTC (permalink / raw)
  To: Serge Semin, Stephen Boyd, Michael Turquette, Rob Herring,
	Krzysztof Kozlowski
  Cc: Serge Semin, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel,
	devicetree

Hi Serge,

On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> Aside with a set of the trigger-like resets Baikal-T1 CCU provides two
> additional blocks with directly controlled reset signals. In particular it
> concerns DDR full and initial resets and various PCIe sub-domains resets.
> Let's add the direct reset assertion/de-assertion of the corresponding
> flags support into the Baikal-T1 CCU driver then. It will be required at
> least for the PCIe platform driver. Obviously the DDR controller isn't
> supposed to be fully reset in the kernel, so the corresponding controls
> are added just for the sake of the interface implementation completeness.
> 
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

This looks good to me, the issues with the previous patch still apply.

[...]
> +static int ccu_rst_set(struct reset_controller_dev *rcdev,
> +		       unsigned long idx, bool high)
> +{
> +	struct ccu_rst *rst;
> +
> +	rst = ccu_rst_get_desc(rcdev, idx);
> +	if (IS_ERR(rst)) {
> +		pr_err("Invalid reset index %lu specified\n", idx);
> +		return PTR_ERR(rst);
> +	}

e.g. this should not be necessary.

regards
Philipp

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

* Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-06-29 15:12   ` Philipp Zabel
@ 2022-07-05 22:07     ` Serge Semin
  2022-07-06  9:16       ` Philipp Zabel
  0 siblings, 1 reply; 20+ messages in thread
From: Serge Semin @ 2022-07-05 22:07 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Alexey Malahov,
	Pavel Parkhomenko, Thomas Bogendoerfer, linux-clk, linux-mips,
	linux-kernel

Hi Philipp,

First of all thank you very much for your comments. I've been trying
to merge this series in for more than four months now. So lately I've
almost completely despaired to get it done any time soon. Getting your
comments gives me a hope to finally finish my work.

On Wed, Jun 29, 2022 at 05:12:25PM +0200, Philipp Zabel wrote:
> Hi Serge,
> 
> On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> > Before adding the directly controlled resets support it's reasonable to
> > move the existing resets control functionality into a dedicated object for
> > the sake of the CCU dividers clock driver simplification. After the new
> > functionality was added clk-ccu-div.c would have got to a mixture of the
> > weakly dependent clocks and resets methods. Splitting the methods up into
> > the two objects will make the code easier to read and maintain. It shall
> > also improve the code scalability (though hopefully we won't need this
> > part that much in the future).
> > 
> > As it was done for the CCU PLLs and Dividers the reset control
> > functionality in its turn has been split up into two sub-modules:
> > hw-interface and generic reset device description. This commit doesn't
> > provide any change in the CCU reset module semantics. As before it
> > supports the trigger-like CCU resets only, which are responsible for the
> > AXI-bus, APB-bus and SATA-ref blocks reset. The assert/de-assert-capable
> > reset controls support will be added in the next commit.
> > 
> > Note the CCU Clock dividers and resets functionality split up was possible
> > due to not having any side-effects (at least we didn't found ones) of the
> > regmap-based concurrent access of the common CCU dividers/reset CSRs.
> > 
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > 
> > ---
> > 
> > Changelog v4:
> > - Completely split CCU Dividers and Resets functionality. (@Stephen)
> > ---
> >  drivers/clk/baikal-t1/Kconfig       |  12 +-
> >  drivers/clk/baikal-t1/Makefile      |   1 +
> >  drivers/clk/baikal-t1/ccu-div.c     |  19 ---
> >  drivers/clk/baikal-t1/ccu-div.h     |   4 +-
> >  drivers/clk/baikal-t1/ccu-rst.c     |  43 +++++
> >  drivers/clk/baikal-t1/ccu-rst.h     |  67 ++++++++
> >  drivers/clk/baikal-t1/clk-ccu-div.c | 101 +++---------
> >  drivers/clk/baikal-t1/clk-ccu-rst.c | 236 ++++++++++++++++++++++++++++
> 

> What is the reason for separating ccu-rst.c and clk-ccu-rst.c?
> 
> I expect implementing the reset ops and registering the reset
> controller in the same compilation unit would be easier.

From the very beginning of the Baikal-T1 driver live the Clock/Reset functionality
has been split up into two parts:
1. ccu-{div,pll}.c - Clock/Reset operations implementation.
2. clk-ccu-{div,pll}.c - Clock/Reset kernel interface implementation.
At least for the clk-part it has made the driver much easier to read.
Code in 1. provides the interface methods like
ccu_{div,pll}_hw_register() to register a clock provider corresponding
to the CCU divider/PLL of the particular type. Code in 2. uses these
methods to create the CCU Dividers/PLL clock descriptors and register
the of-based clocks in the system. The reset functionality was
redistributed in the same manner in the framework of the ccu-div.c and
clk-ccu-div.c modules.

A similar approach I was trying to utilize in the framework of the
separate CCU Resets implementation. Although it turned out to be not as
handy as it was for the clock-part due to the different clock and
reset subsystems API (clock subsystem provides a single clock
source based API, while the reset subsystem expects to have the whole
resets controller described). Anyway I've decided to preserve as much
similarities as possible for the sake of the code unification and
better readability/maintainability. Thus the reset lines control
methods have been placed in the ccu-rst.c object file, while the reset
control registration has been implemented in the clk-ccu-rst.c module.

Anyway if you insist on dropping the independent CCU reset IDs and
reset index functionality, then splitting the reset control driver
up will be even less justified since the reset_control_ops callbacks
implementation will shrink further down. So let's settle that part
first. If we get to agree to drop that functionality then indeed there
won't be much need in splitting the code up too.

> 
> > diff --git a/drivers/clk/baikal-t1/ccu-rst.c b/drivers/clk/baikal-t1/ccu-rst.c
> > new file mode 100644
> > index 000000000000..b355bf0b399a
> > --- /dev/null
> > +++ b/drivers/clk/baikal-t1/ccu-rst.c
> > @@ -0,0 +1,43 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> > + *
> > + * Authors:
> > + *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > + *
> > + * Baikal-T1 CCU Resets interface driver
> > + */
> > +
> > +#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
> > +
> > +#include <linux/delay.h>
> > +#include <linux/kernel.h>
> > +#include <linux/printk.h>
> > +#include <linux/regmap.h>
> > +#include <linux/reset-controller.h>
> > +
> > +#include "ccu-rst.h"
> > +
> > +#define CCU_RST_DELAY_US		1
> > +
> > +static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx)
> > +{
> > +	struct ccu_rst *rst;
> > +
> > +	rst = ccu_rst_get_desc(rcdev, idx);
> > +	if (IS_ERR(rst)) {
> > +		pr_err("Invalid reset index %lu specified\n", idx);
> > +		return PTR_ERR(rst);
> > +	}
> 

> I don't think this is necessary, see my comments below. Since the reset
> ids are contiguous, just setting nr_resets and using the default
> .of_xlate should be enough to make sure this is never called with an
> invalid id.

Using non-contiguous !Clock! IDs turned to be unexpectedly handy. Due to
that design I was able to add the internal clock providers hidden from
the DTS users but still visible in the clocks hierarchy. It has made the
clocks implementation as detailed as possible and protected from the
improper clocks usage. It also simplified a new clock providers adding
in future (though there won't be clock sources left undefined in the
SoC after this patchset is applied).

All of that made me thinking that the same approach can be useful in
the framework of the CCU reset controls implementation too at the very
least for the code unification. Although after the next patch in the
series is applied there won't be resets left undefined in the
Baikal-T1 SoC. So from another side you might be partly right on
suggesting to drop the independent reset IDs/descriptors design and
just assume the IDs contiguousness.

So could you please confirm that you still insists on dropping it?

> 
> > +
> > +	regmap_update_bits(rst->sys_regs, rst->reg_ctl, rst->mask, rst->mask);
> 

> I would expect this to get sys_regs from data, which can be obtained
> from rcdev via container_of. The reg_ctl and mask could then be
> obtained from the ccu_rst_info array, data->rsts_info[idx].

Right. As long as we agreed to drop the independent reset
IDs/descriptor index functionality. Please see my comment above.

> 
> > +
> > +	/* The next delay must be enough to cover all the resets. */
> > +	udelay(CCU_RST_DELAY_US);
> > +
> > +	return 0;
> > +}
> [...]
> > +
> > +const struct reset_control_ops ccu_rst_ops = {
> 

> With ops and controller registration in the same .c file this could be
> static.

Can't argue with that. But please see my second comment.

> 
> > +	.reset = ccu_rst_reset,
> > +};
> > diff --git a/drivers/clk/baikal-t1/ccu-rst.h b/drivers/clk/baikal-t1/ccu-rst.h
> > new file mode 100644
> > index 000000000000..d03bae4b7a05
> > --- /dev/null
> > +++ b/drivers/clk/baikal-t1/ccu-rst.h
> > @@ -0,0 +1,67 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +/*
> > + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> > + *
> > + * Baikal-T1 CCU Resets interface driver
> > + */
> > +#ifndef __CLK_BT1_CCU_RST_H__
> > +#define __CLK_BT1_CCU_RST_H__
> > +
> > +#include <linux/of.h>
> > +#include <linux/regmap.h>
> > +
> > +struct ccu_rst_data;
> > +
> > +/*
> > + * struct ccu_rst_init_data - CCU Resets initialization data
> > + * @sys_regs: Baikal-T1 System Controller registers map.
> > + * @np: Pointer to the node with the System CCU block.
> > + */
> > +struct ccu_rst_init_data {
> > +	struct regmap *sys_regs;
> > +	struct device_node *np;
> > +};
> > +
> > +/*
> > + * struct ccu_rst - CCU Reset descriptor
> > + * @id: Reset identifier.
> > + * @reg_ctl: Reset control register base address.
> > + * @sys_regs: Baikal-T1 System Controller registers map.
> > + * @mask: Reset bitmask (normally it's just a single bit flag).
> > + */
> > +struct ccu_rst {
> > +	unsigned int id;
> 

> I'm not convinced this structure is necessary.
> It is just a copy of struct ccu_rst_info, but with an added regmap
> pointer per entry, which seems excessive since the regmap is the same
> for all resets.

Right. If we agree to drop the independent IDs/index functionality,
then this descriptor just won't be needed. So please
give me your answer to my question in the third comment first.

> 
> [...]
> > diff --git a/drivers/clk/baikal-t1/clk-ccu-rst.c b/drivers/clk/baikal-t1/clk-ccu-rst.c
> > new file mode 100644
> > index 000000000000..b10857f48b8b
> > --- /dev/null
> > +++ b/drivers/clk/baikal-t1/clk-ccu-rst.c
> > @@ -0,0 +1,236 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC
> > + *
> > + * Authors:
> > + *   Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > + *
> > + * Baikal-T1 CCU Resets domain driver
> > + */
> > +#define pr_fmt(fmt) "bt1-ccu-rst: " fmt
> > +
> > +#include <linux/bits.h>
> > +#include <linux/kernel.h>
> > +#include <linux/of.h>
> > +#include <linux/printk.h>
> > +#include <linux/regmap.h>
> > +#include <linux/reset-controller.h>
> > +#include <linux/slab.h>
> > +
> > +#include <dt-bindings/reset/bt1-ccu.h>
> > +
> > +#include "ccu-rst.h"
> > +
> > +#define CCU_AXI_MAIN_BASE		0x030
> > +#define CCU_AXI_DDR_BASE		0x034
> > +#define CCU_AXI_SATA_BASE		0x038
> > +#define CCU_AXI_GMAC0_BASE		0x03C
> > +#define CCU_AXI_GMAC1_BASE		0x040
> > +#define CCU_AXI_XGMAC_BASE		0x044
> > +#define CCU_AXI_PCIE_M_BASE		0x048
> > +#define CCU_AXI_PCIE_S_BASE		0x04C
> > +#define CCU_AXI_USB_BASE		0x050
> > +#define CCU_AXI_HWA_BASE		0x054
> > +#define CCU_AXI_SRAM_BASE		0x058
> > +
> > +#define CCU_SYS_SATA_REF_BASE		0x060
> > +#define CCU_SYS_APB_BASE		0x064
> > +
> > +#define CCU_RST_TRIG(_id, _base, _ofs)		\
> > +	{					\
> > +		.id = _id,			\
> 

> I think the _id parameter and id field could be dropped.

ditto

> 
> > +		.base = _base,			\
> > +		.mask = BIT(_ofs),		\
> > +	}
> > +
> > +struct ccu_rst_info {
> > +	unsigned int id;
> 

> This could be dropped.

ditto

> 
> > +	unsigned int base;
> > +	unsigned int mask;
> 

> Are there actually resets that require setting/clearing multiple bits,
> or is this theoretical?

The next patch in this series adds the reset controls implemented in
the framework of the same CSRs. So the base and mask fields are
required in the info array.

> 
> > +};
> > +
> > +struct ccu_rst_data {
> > +	struct device_node *np;
> 

> This is already in rcdev.of_node, no need to carry a copy.

Ok.

> 
> > +	struct regmap *sys_regs;
> > +
> > +	unsigned int rsts_num;
> 

> Same as above, this is already in rcdev.nr_resets.

Ok.

> 
> > +	const struct ccu_rst_info *rsts_info;
> > +	struct ccu_rst *rsts;
> 

> This is not neccessary if you use sys_regs and rsts_info in the reset
> ops.

Right. rsts can be dropped if the contiguous IDs are implied.

> 
> > +
> > +	struct reset_controller_dev rcdev;
> > +};
> > +#define to_ccu_rst_data(_rcdev) container_of(_rcdev, struct ccu_rst_data, rcdev)
> > +
> > +/*
> > + * Each AXI-bus clock divider is equipped with the corresponding clock-consumer
> > + * domain reset (it's self-deasserted reset control).
> > + */
> > +static const struct ccu_rst_info axi_rst_info[] = {
> > +	CCU_RST_TRIG(CCU_AXI_MAIN_RST, CCU_AXI_MAIN_BASE, 1),
> 

> This could be:
> 
> 	[CCU_AXI_MAIN_RST] = CCU_RST_TRIG(CCU_AXI_MAIN_BASE, 1),

Can't argue with that if we get to agree to drop the independent
reset IDs and reset descriptors index functionality. Please see my
third comment in this email.

> 
> > +	CCU_RST_TRIG(CCU_AXI_DDR_RST, CCU_AXI_DDR_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_SATA_RST, CCU_AXI_SATA_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_GMAC0_RST, CCU_AXI_GMAC0_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_GMAC1_RST, CCU_AXI_GMAC1_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_XGMAC_RST, CCU_AXI_XGMAC_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_PCIE_M_RST, CCU_AXI_PCIE_M_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_PCIE_S_RST, CCU_AXI_PCIE_S_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_USB_RST, CCU_AXI_USB_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_HWA_RST, CCU_AXI_HWA_BASE, 1),
> > +	CCU_RST_TRIG(CCU_AXI_SRAM_RST, CCU_AXI_SRAM_BASE, 1),
> > +};
> > +
> > +/*
> > + * SATA reference clock domain and APB-bus domain are connected with the
> > + * sefl-deasserted reset control, which can be activated via the corresponding
> > + * clock divider register. DDR and PCIe sub-domains can be reset with directly
> > + * controlled reset signals. Resetting the DDR controller though won't end up
> > + * well while the Linux kernel is working.
> > + */
> > +static const struct ccu_rst_info sys_rst_info[] = {
> > +	CCU_RST_TRIG(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_BASE, 1),
> 

> Same as above.

ditto

> 
> > +	CCU_RST_TRIG(CCU_SYS_APB_RST, CCU_SYS_APB_BASE, 1),
> > +};
> > +
> > +struct ccu_rst *ccu_rst_get_desc(struct reset_controller_dev *rcdev, unsigned long idx)
> > +{
> > +	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
> > +
> > +	if (idx >= data->rsts_num)
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	return &data->rsts[idx];
> > +}
> 

> This is not necessary if you just use the reset id as an index into the
> ccu_rst_info array.

Right. ditto

> 
> > +
> > +static int ccu_rst_of_idx_get(struct reset_controller_dev *rcdev,
> > +			      const struct of_phandle_args *rstspec)
> > +{
> > +	struct ccu_rst_data *data = to_ccu_rst_data(rcdev);
> > +	unsigned int id, idx;
> > +
> > +	id = rstspec->args[0];
> > +	for (idx = 0; idx < data->rsts_num; ++idx) {
> > +		if (data->rsts[idx].id == id)
> > +			break;
> > +	}
> > +	if (idx == data->rsts_num) {
> > +		pr_err("Invalid reset ID %u specified\n", id);
> > +		return -EINVAL;
> > +	}
> > +
> > +	return idx;
> > +}
> 

> Unless I'm mistaken, id == idx for all resets, and this is not
> necessary at all. You should be able to use the default .of_xlate.

You aren't mistake, but please see my third comment in this email.

> 
> > +
> > +static struct ccu_rst_data *ccu_rst_create_data(const struct ccu_rst_init_data *rst_init)
> > +{
> > +	struct ccu_rst_data *data;
> > +	int ret;
> > +
> > +	data = kzalloc(sizeof(*data), GFP_KERNEL);
> > +	if (!data)
> > +		return ERR_PTR(-ENOMEM);
> > +
> > +	data->np = rst_init->np;
> 

> No reason to store data->np only to copy it to data->rcdev.of_node
> later.

Ok.

> 
> > +	data->sys_regs = rst_init->sys_regs;
> > +	if (of_device_is_compatible(data->np, "baikal,bt1-ccu-axi")) {
> > +		data->rsts_num = ARRAY_SIZE(axi_rst_info);
> 

> You could store the number of resets directly into
> data->rcdev.nr_resets.

Ok.

> 
> > +		data->rsts_info = axi_rst_info;
> > +	} else if (of_device_is_compatible(data->np, "baikal,bt1-ccu-sys")) {
> > +		data->rsts_num = ARRAY_SIZE(sys_rst_info);
> > +		data->rsts_info = sys_rst_info;
> > +	} else {
> > +		pr_err("Incompatible DT node '%s' specified\n",
> > +			of_node_full_name(data->np));
> > +		ret = -EINVAL;
> > +		goto err_kfree_data;
> > +	}
> > +
> > +	data->rsts = kcalloc(data->rsts_num, sizeof(*data->rsts), GFP_KERNEL);
> > +	if (!data->rsts) {
> > +		ret = -ENOMEM;
> > +		goto err_kfree_data;
> > +	}
> 

> I think data->rsts is not required.

Please see my third comment in this email.

> 
> > +
> > +	return data;
> > +
> > +err_kfree_data:
> > +	kfree(data);
> > +
> > +	return ERR_PTR(ret);
> > +}
> > +
> > +static void ccu_rst_free_data(struct ccu_rst_data *data)
> > +{
> > +	kfree(data->rsts);
> >

> Not necessary.

ditto

> 
> > +	kfree(data);
> > +}
> 

> I would fold this into ccu_rst_hw_unregister().

I disagree in this part. Splitting up the interface methods in a set
of the small coherent methods like protagonists and respective
antagonists makes the code much easier to read and maintain. So I
will insist on having the ccu_rst_free_data() method even if it is
left with only a single kfree() function invocation.

> 
> > +
> > +static void ccu_rst_init_desc(struct ccu_rst_data *data)
> > +{
> > +	struct ccu_rst *rst = data->rsts;
> > +	unsigned int idx;
> > +
> > +	for (idx = 0; idx < data->rsts_num; ++idx, ++rst) {
> > +		const struct ccu_rst_info *info = &data->rsts_info[idx];
> > +
> > +		rst->id = info->id;
> > +		rst->type = info->type;
> > +		rst->reg_ctl = info->base;
> > +		rst->sys_regs = data->sys_regs;
> > +		rst->mask = info->mask;
> > +	}
> > +}
> 

> Not necessary.

Right, but see my third comment in this email.

> 
> > +static int ccu_rst_dev_register(struct ccu_rst_data *data)
> > +{
> > +	int ret;
> > +
> > +	data->rcdev.ops = &ccu_rst_ops;
> > +	data->rcdev.of_node = data->np;
> > +	data->rcdev.nr_resets = data->rsts_num;
> > +	data->rcdev.of_reset_n_cells = 1;
> > +	data->rcdev.of_xlate = ccu_rst_of_idx_get;
> > +
> > +	ret = reset_controller_register(&data->rcdev);
> > +	if (ret) {
> > +		pr_err("Couldn't register '%s' reset controller\n",
> > +			of_node_full_name(data->np));
> > +	}
> > +
> > +	return ret;
> > +}
> > +
> > +static void ccu_rst_dev_unregister(struct ccu_rst_data *data)
> > +{
> > +	reset_controller_unregister(&data->rcdev);
> > +}
> 

> I would fold this into ccu_rst_hw_unregister().

I have to disagree for the same reason as I would preserve the
ccu_rst_free_data() method here. Please see my comment above.

> 
> > +struct ccu_rst_data *ccu_rst_hw_register(const struct ccu_rst_init_data *rst_init)
> > +{
> > +	struct ccu_rst_data *data;
> > +	int ret;
> > +
> > +	data = ccu_rst_create_data(rst_init);
> > +	if (IS_ERR(data))
> > +		return data;
> > +
> > +	ccu_rst_init_desc(data);
> 

> Not necessary.

Right, but see my question in the third comment of this email.

> 
> > +
> > +	ret = ccu_rst_dev_register(data);
> > +	if (ret)
> > +		goto err_free_data;
> > +
> > +	return data;
> > +
> > +err_free_data:
> > +	ccu_rst_free_data(data);
> > +
> > +	return ERR_PTR(ret);
> > +}
> > +
> > +void ccu_rst_hw_unregister(struct ccu_rst_data *data)
> > +{
> > +	ccu_rst_dev_unregister(data);
> > +
> > +	ccu_rst_free_data(data);
> > +}
> 

> To me it looks like you could avoid a few unnecessary complications and
> copied data if you merged ccu-rst.c and clk-ccu-rst.c and made use of
> the contiguous reset ids instead of the custom of_xlate and the copied
> ccu_rst descriptors.

I see your point. Please read my third comment in this email and
answer to my question there. If you still insist on dropping the
independent reset IDs and reset descriptor index functionality despite
of my reasoning there, I'll merge the modules and use the standard
of_xlate implementation.

-Sergey

> 
> regards
> Philipp

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

* Re: [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support
  2022-06-29 15:16   ` Philipp Zabel
@ 2022-07-05 22:11     ` Serge Semin
  0 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-07-05 22:11 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Rob Herring,
	Krzysztof Kozlowski, Alexey Malahov, Pavel Parkhomenko,
	Thomas Bogendoerfer, linux-clk, linux-mips, linux-kernel,
	devicetree

Hi Philipp

On Wed, Jun 29, 2022 at 05:16:56PM +0200, Philipp Zabel wrote:
> Hi Serge,
> 
> On Fr, 2022-06-24 at 17:18 +0300, Serge Semin wrote:
> > Aside with a set of the trigger-like resets Baikal-T1 CCU provides two
> > additional blocks with directly controlled reset signals. In particular it
> > concerns DDR full and initial resets and various PCIe sub-domains resets.
> > Let's add the direct reset assertion/de-assertion of the corresponding
> > flags support into the Baikal-T1 CCU driver then. It will be required at
> > least for the PCIe platform driver. Obviously the DDR controller isn't
> > supposed to be fully reset in the kernel, so the corresponding controls
> > are added just for the sake of the interface implementation completeness.
> > 
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> 

> This looks good to me, the issues with the previous patch still apply.

I see. Let's settle the main question there first then. Further
actions in this patch framework depend on your answer there.

-Sergey

> 
> [...]
> > +static int ccu_rst_set(struct reset_controller_dev *rcdev,
> > +		       unsigned long idx, bool high)
> > +{
> > +	struct ccu_rst *rst;
> > +
> > +	rst = ccu_rst_get_desc(rcdev, idx);
> > +	if (IS_ERR(rst)) {
> > +		pr_err("Invalid reset index %lu specified\n", idx);
> > +		return PTR_ERR(rst);
> > +	}
> 
> e.g. this should not be necessary.
> 
> regards
> Philipp

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

* Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-07-05 22:07     ` Serge Semin
@ 2022-07-06  9:16       ` Philipp Zabel
  2022-07-06 22:10         ` Serge Semin
  0 siblings, 1 reply; 20+ messages in thread
From: Philipp Zabel @ 2022-07-06  9:16 UTC (permalink / raw)
  To: Serge Semin
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Alexey Malahov,
	Pavel Parkhomenko, Thomas Bogendoerfer, linux-clk, linux-mips,
	linux-kernel

Hi Serge,

On Mi, 2022-07-06 at 01:07 +0300, Serge Semin wrote:
[...]
> > What is the reason for separating ccu-rst.c and clk-ccu-rst.c?
> > 
> > I expect implementing the reset ops and registering the reset
> > controller in the same compilation unit would be easier.
> 
> From the very beginning of the Baikal-T1 driver live the Clock/Reset functionality
> has been split up into two parts:
> 1. ccu-{div,pll}.c - Clock/Reset operations implementation.
> 2. clk-ccu-{div,pll}.c - Clock/Reset kernel interface implementation.
> At least for the clk-part it has made the driver much easier to read.
> Code in 1. provides the interface methods like
> ccu_{div,pll}_hw_register() to register a clock provider corresponding
> to the CCU divider/PLL of the particular type. Code in 2. uses these
> methods to create the CCU Dividers/PLL clock descriptors and register
> the of-based clocks in the system. The reset functionality was
> redistributed in the same manner in the framework of the ccu-div.c and
> clk-ccu-div.c modules.
> 
> A similar approach I was trying to utilize in the framework of the
> separate CCU Resets implementation. Although it turned out to be not as
> handy as it was for the clock-part due to the different clock and
> reset subsystems API (clock subsystem provides a single clock
> source based API, while the reset subsystem expects to have the whole
> resets controller described). Anyway I've decided to preserve as much
> similarities as possible for the sake of the code unification and
> better readability/maintainability. Thus the reset lines control
> methods have been placed in the ccu-rst.c object file, while the reset
> control registration has been implemented in the clk-ccu-rst.c module.

Thank you for the detailed explanation. I think that splitting doesn't
help readability much in this case, but I realize that may just be a
matter of preference.

[...]
> > I don't think this is necessary, see my comments below. Since the reset
> > ids are contiguous, just setting nr_resets and using the default
> > .of_xlate should be enough to make sure this is never called with an
> > invalid id.
> 
> Using non-contiguous !Clock! IDs turned to be unexpectedly handy. Due to
> that design I was able to add the internal clock providers hidden from
> the DTS users but still visible in the clocks hierarchy. It has made the
> clocks implementation as detailed as possible and protected from the
> improper clocks usage. It also simplified a new clock providers adding
> in future (though there won't be clock sources left undefined in the
> SoC after this patchset is applied).
> 
> All of that made me thinking that the same approach can be useful in
> the framework of the CCU reset controls implementation too at the very
> least for the code unification. Although after the next patch in the
> series is applied there won't be resets left undefined in the
> Baikal-T1 SoC. So from another side you might be partly right on
> suggesting to drop the independent reset IDs/descriptors design and
> just assume the IDs contiguousness.
> 
> So could you please confirm that you still insists on dropping it?

Please drop it, then. I don't think there is value in carrying this
complexity just because it makes the code more similar to the
neighboring clk code.

I'd prefer to keep the reset ids contiguous, so future hardware should
just get a different set of contiguous IDs, or new IDs appended
contiguously as you do in patch 7.

[...]
> > 
> > 
> > 
> > I would fold this into ccu_rst_hw_unregister().
> 
> I disagree in this part. Splitting up the interface methods in a set
> of the small coherent methods like protagonists and respective
> antagonists makes the code much easier to read and maintain. So I
> will insist on having the ccu_rst_free_data() method even if it is
> left with only a single kfree() function invocation.
[...]
> I have to disagree for the same reason as I would preserve the
> ccu_rst_free_data() method here. Please see my comment above.

I'm fine with that.

> 
regards
Philipp

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

* Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-07-06  9:16       ` Philipp Zabel
@ 2022-07-06 22:10         ` Serge Semin
  2022-07-08 19:32           ` Serge Semin
  0 siblings, 1 reply; 20+ messages in thread
From: Serge Semin @ 2022-07-06 22:10 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Alexey Malahov,
	Pavel Parkhomenko, Thomas Bogendoerfer, linux-clk, linux-mips,
	linux-kernel

On Wed, Jul 06, 2022 at 11:16:34AM +0200, Philipp Zabel wrote:
> Hi Serge,
> 
> On Mi, 2022-07-06 at 01:07 +0300, Serge Semin wrote:
> [...]
> > > What is the reason for separating ccu-rst.c and clk-ccu-rst.c?
> > > 
> > > I expect implementing the reset ops and registering the reset
> > > controller in the same compilation unit would be easier.
> > 
> > From the very beginning of the Baikal-T1 driver live the Clock/Reset functionality
> > has been split up into two parts:
> > 1. ccu-{div,pll}.c - Clock/Reset operations implementation.
> > 2. clk-ccu-{div,pll}.c - Clock/Reset kernel interface implementation.
> > At least for the clk-part it has made the driver much easier to read.
> > Code in 1. provides the interface methods like
> > ccu_{div,pll}_hw_register() to register a clock provider corresponding
> > to the CCU divider/PLL of the particular type. Code in 2. uses these
> > methods to create the CCU Dividers/PLL clock descriptors and register
> > the of-based clocks in the system. The reset functionality was
> > redistributed in the same manner in the framework of the ccu-div.c and
> > clk-ccu-div.c modules.
> > 
> > A similar approach I was trying to utilize in the framework of the
> > separate CCU Resets implementation. Although it turned out to be not as
> > handy as it was for the clock-part due to the different clock and
> > reset subsystems API (clock subsystem provides a single clock
> > source based API, while the reset subsystem expects to have the whole
> > resets controller described). Anyway I've decided to preserve as much
> > similarities as possible for the sake of the code unification and
> > better readability/maintainability. Thus the reset lines control
> > methods have been placed in the ccu-rst.c object file, while the reset
> > control registration has been implemented in the clk-ccu-rst.c module.
> 
> Thank you for the detailed explanation. I think that splitting doesn't
> help readability much in this case, but I realize that may just be a
> matter of preference.
> 
> [...]
> > > I don't think this is necessary, see my comments below. Since the reset
> > > ids are contiguous, just setting nr_resets and using the default
> > > .of_xlate should be enough to make sure this is never called with an
> > > invalid id.
> > 
> > Using non-contiguous !Clock! IDs turned to be unexpectedly handy. Due to
> > that design I was able to add the internal clock providers hidden from
> > the DTS users but still visible in the clocks hierarchy. It has made the
> > clocks implementation as detailed as possible and protected from the
> > improper clocks usage. It also simplified a new clock providers adding
> > in future (though there won't be clock sources left undefined in the
> > SoC after this patchset is applied).
> > 
> > All of that made me thinking that the same approach can be useful in
> > the framework of the CCU reset controls implementation too at the very
> > least for the code unification. Although after the next patch in the
> > series is applied there won't be resets left undefined in the
> > Baikal-T1 SoC. So from another side you might be partly right on
> > suggesting to drop the independent reset IDs/descriptors design and
> > just assume the IDs contiguousness.
> > 
> > So could you please confirm that you still insists on dropping it?
> 

> Please drop it, then. I don't think there is value in carrying this
> complexity just because it makes the code more similar to the
> neighboring clk code.
> 
> I'd prefer to keep the reset ids contiguous, so future hardware should
> just get a different set of contiguous IDs, or new IDs appended
> contiguously as you do in patch 7.

Agreed then. I'll update the patches and resend the series shortly.
Thank you very much for review.

-Sergey

> 
> [...]
> > > 
> > > 
> > > 
> > > I would fold this into ccu_rst_hw_unregister().
> > 
> > I disagree in this part. Splitting up the interface methods in a set
> > of the small coherent methods like protagonists and respective
> > antagonists makes the code much easier to read and maintain. So I
> > will insist on having the ccu_rst_free_data() method even if it is
> > left with only a single kfree() function invocation.
> [...]
> > I have to disagree for the same reason as I would preserve the
> > ccu_rst_free_data() method here. Please see my comment above.
> 
> I'm fine with that.
> 
> > 
> regards
> Philipp

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

* Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module
  2022-07-06 22:10         ` Serge Semin
@ 2022-07-08 19:32           ` Serge Semin
  0 siblings, 0 replies; 20+ messages in thread
From: Serge Semin @ 2022-07-08 19:32 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Serge Semin, Stephen Boyd, Michael Turquette, Alexey Malahov,
	Pavel Parkhomenko, Thomas Bogendoerfer, linux-clk, linux-mips,
	linux-kernel

Hi Philipp

On Thu, Jul 07, 2022 at 01:10:18AM +0300, Serge Semin wrote:
> On Wed, Jul 06, 2022 at 11:16:34AM +0200, Philipp Zabel wrote:
> > Hi Serge,
> > 
> > On Mi, 2022-07-06 at 01:07 +0300, Serge Semin wrote:
> > [...]
> > > > What is the reason for separating ccu-rst.c and clk-ccu-rst.c?
> > > > 
> > > > I expect implementing the reset ops and registering the reset
> > > > controller in the same compilation unit would be easier.
> > > 
> > > From the very beginning of the Baikal-T1 driver live the Clock/Reset functionality
> > > has been split up into two parts:
> > > 1. ccu-{div,pll}.c - Clock/Reset operations implementation.
> > > 2. clk-ccu-{div,pll}.c - Clock/Reset kernel interface implementation.
> > > At least for the clk-part it has made the driver much easier to read.
> > > Code in 1. provides the interface methods like
> > > ccu_{div,pll}_hw_register() to register a clock provider corresponding
> > > to the CCU divider/PLL of the particular type. Code in 2. uses these
> > > methods to create the CCU Dividers/PLL clock descriptors and register
> > > the of-based clocks in the system. The reset functionality was
> > > redistributed in the same manner in the framework of the ccu-div.c and
> > > clk-ccu-div.c modules.
> > > 
> > > A similar approach I was trying to utilize in the framework of the
> > > separate CCU Resets implementation. Although it turned out to be not as
> > > handy as it was for the clock-part due to the different clock and
> > > reset subsystems API (clock subsystem provides a single clock
> > > source based API, while the reset subsystem expects to have the whole
> > > resets controller described). Anyway I've decided to preserve as much
> > > similarities as possible for the sake of the code unification and
> > > better readability/maintainability. Thus the reset lines control
> > > methods have been placed in the ccu-rst.c object file, while the reset
> > > control registration has been implemented in the clk-ccu-rst.c module.
> > 
> > Thank you for the detailed explanation. I think that splitting doesn't
> > help readability much in this case, but I realize that may just be a
> > matter of preference.
> > 
> > [...]
> > > > I don't think this is necessary, see my comments below. Since the reset
> > > > ids are contiguous, just setting nr_resets and using the default
> > > > .of_xlate should be enough to make sure this is never called with an
> > > > invalid id.
> > > 
> > > Using non-contiguous !Clock! IDs turned to be unexpectedly handy. Due to
> > > that design I was able to add the internal clock providers hidden from
> > > the DTS users but still visible in the clocks hierarchy. It has made the
> > > clocks implementation as detailed as possible and protected from the
> > > improper clocks usage. It also simplified a new clock providers adding
> > > in future (though there won't be clock sources left undefined in the
> > > SoC after this patchset is applied).
> > > 
> > > All of that made me thinking that the same approach can be useful in
> > > the framework of the CCU reset controls implementation too at the very
> > > least for the code unification. Although after the next patch in the
> > > series is applied there won't be resets left undefined in the
> > > Baikal-T1 SoC. So from another side you might be partly right on
> > > suggesting to drop the independent reset IDs/descriptors design and
> > > just assume the IDs contiguousness.
> > > 
> > > So could you please confirm that you still insists on dropping it?
> > 
> 

> > Please drop it, then. I don't think there is value in carrying this
> > complexity just because it makes the code more similar to the
> > neighboring clk code.
> > 
> > I'd prefer to keep the reset ids contiguous, so future hardware should
> > just get a different set of contiguous IDs, or new IDs appended
> > contiguously as you do in patch 7.
> 
> Agreed then. I'll update the patches and resend the series shortly.
> Thank you very much for review.

The series has been updated the way you asked. Please review:

Link: https://lore.kernel.org/linux-clk/20220708192725.9501-1-Sergey.Semin@baikalelectronics.ru/

-Sergey

> 
> -Sergey
> 
> > 
> > [...]
> > > > 
> > > > 
> > > > 
> > > > I would fold this into ccu_rst_hw_unregister().
> > > 
> > > I disagree in this part. Splitting up the interface methods in a set
> > > of the small coherent methods like protagonists and respective
> > > antagonists makes the code much easier to read and maintain. So I
> > > will insist on having the ccu_rst_free_data() method even if it is
> > > left with only a single kfree() function invocation.
> > [...]
> > > I have to disagree for the same reason as I would preserve the
> > > ccu_rst_free_data() method here. Please see my comment above.
> > 
> > I'm fine with that.
> > 
> > > 
> > regards
> > Philipp

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

end of thread, other threads:[~2022-07-08 19:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 14:18 [PATCH RESEND v5 0/8] clk/resets: baikal-t1: Add DDR/PCIe resets and xGMAC/SATA fixes Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 1/8] reset: Fix devm bulk optional exclusive control getter Serge Semin
2022-06-26 22:35   ` Dmitry Osipenko
2022-06-27 22:20     ` Serge Semin
2022-06-29 14:02   ` Philipp Zabel
2022-06-29 15:06     ` Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 2/8] clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 3/8] clk: baikal-t1: Fix invalid xGMAC PTP clock divider Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 4/8] clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 5/8] clk: baikal-t1: Add SATA internal ref clock buffer Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module Serge Semin
2022-06-29 15:12   ` Philipp Zabel
2022-07-05 22:07     ` Serge Semin
2022-07-06  9:16       ` Philipp Zabel
2022-07-06 22:10         ` Serge Semin
2022-07-08 19:32           ` Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 7/8] clk: baikal-t1: Add DDR/PCIe directly controlled resets support Serge Semin
2022-06-29 15:16   ` Philipp Zabel
2022-07-05 22:11     ` Serge Semin
2022-06-24 14:18 ` [PATCH RESEND v5 8/8] clk: baikal-t1: Convert to platform device driver Serge Semin

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.