From patchwork Tue Oct 24 09:54:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 116923 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp405645edm; Tue, 24 Oct 2017 02:57:06 -0700 (PDT) X-Received: by 10.159.198.9 with SMTP id f9mr6890971plo.74.1508839026398; Tue, 24 Oct 2017 02:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508839026; cv=none; d=google.com; s=arc-20160816; b=bhqYn8NapvilkhcjOkj43X8OQpXRttxOeHG3xEqffta64vvYi7fl8So/YbFv7ICaft 3ScreYg4Gd1sNt0RKReqsb1VRjV4VjX9XcHfT493fqfamxyG300Hs8QHYowAaszZO3EP OEAAcPPVJAJBx84jEsDZ/6HfkRcS7FLGbot+FCjtjqXSiRfVlHQElkob9LsOZSRdmWyL STuBYfEpChGVL51UayxLNngWDdpeK72XfDHYAYbvyZ4Er9VCYZCzyUADYjraGZ7kauj/ NrBfoD7Ujt0R77liIxLjwyVKqhvLq+1T19CF/2Eo4BqXe1kzAi5s2LxTbLpu+85eH1Mj qCYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/q6CmKPqmFf8JsQtsNDnoenlF5Mh26sEfR7rkgdG9no=; b=FztIIhlYcaI3f9WS59TszQqtQ3ECOxSk8+KgqYX6T5AFoRT0hfVoFUmPldkfgPFyu0 WhzzY0jCHMpvAgCRh7nmjHHBXWPCjWIPGWk9f2SkVn7p7fz8kf9g/Vv7VMUNH3Mxwa/2 hzyaLKgHdx5WxsSXEJHbm+qyfTMPCLuOwyFFAc/SqlH4/okFnetrVXDIV6JYp8wi1eq3 z/R1YNNJdIji/qAKK6pqScC4NX8NM5W49NY3MZsqCYvYhzbGFNrNPUdiV/CX5HzYDf2e qBVtovyjopExS/KSU4n0SuHbGDZyY+DHXzAxSqYw1yfgTTIvKG++B4AslySWF5PSQ2R9 zZuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zy7HhukE; 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 g8si5099262plt.780.2017.10.24.02.57.06; Tue, 24 Oct 2017 02:57:06 -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=Zy7HhukE; 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 S932474AbdJXJ5E (ORCPT + 27 others); Tue, 24 Oct 2017 05:57:04 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:44566 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932267AbdJXJ4v (ORCPT ); Tue, 24 Oct 2017 05:56:51 -0400 Received: by mail-wm0-f65.google.com with SMTP id 196so11588169wma.1 for ; Tue, 24 Oct 2017 02:56:51 -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; bh=/q6CmKPqmFf8JsQtsNDnoenlF5Mh26sEfR7rkgdG9no=; b=Zy7HhukEEoy/a4xZ2hsy6QTSCeXm66awHfwYR+JHkqc0cYEA62n2qBlATiEW6YG/4O fxSGCrD2vCLIIsv24ROUCe13YDm9ubgoCS/8iOvjTCoouKu61O94ypsqb8DRwhuReY6L 3Avtk0pf8nBr9lRY9W4qkb8W81aDwVvGp31F0= 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=/q6CmKPqmFf8JsQtsNDnoenlF5Mh26sEfR7rkgdG9no=; b=jlP8AXG4RBMniw5aNvnE2fvSqbm7wwYBflSbibYpQ4/ZVIFG7rtnyiFHFPn8kPHC7H ZwYUg8gRyIIqm8mcuDGFY5pb6/7bHplsGHGUClw2TJffLbTvqhyWDnedkegE/715NrzN e0A5aowfT5hoVuMHmKfOeIxq/NEiJE5e1H8PTAR71VSKcQhVEFbvdHR4xFo2JYFK/7Wy cPmDBl84vi6hSZz48EYRZVPL+1a2bdUybc6GB0p+eyeM+9de/1bMc9tlaCcvvCIn0TFR kc+wv13BinUtwrWsml3OgKSE2QvX1aRgkbBWB8k3zlVCVtjDCM+4yG2O5DkpeaGsVsxY aMlg== X-Gm-Message-State: AMCzsaV7dA/cnm7Iw+IDJMke+TYra3o6rzhHSDFodOtJPDIOFht8UC/O lJZk5W+h1SevX/h0hiys5zOtvg== X-Google-Smtp-Source: ABhQp+TiMeMc7p82S/68TDPRTzpCFrw+U7m9LDIQwQo2Qm7dsEolNBfreDvV3oFllmVXhXifXbZTOQ== X-Received: by 10.28.217.136 with SMTP id q130mr7430025wmg.89.1508839010253; Tue, 24 Oct 2017 02:56:50 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id 29sm9666451wrz.77.2017.10.24.02.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Oct 2017 02:56:49 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Bryan O'Donoghue , Srinivas Kandagatla Subject: [PATCH 06/10] nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function Date: Tue, 24 Oct 2017 10:54:30 +0100 Message-Id: <1508838874-32252-7-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508838874-32252-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1508838874-32252-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bryan O'Donoghue 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 Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/imx-ocotp.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) -- 1.9.1 diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e10a0da..93d3cb5 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.