2022-06-24 14:41:14

by Serge Semin

[permalink] [raw]
Subject: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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 <[email protected]>

---

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 <[email protected]>
+ *
+ * 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 <[email protected]>
+ *
+ * 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


2022-06-29 16:01:37

by Philipp Zabel

[permalink] [raw]
Subject: Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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 <[email protected]>
>
> ---
>
> 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 <[email protected]>
> + *
> + * 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 <[email protected]>
> + *
> + * 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

2022-07-05 22:16:45

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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 <[email protected]>
> >
> > ---
> >
> > 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 <[email protected]>
> > + *
> > + * 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 <[email protected]>
> > + *
> > + * 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

2022-07-06 09:30:19

by Philipp Zabel

[permalink] [raw]
Subject: Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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

2022-07-06 22:19:14

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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

2022-07-08 20:02:58

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH RESEND v5 6/8] clk: baikal-t1: Move reset-controls code into a dedicated module

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/[email protected]/

-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