From patchwork Mon Jul 29 02:56:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haijun.Zhang@freescale.com X-Patchwork-Id: 2834761 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 A70E2C0319 for ; Mon, 29 Jul 2013 03:49:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FE482012D for ; Mon, 29 Jul 2013 03:49:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B55AC20125 for ; Mon, 29 Jul 2013 03:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752722Ab3G2DtW (ORCPT ); Sun, 28 Jul 2013 23:49:22 -0400 Received: from mail-db9lp0251.outbound.messaging.microsoft.com ([213.199.154.251]:42578 "EHLO db9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752631Ab3G2DtV (ORCPT ); Sun, 28 Jul 2013 23:49:21 -0400 Received: from mail76-db9-R.bigfish.com (10.174.16.233) by DB9EHSOBE004.bigfish.com (10.174.14.67) with Microsoft SMTP Server id 14.1.225.22; Mon, 29 Jul 2013 03:49:20 +0000 Received: from mail76-db9 (localhost [127.0.0.1]) by mail76-db9-R.bigfish.com (Postfix) with ESMTP id 0681930007C; Mon, 29 Jul 2013 03:49:20 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 1 X-BigFish: VS1(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzd2iz1de098h8275bh1de097hz2dh2a8h668h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1155h) Received: from mail76-db9 (localhost.localdomain [127.0.0.1]) by mail76-db9 (MessageSwitch) id 1375069727469099_22077; Mon, 29 Jul 2013 03:48:47 +0000 (UTC) Received: from DB9EHSMHS003.bigfish.com (unknown [10.174.16.230]) by mail76-db9.bigfish.com (Postfix) with ESMTP id 641B6140057; Mon, 29 Jul 2013 03:48:47 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB9EHSMHS003.bigfish.com (10.174.14.13) with Microsoft SMTP Server (TLS) id 14.16.227.3; Mon, 29 Jul 2013 03:48:42 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.3.136.1; Mon, 29 Jul 2013 03:48:40 +0000 Received: from rock.am.freescale.net (rock.ap.freescale.net [10.193.20.106]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id r6T3malJ012312; Sun, 28 Jul 2013 20:48:37 -0700 From: Haijun Zhang To: , CC: , , , , Haijun Zhang , Haijun Zhang Subject: [PATCH 1/3] mmc:core: parse voltage from device-tree Date: Mon, 29 Jul 2013 10:56:33 +0800 Message-ID: <1375066595-14968-1-git-send-email-Haijun.Zhang@freescale.com> X-Mailer: git-send-email 1.8.0 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-8.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 Add function to support get voltage from device-tree. If there are voltage-range specified in device-tree node, this function will parse it and return the avail voltage mask. Signed-off-by: Haijun Zhang --- drivers/mmc/core/core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/core.h | 1 + 2 files changed, 49 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 49a5bca..217cd42 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1196,6 +1197,53 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max) } EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); +#ifdef CONFIG_OF + +/* + * mmc_of_parse_voltage - return mask of supported voltages + * @host: host whose node should be parsed. + * + * 1. Return zero: voltage-ranges unspecified in device-tree. + * 2. Return negative errno: voltage-range is invalid. + * 3. Return ocr_mask: a mask of voltages that parse from device-tree + * node can be provided to MMC/SD/SDIO devices. + */ + +u32 mmc_of_parse_voltage(struct mmc_host *host) +{ + const u32 *voltage_ranges; + int num_ranges, i; + struct device_node *np; + u32 ocr_mask = 0; + + np = host->parent->of_node; + voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); + num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; + if (!voltage_ranges || !num_ranges) { + dev_info(host->parent, "OF: voltage-ranges unspecified\n"); + return 0; + } + + for (i = 0; i < num_ranges; i++) { + const int j = i * 2; + u32 mask; + + mask = mmc_vddrange_to_ocrmask(be32_to_cpu(voltage_ranges[j]), + be32_to_cpu(voltage_ranges[j + 1])); + if (!mask) { + dev_err(host->parent, + "OF: voltage-range #%d is invalid\n", i); + return -EINVAL; + } + ocr_mask |= mask; + } + + return ocr_mask; +} +EXPORT_SYMBOL(mmc_of_parse_voltage); + +#endif /* CONFIG_OF */ + #ifdef CONFIG_REGULATOR /** diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 443243b..107375c 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -209,5 +209,6 @@ static inline void mmc_claim_host(struct mmc_host *host) } extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max); +extern u32 mmc_of_parse_voltage(struct mmc_host *host); #endif /* LINUX_MMC_CORE_H */