Skip to content

Commit

Permalink
mtd: nand: spi: add a setup and a setup_late op to the spinand_contro…
Browse files Browse the repository at this point in the history
…ller
  • Loading branch information
fschrempf committed Dec 12, 2017
1 parent 213caf2 commit 3f39780
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions drivers/mtd/nand/spi/core.c
Expand Up @@ -39,6 +39,22 @@ static inline int spinand_exec_op(struct spinand_device *spinand,
return spinand->controller.controller->ops->exec_op(spinand, op);
}

static inline int spinand_setup_controller(struct spinand_device *spinand)
{
if (!spinand->controller.controller->ops->setup)
return 0;

return spinand->controller.controller->ops->setup(spinand);
}

static inline int spinand_setup_controller_late(struct spinand_device *spinand)
{
if (!spinand->controller.controller->ops->setup_late)
return 0;

return spinand->controller.controller->ops->setup_late(spinand);
}

static inline void spinand_op_init(struct spinand_op *op)
{
memset(op, 0, sizeof(struct spinand_op));
Expand Down Expand Up @@ -687,6 +703,12 @@ int spinand_init(struct spinand_device *spinand, struct module *owner)
struct nand_device *nand = mtd_to_nanddev(mtd);
int ret;

ret = spinand_setup_controller(spinand);
if (ret) {
pr_err("Failed to setup the SPI NAND controller (err = %d).\n", ret);
return ret;
}

ret = spinand_detect(spinand);
if (ret) {
pr_err("Failed to detect a SPI NAND (err = %d).\n", ret);
Expand Down Expand Up @@ -718,6 +740,12 @@ int spinand_init(struct spinand_device *spinand, struct module *owner)
goto err_free_buf;
}

ret = spinand_setup_controller_late(spinand);
if (ret) {
pr_err("Failed to late setup the SPI NAND controller (err = %d).\n", ret);
return ret;
}

/*
* Right now, we don't support ECC, so let the whole oob
* area is available for user.
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mtd/spinand.h
Expand Up @@ -91,6 +91,8 @@ struct spinand_id {
struct spinand_controller_ops {
int (*exec_op)(struct spinand_device *spinand,
struct spinand_op *op);
int (*setup)(struct spinand_device *spinand);
int (*setup_late)(struct spinand_device *spinand);
};

/**
Expand Down

0 comments on commit 3f39780

Please sign in to comment.