Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp344392ybh; Wed, 18 Mar 2020 00:44:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtw4RXTOi+k1MXZiddCA6BstFxhyEeV1OYBVnzMC7Y7y53s2LLgK9GoHA5/X3RsioTTr0g0 X-Received: by 2002:aca:acc2:: with SMTP id v185mr2212692oie.27.1584517440168; Wed, 18 Mar 2020 00:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584517440; cv=none; d=google.com; s=arc-20160816; b=whspT6+uQigJQ69khgpTASueFA4SOq2dbwlzMzChbecJ5x/oKTzvQ2f5rK2uuKSk/g 9aMjQ5m5ya6YXcy/UjEWx1pfD+zX4/VbXy9cSc5voyrJ4wlwNAxFuwZl/KjpdhDwVXrz otkyPJTE0TJYOsFm8/Dz77mO4F3i6Nv9nFP+k40PirT3EOmcN8hm39jbRoZuMTvjyuH2 xayqPqiiGSIodP2Po+0XznTUHjGeN+Mp8/ZnjVHGjLVqiNYFdrOj47GScz76bugDrxWf vXL0KUJX4zC+Y9PxqptHAVO3jayjodchnkVaAr6izb5HmlvHdtrx+DvhnYgIK2+I/T3C cGwQ== 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=1rTM67ITl9yjtq3L9iupxE9h6yi2OpCAs2NyBMZSWo0=; b=NcHO8bpjk0qlpRXwuql/QyYfmL4rBKGUFKeQPTAZYeOiRUGT/JSA2Q0/sfH7FHvnq7 kaOihFBW5tUHbEXzukvipZ4J69eXv/jungvJENC9gLkeBrAlbiXvIOUUxAEjQ3vwqA6Y /nufcEmEakbv/pwkqGNx2G78lYxaE/4tPl7cBSwRE2tzqVq+HJavWEzbfvNzymlWU6CG 43AfZTk6Ys19ThIP5XdTYmvw5pv5Kz2N7C1Sh7Kfg0BNTWQDpiipvu8fCW9hG84RZRjK +OAp3f0sFgZ0NgL9FxHYb5+gpr8KdOoo47sUprdqx2n50SUTm2JYO1NqzLqRv7Z5FQUs 9c+g== 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 l12si3060999otn.101.2020.03.18.00.43.48; Wed, 18 Mar 2020 00:44:00 -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 S1727314AbgCRHms (ORCPT + 99 others); Wed, 18 Mar 2020 03:42:48 -0400 Received: from twhmllg4.macronix.com ([211.75.127.132]:57395 "EHLO TWHMLLG4.macronix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgCRHmr (ORCPT ); Wed, 18 Mar 2020 03:42:47 -0400 Received: from localhost.localdomain ([172.17.195.96]) by TWHMLLG4.macronix.com with ESMTP id 02I7gTOB041137; Wed, 18 Mar 2020 15:42:31 +0800 (GMT-8) (envelope-from masonccyang@mxic.com.tw) From: Mason Yang To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, bbrezillon@kernel.org Cc: frieder.schrempf@kontron.de, tglx@linutronix.de, stefan@agner.ch, juliensu@mxic.com.tw, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, allison@lohutok.net, linux-mtd@lists.infradead.org, yuehaibing@huawei.com, Mason Yang Subject: [PATCH v4 2/2] mtd: rawnand: macronix: Add support for deep power down mode Date: Wed, 18 Mar 2020 15:42:28 +0800 Message-Id: <1584517348-14486-3-git-send-email-masonccyang@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1584517348-14486-1-git-send-email-masonccyang@mxic.com.tw> References: <1584517348-14486-1-git-send-email-masonccyang@mxic.com.tw> X-MAIL: TWHMLLG4.macronix.com 02I7gTOB041137 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Macronix AD series support deep power down mode for a minimum power consumption state. Overload nand_suspend() & nand_resume() in Macronix specific code to support deep power down mode. Signed-off-by: Mason Yang --- drivers/mtd/nand/raw/nand_macronix.c | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c index 3ff7ce0..756c175 100644 --- a/drivers/mtd/nand/raw/nand_macronix.c +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -6,11 +6,14 @@ * Author: Boris Brezillon */ +#include "linux/delay.h" #include "internals.h" #define MACRONIX_READ_RETRY_BIT BIT(0) #define MACRONIX_NUM_READ_RETRY_MODES 6 +#define MXIC_CMD_POWER_DOWN 0xB9 + struct nand_onfi_vendor_macronix { u8 reserved; u8 reliability_func; @@ -91,6 +94,76 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) ONFI_FEATURE_ADDR_TIMING_MODE, 1); } +static 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(MXIC_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, MXIC_CMD_POWER_DOWN, -1, -1); + } + + return 0; +} + +static int mxic_nand_suspend(struct nand_chip *chip) +{ + int ret; + + nand_select_target(chip, 0); + ret = nand_power_down_op(chip); + if (ret < 0) + pr_err("Suspending MXIC NAND chip failed (%d)\n", ret); + nand_deselect_target(chip); + + return ret; +} + +static void mxic_nand_resume(struct nand_chip *chip) +{ + /* + * Toggle #CS pin to resume NAND device and don't care + * of the others CLE, #WE, #RE pins status. + * A NAND controller ensure it is able to assert/de-assert #CS + * by sending any byte over the NAND bus. + * i.e., + * NAND power down command or reset command w/o R/B# status checking. + */ + nand_select_target(chip, 0); + nand_power_down_op(chip); + /* The minimum of a recovery time tRDP is 35 us */ + usleep_range(35, 100); + nand_deselect_target(chip); +} + +static void macronix_nand_deep_power_down_support(struct nand_chip *chip) +{ + int i; + static const char * const deep_power_down_dev[] = { + "MX30UF1G28AD", + "MX30UF2G28AD", + "MX30UF4G28AD", + }; + + i = match_string(deep_power_down_dev, ARRAY_SIZE(deep_power_down_dev), + chip->parameters.model); + if (i < 0) + return; + + chip->suspend = mxic_nand_suspend; + chip->resume = mxic_nand_resume; +} + static int macronix_nand_init(struct nand_chip *chip) { if (nand_is_slc(chip)) @@ -98,6 +171,7 @@ static int macronix_nand_init(struct nand_chip *chip) macronix_nand_fix_broken_get_timings(chip); macronix_nand_onfi_init(chip); + macronix_nand_deep_power_down_support(chip); return 0; } -- 1.9.1