Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2860491pxv; Mon, 12 Jul 2021 03:48:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8lIAPadB0dnHIztz8HcPxHYb6abXUZVpTRo8GGG0ch83X8CT/7VcZcWVOw9UCZ6kJs2lp X-Received: by 2002:a5d:85c1:: with SMTP id e1mr38209681ios.18.1626086939261; Mon, 12 Jul 2021 03:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626086939; cv=none; d=google.com; s=arc-20160816; b=Mg+sKHlWwWrxBhWVrFDJ+y3eIDaMJo4ThDEsVxviXAIuPHxsI0XACM1FeB42EF5fSl 7HFnN7Ud8KUFJc5vwVwnNTKzM+zJnS+JiJXFoZJdnh+iRrCS4SWRNx6dbdJQwEQXbtdS wj4u/nkZ+OG9y7toSgwsVM9DGLHmld8LxnZZ+SSvmX1+juHw332XU0DP2KpBAR6aOUPC xbM8uq0f0cjPkknl49si8bE8338py1nvrQpJQT+AoALHUczFRJENdOu6R8GuqEsfr/x2 wcvN4du33eysR0DiKhK0+VUvzsEu2BXUxh3h4Ee7wVjieGSLlHaQj9xtcMekS4SjL2SR 3rvw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VZ2N8e1pDpTdaP9RV7IdfHnwNmc9GR+iqQbE3Cg2fag=; b=aqs5mmIYWtIWRrISxvfvogt8qihl0VhFG5wkCoQfu7kCNeDe9x49OU7DGQ2EUqJYcm BiDvRfOnSOFUff7MfEL3IgtQM56y17xWeN8Ah+avJgUnzPU2+Q0mOha22vBEmJj1sJ20 oUYDoEON0uREoj1OJI8l3o64PEpyd/wPzxEMdMsO0LKNzMBk7XRtTB2+OsZ1GRyTk6Ay L3MoiUXVKOyxU78MUXRC22S4A2pK+n4g7HGi0g9w6PIwJ2AImoJGNH7uFegJEzRafOS2 7nopkTPV4N0s9Xs5FKwbTeQNzu3L98FJqQJxs/4tz/zt1TfPHjnqQiGfkAlzX+XKv9g9 pV9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l3iaD0uM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si19280711ilj.44.2021.07.12.03.48.47; Mon, 12 Jul 2021 03:48:59 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l3iaD0uM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352959AbhGLIAr (ORCPT + 99 others); Mon, 12 Jul 2021 04:00:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:33590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241456AbhGLHWh (ORCPT ); Mon, 12 Jul 2021 03:22:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2875261167; Mon, 12 Jul 2021 07:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626074389; bh=sPibL6mmZB96dURXwzcDpgE9/GwXMbOuMLhYsqDbWvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3iaD0uMf/peE1ctimBiEhyiQYnNEuFwFokv8mMK5ExRcXSiWgHjs9wZ9FmFBYOSR 043kCtsaqPPKdYQYk6aVZvLO0ZyXHCEx0gn0U+rRLG3hrXSTovn2fpXEh6dn+oypmP +WiyuwAEqBvdlHBc+COhcOrpq2ChDvBZ6WwZu0PA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miquel Raynal , Sasha Levin Subject: [PATCH 5.12 563/700] mtd: rawnand: arasan: Ensure proper configuration for the asserted target Date: Mon, 12 Jul 2021 08:10:46 +0200 Message-Id: <20210712061036.105983370@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miquel Raynal [ Upstream commit b5437c7b682c9a505065b4ab4716cdc951dc3c7c ] The controller being always asserting one CS or the other, there is no need to actually select the right target before doing a page read/write. However, the anfc_select_target() helper actually also changes the timing configuration and clock in the case were two different NAND chips with different timing requirements would be used. In this situation, we must ensure proper configuration of the controller by calling it. As a consequence of this change, the anfc_select_target() helper is being moved earlier in the driver. Fixes: 88ffef1b65cf ("mtd: rawnand: arasan: Support the hardware BCH ECC engine") Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20210526093242.183847-4-miquel.raynal@bootlin.com Signed-off-by: Sasha Levin --- drivers/mtd/nand/raw/arasan-nand-controller.c | 90 ++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c index 549aac00228e..390f8d719c25 100644 --- a/drivers/mtd/nand/raw/arasan-nand-controller.c +++ b/drivers/mtd/nand/raw/arasan-nand-controller.c @@ -273,6 +273,37 @@ static int anfc_pkt_len_config(unsigned int len, unsigned int *steps, return 0; } +static int anfc_select_target(struct nand_chip *chip, int target) +{ + struct anand *anand = to_anand(chip); + struct arasan_nfc *nfc = to_anfc(chip->controller); + int ret; + + /* Update the controller timings and the potential ECC configuration */ + writel_relaxed(anand->timings, nfc->base + DATA_INTERFACE_REG); + + /* Update clock frequency */ + if (nfc->cur_clk != anand->clk) { + clk_disable_unprepare(nfc->controller_clk); + ret = clk_set_rate(nfc->controller_clk, anand->clk); + if (ret) { + dev_err(nfc->dev, "Failed to change clock rate\n"); + return ret; + } + + ret = clk_prepare_enable(nfc->controller_clk); + if (ret) { + dev_err(nfc->dev, + "Failed to re-enable the controller clock\n"); + return ret; + } + + nfc->cur_clk = anand->clk; + } + + return 0; +} + /* * When using the embedded hardware ECC engine, the controller is in charge of * feeding the engine with, first, the ECC residue present in the data array. @@ -401,6 +432,18 @@ static int anfc_read_page_hw_ecc(struct nand_chip *chip, u8 *buf, return 0; } +static int anfc_sel_read_page_hw_ecc(struct nand_chip *chip, u8 *buf, + int oob_required, int page) +{ + int ret; + + ret = anfc_select_target(chip, chip->cur_cs); + if (ret) + return ret; + + return anfc_read_page_hw_ecc(chip, buf, oob_required, page); +}; + static int anfc_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf, int oob_required, int page) { @@ -461,6 +504,18 @@ static int anfc_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf, return ret; } +static int anfc_sel_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf, + int oob_required, int page) +{ + int ret; + + ret = anfc_select_target(chip, chip->cur_cs); + if (ret) + return ret; + + return anfc_write_page_hw_ecc(chip, buf, oob_required, page); +}; + /* NAND framework ->exec_op() hooks and related helpers */ static int anfc_parse_instructions(struct nand_chip *chip, const struct nand_subop *subop, @@ -753,37 +808,6 @@ static const struct nand_op_parser anfc_op_parser = NAND_OP_PARSER( NAND_OP_PARSER_PAT_WAITRDY_ELEM(false)), ); -static int anfc_select_target(struct nand_chip *chip, int target) -{ - struct anand *anand = to_anand(chip); - struct arasan_nfc *nfc = to_anfc(chip->controller); - int ret; - - /* Update the controller timings and the potential ECC configuration */ - writel_relaxed(anand->timings, nfc->base + DATA_INTERFACE_REG); - - /* Update clock frequency */ - if (nfc->cur_clk != anand->clk) { - clk_disable_unprepare(nfc->controller_clk); - ret = clk_set_rate(nfc->controller_clk, anand->clk); - if (ret) { - dev_err(nfc->dev, "Failed to change clock rate\n"); - return ret; - } - - ret = clk_prepare_enable(nfc->controller_clk); - if (ret) { - dev_err(nfc->dev, - "Failed to re-enable the controller clock\n"); - return ret; - } - - nfc->cur_clk = anand->clk; - } - - return 0; -} - static int anfc_check_op(struct nand_chip *chip, const struct nand_operation *op) { @@ -1007,8 +1031,8 @@ static int anfc_init_hw_ecc_controller(struct arasan_nfc *nfc, if (!anand->bch) return -EINVAL; - ecc->read_page = anfc_read_page_hw_ecc; - ecc->write_page = anfc_write_page_hw_ecc; + ecc->read_page = anfc_sel_read_page_hw_ecc; + ecc->write_page = anfc_sel_write_page_hw_ecc; return 0; } -- 2.30.2