From patchwork Tue Oct 24 09:54:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 116927 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp406373edm; Tue, 24 Oct 2017 02:58:14 -0700 (PDT) X-Received: by 10.99.3.21 with SMTP id 21mr13885928pgd.77.1508839094849; Tue, 24 Oct 2017 02:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508839094; cv=none; d=google.com; s=arc-20160816; b=QV/jN7TkNL//v/+ozAtozVXPv7h6UFRLZ6G6cTh/Tj0PnRBsMjuieFF6ExbcJtCiil BudOqH6nKIvBA6C94zeZU7WqFYbFsmTgTIec0xAxWUcgiRatTnDGnfQNrlLxM47Q05Y0 9+uzWeYfXgMgDAlxGU7KHrs/PtBbayCwH3fdNeewTVPzOWsNOVEhiL4vMo6MU8Zo/2Ou KYrFMS4QJRJexVwD8PzKlq+umIKuz3jevgPHAwlO6udbrNLuQIdjFzUi/390gkxijS0T BNgWQFzds6Mlhvf1hGeO1E0ZLwggG2zTkRRiDOosMvNFg7xqFfs+kSWHouCYRt9KeW6O L3dA== 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=d01alMV7QYFXQpiyCMHF/guPbQC1jkujXxb3Y6EbCwA=; b=wKJjhoar8FFSqMrUM2piCPZ97QF+EUdi4q8YlfU1R1MEUhjnjuPCpFh+g4UXRjuaSR w12XTf9AuMq7r1qpT5iJQydSgXdq1mv+7fibhzr1OlRPTGD9Sx8XC0IBxMiKBN6rqsmy 9QlzwjD9kqS10cmeDNiYLI4dVz1bx+/mJ2l9J2nkBaGAE9QwMGjHSFZJ0qOwYIpu+tbD 2VemdbVGBBc7xa9iFs5scVbAllCW4yfiH/Rc10ogs4Rguqq/bvPH08lEqGk+u+JfL7bv 5Z6TSKeZ11Laxi18BCog5YDDcZ7iXIaA3Vp86bnnouOFT7ZnWNIsZiqRfIasAHUuNtgw S8CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P36Zhh2k; 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 u86si6841976pfg.210.2017.10.24.02.58.14; Tue, 24 Oct 2017 02:58:14 -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=P36Zhh2k; 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 S932525AbdJXJ6M (ORCPT + 27 others); Tue, 24 Oct 2017 05:58:12 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:53976 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932337AbdJXJ4w (ORCPT ); Tue, 24 Oct 2017 05:56:52 -0400 Received: by mail-wm0-f66.google.com with SMTP id r196so2123514wmf.2 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=d01alMV7QYFXQpiyCMHF/guPbQC1jkujXxb3Y6EbCwA=; b=P36Zhh2kHGTicje/O9TF3O7O1lqxja1T+82bnPKQNF2J5e1P0nGflRxotThz4jEsnO XCWKR/CkoD0JwwBC0Z76EX1jvKjS4yzSvxLTx4Pv9v9DIVUKfvXB5PYBgYHi9EG1ugYJ udRX56FKLRsWwEavGHyHoPOdMZMVVSKyzbfZI= 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=d01alMV7QYFXQpiyCMHF/guPbQC1jkujXxb3Y6EbCwA=; b=ryuO5OrECDazWHl/RuUAjaHqKYlvVtuRV9FnqaKRLe/UnQQrOLAVPWIZQ5BDaeOf8G vSqCSI3DJx3NvKtNaXR33JTlLmxzbDhcpHUPfii4VFqXu0d27Lwlu6U11BHbYdIsj67h hjDSyECriWy+Dpq7wxt7+ixD1wcGnFBCtE3PuN458c/neDOhyIXLMao0AFCrNS2J18z2 Sk1THklu8E3XlYgoKJOkM/KZXdDzdolJBaNhSzx1IstsnRMrNfuU4zUXWVqJAwlwayBF 3jl08w7WrakOunPkQnHyi2tW+L/Gt7GnudwDjNXXHh5mAZtmtQtzGqVu5gfDXZpO6YVJ OR9A== X-Gm-Message-State: AMCzsaW5qOEsDt2NhrogrxxKp31IhEwe9xB+gUX9hNwTxKCXNZfhH+7F ez0HnsY46zw45bbMbrn1uSPV8MoUcho= X-Google-Smtp-Source: ABhQp+SxpWdeYmV6SYS9w04mSl3U1pPX1mfVVjaG3dimyk5hLjzDoqrlY6/PpX4f1CWzA3HOZO6AVw== X-Received: by 10.28.206.142 with SMTP id e136mr7375058wmg.27.1508839011071; Tue, 24 Oct 2017 02:56:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Oct 2017 02:56:50 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Bryan O'Donoghue , Srinivas Kandagatla Subject: [PATCH 07/10] nvmem: imx-ocotp: Add i.MX7D timing write clock setup support Date: Tue, 24 Oct 2017 10:54:31 +0100 Message-Id: <1508838874-32252-8-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 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 Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/imx-ocotp.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) -- 1.9.1 diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 93d3cb5..be8d002 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -50,17 +50,14 @@ #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 -#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_FSOURCE 1001 /* > 1000 ns */ +#define DEF_STROBE_PROG 10000 /* IPG clocks */ #define IMX_OCOTP_WR_UNLOCK 0x3E770000 #define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA static DEFINE_MUTEX(ocotp_mutex); -struct ocotp_params { - unsigned int nregs; - unsigned int bank_address_words; -}; - struct ocotp_priv { struct device *dev; struct clk *clk; @@ -69,6 +66,12 @@ struct ocotp_priv { struct nvmem_config *config; }; +struct ocotp_params { + unsigned int nregs; + unsigned int bank_address_words; + void (*set_timing)(struct ocotp_priv *priv); +}; + static int imx_ocotp_wait_for_busy(void __iomem *base, u32 flags) { int count; @@ -193,6 +196,27 @@ 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; + u64 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_ULL((u64)clk_rate * DEF_FSOURCE, + NSEC_PER_SEC) + 1; + strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG, + NSEC_PER_SEC) + 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) { @@ -219,7 +243,7 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, } /* Setup the write timing values */ - imx_ocotp_set_imx6_timing(priv); + priv->params->set_timing(priv); /* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. @@ -377,26 +401,31 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val, static const struct ocotp_params imx6q_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sl_params = { .nregs = 64, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6sx_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx6ul_params = { .nregs = 128, .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, }; static const struct ocotp_params imx7d_params = { .nregs = 64, .bank_address_words = 4, + .set_timing = imx_ocotp_set_imx7_timing, }; static const struct of_device_id imx_ocotp_dt_ids[] = {