From patchwork Tue Sep 1 08:50:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 11747669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16AAE109B for ; Tue, 1 Sep 2020 08:50:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4E0A205CB for ; Tue, 1 Sep 2020 08:50:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="RoWkybLw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726078AbgIAIu2 (ORCPT ); Tue, 1 Sep 2020 04:50:28 -0400 Received: from mx1.tq-group.com ([62.157.118.193]:47171 "EHLO mx1.tq-group.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbgIAIu1 (ORCPT ); Tue, 1 Sep 2020 04:50:27 -0400 IronPort-SDR: DwCiWk1/MCA5CPbyQoI42uC+mUG7pJ2VLPGgjl+14SAA3fqvx5hrN7IUuC9NRKxW679rFZTwaC w0flCZ3LFo+YhkiBbVhSs6X4Aifox6uhr5KzTiz9P8pKydk+KJ2qfcKM2sdzrxkoT3oJhXimgC zr17ynR4yoyLtaSNq+QTslAVnfbf1lYRY3kAjOlVTGEME+ivDB8VsIqyub3mJcFMsayXrFtCQ8 288Vyl8ec5E5NwmQj99chjGv8ofvd4VZLkAldt7HjUZM9JkGpj61oBMTeaWMblFu+CkTncnHQT gcg= X-IronPort-AV: E=Sophos;i="5.76,378,1592863200"; d="scan'208";a="13677466" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 01 Sep 2020 10:50:24 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 01 Sep 2020 10:50:24 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 01 Sep 2020 10:50:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1598950224; x=1630486224; h=from:to:cc:subject:date:message-id; bh=Mu2xmjPdSJd4EA0jIUBhaOSiI9fbd+rNqRkizJUx3mI=; b=RoWkybLwVqaRleCcMOQXA3ux5W1Tz8SBqoFet7kmKyXCaQhUMzl7Z2kT KkP0P/0m3xou44eQy/O9aMb9YmFk8KdNOzEyJN8tOmS0saE5Dlzowp5SM 8cUAYg8Cxy+twFQ2pbBmrUud+O6exD4sm6RtjKhzI0ZD1Z8Alwr+M4Ome HpRn5NajzAovCHnEts8gd0ZiukVTRMTY43il7+m0dkOzT0rE2H76llOKW BhtMtfn5tSaPcwi9b01HucydlBETdtaK8y5q4qndBPs05yba7/UThIDrD rUrpaRTruGacO00UC3IFJKLNoNjvAnaopIgwAZ4Y/Smsh8k6sH1RGE80i A==; IronPort-SDR: 6WtvfxfqcFHIhjUrssWxYyY3OST7vbgXxy6Afa6CeOgbuhRvUYhV/kq1K71PIBZV6yoh3l7+N4 IHxqeJdRjbHmQG6ZIdyXCgZJSrHhmQLOqcFIAhYPlvb//8UCcoUXO2nyw4xSfASUyDyqI5CehY S87VWTN7loEr9fOyrOIXCDEfYWje20u2oYLsw7zpdErbEXVMBHgfIq4lfPuL2iUxeFZOZ5ThNU zr5ca2gByzyI0+NdG1VUthjxgTRItVDOr689RVo5cso2lO1z+VvPbkFq6IkhOrpcF6hVkGoHsi 9EA= X-IronPort-AV: E=Sophos;i="5.76,378,1592863200"; d="scan'208";a="13677465" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 01 Sep 2020 10:50:24 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.117.49.26]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 12855280065; Tue, 1 Sep 2020 10:50:24 +0200 (CEST) From: Matthias Schiffer To: Ulf Hansson , Rob Herring Cc: Sascha Hauer , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH mmc-next v4 1/2] dt-bindings: mmc: document alias support Date: Tue, 1 Sep 2020 10:50:03 +0200 Message-Id: <20200901085004.2512-1-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org As for I2C and SPI, it now is possible to reserve a fixed index for mmc/mmcblk devices. Signed-off-by: Matthias Schiffer --- v4: moved alias documentation from example to description v3: new patch Documentation/devicetree/bindings/mmc/mmc-controller.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/mmc/mmc-controller.yaml b/Documentation/devicetree/bindings/mmc/mmc-controller.yaml index b96da0c7f819..f928f66fc59a 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-controller.yaml +++ b/Documentation/devicetree/bindings/mmc/mmc-controller.yaml @@ -14,6 +14,10 @@ description: | that requires the respective functionality should implement them using these definitions. + It is possible to assign a fixed index mmcN to an MMC host controller + (and the corresponding mmcblkN devices) by defining an alias in the + /aliases device tree node. + properties: $nodename: pattern: "^mmc(@.*)?$" From patchwork Tue Sep 1 08:50:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 11747671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 892481575 for ; Tue, 1 Sep 2020 08:50:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B10D20866 for ; Tue, 1 Sep 2020 08:50:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="Jfr9Cnwh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725949AbgIAIuc (ORCPT ); Tue, 1 Sep 2020 04:50:32 -0400 Received: from mx1.tq-group.com ([62.157.118.193]:47171 "EHLO mx1.tq-group.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgIAIu3 (ORCPT ); Tue, 1 Sep 2020 04:50:29 -0400 IronPort-SDR: DntSZN5tGB4ASbg9nzfAw3YQJ+xIADwOOiv8/XVySIDrLfh5tTFgosz8kEAdlCfr6fzrCV1dlP 75cOHyv5u6tc/HdHQaNlonF7HeXlZ969m0/Mm2Ue5roqmdKFdujlzuRL5kXUDzqAIVFr7S1r/t d3b2hM7o+gJ1gNnQNuD2bVEjg4MOeFyKIrNWoT9HlwtsuXMPzP610wqX5ifuUqFM4KMbiwXlPM JYGRR8VoEDIrQNA/wVQycQGoVx7wP34pWI1ZuvLijGSgp988YFAZF8ywz++IBuBEpg/UvwNviv aRQ= X-IronPort-AV: E=Sophos;i="5.76,378,1592863200"; d="scan'208";a="13677468" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 01 Sep 2020 10:50:24 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 01 Sep 2020 10:50:24 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 01 Sep 2020 10:50:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1598950224; x=1630486224; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=F5d5x7a68Mh3YNvlXxZUiOS79u4ypZUgcPmdt4Ds/hM=; b=Jfr9CnwhvSf8sZxF/3/Vs+H0zhwmemAYQ65ebSxF2O7DzCeT7QDAmYaK cmRjZbexmBj7iAYyVgMVpPyrkCXAkKldPe4DpZyAOV0RuLkSSgfmZ9h95 V2dej/ypB/+d8qIOpybuknyLx+HfDQeR8ClX3+37yWS4zj3aTcvrP5T69 irRM/Z+NSXO2S0j46t3AoeTOVM7DOKAVXeDrzLuIBB4mzkCt4d0tolpv4 xPqGSxgni94SfQ3/sOexluOflGk5WLvahY15VJmpoxqdCSjApziRYV2AK +mls7Nn67JpPs5dW+Eo2ssu+9qWG5rVYnmrFMGeIohYO816jDzvIuVVNZ A==; IronPort-SDR: Z5fhJvCA+6HsG/4wH70+J6SxeVrpPa7O/CKZwE4AJxSOAc2ZTTh+OG/e6IRFaMtW12XqGi6Nwt PQdYMec6xxfMrCaVrUa4ow0jOJaj2OM59kGwh4m5ouTbMPK6PDCGARW3LGdoICio4HvSJHF1Tt 472M5ejoQ3Mv3hcUFDTl1VMsG/cdZZCa5bs7EcnWIwzMo0LT9bjwHRrGK/7xXSp1vI+llFi1nS A8XEBfa1+CXFb5pTSLJrL3u2/sqMbb8Zwj8ypcveduU8Zh/pi1MOBAl6UMcHTc8t23P1mnXGgY jkU= X-IronPort-AV: E=Sophos;i="5.76,378,1592863200"; d="scan'208";a="13677467" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 01 Sep 2020 10:50:24 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.117.49.26]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 3C04E280070; Tue, 1 Sep 2020 10:50:24 +0200 (CEST) From: Matthias Schiffer To: Ulf Hansson , Rob Herring Cc: Sascha Hauer , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH mmc-next v4 2/2] mmc: allow setting slot index via device tree alias Date: Tue, 1 Sep 2020 10:50:04 +0200 Message-Id: <20200901085004.2512-2-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200901085004.2512-1-matthias.schiffer@ew.tq-group.com> References: <20200901085004.2512-1-matthias.schiffer@ew.tq-group.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org As with GPIO, UART and others, allow specifying the device index via the aliases node in the device tree. On embedded devices, there is often a combination of removable (e.g. SD card) and non-removable MMC devices (e.g. eMMC). Therefore the index might change depending on * host of removable device * removable card present or not This makes it difficult to hardcode the root device, if it is on the non-removable device. E.g. if SD card is present eMMC will be mmcblk1, if SD card is not present at boot, eMMC will be mmcblk0. Alternative solutions like PARTUUIDs do not cover the case where multiple mmcblk devices contain the same image. This is a common issue on devices that can boot both from eMMC (for regular boot) and SD cards (as a temporary boot medium for development). When a firmware image is installed to eMMC after a test boot via SD card, there will be no reliable way to refer to a specific device using (PART)UUIDs oder LABELs. The demand for this feature has led to multiple attempts to implement it, dating back at least to 2012 (see https://www.spinics.net/lists/linux-mmc/msg26586.html for a previous discussion from 2014). All indices defined in the aliases node will be reserved for use by the respective MMC device, moving the indices of devices that don't have an alias up into the non-reserved range. If the aliases node is not found, the driver will act as before. This is a rebased and cleaned up version of https://www.spinics.net/lists/linux-mmc/msg26588.html . Based-on-patch-by: Sascha Hauer Link: https://lkml.org/lkml/2020/8/5/194 Signed-off-by: Matthias Schiffer --- v4: - minor adjustments to commit message v3: - remove unneeded mmcblock changes - remove most helper functions to simplify code - extended commit message v2: - fix missing symbols for modular mmcblock drivers/mmc/core/host.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index c8fae6611b73..96b2ca1f1b06 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -376,6 +376,20 @@ int mmc_of_parse_voltage(struct device_node *np, u32 *mask) } EXPORT_SYMBOL(mmc_of_parse_voltage); +/** + * mmc_first_nonreserved_index() - get the first index that is not reserved + */ +static int mmc_first_nonreserved_index(void) +{ + int max; + + max = of_alias_get_highest_id("mmc"); + if (max < 0) + return 0; + + return max + 1; +} + /** * mmc_alloc_host - initialise the per-host structure. * @extra: sizeof private data structure @@ -387,6 +401,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) { int err; struct mmc_host *host; + int alias_id, min_idx, max_idx; host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); if (!host) @@ -395,7 +410,16 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) /* scanning will be enabled when we're ready */ host->rescan_disable = 1; - err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL); + alias_id = of_alias_get_id(dev->of_node, "mmc"); + if (alias_id >= 0) { + min_idx = alias_id; + max_idx = alias_id + 1; + } else { + min_idx = mmc_first_nonreserved_index(); + max_idx = 0; + } + + err = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL); if (err < 0) { kfree(host); return NULL;