Skip to contentSkip to conversation

clk: mediatek: Don't check HW status for mt8192/5's imp_iic_wrap clocks

PATCH In review Nícolas F. R. A. Prado 3 participants 7 messages Jul 11, 2022 – Jul 12, 2022

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

PATCH 1/1 clk: mediatek: Don't check HW status for mt8192/5's imp_iic_wrap clocks

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

---

 drivers/clk/mediatek/clk-gate.c                | 6 ++++++
 drivers/clk/mediatek/clk-gate.h                | 1 +
 drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
 drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
 4 files changed, 9 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-gate.c +6 -0
index 421806236228..8e7c719a69b3 100644
@@ -124,6 +124,12 @@ static void mtk_cg_disable_inv_no_setclr(struct clk_hw *hw)
 	mtk_cg_clr_bit_no_setclr(hw);
 }
 
+const struct clk_ops mtk_clk_gate_ops_setclr_counted = {
+	.enable		= mtk_cg_enable,
+	.disable	= mtk_cg_disable,
+};
+EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_setclr_counted);
+
 const struct clk_ops mtk_clk_gate_ops_setclr = {
 	.is_enabled	= mtk_cg_bit_is_cleared,
 	.enable		= mtk_cg_enable,
drivers/clk/mediatek/clk-gate.h +1 -0
index d9897ef53528..b5502b2911f5 100644
@@ -19,6 +19,7 @@ extern const struct clk_ops mtk_clk_gate_ops_setclr;
 extern const struct clk_ops mtk_clk_gate_ops_setclr_inv;
 extern const struct clk_ops mtk_clk_gate_ops_no_setclr;
 extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv;
+extern const struct clk_ops mtk_clk_gate_ops_setclr_counted;
 
 struct mtk_gate_regs {
 	u32 sta_ofs;
drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c +1 -1
index 700356ac6a58..900ee601169c 100644
@@ -20,7 +20,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
 #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)			\
 	GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,	\
-		&mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+		&mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
 static const struct mtk_gate imp_iic_wrap_c_clks[] = {
 	GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_C_I2C10, "imp_iic_wrap_c_i2c10", "infra_i2c0", 0),
drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +1 -1
index fbc809d05072..e50a77b844f4 100644
@@ -18,7 +18,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
 #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)				\
 	GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,	\
-		&mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+		&mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
 static const struct mtk_gate imp_iic_wrap_s_clks[] = {
 	GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_S_I2C5, "imp_iic_wrap_s_i2c5", "top_i2c", 0),
Signature · 1 line
2.37.0
maintainer Tested-by on v1 1/1
#1 lore raw

Il 11/07/22 22:57, Nícolas F. R. A. Prado ha scritto:

Quoted 10 lines

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

For both MT8192 and MT8195:

Quoted 8 lines

---

  drivers/clk/mediatek/clk-gate.c                | 6 ++++++
  drivers/clk/mediatek/clk-gate.h                | 1 +
  drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
  drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
  4 files changed, 9 insertions(+), 2 deletions(-)
#2 lore raw
In reply to Nícolas F. R. A. Prado

Hi,

Quoted 9 lines · Nícolas F. R. A. Prado

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

That's the wrong way to go about it.

The I2C clocks already have the CLK_OPS_PARENT_ENABLE flag set. So the issue is that somewhere in the clk core, a piece of code is not honoring that flag.

And it seems that's in more than one place.

Regards
ChenYu

Quoted 68 lines

---

 drivers/clk/mediatek/clk-gate.c                | 6 ++++++
 drivers/clk/mediatek/clk-gate.h                | 1 +
 drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
 drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
 4 files changed, 9 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-gate.c +6 -0
index 421806236228..8e7c719a69b3 100644
@@ -124,6 +124,12 @@ static void mtk_cg_disable_inv_no_setclr(struct clk_hw *hw)
        mtk_cg_clr_bit_no_setclr(hw);
 }
 
+const struct clk_ops mtk_clk_gate_ops_setclr_counted = {
+       .enable         = mtk_cg_enable,
+       .disable        = mtk_cg_disable,
+};
+EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_setclr_counted);
+
 const struct clk_ops mtk_clk_gate_ops_setclr = {
        .is_enabled     = mtk_cg_bit_is_cleared,
        .enable         = mtk_cg_enable,
drivers/clk/mediatek/clk-gate.h +1 -0
index d9897ef53528..b5502b2911f5 100644
@@ -19,6 +19,7 @@ extern const struct clk_ops mtk_clk_gate_ops_setclr;
 extern const struct clk_ops mtk_clk_gate_ops_setclr_inv;
 extern const struct clk_ops mtk_clk_gate_ops_no_setclr;
 extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv;
+extern const struct clk_ops mtk_clk_gate_ops_setclr_counted;
 
 struct mtk_gate_regs {
        u32 sta_ofs;
drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c +1 -1
index 700356ac6a58..900ee601169c 100644
@@ -20,7 +20,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
 #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                 \
        GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
 static const struct mtk_gate imp_iic_wrap_c_clks[] = {
        GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_C_I2C10, "imp_iic_wrap_c_i2c10", "infra_i2c0", 0),
drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +1 -2
index fbc809d05072..e50a77b844f4 100644
@@ -18,7 +18,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
 #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                         \
        GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
 static const struct mtk_gate imp_iic_wrap_s_clks[] = {
        GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_S_I2C5, "imp_iic_wrap_s_i2c5", "top_i2c", 0),
--

2.37.0

#3 lore raw

Il 12/07/22 12:44, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Hi,

Quoted 9 lines · Nícolas F. R. A. Prado

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

Quoted 8 lines

That's the wrong way to go about it.

The I2C clocks already have the CLK_OPS_PARENT_ENABLE flag set. So the issue is that somewhere in the clk core, a piece of code is not honoring that flag.

And it seems that's in more than one place.

Uhm, you're right. I gave my Tested-by, but not a Reviewed-by because I wasn't really convinced about this solution being the best.

Now that I think of it, the solution may be as simple as:

clk.c

static bool clk_core_is_enabled(struct clk_core *core)

{
	bool ret = false;

	/*
	 * If this clock needs parent enabled, but its parent is
	 * off, we directly return false for two reasons:
	 * 1. This clock being enabled would be impossible
	 * 2. The platform may crash for unclocked access while
	 *    reading the status of this clock (where a .is_enabled
	 *    callback is provided).
	 */
	if (core->flags & CLK_OPS_PARENT_ENABLE &&
	    !clk_core_is_enabled(core->parent))
		return false;

	... etc etc etc ...
}

Nícolas, did you try this approach?

Quoted 71 lines

Regards
ChenYu

Quoted 68 lines

---

  drivers/clk/mediatek/clk-gate.c                | 6 ++++++
  drivers/clk/mediatek/clk-gate.h                | 1 +
  drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
  drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
  4 files changed, 9 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-gate.c +6 -0
index 421806236228..8e7c719a69b3 100644
@@ -124,6 +124,12 @@ static void mtk_cg_disable_inv_no_setclr(struct clk_hw *hw)
         mtk_cg_clr_bit_no_setclr(hw);
  }
 
+const struct clk_ops mtk_clk_gate_ops_setclr_counted = {
+       .enable         = mtk_cg_enable,
+       .disable        = mtk_cg_disable,
+};
+EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_setclr_counted);
+
  const struct clk_ops mtk_clk_gate_ops_setclr = {
         .is_enabled     = mtk_cg_bit_is_cleared,
         .enable         = mtk_cg_enable,
drivers/clk/mediatek/clk-gate.h +1 -0
index d9897ef53528..b5502b2911f5 100644
@@ -19,6 +19,7 @@ extern const struct clk_ops mtk_clk_gate_ops_setclr;
  extern const struct clk_ops mtk_clk_gate_ops_setclr_inv;
  extern const struct clk_ops mtk_clk_gate_ops_no_setclr;
  extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv;
+extern const struct clk_ops mtk_clk_gate_ops_setclr_counted;
 
  struct mtk_gate_regs {
         u32 sta_ofs;
drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c +1 -1
index 700356ac6a58..900ee601169c 100644
@@ -20,7 +20,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
  #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                 \
         GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
  static const struct mtk_gate imp_iic_wrap_c_clks[] = {
         GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_C_I2C10, "imp_iic_wrap_c_i2c10", "infra_i2c0", 0),
drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +1 -2
index fbc809d05072..e50a77b844f4 100644
@@ -18,7 +18,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
  #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                         \
         GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
  static const struct mtk_gate imp_iic_wrap_s_clks[] = {
         GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_S_I2C5, "imp_iic_wrap_s_i2c5", "top_i2c", 0),
--

2.37.0

#4 lore raw
Quoted 51 lines · AngeloGioacchino Del Regno

Il 12/07/22 12:44, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Hi,

Quoted 9 lines · Nícolas F. R. A. Prado

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

Quoted 8 lines

That's the wrong way to go about it.

The I2C clocks already have the CLK_OPS_PARENT_ENABLE flag set. So the issue is that somewhere in the clk core, a piece of code is not honoring that flag.

And it seems that's in more than one place.

Uhm, you're right. I gave my Tested-by, but not a Reviewed-by because I wasn't really convinced about this solution being the best.

Now that I think of it, the solution may be as simple as:

clk.c

static bool clk_core_is_enabled(struct clk_core *core)

{
        bool ret = false;

        /*
         * If this clock needs parent enabled, but its parent is
         * off, we directly return false for two reasons:
         * 1. This clock being enabled would be impossible
         * 2. The platform may crash for unclocked access while
         *    reading the status of this clock (where a .is_enabled
         *    callback is provided).
         */
        if (core->flags & CLK_OPS_PARENT_ENABLE &&
            !clk_core_is_enabled(core->parent))
                return false;

        ... etc etc etc ...
}
Quoted 1 line

Nícolas, did you try this approach?

I have a patch ready, but I got distracted by other stuff today.

ChenYu

Quoted 73 lines
Quoted 71 lines

Regards
ChenYu

Quoted 68 lines

---

  drivers/clk/mediatek/clk-gate.c                | 6 ++++++
  drivers/clk/mediatek/clk-gate.h                | 1 +
  drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
  drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
  4 files changed, 9 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-gate.c +6 -0
index 421806236228..8e7c719a69b3 100644
@@ -124,6 +124,12 @@ static void mtk_cg_disable_inv_no_setclr(struct clk_hw *hw)
         mtk_cg_clr_bit_no_setclr(hw);
  }
 
+const struct clk_ops mtk_clk_gate_ops_setclr_counted = {
+       .enable         = mtk_cg_enable,
+       .disable        = mtk_cg_disable,
+};
+EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_setclr_counted);
+
  const struct clk_ops mtk_clk_gate_ops_setclr = {
         .is_enabled     = mtk_cg_bit_is_cleared,
         .enable         = mtk_cg_enable,
drivers/clk/mediatek/clk-gate.h +1 -0
index d9897ef53528..b5502b2911f5 100644
@@ -19,6 +19,7 @@ extern const struct clk_ops mtk_clk_gate_ops_setclr;
  extern const struct clk_ops mtk_clk_gate_ops_setclr_inv;
  extern const struct clk_ops mtk_clk_gate_ops_no_setclr;
  extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv;
+extern const struct clk_ops mtk_clk_gate_ops_setclr_counted;
 
  struct mtk_gate_regs {
         u32 sta_ofs;
drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c +1 -1
index 700356ac6a58..900ee601169c 100644
@@ -20,7 +20,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
  #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                 \
         GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
  static const struct mtk_gate imp_iic_wrap_c_clks[] = {
         GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_C_I2C10, "imp_iic_wrap_c_i2c10", "infra_i2c0", 0),
drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +1 -2
index fbc809d05072..e50a77b844f4 100644
@@ -18,7 +18,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
  #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                         \
         GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
  static const struct mtk_gate imp_iic_wrap_s_clks[] = {
         GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_S_I2C5, "imp_iic_wrap_s_i2c5", "top_i2c", 0),
--

2.37.0

#5 lore raw

Il 12/07/22 12:56, Chen-Yu Tsai ha scritto:

Quoted 50 lines
Quoted 48 lines · AngeloGioacchino Del Regno

Il 12/07/22 12:44, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Hi,

Quoted 9 lines · Nícolas F. R. A. Prado

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

Quoted 8 lines

That's the wrong way to go about it.

The I2C clocks already have the CLK_OPS_PARENT_ENABLE flag set. So the issue is that somewhere in the clk core, a piece of code is not honoring that flag.

And it seems that's in more than one place.

Uhm, you're right. I gave my Tested-by, but not a Reviewed-by because I wasn't really convinced about this solution being the best.

Now that I think of it, the solution may be as simple as:

clk.c

static bool clk_core_is_enabled(struct clk_core *core) {
bool ret = false;

/*
* If this clock needs parent enabled, but its parent is
* off, we directly return false for two reasons:
* 1. This clock being enabled would be impossible
* 2. The platform may crash for unclocked access while
* reading the status of this clock (where a .is_enabled
* callback is provided).
*/
if (core->flags & CLK_OPS_PARENT_ENABLE &&
!clk_core_is_enabled(core->parent))
return false;

Quoted 7 lines
Quoted 4 lines
         ... etc etc etc ...
}

Nícolas, did you try this approach?

I have a patch ready, but I got distracted by other stuff today.

Let's just wait for your patch then, seems like being the most sensible option.

Cheers!

Quoted 75 lines

ChenYu

Quoted 73 lines
Quoted 71 lines

Regards
ChenYu

Quoted 68 lines

---

   drivers/clk/mediatek/clk-gate.c                | 6 ++++++
   drivers/clk/mediatek/clk-gate.h                | 1 +
   drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c | 2 +-
   drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 2 +-
   4 files changed, 9 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-gate.c +6 -0
index 421806236228..8e7c719a69b3 100644
@@ -124,6 +124,12 @@ static void mtk_cg_disable_inv_no_setclr(struct clk_hw *hw)
          mtk_cg_clr_bit_no_setclr(hw);
   }
 
+const struct clk_ops mtk_clk_gate_ops_setclr_counted = {
+       .enable         = mtk_cg_enable,
+       .disable        = mtk_cg_disable,
+};
+EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_setclr_counted);
+
   const struct clk_ops mtk_clk_gate_ops_setclr = {
          .is_enabled     = mtk_cg_bit_is_cleared,
          .enable         = mtk_cg_enable,
drivers/clk/mediatek/clk-gate.h +1 -0
index d9897ef53528..b5502b2911f5 100644
@@ -19,6 +19,7 @@ extern const struct clk_ops mtk_clk_gate_ops_setclr;
   extern const struct clk_ops mtk_clk_gate_ops_setclr_inv;
   extern const struct clk_ops mtk_clk_gate_ops_no_setclr;
   extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv;
+extern const struct clk_ops mtk_clk_gate_ops_setclr_counted;
 
   struct mtk_gate_regs {
          u32 sta_ofs;
drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.c +1 -1
index 700356ac6a58..900ee601169c 100644
@@ -20,7 +20,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
   #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                 \
          GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
   static const struct mtk_gate imp_iic_wrap_c_clks[] = {
          GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_C_I2C10, "imp_iic_wrap_c_i2c10", "infra_i2c0", 0),
drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +1 -2
index fbc809d05072..e50a77b844f4 100644
@@ -18,7 +18,7 @@ static const struct mtk_gate_regs imp_iic_wrap_cg_regs = {
 
   #define GATE_IMP_IIC_WRAP(_id, _name, _parent, _shift)                         \
          GATE_MTK_FLAGS(_id, _name, _parent, &imp_iic_wrap_cg_regs, _shift,      \
-               &mtk_clk_gate_ops_setclr, CLK_OPS_PARENT_ENABLE)
+               &mtk_clk_gate_ops_setclr_counted, CLK_OPS_PARENT_ENABLE)
 
   static const struct mtk_gate imp_iic_wrap_s_clks[] = {
          GATE_IMP_IIC_WRAP(CLK_IMP_IIC_WRAP_S_I2C5, "imp_iic_wrap_s_i2c5", "top_i2c", 0),
--

2.37.0

Signature · 6 lines
AngeloGioacchino Del Regno
Software Engineer

Collabora Ltd.
Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
Registered in England & Wales, no. 5513718
#6 lore raw
Quoted 55 lines · AngeloGioacchino Del Regno

Il 12/07/22 12:56, Chen-Yu Tsai ha scritto:

Quoted 54 lines
Quoted 52 lines · AngeloGioacchino Del Regno

Il 12/07/22 12:44, Chen-Yu Tsai ha scritto:

Quoted 14 lines

Hi,

Quoted 9 lines · Nícolas F. R. A. Prado

The imp_iic_wrap clocks on mt8192/mt8195 require that the i2c_sel parent clock be enabled before their hardware status can be checked. Since this wasn't taken into account, reading from the clk_summary debugfs file would cause the system to completely freeze.

Assuming that this clock is managed only by the kernel, and not by any firmware, simply drop the is_enabled() optional callback and instead rely on the enable count for the imp_iic_wrap clocks.

Quoted 8 lines

That's the wrong way to go about it.

The I2C clocks already have the CLK_OPS_PARENT_ENABLE flag set. So the issue is that somewhere in the clk core, a piece of code is not honoring that flag.

And it seems that's in more than one place.

Uhm, you're right. I gave my Tested-by, but not a Reviewed-by because I wasn't really convinced about this solution being the best.

Now that I think of it, the solution may be as simple as:

clk.c

static bool clk_core_is_enabled(struct clk_core *core)

{
         bool ret = false;

         /*
          * If this clock needs parent enabled, but its parent is
          * off, we directly return false for two reasons:
          * 1. This clock being enabled would be impossible
          * 2. The platform may crash for unclocked access while
          *    reading the status of this clock (where a .is_enabled
          *    callback is provided).
          */
         if (core->flags & CLK_OPS_PARENT_ENABLE &&
             !clk_core_is_enabled(core->parent))
                 return false;

         ... etc etc etc ...
}

Nícolas, did you try this approach?

From reading the core clock code, it's mentioned that CLK_OPS_PARENT_ENABLE is used "during gate/ungate, set rate and re-parent", there's no mention of "checking the gate state", so I assumed this operation was intentionally not handled by this flag. That's why I went for this solution.

But from the discussion sounds like the flag should indeed be caring about the is_enabled() operation as well, so let's go with Chen-Yu's patch.

Thanks,
Nícolas

Quoted 7 lines
Quoted 3 lines

I have a patch ready, but I got distracted by other stuff today.

Let's just wait for your patch then, seems like being the most sensible option.

Cheers!