From patchwork Thu Apr 25 13:34:25 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: 10917095 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 2861E14C0 for ; Thu, 25 Apr 2019 13:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1770928AC8 for ; Thu, 25 Apr 2019 13:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0961A28AD0; Thu, 25 Apr 2019 13:35:22 +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 8E16C28AC8 for ; Thu, 25 Apr 2019 13:35:21 +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=UnilqLhGzxplW3+5igZnxkTZUdlHfQtq88ZZG4wXP1M=; b=QZHsyBFSolZvYx 9SXIRfgKFun/NnOWCPa0/2vbspeLlOk9XadTHRbiwHKHRTHacdbuQsln/SrRHI8CWWCLE/sowZoCU 0srfPTOP6Cm20yQq+tvliZwE5nt6XR7lUNhU2IyAh6DvelaAj2P6pNPl2W+Na+wMqDeKlxk+hqu3W gmWBUPGLJi3H170DqqHEWG2CcMcLSLI0EhcPd9b1D1hM/9PW/PM1pckRybK3SrDD7i3z6ooaFH5CG iXNUJUyZmN1N86UnYzHv3W+y0QEHc0TEpDih6eoXY2Udc1HiwFI28MPIX3E8aRY0TeJ8WKhujsjyy Rjl0VNUB9qL4ND0LYqkQ==; 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 1hJeWx-0008Ki-PR; Thu, 25 Apr 2019 13:35:15 +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 1hJeWK-0006SA-9F for linux-arm-kernel@lists.infradead.org; Thu, 25 Apr 2019 13:34:38 +0000 Received: by mail-ed1-x541.google.com with SMTP id d46so19169016eda.7 for ; Thu, 25 Apr 2019 06:34:35 -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=CYID9mOljtZzAjb8BGV3ItGDunuSSt6iBRER3TaRlB0=; b=0TJrK5VEI9BG51ZVVo7ZlLubzVKdXsPShfprkWHdh9mkrt3ER6BySeVajxe5q8sXTa Eg4RwlOgFKAlhIMEnUSAu49OvZBoZZzcN5lLgLQCEg+FQHjMOZ4CcioQbop1/kyqmbV4 VUykBDH3OLjctVNcsxKnA54Qfs7TlDqXERY6ClytMeoDuSzwZ6riUT6yao2QJ+zhzBXl g0XVdrZia4wVk4lwmvRTyJWrwh4ilwzuhBq7k9v1khws+YCTbYC6lq6SIIIOhOUPKRs8 cHppj9SMJEimSwNhnKC68M2T2t/W87uT/6lHuPPdW6rIvpoMP7y43dwwYAT4MR+Ksj2R VAxg== 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=CYID9mOljtZzAjb8BGV3ItGDunuSSt6iBRER3TaRlB0=; b=YZI79333jR9Ir/zf42eUyeSU4FvPjPCAo7rYexhoUp8Fu6Ky/fsuG8NeBFD9CsgC6G SAqjlCZi1bTMcBI6ArRhaoa1db9wwYYi5cEt/q9M1KUTyjyCOW7EBr59jXM4gb2AFBMY udZAt5RZdOJlFhSRqDn57wJMaSilmPA4tvmQtPBQVvyQR+04fh0G9JJe9dLoTs5owK2s bvCY0IxDcf12gt5OiQZE20BdhfTua3PxgUYnB4h8bYXczmkb2NxLo04747m2ECZQpaEi zv4bbadZEUr90ME1Trgu/WAwkm6GoWk6klNOmzvf5u5Q4MeBxsPEIi2FV7ORVAwO67BZ DAWQ== X-Gm-Message-State: APjAAAW9u+ltFKpmc2jg9i9XlItewmflktwqw8JAQLdi/vLkslI9jN5Z AJq+p+AagbgLgB+QJIps7D2kfA== X-Google-Smtp-Source: APXvYqy95a8yCE/uka7bH0oDYXAnhQQfXRJEdoVTT9Fu7jIZqnM8gyEyzLacUM1tveBAIbyoL/Sk4A== X-Received: by 2002:aa7:d6d3:: with SMTP id x19mr769564edr.67.1556199273949; Thu, 25 Apr 2019 06:34:33 -0700 (PDT) Received: from event-horizon.net ([80.111.179.123]) by smtp.gmail.com with ESMTPSA id k20sm4027084edb.9.2019.04.25.06.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 06:34:33 -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 v6 3/5] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Date: Thu, 25 Apr 2019 14:34:25 +0100 Message-Id: <20190425133427.30648-4-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190425133427.30648-1-pure.logic@nexus-software.ie> References: <20190425133427.30648-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-20190425_063436_327060_A98CF55D 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..2c5009691dd6 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 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 @@ -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 * 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;