From patchwork Thu Sep 21 14:30:02 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: 113267 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp2112133qgf; Thu, 21 Sep 2017 07:45:25 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA7h9rh+FV9XQKpYnTZBcS60Rcy9XE/H2eArRVW+1fVVtrA/hg+zsoet/Od0enomkV8ZIdS X-Received: by 10.80.208.208 with SMTP id g16mr1437336edf.246.1506005125465; Thu, 21 Sep 2017 07:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506005125; cv=none; d=google.com; s=arc-20160816; b=f4RbDlC5sYatWUV6X7eyPaVPLxaIKyYk0++2xZIRG259Qzh/fTYidd82I309W6ZSUc dHSkBOQyjdPvV8HhzSUlF5x/bFvvwfWcq4dwwYmD6mcuBD/r4DSiOIyZvlypvR2za4dz WTaUSQA3g50UxT9ak/EV/G3+81MCt5b23dox0hpR8QP+BSUbeZu2BJBySzfujBJyX39N QD/urXe9R2oze6wGyw9CpliFKuLgQImZmCz14S3D7QmJ/lnk3P3mIEhmcGGFKojeEjfi 1KmO6B+zPFYneo5KA+bcbKNGJ/NZrrvfBgRLc+kzcOd6KOimp0jhLqAJ7cAAszyOmneq Hd8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=ey50nhY9ljIhGAhWSxdsSyUfdlorzD3z2QOPoeEY8m0=; b=eoIx1wxFauIzPtQ+H1C/Ip0nsgs6Z0zxQ1xOXSdgJtt2UicfJ83WRIpUuOC1LwgnlV CSQ5w9aMg2SIcnQiWSOHaT0OpeUutVvV4aXVQSNG7ifyL3AeIP5Zd1T5TRrGZFpgWuIN Fp0faFg0vKqR6YRp5jtCzHH+wbZICaw4FQRlppb3vKB3D6AyZRHhIvsfH8+QVL2DQiGo nwkL2fJE8fE+o+JMBejleiOJhpcMao/G7RoCVQMYI64Qm3IMnBoUoq1Arc25FA5eMCgE 5qoyM4S1gau0JAPRJmI0lZ96eq/DPlRyb8hO8JJbj/HLjyiCpPoUaB2Xou4mSIuBFc8+ lQ7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=OvopDU7m; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id q7si1387010edk.133.2017.09.21.07.45.24; Thu, 21 Sep 2017 07:45:25 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b=OvopDU7m; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: by lists.denx.de (Postfix, from userid 105) id 79352C22071; Thu, 21 Sep 2017 14:41:09 +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 C0693C22024; Thu, 21 Sep 2017 14:41:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 414A0C2201E; Thu, 21 Sep 2017 14:32:02 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id 67853C21DE8 for ; Thu, 21 Sep 2017 14:31:58 +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 v8LEUudX032518; Thu, 21 Sep 2017 09:30:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1506004256; bh=dKZ+yBw45etXUSBH/wCAno0KXwqw5GQBUoJfEDv5Qyw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=OvopDU7m0p020rnu1thbdCL2w3Ls3ynaG06Cl2xYgvHyE0Zt/GsnQCKroPCoAcACD 9NBdW2igPdPtQaMc1sBJ7L8YZ9/yih9Ivhi9bM1LEeOeHMjlE64OB2dNqyL3+4BQgs DOtlXsQKn8ygLkqNK0VlQxnsMwVmJKS7sSdxKAzk= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v8LEUpNn028848; Thu, 21 Sep 2017 09:30:51 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Thu, 21 Sep 2017 09:30:51 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Thu, 21 Sep 2017 09:30:50 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v8LEUnbk000995; Thu, 21 Sep 2017 09:30:50 -0500 From: Jean-Jacques Hiblot To: , , , Date: Thu, 21 Sep 2017 16:30:02 +0200 Message-ID: <1506004213-22620-16-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506004213-22620-1-git-send-email-jjhiblot@ti.com> References: <1506004213-22620-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 15/26] 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" From: Kishon Vijay Abraham I 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 | 88 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index fd93691..65a3d8e 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -31,6 +31,7 @@ static const unsigned int sd_au_size[] = { }; static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage); +static int mmc_power_cycle(struct mmc *mmc); #if CONFIG_IS_ENABLED(MMC_TINY) static struct mmc mmc_static; @@ -1920,25 +1921,83 @@ static int mmc_power_init(struct mmc *mmc) &mmc->vqmmc_supply); if (ret) debug("%s: No vqmmc supply\n", mmc->dev->name); +#endif +#else /* !CONFIG_DM_MMC */ + /* + * Driver model should use a regulator, as above, rather than calling + * out to board code. + */ + board_mmc_power_init(); +#endif + return 0; +} + +/* + * put the host in the initial state: + * - turn on Vdd (card power supply) + * - configure the bus width and clock to minimal values + */ +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("mmc: failed to set signal voltage\n"); + + mmc_select_mode(mmc, MMC_LEGACY); + mmc_set_bus_width(mmc, 1); + mmc_set_clock(mmc, 0); +} +static int mmc_power_on(struct mmc *mmc) +{ +#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR) if (mmc->vmmc_supply) { - ret = regulator_set_enable(mmc->vmmc_supply, true); + int ret = regulator_set_enable(mmc->vmmc_supply, true); + if (ret) { puts("Error enabling VMMC supply\n"); return ret; } } #endif -#else /* !CONFIG_DM_MMC */ - /* - * Driver model should use a regulator, as above, rather than calling - * out to board code. - */ - board_mmc_power_init(); + return 0; +} + +static int mmc_power_off(struct mmc *mmc) +{ +#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR) + if (mmc->vmmc_supply) { + int ret = regulator_set_enable(mmc->vmmc_supply, false); + + if (ret) { + puts("Error disabling VMMC supply\n"); + return ret; + } + } #endif return 0; } +static int mmc_power_cycle(struct mmc *mmc) +{ + int ret; + + ret = mmc_power_off(mmc); + if (ret) + return ret; + /* + * SD spec recommends at least 1ms of delay. Let's wait for 2ms + * to be on the safer side. + */ + udelay(2000); + return mmc_power_on(mmc); +} + int mmc_start_init(struct mmc *mmc) { bool no_card; @@ -1967,6 +2026,10 @@ int mmc_start_init(struct mmc *mmc) if (err) return err; + err = mmc_power_on(mmc); + if (err) + return err; + #if CONFIG_IS_ENABLED(DM_MMC) /* The device has already been probed ready for use */ #else @@ -1977,16 +2040,7 @@ int mmc_start_init(struct mmc *mmc) #endif mmc->ddr_mode = 0; - /* 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_set_initial_state(mmc); mmc_send_init_stream(mmc); /* Reset the Card */