From patchwork Mon Oct 23 14:34:47 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: 10022611 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 B1AE4601E8 for ; Mon, 23 Oct 2017 14:37:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D5922654B for ; Mon, 23 Oct 2017 14:37:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91B61288AE; Mon, 23 Oct 2017 14:37:29 +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 1FFCA2654B for ; Mon, 23 Oct 2017 14:37:29 +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=C1gSFZzbZhKWu9PNexB6py4dSofXvXdMr50SdqN3sPI=; b=FbHwNa+aHxOTdRatJOdkBja3cr K5i4laXuUA0n+Clb7EsNwq1rquMe0Nhzmw88r9cA8KhP4UKQCqASxS4I7f3qu+BzI+x06b/RbDWVu ovTijZllvNgGxe3nvP483SFB4WDj8QtNyl+aXqjp+P7caoyE+NWcNwojrqXnR11T/SFgsxeLxcl4T XQwpMYs91qh6jsXvCWkGZlUO6CRWvD/Nt8AVWFHPgkSQMesN9f5OWlVj8B5eR2EBx2SYulCOSr00P +o7xlWQFQWLijJqEwOUWZ438dc2t8eFEeF97YB6YBBEe3GkjvlPvNK5cB9D92Akk5eWbeMa7ktuJI 2CeEn3rg==; 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 1e6dr0-0007tq-5s; Mon, 23 Oct 2017 14:37:22 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e6dp0-0005QS-Gj for linux-arm-kernel@lists.infradead.org; Mon, 23 Oct 2017 14:35:33 +0000 Received: by mail-wm0-x243.google.com with SMTP id u138so10284147wmu.4 for ; Mon, 23 Oct 2017 07:34:58 -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=3czTldWEPNdUmWU9FRxauq3L41RLJ6erqurZhZfYLz8=; b=tI+5RBvzmH8yuqgLgQe+5j3GOkhcC4xcP65U01j0cYrCFwFcbzk2Dpjz6fb5u0ZBrf c2O51e7n5xJ9DX0CHrj+pE+nOlvzzxpojxvsJ2JEvQJZlshEFAtiyNO8znDXQK5iTnD5 BV6rJxmxBk7tVhRssLLHldwjcXzwPEWP+fc64XfsV+rjQybsr7Jbl6d9RBBYl/75pYh6 +jxkmaizSnfSMtKSKDtpXuVwPrTwFC4H154CVU5HQLCfg9OWXzOq2n6XRY4e57uyR5ED oPWXd/Kko3lF30JLbKSFEqFd3JXzluSIk9/R1kxAJpK1CXnnnBYFiYUwk+yHSRg/fLVC SiCQ== 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=3czTldWEPNdUmWU9FRxauq3L41RLJ6erqurZhZfYLz8=; b=IDT/MjvLsir2yCks+WTZJpnkqLyNAqdxxGU0HkmIWPqksO7hEArb7Yg2pQyBe9h7DJ Ol5OIZP29pyAlGtH1wBQoSAaeL362mrDxwIcrbrPL7Y3JwB0Ma61Hw+tzsg59639gVtW UlY17US70xjExxziKomaKGE7+FaTdYQXMPN39KXV6Mw+X3UmQb7AghescpQ67hcu2dlv YUByNioQB1aJoUaNqTCEMiO1LaYU/M+qWnHd7+L2/1feAbDevzXC+bwqja6+HEv/v+nD TXhJJg16grgjQGM37t4ONh7+ae+4xljKD0NpPW882yhaFQEvAz1IyfRrnxZGhW8bgNty ubMw== X-Gm-Message-State: AMCzsaWlxh0ykq36NXWQ2Z2KgK5KPVWZmEdGB/SoqQkWzQwSXWWyhUjR qPzwdrlEkhF9rNpwVthN9fz2lA== X-Google-Smtp-Source: ABhQp+SHQr2PzzsNdD25BOplww5LUGZu/7yyxl904Thkrv8AKMEojLZwsqXptFFWY3uVBSWRNTCBvg== X-Received: by 10.80.133.203 with SMTP id q11mr16279863edh.50.1508769296671; Mon, 23 Oct 2017 07:34:56 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w51sm7098180edd.60.2017.10.23.07.34.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 07:34:56 -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 4/7] nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function Date: Mon, 23 Oct 2017 15:34:47 +0100 Message-Id: <1508769290-2646-5-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_073518_832303_C34B7893 X-CRM114-Status: GOOD ( 13.64 ) 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 has a different set of timing requirements, as a pre-cursor to adding the i.MX7 timing parameters, move the i.MX6 stuff to a dedicated function. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Reviewed-by: Philipp Zabel --- drivers/nvmem/imx-ocotp.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e10a0da..93d3cb5 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -168,6 +168,31 @@ static int imx_ocotp_read(void *context, unsigned int offset, return ret; } +static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) +{ + unsigned long clk_rate = 0; + unsigned long strobe_read, relax, strobe_prog; + u32 timing = 0; + + /* 47.3.1.3.1 + * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] + * fields with timing values to match the current frequency of the + * ipg_clk. OTP writes will work at maximum bus frequencies as long + * as the HW_OCOTP_TIMING parameters are set correctly. + */ + clk_rate = clk_get_rate(priv->clk); + + relax = clk_rate / (1000000000 / DEF_RELAX) - 1; + strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; + strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; + + timing = strobe_prog & 0x00000FFF; + timing |= (relax << 12) & 0x0000F000; + timing |= (strobe_read << 16) & 0x003F0000; + + writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); +} + static int imx_ocotp_write(void *context, unsigned int offset, void *val, size_t bytes) { @@ -175,9 +200,6 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, u32 *buf = val; int ret; - unsigned long clk_rate = 0; - unsigned long strobe_read, relax, strobe_prog; - u32 timing = 0; u32 ctrl; u8 waddr; u8 word = 0; @@ -196,23 +218,8 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, return ret; } - /* 47.3.1.3.1 - * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] - * fields with timing values to match the current frequency of the - * ipg_clk. OTP writes will work at maximum bus frequencies as long - * as the HW_OCOTP_TIMING parameters are set correctly. - */ - clk_rate = clk_get_rate(priv->clk); - - relax = clk_rate / (1000000000 / DEF_RELAX) - 1; - strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; - strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; - - timing = strobe_prog & 0x00000FFF; - timing |= (relax << 12) & 0x0000F000; - timing |= (strobe_read << 16) & 0x003F0000; - - writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); + /* Setup the write timing values */ + imx_ocotp_set_imx6_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear.