Add support for Nuvoton MA35D1 SDHCI
Subsystems (4)
v4 cover Add support for Nuvoton MA35D1 SDHCI
This patch adds the SDHCI driver and DT binding documentation for the Nuvoton MA35D1 platform.
This MA35D1 SDHCI driver has been tested on the MA35D1 SOM board with Linux 6.10
v4:
- Update to nuvoton,ma35d1-sdhci.yaml
- Fixing overlooked issues.
v3:
- Update ma35d1 sdhci driver
- Fixing "Alignment" and "spaces preferred around".
- Fixing style for multi-line comments.
- Fixing double call to sdhci_pltfm_free().
v2:
- Update to nuvoton,ma35d1-sdhci.yaml
- Remove some redundant descriptions.
- Replace 'minitem' with 'maxitem' in the clock settings.
- Make corrections to nuvoton,sys description.
- Add sdhci-common.yaml.
- Remove '|' except where necessary to be preserved.
- Keeping one example is sufficient.
- Add regulators in the example.
- Update ma35d1 sdhci driver
- Refer to 'include what you use' to modify included header files.
- Replace the number 8 with sizeof(u8), and similarly for others.
- Use "dev" instead of "&pdev->dev".
- Use the min() macro to improve the code.
- Use dev_err_probe() instead of dev_err().
- Implement an error reset check mechanism.
- Add devm_add_action_or_reset() to help with sdhci_pltfm_free().
- Use devm_reset_control_get_exclusive() instead of devm_reset_control_get().
Shan-Chun Hung (2):
dt-bindings: mmc: nuvoton,ma35d1-sdhci: Document MA35D1 SDHCI
controller
mmc: sdhci-of-ma35d1: Add Nuvoton MA35D1 SDHCI driver
.../bindings/mmc/nuvoton,ma35d1-sdhci.yaml | 87 +++++ drivers/mmc/host/Kconfig | 12 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-of-ma35d1.c | 297 ++++++++++++++++++ 4 files changed, 397 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml create mode 100644 drivers/mmc/host/sdhci-of-ma35d1.c
--
2.25.1
PATCH v4 1/2 dt-bindings: mmc: nuvoton,ma35d1-sdhci: Document MA35D1 SDHCI controller
Add binding for Nuvoton MA35D1 SDHCI controller.
--- .../bindings/mmc/nuvoton,ma35d1-sdhci.yaml | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml new file +87 -0
@@ -0,0 +1,87 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/nuvoton,ma35d1-sdhci.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 SD/SDIO/MMC Controller + +maintainers: + - Shan-Chun Hung <[email protected]> + +allOf: + - $ref: sdhci-common.yaml# + +properties: + compatible: + enum: + - nuvoton,ma35d1-sdhci + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + pinctrl-names: + minItems: 1 + items: + - const: default + - const: state_uhs + + pinctrl-0: + description: + Should contain default/high speed pin ctrl. + maxItems: 1 + + pinctrl-1: + description: + Should contain uhs mode pin ctrl. + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access GCR (Global Control Register) registers. + +required: + - compatible + - reg + - interrupts + - clocks + - pinctrl-names + - pinctrl-0 + - resets + - nuvoton,sys + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + #include <dt-bindings/reset/nuvoton,ma35d1-reset.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + mmc@40190000 { + compatible = "nuvoton,ma35d1-sdhci"; + reg = <0x0 0x40190000 0x0 0x2000>; + interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk SDH1_GATE>; + pinctrl-names = "default", "state_uhs"; + pinctrl-0 = <&pinctrl_sdhci1>; + pinctrl-1 = <&pinctrl_sdhci1_uhs>; + resets = <&sys MA35D1_RESET_SDH1>; + nuvoton,sys = <&sys>; + vqmmc-supply = <&sdhci1_vqmmc_regulator>; + bus-width = <8>; + max-frequency = <200000000>; + }; + };
--
2.25.1
Re: [PATCH v4 1/2] dt-bindings: mmc: nuvoton,ma35d1-sdhci: Document MA35D1 SDHCI controller
Quoted 10 lines · Shan-Chun Hung
Add binding for Nuvoton MA35D1 SDHCI controller.
Signed-off-by Shan-Chun Hung <[email protected]>---
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml new file +4
-0+ + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access GCR (Global Control Register) registers.
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml line 60
Quoted 10 lines
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + - clocks + - pinctrl-names + - pinctrl-0 + - resets + - nuvoton,sys
Keep the same order as in list of properties.
Normally I would give conditional review tag, but not that case because in the past you kept ignoring review comments.
Best regards,
Krzysztof
Re: [PATCH v4 1/2] dt-bindings: mmc: nuvoton,ma35d1-sdhci: Document MA35D1 SDHCI controller
Dear Krzysztof,
Thank you for your review.
I will make sure to keep the same order as in the list of properties.
I'm sorry if I missed your comments before.
I will do my best to address them in the future.
Thanks for your understanding.
Best Regards
Shan-Chun
Quoted 28 lines · Krzysztof Kozlowski
Quoted 9 lines · Shan-Chun Hung
Add binding for Nuvoton MA35D1 SDHCI controller.
Signed-off-by Shan-Chun Hung <[email protected]>---
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml new file +4
-0+ + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access GCR (Global Control Register) registers.Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml line 60
Quoted 10 lines
Documentation/devicetree/bindings/mmc/nuvoton,ma35d1-sdhci.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + - clocks + - pinctrl-names + - pinctrl-0 + - resets + - nuvoton,sysKeep the same order as in list of properties.
Normally I would give conditional review tag, but not that case because in the past you kept ignoring review comments.
Best regards,
Krzysztof
PATCH v4 2/2 mmc: sdhci-of-ma35d1: Add Nuvoton MA35D1 SDHCI driver
In reply to Shan-Chun HungAdd the SDHCI driver for the MA35D1 platform. It is based upon the SDHCI interface, but requires some extra initialization.
--- drivers/mmc/host/Kconfig | 12 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-of-ma35d1.c | 297 +++++++++++++++++++++++++++++ 3 files changed, 310 insertions(+) create mode 100644 drivers/mmc/host/sdhci-of-ma35d1.c
drivers/mmc/host/Kconfig +12 -0
@@ -252,6 +252,18 @@ config MMC_SDHCI_OF_SPARX5 If unsure, say N. +config MMC_SDHCI_OF_MA35D1 + tristate "SDHCI OF support for the MA35D1 SDHCI controller" + depends on ARCH_MA35 || COMPILE_TEST + depends on MMC_SDHCI_PLTFM + help + This selects the MA35D1 Secure Digital Host Controller Interface. + The controller supports SD/MMC/SDIO devices. + + If you have a controller with this interface, say Y or M here. + + If unsure, say N. + config MMC_SDHCI_CADENCE tristate "SDHCI support for the Cadence SD/SDIO/eMMC controller" depends on MMC_SDHCI_PLTFM
drivers/mmc/host/Makefile +1 -0
@@ -88,6 +88,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o obj-$(CONFIG_MMC_SDHCI_OF_DWCMSHC) += sdhci-of-dwcmshc.o obj-$(CONFIG_MMC_SDHCI_OF_SPARX5) += sdhci-of-sparx5.o +obj-$(CONFIG_MMC_SDHCI_OF_MA35D1) += sdhci-of-ma35d1.o obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o obj-$(CONFIG_MMC_SDHCI_IPROC) += sdhci-iproc.o obj-$(CONFIG_MMC_SDHCI_NPCM) += sdhci-npcm.o
drivers/mmc/host/sdhci-of-ma35d1.c new file +297 -0
297 lines not on this page · raw message
--
2.25.1
Re: [PATCH v4 2/2] mmc: sdhci-of-ma35d1: Add Nuvoton MA35D1 SDHCI driver
Quoted 87 lines · Shan-Chun Hung
Add the SDHCI driver for the MA35D1 platform. It is based upon the SDHCI interface, but requires some extra initialization.
Signed-off-by Shan-Chun Hung <[email protected]>--- drivers/mmc/host/Kconfig | 12 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-of-ma35d1.c | 297 +++++++++++++++++++++++++++++ 3 files changed, 310 insertions(+) create mode 100644 drivers/mmc/host/sdhci-of-ma35d1.cdrivers/mmc/host/Kconfig +12
-0@@ -252,6 +252,18 @@ config MMC_SDHCI_OF_SPARX5 If unsure, say N. +config MMC_SDHCI_OF_MA35D1 + tristate "SDHCI OF support for the MA35D1 SDHCI controller" + depends on ARCH_MA35 || COMPILE_TEST + depends on MMC_SDHCI_PLTFM + help + This selects the MA35D1 Secure Digital Host Controller Interface. + The controller supports SD/MMC/SDIO devices. + + If you have a controller with this interface, say Y or M here. + + If unsure, say N. + config MMC_SDHCI_CADENCE tristate "SDHCI support for the Cadence SD/SDIO/eMMC controller" depends on MMC_SDHCI_PLTFMdrivers/mmc/host/Makefile +1
-0@@ -88,6 +88,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o obj-$(CONFIG_MMC_SDHCI_OF_DWCMSHC) += sdhci-of-dwcmshc.o obj-$(CONFIG_MMC_SDHCI_OF_SPARX5) += sdhci-of-sparx5.o +obj-$(CONFIG_MMC_SDHCI_OF_MA35D1) += sdhci-of-ma35d1.o obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o obj-$(CONFIG_MMC_SDHCI_IPROC) += sdhci-iproc.o obj-$(CONFIG_MMC_SDHCI_NPCM) += sdhci-npcm.odrivers/mmc/host/sdhci-of-ma35d1.c new file +35
-0@@ -0,0 +1,297 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2024 Nuvoton Technology Corp. +* +* Author: Shan-Chun Hung <[email protected]> +*/ + +#include <linux/align.h> +#include <linux/array_size.h> +#include <linux/bits.h> +#include <linux/build_bug.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <linux/math.h> +#include <linux/mfd/syscon.h> +#include <linux/minmax.h> +#include <linux/mmc/card.h> +#include <linux/mmc/host.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/pinctrl/consumer.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/reset.h> +#include <linux/sizes.h> +#include <linux/types.h> + +#include "sdhci-pltfm.h" +#include "sdhci.h" + +#define MA35_SYS_MISCFCR0 0x070
drivers/mmc/host/sdhci-of-ma35d1.c line 45
Quoted 10 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +10
-0+#define MA35_SDHCI_MSHCCTL 0x508 +#define MA35_SDHCI_MBIUCTL 0x510 + +#define MA35_SDHCI_CMD_CONFLICT_CHK BIT(0) +#define MA35_SDHCI_INCR_MSK GENMASK(3, 0) +#define MA35_SDHCI_INCR16 BIT(3) +#define MA35_SDHCI_INCR8 BIT(2) + +struct ma35_priv { +struct regmap *regmap;
Drop, you don't use it.
Quoted 11 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +11
-0+struct reset_control *rst; +struct pinctrl *pinctrl; +struct pinctrl_state *pins_uhs; +struct pinctrl_state *pins_default; +}; + +struct ma35_restore_data { +u32 reg; +u32 width; +}; +
...
Quoted 16 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +16
-0+ +static int ma35_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sdhci_pltfm_host *pltfm_host; +struct sdhci_host *host; +struct ma35_priv *priv; +int err; +u32 extra, ctl; + + host =sdhci_pltfm_init (pdev, &sdhci_ma35_pdata,sizeof (struct ma35_priv )); +if (IS_ERR (host)) +return PTR_ERR (host); + +/* Extra adma table cnt for cross 128M boundary handling. */ + extra =DIV_ROUND_UP_ULL (dma_get_required_mask (dev),SZ_128M );
drivers/mmc/host/sdhci-of-ma35d1.c line 217
Quoted 10 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +10
-0+ extra =min (extra,SDHCI_MAX_SEGS ); + + host->adma_table_cnt += extra; + pltfm_host =sdhci_priv (host); + priv =sdhci_pltfm_priv (pltfm_host); + + pltfm_host->clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (pltfm_host->clk)) { + err =PTR_ERR (pltfm_host->clk); +dev_err_probe (dev, err,"failed to get clk\n" );
Syntax is err = dev_err_probe()
drivers/mmc/host/sdhci-of-ma35d1.c line 228
Quoted 11 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +11
-0+ goto err_sdhci; + } + + err =mmc_of_parse (host->mmc); +if (err) + goto err_sdhci; + + priv->rst =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (priv->rst)) { + err =PTR_ERR (priv->rst); +dev_err_probe (dev, err,"failed to get reset control\n" );
err = dev_err_probe
... so all your previous versions were leaking memory. Double check your error paths.
drivers/mmc/host/sdhci-of-ma35d1.c line 233
Quoted 5 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +5
-0+ goto err_sdhci; + } + +sdhci_get_of_property (pdev); +
Best regards,
Krzysztof
Re: [PATCH v4 2/2] mmc: sdhci-of-ma35d1: Add Nuvoton MA35D1 SDHCI driver
Dear Krzysztof,
Thank you for your review.
Quoted 91 lines · Krzysztof Kozlowski
Quoted 90 lines · Shan-Chun Hung
Add the SDHCI driver for the MA35D1 platform. It is based upon the SDHCI interface, but requires some extra initialization.
Signed-off-by Shan-Chun Hung <[email protected]>--- drivers/mmc/host/Kconfig | 12 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-of-ma35d1.c | 297 +++++++++++++++++++++++++++++ 3 files changed, 310 insertions(+)create mode 100644
drivers/mmc/host/sdhci-of-ma35d1.cdrivers/mmc/host/Kconfig +12
-0@@ -252,6 +252,18 @@ config MMC_SDHCI_OF_SPARX5 If unsure, say N. +config MMC_SDHCI_OF_MA35D1 + tristate "SDHCI OF support for the MA35D1 SDHCI controller" + depends on ARCH_MA35 || COMPILE_TEST + depends on MMC_SDHCI_PLTFM + help + This selects the MA35D1 Secure Digital Host Controller Interface. + The controller supports SD/MMC/SDIO devices. + + If you have a controller with this interface, say Y or M here. + + If unsure, say N. + config MMC_SDHCI_CADENCE tristate "SDHCI support for the Cadence SD/SDIO/eMMC controller" depends on MMC_SDHCI_PLTFMdrivers/mmc/host/Makefile +1
-0@@ -88,6 +88,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o obj-$(CONFIG_MMC_SDHCI_OF_DWCMSHC) += sdhci-of-dwcmshc.o obj-$(CONFIG_MMC_SDHCI_OF_SPARX5) += sdhci-of-sparx5.o +obj-$(CONFIG_MMC_SDHCI_OF_MA35D1) += sdhci-of-ma35d1.o obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o obj-$(CONFIG_MMC_SDHCI_IPROC) += sdhci-iproc.o obj-$(CONFIG_MMC_SDHCI_NPCM) += sdhci-npcm.odrivers/mmc/host/sdhci-of-ma35d1.c new file +38
-0@@ -0,0 +1,297 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2024 Nuvoton Technology Corp. +* +* Author: Shan-Chun Hung <[email protected]> +*/ + +#include <linux/align.h> +#include <linux/array_size.h> +#include <linux/bits.h> +#include <linux/build_bug.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <linux/math.h> +#include <linux/mfd/syscon.h> +#include <linux/minmax.h> +#include <linux/mmc/card.h> +#include <linux/mmc/host.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/pinctrl/consumer.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/reset.h> +#include <linux/sizes.h> +#include <linux/types.h> + +#include "sdhci-pltfm.h" +#include "sdhci.h" + +#define MA35_SYS_MISCFCR0 0x070 +#define MA35_SDHCI_MSHCCTL 0x508 +#define MA35_SDHCI_MBIUCTL 0x510 +
Quoted 8 lines
drivers/mmc/host/sdhci-of-ma35d1.c line 45
Quoted 7 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +7
-0+#define MA35_SDHCI_CMD_CONFLICT_CHK BIT(0) +#define MA35_SDHCI_INCR_MSK GENMASK(3, 0) +#define MA35_SDHCI_INCR16 BIT(3) +#define MA35_SDHCI_INCR8 BIT(2) + +struct ma35_priv { +struct regmap *regmap;Drop, you don't use it.
I will remove it and use local variables instead.
Quoted 33 lines
Quoted 12 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +11
-0+struct reset_control *rst; +struct pinctrl *pinctrl; +struct pinctrl_state *pins_uhs; +struct pinctrl_state *pins_default; +}; + +struct ma35_restore_data { +u32 reg; +u32 width; +}; +...
Quoted 19 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +19
-0+ +static int ma35_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sdhci_pltfm_host *pltfm_host; +struct sdhci_host *host; +struct ma35_priv *priv; +int err; +u32 extra, ctl; + + host =sdhci_pltfm_init (pdev, &sdhci_ma35_pdata,sizeof (struct ma35_priv )); +if (IS_ERR (host)) +return PTR_ERR (host); + +/* Extra adma table cnt for cross 128M boundary handling. */ + extra =DIV_ROUND_UP_ULL (dma_get_required_mask (dev),SZ_128M ); + extra =min (extra,SDHCI_MAX_SEGS ); + + host->adma_table_cnt += extra;
Quoted 8 lines
drivers/mmc/host/sdhci-of-ma35d1.c line 217
Quoted 7 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +7
-0+ pltfm_host =sdhci_priv (host); + priv =sdhci_pltfm_priv (pltfm_host); + + pltfm_host->clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (pltfm_host->clk)) { + err =PTR_ERR (pltfm_host->clk); +dev_err_probe (dev, err,"failed to get clk\n" );Syntax is err =
dev_err_probe()
I will fix it.
Quoted 13 lines
drivers/mmc/host/sdhci-of-ma35d1.c line 228
Quoted 11 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +11
-0+ goto err_sdhci; + } + + err =mmc_of_parse (host->mmc); +if (err) + goto err_sdhci; + + priv->rst =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (priv->rst)) { + err =PTR_ERR (priv->rst); +dev_err_probe (dev, err,"failed to get reset control\n" );err =
dev_err_probe
Quoted 2 lines
... so all your previous versions were leaking memory. Double check your error paths.
I will fix it and make sure to double check the error paths.
Quoted 7 lines
drivers/mmc/host/sdhci-of-ma35d1.c line 233
Quoted 5 lines
drivers/mmc/host/sdhci-of-ma35d1.c new file +5
-0+ goto err_sdhci; + } + +sdhci_get_of_property (pdev); +Best regards,
Krzysztof
Best Regards,
Shan-Chun