From patchwork Mon Dec 27 10:14:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chuanxiao.Dong" X-Patchwork-Id: 433751 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBRKCV7V025997 for ; Mon, 27 Dec 2010 20:15:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753263Ab0L0KT4 (ORCPT ); Mon, 27 Dec 2010 05:19:56 -0500 Received: from mga01.intel.com ([192.55.52.88]:1737 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753003Ab0L0KT4 (ORCPT ); Mon, 27 Dec 2010 05:19:56 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 27 Dec 2010 02:19:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.60,234,1291622400"; d="scan'208";a="640712683" Received: from unknown (HELO intel.com) ([172.16.120.128]) by fmsmga002.fm.intel.com with ESMTP; 27 Dec 2010 02:19:55 -0800 Date: Mon, 27 Dec 2010 18:14:43 +0800 From: Chuanxiao Dong To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, cjb@laptop.org, akpm@linux-foundation.org Subject: [PATCH v6 3/3]mmc: implement hwreset_emmc and reinit_emmc callbacks Message-ID: <20101227101443.GD20143@intel.com> Reply-To: Chuanxiao Dong MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 27 Dec 2010 20:15:00 +0000 (UTC) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index ebb5748..8c82b9d 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -745,6 +746,84 @@ static int mmc_awake(struct mmc_host *host) return err; } +/** + * mmc_reinit_card - reinitialize eMMC card after HW reset + * @host: mmc host structure + * + * this callback is used to reinitialize card after a HW + * reset occurs. + * mmc_claim_host should be called before using this callback and + * mmc_release_host should be called after. + * + * Return value: + * 0 - successfully reinitialize + * other - failed to reinitialize + */ +static int mmc_reinit_card(struct mmc_host *host) +{ + int err; + /* + * Before init card, set the clock to be + * the init frequency + */ + host->ios.clock = host->f_init; + mmc_set_clock(host, host->ios.clock); + + err = mmc_init_card(host, host->ocr, host->card); + if (err) + pr_err("%s: Error %d while reinit card\n", + mmc_hostname(host), err); + + return err; +} + +/** + * mmc_reset_card - reset eMMC card + * + * this callback is used to trigger RST_n signal by using GPIO to reset eMMC + * card. The RST_n signal is defined in eMMC4.4 spec + * + * Return value: + * 0 - successfully reset eMMC card + * -ENODEV - no valid GPIO line to be used + * -ENOSYS - GPIO functions is not implemented + * other - failed to reset eMMC card + */ +static int mmc_hwreset_emmc(struct mmc_host *host) +{ + int gpio = host->rst_gpio; + int ret; + if (gpio <= 0) + return -ENODEV; + + /* request reset pin for eMMC */ + ret = gpio_request(gpio, "eMMC_rst_pin"); + if (ret < 0) { + pr_err("gpio %d request failed, err %d\n", + gpio, ret); + return ret; + } + /* set to be output and to be low state */ + ret = gpio_direction_output(gpio, 0); + if (ret < 0) { + pr_err("gpio %d direction output failed, err %d\n", + gpio, ret); + gpio_free(gpio); + return ret; + } + /* delay 10us for tRSTW */ + udelay(10); + /* set to be high and delay 300us */ + gpio_set_value(gpio, 1); + udelay(300); + /* set to be output and to be low state */ + gpio_direction_output(gpio, 0); + /* free reset gpio pin */ + gpio_free(gpio); + + return 0; +} + static const struct mmc_bus_ops mmc_ops = { .awake = mmc_awake, .sleep = mmc_sleep, @@ -753,6 +832,8 @@ static const struct mmc_bus_ops mmc_ops = { .suspend = NULL, .resume = NULL, .power_restore = mmc_power_restore, + .reinit_emmc = mmc_reinit_card, + .hwreset_emmc = mmc_hwreset_emmc, }; static const struct mmc_bus_ops mmc_ops_unsafe = { @@ -763,6 +844,8 @@ static const struct mmc_bus_ops mmc_ops_unsafe = { .suspend = mmc_suspend, .resume = mmc_resume, .power_restore = mmc_power_restore, + .reinit_emmc = mmc_reinit_card, + .hwreset_emmc = mmc_hwreset_emmc, }; static void mmc_attach_bus_ops(struct mmc_host *host) diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index bcb793e..d2b3bf6 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -243,6 +243,8 @@ struct mmc_host { struct dentry *debugfs_root; + unsigned int rst_gpio; /* gpio pin to reset eMMC card */ + unsigned long private[0] ____cacheline_aligned; };