Skip to content

Commit 9da06d7

Browse files
legoaterbroonie
authored andcommitted
spi: aspeed: Add support for direct mapping
Use direct mapping to read the flash device contents. This operation mode is called "Command mode" on Aspeed SoC SMC controllers. It uses a Control Register for the settings to apply when a memory operation is performed on the flash device mapping window. If the window is not big enough, fall back to the "User mode" to perform the read. Direct mapping for writes will come later when validated. Reviewed-by: Joel Stanley <[email protected]> Tested-by: Joel Stanley <[email protected]> Tested-by: Tao Ren <[email protected]> Tested-by: Jae Hyun Yoo <[email protected]> Signed-off-by: Cédric Le Goater <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e3228ed commit 9da06d7

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

drivers/spi/spi-aspeed-smc.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,78 @@ static int aspeed_spi_chip_set_default_window(struct aspeed_spi_chip *chip)
411411
return chip->ahb_window_size ? 0 : -1;
412412
}
413413

414+
static int aspeed_spi_dirmap_create(struct spi_mem_dirmap_desc *desc)
415+
{
416+
struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master);
417+
struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select];
418+
struct spi_mem_op *op = &desc->info.op_tmpl;
419+
u32 ctl_val;
420+
int ret = 0;
421+
422+
chip->clk_freq = desc->mem->spi->max_speed_hz;
423+
424+
/* Only for reads */
425+
if (op->data.dir != SPI_MEM_DATA_IN)
426+
return -EOPNOTSUPP;
427+
428+
if (desc->info.length > chip->ahb_window_size)
429+
dev_warn(aspi->dev, "CE%d window (%dMB) too small for mapping",
430+
chip->cs, chip->ahb_window_size >> 20);
431+
432+
/* Define the default IO read settings */
433+
ctl_val = readl(chip->ctl) & ~CTRL_IO_CMD_MASK;
434+
ctl_val |= aspeed_spi_get_io_mode(op) |
435+
op->cmd.opcode << CTRL_COMMAND_SHIFT |
436+
CTRL_IO_DUMMY_SET(op->dummy.nbytes / op->dummy.buswidth) |
437+
CTRL_IO_MODE_READ;
438+
439+
/* Tune 4BYTE address mode */
440+
if (op->addr.nbytes) {
441+
u32 addr_mode = readl(aspi->regs + CE_CTRL_REG);
442+
443+
if (op->addr.nbytes == 4)
444+
addr_mode |= (0x11 << chip->cs);
445+
else
446+
addr_mode &= ~(0x11 << chip->cs);
447+
writel(addr_mode, aspi->regs + CE_CTRL_REG);
448+
}
449+
450+
/* READ mode is the controller default setting */
451+
chip->ctl_val[ASPEED_SPI_READ] = ctl_val;
452+
writel(chip->ctl_val[ASPEED_SPI_READ], chip->ctl);
453+
454+
dev_info(aspi->dev, "CE%d read buswidth:%d [0x%08x]\n",
455+
chip->cs, op->data.buswidth, chip->ctl_val[ASPEED_SPI_READ]);
456+
457+
return ret;
458+
}
459+
460+
static ssize_t aspeed_spi_dirmap_read(struct spi_mem_dirmap_desc *desc,
461+
u64 offset, size_t len, void *buf)
462+
{
463+
struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master);
464+
struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select];
465+
466+
/* Switch to USER command mode if mapping window is too small */
467+
if (chip->ahb_window_size < offset + len) {
468+
int ret;
469+
470+
ret = aspeed_spi_read_user(chip, &desc->info.op_tmpl, offset, len, buf);
471+
if (ret < 0)
472+
return ret;
473+
} else {
474+
memcpy_fromio(buf, chip->ahb_base + offset, len);
475+
}
476+
477+
return len;
478+
}
479+
414480
static const struct spi_controller_mem_ops aspeed_spi_mem_ops = {
415481
.supports_op = aspeed_spi_supports_op,
416482
.exec_op = aspeed_spi_exec_op,
417483
.get_name = aspeed_spi_get_name,
484+
.dirmap_create = aspeed_spi_dirmap_create,
485+
.dirmap_read = aspeed_spi_dirmap_read,
418486
};
419487

420488
static void aspeed_spi_chip_set_type(struct aspeed_spi *aspi, unsigned int cs, int type)

0 commit comments

Comments
 (0)