mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
mtd: rawnand: qcom: move common code to the 'qpic_common' module
The 'qpic_common' module provides some generic functions which are usable by both the 'qcom_nandc' and by the 'spi-qpic-snand' driver. Move more code from the 'qcom_nandc' driver to there in order to allow using those also from the 'spi-qpic-snand' driver. No functional changes. Signed-off-by: Gabor Juhos <j4g8y7@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
This commit is contained in:
parent
555d48e520
commit
cfae2182fa
|
|
@ -775,5 +775,136 @@ int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
|
|||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_alloc);
|
||||
|
||||
/* reads back FLASH_STATUS register set by the controller */
|
||||
int qcom_nandc_check_flash_errors(struct qcom_nand_controller *nandc,
|
||||
int cw_cnt)
|
||||
{
|
||||
int i;
|
||||
|
||||
qcom_nandc_dev_to_mem(nandc, true);
|
||||
|
||||
for (i = 0; i < cw_cnt; i++) {
|
||||
u32 flash = le32_to_cpu(nandc->reg_read_buf[i]);
|
||||
|
||||
if (flash & (FS_OP_ERR | FS_MPU_ERR))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_check_flash_errors);
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors for configuring registers
|
||||
* before reading a NAND page.
|
||||
*/
|
||||
void qcom_nandc_config_page_read(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->addr0, NAND_ADDR0, 2, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
|
||||
if (!nandc->props->qpic_version2)
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->ecc_buf_cfg, NAND_EBI2_ECC_BUF_CFG, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->erased_cw_detect_cfg_clr,
|
||||
NAND_ERASED_CW_DETECT_CFG, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->erased_cw_detect_cfg_set,
|
||||
NAND_ERASED_CW_DETECT_CFG, 1, NAND_ERASED_CW_SET | NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_config_page_read);
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors used to configure registers needed for
|
||||
* before writing a NAND page.
|
||||
*/
|
||||
void qcom_nandc_config_page_write(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->addr0, NAND_ADDR0, 2, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
|
||||
if (!nandc->props->qpic_version2)
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->ecc_buf_cfg, NAND_EBI2_ECC_BUF_CFG, 1,
|
||||
NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_config_page_write);
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors for configuring registers
|
||||
* before writing each codeword in NAND page.
|
||||
*/
|
||||
void qcom_nandc_config_cw_write(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cmd, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->exec, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL);
|
||||
|
||||
qcom_read_reg_dma(nandc, NAND_FLASH_STATUS, 1, NAND_BAM_NEXT_SGL);
|
||||
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->clrflashstatus, NAND_FLASH_STATUS, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->clrreadstatus, NAND_READ_STATUS, 1,
|
||||
NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_config_cw_write);
|
||||
|
||||
/**
|
||||
* qcom_nandc_set_read_loc_first() - to set read location first register
|
||||
* @nandc: NAND controller's private data
|
||||
* @reg_base: location register base
|
||||
* @cw_offset: code word offset
|
||||
* @read_size: code word read length
|
||||
* @is_last_read_loc: is this the last read location
|
||||
*
|
||||
* This function will set location register value
|
||||
*/
|
||||
void qcom_nandc_set_read_loc_first(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc)
|
||||
{
|
||||
__le32 locreg_val;
|
||||
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
|
||||
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
|
||||
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
|
||||
|
||||
locreg_val = cpu_to_le32(val);
|
||||
|
||||
if (reg_base == NAND_READ_LOCATION_0)
|
||||
nandc->regs->read_location0 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_1)
|
||||
nandc->regs->read_location1 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_2)
|
||||
nandc->regs->read_location2 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_3)
|
||||
nandc->regs->read_location3 = locreg_val;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_set_read_loc_first);
|
||||
|
||||
/**
|
||||
* qcom_nandc_set_read_loc_last - to set read location last register
|
||||
* @nandc: NAND controller's private data
|
||||
* @reg_base: location register base
|
||||
* @cw_offset: code word offset
|
||||
* @read_size: code word read length
|
||||
* @is_last_read_loc: is this the last read location
|
||||
*
|
||||
* This function will set location last register value
|
||||
*/
|
||||
void qcom_nandc_set_read_loc_last(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc)
|
||||
{
|
||||
__le32 locreg_val;
|
||||
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
|
||||
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
|
||||
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
|
||||
|
||||
locreg_val = cpu_to_le32(val);
|
||||
|
||||
if (reg_base == NAND_READ_LOCATION_LAST_CW_0)
|
||||
nandc->regs->read_location_last0 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_1)
|
||||
nandc->regs->read_location_last1 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_2)
|
||||
nandc->regs->read_location_last2 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_3)
|
||||
nandc->regs->read_location_last3 = locreg_val;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_nandc_set_read_loc_last);
|
||||
|
||||
MODULE_DESCRIPTION("QPIC controller common api");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
|
|
|||
|
|
@ -149,68 +149,6 @@ static bool qcom_nandc_is_last_cw(struct nand_ecc_ctrl *ecc, int cw)
|
|||
return cw == (ecc->steps - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* qcom_nandc_set_read_loc_first() - to set read location first register
|
||||
* @nandc: NAND controller's private data
|
||||
* @reg_base: location register base
|
||||
* @cw_offset: code word offset
|
||||
* @read_size: code word read length
|
||||
* @is_last_read_loc: is this the last read location
|
||||
*
|
||||
* This function will set location register value
|
||||
*/
|
||||
static void qcom_nandc_set_read_loc_first(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc)
|
||||
{
|
||||
__le32 locreg_val;
|
||||
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
|
||||
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
|
||||
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
|
||||
|
||||
locreg_val = cpu_to_le32(val);
|
||||
|
||||
if (reg_base == NAND_READ_LOCATION_0)
|
||||
nandc->regs->read_location0 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_1)
|
||||
nandc->regs->read_location1 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_2)
|
||||
nandc->regs->read_location2 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_3)
|
||||
nandc->regs->read_location3 = locreg_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* qcom_nandc_set_read_loc_last - to set read location last register
|
||||
* @nandc: NAND controller's private data
|
||||
* @reg_base: location register base
|
||||
* @cw_offset: code word offset
|
||||
* @read_size: code word read length
|
||||
* @is_last_read_loc: is this the last read location
|
||||
*
|
||||
* This function will set location last register value
|
||||
*/
|
||||
static void qcom_nandc_set_read_loc_last(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc)
|
||||
{
|
||||
__le32 locreg_val;
|
||||
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
|
||||
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
|
||||
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
|
||||
|
||||
locreg_val = cpu_to_le32(val);
|
||||
|
||||
if (reg_base == NAND_READ_LOCATION_LAST_CW_0)
|
||||
nandc->regs->read_location_last0 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_1)
|
||||
nandc->regs->read_location_last1 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_2)
|
||||
nandc->regs->read_location_last2 = locreg_val;
|
||||
else if (reg_base == NAND_READ_LOCATION_LAST_CW_3)
|
||||
nandc->regs->read_location_last3 = locreg_val;
|
||||
}
|
||||
|
||||
/* helper to configure location register values */
|
||||
static void nandc_set_read_loc(struct nand_chip *chip, int cw, int reg,
|
||||
u32 cw_offset, u32 read_size, u32 is_last_read_loc)
|
||||
|
|
@ -301,22 +239,6 @@ static void update_rw_regs(struct qcom_nand_host *host, int num_cw, bool read, i
|
|||
host->cw_data : host->cw_size, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors for configuring registers
|
||||
* before reading a NAND page.
|
||||
*/
|
||||
static void qcom_nandc_config_page_read(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->addr0, NAND_ADDR0, 2, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
|
||||
if (!nandc->props->qpic_version2)
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->ecc_buf_cfg, NAND_EBI2_ECC_BUF_CFG, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->erased_cw_detect_cfg_clr,
|
||||
NAND_ERASED_CW_DETECT_CFG, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->erased_cw_detect_cfg_set,
|
||||
NAND_ERASED_CW_DETECT_CFG, 1, NAND_ERASED_CW_SET | NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors for configuring registers
|
||||
* before reading each codeword in NAND page.
|
||||
|
|
@ -361,35 +283,6 @@ config_nand_single_cw_page_read(struct nand_chip *chip,
|
|||
config_nand_cw_read(chip, use_ecc, cw);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors used to configure registers needed for
|
||||
* before writing a NAND page.
|
||||
*/
|
||||
static void qcom_nandc_config_page_write(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->addr0, NAND_ADDR0, 2, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
|
||||
if (!nandc->props->qpic_version2)
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->ecc_buf_cfg, NAND_EBI2_ECC_BUF_CFG, 1,
|
||||
NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper to prepare DMA descriptors for configuring registers
|
||||
* before writing each codeword in NAND page.
|
||||
*/
|
||||
static void qcom_nandc_config_cw_write(struct qcom_nand_controller *nandc)
|
||||
{
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->cmd, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->exec, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL);
|
||||
|
||||
qcom_read_reg_dma(nandc, NAND_FLASH_STATUS, 1, NAND_BAM_NEXT_SGL);
|
||||
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->clrflashstatus, NAND_FLASH_STATUS, 1, 0);
|
||||
qcom_write_reg_dma(nandc, &nandc->regs->clrreadstatus, NAND_READ_STATUS, 1,
|
||||
NAND_BAM_NEXT_SGL);
|
||||
}
|
||||
|
||||
/*
|
||||
* when using BCH ECC, the HW flags an error in NAND_FLASH_STATUS if it read
|
||||
* an erased CW, and reports an erased CW in NAND_ERASED_CW_DETECT_STATUS.
|
||||
|
|
@ -438,30 +331,6 @@ static bool erased_chunk_check_and_fixup(u8 *data_buf, int data_len)
|
|||
return true;
|
||||
}
|
||||
|
||||
struct qcom_nandc_read_stats {
|
||||
__le32 flash;
|
||||
__le32 buffer;
|
||||
__le32 erased_cw;
|
||||
};
|
||||
|
||||
/* reads back FLASH_STATUS register set by the controller */
|
||||
static int qcom_nandc_check_flash_errors(struct qcom_nand_controller *nandc,
|
||||
int cw_cnt)
|
||||
{
|
||||
int i;
|
||||
|
||||
qcom_nandc_dev_to_mem(nandc, true);
|
||||
|
||||
for (i = 0; i < cw_cnt; i++) {
|
||||
u32 flash = le32_to_cpu(nandc->reg_read_buf[i]);
|
||||
|
||||
if (flash & (FS_OP_ERR | FS_MPU_ERR))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* performs raw read for one codeword */
|
||||
static int
|
||||
qcom_nandc_read_cw_raw(struct mtd_info *mtd, struct nand_chip *chip,
|
||||
|
|
|
|||
|
|
@ -457,6 +457,12 @@ struct qcom_nandc_props {
|
|||
bool use_codeword_fixup;
|
||||
};
|
||||
|
||||
struct qcom_nandc_read_stats {
|
||||
__le32 flash;
|
||||
__le32 buffer;
|
||||
__le32 erased_cw;
|
||||
};
|
||||
|
||||
void qcom_free_bam_transaction(struct qcom_nand_controller *nandc);
|
||||
struct bam_transaction *qcom_alloc_bam_transaction(struct qcom_nand_controller *nandc);
|
||||
void qcom_clear_bam_transaction(struct qcom_nand_controller *nandc);
|
||||
|
|
@ -482,5 +488,16 @@ int qcom_submit_descs(struct qcom_nand_controller *nandc);
|
|||
void qcom_clear_read_regs(struct qcom_nand_controller *nandc);
|
||||
void qcom_nandc_unalloc(struct qcom_nand_controller *nandc);
|
||||
int qcom_nandc_alloc(struct qcom_nand_controller *nandc);
|
||||
int qcom_nandc_check_flash_errors(struct qcom_nand_controller *nandc,
|
||||
int cw_cnt);
|
||||
void qcom_nandc_config_page_read(struct qcom_nand_controller *nandc);
|
||||
void qcom_nandc_config_page_write(struct qcom_nand_controller *nandc);
|
||||
void qcom_nandc_config_cw_write(struct qcom_nand_controller *nandc);
|
||||
void qcom_nandc_set_read_loc_first(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc);
|
||||
void qcom_nandc_set_read_loc_last(struct qcom_nand_controller *nandc,
|
||||
int reg_base, u32 cw_offset,
|
||||
u32 read_size, u32 is_last_read_loc);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user