Commit 1dc8ca71 authored by Mark Brown's avatar Mark Brown

spi: amlogic-spifc-a1: fixes and improvements for

Merge series from Martin Kurbanov <mmkurbanov@sberdevices.ru>:

This series adds support for max_speed_hz and implement adjust_op_size()
callback.
parents b8968c38 8d4d4c68
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
#define SPIFC_A1_USER_DBUF_ADDR_REG 0x248 #define SPIFC_A1_USER_DBUF_ADDR_REG 0x248
#define SPIFC_A1_BUFFER_SIZE 512 #define SPIFC_A1_BUFFER_SIZE 512U
#define SPIFC_A1_MAX_HZ 200000000 #define SPIFC_A1_MAX_HZ 200000000
#define SPIFC_A1_MIN_HZ 1000000 #define SPIFC_A1_MIN_HZ 1000000
...@@ -107,6 +107,7 @@ struct amlogic_spifc_a1 { ...@@ -107,6 +107,7 @@ struct amlogic_spifc_a1 {
struct clk *clk; struct clk *clk;
struct device *dev; struct device *dev;
void __iomem *base; void __iomem *base;
u32 curr_speed_hz;
}; };
static int amlogic_spifc_a1_request(struct amlogic_spifc_a1 *spifc, bool read) static int amlogic_spifc_a1_request(struct amlogic_spifc_a1 *spifc, bool read)
...@@ -235,66 +236,68 @@ static int amlogic_spifc_a1_write(struct amlogic_spifc_a1 *spifc, ...@@ -235,66 +236,68 @@ static int amlogic_spifc_a1_write(struct amlogic_spifc_a1 *spifc,
return amlogic_spifc_a1_request(spifc, false); return amlogic_spifc_a1_request(spifc, false);
} }
static int amlogic_spifc_a1_exec_op(struct spi_mem *mem, static int amlogic_spifc_a1_set_freq(struct amlogic_spifc_a1 *spifc, u32 freq)
const struct spi_mem_op *op)
{ {
struct amlogic_spifc_a1 *spifc =
spi_controller_get_devdata(mem->spi->controller);
size_t off, nbytes = op->data.nbytes;
u32 cmd_cfg, addr_cfg, dummy_cfg, dmode;
int ret; int ret;
amlogic_spifc_a1_user_init(spifc); if (freq == spifc->curr_speed_hz)
return 0;
cmd_cfg = SPIFC_A1_USER_CMD(op);
amlogic_spifc_a1_set_cmd(spifc, cmd_cfg);
if (op->addr.nbytes) { ret = clk_set_rate(spifc->clk, freq);
addr_cfg = SPIFC_A1_USER_ADDR(op); if (ret)
amlogic_spifc_a1_set_addr(spifc, op->addr.val, addr_cfg); return ret;
}
if (op->dummy.nbytes) { spifc->curr_speed_hz = freq;
dummy_cfg = SPIFC_A1_USER_DUMMY(op); return 0;
amlogic_spifc_a1_set_dummy(spifc, dummy_cfg); }
}
if (!op->data.nbytes) static int amlogic_spifc_a1_exec_op(struct spi_mem *mem,
return amlogic_spifc_a1_request(spifc, false); const struct spi_mem_op *op)
{
struct amlogic_spifc_a1 *spifc =
spi_controller_get_devdata(mem->spi->controller);
size_t data_size = op->data.nbytes;
int ret;
dmode = ilog2(op->data.buswidth); ret = amlogic_spifc_a1_set_freq(spifc, mem->spi->max_speed_hz);
off = 0; if (ret)
return ret;
do { amlogic_spifc_a1_user_init(spifc);
size_t block_size = min_t(size_t, nbytes, SPIFC_A1_BUFFER_SIZE); amlogic_spifc_a1_set_cmd(spifc, SPIFC_A1_USER_CMD(op));
amlogic_spifc_a1_set_cmd(spifc, cmd_cfg); if (op->addr.nbytes)
amlogic_spifc_a1_set_addr(spifc, op->addr.val,
SPIFC_A1_USER_ADDR(op));
if (op->addr.nbytes) if (op->dummy.nbytes)
amlogic_spifc_a1_set_addr(spifc, op->addr.val + off, amlogic_spifc_a1_set_dummy(spifc, SPIFC_A1_USER_DUMMY(op));
addr_cfg);
if (op->dummy.nbytes) if (data_size) {
amlogic_spifc_a1_set_dummy(spifc, dummy_cfg); u32 mode = ilog2(op->data.buswidth);
writel(0, spifc->base + SPIFC_A1_USER_DBUF_ADDR_REG); writel(0, spifc->base + SPIFC_A1_USER_DBUF_ADDR_REG);
if (op->data.dir == SPI_MEM_DATA_IN) if (op->data.dir == SPI_MEM_DATA_IN)
ret = amlogic_spifc_a1_read(spifc, ret = amlogic_spifc_a1_read(spifc, op->data.buf.in,
op->data.buf.in + off, data_size, mode);
block_size, dmode);
else else
ret = amlogic_spifc_a1_write(spifc, ret = amlogic_spifc_a1_write(spifc, op->data.buf.out,
op->data.buf.out + off, data_size, mode);
block_size, dmode); } else {
ret = amlogic_spifc_a1_request(spifc, false);
nbytes -= block_size; }
off += block_size;
} while (nbytes != 0 && !ret);
return ret; return ret;
} }
static int amlogic_spifc_a1_adjust_op_size(struct spi_mem *mem,
struct spi_mem_op *op)
{
op->data.nbytes = min(op->data.nbytes, SPIFC_A1_BUFFER_SIZE);
return 0;
}
static void amlogic_spifc_a1_hw_init(struct amlogic_spifc_a1 *spifc) static void amlogic_spifc_a1_hw_init(struct amlogic_spifc_a1 *spifc)
{ {
u32 regv; u32 regv;
...@@ -314,6 +317,7 @@ static void amlogic_spifc_a1_hw_init(struct amlogic_spifc_a1 *spifc) ...@@ -314,6 +317,7 @@ static void amlogic_spifc_a1_hw_init(struct amlogic_spifc_a1 *spifc)
static const struct spi_controller_mem_ops amlogic_spifc_a1_mem_ops = { static const struct spi_controller_mem_ops amlogic_spifc_a1_mem_ops = {
.exec_op = amlogic_spifc_a1_exec_op, .exec_op = amlogic_spifc_a1_exec_op,
.adjust_op_size = amlogic_spifc_a1_adjust_op_size,
}; };
static int amlogic_spifc_a1_probe(struct platform_device *pdev) static int amlogic_spifc_a1_probe(struct platform_device *pdev)
......
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