mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 06:33:34 +00:00
spi: spi-mtk-nor: Unify write buffer on/off
The logical structures of mtk_nor_write_buffer_enable and mtk_nor_write_buffer_disable are very similar, So it is necessary to combine them into one. Signed-off-by: bayi cheng <bayi.cheng@mediatek.com> Link: https://lore.kernel.org/r/20221115124655.10124-1-bayi.cheng@mediatek.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
ec4a04aa69
commit
63d9a4d884
@ -444,36 +444,28 @@ static int mtk_nor_read_pio(struct mtk_nor *sp, const struct spi_mem_op *op)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mtk_nor_write_buffer_enable(struct mtk_nor *sp)
|
||||
static int mtk_nor_setup_write_buffer(struct mtk_nor *sp, bool on)
|
||||
{
|
||||
int ret;
|
||||
u32 val;
|
||||
|
||||
if (sp->wbuf_en)
|
||||
if (!(sp->wbuf_en ^ on))
|
||||
return 0;
|
||||
|
||||
val = readl(sp->base + MTK_NOR_REG_CFG2);
|
||||
writel(val | MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
|
||||
ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
|
||||
val & MTK_NOR_WR_BUF_EN, 0, 10000);
|
||||
if (!ret)
|
||||
sp->wbuf_en = true;
|
||||
return ret;
|
||||
}
|
||||
if (on) {
|
||||
writel(val | MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
|
||||
ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
|
||||
val & MTK_NOR_WR_BUF_EN, 0, 10000);
|
||||
} else {
|
||||
writel(val & ~MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
|
||||
ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
|
||||
!(val & MTK_NOR_WR_BUF_EN), 0, 10000);
|
||||
}
|
||||
|
||||
static int mtk_nor_write_buffer_disable(struct mtk_nor *sp)
|
||||
{
|
||||
int ret;
|
||||
u32 val;
|
||||
|
||||
if (!sp->wbuf_en)
|
||||
return 0;
|
||||
val = readl(sp->base + MTK_NOR_REG_CFG2);
|
||||
writel(val & ~MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
|
||||
ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
|
||||
!(val & MTK_NOR_WR_BUF_EN), 0, 10000);
|
||||
if (!ret)
|
||||
sp->wbuf_en = false;
|
||||
sp->wbuf_en = on;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -483,7 +475,7 @@ static int mtk_nor_pp_buffered(struct mtk_nor *sp, const struct spi_mem_op *op)
|
||||
u32 val;
|
||||
int ret, i;
|
||||
|
||||
ret = mtk_nor_write_buffer_enable(sp);
|
||||
ret = mtk_nor_setup_write_buffer(sp, true);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -502,7 +494,7 @@ static int mtk_nor_pp_unbuffered(struct mtk_nor *sp,
|
||||
const u8 *buf = op->data.buf.out;
|
||||
int ret;
|
||||
|
||||
ret = mtk_nor_write_buffer_disable(sp);
|
||||
ret = mtk_nor_setup_write_buffer(sp, false);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
writeb(buf[0], sp->base + MTK_NOR_REG_WDATA);
|
||||
@ -609,7 +601,7 @@ static int mtk_nor_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
|
||||
}
|
||||
|
||||
if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op)) {
|
||||
ret = mtk_nor_write_buffer_disable(sp);
|
||||
ret = mtk_nor_setup_write_buffer(sp, false);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
mtk_nor_setup_bus(sp, op);
|
||||
|
Loading…
Reference in New Issue
Block a user