Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 95079
b: refs/heads/master
c: 592e7bf
h: refs/heads/master
i:
  95077: 26f0ff8
  95075: d0a3ca9
  95071: 1269bfa
v: v3
  • Loading branch information
Haavard Skinnemoen authored and Linus Torvalds committed Apr 30, 2008
1 parent 98cfab3 commit 825fc9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 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: c6495aaabfaa8256c292c54b48ab081f4d86ad79
refs/heads/master: 592e7bf80566bf5ac3ed073d4e198dd5b0824c04
29 changes: 20 additions & 9 deletions trunk/drivers/spi/atmel_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ static int atmel_spi_setup(struct spi_device *spi)
struct atmel_spi *as;
u32 scbr, csr;
unsigned int bits = spi->bits_per_word;
unsigned long bus_hz, sck_hz;
unsigned long bus_hz;
unsigned int npcs_pin;
int ret;

Expand Down Expand Up @@ -536,23 +536,34 @@ static int atmel_spi_setup(struct spi_device *spi)
return -EINVAL;
}

/* speed zero convention is used by some upper layers */
/*
* Pre-new_1 chips start out at half the peripheral
* bus speed.
*/
bus_hz = clk_get_rate(as->clk);
if (!as->new_1)
bus_hz /= 2;

if (spi->max_speed_hz) {
/* assume div32/fdiv/mbz == 0 */
if (!as->new_1)
bus_hz /= 2;
scbr = ((bus_hz + spi->max_speed_hz - 1)
/ spi->max_speed_hz);
/*
* Calculate the lowest divider that satisfies the
* constraint, assuming div32/fdiv/mbz == 0.
*/
scbr = DIV_ROUND_UP(bus_hz, spi->max_speed_hz);

/*
* If the resulting divider doesn't fit into the
* register bitfield, we can't satisfy the constraint.
*/
if (scbr >= (1 << SPI_SCBR_SIZE)) {
dev_dbg(&spi->dev,
"setup: %d Hz too slow, scbr %u; min %ld Hz\n",
spi->max_speed_hz, scbr, bus_hz/255);
return -EINVAL;
}
} else
/* speed zero means "as slow as possible" */
scbr = 0xff;
sck_hz = bus_hz / scbr;

csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8);
if (spi->mode & SPI_CPOL)
Expand Down Expand Up @@ -589,7 +600,7 @@ static int atmel_spi_setup(struct spi_device *spi)

dev_dbg(&spi->dev,
"setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
sck_hz, bits, spi->mode, spi->chip_select, csr);
bus_hz / scbr, bits, spi->mode, spi->chip_select, csr);

spi_writel(as, CSR0 + 4 * spi->chip_select, csr);

Expand Down

0 comments on commit 825fc9e

Please sign in to comment.