Commit ce329305 authored by Phil Edworthy's avatar Phil Edworthy Committed by Grant Likely

spi/sh-hspi: add CS manual control support

The current HSPI driver used automatic CS control, leading to CS
active for each byte transmitted. This patch changes the driver
to manual CS control, and ensures CS is active thoughout a whole
message. Additionally, it uses the cs_change field to determine
if CS is disabled between transfers in the message.
Signed-off-by: default avatarPhil Edworthy <phil.edworthy@renesas.com>
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
parent 74317984
...@@ -68,6 +68,16 @@ static u32 hspi_read(struct hspi_priv *hspi, int reg) ...@@ -68,6 +68,16 @@ static u32 hspi_read(struct hspi_priv *hspi, int reg)
return ioread32(hspi->addr + reg); return ioread32(hspi->addr + reg);
} }
static void hspi_bit_set(struct hspi_priv *hspi, int reg, u32 mask, u32 set)
{
u32 val = hspi_read(hspi, reg);
val &= ~mask;
val |= set & mask;
hspi_write(hspi, reg, val);
}
/* /*
* transfer function * transfer function
*/ */
...@@ -105,6 +115,13 @@ static int hspi_unprepare_transfer(struct spi_master *master) ...@@ -105,6 +115,13 @@ static int hspi_unprepare_transfer(struct spi_master *master)
return 0; return 0;
} }
#define hspi_hw_cs_enable(hspi) hspi_hw_cs_ctrl(hspi, 0)
#define hspi_hw_cs_disable(hspi) hspi_hw_cs_ctrl(hspi, 1)
static void hspi_hw_cs_ctrl(struct hspi_priv *hspi, int hi)
{
hspi_bit_set(hspi, SPSCR, (1 << 6), (hi) << 6);
}
static void hspi_hw_setup(struct hspi_priv *hspi, static void hspi_hw_setup(struct hspi_priv *hspi,
struct spi_message *msg, struct spi_message *msg,
struct spi_transfer *t) struct spi_transfer *t)
...@@ -155,7 +172,7 @@ static void hspi_hw_setup(struct hspi_priv *hspi, ...@@ -155,7 +172,7 @@ static void hspi_hw_setup(struct hspi_priv *hspi,
hspi_write(hspi, SPCR, spcr); hspi_write(hspi, SPCR, spcr);
hspi_write(hspi, SPSR, 0x0); hspi_write(hspi, SPSR, 0x0);
hspi_write(hspi, SPSCR, 0x1); /* master mode */ hspi_write(hspi, SPSCR, 0x21); /* master mode / CS control */
} }
static int hspi_transfer_one_message(struct spi_master *master, static int hspi_transfer_one_message(struct spi_master *master,
...@@ -166,12 +183,21 @@ static int hspi_transfer_one_message(struct spi_master *master, ...@@ -166,12 +183,21 @@ static int hspi_transfer_one_message(struct spi_master *master,
u32 tx; u32 tx;
u32 rx; u32 rx;
int ret, i; int ret, i;
unsigned int cs_change;
const int nsecs = 50;
dev_dbg(hspi->dev, "%s\n", __func__); dev_dbg(hspi->dev, "%s\n", __func__);
cs_change = 1;
ret = 0; ret = 0;
list_for_each_entry(t, &msg->transfers, transfer_list) { list_for_each_entry(t, &msg->transfers, transfer_list) {
if (cs_change) {
hspi_hw_setup(hspi, msg, t); hspi_hw_setup(hspi, msg, t);
hspi_hw_cs_enable(hspi);
ndelay(nsecs);
}
cs_change = t->cs_change;
for (i = 0; i < t->len; i++) { for (i = 0; i < t->len; i++) {
...@@ -198,9 +224,22 @@ static int hspi_transfer_one_message(struct spi_master *master, ...@@ -198,9 +224,22 @@ static int hspi_transfer_one_message(struct spi_master *master,
} }
msg->actual_length += t->len; msg->actual_length += t->len;
if (t->delay_usecs)
udelay(t->delay_usecs);
if (cs_change) {
ndelay(nsecs);
hspi_hw_cs_disable(hspi);
ndelay(nsecs);
}
} }
msg->status = ret; msg->status = ret;
if (!cs_change) {
ndelay(nsecs);
hspi_hw_cs_disable(hspi);
}
spi_finalize_current_message(master); spi_finalize_current_message(master);
return ret; return ret;
......
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