From patchwork Mon Mar 21 18:46:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 648671 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 p2LIqDlY023640 for ; Mon, 21 Mar 2011 18:52:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753402Ab1CUSww (ORCPT ); Mon, 21 Mar 2011 14:52:52 -0400 Received: from smtp205.alice.it ([82.57.200.101]:54818 "EHLO smtp205.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751494Ab1CUSww (ORCPT ); Mon, 21 Mar 2011 14:52:52 -0400 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 21 Mar 2011 18:52:53 +0000 (UTC) X-Greylist: delayed 337 seconds by postgrey-1.27 at vger.kernel.org; Mon, 21 Mar 2011 14:52:52 EDT Received: from jcn (79.2.146.74) by smtp205.alice.it (8.5.124.08) id 4D0D003808011AA8; Mon, 21 Mar 2011 19:46:51 +0100 Received: from ao2 by jcn with local (Exim 4.74) (envelope-from ) id 1Q1k7t-00077F-3h; Mon, 21 Mar 2011 19:46:49 +0100 From: Antonio Ospite To: linux-mmc@vger.kernel.org Cc: Antonio Ospite , Daniel Ribeiro , David Brownell , Chris Ball , Grant Likely , Ernst Schwab , Sonic Zhang , Linus Walleij , openezx-devel@lists.openezx.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mmc_spi.c: factor out the SD card shutdown sequence Date: Mon, 21 Mar 2011 19:46:40 +0100 Message-Id: <1300733202-27316-3-git-send-email-ospite@studenti.unina.it> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1300733202-27316-1-git-send-email-ospite@studenti.unina.it> References: <1300733202-27316-1-git-send-email-ospite@studenti.unina.it> X-Face: z*RaLf`X<@C75u6Ig9}{oW$H; 1_\2t5)({*|jhM/Vb; ]yA5\I~93>J<_`<4)A{':UrE Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 1db18ce..fe0fdc4 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1176,6 +1176,51 @@ static void mmc_spi_initsequence(struct mmc_spi_host *host) } } +/* See Section 6.4.2, in SD "Simplified Physical Layer Specification 2.0" + * + * If powering down, ground all card inputs to avoid power delivery from data + * lines! On a shared SPI bus, this will probably be temporary; 6.4.2 of + * the simplified SD spec says this must last at least 1msec. + * + * - Clock low means CPOL 0, e.g. mode 0 + * - MOSI low comes from writing zero + * - Chipselect is usually active low... + */ +static void mmc_spi_shutdownsequence(struct mmc_spi_host *host) +{ + int mres; + u8 nullbyte = 0; + + host->spi->mode &= ~(SPI_CPOL|SPI_CPHA); + mres = spi_setup(host->spi); + if (mres < 0) + dev_dbg(&host->spi->dev, + "switch to SPI mode 0 failed\n"); + + if (spi_write(host->spi, &nullbyte, 1) < 0) + dev_dbg(&host->spi->dev, + "put spi signals to low failed\n"); + + /* + * Now clock should be low due to spi mode 0; + * MOSI should be low because of written 0x00; + * chipselect should be low (it is active low) + * power supply is off, so now MMC is off too! + * + * FIXME no, chipselect can be high since the + * device is inactive and SPI_CS_HIGH is clear... + */ + msleep(10); + if (mres == 0) { + host->spi->mode |= (SPI_CPOL|SPI_CPHA); + mres = spi_setup(host->spi); + if (mres < 0) + dev_dbg(&host->spi->dev, + "switch back to SPI mode 3" + " failed\n"); + } +} + static char *mmc_powerstring(u8 power_mode) { switch (power_mode) { @@ -1215,49 +1260,10 @@ static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (ios->power_mode == MMC_POWER_ON) mmc_spi_initsequence(host); - /* If powering down, ground all card inputs to avoid power - * delivery from data lines! On a shared SPI bus, this - * will probably be temporary; 6.4.2 of the simplified SD - * spec says this must last at least 1msec. - * - * - Clock low means CPOL 0, e.g. mode 0 - * - MOSI low comes from writing zero - * - Chipselect is usually active low... - */ + /* See 6.4.2 in the simplified SD card physical spec 2.0 */ if (mmc_spi_canpower(host) && - ios->power_mode == MMC_POWER_OFF) { - int mres; - u8 nullbyte = 0; - - host->spi->mode &= ~(SPI_CPOL|SPI_CPHA); - mres = spi_setup(host->spi); - if (mres < 0) - dev_dbg(&host->spi->dev, - "switch to SPI mode 0 failed\n"); - - if (spi_write(host->spi, &nullbyte, 1) < 0) - dev_dbg(&host->spi->dev, - "put spi signals to low failed\n"); - - /* - * Now clock should be low due to spi mode 0; - * MOSI should be low because of written 0x00; - * chipselect should be low (it is active low) - * power supply is off, so now MMC is off too! - * - * FIXME no, chipselect can be high since the - * device is inactive and SPI_CS_HIGH is clear... - */ - msleep(10); - if (mres == 0) { - host->spi->mode |= (SPI_CPOL|SPI_CPHA); - mres = spi_setup(host->spi); - if (mres < 0) - dev_dbg(&host->spi->dev, - "switch back to SPI mode 3" - " failed\n"); - } - } + ios->power_mode == MMC_POWER_OFF) + mmc_spi_shutdownsequence(host); host->power_mode = ios->power_mode; }