From patchwork Wed Apr 24 20:26:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 10915717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 372111390 for ; Wed, 24 Apr 2019 20:26:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23A0928816 for ; Wed, 24 Apr 2019 20:26:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1746D28A00; Wed, 24 Apr 2019 20:26:58 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 9B59E28816 for ; Wed, 24 Apr 2019 20:26:57 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=cF2aOBmHHyoDDo/3OMC6lym5k8z02e9xUzN+X9GJZdQ=; b=XIeBmDxyXX/p9p +8gzPpmazRi71cZ9CwbDw3fofpFhfRCN1C2b4LmOoHuPJQ06Ec/LGXCuDgxIVYbbqyup0z9jz78Ug kPQGY7ox0rsR5GiB/EaolRb+SNEQ9Cm0n1FZ/9pTTXwKjq98lBXb7VroNjGtWV0oU9P1Ic8VQI0OJ kqaQMHPWrF5xHfmENOmy4CMYo9t4rwQpnuz6rFJGALL27r0mDwGyd5gymtrvmhUleMgKt7oA70YvF 8bngjr0e1vZC8P9BNqhxCYM58SX757NMKWmPKLPujpqPLBYrubOYrmdhn+mjyBuvjcXSYdaHM2tou wY6glYddw8Use6Alhtig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJOTj-0002A0-Ny; Wed, 24 Apr 2019 20:26:51 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJOT9-0001a0-F0 for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2019 20:26:16 +0000 Received: by mail-ed1-x541.google.com with SMTP id d46so17119685eda.7 for ; Wed, 24 Apr 2019 13:26:15 -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 :mime-version:content-transfer-encoding; bh=JidMEU/Hl+MLH6YoI6qqyR5hGcY61IYq8nE9qtsEigg=; b=wVM/8s3befJ9yCE7/lucmtbLjPcTzI6F8vvpKOJy57o4M8il/KhrsPIfXNbr0RnYJy mzj+tWz5r11Kv+8G7ohFCDcpCITjDJsIZQNaZ+7BIvfiSdoRQdBj6XfZmFiRPokZtt7c QUWmV4Q2LtgV/DugrNk2YxVZXfnyejBcGleSc4d+XU6bjWog4SZlR1d3TKx/d9fp+ljr HqI98MQrJH6LoZ1iVaHNkPQ3NVeBKBFaYdhQnc2jAmsxnsv4MLox6Mk3u8z2sDpz15ad ONM8175KBbnONcScKT2wQJRF+9ubpu+7Oywh/p9kidy2ZK8/gpzawEwK9GRILDcHQF+j +YoA== 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=JidMEU/Hl+MLH6YoI6qqyR5hGcY61IYq8nE9qtsEigg=; b=mnoEkUyYC44kLv+2XHTopSa0r3DKOHTriz2AD0/t9daDsWKdTNzXtw7+8FbMPiqRx2 /3/Nt7v/XjEtTAArKcZooddqum1wHIgtcGFsByNmdrrY0FcCJ1VQtFVc1R7af3FHIhBl OY5EATpnAPDi45q6c4806+fJwC83SefJmPRkDIo6eZmlBxUGN8DeMGQAxbJVWMKhHutM eJoKWhz2B3ZAnOGxdB1neGib1j2jxAxP1SsaSLgEROh3Jz6VvhEeUTAOf6Z7U+8WtCC+ 8M/yNu2ClQn9zT/TjAhrH6uyg80/IGfVuWwYCWV1352hng1C1CFr97ccgP4L9yXpTkrC FAQA== X-Gm-Message-State: APjAAAXUAYFHptP3WIxwsbGCGL+2hSCc29vUON1mhhYITyQsB13E3svq xY58/XuzyNQOShjwT0dk85X3Cw== X-Google-Smtp-Source: APXvYqw8s8bKYtRijMLru+U/xwvjpa6gNB0LfrpI39cL+L6KcJQ5+6OFPok81Pd6/7ZQNeFa00ObKQ== X-Received: by 2002:a50:b69c:: with SMTP id d28mr21587137ede.126.1556137574192; Wed, 24 Apr 2019 13:26:14 -0700 (PDT) Received: from event-horizon.net ([80.111.179.123]) by smtp.gmail.com with ESMTPSA id c26sm3728988eja.86.2019.04.24.13.26.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 13:26:13 -0700 (PDT) From: Bryan O'Donoghue To: l.stach@pengutronix.de, peng.fan@nxp.com, shawnguo@kernel.org, srinivas.kandagatla@linaro.org, leonard.crestez@nxp.com Subject: [PATCH v5 3/5] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Date: Wed, 24 Apr 2019 21:26:05 +0100 Message-Id: <20190424202607.23522-4-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424202607.23522-1-pure.logic@nexus-software.ie> References: <20190424202607.23522-1-pure.logic@nexus-software.ie> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190424_132615_512200_043AD3AB X-CRM114-Status: GOOD ( 15.11 ) 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: aisheng.dong@nxp.com, abel.vesa@nxp.com, anson.huang@nxp.com, linux-imx@nxp.com, kernel@pengutronix.de, fabio.estevam@nxp.com, Bryan O'Donoghue , linux-arm-kernel@lists.infradead.org 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 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 --- drivers/nvmem/imx-ocotp.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 85a7d0da3abb..826812d3332f 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -50,7 +50,9 @@ #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 -#define DEF_RELAX 20 /* > 16.5ns */ +#define BV_TIMING_STROBE_PROG_US 10 /* Min time to blow a fuse */ +#define BV_TIMING_STROBE_READ_NS 37 /* Min time before read */ +#define BV_TIMING_RELAX_NS 17 #define DEF_FSOURCE 1001 /* > 1000 ns */ #define DEF_STROBE_PROG 10000 /* IPG clocks */ #define IMX_OCOTP_WR_UNLOCK 0x3E770000 @@ -182,12 +184,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 * BV_TIMING_RELAX_NS, 1000000000) - 1; + strobe_read = DIV_ROUND_UP(clk_rate * BV_TIMING_STROBE_READ_NS, + 1000000000); + strobe_read += 2 * (relax + 1) - 1; + strobe_prog = DIV_ROUND_CLOSEST(clk_rate * BV_TIMING_STROBE_PROG_US, + 1000000); + strobe_prog += 2 * (relax + 1) - 1; timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000; timing |= strobe_prog & 0x00000FFF;