@@ -220,6 +220,26 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
}
EXPORT_SYMBOL_GPL(spi_mem_supports_op);
+int spi_mem_prepare(struct spi_mem *mem)
+{
+ struct spi_controller *ctlr = mem->spi->controller;
+
+ if (ctlr->mem_ops && ctlr->mem_ops->prepare)
+ return ctlr->mem_ops->prepare(mem);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(spi_mem_prepare);
+
+void spi_mem_unprepare(struct spi_mem *mem)
+{
+ struct spi_controller *ctlr = mem->spi->controller;
+
+ if (ctlr->mem_ops && ctlr->mem_ops->unprepare)
+ ctlr->mem_ops->unprepare(mem);
+}
+EXPORT_SYMBOL_GPL(spi_mem_unprepare);
+
static int spi_mem_access_start(struct spi_mem *mem)
{
struct spi_controller *ctlr = mem->spi->controller;
@@ -215,6 +215,12 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem)
* limitations)
* @supports_op: check if an operation is supported by the controller
* @exec_op: execute a SPI memory operation
+ * @prepare: do some prepare works before a set of operations. for example,
+ * read/write/erase/lock/unlock operations of spi-nor flash. This
+ * method is optional.
+ * @unprepare: do some post works after a set of operations. for example,
+ * read/write/erase/lock/unlock operations of spi-nor flash. This
+ * method is optional.
* @get_name: get a custom name for the SPI mem device from the controller.
* This might be needed if the controller driver has been ported
* to use the SPI mem layer and a custom name is used to keep
@@ -253,6 +259,8 @@ struct spi_controller_mem_ops {
int (*adjust_op_size)(struct spi_mem *mem, struct spi_mem_op *op);
bool (*supports_op)(struct spi_mem *mem,
const struct spi_mem_op *op);
+ int (*prepare)(struct spi_mem *mem);
+ void (*unprepare)(struct spi_mem *mem);
int (*exec_op)(struct spi_mem *mem,
const struct spi_mem_op *op);
const char *(*get_name)(struct spi_mem *mem);
@@ -329,6 +337,9 @@ int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op);
bool spi_mem_supports_op(struct spi_mem *mem,
const struct spi_mem_op *op);
+int spi_mem_prepare(struct spi_mem *mem);
+void spi_mem_unprepare(struct spi_mem *mem);
+
int spi_mem_exec_op(struct spi_mem *mem,
const struct spi_mem_op *op);
Some prepare/unprepare works may be necessary before/after a set of operations of the spimem device. For example, before/after spi-nor flash's read/write/erase/lock/unlock. Add optional prepare/unprepare methods in spi_controller_mem_ops to allow the controller to do specific works after/before the operations. The upper user can use spi_mem_{prepare, unprepare}() to call the methods of the controller. Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> --- drivers/spi/spi-mem.c | 20 ++++++++++++++++++++ include/linux/spi/spi-mem.h | 11 +++++++++++ 2 files changed, 31 insertions(+)