From patchwork Mon Dec 17 09:02:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 153959 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2232892ljp; Mon, 17 Dec 2018 01:03:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqVzWc+XGTiE5BvMzGjahNJqNC9jRUGiV+egfcPBwsPIiWv+ND/y4ZdeoPUmtJkVMOdI1+ X-Received: by 2002:a17:906:7a18:: with SMTP id d24-v6mr6589161ejo.16.1545037428668; Mon, 17 Dec 2018 01:03:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545037428; cv=none; d=google.com; s=arc-20160816; b=cOpClnZg5nap4ogD2RinHkeamJ2MenFOV5Un4PmW1pjMCgwTwXvP4HcDCoLWOHHnMf 1gKhmaKRnExHJJXOYWzVjrsJ00yp0X1rZb7+tUzaX6hIDDgVxoyad2TqZdqoeQLykSrJ 6g3Du4myKQ6QwtEa54216YkuDij6cQ6Zqiuuxa+UGVnkssfW8K2Rrc4H8r2Bg/2MNKjn fPGcFWacFaNZ7JvgD9paHRHa0cAOvTyelOkkbNEAFiJ+1QSbKaEq59KOJ36omisBmpAg C88wLv1o9XxkZC3SJiwaoQuunIfEyBZ4F/Onp55uHOrngEvH2A7hUYkj4bGyVnexgt24 JSJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature; bh=dJSO7kmeySVY0FaWkexbGixlD1nOtZf7/PWA2p9irNQ=; b=fdIemGBh5bsKR8XLOEwepZ2Rq2e961FLcnUEht46ab9aiysElRuAioqqApGymeQ5Mo 90wCptPwfX8/x1xwd0kWXHbIN11Pq+JrpJTRTvpx577ULE+vALzHFaYMzksjQ2s2cQCW hpbiNZLjmSpIldY4qgxUoJVYIPQJIG0n8xBsOVgp5lc7/dcJoHOW+hQf08SIRky0fzU9 i0AezvqpbWs0F5jnrRW7j0f9a7pxRS1PE2Fq58tX0qSp1qcU88820T84mlpT8L8lFhZN /tyRXFTpuyw8AhuDDkqBav8Y+Cb+dEbARRsg7KtjtUDR8JiKRESrBeUWQC016+9WDqM6 DjRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DqTOFNQ8; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c23si2922180edn.65.2018.12.17.01.03.48; Mon, 17 Dec 2018 01:03:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DqTOFNQ8; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 481D2C2207A; Mon, 17 Dec 2018 09:03:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E88CAC21DD4; Mon, 17 Dec 2018 09:03:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ADDF2C21DD4; Mon, 17 Dec 2018 09:03:42 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by lists.denx.de (Postfix) with ESMTPS id 0EAADC21D8A for ; Mon, 17 Dec 2018 09:03:42 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id i12so6044069pfo.7 for ; Mon, 17 Dec 2018 01:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=zLrwSkQqARedOUrqadsfPIjl8oNYIIYdk828hAx1u78=; b=DqTOFNQ8ZjWjXqtNmFqjN0UtHXxleVdhqKBL3ne1Wo0qQwXM3WDKWM2sliS/OLyIZr 9MH48TmxEPlFK79WH7RrDuA88Bg6/O9gAUmeI6ZFSRF1W3rVN1lO1iHevkbLPD0pHQqn +oSd/4telRTpV9wrQuFRAvRNlWeGgOaN8ItZA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zLrwSkQqARedOUrqadsfPIjl8oNYIIYdk828hAx1u78=; b=SnPeuTl4s9WYpAw5Rzlqezkeuu72lVPDr61QaWPu+olrdfLyzievhInK1QVmOX6la1 sAdLShuTvVIuJ2UmkYykx4s5x5WBcugl/eoYGYhX2w7TtkLS0kF+WRruAgF4NaKwmPTY UWZ6p4R1MimmcbqmgT7LmXiE8jC7SlAUXi6jxJUE0mcWtWjcW9mJVIJ7ItNjj2QI7sSe yoqQ87ZWwDTwaObd6JlicDKhA7vOyk+OZxrVOQdI8GdNjyaVurmLPwNpbkw+aajNpf+a NFuVDR56VugMyMQhxeFhGrkTTZD0OCt7nwMBaWxu9QKHzqlovTU1pGcg6hVyYSNANAJX e8GA== X-Gm-Message-State: AA+aEWYmBiwQj0+4WOmb7yrpcyLiyWt3fxr2wO62XiRh6H7thc5uiRZo iIuacho+AUEbaV7fzB3Lcdbrsg== X-Received: by 2002:a63:981:: with SMTP id 123mr11537983pgj.444.1545037420477; Mon, 17 Dec 2018 01:03:40 -0800 (PST) Received: from localhost.localdomain (61-216-91-114.HINET-IP.hinet.net. [61.216.91.114]) by smtp.gmail.com with ESMTPSA id t13sm15159236pgr.42.2018.12.17.01.03.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 01:03:38 -0800 (PST) From: Shawn Guo To: Jaehoon Chung Date: Mon, 17 Dec 2018 17:02:31 +0800 Message-Id: <20181217090231.24645-1-shawn.guo@linaro.org> X-Mailer: git-send-email 2.18.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] mmc: hi6220_dw_mmc: add driver model support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" As requested by driver model migration plan, it adds driver model support, i.e. CONFIG_DM_MMC, for hi6220_dw_mmc driver. Signed-off-by: Shawn Guo --- drivers/mmc/hi6220_dw_mmc.c | 83 +++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/mmc/hi6220_dw_mmc.c b/drivers/mmc/hi6220_dw_mmc.c index ce395d53c942..e0de92418274 100644 --- a/drivers/mmc/hi6220_dw_mmc.c +++ b/drivers/mmc/hi6220_dw_mmc.c @@ -23,11 +23,13 @@ static int hi6220_dwmci_core_init(struct dwmci_host *host, int index) host->dev_index = index; +#ifndef CONFIG_BLK /* Add the mmc channel to be registered with mmc core */ if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) { printf("DWMMC%d registration failed\n", index); return -1; } +#endif return 0; } @@ -53,3 +55,84 @@ int hi6220_dwmci_add_port(int index, u32 regbase, int bus_width) return hi6220_dwmci_core_init(host, index); } + +#ifdef CONFIG_DM_MMC +#include +DECLARE_GLOBAL_DATA_PTR; + +struct hi6220_mmc_plat { + struct mmc_config cfg; + struct mmc mmc; +}; + +struct hi6220_dwmmc_priv { + struct dwmci_host host; + int fifo_depth; +}; + +static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev) +{ + struct hi6220_dwmmc_priv *priv = dev_get_priv(dev); + struct dwmci_host *host = &priv->host; + int ret; + + host->priv = dev; + host->name = dev->name; + host->ioaddr = dev_read_addr_ptr(dev); + host->bus_hz = MMC0_DEFAULT_FREQ; + host->buswidth = dev_read_u32_default(dev, "bus-width", 4); + priv->fifo_depth = dev_read_u32_default(dev, "fifo-depth", 0); + + ret = dev_read_alias_seq(dev, &host->dev_index); + if (ret < 0) { + debug("%s: failed to get alias: %d\n", __func__, ret); + return ret; + } + + return 0; +} + +static int hi6220_dwmmc_probe(struct udevice *dev) +{ + struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); + struct hi6220_dwmmc_priv *priv = dev_get_priv(dev); + struct hi6220_mmc_plat *plat = dev_get_platdata(dev); + struct dwmci_host *host = &priv->host; + + host->fifoth_val = MSIZE(0x2) | + RX_WMARK(priv->fifo_depth / 2 - 1) | + TX_WMARK(priv->fifo_depth / 2); + + dwmci_setup_cfg(&plat->cfg, host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ); + host->mmc = &plat->mmc; + host->mmc->priv = &priv->host; + host->priv = dev; + upriv->mmc = host->mmc; + + return dwmci_probe(dev); +} + +static int hi6220_dwmmc_bind(struct udevice *dev) +{ + struct hi6220_mmc_plat *plat = dev_get_platdata(dev); + + return dwmci_bind(dev, &plat->mmc, &plat->cfg); +} + +static const struct udevice_id hi6220_dwmmc_ids[] = { + { .compatible = "hisilicon,hi3798cv200-dw-mshc" }, + { } +}; + +U_BOOT_DRIVER(hi6220_dwmmc_drv) = { + .name = "hi6220_dwmmc", + .id = UCLASS_MMC, + .of_match = hi6220_dwmmc_ids, + .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata, + .bind = hi6220_dwmmc_bind, + .ops = &dm_dwmci_ops, + .probe = hi6220_dwmmc_probe, + .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv), + .platdata_auto_alloc_size = sizeof(struct hi6220_mmc_plat), +}; +#endif