@@ -463,6 +463,68 @@ static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
return spinand_write_reg_op(spinand, REG_BLOCK_LOCK, lock);
}
+/**
+ * spinand_read_param_page_op - Read parameter page operation
+ * @spinand: the spinand device
+ * @page: page number where parameter page tables can be found
+ * @parameters: buffer used to store the parameter page
+ * @len: length of the buffer
+ *
+ * Read parameter page
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ */
+int spinand_parameter_page_read(struct spinand_device *spinand,
+ u8 page, void *parameters, u32 len)
+{
+ struct spi_mem_op pread_op = SPINAND_PAGE_READ_OP(page);
+ struct spi_mem_op pread_cache_op =
+ SPINAND_PAGE_READ_FROM_CACHE_OP(false,
+ 0,
+ 1,
+ parameters,
+ len);
+ u8 feature;
+ u8 status;
+ int ret;
+
+ if (len && !parameters)
+ return -EINVAL;
+
+ ret = spinand_read_reg_op(spinand, REG_CFG,
+ &feature);
+ if (ret)
+ return ret;
+
+ /* CFG_OTP_ENABLE is used to enable parameter page access */
+ feature |= CFG_OTP_ENABLE;
+
+ spinand_write_reg_op(spinand, REG_CFG, feature);
+
+ ret = spi_mem_exec_op(spinand->spimem, &pread_op);
+ if (ret)
+ return ret;
+
+ ret = spinand_wait(spinand, &status);
+ if (ret < 0)
+ return ret;
+
+ ret = spi_mem_exec_op(spinand->spimem, &pread_cache_op);
+ if (ret)
+ return ret;
+
+ ret = spinand_read_reg_op(spinand, REG_CFG,
+ &feature);
+ if (ret)
+ return ret;
+
+ feature &= ~CFG_OTP_ENABLE;
+
+ spinand_write_reg_op(spinand, REG_CFG, feature);
+
+ return 0;
+}
+
static int spinand_check_ecc_status(struct spinand_device *spinand, u8 status)
{
struct nand_device *nand = spinand_to_nand(spinand);
@@ -420,4 +420,7 @@ int spinand_match_and_init(struct spinand_device *dev,
int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
int spinand_select_target(struct spinand_device *spinand, unsigned int target);
+int spinand_parameter_page_read(struct spinand_device *spinand,
+ u8 page, void *parameters, u32 len);
+
#endif /* __LINUX_MTD_SPINAND_H */