From patchwork Tue Apr 1 20:35:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 3925551 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 38DE9BF540 for ; Tue, 1 Apr 2014 20:42:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2891B203DB for ; Tue, 1 Apr 2014 20:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 41645203B8 for ; Tue, 1 Apr 2014 20:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751855AbaDAUmw (ORCPT ); Tue, 1 Apr 2014 16:42:52 -0400 Received: from mail.kmu-office.ch ([178.209.48.102]:43925 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751476AbaDAUmw (ORCPT ); Tue, 1 Apr 2014 16:42:52 -0400 X-Greylist: delayed 407 seconds by postgrey-1.27 at vger.kernel.org; Tue, 01 Apr 2014 16:42:52 EDT Received: from localhost (localhost [127.0.0.1]) by mail.kmu-office.ch (Postfix) with ESMTP id 24775416CF; Tue, 1 Apr 2014 22:32:35 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kmu-office.ch Received: from mail.kmu-office.ch ([127.0.0.1]) by localhost (mail.kmu-office.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xUMmR6G71DGT; Tue, 1 Apr 2014 22:32:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.kmu-office.ch (Postfix) with ESMTP id 21BF8416D1; Tue, 1 Apr 2014 22:32:32 +0200 (CEST) Received: from luegisland.agner.local (195-226-23-140.pool.cyberlink.ch [195.226.23.140]) (Authenticated sender: stefan@agner.ch) by mail.kmu-office.ch (Postfix) with ESMTPSA id B1208416C8; Tue, 1 Apr 2014 22:32:31 +0200 (CEST) From: stefan@agner.ch To: chris@printf.net, linux-mmc@vger.kernel.org Cc: linux-tegra@vger.kernel.org, linux@arm.linux.org.uk, linux-kernel@vger.kernel.org, stefan@agner.ch Subject: [RFC 1/2] mmc: read mmc alias from device tree Date: Tue, 1 Apr 2014 22:35:51 +0200 Message-Id: <5570bdf5ebb3aaae5a376634ecfbac9c2fd7b9f4.1396384101.git.stefan@agner.ch> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 From: Stefan Agner To get the SD/MMC host device ID, read the alias from the device tree. This is useful in case a SoC has multipe SD/MMC host controllers while the second controller should logically be the first device (e.g. if the second controller is connected to an internal eMMC). Combined with block device numbering using MMC/SD host device ID, this results in predictable name assignment of the internal eMMC block device. Signed-off-by: Stefan Agner Reviewed-by: Doug Anderson Tested-by: Doug Anderson --- drivers/mmc/core/host.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 49bc403..29f44cf 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -448,8 +448,8 @@ EXPORT_SYMBOL(mmc_of_parse); */ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) { - int err; struct mmc_host *host; + int of_id = -1, id = -1; host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); if (!host) @@ -459,12 +459,26 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) host->rescan_disable = 1; idr_preload(GFP_KERNEL); spin_lock(&mmc_host_lock); - err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT); - if (err >= 0) - host->index = err; + + if (dev->of_node) + of_id = of_alias_get_id(dev->of_node, "mmc"); + + if (of_id >= 0) { + id = idr_alloc(&mmc_host_idr, host, of_id, of_id + 1, + GFP_NOWAIT); + if (id < 0) + dev_warn(dev, "/aliases ID %d not available\n", of_id); + } + + if (id < 0) + id = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT); + + if (id >= 0) + host->index = id; + spin_unlock(&mmc_host_lock); idr_preload_end(); - if (err < 0) + if (id < 0) goto free; dev_set_name(&host->class_dev, "mmc%d", host->index);