From patchwork Mon Oct 23 14:34: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: 10022617 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 7E2B1601E8 for ; Mon, 23 Oct 2017 14:37:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69B3D288AE for ; Mon, 23 Oct 2017 14:37:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E458288B2; Mon, 23 Oct 2017 14:37:47 +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 074D4286B1 for ; Mon, 23 Oct 2017 14:37:45 +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=j2AFEYSMw89N387sIjGtQsEHTwuxK2udZIYvtB33yE4=; b=lJLba4Sa/nNsX8HhhtFZxYHCyB GC2Y/jn0YEB1T7i6ubIQxKpCo6d9Eihna9Ik5MbPJh21AL+rujxbGDt4qQwpaWdnl5MwgxudhhJuU 3UqJNt4pix6IftR2xqAkyKve0z2WmfREpYbCbRzmu6F+nPKSGJX9gn3QldXXzusQu6oXrEPI03I/W /vkezrPNUqYqNO33juvwP+gJ9aQ5ZS+O0FLlWY901N1kQDwXzi97He++9NKP/AQDftl+E+tCtu5pZ 0pmwwzEQmWXneiTCP+nI5G69250Da1Zbt/5J0PzA1+JsTJs+cBb4zM8yPWbmdNJt1ay53AupfqnZ6 XMEO5DEQ==; 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 1e6drM-0008Gj-R0; Mon, 23 Oct 2017 14:37:44 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e6doy-0005RB-9j for linux-arm-kernel@lists.infradead.org; Mon, 23 Oct 2017 14:35:24 +0000 Received: by mail-wm0-x244.google.com with SMTP id p75so9962429wmg.3 for ; Mon, 23 Oct 2017 07:34:59 -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=9xMkuRuBJdgTOB7llx4wKkQGN/GCD8+xEdovEC733lE=; b=1ZFBYYF+p+rAOc8tioTh6s5IIeuYzobPLQR5ptep92ctBFKg6v4twp+1TL67C2EFBu SUoKSQiT0vsArhC6TVHoVri0PvWkpGD/dX1RLsBurmC8ZqBQ/fSgZTrNbf9XVJXjCrwS r/JnH8uH+CR+f8tJQphMhEuw1qgHTA2mQhyZc/KUG2gXydCCsC44a3V+/BE3JAHsgKWG XALot+ZuwXVthTL1X5khBtO9F6i5kzCYc6Pny5UbBq3ZFirVPXNxwGYMGDPDxSOmVIgu 8hqlTEf+xIlrkImh7+sCXLlKrqLe1KIaEmAabmdeFFdtjwr/xDqI0gNWd0lBpkfNxNBu dowQ== 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=9xMkuRuBJdgTOB7llx4wKkQGN/GCD8+xEdovEC733lE=; b=i4ImPJ91FtTYuUkEXKzc1kA5XmUqj956GRos27R1eVDGbYDsWuklKm9aqlBOfjigoa lg3/AyAA+3hMWhIsUWUBo3MT6OUE2oM1e3nxt9RZqyb0CJMhJjBso/JntGXo/11W+b5k zhVvWE0hSr094xa4CqPAcvT85g97YG7icgZ2cfFEUOEI67+tnH7iDCbpcuWCkK7mw3Hs VRqxbMRJlbMURdOKYKnIFvwUxse0nn2temz4h1sHo5y5xd/KY5acfs6MTUMWhwPsbFg+ CGDL2vGYxMecQL7qrwXYmJ2TOMrPYDEgzB5LKzqG/AUvKqzRSpJIAQZ6W6QMSx8Ctkl1 7Dsg== X-Gm-Message-State: AMCzsaVnxG0S3F4zKweiFk/Ys43mIfoPaJwSzysoTdEEM+xQzyu6YB1w xuNbCLIiC7dU9zQagC7QoQvY/g== X-Google-Smtp-Source: ABhQp+Spp2AcESVIo1XcQhvkkhnoRfFLEw31q3ZH7IeZs2CxX6pxHyaa/QS0kT0MnyIk0Gmb2u30iA== X-Received: by 10.80.183.148 with SMTP id h20mr16875366ede.178.1508769297769; Mon, 23 Oct 2017 07:34:57 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w51sm7098180edd.60.2017.10.23.07.34.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 07:34:57 -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 5/7] nvmem: imx-ocotp: Add i.MX7D timing write clock setup support Date: Mon, 23 Oct 2017 15:34:48 +0100 Message-Id: <1508769290-2646-6-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_073516_605883_48E865E9 X-CRM114-Status: GOOD ( 14.78 ) 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 This patch adds logic to correctly setup the write timing parameters when blowing an OTP fuse for the i.MX7S/D. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue --- drivers/nvmem/imx-ocotp.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 93d3cb5..be8d002 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -50,17 +50,14 @@ #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 -#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_FSOURCE 1001 /* > 1000 ns */ +#define DEF_STROBE_PROG 10000 /* IPG clocks */ #define IMX_OCOTP_WR_UNLOCK 0x3E770000 #define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA static DEFINE_MUTEX(ocotp_mutex); -struct ocotp_params { - unsigned int nregs; - unsigned int bank_address_words; -}; - struct ocotp_priv { struct device *dev; struct clk *clk; @@ -69,6 +66,12 @@ struct ocotp_priv { struct nvmem_config *config; }; +struct ocotp_params { + unsigned int nregs; + unsigned int bank_address_words; + void (*set_timing)(struct ocotp_priv *priv); +}; + static int imx_ocotp_wait_for_busy(void __iomem *base, u32 flags) { int count; @@ -193,6 +196,27 @@ static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); } +static void imx_ocotp_set_imx7_timing(struct ocotp_priv *priv) +{ + unsigned long clk_rate = 0; + u64 fsource, strobe_prog; + u32 timing = 0; + + /* i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1 + * 6.4.3.3 + */ + clk_rate = clk_get_rate(priv->clk); + fsource = DIV_ROUND_UP_ULL((u64)clk_rate * DEF_FSOURCE, + NSEC_PER_SEC) + 1; + strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG, + NSEC_PER_SEC) + 1; + + timing = strobe_prog & 0x00000FFF; + timing |= (fsource << 12) & 0x000FF000; + + writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); +} + static int imx_ocotp_write(void *context, unsigned int offset, void *val, size_t bytes) { @@ -219,7 +243,7 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, } /* Setup the write timing values */ - imx_ocotp_set_imx6_timing(priv); + priv->params->set_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. @@ -377,26 +401,31 @@ static struct nvmem_config imx_ocotp_nvmem_config = { static const struct ocotp_params imx6q_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sl_params = { .nregs = 64, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sx_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6ul_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx7d_params = { .nregs = 64, .bank_address_words = 4, + .set_timing = imx_ocotp_set_imx7_timing, }; static const struct of_device_id imx_ocotp_dt_ids[] = {