[PATCH v4 2/2] mmc: sdhci-of-ma35d1: Add Nuvoton MA35D1 SDHCI driver
Shan-Chun Hung
shanchun1218 at gmail.com
Mon Jul 8 19:07:45 PDT 2024
Dear Krzysztof,
Thank you for your review.
On 2024/7/8 下午 10:25, Krzysztof Kozlowski wrote:
> On 04/07/2024 08:26, Shan-Chun Hung wrote:
>> 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 <shanchun1218 at gmail.com>
>> ---
>> 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
>>
>> diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
>> index bb0d4fb0892a..aa6922ff4210 100644
>> --- a/drivers/mmc/host/Kconfig
>> +++ b/drivers/mmc/host/Kconfig
>> @@ -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
>> diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
>> index f53f86d200ac..3ccffebbe59b 100644
>> --- a/drivers/mmc/host/Makefile
>> +++ b/drivers/mmc/host/Makefile
>> @@ -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
>> diff --git a/drivers/mmc/host/sdhci-of-ma35d1.c b/drivers/mmc/host/sdhci-of-ma35d1.c
>> new file mode 100644
>> index 000000000000..b5aab65b9093
>> --- /dev/null
>> +++ b/drivers/mmc/host/sdhci-of-ma35d1.c
>> @@ -0,0 +1,297 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (C) 2024 Nuvoton Technology Corp.
>> + *
>> + * Author: Shan-Chun Hung <shanchun1218 at gmail.com>
>> + */
>> +
>> +#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
>> +
>> +#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.
>
>> + 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;
>> +};
>> +
> ...
>
>> +
>> +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;
>> + 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.
>> + 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.
I will fix it and make sure to double check the error paths.
>> + goto err_sdhci;
>> + }
>> +
>> + sdhci_get_of_property(pdev);
>> +
> Best regards,
> Krzysztof
Best Regards,
Shan-Chun
More information about the linux-arm-kernel
mailing list