From patchwork Mon Oct 23 14:34:46 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: 10022597 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 2228F601E8 for ; Mon, 23 Oct 2017 14:36:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D5FD288FA for ; Mon, 23 Oct 2017 14:36:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00CB9288BD; Mon, 23 Oct 2017 14:35:59 +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 7D057288FA for ; Mon, 23 Oct 2017 14:35:58 +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=y0caIjo4UjLhxjQ1L5D2vX+am44Do8OxP2awNhPbVQQ=; b=WjZ+swaHIm9idHzIULxD3GkEGC dDeWtlBxyi5ZXxWrgnGu58wVzC4jxPRgCL7OyGN8k+4eyjy5yriW3EZaY9+AB6MFNI64nCDshSrvg F/SKbMTXnz7sfnDrpydMTKaN6y0WRoftNGv+RJgANJ7E51ZNvVZYDpuRPEN1DVErhSjMn0WxUaxoH eRx2B7X0KiO5tNwflJ3wrNsZa5XOIXcE3PbV9niPpGRClK2Isja6P+f3kX7Pt9+BU1T1IdopKvT6i oCQKgiKX070eTddtOAK7A3wAlKxR3NKu14EAhuYwLwf5TIxWm/7Jf5CER5rsaVg94gH1qh4v/EbqK HanPKhrQ==; 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 1e6dpV-00076B-7n; Mon, 23 Oct 2017 14:35:49 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e6dox-0005PY-D9 for linux-arm-kernel@lists.infradead.org; Mon, 23 Oct 2017 14:35:22 +0000 Received: by mail-wm0-x242.google.com with SMTP id p75so9962190wmg.3 for ; Mon, 23 Oct 2017 07:34:56 -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=axKlATbssbxGXOm2ipjIYDSuiqNP3xeLsk5vkwdR570=; b=VMvWkR/X+Xd1omtp1rKgQHh007RuSgD4IVLA09tpn41H8jSiKsV474BxoXEHtNsyyB 3aGYfOWk7vlvVHXZGk1nkw5TPQLHNir+pbCRIjagxKT7s6dW1XXMm3ad6X136nNc6Yzs q52nK1tjhrhSi0yg36i0BBYzFhS30/MIH7j6W7cDkb/w9RNCMJZstWssbUyus8JSm5y/ UToo07MYrSz+iwcvQZEBURJZp7pNAmXa5f4gRRmL/Y1F3HtvIwMN6DkbGalYpUM5D9UA F4O47+1Z/W44OyOP2Sea+7t3nBDVyrTiDO7i9LMBzYd9Csk4kbJVY7hb04FdLM3apkxn VeAQ== 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=axKlATbssbxGXOm2ipjIYDSuiqNP3xeLsk5vkwdR570=; b=gRWpDN9SFu91anJJw7Jpo+vfreI1Rx/hi7fN26Y1oEXpkIiSv9k3delgZvQJVLgQQL z7oQP2/VNA0DVOmRiWxHuJPMOuXPwdzVbBvyd0LBkr79wXZkCRp8Z9JdgXQn1VK0yK3/ ocYPF1bKD2rfL9l9he5f9k+8S23gBiOhBXG8o06C+8++JdITTSoG3GQF3hFVDYujB6g6 aykS/1XgcLhFmeLldlyMh8rJJvK8MDJEg6WX8pNfgUraFhmPGkMzTKImI0qew25Ayxbn KSXdeBnRH8phBf0ljqxydw/u+fJ8UE6Qp5ch2GrWBlhkPatp9j3p7kqnqAE7TtY0ZhQL Uo0w== X-Gm-Message-State: AMCzsaVyOa8pL7Zo9tbRrjoOv9tLhjd6j2p8v1lq3xlbgb6ZnQUFJ9ot 0FBZGg5IJIss/YMPA+7P7gimMw== X-Google-Smtp-Source: ABhQp+ShoQuXDm0vgr6ug3K9OMfR437MNYEwulOY0dlRMlofl2avn/BmtFHz+RgZsByn3W23cQjqPQ== X-Received: by 10.80.164.187 with SMTP id w56mr17041413edb.78.1508769295633; Mon, 23 Oct 2017 07:34:55 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w51sm7098180edd.60.2017.10.23.07.34.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 07:34:55 -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 v4 3/7] nvmem: imx-ocotp: Add support for banked OTP addressing Date: Mon, 23 Oct 2017 15:34:46 +0100 Message-Id: <1508769290-2646-4-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508769290-2646-1-git-send-email-pure.logic@nexus-software.ie> References: <1508769290-2646-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-20171023_073515_758293_AB9DCF0D X-CRM114-Status: GOOD ( 17.52 ) 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 Reviewed-by: Philipp Zabel --- drivers/nvmem/imx-ocotp.c | 68 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index b035e47..e10a0da 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,23 @@ 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/i.MX7 mode the OTP register bank goes into waddr + * see i.MX 7Solo Applications Processor Reference Manual, Rev. + * 0.1 section 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 { + /* + * Non-banked i.MX6 mode. + * 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,43 @@ 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) { + /* Banked/i.MX7 mode */ + 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; + } + } else { + /* Non-banked i.MX6 mode */ + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); + } /* 47.4.1.4.5 * Once complete, the controller will clear BUSY. A write request to a @@ -314,22 +369,27 @@ static struct nvmem_config imx_ocotp_nvmem_config = { static const struct ocotp_params imx6q_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx6sl_params = { .nregs = 64, + .bank_address_words = 0, }; static const struct ocotp_params imx6sx_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx6ul_params = { .nregs = 128, + .bank_address_words = 0, }; static const struct ocotp_params imx7d_params = { .nregs = 64, + .bank_address_words = 4, }; static const struct of_device_id imx_ocotp_dt_ids[] = {