From patchwork Wed Oct 4 22:25:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 9985785 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 91FF8602B8 for ; Wed, 4 Oct 2017 22:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8336828C2B for ; Wed, 4 Oct 2017 22:28:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7703928C35; Wed, 4 Oct 2017 22:28:19 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable 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 CEDB628C2B for ; Wed, 4 Oct 2017 22:28:18 +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: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=s1DlLyVnL2XFOx9pBBaxlSaSaTzfLG0aW1Mw3cAdX6E=; b=BbEBu0x574ZD/BO3v5zkqvJdvb xZVNG1NS6YZujZPfNApeJsPpR956314g+mwj3FTUdkqKXyrqSCGw7++T5UJ0bfZVFv3yCCOJeo0mp iaSrzzda3j+ujFAj3IOzlBVP3lsTScvT/de0xTcCX03ceMNaHKITn5D7FL2F3El6safmPbSzdLydR EhV2DNqReFWfKvnc//R60g+1kQrr8K950OO1OvH2b/CdlwYJ2Hir6CTmn17D2AjIbfTs+nnrBSOdV sLTO/RQ7GePgacmLAqwb9N5hLxj7LosUq7lQGqb4qQ4heYDp1HmZ/UG5SPSiAQ0HnTK8+f3N/roqv Nyys7j/w==; 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 1dzs9F-0007Re-BV; Wed, 04 Oct 2017 22:28:13 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzs6t-0005Ye-V7 for linux-arm-kernel@lists.infradead.org; Wed, 04 Oct 2017 22:25:52 +0000 Received: by mail-wm0-x22c.google.com with SMTP id t69so25418198wmt.2 for ; Wed, 04 Oct 2017 15:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexus-software-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/zIncxfjgY+JVx4WveBep+dYV/sf4M3DZKlL++fUi30=; b=f0wmKjrcGPTxM+lVztZ+h7bf34eRlMYATpEV5Dm20zsRvsT+FVMek008NPW0+cgD5L F8O9READrm6BrSoH94zpfnLoq3P4DF38nigF86Y9HZisYUwcKpg7VWuSsnQupdW8od0m bg8iP8v13O8yAMtvCgWCk2zhNi+lN57w7K/f2qpk/DZIfqEinM4NeaLliChR2oJfpocA y1UTMqiHoNo1IBkEE9+Eldt1X+xGGvgulyooB026OvWOrFQZI6APsW9HJyW7ZQ4eYCWz E0ZWGRSjIGobKwNqCXURFg2n4FJ3qajhBxLeMZZNdU2AGFwLHuAAELizGb2g42AztdwU 77nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/zIncxfjgY+JVx4WveBep+dYV/sf4M3DZKlL++fUi30=; b=ZQ18AQr3PsfTPxWXOUvSCZlG4PCGRtm0EnzFOvjUdnREOAa9bAD+hdsDYoJhz62Bx2 tvdG1GKQAoZ0r8ZpbqdYYGRoLFSwtjqhstXj2VRSlK0UtCdDiCwzeB9HL+5+2ImyCCND lo/56xpHHo8O3mAUY+A8jdZP3v4pe0MX5n7Ca8isah7wK1RFWxhLUhUAvsiVAy7LlgMX gsCi3c3YudNmov5geezwYW91MRd1SiT9Q9xfzR0W9qGVdWq0/XzJOPxEeKHFRKQHDSv+ TlGrrYWqJcVo+5gf0R+DtfNNTkgwb+DZbx5IEE+JIMteciKSh/ciatcTipXq6uSwQkTf 0i+A== X-Gm-Message-State: AHPjjUjhA9dow37x2vqWxSBryToOHyl9Rhp6oom+vpOgJydVhqfd45EY 9i/xo/cITgx5oE3VMtYTmAc3cA== X-Google-Smtp-Source: AOwi7QB1Jl4XTxY8O6J2JHUGv2SNukKdy7iJATp3hVCqet7J26Q6nAURlbVnpiBdRBuvcN0W9hfmZA== X-Received: by 10.80.177.141 with SMTP id m13mr30788250edd.114.1507155925714; Wed, 04 Oct 2017 15:25:25 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id i6sm12459022edk.3.2017.10.04.15.25.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 15:25:25 -0700 (PDT) From: Bryan O'Donoghue To: richard.leitner@skidata.com, srinivas.kandagatla@linaro.org, axel.lin@ingics.com, ping.bai@nxp.com, d.schultz@phytec.de, peng.fan@nxp.com, van.freenix@gmail.com, p.zabel@pengutronix.de Subject: [RESEND][PATCH 3/7] nvmem: imx-ocotp: Add support for banked OTP addressing Date: Wed, 4 Oct 2017 23:25:17 +0100 Message-Id: <1507155921-824-4-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507155921-824-1-git-send-email-pure.logic@nexus-software.ie> References: <1507155921-824-1-git-send-email-pure.logic@nexus-software.ie> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171004_152548_195733_19B45B0D X-CRM114-Status: GOOD ( 18.23 ) 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: pure.logic@nexus-software.ie, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 The i.MX7S/D takes the bank address in the CTRLn.ADDR field and the data value in one of the DATAx {0, 1, 2, 3} register fields. The current write routine is based on writing the CTRLn.ADDR field and writing a single DATA register only. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue --- drivers/nvmem/imx-ocotp.c | 71 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index fed76a4..8034937 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -40,7 +40,10 @@ #define IMX_OCOTP_ADDR_CTRL_SET 0x0004 #define IMX_OCOTP_ADDR_CTRL_CLR 0x0008 #define IMX_OCOTP_ADDR_TIMING 0x0010 -#define IMX_OCOTP_ADDR_DATA 0x0020 +#define IMX_OCOTP_ADDR_DATA0 0x0020 +#define IMX_OCOTP_ADDR_DATA1 0x0030 +#define IMX_OCOTP_ADDR_DATA2 0x0040 +#define IMX_OCOTP_ADDR_DATA3 0x0050 #define IMX_OCOTP_BM_CTRL_ADDR 0x0000007F #define IMX_OCOTP_BM_CTRL_BUSY 0x00000100 @@ -55,6 +58,8 @@ static DEFINE_MUTEX(ocotp_mutex); struct octp_params { unsigned int nregs; + bool banked; + unsigned int regs_per_bank; }; struct ocotp_priv { @@ -176,6 +181,7 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, u32 timing = 0; u32 ctrl; u8 waddr; + u8 word = 0; /* allow only writing one complete OTP word at a time */ if ((bytes != priv->config->word_size) || @@ -228,8 +234,22 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, * description. Both the unlock code and address can be written in the * same operation. */ - /* OTP write/read address specifies one of 128 word address locations */ - waddr = offset / 4; + if (priv->params->banked) { + /* + * In banked mode the OTP register bank goes into waddr see + * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1 + * 6.4.3.1 + */ + offset = offset / priv->config->word_size; + waddr = offset / priv->params->regs_per_bank; + word = offset & (priv->params->regs_per_bank - 1); + } else { + /* + * OTP write/read address specifies one of 128 word address + * locations + */ + waddr = offset / 4; + } ctrl = readl(priv->base + IMX_OCOTP_ADDR_CTRL); ctrl &= ~IMX_OCOTP_BM_CTRL_ADDR; @@ -255,8 +275,41 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, * shift right (with zero fill). This shifting is required to program * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be * modified. + * Note: on i.MX7 there are four data fields to write for banked write + * with the fuse blowing operation only taking place after data0 + * has been written. This is why data0 must always be the last + * register written. */ - writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA); + if (!priv->params->banked) { + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); + } else { + switch (word) { + case 0: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 1: + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 2: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + case 3: + writel(0, priv->base + IMX_OCOTP_ADDR_DATA1); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA2); + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA3); + writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); + break; + } + } /* 47.4.1.4.5 * Once complete, the controller will clear BUSY. A write request to a @@ -313,11 +366,11 @@ static struct nvmem_config imx_ocotp_nvmem_config = { }; static const struct octp_params params[] = { - { .nregs = 128}, - { .nregs = 64}, - { .nregs = 128}, - { .nregs = 128}, - { .nregs = 64}, + { .nregs = 128, .banked = false, .regs_per_bank = 0}, + { .nregs = 64, .banked = false, .regs_per_bank = 0}, + { .nregs = 128, .banked = false, .regs_per_bank = 0}, + { .nregs = 128, .banked = false, .regs_per_bank = 0}, + { .nregs = 64, .banked = true, .regs_per_bank = 4}, }; static const struct of_device_id imx_ocotp_dt_ids[] = {