Commit b057e498 authored by Md Sadre Alam's avatar Md Sadre Alam Committed by Miquel Raynal

mtd: rawnand: qcom: Add helper to check last code word

Add the qcom_nandc_is_last_cw() helper which checks if
the input cw index is the last one or not.
Signed-off-by: default avatarMd Sadre Alam <mdalam@codeaurora.org>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/1614109141-7531-2-git-send-email-mdalam@codeaurora.org
parent 9a7c39e2
...@@ -662,6 +662,12 @@ static void nandc_set_reg(struct nand_chip *chip, int offset, ...@@ -662,6 +662,12 @@ static void nandc_set_reg(struct nand_chip *chip, int offset,
*reg = cpu_to_le32(val); *reg = cpu_to_le32(val);
} }
/* Helper to check the code word, whether it is last cw or not */
static bool qcom_nandc_is_last_cw(struct nand_ecc_ctrl *ecc, int cw)
{
return cw == (ecc->steps - 1);
}
/* helper to configure address register values */ /* helper to configure address register values */
static void set_address(struct qcom_nand_host *host, u16 column, int page) static void set_address(struct qcom_nand_host *host, u16 column, int page)
{ {
...@@ -1629,7 +1635,7 @@ qcom_nandc_read_cw_raw(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1629,7 +1635,7 @@ qcom_nandc_read_cw_raw(struct mtd_info *mtd, struct nand_chip *chip,
data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1); data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1);
oob_size1 = host->bbm_size; oob_size1 = host->bbm_size;
if (cw == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, cw)) {
data_size2 = ecc->size - data_size1 - data_size2 = ecc->size - data_size1 -
((ecc->steps - 1) * 4); ((ecc->steps - 1) * 4);
oob_size2 = (ecc->steps * 4) + host->ecc_bytes_hw + oob_size2 = (ecc->steps * 4) + host->ecc_bytes_hw +
...@@ -1710,7 +1716,7 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf, ...@@ -1710,7 +1716,7 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf,
} }
for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) { for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) {
if (cw == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, cw)) {
data_size = ecc->size - ((ecc->steps - 1) * 4); data_size = ecc->size - ((ecc->steps - 1) * 4);
oob_size = (ecc->steps * 4) + host->ecc_bytes_hw; oob_size = (ecc->steps * 4) + host->ecc_bytes_hw;
} else { } else {
...@@ -1770,7 +1776,7 @@ static int parse_read_errors(struct qcom_nand_host *host, u8 *data_buf, ...@@ -1770,7 +1776,7 @@ static int parse_read_errors(struct qcom_nand_host *host, u8 *data_buf,
u32 flash, buffer, erased_cw; u32 flash, buffer, erased_cw;
int data_len, oob_len; int data_len, oob_len;
if (i == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, i)) {
data_len = ecc->size - ((ecc->steps - 1) << 2); data_len = ecc->size - ((ecc->steps - 1) << 2);
oob_len = ecc->steps << 2; oob_len = ecc->steps << 2;
} else { } else {
...@@ -1869,7 +1875,7 @@ static int read_page_ecc(struct qcom_nand_host *host, u8 *data_buf, ...@@ -1869,7 +1875,7 @@ static int read_page_ecc(struct qcom_nand_host *host, u8 *data_buf,
for (i = 0; i < ecc->steps; i++) { for (i = 0; i < ecc->steps; i++) {
int data_size, oob_size; int data_size, oob_size;
if (i == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, i)) {
data_size = ecc->size - ((ecc->steps - 1) << 2); data_size = ecc->size - ((ecc->steps - 1) << 2);
oob_size = (ecc->steps << 2) + host->ecc_bytes_hw + oob_size = (ecc->steps << 2) + host->ecc_bytes_hw +
host->spare_bytes; host->spare_bytes;
...@@ -2048,7 +2054,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf, ...@@ -2048,7 +2054,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf,
for (i = 0; i < ecc->steps; i++) { for (i = 0; i < ecc->steps; i++) {
int data_size, oob_size; int data_size, oob_size;
if (i == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, i)) {
data_size = ecc->size - ((ecc->steps - 1) << 2); data_size = ecc->size - ((ecc->steps - 1) << 2);
oob_size = (ecc->steps << 2) + host->ecc_bytes_hw + oob_size = (ecc->steps << 2) + host->ecc_bytes_hw +
host->spare_bytes; host->spare_bytes;
...@@ -2068,7 +2074,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf, ...@@ -2068,7 +2074,7 @@ static int qcom_nandc_write_page(struct nand_chip *chip, const uint8_t *buf,
* itself. For the last codeword, we skip the bbm positions and * itself. For the last codeword, we skip the bbm positions and
* write to the free oob area. * write to the free oob area.
*/ */
if (i == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, i)) {
oob_buf += host->bbm_size; oob_buf += host->bbm_size;
write_data_dma(nandc, FLASH_BUF_ACC + data_size, write_data_dma(nandc, FLASH_BUF_ACC + data_size,
...@@ -2123,7 +2129,7 @@ static int qcom_nandc_write_page_raw(struct nand_chip *chip, ...@@ -2123,7 +2129,7 @@ static int qcom_nandc_write_page_raw(struct nand_chip *chip,
data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1); data_size1 = mtd->writesize - host->cw_size * (ecc->steps - 1);
oob_size1 = host->bbm_size; oob_size1 = host->bbm_size;
if (i == (ecc->steps - 1)) { if (qcom_nandc_is_last_cw(ecc, i)) {
data_size2 = ecc->size - data_size1 - data_size2 = ecc->size - data_size1 -
((ecc->steps - 1) << 2); ((ecc->steps - 1) << 2);
oob_size2 = (ecc->steps << 2) + host->ecc_bytes_hw + oob_size2 = (ecc->steps << 2) + host->ecc_bytes_hw +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment