From patchwork Tue Aug 25 13:44:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 11735745 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 D8DD7722 for ; Tue, 25 Aug 2020 13:46:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFBCA20738 for ; Tue, 25 Aug 2020 13:46:11 +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="N1MxhvFB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726672AbgHYNp6 (ORCPT ); Tue, 25 Aug 2020 09:45:58 -0400 Received: from mx1.tq-group.com ([62.157.118.193]:40528 "EHLO mx1.tq-group.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbgHYNpx (ORCPT ); Tue, 25 Aug 2020 09:45:53 -0400 IronPort-SDR: EWepCS+1mazOO+d5eLqNjy3LCf4T4rGNVIZfE5RnWj3/mC2fy6VwcCarTx4PlRW7xqYxs4CTPD x80tyrxo8qkNz+DY8xVh2QFvDzdlAhbVa43SSt5g6n1B6UTgYOhmw21wQeYNGe1KMsRjejO8Fb d9d8RwdDrPJz5AxUt3C6NrZ3yU/gNET2YTixcYyHJjYgwOtC2GEdHiMED8760kPj6RmZnhjpjG O6Vj+s51HhXAvLFL4atetCaB0RusqjKtnML2e9MoWcTREqNWpj2LLoPRNCjPIdJC8KzJoIGj7g QIs= X-IronPort-AV: E=Sophos;i="5.76,352,1592863200"; d="scan'208";a="13592257" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 25 Aug 2020 15:45:34 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 25 Aug 2020 15:45:34 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 25 Aug 2020 15:45:34 +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=1598363134; x=1629899134; h=from:to:cc:subject:date:message-id; bh=fUqsPE/ZO4LWYoE8Q40E9k79iF8jdqLY6H5vK/D03uU=; b=N1MxhvFBkHSgLoGTAkYNUnrzhNL2SLQIPQaUmt1EpiBJhtMP9HiTRPto Y2qbpaWRZKtKM1AkgGNdZlFOLRQeGH6Z9MwW/yq6A7wi3JJ/Mn7Jx2JDX loGCItdOZnJwfy5hEqp6WsTWpg5kp+jir/k+a2vp7PvcrQpGfmVfdmpQd pueFlhDZQ7oPL5gQCLH/HNp9+LlOaJyd9QVtsHDRvAUkXBKYdD0mpRpIP CsebwOAEMcEpWeVsPapwvKn2LyFEEEhsUOEF9GCfmSH2pTz8WWZdKjx8Q pY+6+HAkdLJvjd7Y2q5ydTvpgbze+6rqZPE8KIBfH5mIGTzuVydzhU4bR A==; IronPort-SDR: T2F+3bqy5rZURdVPnteiUoZlsLwR7+OAK9TaRMfSCf3g99BUQOIVMLEFNQBnxLRx6covkVmJ8F L8fSAClNtpW+amrJ7JA80xz0KKAV3tt0JhPKdVKMSg44qp6BuxD+GWJGilfNGUbiqlxCxuREGK pG6y41bO1TUk51ontoPE7lywW2c9TJZKKS+utz39F5e3QcnFF/VoaIkU7S8vptiXampI1z1DXd nHm1qawYEaVwD/yGWA8vbcksMGTJQxiW2IyUiw8PKStaM+6Y4o14+eWSYzN9Qe3ospvV07VwsA zKY= X-IronPort-AV: E=Sophos;i="5.76,352,1592863200"; d="scan'208";a="13592256" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 25 Aug 2020 15:45:34 +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 7E1E9280065; Tue, 25 Aug 2020 15:45:34 +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 v3 1/2] dt-bindings: mmc: add alias example Date: Tue, 25 Aug 2020 15:44:40 +0200 Message-Id: <20200825134441.17537-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 --- v3: new patch Documentation/devicetree/bindings/mmc/mmc-controller.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/mmc/mmc-controller.yaml b/Documentation/devicetree/bindings/mmc/mmc-controller.yaml index b96da0c7f819..22ed4a36c65d 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-controller.yaml +++ b/Documentation/devicetree/bindings/mmc/mmc-controller.yaml @@ -367,6 +367,14 @@ examples: }; - | + /* + * Optionally define an alias to reserve a fixed index for the + * mmc and mmcblk devices + */ + aliases { + mmc0 = &mmc3; + }; + mmc3: mmc@1c12000 { #address-cells = <1>; #size-cells = <0>; From patchwork Tue Aug 25 13:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 11735747 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 F3A02913 for ; Tue, 25 Aug 2020 13:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC2C12075F for ; Tue, 25 Aug 2020 13:46:13 +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="Z/1Jlk7M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726790AbgHYNqK (ORCPT ); Tue, 25 Aug 2020 09:46:10 -0400 Received: from mx1.tq-group.com ([62.157.118.193]:40528 "EHLO mx1.tq-group.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726222AbgHYNp6 (ORCPT ); Tue, 25 Aug 2020 09:45:58 -0400 IronPort-SDR: kDSN0DkYWghQWgQQkhZGvNtgXF/NABg78EzK4u2OZtqgeHwO06ZQsN2Qu0sk1HHyix1x+LUn+T LUm4qvzMRbkE8grGO7DJ5xpsrRUSrr0JY7DjFGRBSfwg/VL2uOIRbxBVEQ6qu0xaNyflxmA5QK VBAxv80SCTBVZ2l/rHeU1DhWJn7qeEoIv0LjMXzWNgmpWyxHtgofKRAyA/g3LYAMQzTUHq4Doc hzRFmEV9EUAlx22LNB2vzqEsnbCd5Xpb3fTmGGQTEkoeiyHPAPD1H8IAhyki0nb6PZWh0ni3K9 TdY= X-IronPort-AV: E=Sophos;i="5.76,352,1592863200"; d="scan'208";a="13592259" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 25 Aug 2020 15:45:34 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 25 Aug 2020 15:45:34 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 25 Aug 2020 15:45:34 +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=1598363134; x=1629899134; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Kf6ual87ynJDYkTPylmWVOktoJJ6W4UH22mbaq4n/Kc=; b=Z/1Jlk7MXlCJplMtcnE+rXN7G13o8aSYcEhQIJLODmj1oBpKALnGpTGt qupiHrbqX+h1Az+Fn20ppLOqoTJ61/G0kvN5BLkyS5ZGP/nR8qiBt4yuZ rDjGSkKXiesZ7JQy3jE1uprJiGowiTbZ05RXAnMpxOoeyimjK03OTBNwT lGXhnqTM5M+5IE2UkcSZJSF3wEpGckzkffCtECo3PkOEdJwjwxtvjQAj7 Y9lZS2lXPoXqqSLyx2SWIk/JAOqvQRSyaEcGLMS81zO6P4jUu0E2GKwV+ xCT8V0gpI2Y4ADTJcr6++xIxejdMNoISBo2SeOnvfFyVSm2o2oSQdDxs8 g==; IronPort-SDR: o4ujDa1t/5pkBVSaxybA6FMbxtryVjsnmPDVhisg3nsc6fTMJ90Spp+Lz8RtRS+Kmz5ZEl6IJM xCr/1D02Z66cj3RH50oYvXpZ/cPV8voDvxBxncTzSihynY3me2Buyd8Sak0cQxflM9jjqqD6mH 51aPPh7YO0VUQSv+aZnd7mRaGOaGq5kZvrphSdIGgd2BsyBI+5Wnu+TPHs+deBM7hgA10LuL9E bej6jK8oOj05TO/0K6aJgcFI95h2Ia8pArSKiAat/9OC7Dpv8RSIvGIqcWQiHb0ibeDtlHE6+k SOk= X-IronPort-AV: E=Sophos;i="5.76,352,1592863200"; d="scan'208";a="13592258" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 25 Aug 2020 15:45:34 +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 AF250280070; Tue, 25 Aug 2020 15:45:34 +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 v3 2/2] mmc: allow setting slot index via device tree alias Date: Tue, 25 Aug 2020 15:44:41 +0200 Message-Id: <20200825134441.17537-2-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825134441.17537-1-matthias.schiffer@ew.tq-group.com> References: <20200825134441.17537-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 slightly 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 --- 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;