Skip to content

Commit

Permalink
spi: sc18is602: Convert to let spi core validate transfer speed
Browse files Browse the repository at this point in the history
Set master->max_speed_hz and master->min_speed_hz then spi core will handle
checking transfer speed. So we can remove the same checking in this driver.

This patch also remove testing if hz is 0 because spi->max_speed_hz will be
default set to master->min_speed_hz if it was not set. So the transfer speed
will never set to 0.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Axel Lin authored and Mark Brown committed Mar 13, 2014
1 parent c5c67e3 commit 09e99bc
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions drivers/spi/spi-sc18is602.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,9 @@ static int sc18is602_setup_transfer(struct sc18is602 *hw, u32 hz, u8 mode)
static int sc18is602_check_transfer(struct spi_device *spi,
struct spi_transfer *t, int tlen)
{
uint32_t hz;

if (t && t->len + tlen > SC18IS602_BUFSIZ)
return -EINVAL;

hz = spi->max_speed_hz;
if (t && t->speed_hz)
hz = t->speed_hz;
if (hz == 0)
return -EINVAL;

return 0;
}

Expand All @@ -207,14 +199,13 @@ static int sc18is602_transfer_one(struct spi_master *master,

hw->tlen = 0;
list_for_each_entry(t, &m->transfers, transfer_list) {
u32 hz = t->speed_hz ? : spi->max_speed_hz;
bool do_transfer;

status = sc18is602_check_transfer(spi, t, hw->tlen);
if (status < 0)
break;

status = sc18is602_setup_transfer(hw, hz, spi->mode);
status = sc18is602_setup_transfer(hw, t->speed_hz, spi->mode);
if (status < 0)
break;

Expand Down Expand Up @@ -305,6 +296,8 @@ static int sc18is602_probe(struct i2c_client *client,
master->setup = sc18is602_setup;
master->transfer_one_message = sc18is602_transfer_one;
master->dev.of_node = np;
master->min_speed_hz = hw->freq / 128;
master->max_speed_hz = hw->freq / 4;

error = devm_spi_register_master(dev, master);
if (error)
Expand Down

0 comments on commit 09e99bc

Please sign in to comment.