From patchwork Thu Aug 29 16:39:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 2851513 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E6CABF546 for ; Thu, 29 Aug 2013 16:39:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4BA3F20451 for ; Thu, 29 Aug 2013 16:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 056E22045A for ; Thu, 29 Aug 2013 16:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755152Ab3H2QjU (ORCPT ); Thu, 29 Aug 2013 12:39:20 -0400 Received: from mail-qa0-f74.google.com ([209.85.216.74]:47949 "EHLO mail-qa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754240Ab3H2QjS (ORCPT ); Thu, 29 Aug 2013 12:39:18 -0400 Received: by mail-qa0-f74.google.com with SMTP id i13so86577qae.5 for ; Thu, 29 Aug 2013 09:39:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NTk/poGJhHt8z94MNhH1MJN7nid/LYuyrF21zLsybb4=; b=HG7ZiUG4S9lVck9z1PEfgBr1SEg7oDSK1+B3bUOF0+07KONqJCUM246KOtAo3WjAcO fKOg/tGh3D2RqfTlbAQjL43lhUYZuU2KwUnx/A9i5SuW3mdBcCQkCeI1k+2+Wd1LuWl5 ovwgSqDLgCOD7F8kci+jbLDQ3KH5Pc8njQwaokLgVHzJ9W/yPbd9dtjGr9Ou1ofAjPy4 IoSGXZBUBVn8SsqRgi6Co5ZemhKmpq0IbFtnVbjvGRFbEaEYzN5Q9TqoybAyjIk6LVo3 x9hIBWWRKvT0MJO595WkQWriu2+h5t14VZx/+k/oDyvgzzZO2lhudnhIja711sgIBemH tm8w== X-Gm-Message-State: ALoCoQlVejhkiYKdeqaJFm3VK8F6BLMeKYBqNM+1eBJ0iLfQ/XhmApc/66XsF4gHPMl1+5tCzY4JUD3WlJQny6Uk5/iuniV46UGT1FgotmxvG8KVF9ghTrNBzcxuQPmbqcU3WI+ndikXE7Om/EEyXKN6L9OFHb/BBnf7/iv4HIN4LKD1pM1NTesV+wIoF0mC3+sTa932GtM01mQYfXWPuIdujOdUUQaoIg== X-Received: by 10.236.68.193 with SMTP id l41mr1589043yhd.19.1377794357744; Thu, 29 Aug 2013 09:39:17 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id a42si1970318yhj.6.1969.12.31.16.00.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Thu, 29 Aug 2013 09:39:17 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.72.141]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 722E531C00D; Thu, 29 Aug 2013 09:39:17 -0700 (PDT) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 2310780A33; Thu, 29 Aug 2013 09:39:17 -0700 (PDT) From: Doug Anderson To: Chris Ball Cc: Jaehoon Chung , Seungwon Jeon , James Hogan , Grant Grundler , Alim Akhtar , Abhilash Kesavan , Tomasz Figa , Olof Johansson , Doug Anderson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/3] mmc: dw_mmc: Honor requests to set the clock to 0 (turn off clock) Date: Thu, 29 Aug 2013 09:39:09 -0700 Message-Id: <1377794350-12335-3-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1377794350-12335-1-git-send-email-dianders@chromium.org> References: <1377188348-3418-1-git-send-email-dianders@chromium.org> <1377794350-12335-1-git-send-email-dianders@chromium.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously the dw_mmc driver would ignore any requests to disable the card's clock. This doesn't seem like a good thing in general, but had one extra bad side effect in the following situtation: * mmc core would set clk to 400kHz at boot time while initting * mmc core would set clk to 0 since no card, but it would be ignored. * suspend to ram and resume; clocks in the dw_mmc IP block are now 0 but dw_mmc thinks that they're 400kHz (it ignored the set to 0). * insert card * mmc core would set clk to 400kHz which would be considered a no-op. Note that if there is no card in the slot and we do a suspend/resume cycle, we _do_ still end up with differences in a dw_mmc register dump, but the differences are clock related and we've got the clock disabled both before and after, so this should be OK. Signed-off-by: Doug Anderson --- Changes in v7: - Avoid printing the same clock over and over again w/ MMC_CLKGATE. Changes in v6: - Replaces previous pathes that ensured saving/restoring clocks. drivers/mmc/host/dw_mmc.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index ee5f167..1584705 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -88,6 +88,8 @@ struct idmac_desc { * @queue_node: List node for placing this node in the @queue list of * &struct dw_mci. * @clock: Clock rate configured by set_ios(). Protected by host->lock. + * @last_printed_clock: The last clock we printed. Keeping track of this helps + * us to avoid spamming the console with CONFIG_MMC_CLKGATE. * @flags: Random state bits associated with the slot. * @id: Number of this slot. * @last_detect_state: Most recently observed card detect state. @@ -105,6 +107,7 @@ struct dw_mci_slot { struct list_head queue_node; unsigned int clock; + unsigned int last_printed_clock; unsigned long flags; #define DW_MMC_CARD_PRESENT 0 #define DW_MMC_CARD_NEED_INIT 1 @@ -635,7 +638,11 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) u32 div; u32 clk_en_a; - if (slot->clock != host->current_speed || force_clkinit) { + if (slot->clock == 0) { + mci_writel(host, CLKENA, 0); + mci_send_cmd(slot, + SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); + } else if (slot->clock != host->current_speed || force_clkinit) { div = host->bus_hz / slot->clock; if (host->bus_hz % slot->clock && host->bus_hz > slot->clock) /* @@ -646,10 +653,14 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0; - dev_info(&slot->mmc->class_dev, - "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" - " div = %d)\n", slot->id, host->bus_hz, slot->clock, - div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div); + if (slot->clock != slot->last_printed_clock || force_clkinit) { + dev_info(&slot->mmc->class_dev, + "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n", + slot->id, host->bus_hz, slot->clock, + div ? ((host->bus_hz / div) >> 1) : + host->bus_hz, div); + slot->last_printed_clock = slot->clock; + } /* disable clock */ mci_writel(host, CLKENA, 0); @@ -675,9 +686,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) /* inform CIU */ mci_send_cmd(slot, SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); - - host->current_speed = slot->clock; } + host->current_speed = slot->clock; /* Set the current slot bus width */ mci_writel(host, CTYPE, (slot->ctype << slot->id)); @@ -807,13 +817,11 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) mci_writel(slot->host, UHS_REG, regs); - if (ios->clock) { - /* - * Use mirror of ios->clock to prevent race with mmc - * core ios update when finding the minimum. - */ - slot->clock = ios->clock; - } + /* + * Use mirror of ios->clock to prevent race with mmc + * core ios update when finding the minimum. + */ + slot->clock = ios->clock; if (drv_data && drv_data->set_ios) drv_data->set_ios(slot->host, ios);