From patchwork Thu Aug 25 05:52:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 74648 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp667383qga; Wed, 24 Aug 2016 22:53:51 -0700 (PDT) X-Received: by 10.194.106.1 with SMTP id gq1mr5234352wjb.167.1472104431842; Wed, 24 Aug 2016 22:53:51 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id 8si30130674wmu.68.2016.08.24.22.53.51; Wed, 24 Aug 2016 22:53:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5FC0DA754A; Thu, 25 Aug 2016 07:53:51 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PZT58qemX5Gz; Thu, 25 Aug 2016 07:53:51 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C66A7A7534; Thu, 25 Aug 2016 07:53:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 914D94B811 for ; Thu, 25 Aug 2016 07:53:46 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G10rtEYxVXoC for ; Thu, 25 Aug 2016 07:53:46 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-11.nifty.com (conuserg-11.nifty.com [210.131.2.78]) by theia.denx.de (Postfix) with ESMTPS id D7FB3A753A for ; Thu, 25 Aug 2016 07:51:12 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id u7P5oZi1017421; Thu, 25 Aug 2016 14:50:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com u7P5oZi1017421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1472104236; bh=yrOLnAV2KEy0I6E5BcLRsjc3ihY8fB3SWAEWOQgAEro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r7tQVhqeoBN7FR4/x1cGiSpLOZxM/gGpYUa2HxfWTgbrUXPphkioWKyh/S1JI42Px edifxC4anGsNvlNqXLO2Ten3HzffVEobSLwnJwylbAHn1KNFfpT1fL1j7KyL01xm+6 VmpYQ9ytnwXTMs5AP8RFmQdkexOGSBI75Ag8DK7PUqkNzWnRxS9ripBsh1T62TespR c000cOk3Yj7wdo6JoswM44iTRrLl2ZtMV/d4EOsLZC3yYwsBNwpVRMQU+Fjhmtxz7k yJIzRowwovodm2lLdsrw/70omolHJEXYZF8vmp1Dhp2a+78Zl6+Tx8F0I9zrTVzibb oUkTNi1oemgfA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 25 Aug 2016 14:52:35 +0900 Message-Id: <1472104359-23551-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472104359-23551-1-git-send-email-yamada.masahiro@socionext.com> References: <1472104359-23551-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 1/5] mmc: uniphier-sd: migrate to CONFIG_DM_MMC_OPS X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Catch up with the DM migration. As struct dm_mmc_ops does not have .init callback, call the init function directly from the probe function. Signed-off-by: Masahiro Yamada --- drivers/mmc/Kconfig | 1 + drivers/mmc/uniphier-sd.c | 97 ++++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 47 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index b820485..4cdd9b1 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -80,6 +80,7 @@ config ROCKCHIP_SDHCI config MMC_UNIPHIER bool "UniPhier SD/MMC Host Controller support" depends on ARCH_UNIPHIER + select DM_MMC_OPS help This selects support for the SD/MMC Host Controller on UniPhier SoCs. diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c index f06e737..b8e784f 100644 --- a/drivers/mmc/uniphier-sd.c +++ b/drivers/mmc/uniphier-sd.c @@ -122,7 +122,6 @@ DECLARE_GLOBAL_DATA_PTR; struct uniphier_sd_priv { struct mmc_config cfg; struct mmc *mmc; - struct udevice *dev; void __iomem *regbase; unsigned long mclk; unsigned int version; @@ -152,8 +151,9 @@ static void __dma_unmap_single(dma_addr_t addr, size_t size, invalidate_dcache_range(addr, addr + size); } -static int uniphier_sd_check_error(struct uniphier_sd_priv *priv) +static int uniphier_sd_check_error(struct udevice *dev) { + struct uniphier_sd_priv *priv = dev_get_priv(dev); u32 info2 = readl(priv->regbase + UNIPHIER_SD_INFO2); if (info2 & UNIPHIER_SD_INFO2_ERR_RTO) { @@ -166,38 +166,39 @@ static int uniphier_sd_check_error(struct uniphier_sd_priv *priv) } if (info2 & UNIPHIER_SD_INFO2_ERR_TO) { - dev_err(priv->dev, "timeout error\n"); + dev_err(dev, "timeout error\n"); return -ETIMEDOUT; } if (info2 & (UNIPHIER_SD_INFO2_ERR_END | UNIPHIER_SD_INFO2_ERR_CRC | UNIPHIER_SD_INFO2_ERR_IDX)) { - dev_err(priv->dev, "communication out of sync\n"); + dev_err(dev, "communication out of sync\n"); return -EILSEQ; } if (info2 & (UNIPHIER_SD_INFO2_ERR_ILA | UNIPHIER_SD_INFO2_ERR_ILR | UNIPHIER_SD_INFO2_ERR_ILW)) { - dev_err(priv->dev, "illegal access\n"); + dev_err(dev, "illegal access\n"); return -EIO; } return 0; } -static int uniphier_sd_wait_for_irq(struct uniphier_sd_priv *priv, - unsigned int reg, u32 flag) +static int uniphier_sd_wait_for_irq(struct udevice *dev, unsigned int reg, + u32 flag) { + struct uniphier_sd_priv *priv = dev_get_priv(dev); long wait = 1000000; int ret; while (!(readl(priv->regbase + reg) & flag)) { if (wait-- < 0) { - dev_err(priv->dev, "timeout\n"); + dev_err(dev, "timeout\n"); return -ETIMEDOUT; } - ret = uniphier_sd_check_error(priv); + ret = uniphier_sd_check_error(dev); if (ret) return ret; @@ -207,14 +208,14 @@ static int uniphier_sd_wait_for_irq(struct uniphier_sd_priv *priv, return 0; } -static int uniphier_sd_pio_read_one_block(struct mmc *mmc, u32 **pbuf, +static int uniphier_sd_pio_read_one_block(struct udevice *dev, u32 **pbuf, uint blocksize) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); int i, ret; /* wait until the buffer is filled with data */ - ret = uniphier_sd_wait_for_irq(priv, UNIPHIER_SD_INFO2, + ret = uniphier_sd_wait_for_irq(dev, UNIPHIER_SD_INFO2, UNIPHIER_SD_INFO2_BRE); if (ret) return ret; @@ -237,14 +238,14 @@ static int uniphier_sd_pio_read_one_block(struct mmc *mmc, u32 **pbuf, return 0; } -static int uniphier_sd_pio_write_one_block(struct mmc *mmc, const u32 **pbuf, - uint blocksize) +static int uniphier_sd_pio_write_one_block(struct udevice *dev, + const u32 **pbuf, uint blocksize) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); int i, ret; /* wait until the buffer becomes empty */ - ret = uniphier_sd_wait_for_irq(priv, UNIPHIER_SD_INFO2, + ret = uniphier_sd_wait_for_irq(dev, UNIPHIER_SD_INFO2, UNIPHIER_SD_INFO2_BWE); if (ret) return ret; @@ -263,7 +264,7 @@ static int uniphier_sd_pio_write_one_block(struct mmc *mmc, const u32 **pbuf, return 0; } -static int uniphier_sd_pio_xfer(struct mmc *mmc, struct mmc_data *data) +static int uniphier_sd_pio_xfer(struct udevice *dev, struct mmc_data *data) { u32 *dest = (u32 *)data->dest; const u32 *src = (const u32 *)data->src; @@ -271,10 +272,10 @@ static int uniphier_sd_pio_xfer(struct mmc *mmc, struct mmc_data *data) for (i = 0; i < data->blocks; i++) { if (data->flags & MMC_DATA_READ) - ret = uniphier_sd_pio_read_one_block(mmc, &dest, + ret = uniphier_sd_pio_read_one_block(dev, &dest, data->blocksize); else - ret = uniphier_sd_pio_write_one_block(mmc, &src, + ret = uniphier_sd_pio_write_one_block(dev, &src, data->blocksize); if (ret) return ret; @@ -306,14 +307,15 @@ static void uniphier_sd_dma_start(struct uniphier_sd_priv *priv, writel(UNIPHIER_SD_DMA_CTL_START, priv->regbase + UNIPHIER_SD_DMA_CTL); } -static int uniphier_sd_dma_wait_for_irq(struct uniphier_sd_priv *priv, u32 flag, +static int uniphier_sd_dma_wait_for_irq(struct udevice *dev, u32 flag, unsigned int blocks) { + struct uniphier_sd_priv *priv = dev_get_priv(dev); long wait = 1000000 + 10 * blocks; while (!(readl(priv->regbase + UNIPHIER_SD_DMA_INFO1) & flag)) { if (wait-- < 0) { - dev_err(priv->dev, "timeout during DMA\n"); + dev_err(dev, "timeout during DMA\n"); return -ETIMEDOUT; } @@ -321,16 +323,16 @@ static int uniphier_sd_dma_wait_for_irq(struct uniphier_sd_priv *priv, u32 flag, } if (readl(priv->regbase + UNIPHIER_SD_DMA_INFO2)) { - dev_err(priv->dev, "error during DMA\n"); + dev_err(dev, "error during DMA\n"); return -EIO; } return 0; } -static int uniphier_sd_dma_xfer(struct mmc *mmc, struct mmc_data *data) +static int uniphier_sd_dma_xfer(struct udevice *dev, struct mmc_data *data) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); size_t len = data->blocks * data->blocksize; void *buf; enum dma_data_direction dir; @@ -358,7 +360,7 @@ static int uniphier_sd_dma_xfer(struct mmc *mmc, struct mmc_data *data) uniphier_sd_dma_start(priv, dma_addr); - ret = uniphier_sd_dma_wait_for_irq(priv, poll_flag, data->blocks); + ret = uniphier_sd_dma_wait_for_irq(dev, poll_flag, data->blocks); __dma_unmap_single(dma_addr, len, dir); @@ -384,15 +386,15 @@ static bool uniphier_sd_addr_is_dmaable(unsigned long addr) return true; } -static int uniphier_sd_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, +static int uniphier_sd_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, struct mmc_data *data) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); int ret; u32 tmp; if (readl(priv->regbase + UNIPHIER_SD_INFO2) & UNIPHIER_SD_INFO2_CBSY) { - dev_err(priv->dev, "command busy\n"); + dev_err(dev, "command busy\n"); return -EBUSY; } @@ -446,15 +448,15 @@ static int uniphier_sd_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, tmp |= UNIPHIER_SD_CMD_RSP_R3; break; default: - dev_err(priv->dev, "unknown response type\n"); + dev_err(dev, "unknown response type\n"); return -EINVAL; } - dev_dbg(priv->dev, "sending CMD%d (SD_CMD=%08x, SD_ARG=%08x)\n", + dev_dbg(dev, "sending CMD%d (SD_CMD=%08x, SD_ARG=%08x)\n", cmd->cmdidx, tmp, cmd->cmdarg); writel(tmp, priv->regbase + UNIPHIER_SD_CMD); - ret = uniphier_sd_wait_for_irq(priv, UNIPHIER_SD_INFO1, + ret = uniphier_sd_wait_for_irq(dev, UNIPHIER_SD_INFO1, UNIPHIER_SD_INFO1_RSP); if (ret) return ret; @@ -481,11 +483,11 @@ static int uniphier_sd_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, /* use DMA if the HW supports it and the buffer is aligned */ if (priv->caps & UNIPHIER_SD_CAP_DMA_INTERNAL && uniphier_sd_addr_is_dmaable((long)data->src)) - ret = uniphier_sd_dma_xfer(mmc, data); + ret = uniphier_sd_dma_xfer(dev, data); else - ret = uniphier_sd_pio_xfer(mmc, data); + ret = uniphier_sd_pio_xfer(dev, data); - ret = uniphier_sd_wait_for_irq(priv, UNIPHIER_SD_INFO1, + ret = uniphier_sd_wait_for_irq(dev, UNIPHIER_SD_INFO1, UNIPHIER_SD_INFO1_CMP); if (ret) return ret; @@ -581,11 +583,12 @@ static void uniphier_sd_set_clk_rate(struct uniphier_sd_priv *priv, writel(tmp, priv->regbase + UNIPHIER_SD_CLKCTL); } -static void uniphier_sd_set_ios(struct mmc *mmc) +static int uniphier_sd_set_ios(struct udevice *dev) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); + struct mmc *mmc = mmc_get_mmc_dev(dev); - dev_dbg(priv->dev, "clock %uHz, DDRmode %d, width %u\n", + dev_dbg(dev, "clock %uHz, DDRmode %d, width %u\n", mmc->clock, mmc->ddr_mode, mmc->bus_width); uniphier_sd_set_bus_width(priv, mmc); @@ -593,11 +596,12 @@ static void uniphier_sd_set_ios(struct mmc *mmc) uniphier_sd_set_clk_rate(priv, mmc); udelay(1000); + + return 0; } -static int uniphier_sd_init(struct mmc *mmc) +static int uniphier_sd_init(struct uniphier_sd_priv *priv) { - struct uniphier_sd_priv *priv = mmc->priv; u32 tmp; /* soft reset of the host */ @@ -628,9 +632,9 @@ static int uniphier_sd_init(struct mmc *mmc) return 0; } -static int uniphier_sd_getcd(struct mmc *mmc) +static int uniphier_sd_get_cd(struct udevice *dev) { - struct uniphier_sd_priv *priv = mmc->priv; + struct uniphier_sd_priv *priv = dev_get_priv(dev); if (priv->caps & UNIPHIER_SD_CAP_NONREMOVABLE) return 1; @@ -639,11 +643,10 @@ static int uniphier_sd_getcd(struct mmc *mmc) UNIPHIER_SD_INFO1_CD); } -static const struct mmc_ops uniphier_sd_ops = { +static const struct dm_mmc_ops uniphier_sd_ops = { .send_cmd = uniphier_sd_send_cmd, .set_ios = uniphier_sd_set_ios, - .init = uniphier_sd_init, - .getcd = uniphier_sd_getcd, + .get_cd = uniphier_sd_get_cd, }; static int uniphier_sd_probe(struct udevice *dev) @@ -654,8 +657,6 @@ static int uniphier_sd_probe(struct udevice *dev) struct clk clk; int ret; - priv->dev = dev; - base = dev_get_addr(dev); if (base == FDT_ADDR_T_NONE) return -EINVAL; @@ -686,7 +687,6 @@ static int uniphier_sd_probe(struct udevice *dev) } priv->cfg.name = dev->name; - priv->cfg.ops = &uniphier_sd_ops; priv->cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS; switch (fdtdec_get_int(gd->fdt_blob, dev->of_offset, "bus-width", 1)) { @@ -715,6 +715,8 @@ static int uniphier_sd_probe(struct udevice *dev) priv->caps |= UNIPHIER_SD_CAP_DIV1024; } + uniphier_sd_init(priv); + priv->cfg.voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34; priv->cfg.f_min = priv->mclk / (priv->caps & UNIPHIER_SD_CAP_DIV1024 ? 1024 : 512); @@ -752,4 +754,5 @@ U_BOOT_DRIVER(uniphier_mmc) = { .probe = uniphier_sd_probe, .remove = uniphier_sd_remove, .priv_auto_alloc_size = sizeof(struct uniphier_sd_priv), + .ops = &uniphier_sd_ops, };