From patchwork Mon Oct 9 14:11:49 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: 9993559 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 355EC602D7 for ; Mon, 9 Oct 2017 14:14:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26753287F8 for ; Mon, 9 Oct 2017 14:14:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AEAF287FA; Mon, 9 Oct 2017 14:14:07 +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 977BE287F8 for ; Mon, 9 Oct 2017 14:14:06 +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=T0kN0jd4eMAKXyGuOlCUBmqlGLqbNjWgh4TMk3vdISU=; b=g6ZJ7wCHBdNElCBJC0LEhwd3pw MFmKGd4L2q2hrpfZGBzQtHuB34qkc/tzTwi5kjqHiiqXkvPsvUW+U3qL0+YAtVuDgDuuCl93l0LIu rRH+dgmf+Do8GqSZIXo1sXEVs/kX7HWSvPXIYMhUg3d2KrDgdV2JBKBasADwHohqJG8fJC04aRXRC igyJoqJmAyT0udhw35/U/mkqUmwmZkYokRqBdOWi2Qvjo2IMf3pIdgJjcnZxEMUZK2+B8qwkuPAsT nNm7H8Y9Sg7bB2yH9ppEqM2itOXNmXEJ+Q0W8wQB8E6fvBXqx/6kO+xHt0QRn7qgzv4B15VC8F9T/ MhGtpj3A==; 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 1e1Yon-0000CK-L0; Mon, 09 Oct 2017 14:14:05 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e1Yn7-00077g-IV for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2017 14:12:29 +0000 Received: by mail-wm0-x232.google.com with SMTP id u138so22900400wmu.5 for ; Mon, 09 Oct 2017 07:12:01 -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=IfhrCAX0HZOpm5qkQyYnAThEYVB4LDV14ZtM0w5dJ2k=; b=f3p3b2mbtPCJ3JpfWAUc5AZ8VcyK0D+Ojgji1Bo6BYSlZ5uQgoqgS/u0qTePrqHm/H XERAjtSRZOpwfG8q0xFjZcfuxl5mRu2rCBA3dvOsGSmtclxJuie5IhZIMQVbBuKA1aGV VMfp9/WjAFuNVhhFnBc73xE5PBTMbf3+RxzupdERmJ+hk3QM5s2lTMJvGzKVYKm4C9xX jakgOx5Dfkfx/e0pOwk50lR6jd44cqWoQwtbDaQbO637/r3WtBMy80btxh7KglNqEqH4 6oXSI+XYd92HQti6RQdSvcICIOUMl0G5LZsV+ejRJfRkDENJ1VnP4JoEfsLyzzj2Bj6K ghfg== 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=IfhrCAX0HZOpm5qkQyYnAThEYVB4LDV14ZtM0w5dJ2k=; b=KPPl0LDG9VSkgPrD5YxUzXwukeevYB6Ujpb44Tkqj6carsKUzxHT15jkLenzKeMUNI q/IsPTxVPH7ncoKXswslKJgKZQIP/9I4+CCx3mTqnDTnyiLYDzgpQnf53Af0ShAq7rfr GsqCcU9YPONj8+TRnWmlCF4N2JqlqEpB/QsYw2rmS67Th+pXsoAX0/psSdwXat+sbsht EVjCbhH4MI2D46OXeRNlZ6kWXPVdnx3ZrN+mqnC8WLAsenNFbEszI4emQUvkB0ZaeT2I m5n/T8nD4MuB2lPnl8wRjlbhSE4G858FkcxfJMWn3rKNTYVfxJT6DggHrTu7f772vNGn FFlw== X-Gm-Message-State: AMCzsaUnyegyC6Vjwqj9n/F26syKNpAZL0KAjGk4G8PC6/NLf1DdqX0G ANjSPBog2FFsEEuYYXHsjYfaKQ== X-Google-Smtp-Source: AOwi7QB44RxAwRqCNo7ZPr2jaMXyld9oQA+R/Tc3Oj9iFAkXL4uBQrpsVL0+kSdzqWy5mFb29ncOxw== X-Received: by 10.80.208.155 with SMTP id v27mr13277207edd.62.1507558319717; Mon, 09 Oct 2017 07:11:59 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id g49sm451117edc.31.2017.10.09.07.11.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 07:11:59 -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 4/7] nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function Date: Mon, 9 Oct 2017 15:11:49 +0100 Message-Id: <1507558312-20580-5-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_071221_845391_1D30D02E X-CRM114-Status: GOOD ( 13.89 ) 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 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 927d525..2645ee3 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.