From patchwork Sat Mar 24 23:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban X-Patchwork-Id: 890741 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=free.fr Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WSoIuD2l"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="AmPeftFr"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 408YNH6kMkz9ryk for ; Mon, 26 Mar 2018 10:27:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0SrA/T4JMi9iFbbNme9ONfnn9Q3Tia1IcE1XSx37D6s=; b=WSoIuD2lFQQZp4ExPeH6JCePR4 1Emw4uZihEH7hcVhG2V+WZa3/DLwkdqFJvcoz8fpS/TVV767cdscs3jFDRVuDf4Q20z1C5I53h0bE BnKWI5UfHEjJ3yVr5E/O43hyE1oRpz8K/jGgXN9JWnsNBUWEWgFYct2b4uRKkk551MVDO0v9Kj4g8 OpzcZtc3XpHErAd/r/m4swMMfptr1UElj4Gu5ia7YYN8LnK6bSGGPF7KVhXr4tcgaQMuRBKyrJlT0 8HrLwzX4n6lYN33Jh6F1+10/3RBQG8CTnXATuUVtiC5769/LAm4v9NVNmFLtO16glDaB6SXK5pP5H yhkv4zcw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0F31-000792-GT; Sun, 25 Mar 2018 23:27:35 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0En2-0006ba-WB for linux-mtd@bombadil.infradead.org; Sun, 25 Mar 2018 23:11:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=AoRCd2gxqU2q3u+Yx0s/qg6uAhoGijuIfrunjXy7/pY=; b=AmPeftFrkTnzpitA5aBfsUcKN byQJcnfSDRnacQtebK41Kk5ATh3fJ3CAq22HTyky+0cjn1LoYeM2qPta0JzQzoFYifs3Qsc6yTht3 ikhSLXhOBntdchcBaH2pFtwtLxHpD8b0vdSOkFioa+TxTmy1eBJZ6VT7f2heP9Nt6UNDt/ZKVdZzR 9jB9KHpQmqA3PDu+BiD2NL2A+CeJVyJXaZwlTDz06Dr+aCn/i335fp2/G6s1zC+YgZbFdj7Qtbs+P ZtF+5qCO3nN5Lr5x/sAvaZJRXjtdRsx8uvYlPDwNSoQ1XckQwQlnivyRERcjNfV+YriOGLrfKMuHN zUx/kMNrw==; Received: from smtp4-g21.free.fr ([212.27.42.4]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezsYz-0004ik-Fq for linux-mtd@lists.infradead.org; Sat, 24 Mar 2018 23:27:06 +0000 Received: from tock.home (unknown [IPv6:2a02:8108:4740:3978:85fa:b641:9ec1:a586]) (Authenticated sender: albeu) by smtp4-g21.free.fr (Postfix) with ESMTPA id 1197719F4EA; Sun, 25 Mar 2018 00:25:46 +0100 (CET) From: Alban Bedel To: linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] nvmem: Update the OF binding to use a subnode for the cells list Date: Sun, 25 Mar 2018 00:24:57 +0100 Message-Id: <1521933899-362-2-git-send-email-albeu@free.fr> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521933899-362-1-git-send-email-albeu@free.fr> References: <1521933899-362-1-git-send-email-albeu@free.fr> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180324_192705_902054_4C940AB1 X-CRM114-Status: GOOD ( 16.19 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [212.27.42.4 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [212.27.42.4 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (albeu[at]free.fr) -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Boris Brezillon , devicetree@vger.kernel.org, Richard Weinberger , Marek Vasut , Rob Herring , Srinivas Kandagatla , linux-mtd@lists.infradead.org, Cyrille Pitchen , Alban Bedel , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Having the cells as subnodes of the provider device without any compatible property might clash with other bindings. To avoid this problem update the binding to have all the cells in a 'nvmem-cells' subnode with a 'nvmem-cells' compatible string. This new binding guarantee that we can turn any kind of device in a nvmem provider. While discouraged for new uses the old scheme is still supported for backward compatibility. Signed-off-by: Alban Bedel --- Documentation/devicetree/bindings/nvmem/nvmem.txt | 55 ++++++++++++++++------- drivers/nvmem/core.c | 10 +++++ 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.txt b/Documentation/devicetree/bindings/nvmem/nvmem.txt index fd06c09..6b723e7 100644 --- a/Documentation/devicetree/bindings/nvmem/nvmem.txt +++ b/Documentation/devicetree/bindings/nvmem/nvmem.txt @@ -11,14 +11,29 @@ these data from, and where they are stored on the storage device. This document is here to document this. = Data providers = -Contains bindings specific to provider drivers and data cells as children -of this node. +A data provider should have a subnode named 'nvmem-cells' that contains +a subnodes for each data cells. + +For backward compatibility the nvmem data cells can be direct children +of the data provider. This use is discouraged as it can conflict with +other bindings. Optional properties: read-only: Mark the provider as read only. += Data cells list = +The data cells list node should be named 'nvmem-cells' and have a +child node for each data cell. + +Required properties: + compatible: Must be "nvmem-cells" + #address-cells: <1> if the provider use 32 bit addressing, + <2> for 64 bits addressing + #size-cells: <1> if the provider use 32 bit sizes, + <2> for 64 bits sizes + = Data cells = -These are the child nodes of the provider which contain data cell +These are the child nodes of the nvmem-cells node which contain data cell information like offset and size in nvmem provider. Required properties: @@ -37,24 +52,30 @@ For example: ... /* Data cells */ - tsens_calibration: calib@404 { - reg = <0x404 0x10>; - }; + nvmem-cells { + compatible = "nvmem-cells"; + #address-cells = <1>; + #size-cells = <1>; - tsens_calibration_bckp: calib_bckp@504 { - reg = <0x504 0x11>; - bits = <6 128> - }; + tsens_calibration: calib@404 { + reg = <0x404 0x10>; + }; - pvs_version: pvs-version@6 { - reg = <0x6 0x2> - bits = <7 2> - }; + tsens_calibration_bckp: calib_bckp@504 { + reg = <0x504 0x11>; + bits = <6 128> + }; - speed_bin: speed-bin@c{ - reg = <0xc 0x1>; - bits = <2 3>; + pvs_version: pvs-version@6 { + reg = <0x6 0x2> + bits = <7 2> + }; + speed_bin: speed-bin@c{ + reg = <0xc 0x1>; + bits = <2 3>; + + }; }; ... }; diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 78051f0..a59195c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -783,6 +783,16 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, if (!nvmem_np) return ERR_PTR(-EINVAL); + /* Devices using the new binding have all the cells in + * a subnode with compatible = "nvmem-cells". In this + * case the device will be the parent of this node. + */ + if (of_device_is_compatible(nvmem_np, "nvmem-cells")) { + nvmem_np = of_get_next_parent(nvmem_np); + if (!nvmem_np) + return ERR_PTR(-EINVAL); + } + nvmem = __nvmem_device_get(nvmem_np, NULL, NULL); of_node_put(nvmem_np); if (IS_ERR(nvmem)) From patchwork Sat Mar 24 23:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban X-Patchwork-Id: 890739 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=free.fr Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WiIWjWks"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="jtKerYk1"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 408YMX4NVbz9ryk for ; Mon, 26 Mar 2018 10:27:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3yAljqeG53JsS1mXgD9Eim+2f3peUHDVduL8m7o+96U=; b=WiIWjWksQncUL9CPec7xpiaXXT XyeRt13QFsa2dLZi8P+qPj3EtVKPLuvzSR8yZ3FEMXPyeXRHCjr+ahz9KADeSb2m0fEuq795Lrm2q cUhYPqCC1A8bD5MQ3QT/JUWK7+KROa08V7MdsiQmeHCGBG5LbFUpQIevRAyrZMQJOEfH+RFfkb4WL 5ROguoSAUJHln++PTThQcnfCwGg/97lEWck+yTGHeJr3qTLT3e2Q95B0RE+67Rr0zOJESmh2rmwCD GOKAPEUTZQ5GCMQHXD28zfOkHeF841tTqq0bZfc0OlfUmScPpG3pR/BlaHhoMRci0WUMPB5mIYefu T3E/GG9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0F2O-0006dA-2f; Sun, 25 Mar 2018 23:26:56 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0En1-0006ba-I6 for linux-mtd@bombadil.infradead.org; Sun, 25 Mar 2018 23:11:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ThTx1wkjKSuMbVCUKrsfojQN+I0+nngDCHqmJ4MC4n0=; b=jtKerYk1nCchqY0ONc+8FwVPR 69zntBEgHwzqfTeIz8UePK9gKnRKdlQgcHdQCuRql3S+mqrU/kidKR7uf5/5kEyz2od26ekVoIbc1 GawnFS2fd3EXlb3huTnOBMyYoPP6xgM0nSZGcytvrz67XjHRy3C5IzCSTQ5OAM9+YVJg/35FQzJ3+ NMklIqF/nEGjp5wnZygiYtvkr9IzYALmtHSbEUA1GpPrvJJTvyNIfJuaz/LAw+6xYE7VwKGG0V+mU orbOn5y3335VjpBPLuCr0mwvFVI5O/qTOt37NBL/VPNjTsoGnNhBktrP3MuEHqQf6tfGuVU4HGSDP 4EgUQunlg==; Received: from smtp4-g21.free.fr ([212.27.42.4]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezsZJ-0004jA-N9 for linux-mtd@lists.infradead.org; Sat, 24 Mar 2018 23:27:26 +0000 Received: from tock.home (unknown [IPv6:2a02:8108:4740:3978:85fa:b641:9ec1:a586]) (Authenticated sender: albeu) by smtp4-g21.free.fr (Postfix) with ESMTPA id 4B6F519F4B5; Sun, 25 Mar 2018 00:26:14 +0100 (CET) From: Alban Bedel To: linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] doc: bindings: Add bindings documentation for mtd nvmem Date: Sun, 25 Mar 2018 00:24:58 +0100 Message-Id: <1521933899-362-3-git-send-email-albeu@free.fr> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521933899-362-1-git-send-email-albeu@free.fr> References: <1521933899-362-1-git-send-email-albeu@free.fr> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180324_192725_877045_56B8026E X-CRM114-Status: GOOD ( 11.25 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [212.27.42.4 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [212.27.42.4 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (albeu[at]free.fr) -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Boris Brezillon , devicetree@vger.kernel.org, Richard Weinberger , Marek Vasut , Rob Herring , Srinivas Kandagatla , linux-mtd@lists.infradead.org, Cyrille Pitchen , Alban Bedel , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Config data for drivers, like MAC addresses, is often stored in MTD. Add a binding that define how such data storage can be represented in device tree. Signed-off-by: Alban Bedel --- Changelog: v2: * Added a "Required properties" section with the nvmem-provider property v3: * Fixed my name in From and Signed-off-by * Moved to the new nvmem binding with the nvmem-cells subnode --- .../devicetree/bindings/nvmem/mtd-nvmem.txt | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt new file mode 100644 index 0000000..c819a69 --- /dev/null +++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt @@ -0,0 +1,27 @@ += NVMEM in MTD = + +Config data for drivers, like MAC addresses, is often stored in MTD. +An MTD device, or one of its partition, can be defined as a NVMEM provider +by having an 'nvmem-cells' subnode as defined in nvmem.txt. + +Example: + + flash@0 { + ... + + partition@2 { + label = "art"; + reg = <0x7F0000 0x010000>; + read-only; + + nvmem-cells { + compatible = "nvmem-cells"; + #address-cells = <1>; + #size-cells = <1>; + + eeprom@1000 { + reg = <0x1000 0x1000>; + }; + }; + }; + }; From patchwork Sat Mar 24 23:24:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban X-Patchwork-Id: 890738 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=free.fr Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mol0uD5b"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Ck5kvXd8"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 408YM60SW2z9ryk for ; Mon, 26 Mar 2018 10:26:42 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p48KJdDe/nkH9oyMghCyTY0DUzj2WFTmFwbvbdMIU24=; b=mol0uD5bCnU1ofBlpQkxAiOkgX 94QHpRyLBnGjO+b7/GYaqeLRekYxWV0UxDhfBsHoxSNCM3seQaGl82iOXZ5H3lSNiQEqDlb8BvBZA mqbMWZnnZ5yK/+VJhHIxdbTm+RtlsQoOeVcIe8rJq8Rkc3UBxNmVhlSYW+FX9W1NbwhNeUrcMKkYb XDjVYTLFscgyiC4m+iaXkOxRNEtOG55iNA/25WLUOv1p34hflilNdIlW3uo3fWiKiYwJb/yMvu2LM OScoGJQ+Z40Xbmuzo+DOMbXQrY1HWTi8yv80tWINJKqoWhutggwMctMmnAmp6oktLEJ24YI1/aPeS bGDprlTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0F25-0006On-AS; Sun, 25 Mar 2018 23:26:37 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0Emz-0006ba-Ov for linux-mtd@bombadil.infradead.org; Sun, 25 Mar 2018 23:11:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4Wpsb9fR1pNZwIiEIyGd5SjQ9ybyCGrCUDxq+pWR0zo=; b=Ck5kvXd8m2JP+lFVlV9CLzLSb C8nW6Y0uB1bXMl0MF7AF9pK0HOOh4Ta0OdhS12R358Abkd0CBVSIANs6duhsFmZCXieyAQNv+txkU 3Z1gkEgLB8qAHJ8m5l9fyjfnwKMHQtm9X+ea9QuTYSZuCub3sxy2R5qw/3LzfNDl86FY5FnHsri8k nPAtdkLfjFrm74w/R5nJXGp0kcosuE1h9xYDbFzavM2AZ8c4KyqBG0wZ7kfiZNxeOjkcMZNWvnQRz 03pCLtenseKtnb9wf9BgK9/wn4W+hi2r0tx51izY8EU630HSjgjuarDHLO1shH+BmygNzDA5yFY80 em07oq06g==; Received: from smtp4-g21.free.fr ([212.27.42.4]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezsZl-0004jg-BO for linux-mtd@lists.infradead.org; Sat, 24 Mar 2018 23:27:54 +0000 Received: from tock.home (unknown [IPv6:2a02:8108:4740:3978:85fa:b641:9ec1:a586]) (Authenticated sender: albeu) by smtp4-g21.free.fr (Postfix) with ESMTPA id 9B62319F574; Sun, 25 Mar 2018 00:26:41 +0100 (CET) From: Alban Bedel To: linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] mtd: Add support for reading MTD devices via the nvmem API Date: Sun, 25 Mar 2018 00:24:59 +0100 Message-Id: <1521933899-362-4-git-send-email-albeu@free.fr> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521933899-362-1-git-send-email-albeu@free.fr> References: <1521933899-362-1-git-send-email-albeu@free.fr> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180324_192753_585336_DDF5F85B X-CRM114-Status: GOOD ( 20.00 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [212.27.42.4 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (albeu[at]free.fr) -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [212.27.42.4 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Boris Brezillon , devicetree@vger.kernel.org, Richard Weinberger , Marek Vasut , Rob Herring , Srinivas Kandagatla , linux-mtd@lists.infradead.org, Cyrille Pitchen , Alban Bedel , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Allow drivers that use the nvmem API to read data stored on MTD devices. For this the mtd devices are registered as read-only NVMEM providers. On OF systems only devices that have the 'nvmem-provider' property are registered, on non-OF system all MTD devices are registered. Signed-off-by: Alban Bedel --- Changelog: v2: * Moved to the MTD core instead of using notifiers * Fixed the Kconfig description v3: * Rebased on current kernel * Moved the code to mtdcore.c and removed the conditional compilation as suggested by Boris Brezillon * Fixed my name in From and Signed-off-by * Only allow root to read from the nvmem sysfs interface --- drivers/mtd/Kconfig | 1 + drivers/mtd/mtdcore.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 2 ++ 3 files changed, 62 insertions(+) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 2a8ac68..911d869 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -1,5 +1,6 @@ menuconfig MTD tristate "Memory Technology Device (MTD) support" + imply NVMEM help Memory Technology Devices are flash, RAM and similar chips, often used for solid state file systems on embedded devices. This option diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 28553c8..d2a127c 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -478,6 +478,48 @@ int mtd_pairing_groups(struct mtd_info *mtd) } EXPORT_SYMBOL_GPL(mtd_pairing_groups); +static int mtd_nvmem_reg_read(void *priv, unsigned int offset, + void *val, size_t bytes) +{ + struct mtd_info *mtd = priv; + size_t retlen; + int err; + + err = mtd_read(mtd, offset, bytes, &retlen, val); + if (err && err != -EUCLEAN) + return err; + + return retlen == bytes ? 0 : -EIO; +} + +static int mtd_nvmem_add(struct mtd_info *mtd) +{ + struct nvmem_config config = {}; + + config.dev = &mtd->dev; + config.owner = THIS_MODULE; + config.reg_read = mtd_nvmem_reg_read; + config.size = mtd->size; + config.word_size = 1; + config.stride = 1; + config.read_only = true; + config.root_only = true; + config.priv = mtd; + + mtd->nvmem = nvmem_register(&config); + if (IS_ERR(mtd->nvmem)) { + /* Just ignore if there is no NVMEM support in the kernel */ + if (PTR_ERR(mtd->nvmem) == -ENOSYS) { + mtd->nvmem = NULL; + } else { + dev_err(&mtd->dev, "Failed to register NVMEM device\n"); + return PTR_ERR(mtd->nvmem); + } + } + + return 0; +} + static struct dentry *dfs_dir_mtd; /** @@ -560,6 +602,11 @@ int add_mtd_device(struct mtd_info *mtd) if (error) goto fail_added; + /* Add the nvmem provider */ + error = mtd_nvmem_add(mtd); + if (error) + goto fail_nvmem_add; + if (!IS_ERR_OR_NULL(dfs_dir_mtd)) { mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), dfs_dir_mtd); if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) { @@ -585,6 +632,8 @@ int add_mtd_device(struct mtd_info *mtd) __module_get(THIS_MODULE); return 0; +fail_nvmem_add: + device_unregister(&mtd->dev); fail_added: of_node_put(mtd_get_of_node(mtd)); idr_remove(&mtd_idr, i); @@ -627,6 +676,16 @@ int del_mtd_device(struct mtd_info *mtd) mtd->index, mtd->name, mtd->usecount); ret = -EBUSY; } else { + /* Try to remove the NVMEM provider */ + if (mtd->nvmem) { + ret = nvmem_unregister(mtd->nvmem); + if (ret) { + dev_err(&mtd->dev, + "Failed to unregister NVMEM device\n"); + goto out_error; + } + } + device_unregister(&mtd->dev); idr_remove(&mtd_idr, mtd->index); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 205eded..660b8e7 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -352,6 +353,7 @@ struct mtd_info { struct device dev; int usecount; struct mtd_debug_info dbg; + struct nvmem_device *nvmem; }; int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,