Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3114488ybf; Mon, 2 Mar 2020 23:22:13 -0800 (PST) X-Google-Smtp-Source: ADFU+vsH2sbwSsvDeAk+6HG/i0SlAzcyGFdJMQMpA++ARV4fbSa86ql5CEAFUWi1vAuFM21iuWg/ X-Received: by 2002:a9d:443:: with SMTP id 61mr2152738otc.357.1583220133403; Mon, 02 Mar 2020 23:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583220133; cv=none; d=google.com; s=arc-20160816; b=cQvP4pk5JxpLp8XMTwdrUFF5lCH6jY2IZ1wGHhpaeH3NJSpoLbOzAM/Tstw2iywYUl re66hJ0vYJWpZuvSYPjvWeUlCREaffCJL/NGmB2WzWVb3oL+ZJ0rNlDHWxklUWAdc9FU EGMXmO7CViifq143AuobFNBwIj2tzHzLwo6C+k0cR/OMeasC3PO/H6C2IEHo0ipzX7xU OJTxaVsx74Yw4pYy9pGCWaaztRYujP6ItEdmDhwGADgdsAULKevTYueVc3IJs5m2B8Ds /nthrmVZOpT72vP/n+vcFtIG5gdIE2uQXy0kmRaEilbw3V5DIoCF2aaqdaOG1l0iy/F1 +FhQ== 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=DQ0rpDWkzz39cFhbkgVmp23aDE9oErhpkpSFiOwAB48=; b=k3w+qtKHZgOR1+0FPsPHBg5H4UBO/JiljnxHhhKdbfM7gPtk2gO/Sqhi/3WU2QKd/q c7JEYyBpVzHfTmnzjchsok7B0oBT63SkiZIxd+N99ZcmDJa7N/nBuQu5WmpyC6c2pwed p2avAjDHGLSbonML54l0ea7E+17iiNTvGKY4giIw+SOvL18o0NynWk8WxDukoit7lwK5 mGZOhX9NaJUgWHW20RWszNIDBZiRZHTRsg8ZB00auizvAQicSIW+Njc2DKLwuKl9oIFK 5DV2tSj5elIv9cDy3pN/cfrvc8NZYEvOroCqEC1P7iJdP83chFmzqtq5TEcce+4CVRS4 XnCA== 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 l23si1631326otj.144.2020.03.02.23.22.01; Mon, 02 Mar 2020 23:22:13 -0800 (PST) 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 S1727591AbgCCHVv (ORCPT + 99 others); Tue, 3 Mar 2020 02:21:51 -0500 Received: from twhmllg3.macronix.com ([211.75.127.131]:31755 "EHLO TWHMLLG3.macronix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727571AbgCCHVu (ORCPT ); Tue, 3 Mar 2020 02:21:50 -0500 Received: from localhost.localdomain ([172.17.195.96]) by TWHMLLG3.macronix.com with ESMTP id 0237LRLA023026; Tue, 3 Mar 2020 15:21:29 +0800 (GMT-8) (envelope-from masonccyang@mxic.com.tw) From: Mason Yang To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Cc: frieder.schrempf@kontron.de, tglx@linutronix.de, stefan@agner.ch, juliensu@mxic.com.tw, allison@lohutok.net, linux-kernel@vger.kernel.org, bbrezillon@kernel.org, rfontana@redhat.com, linux-mtd@lists.infradead.org, yuehaibing@huawei.com, s.hauer@pengutronix.de, Mason Yang Subject: [PATCH v3 1/4] mtd: rawnand: Add support manufacturer specific lock/unlock operation Date: Tue, 3 Mar 2020 15:21:21 +0800 Message-Id: <1583220084-10890-2-git-send-email-masonccyang@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1583220084-10890-1-git-send-email-masonccyang@mxic.com.tw> References: <1583220084-10890-1-git-send-email-masonccyang@mxic.com.tw> X-MAIL: TWHMLLG3.macronix.com 0237LRLA023026 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add nand_lock() & nand_unlock() for manufacturer specific lock & unlock operation while the device supports Block Portection function. Signed-off-by: Mason Yang Reported-by: kbuild test robot Reviewed-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 36 ++++++++++++++++++++++++++++++++++-- include/linux/mtd/rawnand.h | 5 +++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index f64e3b6..769be81 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4360,6 +4360,38 @@ static void nand_shutdown(struct mtd_info *mtd) nand_suspend(mtd); } +/** + * nand_lock - [MTD Interface] Lock the NAND flash + * @mtd: MTD device structure + * @ofs: offset byte address + * @len: number of bytes to lock (must be a multiple of block/page size) + */ +static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + + if (!chip->lock_area) + return -ENOTSUPP; + + return chip->lock_area(chip, ofs, len); +} + +/** + * nand_unlock - [MTD Interface] Unlock the NAND flash + * @mtd: MTD device structure + * @ofs: offset byte address + * @len: number of bytes to unlock (must be a multiple of block/page size) + */ +static int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + + if (!chip->unlock_area) + return -ENOTSUPP; + + return chip->unlock_area(chip, ofs, len); +} + /* Set default functions */ static void nand_set_defaults(struct nand_chip *chip) { @@ -5786,8 +5818,8 @@ static int nand_scan_tail(struct nand_chip *chip) mtd->_read_oob = nand_read_oob; mtd->_write_oob = nand_write_oob; mtd->_sync = nand_sync; - mtd->_lock = NULL; - mtd->_unlock = NULL; + mtd->_lock = nand_lock; + mtd->_unlock = nand_unlock; mtd->_suspend = nand_suspend; mtd->_resume = nand_resume; mtd->_reboot = nand_shutdown; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 4ab9bcc..bc2fa3c 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1077,6 +1077,8 @@ struct nand_legacy { * @manufacturer: [INTERN] Contains manufacturer information * @manufacturer.desc: [INTERN] Contains manufacturer's description * @manufacturer.priv: [INTERN] Contains manufacturer private information + * @lock_area: [REPLACEABLE] specific NAND chip lock operation + * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation */ struct nand_chip { @@ -1136,6 +1138,9 @@ struct nand_chip { const struct nand_manufacturer *desc; void *priv; } manufacturer; + + int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); + int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); }; extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops; -- 1.9.1