From patchwork Sun Oct 8 22:41:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 9992067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 994CC60244 for ; Sun, 8 Oct 2017 22:50:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 854E428639 for ; Sun, 8 Oct 2017 22:50:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79AE42863D; Sun, 8 Oct 2017 22:50:33 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 F3F8E28639 for ; Sun, 8 Oct 2017 22:50:32 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=BNMYD+4hcgSnOL5pFMcGtmbDCsJ2/sVQKsltzrdx6xM=; b=LTdmKJjOvvQQCvGc13U7GF17xE 3jGdSJHGgoxNT+g826X12SNwI72eMcgPcoH+6Z9hoLKYwPUo1ebPIV4sTUmjKsL//HYnStVf7ngwD T+z3p3fnb7W42o9iaHyEnsYrdHQdxJ96+kM34NbARvgEJ07gOGzVuJ5iXepv66cL9eBoGTybIpFyv G7l9xqgg3SJj79kHA+tFmRLT5t3hGi1vhS/xGBYlyG7v008J1EiVjZMYVf7vNq9mER+Dmk7DA3pls HQCuaihkarNzm8AKc68T7vzNI8cqN8K3i/TxKScClcfkz6zezgjW3DZToVaa+O+uTDGe3/oersE/W U1laeN9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e1KOh-0001Mx-52; Sun, 08 Oct 2017 22:50:11 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e1KGd-0003kr-Ev for linux-arm-kernel@lists.infradead.org; Sun, 08 Oct 2017 22:41:54 +0000 Received: by mail-wm0-x22c.google.com with SMTP id t69so18105536wmt.2 for ; Sun, 08 Oct 2017 15:41:30 -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; bh=wyoedpHeuuK0Wx48JlYnSPGQMt5IB2kSkQPLXlVz9K4=; b=Bunb2I7nqW3WkFHlU/LoR6GXqwRRWN3PJ4q82Pwq6H6pDqc8XLMdphfvUCtYDRmHb3 emotP0PRFZjiiqBhIss6l9LXU27VtEOXo/p/rquRey73Jcn3NLiGLRPqz3z8pqDrUhrC I79MzSd58c4AXCKwhbUKLTUT3zoY8EV3GCDjOmD0ItYoTjO7DWk9ZuUBY9S0EjdZIo6r tCVtX6uzjYdxf6FL5+nA4YcVw/XSOBZ7rUmhRmQNuW0RDG8PieIyRF7rqE89qMtkqe7+ hiHQgZ/C+IBmHlTvbQC+I/ROCptn6sZtNniN0LB3eDL4yXQc00BzOijvP0GEEn9HMPUa DlCw== 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=wyoedpHeuuK0Wx48JlYnSPGQMt5IB2kSkQPLXlVz9K4=; b=SLmSQa8hBaTsligDxD9PPwaraRRVqC97UxSihmfNewNm/NRa8AFNOgTtYCIibiQO5r SjBo58Fs0+qJ3WNHWcID6bLJZfmecKa8NRpeR3cwaeAiKeXMUgGwV0qaAaJZADN4LaFS 6tFli0jkh5k2XN2686EWrJLjWDuacPmzHzqPzjeQTCNtxzNgUwQ0JM426erOkBHZU4Ea opFdcCBeboqHY53qNiWDWpT1RenV5kYHXeucqlD0xWSHVZnkz580QZDp8fdbQSEbxze9 kmVJi6iXMxt6TncR/XBW4ppiWE/kPFoqYUJvJQdYrA8CsgBd2SQg/6ApMeN+9yclwhbw 2NFA== X-Gm-Message-State: AMCzsaUkZFdaTJhtRwqwO9kugPLMXeIKOXtpebbvnScWwuRfj2r8eSdU gNQeLp8ZOjsskIMr87H2WiEm5A== X-Google-Smtp-Source: AOwi7QDNQKKk/TpUO25xWA8AGjmX/ozkMjNuuM9lJ7bWAKFIBQPxBXWOR4kAkl2OydV7ZHhtd8jbHw== X-Received: by 10.80.150.69 with SMTP id y63mr11776675eda.75.1507502489402; Sun, 08 Oct 2017 15:41:29 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id g45sm432909eda.19.2017.10.08.15.41.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Oct 2017 15:41:28 -0700 (PDT) From: Bryan O'Donoghue To: p.zabel@pengutronix.de, richard.leitner@skidata.com, srinivas.kandagatla@linaro.org, axel.lin@ingics.com, ping.bai@nxp.com, d.schultz@phytec.de, peng.fan@nxp.com, van.freenix@gmail.com Subject: [PATCH v2 5/7] nvmem: imx-ocotp: Add i.MX7D timing write clock setup support Date: Sun, 8 Oct 2017 23:41:20 +0100 Message-Id: <1507502482-22518-6-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507502482-22518-1-git-send-email-pure.logic@nexus-software.ie> References: <1507502482-22518-1-git-send-email-pure.logic@nexus-software.ie> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171008_154151_758191_B1E7622B X-CRM114-Status: GOOD ( 15.53 ) 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: Bryan O'Donoghue , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 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 --- drivers/nvmem/imx-ocotp.c | 65 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 74c2f15..f80aee9 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -51,16 +51,12 @@ #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 #define DEF_RELAX 20 /* > 16.5ns */ +#define DEF_FSOURCE 1001 #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 +65,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 +195,25 @@ 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; + unsigned long 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(((clk_rate / 1000) * DEF_FSOURCE), 1000000) + 1; + strobe_prog = ((clk_rate * 10) / 1000000) + 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 +240,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. @@ -371,12 +392,32 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .reg_write = imx_ocotp_write, }; -static const struct octop_params params[] = { - { .nregs = 128, .bank_address_words = 0 }, - { .nregs = 64, .bank_address_words = 0 }, - { .nregs = 128, .bank_address_words = 0 }, - { .nregs = 128, .bank_address_words = 0 }, - { .nregs = 64, .bank_address_words = 4 }, +static const struct ocotp_params params[] = { + { + .nregs = 128, + .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, + }, + { + .nregs = 64, + .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, + }, + { + .nregs = 128, + .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, + }, + { + .nregs = 128, + .bank_address_words = 0, + .set_timing = imx_ocotp_set_imx6_timing, + }, + { + .nregs = 64, + .bank_address_words = 4, + .set_timing = imx_ocotp_set_imx7_timing, + }, }; static const struct of_device_id imx_ocotp_dt_ids[] = {