From patchwork Mon Feb 27 19:27:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 9593817 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 20097604AB for ; Mon, 27 Feb 2017 19:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CE3C283ED for ; Mon, 27 Feb 2017 19:28:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01B3C28488; Mon, 27 Feb 2017 19:28:16 +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 32D73283ED for ; Mon, 27 Feb 2017 19:28:15 +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=Cpl/R01LPxptyBD1f4zOyhEHurFgNpLlcOynTQfCnlo=; b=M+h dSdXah9xLf5AALKBOPSRU/1GqefyhEqj4DWlCA5uX7u7cTA8WOQxDrUH0W7YMqAETm+0PblLjWDBk jrYfyCagOi1As3AwxY/0mcCp/y/Z9KyuTIRQUx0GjE+VOektO7EUU5xFdeJMrFjjf063ER8vIpVwi R7/lkTwJsN0BNM/wpHkUesWMkx8+MoB2ZDD/Bv1rEXaFFKg8U1nw3SZyq2SHHljkLiJnEzvPu5114 L+ETKrqLOmA/XhHPbs4ql/s/myc8ars9/cAdB3R1lyWPPd042neKwDjlRnA5HdzUS8z61bj0nFmOu vvL5zHC1A3CfQ3YbqO/PY/qS2jOadxQ==; 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 1ciQxw-0001a4-U5; Mon, 27 Feb 2017 19:28:12 +0000 Received: from forward15h.cmail.yandex.net ([87.250.230.157]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ciQxp-00011y-JO for linux-arm-kernel@lists.infradead.org; Mon, 27 Feb 2017 19:28:10 +0000 Received: from smtp1m.mail.yandex.net (smtp1m.mail.yandex.net [77.88.61.132]) by forward15h.cmail.yandex.net (Yandex) with ESMTP id 28C3E22017; Mon, 27 Feb 2017 22:27:41 +0300 (MSK) Received: from smtp1m.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1m.mail.yandex.net (Yandex) with ESMTP id 753A563C0D2C; Mon, 27 Feb 2017 22:27:35 +0300 (MSK) Received: by smtp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 7Z3HtOy2lJ-RT7GjxOL; Mon, 27 Feb 2017 22:27:34 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aosc.xyz; s=mail; t=1488223654; bh=cMe+B+oZIDGhbCN6P38UJz//a3ibBTmqoxeb6bdWAgk=; h=From:To:Cc:Subject:Date:Message-Id; b=WzAKgHFe+DF2Ihruzbto/ctjrjggluRoyXFDUxBUv8ysSdbfMkSsvbXjnbwU7PLKg eLuVJXmTM6AC51PYyRQrRJBPthXX0xJMMpRO96G0nIqiT1aAXdpeASb4iJfwXKub89 CtYgvyWp2So9YUddgzQ1I3YVuivrTIX6t8IvYEzU= Authentication-Results: smtp1m.mail.yandex.net; dkim=pass header.i=@aosc.xyz X-Yandex-ForeignMX: US X-Yandex-Suid-Status: 1 0,1 0,1 0,1 0,1 0,1 0,1 0,1 0,1 1130000036118848 From: Icenowy Zheng To: Srinivas Kandagatla , Maxime Ripard , Rob Herring , Chen-Yu Tsai Subject: [PATCH v5 1/3] nvmem: sunxi-sid: read NVMEM size from device compatible Date: Tue, 28 Feb 2017 03:27:13 +0800 Message-Id: <20170227192715.50198-1-icenowy@aosc.xyz> X-Mailer: git-send-email 2.11.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170227_112807_111219_9B587899 X-CRM114-Status: GOOD ( 12.22 ) 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: devicetree@vger.kernel.org, linux-sunxi@googlegroups.com, 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 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);