Skip to content

Commit

Permalink
spi: omap-100k: Rely on validations done by spi core
Browse files Browse the repository at this point in the history
SPI core validates both bits_per_word and speed_hz transfer parameters and
defaults to spi->bits_per_word and spi->max_speed_hz in case these per
transfer parameters are not set.

This allows to remove a few if statements around per transfer bits_per_word
and speed_hz tests as they evaluate always to true.

Also defaulting word_len to 8 is needless since spi_setup() has already
made sure spi->bits_per_word is 8 in case it is not set.

Signed-off-by: Jarkko Nikula <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
jhnikula authored and broonie committed Sep 17, 2015
1 parent 6ff33f3 commit 76f67ea
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions drivers/spi/spi-omap-100k.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ static int omap1_spi100k_setup_transfer(struct spi_device *spi,
{
struct omap1_spi100k *spi100k = spi_master_get_devdata(spi->master);
struct omap1_spi100k_cs *cs = spi->controller_state;
u8 word_len = spi->bits_per_word;
u8 word_len;

if (t != NULL && t->bits_per_word)
if (t != NULL)
word_len = t->bits_per_word;
if (!word_len)
word_len = 8;
else
word_len = spi->bits_per_word;

if (spi->bits_per_word > 32)
return -EINVAL;
Expand Down Expand Up @@ -302,22 +302,16 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master,
struct spi_device *spi = m->spi;
struct spi_transfer *t = NULL;
int cs_active = 0;
int par_override = 0;
int status = 0;

list_for_each_entry(t, &m->transfers, transfer_list) {
if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
status = -EINVAL;
break;
}
if (par_override || t->speed_hz || t->bits_per_word) {
par_override = 1;
status = omap1_spi100k_setup_transfer(spi, t);
if (status < 0)
break;
if (!t->speed_hz && !t->bits_per_word)
par_override = 0;
}
status = omap1_spi100k_setup_transfer(spi, t);
if (status < 0)
break;

if (!cs_active) {
omap1_spi100k_force_cs(spi100k, 1);
Expand Down Expand Up @@ -347,11 +341,7 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master,
}
}

/* Restore defaults if they were overriden */
if (par_override) {
par_override = 0;
status = omap1_spi100k_setup_transfer(spi, NULL);
}
status = omap1_spi100k_setup_transfer(spi, NULL);

if (cs_active)
omap1_spi100k_force_cs(spi100k, 0);
Expand Down

0 comments on commit 76f67ea

Please sign in to comment.