Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 343611
b: refs/heads/master
c: ce32930
h: refs/heads/master
i:
  343609: 9496c58
  343607: b993a92
v: v3
  • Loading branch information
Phil Edworthy authored and Grant Likely committed Nov 23, 2012
1 parent 35d8e97 commit 0f0deca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 743179849015dc71bb2ea63d8cd4bfa7fdfb4bc6
refs/heads/master: ce3293058637ada3b1837a77c8f9c672a51b2434
43 changes: 41 additions & 2 deletions trunk/drivers/spi/spi-sh-hspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ static u32 hspi_read(struct hspi_priv *hspi, int 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
*/
Expand Down Expand Up @@ -105,6 +115,13 @@ static int hspi_unprepare_transfer(struct spi_master *master)
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,
struct spi_message *msg,
struct spi_transfer *t)
Expand Down Expand Up @@ -155,7 +172,7 @@ static void hspi_hw_setup(struct hspi_priv *hspi,

hspi_write(hspi, SPCR, spcr);
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,
Expand All @@ -166,12 +183,21 @@ static int hspi_transfer_one_message(struct spi_master *master,
u32 tx;
u32 rx;
int ret, i;
unsigned int cs_change;
const int nsecs = 50;

dev_dbg(hspi->dev, "%s\n", __func__);

cs_change = 1;
ret = 0;
list_for_each_entry(t, &msg->transfers, transfer_list) {
hspi_hw_setup(hspi, msg, t);

if (cs_change) {
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++) {

Expand All @@ -198,9 +224,22 @@ static int hspi_transfer_one_message(struct spi_master *master,
}

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;
if (!cs_change) {
ndelay(nsecs);
hspi_hw_cs_disable(hspi);
}
spi_finalize_current_message(master);

return ret;
Expand Down

0 comments on commit 0f0deca

Please sign in to comment.