From patchwork Wed Jun 26 10:27:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 167793 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp760317ilk; Wed, 26 Jun 2019 03:28:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfigf8MhM7o9a87H8pNuy08IIA1Iv4wtdWAfB69kVYeduBcnSJEkZOL2E6iNGIa4/X8m7Z X-Received: by 2002:a63:fe13:: with SMTP id p19mr2265491pgh.359.1561544893942; Wed, 26 Jun 2019 03:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561544893; cv=none; d=google.com; s=arc-20160816; b=Qnw3mNFayrp2YT8lg9AbfRYtIDqSAfuqK2eQQEdWgpGx5CSEOTn9+WN4HRJ3eCjO51 OD9JsG3L43nATO4kuAqChEYAT54uZiyA+afARzDQy1teA98/ptlZJMkif1DsBpshPgXI mqmmPPHP5G+bLu9CwB0nX74zGK7yfMPIL8fM4o1r9ioXcMNSz7i8jcTOsfnPeYGZkxvL 0O4yhmDlUdbqW9XHJKUxdHKj1kciyHkCrXaer95SWjQcYVZmuOirSN2/WP1OnxL81auW 4GC9/o8yYNKLF25XsZmQNajCisF72iBxgSrMeIyxtRDVzvotTMsCLafymEoMbYF0ki4I 1Fvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q2uYpOpXs+pbPux8Et5aQ4qoOceeJiTpOWIeON9aqJw=; b=yOwumfHdphLqeBZ53aGLP6KTcjjzu4pzNR+CNGn/zUJiIcz27Vvr/tcycWle1bUpa0 dbSw8Qrm4z6PKDoyzDE1SMsw+dWs+3M91uWguPgygCj/Cz39gMf3f+9u2gP8sKSgp8Gp Xs/yBXdoipVY0wwWC0ZLgzHj47a+HtIs2oD1k0IZh8NqdaaT6uFdfFiiYRHpFzTGj3co QJ+6aNi62br97QzBxcJKPSSPobxlBXiJnxbJNOYgKzS9zLnCrZ3/+rBNMrZMNfEt4hgA oUkqWBuQ4tk6Qvl/9JwqN0+MAmqVf9DAKp+LaquTUpkOTeTyCbcO5xjdGwVMAyNh7Y6c oCpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKbBdaaG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si3068839plb.407.2019.06.26.03.28.13; Wed, 26 Jun 2019 03:28:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKbBdaaG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbfFZK2I (ORCPT + 30 others); Wed, 26 Jun 2019 06:28:08 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34110 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727127AbfFZK2G (ORCPT ); Wed, 26 Jun 2019 06:28:06 -0400 Received: by mail-wr1-f67.google.com with SMTP id k11so2126784wrl.1 for ; Wed, 26 Jun 2019 03:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q2uYpOpXs+pbPux8Et5aQ4qoOceeJiTpOWIeON9aqJw=; b=TKbBdaaGYBpQghXpwDdVwuYb2eCWIDnI0Lq2bX+5Ha7ssWcmvOzVFnhTmq7RY7F16j 3i7coj0QCT3zQ3ystfb83L4SINRepuK4shd6GTXtBWTQ3M81th5gOmuB1aces34W8oqi XrpOYvnk6LNfhvIwp44XXW8jCEy6FLEt0J/KQBAIhGBLt0xL5JQR3fKTxMUjomnxVfPx VBdOjiimLfLkrbfAObkmp8FdRuZ+y7cqEKd7UQHhieS7xDaBotVrBkFIL1zfQ1bkV2pQ eIUIfb7Nm85ZDgU5lkZZWG64qigVpgceTPCphe/S4LtxEaWbqQrvZpnlvzlnyTICxriQ LSYg== 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:mime-version:content-transfer-encoding; bh=Q2uYpOpXs+pbPux8Et5aQ4qoOceeJiTpOWIeON9aqJw=; b=VHfYvc4k4wbUTgT12pRfRcVcaQqWYOg5Ifski1zrwP8U7pDpfjDmV4v98o3EvaLoW7 KSAa7C6aOa+mZa/9AjThQzY+ampkCEHuzoRAU8YCKLk2XQ4N5nCEafwsM7TQTD3CZVSc gfD1IS3jOlJ3ElR2vYOov/aNambpzXsmw3O0kDN58T6Yk9/DSmoklC7k909H0bi3DlnS cudMp7MSgxReEeQHQ887xwDLJ25m04J0mqqtgFBueCKdGSu8qAYK24ZQikiQSNGqNIlc ZXWjrS6YLLAObN6iR+qbJgAiLB4SmsV4MH97Rup/nwe7OGe7mRP5ctCSlZq3n+m7Zf4B ryJA== X-Gm-Message-State: APjAAAV21XquVePq4+DsPf1AJg70QfpcmqsA3yGOypB9dn84v74nBT8o XX73mFWJOz+Q/Iu+Ail6oKMXGg== X-Received: by 2002:adf:e490:: with SMTP id i16mr3068418wrm.280.1561544883691; Wed, 26 Jun 2019 03:28:03 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id z19sm2212042wmi.7.2019.06.26.03.28.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 26 Jun 2019 03:28:03 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Bryan O'Donoghue , Leonard Crestez , Srinivas Kandagatla Subject: [PATCH 3/6] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Date: Wed, 26 Jun 2019 11:27:30 +0100 Message-Id: <20190626102733.11708-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190626102733.11708-1-srinivas.kandagatla@linaro.org> References: <20190626102733.11708-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bryan O'Donoghue The RELAX field of the OCOTP block is turning out as a zero on i.MX8MM. This messes up the subsequent re-load of the fuse shadow registers. After some discussion with people @ NXP its clear we have missed a trick here in Linux. The OCOTP fuse programming time has a physical minimum 'burn time' that is not related to the ipg_clk. We need to define the RELAX, STROBE_READ and STROBE_PROG fields in terms of desired timings to allow for the burn-in to safely complete. Right now only the RELAX field is calculated in terms of an absolute time and we are ending up with a value of zero. This patch inherits the u-boot timings for the OCOTP_TIMING calculation on the i.MX6 and i.MX8. Those timings are known to work and critically specify values such as STROBE_PROG as a minimum timing. Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support") Signed-off-by: Bryan O'Donoghue Suggested-by: Leonard Crestez Reviewed-by: Leonard Crestez Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/imx-ocotp.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) -- 2.21.0 diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index f4e117bbf2c3..b7dacf53c715 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -44,7 +44,9 @@ #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 -#define DEF_RELAX 20 /* > 16.5ns */ +#define TIMING_STROBE_PROG_US 10 /* Min time to blow a fuse */ +#define TIMING_STROBE_READ_NS 37 /* Min time before read */ +#define TIMING_RELAX_NS 17 #define DEF_FSOURCE 1001 /* > 1000 ns */ #define DEF_STROBE_PROG 10000 /* IPG clocks */ #define IMX_OCOTP_WR_UNLOCK 0x3E770000 @@ -176,12 +178,38 @@ static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) * 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. + * + * Note: there are minimum timings required to ensure an OTP fuse burns + * correctly that are independent of the ipg_clk. Those values are not + * formally documented anywhere however, working from the minimum + * timings given in u-boot we can say: + * + * - Minimum STROBE_PROG time is 10 microseconds. Intuitively 10 + * microseconds feels about right as representative of a minimum time + * to physically burn out a fuse. + * + * - Minimum STROBE_READ i.e. the time to wait post OTP fuse burn before + * performing another read is 37 nanoseconds + * + * - Minimum RELAX timing is 17 nanoseconds. This final RELAX minimum + * timing is not entirely clear the documentation says "This + * count value specifies the time to add to all default timing + * parameters other than the Tpgm and Trd. It is given in number + * of ipg_clk periods." where Tpgm and Trd refer to STROBE_PROG + * and STROBE_READ respectively. What the other timing parameters + * are though, is not specified. Experience shows a zero RELAX + * value will mess up a re-load of the shadow registers post OTP + * burn. */ 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; + relax = DIV_ROUND_UP(clk_rate * TIMING_RELAX_NS, 1000000000) - 1; + strobe_read = DIV_ROUND_UP(clk_rate * TIMING_STROBE_READ_NS, + 1000000000); + strobe_read += 2 * (relax + 1) - 1; + strobe_prog = DIV_ROUND_CLOSEST(clk_rate * TIMING_STROBE_PROG_US, + 1000000); + strobe_prog += 2 * (relax + 1) - 1; timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000; timing |= strobe_prog & 0x00000FFF;