From patchwork Tue Nov 2 00:05:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Panizzo X-Patchwork-Id: 296202 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 oA205isA024760 for ; Tue, 2 Nov 2010 00:05:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752693Ab0KBAFn (ORCPT ); Mon, 1 Nov 2010 20:05:43 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:33653 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751069Ab0KBAFm (ORCPT ); Mon, 1 Nov 2010 20:05:42 -0400 Received: by wyf28 with SMTP id 28so6084568wyf.19 for ; Mon, 01 Nov 2010 17:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=4vSi8/45XVzZKoeVhuRRn5eeW+xINzCiZHa88fNoGM8=; b=X/JrXGNWp04aaD7H6ahRVO37FoLYawXAzXeO2yr5a5sEom4CjuZlaTHpqdgzg2gVBN ZD25TweMiq+qikmcQQzlLpXY2L6aXf3V+jqXRmxJQQmJJpxQ8yMuY8o7c55vIsg23UW6 Gb25OQjaU03e2xzJFdgixDiHd+yRD+mzZDchs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=D5THZ4X36SqF0vUV/XVJY6pOHNho7KrjJV/veoXo8sjDf12HpdyAMWwRtIKiqkKZTQ fhfAem5pVQh2p49LuJnMXe6LS9z+0GmvuopLUWnpag1FKhfFL90UfR9F2UUtZ3bFpKcI xErm6O+ITMGUuKgGsFJKsLWOFS31q8+IchbL4= Received: by 10.227.147.194 with SMTP id m2mr3243454wbv.105.1288656341131; Mon, 01 Nov 2010 17:05:41 -0700 (PDT) Received: from [192.168.1.101] (host-9473-86-114.popwifi.it [94.73.86.114]) by mx.google.com with ESMTPS id f14sm5719842wbe.2.2010.11.01.17.05.38 (version=SSLv3 cipher=RC4-MD5); Mon, 01 Nov 2010 17:05:39 -0700 (PDT) Subject: [PATCH] mxcmmc: Add the ability to bind a regulator to manage the MMC card voltage From: Alberto Panizzo To: Sascha Hauer Cc: Daniel Mack , Andrew Morton , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Eric =?ISO-8859-1?Q?B=E9nard?= , Fabio Estevam , linux-kernel , linux-mmc Date: Tue, 02 Nov 2010 01:05:37 +0100 Message-ID: <1288656337.29881.13.camel@realization> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 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]); Tue, 02 Nov 2010 00:05:45 +0000 (UTC) diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c index 350f78e..e4637fc 100644 --- a/drivers/mmc/host/mxcmmc.c +++ b/drivers/mmc/host/mxcmmc.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -141,10 +142,45 @@ struct mxcmci_host { struct work_struct datawork; spinlock_t lock; + + struct regulator *vcc; }; static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios); +static inline void mxcmci_init_ocr(struct mxcmci_host *host) +{ +#ifdef CONFIG_REGULATOR + host->vcc = regulator_get(mmc_dev(host->mmc), "vmmc"); + + if (IS_ERR(host->vcc)) { + host->vcc = NULL; + } else { + host->mmc->ocr_avail = mmc_regulator_get_ocrmask(host->vcc); + if (host->pdata && host->pdata->ocr_avail) + dev_warn(mmc_dev(host->mmc), + "pdata->ocr_avail will not be used\n"); + } +#endif + if (host->vcc == NULL) { + /* fall-back to platform data */ + if (host->pdata && host->pdata->ocr_avail) + host->mmc->ocr_avail = host->pdata->ocr_avail; + else + host->mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; + } +} + +static inline void mxcmci_set_power(struct mxcmci_host *host, unsigned int vdd) +{ +#ifdef CONFIG_REGULATOR + if (host->vcc) + mmc_regulator_set_ocr(host->vcc, vdd); +#endif + if (host->pdata && host->pdata->setpower) + host->pdata->setpower(mmc_dev(host->mmc), vdd); +} + static inline int mxcmci_use_dma(struct mxcmci_host *host) { return host->do_dma; @@ -680,9 +716,9 @@ static void mxcmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) host->cmdat &= ~CMD_DAT_CONT_BUS_WIDTH_4; if (host->power_mode != ios->power_mode) { - if (host->pdata && host->pdata->setpower) - host->pdata->setpower(mmc_dev(mmc), ios->vdd); + mxcmci_set_power(host, ios->vdd); host->power_mode = ios->power_mode; + if (ios->power_mode == MMC_POWER_ON) host->cmdat |= CMD_DAT_CONT_INIT; } @@ -808,10 +844,7 @@ static int mxcmci_probe(struct platform_device *pdev) host->pdata = pdev->dev.platform_data; spin_lock_init(&host->lock); - if (host->pdata && host->pdata->ocr_avail) - mmc->ocr_avail = host->pdata->ocr_avail; - else - mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; + mxcmci_init_ocr(host); if (host->pdata && host->pdata->dat3_card_detect) host->default_irq_mask = @@ -916,6 +949,9 @@ static int mxcmci_remove(struct platform_device *pdev) mmc_remove_host(mmc); + if (host->vcc) + regulator_put(host->vcc); + if (host->pdata && host->pdata->exit) host->pdata->exit(&pdev->dev, mmc);