mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 07:04:24 +00:00
spi: mxic: Create a helper to configure the controller before an operation
Create the mxic_spi_set_hc_cfg() helper to configure the HC_CFG register. This helper will soon be used by the dirmap implementation and having this code factorized out earlier will clarify this addition. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/linux-mtd/20220127091808.1043392-11-miquel.raynal@bootlin.com
This commit is contained in:
parent
5fd6739e0d
commit
b7b64db74e
1 changed files with 19 additions and 12 deletions
|
@ -280,6 +280,22 @@ static void mxic_spi_hw_init(struct mxic_spi *mxic)
|
|||
mxic->regs + HC_CFG);
|
||||
}
|
||||
|
||||
static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags)
|
||||
{
|
||||
int nio = 1;
|
||||
|
||||
if (spi->mode & (SPI_TX_OCTAL | SPI_RX_OCTAL))
|
||||
nio = 8;
|
||||
else if (spi->mode & (SPI_TX_QUAD | SPI_RX_QUAD))
|
||||
nio = 4;
|
||||
else if (spi->mode & (SPI_TX_DUAL | SPI_RX_DUAL))
|
||||
nio = 2;
|
||||
|
||||
return flags | HC_CFG_NIO(nio) |
|
||||
HC_CFG_TYPE(spi->chip_select, HC_CFG_TYPE_SPI_NOR) |
|
||||
HC_CFG_SLV_ACT(spi->chip_select) | HC_CFG_IDLE_SIO_LVL(1);
|
||||
}
|
||||
|
||||
static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,
|
||||
void *rxbuf, unsigned int len)
|
||||
{
|
||||
|
@ -349,7 +365,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
|
|||
const struct spi_mem_op *op)
|
||||
{
|
||||
struct mxic_spi *mxic = spi_master_get_devdata(mem->spi->master);
|
||||
int nio = 1, i, ret;
|
||||
int i, ret;
|
||||
u32 ss_ctrl;
|
||||
u8 addr[8], cmd[2];
|
||||
|
||||
|
@ -357,18 +373,9 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (mem->spi->mode & (SPI_TX_OCTAL | SPI_RX_OCTAL))
|
||||
nio = 8;
|
||||
else if (mem->spi->mode & (SPI_TX_QUAD | SPI_RX_QUAD))
|
||||
nio = 4;
|
||||
else if (mem->spi->mode & (SPI_TX_DUAL | SPI_RX_DUAL))
|
||||
nio = 2;
|
||||
|
||||
writel(HC_CFG_NIO(nio) |
|
||||
HC_CFG_TYPE(mem->spi->chip_select, HC_CFG_TYPE_SPI_NOR) |
|
||||
HC_CFG_SLV_ACT(mem->spi->chip_select) | HC_CFG_IDLE_SIO_LVL(1) |
|
||||
HC_CFG_MAN_CS_EN,
|
||||
writel(mxic_spi_prep_hc_cfg(mem->spi, HC_CFG_MAN_CS_EN),
|
||||
mxic->regs + HC_CFG);
|
||||
|
||||
writel(HC_EN_BIT, mxic->regs + HC_EN);
|
||||
|
||||
ss_ctrl = OP_CMD_BYTES(op->cmd.nbytes) |
|
||||
|
|
Loading…
Reference in a new issue