Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4681137pxb; Tue, 2 Nov 2021 13:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtEEClJ7YdZCXrg++1g9mnPSAcPY4xAh3YPjAOSBZmqT3S/1en/PyZgWCJHw1YhB8JBrq5 X-Received: by 2002:a92:d03:: with SMTP id 3mr27189945iln.216.1635886570654; Tue, 02 Nov 2021 13:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635886570; cv=none; d=google.com; s=arc-20160816; b=oYkQ+cQZJJwThnbwXf40+RRJXbuoxg/buQ+slJfW8Gijgok0wZoJaVg9PUjzteNHlV SbrhLuGUvivzfmpdUgX4uCcnGSrQMdkiqY7WePj9RcGmEZWY7rqkV/nH8Ps0G74eiuDM RqBJRa0E3bID1XFiX/XfS6niNXhyW5nrdKJ5W/yGDEI9ZyKEP2E+MQALpBrvBUmFUp4N uVsGK2ndk/pYM+g1JrCLMdePwGLSlrdGsuMiBiqY2+As+INDxpyFltQjROri65cJ7PUU UgMZ77F+BrCCx96vlcjtXLfZoZCNsWv0rCtU54ysYqKMT48kK/UdfL5SiSz+H2k9dYjX kZaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gERsJMVABVtxtxpf/8lRy5+N9W0xbVKjOyfkXHhnMQs=; b=KStIQTJwAiXmC0JR3Wab+q1WOGVSJ/8sEbeB3WuvM8ma7XdyPs4TA32CWH7eYPz9X1 ORMZQDPcy4uzHHFsoEgxWF8VCprqccoDwi1GfOOZxWfVCaALw86fj66gNXXKXmVYxsyn KypJNmMJ16DNtnpgZSU7aA12B9Rlkfe20yg1vEgvgf5oFzxixGtrHSPoztiW/JgcKtWl 2HRtsdkZBqxDxhxoYvqk3g6zkTthYJLqcjJmwlWTcZfCoVFD0MQatpDDqO23bAmgSrol +ga+NwZ2OAHLrnS/sKlZAZ9dasLuX542FQ8sayyYJ2rKWZvI48vrzHU91gk/nOUq9qCS oXzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si28060jac.29.2021.11.02.13.55.59; Tue, 02 Nov 2021 13:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbhKBU51 (ORCPT + 99 others); Tue, 2 Nov 2021 16:57:27 -0400 Received: from mailout10.rmx.de ([94.199.88.75]:51886 "EHLO mailout10.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbhKBU5Y (ORCPT ); Tue, 2 Nov 2021 16:57:24 -0400 X-Greylist: delayed 1986 seconds by postgrey-1.27 at vger.kernel.org; Tue, 02 Nov 2021 16:57:24 EDT Received: from kdin02.retarus.com (kdin02.dmz1.retloc [172.19.17.49]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout10.rmx.de (Postfix) with ESMTPS id 4HkLsJ0bxbz33G7; Tue, 2 Nov 2021 21:21:40 +0100 (CET) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin02.retarus.com (Postfix) with ESMTPS id 4HkLrz3xN8z2TTHk; Tue, 2 Nov 2021 21:21:23 +0100 (CET) Received: from N95HX1G2.arri.de (192.168.54.19) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 2 Nov 2021 21:21:22 +0100 From: Christian Eggers To: Michael Trimarchi , Miquel Raynal , Stefan Riedmueller , Han Xu , Greg Ungerer CC: Sascha Hauer , Christian Hemp , Boris Brezillon , Richard Weinberger , Vignesh Raghavendra , , , Christian Eggers , "Stefan Riedmueller" , Subject: [PATCH 2/2] gpmi-nand: Add ERR007117 protection for nfc_apply_timings Date: Tue, 2 Nov 2021 21:20:22 +0100 Message-ID: <20211102202022.15551-2-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211102202022.15551-1-ceggers@arri.de> References: <20211102202022.15551-1-ceggers@arri.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.54.19] X-RMX-ID: 20211102-212123-kxqJGwhBvLjf-0@out02.hq X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gpmi_io clock needs to be gated off when changing the parent/dividers of enfc_clk_root (i.MX6Q/i.MX6UL) respectively qspi2_clk_root (i.MX6SX). Otherwise this rate change can lead to an unresponsive GPMI core which results in DMA timeouts and failed driver probe: [ 4.072318] gpmi-nand 112000.gpmi-nand: DMA timeout, last DMA ... [ 4.370355] gpmi-nand 112000.gpmi-nand: Chip: 0, Error -110 ... [ 4.375988] gpmi-nand 112000.gpmi-nand: Chip: 0, Error -22 [ 4.381524] gpmi-nand 112000.gpmi-nand: Error in ECC-based read: -22 [ 4.387988] gpmi-nand 112000.gpmi-nand: Chip: 0, Error -22 [ 4.393535] gpmi-nand 112000.gpmi-nand: Chip: 0, Error -22 ... Other than stated in i.MX 6 erratum ERR007117, it should be sufficient to gate only gpmi_io because all other bch/nand clocks are derived from different clock roots. The i.MX6 reference manuals state that changing clock muxers can cause glitches but are silent about changing dividers. But tests showed that these glitches can definitely happen on i.MX6ULL. For i.MX7D/8MM in turn, the manual guarantees that no glitches can happen when changing dividers. Co-developed-by: Stefan Riedmueller Signed-off-by: Stefan Riedmueller Signed-off-by: Christian Eggers Cc: stable@vger.kernel.org --- Changelog: ----------- RFC --> v1 - added comment about clock divider behavior on the different i.MX series - perform clock gating also on i.MX6SX - only gate gpmi_io clock. Other GPMI/BCH clocks are not affected when ENFC_CLK_ROOT divides are changes - add error checking for clk_set_rate() - Cc: stable@vger.kernel.org drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index a1f7000f033e..6e9f7d80ef8b 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -713,14 +713,32 @@ static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this, (use_half_period ? BM_GPMI_CTRL1_HALF_PERIOD : 0); } -static void gpmi_nfc_apply_timings(struct gpmi_nand_data *this) +static int gpmi_nfc_apply_timings(struct gpmi_nand_data *this) { struct gpmi_nfc_hardware_timing *hw = &this->hw; struct resources *r = &this->resources; void __iomem *gpmi_regs = r->gpmi_regs; unsigned int dll_wait_time_us; + int ret; + + /* Clock dividers do NOT guarantee a clean clock signal on its output + * during the change of the divide factor on i.MX6Q/UL/SX. On i.MX7/8, + * all clock dividers provide these guarantee. + */ + if (GPMI_IS_MX6Q(this) || GPMI_IS_MX6SX(this)) + clk_disable_unprepare(r->clock[0]); + + ret = clk_set_rate(r->clock[0], hw->clk_rate); + if (ret) { + dev_err(this->dev, "cannot set clock rate to %lu Hz: %d\n", hw->clk_rate, ret); + return ret; + } - clk_set_rate(r->clock[0], hw->clk_rate); + if (GPMI_IS_MX6Q(this) || GPMI_IS_MX6SX(this)) { + ret = clk_prepare_enable(r->clock[0]); + if (ret) + return ret; + } writel(hw->timing0, gpmi_regs + HW_GPMI_TIMING0); writel(hw->timing1, gpmi_regs + HW_GPMI_TIMING1); @@ -739,6 +757,8 @@ static void gpmi_nfc_apply_timings(struct gpmi_nand_data *this) /* Wait for the DLL to settle. */ udelay(dll_wait_time_us); + + return 0; } static int gpmi_setup_interface(struct nand_chip *chip, int chipnr, @@ -2271,7 +2291,9 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip, */ if (this->hw.must_apply_timings) { this->hw.must_apply_timings = false; - gpmi_nfc_apply_timings(this); + ret = gpmi_nfc_apply_timings(this); + if (ret) + return ret; } dev_dbg(this->dev, "%s: %d instructions\n", __func__, op->ninstrs); -- Christian Eggers Embedded software developer Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918 Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477 Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler