From: Eddie James Date: Thu, 15 Aug 2019 14:27:42 -0500 Subject: [U-Boot] [PATCH v2 2/4] mmc: Add Aspeed SD controller driver In-Reply-To: <64258ab5-e26b-e7b2-4128-5fd045b7c4b4@kaod.org> References: <1565724701-17344-1-git-send-email-eajames@linux.ibm.com> <1565724701-17344-3-git-send-email-eajames@linux.ibm.com> <64258ab5-e26b-e7b2-4128-5fd045b7c4b4@kaod.org> Message-ID: <51ce8fe1-b0f3-a4e0-c464-d367f12a526a@linux.ibm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de On 8/14/19 10:18 AM, C=C3=A9dric Le Goater wrote: > On 13/08/2019 21:31, Eddie James wrote: >> Add support for the Aspeed SD host controller engine. > It looks correct and simple enough. Some comments below. > >> Signed-off-by: Eddie James >> --- >> drivers/mmc/Kconfig | 11 +++++++ >> drivers/mmc/Makefile | 1 + >> drivers/mmc/aspeed_sdhci.c | 78 ++++++++++++++++++++++++++++++++++++++= ++++++++ >> 3 files changed, 90 insertions(+) >> create mode 100644 drivers/mmc/aspeed_sdhci.c >> >> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig >> index c6812f6..536f66a 100644 >> --- a/drivers/mmc/Kconfig >> +++ b/drivers/mmc/Kconfig >> @@ -421,6 +421,17 @@ config SPL_MMC_SDHCI_ADMA >> This enables support for the ADMA (Advanced DMA) defined >> in the SD Host Controller Standard Specification Version 3.00 in SP= L. >> =20 >> +config MMC_SDHCI_ASPEED >> + bool "Aspeed SDHCI controller" >> + depends on ARCH_ASPEED >> + depends on DM_MMC >> + depends on MMC_SDHCI >> + help >> + Enables support for the Aspeed SDHCI 2.0 controller present on Aspeed >> + SoCs. This device is compatible with SD 3.0 and/or MMC 4.3 >> + specifications. On the AST2600, the device is also compatible with >> + MMC 5.1 and eMMC 3.0. >> + >> config MMC_SDHCI_ATMEL >> bool "Atmel SDHCI controller support" >> depends on ARCH_AT91 >> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile >> index 6cc018b..5594195 100644 >> --- a/drivers/mmc/Makefile >> +++ b/drivers/mmc/Makefile >> @@ -46,6 +46,7 @@ obj-$(CONFIG_JZ47XX_MMC) +=3D jz_mmc.o >> =20 >> # SDHCI >> obj-$(CONFIG_MMC_SDHCI) +=3D sdhci.o >> +obj-$(CONFIG_MMC_SDHCI_ASPEED) +=3D aspeed_sdhci.o >> obj-$(CONFIG_MMC_SDHCI_ATMEL) +=3D atmel_sdhci.o >> obj-$(CONFIG_MMC_SDHCI_BCM2835) +=3D bcm2835_sdhci.o >> obj-$(CONFIG_MMC_SDHCI_BCMSTB) +=3D bcmstb_sdhci.o >> diff --git a/drivers/mmc/aspeed_sdhci.c b/drivers/mmc/aspeed_sdhci.c >> new file mode 100644 >> index 0000000..c292c42 >> --- /dev/null >> +++ b/drivers/mmc/aspeed_sdhci.c >> @@ -0,0 +1,78 @@ >> +// SPDX-License-Identifier: GPL-2.0+ >> +/* >> + * Copyright 2019 IBM Corp. >> + * Eddie James >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +struct aspeed_sdhci_plat { >> + struct mmc_config cfg; >> + struct mmc mmc; >> +}; >> + >> +static int aspeed_sdhci_probe(struct udevice *dev) >> +{ >> + struct mmc_uclass_priv *upriv =3D dev_get_uclass_priv(dev); >> + struct aspeed_sdhci_plat *plat =3D dev_get_platdata(dev); >> + struct sdhci_host *host =3D dev_get_priv(dev); >> + u32 max_clk; >> + struct clk clk; >> + int ret; >> + >> + ret =3D clk_get_by_index(dev, 0, &clk); >> + if (ret) >> + return ret; >> + >> + ret =3D clk_enable(&clk); >> + if (ret) >> + return ret; > Don't we need to release the clock below in case of error ? Yes. >> + host->name =3D dev->name; >> + host->ioaddr =3D (void *)devfdt_get_addr(dev); >> + >> + max_clk =3D clk_get_rate(&clk); >> + if (!max_clk) > may be use IS_ERR_VALUE(max_clk) and return max_clk Yep, good idea. Thanks for the quick review! Eddie > >> + return -EINVAL; >> + >> + host->max_clk =3D max_clk; >> + host->mmc =3D &plat->mmc; >> + host->mmc->dev =3D dev; >> + host->mmc->priv =3D host; >> + upriv->mmc =3D host->mmc; >> + >> + ret =3D sdhci_setup_cfg(&plat->cfg, host, 0, 0); >> + if (ret) >> + return ret; >> + >> + return sdhci_probe(dev); >> +} >> + >> +static int aspeed_sdhci_bind(struct udevice *dev) >> +{ >> + struct aspeed_sdhci_plat *plat =3D dev_get_platdata(dev); >> + >> + return sdhci_bind(dev, &plat->mmc, &plat->cfg); >> +} >> + >> +static const struct udevice_id aspeed_sdhci_ids[] =3D { >> + { .compatible =3D "aspeed,ast2400-sdhci" }, >> + { .compatible =3D "aspeed,ast2500-sdhci" }, >> + { .compatible =3D "aspeed,ast2600-sdhci" }, >> + { } >> +}; >> + >> +U_BOOT_DRIVER(aspeed_sdhci_drv) =3D { >> + .name =3D "aspeed_sdhci", >> + .id =3D UCLASS_MMC, >> + .of_match =3D aspeed_sdhci_ids, >> + .ops =3D &sdhci_ops, >> + .bind =3D aspeed_sdhci_bind, >> + .probe =3D aspeed_sdhci_probe, >> + .priv_auto_alloc_size =3D sizeof(struct sdhci_host), >> + .platdata_auto_alloc_size =3D sizeof(struct aspeed_sdhci_plat), >> +}; >>