Commit 425f96d2 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

spi: txx9: Convert to let spi core handle checking transfer speed

By setting master->max_speed_hz and master->min_speed_hz, spi core will handle
checking transfer speed. Then we can remove the same checking in this driver.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Reviewed-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 38dbfb59
...@@ -80,7 +80,6 @@ struct txx9spi { ...@@ -80,7 +80,6 @@ struct txx9spi {
void __iomem *membase; void __iomem *membase;
int baseclk; int baseclk;
struct clk *clk; struct clk *clk;
u32 max_speed_hz, min_speed_hz;
int last_chipselect; int last_chipselect;
int last_chipselect_val; int last_chipselect_val;
}; };
...@@ -117,9 +116,7 @@ static int txx9spi_setup(struct spi_device *spi) ...@@ -117,9 +116,7 @@ static int txx9spi_setup(struct spi_device *spi)
{ {
struct txx9spi *c = spi_master_get_devdata(spi->master); struct txx9spi *c = spi_master_get_devdata(spi->master);
if (!spi->max_speed_hz if (!spi->max_speed_hz)
|| spi->max_speed_hz > c->max_speed_hz
|| spi->max_speed_hz < c->min_speed_hz)
return -EINVAL; return -EINVAL;
if (gpio_direction_output(spi->chip_select, if (gpio_direction_output(spi->chip_select,
...@@ -309,15 +306,12 @@ static int txx9spi_transfer(struct spi_device *spi, struct spi_message *m) ...@@ -309,15 +306,12 @@ static int txx9spi_transfer(struct spi_device *spi, struct spi_message *m)
/* check each transfer's parameters */ /* check each transfer's parameters */
list_for_each_entry(t, &m->transfers, transfer_list) { list_for_each_entry(t, &m->transfers, transfer_list) {
u32 speed_hz = t->speed_hz ? : spi->max_speed_hz;
u8 bits_per_word = t->bits_per_word; u8 bits_per_word = t->bits_per_word;
if (!t->tx_buf && !t->rx_buf && t->len) if (!t->tx_buf && !t->rx_buf && t->len)
return -EINVAL; return -EINVAL;
if (t->len & ((bits_per_word >> 3) - 1)) if (t->len & ((bits_per_word >> 3) - 1))
return -EINVAL; return -EINVAL;
if (speed_hz < c->min_speed_hz || speed_hz > c->max_speed_hz)
return -EINVAL;
} }
spin_lock_irqsave(&c->lock, flags); spin_lock_irqsave(&c->lock, flags);
...@@ -360,8 +354,8 @@ static int txx9spi_probe(struct platform_device *dev) ...@@ -360,8 +354,8 @@ static int txx9spi_probe(struct platform_device *dev)
goto exit; goto exit;
} }
c->baseclk = clk_get_rate(c->clk); c->baseclk = clk_get_rate(c->clk);
c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1); master->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1); master->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
res = platform_get_resource(dev, IORESOURCE_MEM, 0); res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res) if (!res)
......
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