Skip to contentSkip to conversation

dt-bindings: mmc: mtk-sd: Add eMMC for AN7581

PATCH In review Christian Marangi 4 participants 6 messages Jan 20, 2025 – Jan 27, 2025

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

PATCH v2 1/2 dt-bindings: mmc: mtk-sd: Add eMMC for AN7581

Document eMMC compatible for AN7581. This eMMC controller doesn't have regulator exposed to the system and have a single clock only for source clock and only default pintctrl.

Rework the schema to permit these new requirements and make supply optional only for airoha,an7581-mmc compatible.

Also provide an example for airoha,an7581-mmc.

---
Changes v2:
- Drop else condition
- Move Required and pinctrl property to dedicated if condition

 .../devicetree/bindings/mmc/mtk-sd.yaml       | 116 +++++++++++++++++-
 1 file changed, 110 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/mmc/mtk-sd.yaml +110 -6
index f86ebd81f5a5..4c1da48aaa1b 100644
@@ -14,6 +14,7 @@ properties:
   compatible:
     oneOf:
       - enum:
+          - airoha,an7581-mmc
           - mediatek,mt2701-mmc
           - mediatek,mt2712-mmc
           - mediatek,mt6779-mmc
@@ -48,11 +49,11 @@ properties:
   clocks:
     description:
       Should contain phandle for the clock feeding the MMC controller.
-    minItems: 2
+    minItems: 1
     maxItems: 7
 
   clock-names:
-    minItems: 2
+    minItems: 1
     maxItems: 7
 
   interrupts:
@@ -72,7 +73,7 @@ properties:
       Should at least contain default and state_uhs. To support SDIO in-band wakeup, dat1 pin
       will be switched between GPIO mode and SDIO DAT1 mode, state_eint is mandatory in this
       scenario.
-    minItems: 2
+    minItems: 1
     items:
       - const: default
       - const: state_uhs
@@ -170,9 +171,6 @@ required:
   - clock-names
   - pinctrl-names
   - pinctrl-0
-  - pinctrl-1
-  - vmmc-supply
-  - vqmmc-supply
 
 allOf:
   - $ref: mmc-controller.yaml#
@@ -275,12 +273,14 @@ allOf:
     then:
       properties:
         clocks:
+          minItems: 2
           items:
             - description: source clock
             - description: HCLK which used for host
             - description: Advanced eXtensible Interface
             - description: Advanced High-performance Bus clock
         clock-names:
+          minItems: 2
           items:
             - const: source
             - const: hclk
@@ -317,6 +317,7 @@ allOf:
     then:
       properties:
         clocks:
+          minItems: 2
           items:
             - description: source clock
             - description: HCLK which used for host
@@ -326,6 +327,7 @@ allOf:
             - description: AXI bus clock gate
             - description: AHB bus clock gate
         clock-names:
+          minItems: 2
           items:
             - const: source
             - const: hclk
@@ -335,6 +337,89 @@ allOf:
             - const: axi_cg
             - const: ahb_cg
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: airoha,an7581-mmc
+    then:
+      properties:
+        clocks:
+          items:
+            - description: source clock
+
+        clock-names:
+          items:
+            - const: source
+
+  - if:
+      properties:
+        compatible:
+          enum:
+            - mediatek,mt2701-mmc
+            - mediatek,mt2712-mmc
+            - mediatek,mt6779-mmc
+            - mediatek,mt6795-mmc
+            - mediatek,mt7620-mmc
+            - mediatek,mt7622-mmc
+            - mediatek,mt7623-mmc
+            - mediatek,mt7986-mmc
+            - mediatek,mt7988-mmc
+            - mediatek,mt8135-mmc
+            - mediatek,mt8173-mmc
+            - mediatek,mt8183-mmc
+            - mediatek,mt8186-mmc
+            - mediatek,mt8188-mmc
+            - mediatek,mt8192-mmc
+            - mediatek,mt8195-mmc
+            - mediatek,mt8196-mmc
+            - mediatek,mt8365-mmc
+            - mediatek,mt8516-mmc
+    then:
+      properties:
+        pinctrl-names:
+          minItems: 2
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: airoha,an7581-mmc
+    then:
+      properties:
+        pinctrl-names:
+          items:
+            - const: default
+
+  - if:
+      properties:
+        compatible:
+          enum:
+            - mediatek,mt2701-mmc
+            - mediatek,mt2712-mmc
+            - mediatek,mt6779-mmc
+            - mediatek,mt6795-mmc
+            - mediatek,mt7620-mmc
+            - mediatek,mt7622-mmc
+            - mediatek,mt7623-mmc
+            - mediatek,mt7986-mmc
+            - mediatek,mt7988-mmc
+            - mediatek,mt8135-mmc
+            - mediatek,mt8173-mmc
+            - mediatek,mt8183-mmc
+            - mediatek,mt8186-mmc
+            - mediatek,mt8188-mmc
+            - mediatek,mt8192-mmc
+            - mediatek,mt8195-mmc
+            - mediatek,mt8196-mmc
+            - mediatek,mt8365-mmc
+            - mediatek,mt8516-mmc
+    then:
+      required:
+        - pinctrl-1
+        - vmmc-supply
+        - vqmmc-supply
+
 unevaluatedProperties: false
 
 examples:
@@ -389,5 +474,24 @@ examples:
         vqmmc-supply = <&mt6397_vgp3_reg>;
         mmc-pwrseq = <&wifi_pwrseq>;
     };
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/en7523-clk.h>
+    mmc@1fa0e000 {
+        compatible = "airoha,an7581-mmc";
+        reg = <0x1fa0e000 0x1000>,
+              <0x1fa0c000 0x60>;
+        clocks = <&scuclk EN7581_CLK_EMMC>;
+        clock-names = "source";
+        interrupts = <GIC_SPI 170 IRQ_TYPE_LEVEL_HIGH>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&mmc_pins>;
+        bus-width = <4>;
+        max-frequency = <52000000>;
+        disable-wp;
+        cap-mmc-highspeed;
+        non-removable;
+    };
 
 ...
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 2/2 mmc: mtk-sd: add support for AN7581 MMC Host

Add support for AN7581 MMC Host. The MMC Host controller is based on mt7622 with the difference of not having regulator supply and state_uhs pins and hclk clock.

Some minor fixes are applied to check if the state_uhs pins are defined and make hclk optional for the new airoha compatible.

---
Changes v2:
- Drop redundant if condition where regulator is not supported
- Correctly set pin in msdc_ops_switch_volt

 drivers/mmc/host/mtk-sd.c | 59 +++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 14 deletions(-)
drivers/mmc/host/mtk-sd.c +45 -14
index efb0d2d5716b..f76f20502409 100644
@@ -666,6 +666,20 @@ static const struct mtk_mmc_compatible mt8196_compat = {
 	.support_new_rx = true,
 };
 
+static const struct mtk_mmc_compatible an7581_compat = {
+	.clk_div_bits = 12,
+	.recheck_sdio_irq = true,
+	.hs400_tune = false,
+	.pad_tune_reg = MSDC_PAD_TUNE0,
+	.async_fifo = true,
+	.data_tune = true,
+	.busy_check = true,
+	.stop_clk_fix = true,
+	.stop_dly_sel = 3,
+	.enhance_rx = true,
+	.support_64g = false,
+};
+
 static const struct of_device_id msdc_of_ids[] = {
 	{ .compatible = "mediatek,mt2701-mmc", .data = &mt2701_compat},
 	{ .compatible = "mediatek,mt2712-mmc", .data = &mt2712_compat},
@@ -680,7 +694,7 @@ static const struct of_device_id msdc_of_ids[] = {
 	{ .compatible = "mediatek,mt8183-mmc", .data = &mt8183_compat},
 	{ .compatible = "mediatek,mt8196-mmc", .data = &mt8196_compat},
 	{ .compatible = "mediatek,mt8516-mmc", .data = &mt8516_compat},
-
+	{ .compatible = "airoha,an7581-mmc", .data = &an7581_compat},
 	{}
 };
 MODULE_DEVICE_TABLE(of, msdc_of_ids);
@@ -1614,12 +1628,15 @@ static int msdc_ops_switch_volt(struct mmc_host *mmc, struct mmc_ios *ios)
 			return ret;
 		}
 
-		/* Apply different pinctrl settings for different signal voltage */
-		if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
-			pinctrl_select_state(host->pinctrl, host->pins_uhs);
-		else
-			pinctrl_select_state(host->pinctrl, host->pins_default);
 	}
+
+	/* Apply different pinctrl settings for different signal voltage */
+	if (!IS_ERR(mmc->supply.vqmmc) &&
+	    ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
+		pinctrl_select_state(host->pinctrl, host->pins_uhs);
+	else
+		pinctrl_select_state(host->pinctrl, host->pins_default);
+
 	return 0;
 }
 
@@ -1699,7 +1716,9 @@ static void msdc_enable_sdio_irq(struct mmc_host *mmc, int enb)
 				dev_dbg(host->dev, "SDIO eint irq: %d!\n", host->eint_irq);
 			}
 
-			pinctrl_select_state(host->pinctrl, host->pins_uhs);
+			/* Skip setting uhs pins if not supported */
+			if (host->pins_uhs)
+				pinctrl_select_state(host->pinctrl, host->pins_uhs);
 		} else {
 			dev_pm_clear_wake_irq(host->dev);
 		}
@@ -2816,9 +2835,12 @@ static int msdc_of_clock_parse(struct platform_device *pdev,
 	if (IS_ERR(host->src_clk))
 		return PTR_ERR(host->src_clk);
 
-	host->h_clk = devm_clk_get(&pdev->dev, "hclk");
-	if (IS_ERR(host->h_clk))
-		return PTR_ERR(host->h_clk);
+	/* AN7581 SoC doesn't have hclk */
+	if (!device_is_compatible(&pdev->dev, "airoha,an7581-mmc")) {
+		host->h_clk = devm_clk_get(&pdev->dev, "hclk");
+		if (IS_ERR(host->h_clk))
+			return PTR_ERR(host->h_clk);
+	}
 
 	host->bus_clk = devm_clk_get_optional(&pdev->dev, "bus_clk");
 	if (IS_ERR(host->bus_clk))
@@ -2926,10 +2948,13 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		return PTR_ERR(host->pins_default);
 	}
 
-	host->pins_uhs = pinctrl_lookup_state(host->pinctrl, "state_uhs");
-	if (IS_ERR(host->pins_uhs)) {
-		dev_err(&pdev->dev, "Cannot find pinctrl uhs!\n");
-		return PTR_ERR(host->pins_uhs);
+	/* AN7581 doesn't have state_uhs pins */
+	if (!device_is_compatible(&pdev->dev, "airoha,an7581-mmc")) {
+		host->pins_uhs = pinctrl_lookup_state(host->pinctrl, "state_uhs");
+		if (IS_ERR(host->pins_uhs)) {
+			dev_err(&pdev->dev, "Cannot find pinctrl uhs!\n");
+			return PTR_ERR(host->pins_uhs);
+		}
 	}
 
 	/* Support for SDIO eint irq ? */
@@ -3010,6 +3035,12 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Cannot ungate clocks!\n");
 		goto release_clk;
 	}
+
+	/* AN7581 without regulator require tune to OCR values */
+	if (device_is_compatible(&pdev->dev, "airoha,an7581-mmc") &&
+	    !mmc->ocr_avail)
+		mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
+
 	msdc_init_hw(host);
 
 	if (mmc->caps2 & MMC_CAP2_CQE) {
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH v2 2/2] mmc: mtk-sd: add support for AN7581 MMC Host

Quoted 8 lines · Christian Marangi
drivers/mmc/host/mtk-sd.c +3 -1
-			pinctrl_select_state(host->pinctrl, host->pins_uhs);
+			/* Skip setting uhs pins if not supported */
+			if (host->pins_uhs)
+				pinctrl_select_state(host->pinctrl, host->pins_uhs);
 		} else {
 			dev_pm_clear_wake_irq(host->dev);
 		}

drivers/mmc/host/mtk-sd.c static int msdc_of_clock_parse(struct platform_device *pdev, · line 2839

Quoted 8 lines
drivers/mmc/host/mtk-sd.c +2 -3
@@ -2816,9 +2835,12 @@ static int msdc_of_clock_parse(struct platform_device *pdev,
 	if (IS_ERR(host->src_clk))
 		return PTR_ERR(host->src_clk);
 
-	host->h_clk = devm_clk_get(&pdev->dev, "hclk");
-	if (IS_ERR(host->h_clk))
-		return PTR_ERR(host->h_clk);
+	/* AN7581 SoC doesn't have hclk */
+	if (!device_is_compatible(&pdev->dev, "airoha,an7581-mmc")) {

Please avoid coding compatible in multiple places. Not only because above check is slow comparing to check on integer, but it just scales poorly and leads to less readable further code. Use driver data with model name or flags/quirks bitmask.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 2/2] mmc: mtk-sd: add support for AN7581 MMC Host

Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · Christian Marangi
drivers/mmc/host/mtk-sd.c +3 -1
-			pinctrl_select_state(host->pinctrl, host->pins_uhs);
+			/* Skip setting uhs pins if not supported */
+			if (host->pins_uhs)
+				pinctrl_select_state(host->pinctrl, host->pins_uhs);
 		} else {
 			dev_pm_clear_wake_irq(host->dev);
 		}
@@ -2816,9 +2835,12 @@ static int msdc_of_clock_parse(struct platform_device *pdev,
 	if (IS_ERR(host->src_clk))
 		return PTR_ERR(host->src_clk);
 
Quoted 11 lines

drivers/mmc/host/mtk-sd.c static int msdc_of_clock_parse(struct platform_device *pdev, · line 2839

Quoted 5 lines
drivers/mmc/host/mtk-sd.c +2 -3
-	host->h_clk = devm_clk_get(&pdev->dev, "hclk");
-	if (IS_ERR(host->h_clk))
-		return PTR_ERR(host->h_clk);
+	/* AN7581 SoC doesn't have hclk */
+	if (!device_is_compatible(&pdev->dev, "airoha,an7581-mmc")) {

Please avoid coding compatible in multiple places. Not only because above check is slow comparing to check on integer, but it just scales poorly and leads to less readable further code. Use driver data with model name or flags/quirks bitmask.

I implemented this in a more compatible way so we don't need an additional compatible anymore. Soo this series is not needed anymore.

Should I flag these as not applicable anywhere in the patchwork systems?

Signature · 1 line
	Ansuel
#4 lore raw

Re: [PATCH v2 2/2] mmc: mtk-sd: add support for AN7581 MMC Host

Quoted 26 lines · Christian Marangi
Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · Christian Marangi
drivers/mmc/host/mtk-sd.c +3 -1
-                   pinctrl_select_state(host->pinctrl, host->pins_uhs);
+                   /* Skip setting uhs pins if not supported */
+                   if (host->pins_uhs)
+                           pinctrl_select_state(host->pinctrl, host->pins_uhs);
            } else {
                    dev_pm_clear_wake_irq(host->dev);
            }
@@ -2816,9 +2835,12 @@ static int msdc_of_clock_parse(struct platform_device *pdev,
    if (IS_ERR(host->src_clk))
            return PTR_ERR(host->src_clk);
 
Quoted 11 lines

drivers/mmc/host/mtk-sd.c static int msdc_of_clock_parse(struct platform_device *pdev, · line 2839

Quoted 5 lines
drivers/mmc/host/mtk-sd.c +2 -3
-   host->h_clk = devm_clk_get(&pdev->dev, "hclk");
-   if (IS_ERR(host->h_clk))
-           return PTR_ERR(host->h_clk);
+   /* AN7581 SoC doesn't have hclk */
+   if (!device_is_compatible(&pdev->dev, "airoha,an7581-mmc")) {

Please avoid coding compatible in multiple places. Not only because above check is slow comparing to check on integer, but it just scales poorly and leads to less readable further code. Use driver data with model name or flags/quirks bitmask.

Quoted 4 lines

I implemented this in a more compatible way so we don't need an additional compatible anymore. Soo this series is not needed anymore.

Should I flag these as not applicable anywhere in the patchwork systems?

No need to, just send new versions.

Kind regards
Uffe

#5 lore raw
In reply to Christian Marangi
Quoted 9 lines · Christian Marangi

Document eMMC compatible for AN7581. This eMMC controller doesn't have regulator exposed to the system and have a single clock only for source clock and only default pintctrl.

Rework the schema to permit these new requirements and make supply optional only for airoha,an7581-mmc compatible.

Also provide an example for airoha,an7581-mmc.

Quoted 9 lines

---
Changes v2:
- Drop else condition
- Move Required and pinctrl property to dedicated if condition

 .../devicetree/bindings/mmc/mtk-sd.yaml       | 116 +++++++++++++++++-
 1 file changed, 110 insertions(+), 6 deletions(-)

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/mmc/mtk-sd.example.dts:104.31-32 syntax error FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:131: Documentation/devicetree/bindings/mmc/mtk-sd.example.dtb] Error 1 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1506: dt_binding_check] Error 2
make: *** [Makefile:251: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.