@ -26,8 +26,6 @@ Signed-off-by: Ram Chandra Jangir <rjangir@codeaurora.org>
2 files changed, 721 insertions(+), 59 deletions(-)
create mode 100644 include/linux/dma/qcom_bam_dma.h
diff --git a/drivers/mtd/nand/qcom_nandc.c b/drivers/mtd/nand/qcom_nandc.c
index 76a0ffc..9d941e3 100644
--- a/drivers/mtd/nand/qcom_nandc.c
+++ b/drivers/mtd/nand/qcom_nandc.c
@@ -22,6 +22,7 @@
@ -223,7 +221,7 @@ index 76a0ffc..9d941e3 100644
static inline struct qcom_nand_host *to_qcom_nand_host(struct nand_chip *chip)
{
return container_of(chip, struct qcom_nand_host, chip);
@@ -398,6 +522,16 @@ static __le32 *offset_to_nandc_reg(struc t nandc_regs *regs, int offset)
@@ -398,6 +522,16 @@ static __le32 *offset_to_nandc_reg(struc
return ®s->orig_vld;
case NAND_EBI2_ECC_BUF_CFG:
return ®s->ecc_buf_cfg;
@ -240,7 +238,7 @@ index 76a0ffc..9d941e3 100644
default:
return NULL;
}
@@ -439,7 +573,7 @@ static void update_rw_regs(struct qcom_n and_host *host, int num_cw, bool read)
@@ -439,7 +573,7 @@ static void update_rw_regs(struct qcom_n
{
struct nand_chip *chip = &host->chip;
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
@ -249,7 +247,7 @@ index 76a0ffc..9d941e3 100644
if (read) {
if (host->use_ecc)
@@ -456,12 +590,20 @@ static void update_rw_regs(struct qcom_n and_host *host, int num_cw, bool read)
@@ -456,12 +590,20 @@ static void update_rw_regs(struct qcom_n
cfg1 = host->cfg1;
ecc_bch_cfg = host->ecc_bch_cfg;
@ -270,15 +268,15 @@ index 76a0ffc..9d941e3 100644
}
nandc_set_reg(nandc, NAND_FLASH_CMD, cmd);
@@ -472,8 +614,104 @@ static void update_rw_regs(struct qcom_n and_host *host, int num_cw, bool read)
@@ -472,8 +614,104 @@ static void update_rw_regs(struct qcom_n
nandc_set_reg(nandc, NAND_FLASH_STATUS, host->clrflashstatus);
nandc_set_reg(nandc, NAND_READ_STATUS, host->clrreadstatus);
nandc_set_reg(nandc, NAND_EXEC_CMD, 1);
+
+ if (read)
+ nandc_set_reg(nandc, NAND_READ_LOCATION_0, read_location0);
}
+}
+
+/*
+ * Prepares the command descriptor for BAM DMA which will be used for NAND
+ * register read and write. The command descriptor requires the command
@ -339,8 +337,8 @@ index 76a0ffc..9d941e3 100644
+ }
+
+ return 0;
+}
+
}
+/*
+ * Prepares the data descriptor for BAM DMA which will be used for NAND
+ * data read and write.
@ -375,7 +373,7 @@ index 76a0ffc..9d941e3 100644
static int prep_dma_desc(struct qcom_nand_controller *nandc, bool read,
int reg_off, const void *vaddr, int size,
bool flow_control)
@@ -552,7 +790,7 @@ static int prep_dma_desc(struct qcom_nand_controller *nandc, bool read,
@@ -552,7 +790,7 @@ err:
* @num_regs: number of registers to read
*/
static int read_reg_dma(struct qcom_nand_controller *nandc, int first,
@ -384,7 +382,7 @@ index 76a0ffc..9d941e3 100644
{
bool flow_control = false;
void *vaddr;
@@ -561,10 +799,18 @@ static int read_reg_dma(struct qcom_nand _controller *nandc, int first,
@@ -561,10 +799,18 @@ static int read_reg_dma(struct qcom_nand
if (first == NAND_READ_ID || first == NAND_FLASH_STATUS)
flow_control = true;
@ -404,7 +402,7 @@ index 76a0ffc..9d941e3 100644
return prep_dma_desc(nandc, true, first, vaddr, size, flow_control);
}
@@ -576,7 +822,7 @@ static int read_reg_dma(struct qcom_nand _controller *nandc, int first,
@@ -576,7 +822,7 @@ static int read_reg_dma(struct qcom_nand
* @num_regs: number of registers to write
*/
static int write_reg_dma(struct qcom_nand_controller *nandc, int first,
@ -413,7 +411,7 @@ index 76a0ffc..9d941e3 100644
{
bool flow_control = false;
struct nandc_regs *regs = nandc->regs;
@@ -588,12 +834,29 @@ static int write_reg_dma(struct qcom_nan d_controller *nandc, int first,
@@ -588,12 +834,29 @@ static int write_reg_dma(struct qcom_nan
if (first == NAND_FLASH_CMD)
flow_control = true;
@ -443,7 +441,7 @@ index 76a0ffc..9d941e3 100644
size = num_regs * sizeof(u32);
return prep_dma_desc(nandc, false, first, vaddr, size, flow_control);
@@ -608,8 +871,12 @@ static int write_reg_dma(struct qcom_nan d_controller *nandc, int first,
@@ -608,8 +871,12 @@ static int write_reg_dma(struct qcom_nan
* @size: DMA transaction size in bytes
*/
static int read_data_dma(struct qcom_nand_controller *nandc, int reg_off,
@ -457,7 +455,7 @@ index 76a0ffc..9d941e3 100644
return prep_dma_desc(nandc, true, reg_off, vaddr, size, false);
}
@@ -622,8 +889,12 @@ static int read_data_dma(struct qcom_nan d_controller *nandc, int reg_off,
@@ -622,8 +889,12 @@ static int read_data_dma(struct qcom_nan
* @size: DMA transaction size in bytes
*/
static int write_data_dma(struct qcom_nand_controller *nandc, int reg_off,
@ -471,7 +469,7 @@ index 76a0ffc..9d941e3 100644
return prep_dma_desc(nandc, false, reg_off, vaddr, size, false);
}
@@ -633,14 +904,57 @@ static int write_data_dma(struct qcom_na nd_controller *nandc, int reg_off,
@@ -633,14 +904,57 @@ static int write_data_dma(struct qcom_na
*/
static void config_cw_read(struct qcom_nand_controller *nandc)
{
@ -490,10 +488,10 @@ index 76a0ffc..9d941e3 100644
+ if (nandc->dma_bam_enabled)
+ write_reg_dma(nandc, NAND_READ_LOCATION_0, 1,
+ DMA_DESC_FLAG_BAM_NEXT_SGL);
+
- read_reg_dma(nandc, NAND_FLASH_STATUS, 2);
- read_reg_dma(nandc, NAND_ERASED_CW_DETECT_STATUS, 1);
+
+ write_reg_dma(nandc, NAND_EXEC_CMD, 1, DMA_DESC_FLAG_BAM_NWD |
+ DMA_DESC_FLAG_BAM_NEXT_SGL);
+
@ -535,7 +533,7 @@ index 76a0ffc..9d941e3 100644
}
/*
@@ -649,19 +963,20 @@ static void config_cw_read(struct qcom_n and_controller *nandc)
@@ -649,19 +963,20 @@ static void config_cw_read(struct qcom_n
*/
static void config_cw_write_pre(struct qcom_nand_controller *nandc)
{
@ -563,7 +561,7 @@ index 76a0ffc..9d941e3 100644
}
/*
@@ -675,6 +990,8 @@ static int nandc_param(struct qcom_nand_ host *host)
@@ -675,6 +990,8 @@ static int nandc_param(struct qcom_nand_
struct nand_chip *chip = &host->chip;
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
@ -572,7 +570,7 @@ index 76a0ffc..9d941e3 100644
/*
* NAND_CMD_PARAM is called before we know much about the FLASH chip
* in use. we configure the controller to perform a raw read of 512
@@ -708,9 +1025,13 @@ static int nandc_param(struct qcom_nand_ host *host)
@@ -708,9 +1025,13 @@ static int nandc_param(struct qcom_nand_
nandc_set_reg(nandc, NAND_DEV_CMD1_RESTORE, nandc->cmd1);
nandc_set_reg(nandc, NAND_DEV_CMD_VLD_RESTORE, nandc->vld);
@ -588,7 +586,7 @@ index 76a0ffc..9d941e3 100644
nandc->buf_count = 512;
memset(nandc->data_buffer, 0xff, nandc->buf_count);
@@ -718,11 +1039,12 @@ static int nandc_param(struct qcom_nand_ host *host)
@@ -718,11 +1039,12 @@ static int nandc_param(struct qcom_nand_
config_cw_read(nandc);
read_data_dma(nandc, FLASH_BUF_ACC, nandc->data_buffer,
@ -604,7 +602,7 @@ index 76a0ffc..9d941e3 100644
return 0;
}
@@ -733,6 +1055,8 @@ static int erase_block(struct qcom_nand_ host *host, int page_addr)
@@ -733,6 +1055,8 @@ static int erase_block(struct qcom_nand_
struct nand_chip *chip = &host->chip;
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
@ -613,7 +611,7 @@ index 76a0ffc..9d941e3 100644
nandc_set_reg(nandc, NAND_FLASH_CMD,
BLOCK_ERASE | PAGE_ACC | LAST_PAGE);
nandc_set_reg(nandc, NAND_ADDR0, page_addr);
@@ -744,14 +1068,15 @@ static int erase_block(struct qcom_nand_ host *host, int page_addr)
@@ -744,14 +1068,15 @@ static int erase_block(struct qcom_nand_
nandc_set_reg(nandc, NAND_FLASH_STATUS, host->clrflashstatus);
nandc_set_reg(nandc, NAND_READ_STATUS, host->clrreadstatus);
@ -625,17 +623,17 @@ index 76a0ffc..9d941e3 100644
+ write_reg_dma(nandc, NAND_FLASH_CMD, 3, DMA_DESC_FLAG_BAM_NEXT_SGL);
+ write_reg_dma(nandc, NAND_DEV0_CFG0, 2, DMA_DESC_FLAG_BAM_NEXT_SGL);
+ write_reg_dma(nandc, NAND_EXEC_CMD, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
+
+ read_reg_dma(nandc, NAND_FLASH_STATUS, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
- write_reg_dma(nandc, NAND_FLASH_STATUS, 1);
- write_reg_dma(nandc, NAND_READ_STATUS, 1);
+ read_reg_dma(nandc, NAND_FLASH_STATUS, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
+
+ write_reg_dma(nandc, NAND_FLASH_STATUS, 1, 0);
+ write_reg_dma(nandc, NAND_READ_STATUS, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
return 0;
}
@@ -765,16 +1090,19 @@ static int read_id(struct qcom_nand_host *host, int column)
@@ -765,16 +1090,19 @@ static int read_id(struct qcom_nand_host
if (column == -1)
return 0;
@ -659,7 +657,7 @@ index 76a0ffc..9d941e3 100644
return 0;
}
@@ -785, 15 +1113,61 @@ static int reset(struct qcom_nand_host *host)
@@ -785, 28 +1113,108 @@ static int reset(struct qcom_nand_host *
struct nand_chip *chip = &host->chip;
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
@ -672,12 +670,13 @@ index 76a0ffc..9d941e3 100644
- write_reg_dma(nandc, NAND_EXEC_CMD, 1);
+ write_reg_dma(nandc, NAND_FLASH_CMD, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
+ write_reg_dma(nandc, NAND_EXEC_CMD, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
+
- read_reg_dma(nandc, NAND_FLASH_STATUS, 1);
+ read_reg_dma(nandc, NAND_FLASH_STATUS, 1, DMA_DESC_FLAG_BAM_NEXT_SGL);
+
+ return 0;
+}
+
return 0;
}
+static int prepare_bam_async_desc(struct qcom_nand_controller *nandc,
+ struct dma_chan *chan,
+ struct qcom_bam_sgl *bam_sgl,
@ -715,16 +714,15 @@ index 76a0ffc..9d941e3 100644
+ }
+
+ desc->dma_desc = dma_desc;
- read_reg_dma(nandc, NAND_FLASH_STATUS, 1);
+
+ list_add_tail(&desc->node, &nandc->desc_list);
return 0;
+
}
+ return 0;
+
+}
+
/* helpers to submit/free our list of dma descriptors */
@@ -801,12 +1175,46 @@ static int submit_descs(struct qcom_nand_controller *nandc)
static int submit_descs(struct qcom_nand_controller *nandc)
{
struct desc_info *desc;
dma_cookie_t cookie = 0;
@ -773,7 +771,7 @@ index 76a0ffc..9d941e3 100644
return 0;
}
@@ -817,7 +1225,16 @@ static void free_descs(struct qcom_nand_ controller *nandc)
@@ -817,7 +1225,16 @@ static void free_descs(struct qcom_nand_
list_for_each_entry_safe(desc, n, &nandc->desc_list, node) {
list_del(&desc->node);
@ -791,7 +789,7 @@ index 76a0ffc..9d941e3 100644
kfree(desc);
}
}
@@ -1128,6 +1545,9 @@ static int read_page_ecc(struct qcom_nan d_host *host, u8 *data_buf,
@@ -1128,6 +1545,9 @@ static int read_page_ecc(struct qcom_nan
struct nand_ecc_ctrl *ecc = &chip->ecc;
int i, ret;
@ -801,7 +799,7 @@ index 76a0ffc..9d941e3 100644
/* queue cmd descs for each codeword */
for (i = 0; i < ecc->steps; i++) {
int data_size, oob_size;
@@ -1141,11 +1561,36 @@ static int read_page_ecc(struct qcom_nan d_host *host, u8 *data_buf,
@@ -1141,11 +1561,36 @@ static int read_page_ecc(struct qcom_nan
oob_size = host->ecc_bytes_hw + host->spare_bytes;
}
@ -840,7 +838,7 @@ index 76a0ffc..9d941e3 100644
/*
* when ecc is enabled, the controller doesn't read the real
@@ -1161,7 +1606,7 @@ static int read_page_ecc(struct qcom_nan d_host *host, u8 *data_buf,
@@ -1161,7 +1606,7 @@ static int read_page_ecc(struct qcom_nan
*oob_buf++ = 0xff;
read_data_dma(nandc, FLASH_BUF_ACC + data_size,
@ -849,7 +847,7 @@ index 76a0ffc..9d941e3 100644
}
if (data_buf)
@@ -1200,10 +1645,14 @@ static int copy_last_cw(struct qcom_nand _host *host, int page)
@@ -1200,10 +1645,14 @@ static int copy_last_cw(struct qcom_nand
set_address(host, host->cw_size * (ecc->steps - 1), page);
update_rw_regs(host, 1, true);
@ -865,7 +863,7 @@ index 76a0ffc..9d941e3 100644
ret = submit_descs(nandc);
if (ret)
@@ -1226,6 +1675,7 @@ static int qcom_nandc_read_page(struct m td_info *mtd, struct nand_chip *chip,
@@ -1226,6 +1675,7 @@ static int qcom_nandc_read_page(struct m
data_buf = buf;
oob_buf = oob_required ? chip->oob_poi : NULL;
@ -873,7 +871,7 @@ index 76a0ffc..9d941e3 100644
ret = read_page_ecc(host, data_buf, oob_buf);
if (ret) {
dev_err(nandc->dev, "failure to read page\n");
@@ -1245,13 +1695,19 @@ static int qcom_nandc_read_page_raw(stru ct mtd_info *mtd,
@@ -1245,13 +1695,19 @@ static int qcom_nandc_read_page_raw(stru
u8 *data_buf, *oob_buf;
struct nand_ecc_ctrl *ecc = &chip->ecc;
int i, ret;
@ -893,7 +891,7 @@ index 76a0ffc..9d941e3 100644
for (i = 0; i < ecc->steps; i++) {
int data_size1, data_size2, oob_size1, oob_size2;
int reg_off = FLASH_BUF_ACC;
@@ -1269,21 +1725,49 @@ static int qcom_nandc_read_page_raw(stru ct mtd_info *mtd,
@@ -1269,21 +1725,49 @@ static int qcom_nandc_read_page_raw(stru
oob_size2 = host->ecc_bytes_hw + host->spare_bytes;
}
@ -948,7 +946,7 @@ index 76a0ffc..9d941e3 100644
oob_buf += oob_size2;
}
@@ -1306,6 +1790,7 @@ static int qcom_nandc_read_oob(struct mt d_info *mtd, struct nand_chip *chip,
@@ -1306,6 +1790,7 @@ static int qcom_nandc_read_oob(struct mt
int ret;
clear_read_regs(nandc);
@ -956,7 +954,7 @@ index 76a0ffc..9d941e3 100644
host->use_ecc = true;
set_address(host, 0, page);
@@ -1329,6 +1814,7 @@ static int qcom_nandc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
@@ -1329,6 +1814,7 @@ static int qcom_nandc_write_page(struct
int i, ret;
clear_read_regs(nandc);
@ -964,7 +962,7 @@ index 76a0ffc..9d941e3 100644
data_buf = (u8 *)buf;
oob_buf = chip->oob_poi;
@@ -1350,7 +1836,8 @@ static int qcom_nandc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
@@ -1350,7 +1836,8 @@ static int qcom_nandc_write_page(struct
config_cw_write_pre(nandc);
@ -974,7 +972,7 @@ index 76a0ffc..9d941e3 100644
/*
* when ECC is enabled, we don't really need to write anything
@@ -1363,7 +1850,7 @@ static int qcom_nandc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
@@ -1363,7 +1850,7 @@ static int qcom_nandc_write_page(struct
oob_buf += host->bbm_size;
write_data_dma(nandc, FLASH_BUF_ACC + data_size,
@ -983,7 +981,7 @@ index 76a0ffc..9d941e3 100644
}
config_cw_write_post(nandc);
@@ -1393,6 +1880,7 @@ static int qcom_nandc_write_page_raw(str uct mtd_info *mtd,
@@ -1393,6 +1880,7 @@ static int qcom_nandc_write_page_raw(str
int i, ret;
clear_read_regs(nandc);
@ -991,7 +989,7 @@ index 76a0ffc..9d941e3 100644
data_buf = (u8 *)buf;
oob_buf = chip->oob_poi;
@@ -1419,19 +1907,22 @@ static int qcom_nandc_write_page_raw(str uct mtd_info *mtd,
@@ -1419,19 +1907,22 @@ static int qcom_nandc_write_page_raw(str
config_cw_write_pre(nandc);
@ -1018,7 +1016,7 @@ index 76a0ffc..9d941e3 100644
oob_buf += oob_size2;
config_cw_write_post(nandc);
@@ -1467,6 +1958,7 @@ static int qcom_nandc_write_oob(struct m td_info *mtd, struct nand_chip *chip,
@@ -1467,6 +1958,7 @@ static int qcom_nandc_write_oob(struct m
host->use_ecc = true;
@ -1026,7 +1024,7 @@ index 76a0ffc..9d941e3 100644
ret = copy_last_cw(host, page);
if (ret)
return ret;
@@ -1486,7 +1978,7 @@ static int qcom_nandc_write_oob(struct m td_info *mtd, struct nand_chip *chip,
@@ -1486,7 +1978,7 @@ static int qcom_nandc_write_oob(struct m
config_cw_write_pre(nandc);
write_data_dma(nandc, FLASH_BUF_ACC, nandc->data_buffer,
@ -1035,7 +1033,7 @@ index 76a0ffc..9d941e3 100644
config_cw_write_post(nandc);
ret = submit_descs(nandc);
@@ -1524,6 +2016,7 @@ static int qcom_nandc_block_bad(struct m td_info *mtd, loff_t ofs)
@@ -1524,6 +2016,7 @@ static int qcom_nandc_block_bad(struct m
*/
host->use_ecc = false;
@ -1043,7 +1041,7 @@ index 76a0ffc..9d941e3 100644
ret = copy_last_cw(host, page);
if (ret)
goto err;
@@ -1554,6 +2047,7 @@ static int qcom_nandc_block_markbad(stru ct mtd_info *mtd, loff_t ofs)
@@ -1554,6 +2047,7 @@ static int qcom_nandc_block_markbad(stru
int page, ret, status = 0;
clear_read_regs(nandc);
@ -1051,7 +1049,7 @@ index 76a0ffc..9d941e3 100644
/*
* to mark the BBM as bad, we flash the entire last codeword with 0s.
@@ -1570,7 +2064,8 @@ static int qcom_nandc_block_markbad(stru ct mtd_info *mtd, loff_t ofs)
@@ -1570,7 +2064,8 @@ static int qcom_nandc_block_markbad(stru
update_rw_regs(host, 1, false);
config_cw_write_pre(nandc);
@ -1061,7 +1059,7 @@ index 76a0ffc..9d941e3 100644
config_cw_write_post(nandc);
ret = submit_descs(nandc);
@@ -1930,6 +2425,8 @@ static int qcom_nand_host_setup(struct q com_nand_host *host)
@@ -1930,6 +2425,8 @@ static int qcom_nand_host_setup(struct q
host->clrflashstatus = FS_READY_BSY_N;
host->clrreadstatus = 0xc0;
@ -1070,7 +1068,7 @@ index 76a0ffc..9d941e3 100644
dev_dbg(nandc->dev,
"cfg0 %x cfg1 %x ecc_buf_cfg %x ecc_bch cfg %x cw_size %d cw_data %d strength %d parity_bytes %d steps %d\n",
@@ -2008,6 +2505,12 @@ static int qcom_nandc_alloc(struct qcom_ nand_controller *nandc)
@@ -2008,6 +2505,12 @@ static int qcom_nandc_alloc(struct qcom_
dev_err(nandc->dev, "failed to request cmd channel\n");
return -ENODEV;
}
@ -1083,7 +1081,7 @@ index 76a0ffc..9d941e3 100644
}
INIT_LIST_HEAD(&nandc->desc_list);
@@ -2043,6 +2546,9 @@ static void qcom_nandc_unalloc(struct qc om_nand_controller *nandc)
@@ -2043,6 +2546,9 @@ static void qcom_nandc_unalloc(struct qc
devm_kfree(nandc->dev, nandc->reg_read_buf);
}
@ -1093,7 +1091,7 @@ index 76a0ffc..9d941e3 100644
if (nandc->regs)
devm_kfree(nandc->dev, nandc->regs);
@@ -2053,11 +2559,18 @@ static void qcom_nandc_unalloc(struct qc om_nand_controller *nandc)
@@ -2053,11 +2559,18 @@ static void qcom_nandc_unalloc(struct qc
/* one time setup of a few nand controller registers */
static int qcom_nandc_setup(struct qcom_nand_controller *nandc)
{
@ -1114,9 +1112,6 @@ index 76a0ffc..9d941e3 100644
/* save the original values of these registers */
nandc->cmd1 = nandc_read(nandc, NAND_DEV_CMD1);
diff --git a/include/linux/dma/qcom_bam_dma.h b/include/linux/dma/qcom_bam_dma.h
new file mode 100644
index 0000000..7e87a85
--- /dev/null
+++ b/include/linux/dma/qcom_bam_dma.h
@@ -0,0 +1,149 @@
@ -1269,5 +1264,3 @@ index 0000000..7e87a85
+ bam_ce->mask = 0xFFFFFFFF;
+}
+#endif
--
2.7.2