From patchwork Mon Oct 9 14:11:48 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: 9993549 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 AA608602D7 for ; Mon, 9 Oct 2017 14:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A9FE2852E for ; Mon, 9 Oct 2017 14:13:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F7B6287F8; Mon, 9 Oct 2017 14:13: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=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 048DA2852E for ; Mon, 9 Oct 2017 14:13:19 +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=ELrQ8bn9P99InME7rPnEZafh7mYhnuvco4Cky2Q/2LA=; b=f+XEoOtRVAUQP7SfRO6dR98Har HQnTXAk8TWcDPimyBGdf05O9eirygNI020ieMLYUZbinfdehFe3VvbWMo/ORG9TcFGtjZ9UDxKpL1 lINiKj3MJp+P0z1PiKiLyEJq9/ggWNWkyMABfsxZDvjqC7dwv7RSNMclHGUZfbi5PQkuY1iiD3n8A z3ZJI8mOR947NdVC0WcqfqL/SVSmUKqgqlyjHjQdGkx7P4FWlQKPYMqcN2EKTcROS/q59dfXR3hnF PqQSz28yxKqb9xlNDhYdo2xa8V+lvt33y6QUcDrzid0Yuvaa9YpRZmvoxBUqVXNb/HHvBI5xxxHA3 Eaw7wr8w==; 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 1e1Yo2-00081N-B2; Mon, 09 Oct 2017 14:13:18 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e1Yn6-00077Y-Gd for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2017 14:12:26 +0000 Received: by mail-wm0-x22b.google.com with SMTP id t69so22924209wmt.2 for ; Mon, 09 Oct 2017 07:12:00 -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=vyH/hReiZsUd/TXvsI8i9deqY3uH/ZpZyz5aU8iEDMo=; b=eM5gN1eNde0NXyk9ia+6Vf3Cqxm253bV7FtGqZLe1FW/WuzDAheAh2y34xfliS7B6F eL4jj482bnoeCLPpnI9xkqhxuLxaA85/RwacRn0paicJlA1ZroBoMLJPRuXzD0DzczHv oTjh92LHkYMZET126S8fknYKYIgSHHrqMToRO5FM1F0N3xHWk4r/BB4OmDGLwP2vQaEb vFfoKqJNhLQF7D/1WuIRA3ExESpZB2KT2YMsVGQ4I4OuPiNE9iWswbAwu2qNvJMBF96V yA8QgqKghDVLJyXx4H06+CMiay5Ih0X7tr1voACR3RHSEkiRx01hAEtUh5J91CXtycqN 2vnA== 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=vyH/hReiZsUd/TXvsI8i9deqY3uH/ZpZyz5aU8iEDMo=; b=IqTcA8B68s1wexEnspEiafeoQ6jkO9gUgQeU3uyyIGlmvcYjIgFzlfIJXIG0xnGshI 9uAX3Ud6eGcefAb7Cq/jGYDDNS/GYP3ihd46vevF1mFYTHEj3xon9A9OnUfs6kCkoacU udvJadLcTHl1p/DD4ofNSJBKLvadL7qxm0zrlAwn9hHdkw1SGoQPfRO7qcNZ6AmD1X9y YuztM31L2O8sCzv1FdeiAAm0teo0NMZrbffVbI/vFxtJ/NVADuSkUODOR/8m6vTXI9qL drWWFoJrA3xpTQvVLuceFtzIQIFB1d/1uTkxqpwSTWCnvMeXXIIcoaeD6J5rGYUJpb41 XoYA== X-Gm-Message-State: AMCzsaUTu9HkBT26fsEeXKKeE0bO2/mR+k0yfy9Ic1WQADBIFig6+p83 zm1RcYY9K0jAtlsbqrMiPILdfw== X-Google-Smtp-Source: AOwi7QBkLeBdb3irmO7XI057Low1yu57WuuF0uivzTqWMuZozuklfL/v0VcswLwJH+M0DMl++Fq2Eg== X-Received: by 10.80.243.145 with SMTP id g17mr5596141edm.42.1507558318675; Mon, 09 Oct 2017 07:11:58 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id g49sm451117edc.31.2017.10.09.07.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 07:11:58 -0700 (PDT) From: Bryan O'Donoghue To: p.zabel@pengutronix.de, 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 Subject: [PATCH v3 3/7] nvmem: imx-ocotp: Add support for banked OTP addressing Date: Mon, 9 Oct 2017 15:11:48 +0100 Message-Id: <1507558312-20580-4-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507558312-20580-1-git-send-email-pure.logic@nexus-software.ie> References: <1507558312-20580-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-20171009_071220_709846_93CAF6AC X-CRM114-Status: GOOD ( 18.77 ) 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: Bryan O'Donoghue , 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 Reviewed-by: Philipp Zabel --- drivers/nvmem/imx-ocotp.c | 70 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 7798571..927d525 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,7 @@ static DEFINE_MUTEX(ocotp_mutex); struct ocotp_params { unsigned int nregs; + unsigned int bank_address_words; }; struct ocotp_priv { @@ -176,6 +180,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 +233,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->bank_address_words != 0) { + /* + * 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->bank_address_words; + word = offset & (priv->params->bank_address_words - 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 +274,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->bank_address_words == 0) { + 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 +365,11 @@ static struct nvmem_config imx_ocotp_nvmem_config = { }; static const struct ocotp_params params[] = { - { .nregs = 128 }, - { .nregs = 64 }, - { .nregs = 128 }, - { .nregs = 128 }, - { .nregs = 64 }, + { .nregs = 128, .bank_address_words = 0 }, + { .nregs = 64, .bank_address_words = 0 }, + { .nregs = 128, .bank_address_words = 0 }, + { .nregs = 128, .bank_address_words = 0 }, + { .nregs = 64, .bank_address_words = 4 }, }; static const struct of_device_id imx_ocotp_dt_ids[] = {