Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6366606ybe; Wed, 18 Sep 2019 02:13:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPuEzsgZjuG2fiHKffiy1q4GHblUL45Q4A72oHjuQGVp143Q6Paim5u3z3+Lp/qmMNfxcX X-Received: by 2002:a17:906:2311:: with SMTP id l17mr8547771eja.12.1568797997609; Wed, 18 Sep 2019 02:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568797997; cv=none; d=google.com; s=arc-20160816; b=JDgtKtxCRNR5/KZaKdTUYxfqSsELKvgHyNIiKMS4BoRbaqkcoK69f+kYxzAamdREpa 0m2UOrrFCfX+1cyTsmLvgdzNFVGIJcn43k9Io+mzcUCtdqjBZfpohpU+3WVmgk8OVIac cCrtmG49OPOQ3jjwkWAs4trtRRUywVxZln7u7y2MI2CpERbwZyOiDdywrqlXtpb8Gfxa s/M4++uQMre9PriszQzqVAxl2uv++F1GXxf/6SnsatoRF6p9QgEt1bsjonpaTmDxmTHF //I1KEUEqnPWlwUwonQjc/aVqOlXSW2pcGvEk4FSUTygFSKPFoLdyV7ch1TKJK8sjJvi /Yrg== 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; bh=kQrDlI0RwyyjC0l8/E+0Tdgl+4SmTxzdif3ubGvzjiI=; b=UfXA+St5U/I9s8JUHuHySBECBPUDKlkx3cdVGbO2czn34EigxSqhSUlHnqINgiW3nj +RPq+KyLi6+m8xu9Sm98byZ2tVH7OmsO7BZZPUF9vtFa8VRnKdqgs7mIwROIxRUJOupu 2EvD8TK+c6iujPMzOTJ9J7LuCHXRpHtEmS9OjcVWIwbbL6Zo9N7j1fhVZVScFPO+JDcE cGKwucf3a1lJIhw2N+svsb1jCWakVfkUkkW3UQ2ILZZQuYNEgek0olIUoRG4fGAMK45p Ze1/MEBPr04Y0zrqykdPdJdSK5wRqixBriYOqFsMkMHtmtJiRjedaJDCJvjpGenBFKSC 7MjQ== 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 y8si2987956edd.355.2019.09.18.02.12.54; Wed, 18 Sep 2019 02:13:17 -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 S1729103AbfIRHcG (ORCPT + 99 others); Wed, 18 Sep 2019 03:32:06 -0400 Received: from twhmllg3.macronix.com ([122.147.135.201]:18814 "EHLO TWHMLLG3.macronix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbfIRHcG (ORCPT ); Wed, 18 Sep 2019 03:32:06 -0400 Received: from localhost.localdomain ([172.17.195.96]) by TWHMLLG3.macronix.com with ESMTP id x8I7VoOf060926; Wed, 18 Sep 2019 15:31:52 +0800 (GMT-8) (envelope-from masonccyang@mxic.com.tw) From: Mason Yang To: miquel.raynal@bootlin.com, richard@nod.at, marek.vasut@gmail.com, dwmw2@infradead.org, bbrezillon@kernel.org, computersforpeace@gmail.com, vigneshr@ti.com Cc: marcel.ziswiler@toradex.com, juliensu@mxic.com.tw, linux-kernel@vger.kernel.org, frieder.schrempf@kontron.de, gregkh@linuxfoundation.org, linux-mtd@lists.infradead.org, masonccyang@mxic.com.tw, tglx@linutronix.de Subject: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode Date: Wed, 18 Sep 2019 15:56:26 +0800 Message-Id: <1568793387-25199-3-git-send-email-masonccyang@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1568793387-25199-1-git-send-email-masonccyang@mxic.com.tw> References: <1568793387-25199-1-git-send-email-masonccyang@mxic.com.tw> X-MAIL: TWHMLLG3.macronix.com x8I7VoOf060926 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Macronix AD series support using power down command to enter a minimum power consumption state. MTD default _suspend/_resume function replacement by manufacturer postponed initialization. Signed-off-by: Mason Yang --- drivers/mtd/nand/raw/nand_macronix.c | 78 +++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c index 991c636..99a7b2e 100644 --- a/drivers/mtd/nand/raw/nand_macronix.c +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -15,6 +15,8 @@ #define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38 #define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0 +#define NAND_CMD_POWER_DOWN 0xB9 + struct nand_onfi_vendor_macronix { u8 reserved; u8 reliability_func; @@ -78,6 +80,12 @@ static void macronix_nand_onfi_init(struct nand_chip *chip) "MX30UF4G28AC", }; +static const char * const nand_power_down[] = { + "MX30LF1G28AD", + "MX30LF2G28AD", + "MX30LF4G28AD", +}; + static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) { unsigned int i; @@ -144,8 +152,64 @@ static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) return ret; } +int nand_power_down_op(struct nand_chip *chip) +{ + int ret; + + if (nand_has_exec_op(chip)) { + struct nand_op_instr instrs[] = { + NAND_OP_CMD(NAND_CMD_POWER_DOWN, 0), + }; + + struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); + + ret = nand_exec_op(chip, &op); + if (ret) + return ret; + + } else { + chip->legacy.cmdfunc(chip, NAND_CMD_POWER_DOWN, -1, -1); + } + + return 0; +} + +static int mxic_nand_suspend(struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + + mutex_lock(&chip->lock); + + nand_select_target(chip, 0); + nand_power_down_op(chip); + nand_deselect_target(chip); + + chip->suspend = 1; + mutex_unlock(&chip->lock); + + return 0; +} + +static void mxic_nand_resume(struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + + mutex_lock(&chip->lock); + // toggle #CS pin to resume NAND device + nand_select_target(chip, 0); + ndelay(20); + nand_deselect_target(chip); + + if (chip->suspend) + chip->suspended = 0; + else + pr_err("%s call for a chip which is not in suspended state\n", + __func__); + mutex_unlock(&chip->lock); +} + /* - * Macronix AC series support using SET/GET_FEATURES to change + * Macronix AC and AD series support using SET/GET_FEATURES to change * Block Protection and Unprotection. * * MTD call-back function replacement by manufacturer postponed @@ -163,6 +227,18 @@ static void macronix_nand_post_init(struct nand_chip *chip) } } + for (i = 0; i < ARRAY_SIZE(nand_power_down); i++) { + if (!strcmp(nand_power_down[i], chip->parameters.model)) { + blockprotected = 1; + break; + } + } + + if (i < ARRAY_SIZE(nand_power_down)) { + mtd->_suspend = mxic_nand_suspend; + mtd->_resume = mxic_nand_resume; + } + if (blockprotected && chip->parameters.supports_set_get_features) { bitmap_set(chip->parameters.set_feature_list, ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); -- 1.9.1