Skip to content

Commit 9227008

Browse files
Mason Yangmiquelraynal
authored andcommitted
mtd: rawnand: Add support for manufacturer specific lock/unlock operation
Add nand_lock() & nand_unlock() for manufacturer specific lock & unlock operation while the device supports Block Portection function. Signed-off-by: Mason Yang <masonccyang@mxic.com.tw> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/1583220084-10890-2-git-send-email-masonccyang@mxic.com.tw
1 parent e015d72 commit 9227008

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎drivers/mtd/nand/raw/nand_base.c‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4365,6 +4365,38 @@ static void nand_shutdown(struct mtd_info *mtd)
43654365
nand_suspend(mtd);
43664366
}
43674367

4368+
/**
4369+
* nand_lock - [MTD Interface] Lock the NAND flash
4370+
* @mtd: MTD device structure
4371+
* @ofs: offset byte address
4372+
* @len: number of bytes to lock (must be a multiple of block/page size)
4373+
*/
4374+
static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
4375+
{
4376+
struct nand_chip *chip = mtd_to_nand(mtd);
4377+
4378+
if (!chip->lock_area)
4379+
return -ENOTSUPP;
4380+
4381+
return chip->lock_area(chip, ofs, len);
4382+
}
4383+
4384+
/**
4385+
* nand_unlock - [MTD Interface] Unlock the NAND flash
4386+
* @mtd: MTD device structure
4387+
* @ofs: offset byte address
4388+
* @len: number of bytes to unlock (must be a multiple of block/page size)
4389+
*/
4390+
static int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
4391+
{
4392+
struct nand_chip *chip = mtd_to_nand(mtd);
4393+
4394+
if (!chip->unlock_area)
4395+
return -ENOTSUPP;
4396+
4397+
return chip->unlock_area(chip, ofs, len);
4398+
}
4399+
43684400
/* Set default functions */
43694401
static void nand_set_defaults(struct nand_chip *chip)
43704402
{
@@ -5791,8 +5823,8 @@ static int nand_scan_tail(struct nand_chip *chip)
57915823
mtd->_read_oob = nand_read_oob;
57925824
mtd->_write_oob = nand_write_oob;
57935825
mtd->_sync = nand_sync;
5794-
mtd->_lock = NULL;
5795-
mtd->_unlock = NULL;
5826+
mtd->_lock = nand_lock;
5827+
mtd->_unlock = nand_unlock;
57965828
mtd->_suspend = nand_suspend;
57975829
mtd->_resume = nand_resume;
57985830
mtd->_reboot = nand_shutdown;

‎include/linux/mtd/rawnand.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ struct nand_legacy {
10771077
* @manufacturer: [INTERN] Contains manufacturer information
10781078
* @manufacturer.desc: [INTERN] Contains manufacturer's description
10791079
* @manufacturer.priv: [INTERN] Contains manufacturer private information
1080+
* @lock_area: [REPLACEABLE] specific NAND chip lock operation
1081+
* @unlock_area: [REPLACEABLE] specific NAND chip unlock operation
10801082
*/
10811083

10821084
struct nand_chip {
@@ -1136,6 +1138,9 @@ struct nand_chip {
11361138
const struct nand_manufacturer *desc;
11371139
void *priv;
11381140
} manufacturer;
1141+
1142+
int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len);
1143+
int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len);
11391144
};
11401145

11411146
extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;

0 commit comments

Comments
 (0)