Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753435AbdC0Nmz (ORCPT ); Mon, 27 Mar 2017 09:42:55 -0400 Received: from mail1.skidata.com ([91.230.2.99]:48892 "EHLO mail1.skidata.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbdC0Nmw (ORCPT ); Mon, 27 Mar 2017 09:42:52 -0400 X-Greylist: delayed 597 seconds by postgrey-1.27 at vger.kernel.org; Mon, 27 Mar 2017 09:42:51 EDT Authentication-Results: mail1.skidata.com; spf=None smtp.pra=richard.leitner@skidata.com; spf=PermError smtp.mailfrom=Richard.Leitner@skidata.com; spf=None smtp.helo=postmaster@sdmr1srv.skidata.net X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2GfBAB1E9lY/0oKEKxUCB0BBQELAYVAB?= =?us-ascii?q?59HkyyCD4IOgmyDNoNVFwECAQEBAQEBAQOBEIVDUiiBFgENBbdDOiYCihEBAQE?= =?us-ascii?q?HAiYJAYZEiSGGBwWJF4gWiy6CBZBJgXqIdQyGNJNlIQKBORISEQUfhSsDHYFlc?= =?us-ascii?q?4gogQ0BAQE?= X-IPAS-Result: =?us-ascii?q?A2GfBAB1E9lY/0oKEKxUCB0BBQELAYVAB59HkyyCD4IOgmy?= =?us-ascii?q?DNoNVFwECAQEBAQEBAQOBEIVDUiiBFgENBbdDOiYCihEBAQEHAiYJAYZEiSGGB?= =?us-ascii?q?wWJF4gWiy6CBZBJgXqIdQyGNJNlIQKBORISEQUfhSsDHYFlc4gogQ0BAQE?= X-IronPort-AV: E=Sophos;i="5.36,231,1486422000"; d="scan'208";a="3178136" From: Richard Leitner To: , , CC: , , , , Richard Leitner Subject: [PATCH 1/2] nvmem: imx-ocotp: clear error bit after reading locked values Date: Mon, 27 Mar 2017 15:31:30 +0200 Message-ID: <1490621491-28247-1-git-send-email-richard.leitner@skidata.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.16.60.30] X-ClientProxiedBy: sdex1srv.skidata.net (172.16.10.92) To sdex1srv.skidata.net (172.16.10.92) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2410 Lines: 81 When reading a "read locked" value from the OCOTP controller on i.MX6 SoC's an error bit is set. This bit has to be cleared by software before any new write, read or reload access can be issued. Therefore clear it after we detect such an "locked read". Signed-off-by: Richard Leitner --- drivers/nvmem/imx-ocotp.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index b8ca1e6..e2b62b3 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -25,6 +25,19 @@ #include #include +#define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the + * OTP Bank0 Word0 + */ +#define IMX_OCOTP_OFFSET_PER_WORD 0x10 /* Offset between the start addr + * of two consecutive OTP words. + */ +#define IMX_OCOTP_ADDR_CTRL 0x0000 +#define IMX_OCOTP_ADDR_CTRL_CLR 0x0008 + +#define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 + +#define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA + struct ocotp_priv { struct device *dev; struct clk *clk; @@ -32,6 +45,17 @@ struct ocotp_priv { unsigned int nregs; }; +static void imx_ocotp_clr_err_if_set(void __iomem *base) +{ + u32 c; + + c = readl(base + IMX_OCOTP_ADDR_CTRL); + if (!(c & IMX_OCOTP_BM_CTRL_ERROR)) + return; + + writel(IMX_OCOTP_BM_CTRL_ERROR, base + IMX_OCOTP_ADDR_CTRL_CLR); +} + static int imx_ocotp_read(void *context, unsigned int offset, void *val, size_t bytes) { @@ -52,11 +76,22 @@ static int imx_ocotp_read(void *context, unsigned int offset, dev_err(priv->dev, "failed to prepare/enable ocotp clk\n"); return ret; } - for (i = index; i < (index + count); i++) - *buf++ = readl(priv->base + 0x400 + i * 0x10); - clk_disable_unprepare(priv->clk); + for (i = index; i < (index + count); i++) { + *buf++ = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 + + i * IMX_OCOTP_OFFSET_PER_WORD); + + /* 47.3.1.2 + * For "read locked" registers 0xBADABADA will be returned and + * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by + * software before any new write, read or reload access can be + * issued + */ + if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL) + imx_ocotp_clr_err_if_set(priv->base); + } + clk_disable_unprepare(priv->clk); return 0; } -- 2.1.4