Skip to contentSkip to conversation

Add SMI reset and clamp for MediaTek MT8188 SoC

PATCH Superseded Friday Yang 4 participants 10 messages Sep 17, 2025 – Oct 31, 2025

Subsystems (4)

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v11 cover Add SMI reset and clamp for MediaTek MT8188 SoC

Based on tag: next-20250916, linux-next/master

On the MediaTek MT8188 SoC platform, we encountered power-off failures and SMI bus hang issues during camera stress tests. The issue arises because bus glitches are sometimes produced when MTCMOS powers on or off. While this is fairly normal, the software must handle these glitches to avoid mistaking them for transaction signals. What's more, this issue emerged only after the initial upstreaming of SMI driver.

The software solutions can be summarized as follows:

1. Use CLAMP to disable the SMI sub-common port after turning off the LARB CG and before turning off the LARB MTCMOS.
2. Use CLAMP to disable/enable the SMI sub-common port.
3. Implement an AXI reset for SMI LARBs.

---
Changes in v11:
- Add error checking in the 'mtk_smi_genpd_callback' function and use 'switch-case' statement instead of 'if-else'.
- Use 'larb->larb_gen->clamp_port[larb->larbid]' to determine whether smi larb requires clamp and reset operations or not in 'mtk_smi_larb_probe'. Remove the '_optional' suffix from the function name.
- Replace 'devm_reset_control_get_optional_exclusive' with 'devm_reset_control_get_exclusive' in 'mtk_smi_larb_parse_reset', return the error code if it fails to get the reset controller.
- Remove genpd callback when smi larb probe fails.

Changes in v10:
- Rename 'smi_comm_inport_id' to 'smi_comm_in_port_id'.
- Return 0 when it fails to get 'larb_id' in 'mtk_smi_larb_parse_clamp_optional'.
- Link to v10:
https://lore.kernel.org/lkml/[email protected]/

Changes in v9:
- Add 'dev_pm_genpd_remove_notifier' in 'mtk_smi_larb_remove'.
- Remove unused macros.
- Rename 'sub_comm_syscon' to 'smi_comm_syscon'.
- Rename 'sub_comm_inport_id' to 'smi_comm_inport_id'.
- Add more detailed descriptions in change log.
- Fix incorrect tags.
- Link to v9:
https://lore.kernel.org/lkml/[email protected]/

Changes in v8:
- Fix incorrect tags.
- Link to v8:
https://lore.kernel.org/lkml/[email protected]/

Changes in v7:
- We replaced 'pm_runtime_enable' with 'devm_pm_runtime_enable' in the v6 patch. This changed the order of cleanup, and reviewers expressed concerns that it could introduce unexpected issues. So v7 discard this change and continue using 'pm_runtime_enable'. We need to conduct further investigation to determine if there are any issues related to the cleanup order. This might be resolved in the future, but for now, we just maintain the current status.
- Link to v7:
https://lore.kernel.org/lkml/[email protected]/

Changes in v6:
- Fix coding style.
- Add another patch to replace 'pm_runtime_enable' with 'devm_pm_runtime_enable'.
- Link to v6:
https://lore.kernel.org/lkml/[email protected]/

Changes in v5:
- Use 'devm_pm_runtime_enable' instead of 'pm_runtime_enable'.
- Remove 'pm_runtime_disable' in 'mtk_smi_common_remove' and 'mtk_smi_larb_remove'.
- Link to v5:
https://lore.kernel.org/lkml/[email protected]/

Changes in v4:
- Use 'devm_reset_control_get_optional_exclusive' instead of 'devm_reset_control_get'.
- Link to v4:
https://lore.kernel.org/lkml/[email protected]/

Changes in v3:
- Remove redundant descriptions for 'resets' and 'reset-names'.
- Modify the requirements for 'resets' and 'reset-names'.
- Rename 'mtk_smi_larb_parse_clamp' to 'mtk_smi_larb_parse_clamp_optional'.
- Rename 'mtk_smi_larb_parse_reset' to 'mtk_smi_larb_parse_reset_optional'.
- Merge 'mtk_smi_larb_clamp_protect_enable' and 'mtk_smi_larb_clamp_protect_disble' into one function.
- Modify the definition for mtk_smi_larb_clamp_port_mt8188,
use 'larbid' as the index of the array.
- Use 'syscon_regmap_lookup_by_phandle' instead of 'device_node_to_regmap'.
- Do Not parse 'resets', just check the return value of 'devm_reset_control_get'.
- Add 'has_gals' flag for 'mtk_smi_sub_common_mt8188'.
- Link to v3:
https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
- According to previous discussions in v1, divided these four patches into two topic separately.
- Modify the description for 'resets' in binding.
- Add const value 'larb' for 'reset-names' in binding.
- Modify requirement for 'resets' and 'reset-names' in binding.
- Delete 'mediatek,smi-sub-comm' in binding.
- Delete 'mediatek,smi-sub-comm-in-portid' in binding.
- Modify the example in binding.
- Add 'mtk_smi_larb_clamp_port_mt8188' definition in SMI driver.
- Change the way to parse the 'resets' in driver.
- Change label from 'err_pm_disable' to 'err_link_remove'.
- Link to v2:
https://lore.kernel.org/lkml/[email protected]/

Friday Yang (2):
dt-bindings: memory: mediatek: Add SMI reset and clamp for MT8188
memory: mtk-smi: mt8188: Add SMI reset and clamp

 .../mediatek,smi-common.yaml                  |   2 +
 .../memory-controllers/mediatek,smi-larb.yaml |  19 +++
 drivers/memory/mtk-smi.c                      | 151 ++++++++++++++++++
 3 files changed, 172 insertions(+)

--
2.46.0

#1 lore raw

PATCH v11 1/2 dt-bindings: memory: mediatek: Add SMI reset and clamp for MT8188

Add 'resets' and 'reset-names' properties for SMI LARBs to support SMI reset operations.
On the MediaTek platform, some SMI LARBs are directly connected to the SMI Common, while others are connected to the SMI Sub-Common, which in turn is connected to the SMI Common. The hardware block diagram can be described as follows.

SMI-Common(Smart Multimedia Interface Common)
|
+----------------+------------------+
| | |
| | |
| | |
| | |
| | |
larb0 SMI-Sub-Common0 SMI-Sub-Common1
| | | | |
larb1 larb2 larb3 larb7 larb9

---
 .../mediatek,smi-common.yaml                  |  2 ++
 .../memory-controllers/mediatek,smi-larb.yaml | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-common.yaml +2 -0
index 0762e0ff66ef..3d98c08b2149 100644
@@ -40,6 +40,7 @@ properties:
           - mediatek,mt8186-smi-common
           - mediatek,mt8188-smi-common-vdo
           - mediatek,mt8188-smi-common-vpp
+          - mediatek,mt8188-smi-sub-common
           - mediatek,mt8192-smi-common
           - mediatek,mt8195-smi-common-vdo
           - mediatek,mt8195-smi-common-vpp
@@ -108,6 +109,7 @@ allOf:
         compatible:
           contains:
             enum:
+              - mediatek,mt8188-smi-sub-common
               - mediatek,mt8195-smi-sub-common
     then:
       required:
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml +19 -0
index 2e7fac4b5094..fc5feb2eac1f 100644
@@ -70,6 +70,12 @@ properties:
     description: the hardware id of this larb. It's only required when this
       hardware id is not consecutive from its M4U point of view.
 
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: larb
+
 required:
   - compatible
   - reg
@@ -126,6 +132,19 @@ allOf:
       required:
         - mediatek,larb-id
 
+  - if:  # only for image, camera and ipe subsys
+      properties:
+        compatible:
+          const: mediatek,mt8188-smi-larb
+        mediatek,larb-id:
+          enum:
+            [ 9, 10, 11, 12, 13, 16, 17, 18, 19, 20 ]
+
+    then:
+      required:
+        - resets
+        - reset-names
+
 additionalProperties: false
 
 examples:

--
2.46.0

#5 lore raw

PATCH v11 2/2 memory: mtk-smi: mt8188: Add SMI reset and clamp

In reply to Friday Yang

To prevent handling glitch signals during MTCMOS on/off transitions, SMI requires clamp and reset operations. Parse the reset settings for SMI LARBs and the clamp settings for the SMI Sub-Common. Register genpd callback for the SMI LARBs located in image, camera and IPE subsystems, and apply reset and clamp operations within the callback.

---
 drivers/memory/mtk-smi.c | 151 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)
drivers/memory/mtk-smi.c +151 -0
index 733e22f695ab..117ff528db01 100644
@@ -10,11 +10,15 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
 #include <linux/soc/mediatek/mtk_sip_svc.h>
 #include <soc/mediatek/smi.h>
 #include <dt-bindings/memory/mt2701-larb-port.h>
@@ -34,6 +38,8 @@
 #define SMI_FIFO_TH1			0x238
 #define SMI_FIFO_TH2			0x23c
 #define SMI_DCM				0x300
+#define SMI_COMMON_CLAMP_EN_SET		0x3c4
+#define SMI_COMMON_CLAMP_EN_CLR		0x3c8
 #define SMI_DUMMY			0x444
 
 /* SMI LARB */
@@ -134,6 +140,7 @@ struct mtk_smi_larb_gen {
 	unsigned int			larb_direct_to_common_mask;
 	unsigned int			flags_general;
 	const u8			(*ostd)[SMI_LARB_PORT_NR_MAX];
+	const u8			*clamp_port;
 };
 
 struct mtk_smi {
@@ -150,6 +157,7 @@ struct mtk_smi {
 };
 
 struct mtk_smi_larb { /* larb: local arbiter */
+	struct device			*dev;
 	struct mtk_smi			smi;
 	void __iomem			*base;
 	struct device			*smi_common_dev; /* common or sub-common dev */
@@ -157,6 +165,10 @@ struct mtk_smi_larb { /* larb: local arbiter */
 	int				larbid;
 	u32				*mmu;
 	unsigned char			*bank;
+	struct regmap			*smi_comm_syscon; /* smi-comm or sub-comm */
+	u8				smi_comm_in_port_id; /* smi-comm or sub-comm */
+	struct notifier_block		nb;
+	struct reset_control		*rst_con;
 };
 
 static int
@@ -478,6 +490,19 @@ static const u8 mtk_smi_larb_mt8195_ostd[][SMI_LARB_PORT_NR_MAX] = {
 	[28] = {0x1a, 0x0e, 0x0a, 0x0a, 0x0c, 0x0e, 0x10,},
 };
 
+static const u8 mtk_smi_larb_clamp_port_mt8188[MTK_LARB_NR_MAX] = {
+	[9]	= BIT(1), /* larb10 */
+	[10]	= BIT(2), /* larb11a */
+	[11]	= BIT(2), /* larb11b */
+	[12]	= BIT(3), /* larb11c */
+	[13]	= BIT(0), /* larb12 */
+	[16]	= BIT(1), /* larb15 */
+	[17]	= BIT(2), /* larb16a */
+	[18]	= BIT(2), /* larb16b */
+	[19]	= BIT(3), /* larb17a */
+	[20]	= BIT(3), /* larb17b */
+};
+
 static const struct mtk_smi_larb_gen mtk_smi_larb_mt2701 = {
 	.port_in_larb = {
 		LARB0_PORT_OFFSET, LARB1_PORT_OFFSET,
@@ -531,6 +556,7 @@ static const struct mtk_smi_larb_gen mtk_smi_larb_mt8188 = {
 	.flags_general	            = MTK_SMI_FLAG_THRT_UPDATE | MTK_SMI_FLAG_SW_FLAG |
 				      MTK_SMI_FLAG_SLEEP_CTL | MTK_SMI_FLAG_CFG_PORT_SEC_CTL,
 	.ostd		            = mtk_smi_larb_mt8188_ostd,
+	.clamp_port                 = mtk_smi_larb_clamp_port_mt8188,
 };
 
 static const struct mtk_smi_larb_gen mtk_smi_larb_mt8192 = {
@@ -582,6 +608,53 @@ static void mtk_smi_larb_sleep_ctrl_disable(struct mtk_smi_larb *larb)
 	writel_relaxed(0, larb->base + SMI_LARB_SLP_CON);
 }
 
+static int mtk_smi_larb_clamp_protect_enable(struct device *dev, bool enable)
+{
+	struct mtk_smi_larb *larb = dev_get_drvdata(dev);
+	u32 reg;
+	int ret;
+
+	reg = enable ? SMI_COMMON_CLAMP_EN_SET : SMI_COMMON_CLAMP_EN_CLR;
+	ret = regmap_write(larb->smi_comm_syscon, reg, larb->smi_comm_in_port_id);
+	if (ret)
+		dev_err(dev, "Unable to %s clamp for input port %d: %d\n",
+			enable ? "enable" : "disable",
+			larb->smi_comm_in_port_id, ret);
+
+	return ret;
+}
+
+static int mtk_smi_genpd_callback(struct notifier_block *nb,
+				  unsigned long event, void *data)
+{
+	struct mtk_smi_larb *larb = container_of(nb, struct mtk_smi_larb, nb);
+	struct device *dev = larb->dev;
+	int ret = 0;
+
+	switch (event) {
+	case GENPD_NOTIFY_PRE_ON:
+	case GENPD_NOTIFY_PRE_OFF:
+		/* Clamp this larb to avoid the redundant commands */
+		ret = mtk_smi_larb_clamp_protect_enable(dev, true);
+		break;
+	case GENPD_NOTIFY_ON:
+		ret = reset_control_reset(larb->rst_con);
+		if (ret) {
+			dev_err(dev, "Failed to reset smi larb %d\n", ret);
+			break;
+		}
+
+		ret = mtk_smi_larb_clamp_protect_enable(dev, false);
+		break;
+	default:
+		break;
+	}
+	if (ret)
+		return NOTIFY_BAD;
+
+	return NOTIFY_OK;
+}
+
 static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev)
 {
 	struct platform_device *smi_com_pdev;
@@ -638,6 +711,46 @@ static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi,
 	return ret;
 }
 
+static int mtk_smi_larb_parse_syscon(struct mtk_smi_larb *larb, int larbid)
+{
+	struct device *dev = larb->dev;
+	const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
+	int ret;
+
+	larb->smi_comm_in_port_id = larb_gen->clamp_port[larbid];
+	larb->smi_comm_syscon = syscon_regmap_lookup_by_phandle(dev->of_node,
+								"mediatek,smi");
+	if (IS_ERR(larb->smi_comm_syscon)) {
+		ret = PTR_ERR(larb->smi_comm_syscon);
+		larb->smi_comm_syscon = NULL;
+		return dev_err_probe(dev, ret,
+				     "Failed to get smi syscon for larb %d\n", larbid);
+	}
+
+	return 0;
+}
+
+static int mtk_smi_larb_parse_reset(struct mtk_smi_larb *larb)
+{
+	struct device *dev = larb->dev;
+	int ret;
+
+	larb->rst_con = devm_reset_control_get_exclusive(dev, "larb");
+	if (IS_ERR(larb->rst_con))
+		return dev_err_probe(dev, PTR_ERR(larb->rst_con),
+				     "Failed to get reset controller\n");
+
+	larb->nb.notifier_call = mtk_smi_genpd_callback;
+	ret = dev_pm_genpd_add_notifier(dev, &larb->nb);
+	if (ret) {
+		larb->nb.notifier_call = NULL;
+		return dev_err_probe(dev, ret,
+				     "Failed to add genpd callback\n");
+	}
+
+	return 0;
+}
+
 static int mtk_smi_larb_probe(struct platform_device *pdev)
 {
 	struct mtk_smi_larb *larb;
@@ -648,6 +761,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
 	if (!larb)
 		return -ENOMEM;
 
+	larb->dev = dev;
 	larb->larb_gen = of_device_get_match_data(dev);
 	larb->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(larb->base))
@@ -664,6 +778,30 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
+	/* The larbid are sequential for IOMMU if this property is not present */
+	if (!of_property_present(dev->of_node, "mediatek,larb-id"))
+		goto pm_runtime_en;
+	ret = of_property_read_s32(dev->of_node, "mediatek,larb-id", &larb->larbid);
+	if (ret || larb->larbid >= MTK_LARB_NR_MAX) {
+		ret = -EINVAL;
+		goto err_link_remove;
+	}
+
+	/*
+	 * Only SMI LARBs in camera, image and IPE subsys need to
+	 * apply clamp and reset operations, others can be skipped.
+	 */
+	if (larb->larb_gen->clamp_port && larb->larb_gen->clamp_port[larb->larbid]) {
+		ret = mtk_smi_larb_parse_syscon(larb, larb->larbid);
+		if (ret)
+			goto err_link_remove;
+
+		ret = mtk_smi_larb_parse_reset(larb);
+		if (ret)
+			goto err_link_remove;
+	}
+
+pm_runtime_en:
 	pm_runtime_enable(dev);
 	platform_set_drvdata(pdev, larb);
 	ret = component_add(dev, &mtk_smi_larb_component_ops);
@@ -672,7 +810,11 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
 	return 0;
 
 err_pm_disable:
+	if (larb->nb.notifier_call)
+		dev_pm_genpd_remove_notifier(&pdev->dev);
+
 	pm_runtime_disable(dev);
+err_link_remove:
 	device_link_remove(dev, larb->smi_common_dev);
 	return ret;
 }
@@ -681,6 +823,9 @@ static void mtk_smi_larb_remove(struct platform_device *pdev)
 {
 	struct mtk_smi_larb *larb = platform_get_drvdata(pdev);
 
+	if (larb->nb.notifier_call)
+		dev_pm_genpd_remove_notifier(&pdev->dev);
+
 	device_link_remove(&pdev->dev, larb->smi_common_dev);
 	pm_runtime_disable(&pdev->dev);
 	component_del(&pdev->dev, &mtk_smi_larb_component_ops);
@@ -803,6 +948,11 @@ static const struct mtk_smi_common_plat mtk_smi_common_mt8188_vpp = {
 	.init     = mtk_smi_common_mt8195_init,
 };
 
+static const struct mtk_smi_common_plat mtk_smi_sub_common_mt8188 = {
+	.type     = MTK_SMI_GEN2_SUB_COMM,
+	.has_gals = true,
+};
+
 static const struct mtk_smi_common_plat mtk_smi_common_mt8192 = {
 	.type     = MTK_SMI_GEN2,
 	.has_gals = true,
@@ -847,6 +997,7 @@ static const struct of_device_id mtk_smi_common_of_ids[] = {
 	{.compatible = "mediatek,mt8186-smi-common", .data = &mtk_smi_common_mt8186},
 	{.compatible = "mediatek,mt8188-smi-common-vdo", .data = &mtk_smi_common_mt8188_vdo},
 	{.compatible = "mediatek,mt8188-smi-common-vpp", .data = &mtk_smi_common_mt8188_vpp},
+	{.compatible = "mediatek,mt8188-smi-sub-common", .data = &mtk_smi_sub_common_mt8188},
 	{.compatible = "mediatek,mt8192-smi-common", .data = &mtk_smi_common_mt8192},
 	{.compatible = "mediatek,mt8195-smi-common-vdo", .data = &mtk_smi_common_mt8195_vdo},
 	{.compatible = "mediatek,mt8195-smi-common-vpp", .data = &mtk_smi_common_mt8195_vpp},

--
2.46.0

maintainer Reviewed-by on v11 2/2
#6 lore raw

Re: [PATCH v11 2/2] memory: mtk-smi: mt8188: Add SMI reset and clamp

Il 17/09/25 14:07, Friday Yang ha scritto:

Quoted 7 lines

To prevent handling glitch signals during MTCMOS on/off transitions, SMI requires clamp and reset operations. Parse the reset settings for SMI LARBs and the clamp settings for the SMI Sub-Common. Register genpd callback for the SMI LARBs located in image, camera and IPE subsystems, and apply reset and clamp operations within the callback.

maintainer Reviewed-by on v11 2/2
#7 lore raw

Re: [PATCH v11 2/2] memory: mtk-smi: mt8188: Add SMI reset and clamp

In reply to Friday Yang
Quoted 11 lines · Friday Yang

To prevent handling glitch signals during MTCMOS on/off transitions, SMI requires clamp and reset operations. Parse the reset settings for SMI LARBs and the clamp settings for the SMI Sub-Common. Register genpd callback for the SMI LARBs located in image, camera and IPE subsystems, and apply reset and clamp operations within the callback.

---
 drivers/memory/mtk-smi.c | 151
+++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)
#8 lore raw

Re: [PATCH v11 2/2] memory: mtk-smi: mt8188: Add SMI reset and clamp

In reply to Friday Yang
Quoted 6 lines · Friday Yang

static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev) {

drivers/memory/mtk-smi.c +0 -0
 	struct platform_device *smi_com_pdev;
@@ -638,6 +711,46 @@ static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi,
 	return ret;
 }

drivers/memory/mtk-smi.c static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, · line 722

Quoted 10 lines
drivers/memory/mtk-smi.c +9 -0
 
+static int mtk_smi_larb_parse_syscon(struct mtk_smi_larb *larb, int larbid)
+{
+	struct device *dev = larb->dev;
+	const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
+	int ret;
+
+	larb->smi_comm_in_port_id = larb_gen->clamp_port[larbid];
+	larb->smi_comm_syscon = syscon_regmap_lookup_by_phandle(dev->of_node,
+								"mediatek,smi");

The code already parses this phandle (in other place). Why do you need second time?

Quoted 9 lines
drivers/memory/mtk-smi.c +9 -0
+	if (IS_ERR(larb->smi_comm_syscon)) {
+		ret = PTR_ERR(larb->smi_comm_syscon);
+		larb->smi_comm_syscon = NULL;
+		return dev_err_probe(dev, ret,
+				     "Failed to get smi syscon for larb %d\n", larbid);
+	}
+
+	return 0;
+}

drivers/memory/mtk-smi.c static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, · line 741

Quoted 10 lines
drivers/memory/mtk-smi.c +10 -0
+
+static int mtk_smi_larb_parse_reset(struct mtk_smi_larb *larb)
+{
+	struct device *dev = larb->dev;
+	int ret;
+
+	larb->rst_con = devm_reset_control_get_exclusive(dev, "larb");
+	if (IS_ERR(larb->rst_con))
+		return dev_err_probe(dev, PTR_ERR(larb->rst_con),
+				     "Failed to get reset controller\n");

This looks like ABI break. Aren't all devices affected?

drivers/memory/mtk-smi.c static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, · line 753

Quoted 12 lines
drivers/memory/mtk-smi.c +12 -0
+
+	larb->nb.notifier_call = mtk_smi_genpd_callback;
+	ret = dev_pm_genpd_add_notifier(dev, &larb->nb);
+	if (ret) {
+		larb->nb.notifier_call = NULL;
+		return dev_err_probe(dev, ret,
+				     "Failed to add genpd callback\n");
+	}
+
+	return 0;
+}
+

Best regards,
Krzysztof

#2 lore raw

Re: [PATCH v11 1/2] dt-bindings: memory: mediatek: Add SMI reset and clamp for MT8188

In reply to Friday Yang
Quoted 2 lines · Friday Yang

Add 'resets' and 'reset-names' properties for SMI LARBs to support SMI reset operations.

Not informative...

Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml properties: · line 77

Quoted 13 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml +5 -0
index 2e7fac4b5094..fc5feb2eac1f 100644
@@ -70,6 +70,12 @@ properties:
     description: the hardware id of this larb. It's only required when this
       hardware id is not consecutive from its M4U point of view.
 
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: larb

Is the reset valid for all existing devices as well? Commit msg does not explain that... it is pretty useless - you say what you did. We see that from the diff. Explain something not obvious.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v11 2/2] memory: mtk-smi: mt8188: Add SMI reset and clamp

In reply to Krzysztof Kozlowski
Quoted 23 lines · Krzysztof Kozlowski

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 18 lines · Friday Yang

static int mtk_smi_device_link_common(struct device *dev, struct
device **com_dev)

 {
      struct platform_device *smi_com_pdev;
drivers/memory/mtk-smi.c +8 -0
@@ -638,6 +711,46 @@ static int mtk_smi_dts_clk_init(struct device
 *dev, struct mtk_smi *smi,
      return ret;
 }
 
+static int mtk_smi_larb_parse_syscon(struct mtk_smi_larb *larb,
 int larbid)
+{
+     struct device *dev = larb->dev;
+     const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
+     int ret;
+
+     larb->smi_comm_in_port_id = larb_gen->clamp_port[larbid];
+     larb->smi_comm_syscon = syscon_regmap_lookup_by_phandle(dev-
Quoted 8 lines
Quoted 3 lines
(quoted diff) +1 -0
 >of_node,
+                                                             "medi

atek,smi");

The code already parses this phandle (in other place). Why do you need
second time?

Thanks for comments. We did parse the 'mediatek,smi' property in mtk_smi_device_link_common. We need to modify 'mtk_smi_device_link_common' function if this need to be fixed. Below is the modification, is this acceptable for you?

static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev,bool require_clamp)
{
...

	struct mtk_smi_larb *larb;
	struct mtk_smi_larb_gen *larb_gen;
	int larbid, ret;

	smi_com_node = of_parse_phandle(dev->of_node, "mediatek,smi",
0);
	if (!smi_com_node)
		return -EINVAL;
	smi_com_pdev = of_find_device_by_node(smi_com_node);
...
	if (require_clamp) {
		larb = container_of(com_dev, struct mtk_smi_larb,
smi_common_dev);
		larb_gen = larb->larb_gen;
		larbid = larb->larb_id;
		larb->smi_comm_in_port_id = larb_gen-
Quoted 1 line

clamp_port[larbid];

		larb->smi_comm_syscon =
syscon_node_to_regmap(smi_com_node);
		if (IS_ERR(larb->smi_comm_syscon)) {
			dev_err(dev, "Failed to get smi syscon for larb %d\n", larbid);
			ret = PTR_ERR(larb->smi_comm_syscon);
			larb->smi_comm_syscon = NULL;
			goto err_remove_link;
		}
	}
	of_node_put(smi_com_node);
	return 0;

err_remove_link:

	device_link_remove(dev, smi_com_dev);
err_put_device:
	put_device(&smi_com_pdev->dev);
err_put_node:
	of_node_put(smi_com_node);
	return ret;
}

static int mtk_smi_larb_probe(struct platform_device *pdev)

{
	bool require_clamp;

...

	/* The larbid are sequential for IOMMU if this property is not
present */
	ret = of_property_read_s32(dev->of_node, "mediatek,larb-id",
&larb->larbid);
	if (ret == -EINVAL)
		goto add_dev_link;
	else if (ret || larb->larbid >= MTK_LARB_NR_MAX)
		return dev_err_probe(dev, -EINVAL, "Invalid

larbid:%d\n", larb->larbid);

	if (larb->larb_gen->clamp_port && larb->larb_gen-
Quoted 1 line

clamp_port[larb->larbid])

		require_clamp = true;

add_dev_link:

	ret = mtk_smi_device_link_common(dev, &larb->smi_common_dev,
require_clamp);
	if (ret < 0)
		return ret;

	/*
	 * Only SMI LARBs in camera, image and IPE subsys need to
	 * apply clamp and reset operations, others can be skipped.
	 */
	if (require_clamp) {
		ret = mtk_smi_larb_parse_reset(larb);
		if (ret)
			goto err_link_remove;
	}

pm_runtime_en:

	pm_runtime_enable(dev);

...
}

static int mtk_smi_common_probe(struct platform_device *pdev) {
...

	if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) {
		ret = mtk_smi_device_link_common(dev, &common-
Quoted 1 line

smi_common_dev, false);

		if (ret < 0)
			return ret;
	}

...
}

Quoted 17 lines
Quoted 17 lines
drivers/memory/mtk-smi.c +5 -0
+     if (IS_ERR(larb->smi_comm_syscon)) {
+             ret = PTR_ERR(larb->smi_comm_syscon);
+             larb->smi_comm_syscon = NULL;
+             return dev_err_probe(dev, ret,
+                                  "Failed to get smi syscon for

larb %d\n", larbid);

drivers/memory/mtk-smi.c +11 -0
+     }
+
+     return 0;
+}
+
+static int mtk_smi_larb_parse_reset(struct mtk_smi_larb *larb)
+{
+     struct device *dev = larb->dev;
+     int ret;
+
+     larb->rst_con = devm_reset_control_get_exclusive(dev,
Quoted 9 lines
Quoted 5 lines

"larb");

drivers/memory/mtk-smi.c +3 -0
+     if (IS_ERR(larb->rst_con))
+             return dev_err_probe(dev, PTR_ERR(larb->rst_con),
+                                  "Failed to get reset

controller\n");

This looks like ABI break. Aren't all devices affected?

This does not affect other devices, we use this 'clamp_port' to judge whether to apply clamp or not in 'mtk_smi_larb_probe', like below:

	if (larb->larb_gen->clamp_port && larb->larb_gen-
Quoted 1 line

clamp_port[larb->larbid])

		require_clamp = true;
static const struct mtk_smi_larb_gen mtk_smi_larb_mt8188 = {
	...
	.clamp_port                 = mtk_smi_larb_clamp_port_mt8188,
};
Quoted 15 lines

drivers/memory/mtk-smi.c static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, · line 732

Quoted 12 lines
drivers/memory/mtk-smi.c +6 -0
+     larb->nb.notifier_call = mtk_smi_genpd_callback;
+     ret = dev_pm_genpd_add_notifier(dev, &larb->nb);
+     if (ret) {
+             larb->nb.notifier_call = NULL;
+             return dev_err_probe(dev, ret,
+                                  "Failed to add genpd

callback\n");

drivers/memory/mtk-smi.c +5 -0
+     }
+
+     return 0;
+}
+

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v11 1/2] dt-bindings: memory: mediatek: Add SMI reset and clamp for MT8188

In reply to Krzysztof Kozlowski
Quoted 24 lines · Krzysztof Kozlowski

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 2 lines · Friday Yang

Add 'resets' and 'reset-names' properties for SMI LARBs to support SMI reset operations.

Not informative...

Quoted 14 lines
(quoted diff) +0 -0

controllers/mediatek,smi-larb.yaml
b/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml
index 2e7fac4b5094..fc5feb2eac1f 100644
--- a/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml
+++ b/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml

(quoted diff) +0 -0
@@ -70,6 +70,12 @@ properties:
     description: the hardware id of this larb. It's only required

when this
hardware id is not consecutive from its M4U point of view.

Quoted 12 lines

Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml properties: · line 77

Quoted 5 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml +5 -0
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: larb

Is the reset valid for all existing devices as well? Commit msg does not
explain that... it is pretty useless - you say what you did. We see that
from the diff. Explain something not obvious.

Thanks, I could add more descriptions here, like below:

On the MediaTek MT8188 SoC, bus glitches may occur during MTCMOS on/off transitions. To prevent these glitches from causing errors, SMI requires clamp and reset operations. This issue specifically affects the image, camera, and IPE subsystems. This change adds the 'resets' and 'reset-names' properties to the SMI LARBs within these subsystems to support the necessary reset operations.
...

Can I still remain the 'Reviewed-by' and 'Acked-by' tags if I only change the commit mesg in v12? I will not change the bindings.

Quoted 4 lines

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v11 1/2] dt-bindings: memory: mediatek: Add SMI reset and clamp for MT8188

Quoted 38 lines · Friday Yang (杨阳)
Quoted 24 lines · Krzysztof Kozlowski

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 2 lines · Friday Yang

Add 'resets' and 'reset-names' properties for SMI LARBs to support SMI reset operations.

Not informative...

Quoted 14 lines
(quoted diff) +0 -0

controllers/mediatek,smi-larb.yaml
b/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml
index 2e7fac4b5094..fc5feb2eac1f 100644
--- a/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml
+++ b/Documentation/devicetree/bindings/memory-
controllers/mediatek,smi-larb.yaml

(quoted diff) +0 -0
@@ -70,6 +70,12 @@ properties:
     description: the hardware id of this larb. It's only required

when this
hardware id is not consecutive from its M4U point of view.

Quoted 12 lines

Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml properties: · line 77

Quoted 5 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.yaml +5 -0
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: larb

Is the reset valid for all existing devices as well? Commit msg does not
explain that... it is pretty useless - you say what you did. We see that
from the diff. Explain something not obvious.

Quoted 6 lines

Thanks, I could add more descriptions here, like below:

On the MediaTek MT8188 SoC, bus glitches may occur during MTCMOS on/off transitions. To prevent these glitches from causing errors, SMI requires clamp and reset operations. This issue specifically affects the image, camera, and IPE subsystems.

This explains why you need it. But I asked more questions than only "whY".

Read the question:
"Is the reset valid for all existing devices as well?" Where is the answer for that? I still do not know...

Do not reply to only pieces of review.

Quoted 3 lines

This change adds the
'resets' and 'reset-names' properties to the SMI LARBs within these subsystems to support the necessary reset operations.

Read again my message:
" it is pretty useless - you say what you did"
That's the same, drop.

So again you just cared to implement only piece of review.

Best regards,
Krzysztof