Commit c17556f5 authored by Boris Brezillon's avatar Boris Brezillon Committed by Miquel Raynal

mtd: rawnand: Pass a nand_chip object to chip->block_xxx() hooks

Let's make the raw NAND API consistent by patching all helpers and
hooks to take a nand_chip object instead of an mtd_info one or
remove the mtd_info object when both are passed.

Let's tackle all chip->block_xxx() hooks at once.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 758b56f5
...@@ -546,7 +546,7 @@ static int cafe_nand_write_page_lowlevel(struct nand_chip *chip, ...@@ -546,7 +546,7 @@ static int cafe_nand_write_page_lowlevel(struct nand_chip *chip,
return nand_prog_page_end_op(chip); return nand_prog_page_end_op(chip);
} }
static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs) static int cafe_nand_block_bad(struct nand_chip *chip, loff_t ofs)
{ {
return 0; return 0;
} }
......
...@@ -777,7 +777,7 @@ static int doc200x_dev_ready(struct mtd_info *mtd) ...@@ -777,7 +777,7 @@ static int doc200x_dev_ready(struct mtd_info *mtd)
} }
} }
static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs) static int doc200x_block_bad(struct nand_chip *this, loff_t ofs)
{ {
/* This is our last resort if we couldn't find or create a BBT. Just /* This is our last resort if we couldn't find or create a BBT. Just
pretend all blocks are good. */ pretend all blocks are good. */
......
...@@ -1102,7 +1102,7 @@ static int __init read_factory_bbt(struct mtd_info *mtd) ...@@ -1102,7 +1102,7 @@ static int __init read_factory_bbt(struct mtd_info *mtd)
return 0; return 0;
} }
static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs) static int docg4_block_markbad(struct nand_chip *nand, loff_t ofs)
{ {
/* /*
* Mark a block as bad. Bad blocks are marked in the oob area of the * Mark a block as bad. Bad blocks are marked in the oob area of the
...@@ -1115,7 +1115,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -1115,7 +1115,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs)
int ret, i; int ret, i;
uint8_t *buf; uint8_t *buf;
struct nand_chip *nand = mtd_to_nand(mtd); struct mtd_info *mtd = nand_to_mtd(nand);
struct docg4_priv *doc = nand_get_controller_data(nand); struct docg4_priv *doc = nand_get_controller_data(nand);
struct nand_bbt_descr *bbtd = nand->badblock_pattern; struct nand_bbt_descr *bbtd = nand->badblock_pattern;
int page = (int)(ofs >> nand->page_shift); int page = (int)(ofs >> nand->page_shift);
...@@ -1147,7 +1147,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -1147,7 +1147,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs)
return ret; return ret;
} }
static int docg4_block_neverbad(struct mtd_info *mtd, loff_t ofs) static int docg4_block_neverbad(struct nand_chip *nand, loff_t ofs)
{ {
/* only called when module_param ignore_badblocks is set */ /* only called when module_param ignore_badblocks is set */
return 0; return 0;
......
...@@ -1542,9 +1542,9 @@ static int gpmi_ecc_write_oob_raw(struct nand_chip *chip, int page) ...@@ -1542,9 +1542,9 @@ static int gpmi_ecc_write_oob_raw(struct nand_chip *chip, int page)
return gpmi_ecc_write_page_raw(chip, NULL, 1, page); return gpmi_ecc_write_page_raw(chip, NULL, 1, page);
} }
static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs) static int gpmi_block_markbad(struct nand_chip *chip, loff_t ofs)
{ {
struct nand_chip *chip = mtd_to_nand(mtd); struct mtd_info *mtd = nand_to_mtd(chip);
struct gpmi_nand_data *this = nand_get_controller_data(chip); struct gpmi_nand_data *this = nand_get_controller_data(chip);
int ret = 0; int ret = 0;
uint8_t *block_mark; uint8_t *block_mark;
...@@ -1776,7 +1776,7 @@ static int mx23_boot_init(struct gpmi_nand_data *this) ...@@ -1776,7 +1776,7 @@ static int mx23_boot_init(struct gpmi_nand_data *this)
*/ */
if (block_mark != 0xff) { if (block_mark != 0xff) {
dev_dbg(dev, "Transcribing mark in block %u\n", block); dev_dbg(dev, "Transcribing mark in block %u\n", block);
ret = chip->block_markbad(mtd, byte); ret = chip->block_markbad(chip, byte);
if (ret) if (ret)
dev_err(dev, dev_err(dev,
"Failed to mark block bad with ret %d\n", "Failed to mark block bad with ret %d\n",
......
...@@ -398,15 +398,15 @@ static void nand_read_buf16(struct nand_chip *chip, uint8_t *buf, int len) ...@@ -398,15 +398,15 @@ static void nand_read_buf16(struct nand_chip *chip, uint8_t *buf, int len)
/** /**
* nand_block_bad - [DEFAULT] Read bad block marker from the chip * nand_block_bad - [DEFAULT] Read bad block marker from the chip
* @mtd: MTD device structure * @chip: NAND chip object
* @ofs: offset from device start * @ofs: offset from device start
* *
* Check, if the block is bad. * Check, if the block is bad.
*/ */
static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) static int nand_block_bad(struct nand_chip *chip, loff_t ofs)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
int page, page_end, res; int page, page_end, res;
struct nand_chip *chip = mtd_to_nand(mtd);
u8 bad; u8 bad;
if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
...@@ -435,16 +435,16 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) ...@@ -435,16 +435,16 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
/** /**
* nand_default_block_markbad - [DEFAULT] mark a block bad via bad block marker * nand_default_block_markbad - [DEFAULT] mark a block bad via bad block marker
* @mtd: MTD device structure * @chip: NAND chip object
* @ofs: offset from device start * @ofs: offset from device start
* *
* This is the default implementation, which can be overridden by a hardware * This is the default implementation, which can be overridden by a hardware
* specific driver. It provides the details for writing a bad block marker to a * specific driver. It provides the details for writing a bad block marker to a
* block. * block.
*/ */
static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) static int nand_default_block_markbad(struct nand_chip *chip, loff_t ofs)
{ {
struct nand_chip *chip = mtd_to_nand(mtd); struct mtd_info *mtd = nand_to_mtd(chip);
struct mtd_oob_ops ops; struct mtd_oob_ops ops;
uint8_t buf[2] = { 0, 0 }; uint8_t buf[2] = { 0, 0 };
int ret = 0, res, i = 0; int ret = 0, res, i = 0;
...@@ -510,7 +510,7 @@ static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs) ...@@ -510,7 +510,7 @@ static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)
/* Write bad block marker to OOB */ /* Write bad block marker to OOB */
nand_get_device(mtd, FL_WRITING); nand_get_device(mtd, FL_WRITING);
ret = chip->block_markbad(mtd, ofs); ret = chip->block_markbad(chip, ofs);
nand_release_device(mtd); nand_release_device(mtd);
} }
...@@ -583,7 +583,7 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt) ...@@ -583,7 +583,7 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt)
struct nand_chip *chip = mtd_to_nand(mtd); struct nand_chip *chip = mtd_to_nand(mtd);
if (!chip->bbt) if (!chip->bbt)
return chip->block_bad(mtd, ofs); return chip->block_bad(chip, ofs);
/* Return info from the table */ /* Return info from the table */
return nand_isbad_bbt(mtd, ofs, allowbbt); return nand_isbad_bbt(mtd, ofs, allowbbt);
......
...@@ -683,14 +683,13 @@ static void mark_bbt_block_bad(struct nand_chip *this, ...@@ -683,14 +683,13 @@ static void mark_bbt_block_bad(struct nand_chip *this,
struct nand_bbt_descr *td, struct nand_bbt_descr *td,
int chip, int block) int chip, int block)
{ {
struct mtd_info *mtd = nand_to_mtd(this);
loff_t to; loff_t to;
int res; int res;
bbt_mark_entry(this, block, BBT_BLOCK_WORN); bbt_mark_entry(this, block, BBT_BLOCK_WORN);
to = (loff_t)block << this->bbt_erase_shift; to = (loff_t)block << this->bbt_erase_shift;
res = this->block_markbad(mtd, to); res = this->block_markbad(this, to);
if (res) if (res)
pr_warn("nand_bbt: error %d while marking block %d bad\n", pr_warn("nand_bbt: error %d while marking block %d bad\n",
res, block); res, block);
......
...@@ -2196,9 +2196,9 @@ static int qcom_nandc_write_oob(struct nand_chip *chip, int page) ...@@ -2196,9 +2196,9 @@ static int qcom_nandc_write_oob(struct nand_chip *chip, int page)
return nand_prog_page_end_op(chip); return nand_prog_page_end_op(chip);
} }
static int qcom_nandc_block_bad(struct mtd_info *mtd, loff_t ofs) static int qcom_nandc_block_bad(struct nand_chip *chip, loff_t ofs)
{ {
struct nand_chip *chip = mtd_to_nand(mtd); struct mtd_info *mtd = nand_to_mtd(chip);
struct qcom_nand_host *host = to_qcom_nand_host(chip); struct qcom_nand_host *host = to_qcom_nand_host(chip);
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
struct nand_ecc_ctrl *ecc = &chip->ecc; struct nand_ecc_ctrl *ecc = &chip->ecc;
...@@ -2234,9 +2234,8 @@ static int qcom_nandc_block_bad(struct mtd_info *mtd, loff_t ofs) ...@@ -2234,9 +2234,8 @@ static int qcom_nandc_block_bad(struct mtd_info *mtd, loff_t ofs)
return bad; return bad;
} }
static int qcom_nandc_block_markbad(struct mtd_info *mtd, loff_t ofs) static int qcom_nandc_block_markbad(struct nand_chip *chip, loff_t ofs)
{ {
struct nand_chip *chip = mtd_to_nand(mtd);
struct qcom_nand_host *host = to_qcom_nand_host(chip); struct qcom_nand_host *host = to_qcom_nand_host(chip);
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
struct nand_ecc_ctrl *ecc = &chip->ecc; struct nand_ecc_ctrl *ecc = &chip->ecc;
......
...@@ -99,8 +99,9 @@ static const struct mtd_ooblayout_ops oob_sm_small_ops = { ...@@ -99,8 +99,9 @@ static const struct mtd_ooblayout_ops oob_sm_small_ops = {
.free = oob_sm_small_ooblayout_free, .free = oob_sm_small_ooblayout_free,
}; };
static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs) static int sm_block_markbad(struct nand_chip *chip, loff_t ofs)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
struct mtd_oob_ops ops; struct mtd_oob_ops ops;
struct sm_oob oob; struct sm_oob oob;
int ret; int ret;
......
...@@ -1288,8 +1288,8 @@ struct nand_chip { ...@@ -1288,8 +1288,8 @@ struct nand_chip {
void (*write_buf)(struct nand_chip *chip, const uint8_t *buf, int len); void (*write_buf)(struct nand_chip *chip, const uint8_t *buf, int len);
void (*read_buf)(struct nand_chip *chip, uint8_t *buf, int len); void (*read_buf)(struct nand_chip *chip, uint8_t *buf, int len);
void (*select_chip)(struct nand_chip *chip, int cs); void (*select_chip)(struct nand_chip *chip, int cs);
int (*block_bad)(struct mtd_info *mtd, loff_t ofs); int (*block_bad)(struct nand_chip *chip, loff_t ofs);
int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); int (*block_markbad)(struct nand_chip *chip, loff_t ofs);
void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl); void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
int (*dev_ready)(struct mtd_info *mtd); int (*dev_ready)(struct mtd_info *mtd);
void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment