From patchwork Tue Dec 16 00:22:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 5498581 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 4B115BEEA8 for ; Tue, 16 Dec 2014 00:23:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B2DB20A14 for ; Tue, 16 Dec 2014 00:23:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49BE920A15 for ; Tue, 16 Dec 2014 00:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751441AbaLPAWa (ORCPT ); Mon, 15 Dec 2014 19:22:30 -0500 Received: from mail-ig0-f174.google.com ([209.85.213.174]:44332 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751429AbaLPAW3 (ORCPT ); Mon, 15 Dec 2014 19:22:29 -0500 Received: by mail-ig0-f174.google.com with SMTP id hn15so6012577igb.1 for ; Mon, 15 Dec 2014 16:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=Cx6mSvERagoZA7F6DgPUfS50G8m6xifa74KAuYXqjNA=; b=ZNqK2QbO4G9hwU9OQD34uibnjl6fCWg1ha0cqr//fClYxOeBbRxBFawWzXiqHBq8OF ePdJiD6xhLlxtNmWc7fcNVC4wbQFLMLdEcfERZnDQTYyfu3lxIsVhCqpbRfNrDQVwiwy E5yJAmazJgEf+fylESV1tgPZ1bW/R2X14g458= 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; bh=Cx6mSvERagoZA7F6DgPUfS50G8m6xifa74KAuYXqjNA=; b=AScysB/IWOd9G1wALT7da0f7p0npWlDRf+4du06wDTSMahkTPMYfKKNVZSxvAXxUxc p0zHdQPd/gA1AaMMyMwgTDruimFi4wP1uuU4yw4OT+0i5kFDNEE6MApPnjqHFKqA6Zkn dXyS3K3921UKuoZZxoFgl5wJF01jgChoAgihZJh7jX9qOnOczh0lhl6eieYsxV4Cr9ed uqzdyXHIXXU3QeUReeMcrGflvYhnwF5/O38It/QqAwk9KZK/vg2OvlaL6l42wRP7u7Kd 1DKFZwaUejQWscUzlHoCi0EZiCll9E/uWnmNZZhPfPjdZOfA0Xr6JoAUV4LGMfgu5TOm p22A== X-Gm-Message-State: ALoCoQkidQAYPIkQcqALC2b3diVsxVKm5+67GszOGe0r8AQAAEjLVtfOBPos5nU43jmaLKjLPhN5 X-Received: by 10.42.39.6 with SMTP id f6mr29649222ice.14.1418689348546; Mon, 15 Dec 2014 16:22:28 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id v83sm5434330iov.30.2014.12.15.16.22.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Dec 2014 16:22:28 -0800 (PST) From: Doug Anderson To: Ulf Hansson , Heiko Stuebner , Jaehoon Chung , Seungwon Jeon Cc: Mark Brown , Alexandru Stan , Alim Akhtar , Sonny Rao , Andrew Bresticker , linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Doug Anderson , chris@printf.net, johan.rudholm@axis.com, tim.kryger@gmail.com, andrew_gabbasov@mentor.com, adrian.hunter@intel.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] mmc: core: Add mmc_regulator_set_vqmmc() Date: Mon, 15 Dec 2014 16:22:18 -0800 Message-Id: <1418689340-29517-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable 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 This adds logic to the MMC core to set VQMMC. This is expected to be called by MMC drivers like dw_mmc as part of (or instead of) their start_signal_voltage_switch() callback. A few notes: * When setting the signal voltage to 3.3V we do our best to make VQMMC and VMMC match. It's been reported that this makes some old cards happy since they were tested back in the day before UHS when VQMMC and VMMC were provided by the same regulator. A nice side effect of this is that we don't end up on the hairy edge of VQMMC (2.7V), which some EEs claim is a little too close to the minimum for comfort. * When setting the signal voltage to 1.8V or 1.2V we aim for that specific voltage instead of picking the lowest one in the range. * We very purposely don't print errors in mmc_regulator_set_vqmmc(). There are cases where the MMC core will try several different voltages and we don't want to pollute the logs. Signed-off-by: Doug Anderson Reviewed-by: Andrew Bresticker --- Changes in v3: None Changes in v2: - Now use existing regulator_set_voltage_tol() function. drivers/mmc/core/core.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 7 +++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 9584bff..670dc65 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1333,6 +1333,57 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, } EXPORT_SYMBOL_GPL(mmc_regulator_set_ocr); +static int mmc_regulator_set_voltage_if_supported(struct regulator *regulator, + int new_uV, int tol_uV) +{ + /* + * Check if supported first to avoid errors since we may try several + * signal levels during power up and don't want to show errors. + */ + if (!regulator_is_supported_voltage_tol(regulator, new_uV, tol_uV)) + return -EINVAL; + + return regulator_set_voltage_tol(regulator, new_uV, tol_uV); +} + +/** + * mmc_regulator_set_vqmmc - Set VQMMC as per the ios + * + * For 3.3V signaling, we try to match VQMMC to VMMC as closely as possible. + * That will match the behavior of old boards where VQMMC and VMMC were supplied + * by the same supply. The Bus Operating conditions for 3.3V signaling in the + * SD card spec also define VQMMC in terms of VMMC. + * + * For 1.2V and 1.8V signaling we'll try to get as close as possible to the + * requested voltage. This is definitely a good idea for UHS where there's a + * separate regulator on the card that's trying to make 1.8V and it's best if + * we match. + * + * This function is expected to be used by a controller's + * start_signal_voltage_switch() function. + */ +int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) +{ + /* If no vqmmc supply then we can't change the voltage */ + if (IS_ERR(mmc->supply.vqmmc)) + return -EINVAL; + + switch (ios->signal_voltage) { + case MMC_SIGNAL_VOLTAGE_120: + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + 1200000, 100000); + case MMC_SIGNAL_VOLTAGE_180: + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + 1800000, 100000); + case MMC_SIGNAL_VOLTAGE_330: + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + regulator_get_voltage(mmc->supply.vmmc), 300000); + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); + #endif /* CONFIG_REGULATOR */ int mmc_regulator_get_supply(struct mmc_host *mmc) diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 9f32270..524d6fc 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -416,6 +416,7 @@ int mmc_regulator_get_ocrmask(struct regulator *supply); int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, unsigned short vdd_bit); +int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios); #else static inline int mmc_regulator_get_ocrmask(struct regulator *supply) { @@ -428,6 +429,12 @@ static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, { return 0; } + +static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, + struct mmc_ios *ios) +{ + return -EINVAL; +} #endif int mmc_regulator_get_supply(struct mmc_host *mmc);