From patchwork Fri Apr 5 08:33:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Liu X-Patchwork-Id: 2397151 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7BDD83FD8C for ; Fri, 5 Apr 2013 08:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751345Ab3DEIdo (ORCPT ); Fri, 5 Apr 2013 04:33:44 -0400 Received: from mail-ob0-f179.google.com ([209.85.214.179]:64011 "EHLO mail-ob0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750837Ab3DEIdm (ORCPT ); Fri, 5 Apr 2013 04:33:42 -0400 Received: by mail-ob0-f179.google.com with SMTP id vb8so3471125obc.10 for ; Fri, 05 Apr 2013 01:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type; bh=OFtzKA5XyslXrnupzSgq8GdqzvhRgU6nGPIHO8CCfEw=; b=RjaH20yxnauWHXYvWhmwpcHpdqxTohyHSSWUtZpY03oC2wR0/otVdujBHMxB/mqRKk 9TeopX+EDuQ6jsTZR/IsXHw765LvWyszN5qzD0h8Bq25m+iEYZaZbLGNUyGqSU4D10IJ XGjTzWTMKQ07Lx9tvYi20q7rBOcSwt0zH601zTbpX2+W2ZrwhzoEL8NgF3NfF6VryYPT 42gzrKlHCGbJkgfk2Css2g0pJK1hu42mZwgtUe3Y6I+OYtpwi0rQ11cYItWtuLHgiZZU uwTnQ5gMX2EFkigZjMmQQLRLftkeSvqr2mBsfqKLHkwJk8LEmkXz22rw/bl9Picvv4GZ OOrw== MIME-Version: 1.0 X-Received: by 10.60.27.66 with SMTP id r2mr7378851oeg.139.1365150822433; Fri, 05 Apr 2013 01:33:42 -0700 (PDT) Received: by 10.60.37.194 with HTTP; Fri, 5 Apr 2013 01:33:42 -0700 (PDT) Date: Fri, 5 Apr 2013 16:33:42 +0800 Message-ID: Subject: Re: core: negotiate ocr during resume From: Kevin Liu To: Prasanna NAVARATNA Cc: "linux-mmc@vger.kernel.org" Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org > -----Original Message----- > From: linux-mmc-owner@vger.kernel.org [mailto:linux-mmc-owner@vger.kernel.org] On Behalf Of Prasanna NAVARATNA > Sent: Thursday, April 04, 2013 10:35 PM > To: linux-mmc@vger.kernel.org > Subject: mmc: core: negotiate ocr during resume > > From f43005e05f1e9d93705ec6b3ab98cfa5215c1896 Mon Sep 17 00:00:00 2001 > From: Prasanna NAVARATNA > Date: Thu, 4 Apr 2013 19:55:19 +0530 > Subject: [PATCH] mmc: core: negotiate ocr during resume > > Save the card ocr into struct mmc_card when read from sd card and > negotiate ocr mask during mmc_sd_init_card with host->ocr & card->ocr. > --- > drivers/mmc/core/sd.c | 7 +++++++ > include/linux/mmc/card.h | 1 + > 2 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c > index 9e645e1..8ee27e8 100644 > --- a/drivers/mmc/core/sd.c > +++ b/drivers/mmc/core/sd.c > @@ -910,6 +910,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 > ocr, > BUG_ON(!host); > WARN_ON(!host->claimed); > > + /* Negotiate OCR with oldcard->ocr */ > + if (oldcard) > + ocr &= oldcard->ocr; > + I think there are several issues here: 1. with this patch the vmmc voltage should still be 3.3v after resume back since the vmmc voltage is updated in set_ios which depend on mmc_select_voltage. But mmc_select_voltage didn't notice your ocr update. 2. you didn't handle the special case that the card is changed to a new card during suspended. So the ocr may be different here. 3. mmc.c and sdio.c should also be updated besides sd.c. I have another old version of this patch attached below for your reference: Thanks Kevin > err = mmc_sd_get_cid(host, ocr, cid, &rocr); > if (err) > return err; > @@ -1185,6 +1189,9 @@ int mmc_attach_sd(struct mmc_host *host) > ocr &= ~MMC_VDD_165_195; > } > > + /* Save the card OCR */ > + host->card->ocr = ocr; > + > host->ocr = mmc_select_voltage(host, ocr); > > /* > diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h > index f31725b..1bbec2f 100644 > --- a/include/linux/mmc/card.h > +++ b/include/linux/mmc/card.h > @@ -273,6 +273,7 @@ struct mmc_card { > u32 raw_cid[4]; /* raw card CID */ > u32 raw_csd[4]; /* raw card CSD */ > u32 raw_scr[2]; /* raw card SCR */ > + u32 ocr; /* card OCR */ > struct mmc_cid cid; /* card identification */ > struct mmc_csd csd; /* card specific */ > struct mmc_ext_csd ext_csd; /* mmc v4 extended card > specific */ > -- > 1.7.6 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-mmc" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html --- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index aaed768..f3c7b33 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1351,6 +1351,7 @@ void mmc_power_off(struct mmc_host *host) * Reset ocr mask to be the highest possible voltage supported for * this mmc host. This value will be used at next power up. */ + host->ocr_bak = host->ocr; host->ocr = 1 << (fls(host->ocr_avail) - 1); if (!mmc_host_is_spi(host)) { @@ -2491,7 +2492,6 @@ int mmc_resume_host(struct mmc_host *host) if (host->bus_ops && !host->bus_dead) { if (!mmc_card_keep_power(host)) { mmc_power_up(host); - mmc_select_voltage(host, host->ocr); /* * Tell runtime PM core we just powered up the card, * since it still believes the card is powered off. diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index e6e3911..a8e81d2 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -882,7 +882,9 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, err = -ENOENT; goto err; } - + /* restore ocr for the same card */ + if (host->ocr_bak && (host->ocr_bak != host->ocr)) + host->ocr = mmc_select_voltage(host, host->ocr_bak); card = oldcard; } else { /* diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 3dafb54..2eea1ae 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -908,7 +908,9 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, if (oldcard) { if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) return -ENOENT; - + /* restore ocr for the same card */ + if (host->ocr_bak && (host->ocr_bak != host->ocr)) + host->ocr = mmc_select_voltage(host, host->ocr_bak); card = oldcard; } else { /* diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 2273ce6..f66cc9a 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -594,6 +594,11 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, err = mmc_send_io_op_cond(host, host->ocr, &ocr); if (err) goto err; + if (oldcard) { + /* restore ocr for the same card */ + if (host->ocr_bak && (host->ocr_bak != host->ocr)) + host->ocr = mmc_select_voltage(host, host->ocr_bak); + } } /* diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index a90ea7b..ae5533e 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -285,6 +285,7 @@ struct mmc_host { struct mmc_ios ios; /* current io bus settings */ u32 ocr; /* the current OCR setting */ + u32 ocr_bak; /* save current OCR setting */ /* group bitfields together to minimize padding */ unsigned int use_spi_crc:1;