From patchwork Fri May 12 18:16:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 761798 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wPdkk6DJlz9s7B for ; Sat, 13 May 2017 04:27:58 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="xZV/hjKS"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 8A3E3C21FE4; Fri, 12 May 2017 18:22:48 +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_NONE, 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 826D2C21F7B; Fri, 12 May 2017 18:19:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 39A7EC21F7B; Fri, 12 May 2017 18:17:58 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id 4A48AC21FD8 for ; Fri, 12 May 2017 18:17:52 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v4CIH5SY003488; Fri, 12 May 2017 13:17:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1494613025; bh=E+Nd1pQh+cJewZ+4EfIFmFG5dWfWTefSBNHPk1b/EzQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=xZV/hjKSJxWwH8Tq4EoRDcWaY0/759esnONb9x0P4E1F2e9Io/JM95e2fgp0Yc/Ok h+2Dsjrd1eJvz+vkBxWK3CxQN5OavAbK5bh1UzHsJ4qn2rGjiDW8SkAERK6+KITZnQ AE8UTa9x8hpXXaQIP1u7YdyY5XrDo494Bkz8eefk= Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v4CIH0pt021710; Fri, 12 May 2017 13:17:00 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Fri, 12 May 2017 13:16:59 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v4CIGxj6019714; Fri, 12 May 2017 13:16:59 -0500 From: Jean-Jacques Hiblot To: , , , , Date: Fri, 12 May 2017 20:16:32 +0200 Message-ID: <1494613000-8156-15-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1494613000-8156-1-git-send-email-jjhiblot@ti.com> References: <1494613000-8156-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 14/22] mmc: add power cyle support in mmc core 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" mmc/sd specification requires vdd to be disabled for 1 ms and then enabled again during power cycle. Add a function in mmc core to perform power cycle and set the io signal to it's initial state. Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Jean-Jacques Hiblot --- drivers/mmc/mmc.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index d40a22b..032260b 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -30,6 +30,7 @@ static const unsigned int sd_au_size[] = { SZ_16M / 512, (SZ_16M + SZ_8M) / 512, SZ_32M / 512, SZ_64M / 512, }; static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage); +static void mmc_power_cycle(struct mmc *mmc); #if CONFIG_IS_ENABLED(MMC_TINY) static struct mmc mmc_static; @@ -1915,6 +1916,45 @@ static int mmc_power_init(struct mmc *mmc) return 0; } +static void mmc_set_initial_state(struct mmc *mmc) +{ + int err; + + /* First try to set 3.3V. If it fails set to 1.8V */ + err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_330); + if (err != 0) + err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_180); + if (err != 0) + printf("failed to set signal voltage\n"); + + mmc_set_bus_width(mmc, 1); + mmc_set_clock(mmc, 1); + mmc_select_mode(mmc, MMC_LEGACY); +} + +static void mmc_power_up(struct mmc *mmc) +{ + mmc_set_initial_state(mmc); + mmc_set_vdd(mmc, true); + udelay(10000); +} + +static void mmc_power_off(struct mmc *mmc) +{ + mmc_set_vdd(mmc, false); +} + +static void mmc_power_cycle(struct mmc *mmc) +{ + mmc_power_off(mmc); + /* + * SD spec recommends at least 1ms of delay. Let's wait for 2ms + * to be on the safer side. + */ + udelay(2000); + mmc_power_up(mmc); +} + int mmc_start_init(struct mmc *mmc) { bool no_card; @@ -1952,16 +1992,8 @@ int mmc_start_init(struct mmc *mmc) return err; #endif mmc->ddr_mode = 0; - mmc_set_vdd(mmc, true); - /* First try to set 3.3V. If it fails set to 1.8V */ - err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_330); - if (err != 0) - err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_180); - if (err != 0) - printf("failed to set signal voltage\n"); - mmc_set_bus_width(mmc, 1); - mmc_set_clock(mmc, 1); + mmc_power_cycle(mmc); /* Reset the Card */ err = mmc_go_idle(mmc);