Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1836691imm; Mon, 3 Sep 2018 10:42:04 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+fE2BEe9l9JzQ6dX6+DpaMHCZez0SQvm3EqJaFF2FmPhwUo+ejmHnhLuX+6JpdypniLAh X-Received: by 2002:a63:24c4:: with SMTP id k187-v6mr22499746pgk.162.1535996524250; Mon, 03 Sep 2018 10:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996524; cv=none; d=google.com; s=arc-20160816; b=ywsdgjw0Dmvy0ZgBW8F5/rFO4inhvUZJR/Wqw1KL3Bwkk4pHXSQW4CszpHG3r45Hhy deewN/YoAf0E8N/5c4A2N/o/7YCKZ2HLebV9gtXq1/cDsj7HXkg7i6gx6p/42HVEdLxK l9fIzAD513tSM/Z3EiWrb4PHVfi/yo6iZEUhfcoQnmyEcU0Hm3nuutgV4aODhhnK4Ngm F7u3yvSGIYB9c8Qk8NV/WRoU10wTJXhjfMJg7O9zy07dLKIhcpMuPuTVI8OtZNK8xd4+ pAwnmd2CshEhk4fuX3PSodslaekHBP8Vqtx1EeS1843hwik2IfpLEKhnS4QO4HJGi7CG KaDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kT754rxrXE4jee7vOpN9ULCiGykvt5Yzkk8Hec7VBoI=; b=wgITWBz7Vy+wW0ZS1DFC46kz5MLmih0MOcl9AYPcF2rvgJ3utgjo0swYP0gc0Dog/I ql0dme7+F5XIP5tKX+97RGsmMDup6TUoiaacVovpjc+NuBXI/zFjWAfGcx3ABg6J31u3 9s56Xk8zTZvmmVxTZFm5Hcs6SMHb7jGQNZxtGsD/J9QENLuBgNcYVG9531Ou8AoaSc3R /br3Su2z4b1C5N1Y5tbKOTRzKOelEoA4RgozHX0x7e2KpywaAvqMOabAykz/p/5TRbjN 6ToKyIYHz9f9TKxyvn01knURC2jWlrE/2zTHe0Gqfe1khZXoyPkdorI3/W+BFgReX44g RTIA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3-v6si18373548plc.502.2018.09.03.10.41.49; Mon, 03 Sep 2018 10:42:04 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732039AbeICWBw (ORCPT + 99 others); Mon, 3 Sep 2018 18:01:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49412 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727466AbeICWBw (ORCPT ); Mon, 3 Sep 2018 18:01:52 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 481BFBC4; Mon, 3 Sep 2018 17:40:40 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Mack , Miquel Raynal Subject: [PATCH 4.18 113/123] mtd: rawnand: marvell: add suspend and resume hooks Date: Mon, 3 Sep 2018 18:57:37 +0200 Message-Id: <20180903165724.283945860@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Mack commit bd9c3f9b3c00da322b5e784e820533f1598f690a upstream. This patch restores the suspend and resume hooks that the old driver used to have. Apart from stopping and starting the clocks, the resume callback also nullifies the selected_chip pointer, so the next command that is issued will re-select the chip and thereby restore the timing registers. Factor out some code from marvell_nfc_init() into a new function marvell_nfc_reset() and also call it at resume time to reset some registers that don't retain their contents during low-power mode. Without this patch, a PXA3xx based system would cough up an error similar to the one below after resume. [ 44.660162] marvell-nfc 43100000.nand-controller: Timeout waiting for RB signal [ 44.671492] ubi0 error: ubi_io_write: error -110 while writing 2048 bytes to PEB 102:38912, written 0 bytes [ 44.682887] CPU: 0 PID: 1417 Comm: remote-control Not tainted 4.18.0-rc2+ #344 [ 44.691197] Hardware name: Marvell PXA3xx (Device Tree Support) [ 44.697111] Backtrace: [ 44.699593] [] (dump_backtrace) from [] (show_stack+0x18/0x1c) [ 44.708931] r7:00000800 r6:00009800 r5:00000066 r4:c6139000 [ 44.715833] [] (show_stack) from [] (dump_stack+0x20/0x28) [ 44.724206] [] (dump_stack) from [] (ubi_io_write+0x3d4/0x630) [ 44.732925] [] (ubi_io_write) from [] (ubi_eba_write_leb+0x690/0x6fc) ... Fixes: 02f26ecf8c77 ("mtd: nand: add reworked Marvell NAND controller driver") Cc: stable@vger.kernel.org Signed-off-by: Daniel Mack Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/raw/marvell_nand.c | 73 ++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) --- a/drivers/mtd/nand/raw/marvell_nand.c +++ b/drivers/mtd/nand/raw/marvell_nand.c @@ -2677,6 +2677,21 @@ static int marvell_nfc_init_dma(struct m return 0; } +static void marvell_nfc_reset(struct marvell_nfc *nfc) +{ + /* + * ECC operations and interruptions are only enabled when specifically + * needed. ECC shall not be activated in the early stages (fails probe). + * Arbiter flag, even if marked as "reserved", must be set (empirical). + * SPARE_EN bit must always be set or ECC bytes will not be at the same + * offset in the read page and this will fail the protection. + */ + writel_relaxed(NDCR_ALL_INT | NDCR_ND_ARB_EN | NDCR_SPARE_EN | + NDCR_RD_ID_CNT(NFCV1_READID_LEN), nfc->regs + NDCR); + writel_relaxed(0xFFFFFFFF, nfc->regs + NDSR); + writel_relaxed(0, nfc->regs + NDECCCTRL); +} + static int marvell_nfc_init(struct marvell_nfc *nfc) { struct device_node *np = nfc->dev->of_node; @@ -2715,17 +2730,7 @@ static int marvell_nfc_init(struct marve if (!nfc->caps->is_nfcv2) marvell_nfc_init_dma(nfc); - /* - * ECC operations and interruptions are only enabled when specifically - * needed. ECC shall not be activated in the early stages (fails probe). - * Arbiter flag, even if marked as "reserved", must be set (empirical). - * SPARE_EN bit must always be set or ECC bytes will not be at the same - * offset in the read page and this will fail the protection. - */ - writel_relaxed(NDCR_ALL_INT | NDCR_ND_ARB_EN | NDCR_SPARE_EN | - NDCR_RD_ID_CNT(NFCV1_READID_LEN), nfc->regs + NDCR); - writel_relaxed(0xFFFFFFFF, nfc->regs + NDSR); - writel_relaxed(0, nfc->regs + NDECCCTRL); + marvell_nfc_reset(nfc); return 0; } @@ -2840,6 +2845,51 @@ static int marvell_nfc_remove(struct pla return 0; } +static int __maybe_unused marvell_nfc_suspend(struct device *dev) +{ + struct marvell_nfc *nfc = dev_get_drvdata(dev); + struct marvell_nand_chip *chip; + + list_for_each_entry(chip, &nfc->chips, node) + marvell_nfc_wait_ndrun(&chip->chip); + + clk_disable_unprepare(nfc->reg_clk); + clk_disable_unprepare(nfc->core_clk); + + return 0; +} + +static int __maybe_unused marvell_nfc_resume(struct device *dev) +{ + struct marvell_nfc *nfc = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(nfc->core_clk); + if (ret < 0) + return ret; + + if (!IS_ERR(nfc->reg_clk)) { + ret = clk_prepare_enable(nfc->reg_clk); + if (ret < 0) + return ret; + } + + /* + * Reset nfc->selected_chip so the next command will cause the timing + * registers to be restored in marvell_nfc_select_chip(). + */ + nfc->selected_chip = NULL; + + /* Reset registers that have lost their contents */ + marvell_nfc_reset(nfc); + + return 0; +} + +static const struct dev_pm_ops marvell_nfc_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(marvell_nfc_suspend, marvell_nfc_resume) +}; + static const struct marvell_nfc_caps marvell_armada_8k_nfc_caps = { .max_cs_nb = 4, .max_rb_nb = 2, @@ -2924,6 +2974,7 @@ static struct platform_driver marvell_nf .driver = { .name = "marvell-nfc", .of_match_table = marvell_nfc_of_ids, + .pm = &marvell_nfc_pm_ops, }, .id_table = marvell_nfc_platform_ids, .probe = marvell_nfc_probe,