From patchwork Wed Oct 4 22:25: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: 9985787 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 1C98A602B8 for ; Wed, 4 Oct 2017 22:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DFB828C2B for ; Wed, 4 Oct 2017 22:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02EA428C35; Wed, 4 Oct 2017 22:28: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 6CA9528C2B for ; Wed, 4 Oct 2017 22:28:46 +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=QHGxthzqbPzxobZTGPYLSkb50ZcANOkr86knv3NomkI=; b=JlUyZ0N0Ikn7bCSfXhGLrZ5qU1 K9pdLCB+L6CMxx9MrPV4iB4Jy8EYdp8U3QqBf8iML/r4R0CWOTjL1+ooYhmVVZRtTu7GHe7ObHUFb 6PJeDjC4+00reGF8WjtPB1ffcqsq6MoTdZWZ12npmTSkoDcUdRN0R2Fn2QwPs2Fvi1E9fm56ow2Ya 9WJfkNjhF8hPyr00FKQoBtNujtkACwFlKgf+oXK/8AqN0RvrF4SipbmWZYkXksu1wVoG2HlrZkNFl cgdBGZfLVVVmDhJtaCpWzoLkQWvyI3YiJqilEeRsKSGae3/Mxc5NykB/1NfxDSw8WE6BOgzKRIhyX vuxJhtyA==; 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 1dzs9c-0007o1-Hf; Wed, 04 Oct 2017 22:28:36 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzs6w-0005Yw-17 for linux-arm-kernel@lists.infradead.org; Wed, 04 Oct 2017 22:25:53 +0000 Received: by mail-wm0-x22b.google.com with SMTP id u138so25404580wmu.5 for ; Wed, 04 Oct 2017 15:25: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=+ibbz3djHY1bmUR7oR/9cOptDDghbRib60bDt6nPxZE=; b=HcSxr4iIeMiHvSgLyDi3pWQaG2QYz2QmGbntDB9WLmGk7OYCV9fN7Rmg7gyZl4ojyU Q4U4m7dBmq+boRd7E3nuqzdazDmju4hSqjrASZRT0VYPPLzLxn1kiEgwdEGtxPtcmR7e GztaO8eh2lklrxOhyzE2Ynw0AvRGQuhFil/q9eTQ+F2FreLKEVaVELsGcaTAPUEDa69h Wdu0oR19Mm/75CYCXvumNQNf2Aa4Gsl7nUnDK+l/D6zsb6Xf9rGDW8p5bHyWknBcdW+h R/UhBJMSOdaQENmn2KdPqqVDEdX4mlVWDBfEZMwrHTWG/y/OwrVSwiUmlVNaRjZ4WcAF oukg== 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=+ibbz3djHY1bmUR7oR/9cOptDDghbRib60bDt6nPxZE=; b=QN/3G5cMOu2MMr+YAjzPKlPXb2gF4VHJZJrh7PEr3cWjTDkAn3rDruhOmrGYdQc0m6 52rjzEHO6J+8FVhkKFaDCbOJWLA4TJzCVBOItDtxBeHTKrmUXkMhMI7zczLDdZ6PY8tn WQ8FXXu7V+B3v+gOsutjf6NFU5iziHkZpucjC8eVzTWrDr848SevgUCW0AtUmXKZp44q 0wrK+bnMsTED4t2DOafbNULp9hyIYxBMbAoFVDalYZyisYqLxzWA1S7GhNDOSRtcpDn/ g+oBUMHsJMcrfrnzuQwcbuXPMFKq5n9YJ8x8xNzM3k2iz2apjZb5itCdcaH1X6NwDh6f fpIw== X-Gm-Message-State: AMCzsaUBtO//ceFv/K2RCdH+WSaX+kLGoVkgTWOA8I8IPcHbsAYqdmpr BvINARtIEkWp0T+1JkRYCF01dg== X-Google-Smtp-Source: AOwi7QAQmBgtMe3UTDRlIza6/N9cX6jcRvPlpxBo4mDO2Q5flE1MJreoFwal9oFDkrD0VnDOJFJlDw== X-Received: by 10.80.144.52 with SMTP id b49mr2294664eda.204.1507155927879; Wed, 04 Oct 2017 15:25:27 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id i6sm12459022edk.3.2017.10.04.15.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 15:25:27 -0700 (PDT) From: Bryan O'Donoghue To: 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, p.zabel@pengutronix.de Subject: [RESEND][PATCH 5/7] nvmem: imx-ocotp: Add i.MX7D timing write clock setup support Date: Wed, 4 Oct 2017 23:25:19 +0100 Message-Id: <1507155921-824-6-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507155921-824-1-git-send-email-pure.logic@nexus-software.ie> References: <1507155921-824-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-20171004_152550_423679_AE6471C9 X-CRM114-Status: GOOD ( 15.68 ) 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 | 61 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 0cd7e03..40a1669 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -51,6 +51,7 @@ #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 #define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_FSOURCE 1001 #define IMX_OCOTP_WR_UNLOCK 0x3E770000 #define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA @@ -60,6 +61,7 @@ struct octp_params { unsigned int nregs; bool banked; unsigned int regs_per_bank; + bool mx7_timing; }; struct ocotp_priv { @@ -194,6 +196,25 @@ 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; + unsigned long 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(((clk_rate / 1000) * DEF_FSOURCE), 1000000) + 1; + strobe_prog = ((clk_rate * 10) / 1000000) + 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) { @@ -220,7 +241,10 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, } /* Setup the write timing values */ - imx_ocotp_set_imx6_timing(priv); + if (priv->params->mx7_timing) + imx_ocotp_set_imx7_timing(priv); + else + imx_ocotp_set_imx6_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. @@ -373,11 +397,36 @@ static struct nvmem_config imx_ocotp_nvmem_config = { }; static const struct octp_params params[] = { - { .nregs = 128, .banked = false, .regs_per_bank = 0}, - { .nregs = 64, .banked = false, .regs_per_bank = 0}, - { .nregs = 128, .banked = false, .regs_per_bank = 0}, - { .nregs = 128, .banked = false, .regs_per_bank = 0}, - { .nregs = 64, .banked = true, .regs_per_bank = 4}, + { + .nregs = 128, + .banked = false, + .regs_per_bank = 0, + .mx7_timing = false + }, + { + .nregs = 64, + .banked = false, + .regs_per_bank = 0, + .mx7_timing = false + }, + { + .nregs = 128, + .banked = false, + .regs_per_bank = 0, + .mx7_timing = false + }, + { + .nregs = 128, + .banked = false, + .regs_per_bank = 0, + .mx7_timing = false + }, + { + .nregs = 64, + .banked = true, + .regs_per_bank = 4, + .mx7_timing = true + }, }; static const struct of_device_id imx_ocotp_dt_ids[] = {