From patchwork Sun Oct 8 22:41:19 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: 9992057 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 C237A60364 for ; Sun, 8 Oct 2017 22:42:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1D6F28631 for ; Sun, 8 Oct 2017 22:42:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A510828639; Sun, 8 Oct 2017 22:42:56 +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 2946028631 for ; Sun, 8 Oct 2017 22:42:56 +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=rUY8TJHuLqWMmCl8zO7Db0HMZeCYs7HDG6f7rsZ6UDE=; b=iHMOcAYw35UNHQmO85RtFoQbQh UxjSFkIaEVNPN2NaPRS3BKnWgLfekQE34q0tiPdcLgY6uyZenI2qNRpJvcn1gZLS2WhyKoFhIyav6 6u6R3d+GEQIhMdmIc7lPeQi9LjLUf2ykvR9iECWsAeEyLRLOJneb27MyDix5kVbL9PCQqTtCFjECK RvsO4C4R7noOKzoNLGwdy9FnuhdQzck+N2YF2ufBJ0CPRRrD98o6HvvqjZenbx4k3bkpqD7U0tCAe bU1YIWULBGhjjkh93oynToNq+cZ15aSBjkB+vd/IOtDjwxS7h14IOyGmlaShO2ZdGhLEBlqZUdHtQ alWQu3nA==; 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 1e1KHf-0004o7-75; Sun, 08 Oct 2017 22:42:55 +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 1e1KGc-0003kd-Cc for linux-arm-kernel@lists.infradead.org; Sun, 08 Oct 2017 22:41:53 +0000 Received: by mail-wm0-x232.google.com with SMTP id b189so18052447wmd.4 for ; Sun, 08 Oct 2017 15:41:29 -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=V055LQGoWQmp+LWAaIfbSUBVtxF1zjUTD63oSwbTfgI=; b=EPDGptN7TnCvCaOUrmaa53faWxCT1fTlfMsGsteQolstMFy0yYgaXBy2bQE7S3qTlc PQAdy4qZGKjLKAoivJa6lQfHgA9+ia9GNvRyDI/KPA2W9fc7uPNWHNRTPFsqwkpyXLrU QFvnGrFK8tEHWi99st2VfJofjjmjIFCxRtgN0G0Sl8N6fmrXftiIB8bnJnSsHH7612ro Ch5paCTH2YCJUoJE0xVixd5ntxSI652LnoCoANUkLpLPtlorrv5003653zioO0enG0Sk Qhlccjc/hQh9MRG80SoBn6LuUrG18NjNnrHkQ3w5TgFw/28NyXfN7Sr42ZIavgwGqUjG 5Ppw== 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=V055LQGoWQmp+LWAaIfbSUBVtxF1zjUTD63oSwbTfgI=; b=AhfKHSUy9BF0q4L0EbIT6ST94pYdwUCWvRvrPYnl+34qYDPHWgUzR5nYAXxH4WKe8D E69Oz+sA5vsQ4SQ8vGPIpFjOKViCjGbrQbZWwo0h4kOAXQcSGIiN+RIY1Zcr9yuuLIsi cDLk0b/gtgZ9Vd4hHwo0GI2UPGeQVQf/HdgNLQ1l29JO9TAM8Gql8entECFmO/CLRPWc EqOhIK8RcZ2hyTVmzWmEPvpbdhGhha/6XNGPMhKiYM4MLlh0D4JCz8Gkh0y+0KK7QjQn LHxaZFK9PfvPnNNVGIUm22UQ7M+k5JVxecZkPnpTJF9ADjn2K3MLWN/KtdBpLU0NqpRD wf0Q== X-Gm-Message-State: AMCzsaUi30oXxitrC9rlCugM+x5Y1Cn2rHBHEIiCz3cvGFi2hd+2YLEr fQ02LaeCNlqPlkWW5G7KaThGBA== X-Google-Smtp-Source: AOwi7QCXpAlpYRYwRZRHzRHoO/45IFTJvVTmeoLKza/KR6rss8ayuzl45aeqRiHi+CtnNZfQ7D0EcQ== X-Received: by 10.80.146.178 with SMTP id k47mr11445708eda.197.1507502488326; Sun, 08 Oct 2017 15:41:28 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id g45sm432909eda.19.2017.10.08.15.41.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Oct 2017 15:41:27 -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 v2 4/7] nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function Date: Sun, 8 Oct 2017 23:41:19 +0100 Message-Id: <1507502482-22518-5-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507502482-22518-1-git-send-email-pure.logic@nexus-software.ie> References: <1507502482-22518-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-20171008_154150_817053_8EA2FDAF X-CRM114-Status: GOOD ( 13.95 ) 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 3b18351..74c2f15 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.