From patchwork Thu Mar 30 08:10:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 9653167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77AE4602C8 for ; Thu, 30 Mar 2017 08:11:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6820B28541 for ; Thu, 30 Mar 2017 08:11:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C1F828547; Thu, 30 Mar 2017 08:11:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6043228541 for ; Thu, 30 Mar 2017 08:11:26 +0000 (UTC) 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: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:In-Reply-To: References:List-Owner; bh=ZtyS1Y2r1Th2EgkptfsVxWyX+0UN9zjn8iTT/1TXDVo=; b=gWl Ikrzj0ck9/gTWoOvrQxGMLvVDTFSzbSoeuqvDh+6d0kDJCONUTrLNlAl48THispvVLq+U41JHUmfQ QmKYCclIbAWwZcNIhBdqmEYkNOzh4TtgcDvDGxbD581+zgC60itOVRYPCKw+9oZdeFJvjSreBUM2T Pjm9R+F0m2CpaQuqpzhyeiXAj1mxdT+3x0w0xpEMoM4+9MfzjJnNW2dTvs6JoXyq58FAtE/Nh0Lw8 haxVzxhyYdRNboYk3DsoLWpaL3ibWt32GrCaEwg4Hc7bLTOm0VB7tJRALw8bNBqEtgz/bVieoHfI4 sme3Tt4Xi5Z/xr08FnZ1IE0va6wOOtQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctVAy-0001UJ-F8; Thu, 30 Mar 2017 08:11:24 +0000 Received: from nov-007-i458.relay.mailchannels.net ([46.232.183.12]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctVAq-00017o-Ah for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2017 08:11:21 +0000 X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6DFAE3606F8; Thu, 30 Mar 2017 08:10:48 +0000 (UTC) Received: from hermes.aosc.io (unknown [100.96.129.119]) by relay.mailchannels.net (Postfix) with ESMTPA id EFF16362470; Thu, 30 Mar 2017 08:10:47 +0000 (UTC) X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from hermes.aosc.io (hermes.aosc.io [172.20.88.133]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.7.37); Thu, 30 Mar 2017 08:10:48 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io X-MailChannels-Auth-Id: lmn-TZDUIOWCRQMW X-Illegal-Broad: 605f39426af919e6_1490861448251_1987102940 X-MC-Loop-Signature: 1490861448251:1623106752 X-MC-Ingress-Time: 1490861448251 Received: from localhost.localdomain (unknown [120.236.174.154]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id D37F17E679; Thu, 30 Mar 2017 08:10:37 +0000 (UTC) From: Icenowy Zheng To: Srinivas Kandagatla , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH v6 1/3] nvmem: sunxi-sid: read NVMEM size from device compatible Date: Thu, 30 Mar 2017 16:10:17 +0800 Message-Id: <20170330081019.59979-1-icenowy@aosc.io> X-Mailer: git-send-email 2.12.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_011117_483395_FDAE4012 X-CRM114-Status: GOOD ( 11.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Icenowy Zheng MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Icenowy Zheng Sometimes the SID device have more memory address space than the real NVMEM size (for the registers used to read/write the SID). Fetch the NVMEM size from device compatible, rather than the memory address space's length, in order to prepare for adding some registers-based read support. Signed-off-by: Icenowy Zheng Acked-by: Maxime Ripard --- Changes in v4: - Added Maxime's ACK. drivers/nvmem/sunxi_sid.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 1567ccca8de3..69524b67007f 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,10 @@ static struct nvmem_config econfig = { .owner = THIS_MODULE, }; +struct sunxi_sid_cfg { + u32 size; +}; + struct sunxi_sid { void __iomem *base; }; @@ -72,18 +77,24 @@ static int sunxi_sid_probe(struct platform_device *pdev) struct sunxi_sid *sid; int ret, i, size; char *randomness; + const struct sunxi_sid_cfg *cfg; sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); if (!sid) return -ENOMEM; + cfg = of_device_get_match_data(dev); + if (!cfg) + return -EINVAL; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); sid->base = devm_ioremap_resource(dev, res); if (IS_ERR(sid->base)) return PTR_ERR(sid->base); - size = resource_size(res) - 1; - econfig.size = resource_size(res); + size = cfg->size; + + econfig.size = size; econfig.dev = dev; econfig.reg_read = sunxi_sid_read; econfig.priv = sid; @@ -119,9 +130,17 @@ static int sunxi_sid_remove(struct platform_device *pdev) return nvmem_unregister(nvmem); } +static const struct sunxi_sid_cfg sun4i_a10_cfg = { + .size = 0x10, +}; + +static const struct sunxi_sid_cfg sun7i_a20_cfg = { + .size = 0x200, +}; + static const struct of_device_id sunxi_sid_of_match[] = { - { .compatible = "allwinner,sun4i-a10-sid" }, - { .compatible = "allwinner,sun7i-a20-sid" }, + { .compatible = "allwinner,sun4i-a10-sid", .data = &sun4i_a10_cfg }, + { .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg }, {/* sentinel */}, }; MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);