Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 861fbd6e authored by Janusz Krzysztofik's avatar Janusz Krzysztofik Committed by Miquel Raynal
Browse files

mtd: rawnand: ams-delta: Convert the driver to ->exec_op()



Replace legacy callbacks with ->select_chip() and ->exec_op().

Suggested-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: default avatarJanusz Krzysztofik <jmkrzyszt@gmail.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 3bd647ee
Loading
Loading
Loading
Loading
+56 −44
Original line number Original line Diff line number Diff line
@@ -99,10 +99,9 @@ static void ams_delta_dir_input(struct ams_delta_nand *priv, bool in)
	priv->data_in = in;
	priv->data_in = in;
}
}


static void ams_delta_write_buf(struct nand_chip *this, const u_char *buf,
static void ams_delta_write_buf(struct ams_delta_nand *priv, const u_char *buf,
				int len)
				int len)
{
{
	struct ams_delta_nand *priv = nand_get_controller_data(this);
	int i;
	int i;


	if (priv->data_in)
	if (priv->data_in)
@@ -112,9 +111,9 @@ static void ams_delta_write_buf(struct nand_chip *this, const u_char *buf,
		ams_delta_io_write(priv, buf[i]);
		ams_delta_io_write(priv, buf[i]);
}
}


static void ams_delta_read_buf(struct nand_chip *this, u_char *buf, int len)
static void ams_delta_read_buf(struct ams_delta_nand *priv, u_char *buf,
			       int len)
{
{
	struct ams_delta_nand *priv = nand_get_controller_data(this);
	int i;
	int i;


	if (!priv->data_in)
	if (!priv->data_in)
@@ -124,46 +123,66 @@ static void ams_delta_read_buf(struct nand_chip *this, u_char *buf, int len)
		buf[i] = ams_delta_io_read(priv);
		buf[i] = ams_delta_io_read(priv);
}
}


static u_char ams_delta_read_byte(struct nand_chip *this)
static void ams_delta_select_chip(struct nand_chip *this, int n)
{
{
	u_char res;
	struct ams_delta_nand *priv = nand_get_controller_data(this);


	ams_delta_read_buf(this, &res, 1);
	if (n > 0)
		return;


	return res;
	gpiod_set_value(priv->gpiod_nce, n < 0);
}
}


/*
static int ams_delta_exec_op(struct nand_chip *this,
 * Command control function
			     const struct nand_operation *op, bool check_only)
 *
 * ctrl:
 * NAND_NCE: bit 0 -> bit 2
 * NAND_CLE: bit 1 -> bit 7
 * NAND_ALE: bit 2 -> bit 6
 */
static void ams_delta_hwcontrol(struct nand_chip *this, int cmd,
				unsigned int ctrl)
{
{
	struct ams_delta_nand *priv = nand_get_controller_data(this);
	struct ams_delta_nand *priv = nand_get_controller_data(this);
	const struct nand_op_instr *instr;
	int ret = 0;


	if (ctrl & NAND_CTRL_CHANGE) {
	if (check_only)
		gpiod_set_value(priv->gpiod_nce, !(ctrl & NAND_NCE));
		return 0;
		gpiod_set_value(priv->gpiod_cle, !!(ctrl & NAND_CLE));
		gpiod_set_value(priv->gpiod_ale, !!(ctrl & NAND_ALE));
	}

	if (cmd != NAND_CMD_NONE) {
		u_char byte = cmd;


		ams_delta_write_buf(this, &byte, 1);
	for (instr = op->instrs; instr < op->instrs + op->ninstrs; instr++) {
	}

		switch (instr->type) {
		case NAND_OP_CMD_INSTR:
			gpiod_set_value(priv->gpiod_cle, 1);
			ams_delta_write_buf(priv, &instr->ctx.cmd.opcode, 1);
			gpiod_set_value(priv->gpiod_cle, 0);
			break;

		case NAND_OP_ADDR_INSTR:
			gpiod_set_value(priv->gpiod_ale, 1);
			ams_delta_write_buf(priv, instr->ctx.addr.addrs,
					    instr->ctx.addr.naddrs);
			gpiod_set_value(priv->gpiod_ale, 0);
			break;

		case NAND_OP_DATA_IN_INSTR:
			ams_delta_read_buf(priv, instr->ctx.data.buf.in,
					   instr->ctx.data.len);
			break;

		case NAND_OP_DATA_OUT_INSTR:
			ams_delta_write_buf(priv, instr->ctx.data.buf.out,
					    instr->ctx.data.len);
			break;

		case NAND_OP_WAITRDY_INSTR:
			ret = priv->gpiod_rdy ?
			      nand_gpio_waitrdy(this, priv->gpiod_rdy,
						instr->ctx.waitrdy.timeout_ms) :
			      nand_soft_waitrdy(this,
						instr->ctx.waitrdy.timeout_ms);
			break;
		}
		}


static int ams_delta_nand_ready(struct nand_chip *this)
		if (ret)
{
			break;
	struct ams_delta_nand *priv = nand_get_controller_data(this);
	}


	return gpiod_get_value(priv->gpiod_rdy);
	return ret;
}
}




@@ -211,10 +230,8 @@ static int ams_delta_init(struct platform_device *pdev)
	nand_set_controller_data(this, priv);
	nand_set_controller_data(this, priv);


	/* Set address of NAND IO lines */
	/* Set address of NAND IO lines */
	this->legacy.read_byte = ams_delta_read_byte;
	this->select_chip = ams_delta_select_chip;
	this->legacy.write_buf = ams_delta_write_buf;
	this->exec_op = ams_delta_exec_op;
	this->legacy.read_buf = ams_delta_read_buf;
	this->legacy.cmd_ctrl = ams_delta_hwcontrol;


	priv->gpiod_rdy = devm_gpiod_get_optional(&pdev->dev, "rdy", GPIOD_IN);
	priv->gpiod_rdy = devm_gpiod_get_optional(&pdev->dev, "rdy", GPIOD_IN);
	if (IS_ERR(priv->gpiod_rdy)) {
	if (IS_ERR(priv->gpiod_rdy)) {
@@ -223,11 +240,6 @@ static int ams_delta_init(struct platform_device *pdev)
		goto out_mtd;
		goto out_mtd;
	}
	}


	if (priv->gpiod_rdy)
		this->legacy.dev_ready = ams_delta_nand_ready;

	/* 25 us command delay time */
	this->legacy.chip_delay = 30;
	this->ecc.mode = NAND_ECC_SOFT;
	this->ecc.mode = NAND_ECC_SOFT;
	this->ecc.algo = NAND_ECC_HAMMING;
	this->ecc.algo = NAND_ECC_HAMMING;