Skip to content

Commit

Permalink
spi: convert drivers to use bits_per_word_mask
Browse files Browse the repository at this point in the history
Fill in the recently added spi_master.bits_per_word_mask field in as
many drivers as possible. Make related cleanups, such as removing any
redundant error-checking, or empty setup callbacks.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Stephen Warren authored and Mark Brown committed May 29, 2013
1 parent 2922a8d commit 24778be
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 280 deletions.
12 changes: 0 additions & 12 deletions drivers/spi/spi-altera.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ static void altera_spi_chipsel(struct spi_device *spi, int value)
}
}

static int altera_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
{
return 0;
}

static int altera_spi_setup(struct spi_device *spi)
{
return 0;
}

static inline unsigned int hw_txbyte(struct altera_spi *hw, int count)
{
if (hw->tx) {
Expand Down Expand Up @@ -231,7 +221,6 @@ static int altera_spi_probe(struct platform_device *pdev)
master->bus_num = pdev->id;
master->num_chipselect = 16;
master->mode_bits = SPI_CS_HIGH;
master->setup = altera_spi_setup;

hw = spi_master_get_devdata(master);
platform_set_drvdata(pdev, hw);
Expand All @@ -240,7 +229,6 @@ static int altera_spi_probe(struct platform_device *pdev)
hw->bitbang.master = spi_master_get(master);
if (!hw->bitbang.master)
return err;
hw->bitbang.setup_transfer = altera_spi_setupxfer;
hw->bitbang.chipselect = altera_spi_chipsel;
hw->bitbang.txrx_bufs = altera_spi_txrx;

Expand Down
4 changes: 1 addition & 3 deletions drivers/spi/spi-ath79.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ static int ath79_spi_setup(struct spi_device *spi)
{
int status = 0;

if (spi->bits_per_word > 32)
return -EINVAL;

if (!spi->controller_state) {
status = ath79_spi_setup_cs(spi);
if (status)
Expand Down Expand Up @@ -226,6 +223,7 @@ static int ath79_spi_probe(struct platform_device *pdev)

pdata = pdev->dev.platform_data;

master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
master->setup = ath79_spi_setup;
master->cleanup = ath79_spi_cleanup;
if (pdata) {
Expand Down
9 changes: 1 addition & 8 deletions drivers/spi/spi-atmel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,13 +1268,6 @@ static int atmel_spi_setup(struct spi_device *spi)
return -EINVAL;
}

if (bits < 8 || bits > 16) {
dev_dbg(&spi->dev,
"setup: invalid bits_per_word %u (8 to 16)\n",
bits);
return -EINVAL;
}

/* see notes above re chipselect */
if (!atmel_spi_is_v2(as)
&& spi->chip_select == 0
Expand Down Expand Up @@ -1515,7 +1508,7 @@ static int atmel_spi_probe(struct platform_device *pdev)

/* the spi->mode bits understood by this driver: */
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;

master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
master->dev.of_node = pdev->dev.of_node;
master->bus_num = pdev->id;
master->num_chipselect = master->dev.of_node ? 0 : 4;
Expand Down
12 changes: 1 addition & 11 deletions drivers/spi/spi-au1550.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
hz = t->speed_hz;
}

if (bpw < 4 || bpw > 24) {
dev_err(&spi->dev, "setupxfer: invalid bits_per_word=%d\n",
bpw);
return -EINVAL;
}
if (hz > spi->max_speed_hz || hz > hw->freq_max || hz < hw->freq_min) {
dev_err(&spi->dev, "setupxfer: clock rate=%d out of range\n",
hz);
Expand Down Expand Up @@ -296,12 +291,6 @@ static int au1550_spi_setup(struct spi_device *spi)
{
struct au1550_spi *hw = spi_master_get_devdata(spi->master);

if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
spi->bits_per_word);
return -EINVAL;
}

if (spi->max_speed_hz == 0)
spi->max_speed_hz = hw->freq_max;
if (spi->max_speed_hz > hw->freq_max
Expand Down Expand Up @@ -782,6 +771,7 @@ static int au1550_spi_probe(struct platform_device *pdev)

/* the spi->mode bits understood by this driver: */
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 24);

hw = spi_master_get_devdata(master);

Expand Down
20 changes: 1 addition & 19 deletions drivers/spi/spi-bcm63xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ static void bcm63xx_spi_setup_transfer(struct spi_device *spi,
/* the spi->mode bits understood by this driver: */
#define MODEBITS (SPI_CPOL | SPI_CPHA)

static int bcm63xx_spi_setup(struct spi_device *spi)
{
if (spi->bits_per_word != 8) {
dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
__func__, spi->bits_per_word);
return -EINVAL;
}

return 0;
}

static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *first,
unsigned int num_transfers)
{
Expand Down Expand Up @@ -277,13 +266,6 @@ static int bcm63xx_spi_transfer_one(struct spi_master *master,
* full-duplex transfers.
*/
list_for_each_entry(t, &m->transfers, transfer_list) {
if (t->bits_per_word != 8) {
dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
__func__, t->bits_per_word);
status = -EINVAL;
goto exit;
}

if (!first)
first = t;

Expand Down Expand Up @@ -430,11 +412,11 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)

master->bus_num = pdata->bus_num;
master->num_chipselect = pdata->num_chipselect;
master->setup = bcm63xx_spi_setup;
master->prepare_transfer_hardware = bcm63xx_spi_prepare_transfer;
master->unprepare_transfer_hardware = bcm63xx_spi_unprepare_transfer;
master->transfer_one_message = bcm63xx_spi_transfer_one;
master->mode_bits = MODEBITS;
master->bits_per_word_mask = SPI_BPW_MASK(8);
bs->msg_type_shift = pdata->msg_type_shift;
bs->msg_ctl_width = pdata->msg_ctl_width;
bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA));
Expand Down
10 changes: 2 additions & 8 deletions drivers/spi/spi-bfin-sport.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ bfin_sport_spi_pump_transfers(unsigned long data)

/* Bits per word setup */
bits_per_word = transfer->bits_per_word;
if (bits_per_word % 16 == 0)
if (bits_per_word == 16)
drv_data->ops = &bfin_sport_transfer_ops_u16;
else
drv_data->ops = &bfin_sport_transfer_ops_u8;
Expand Down Expand Up @@ -600,13 +600,6 @@ bfin_sport_spi_setup(struct spi_device *spi)
}
}

if (spi->bits_per_word % 8) {
dev_err(&spi->dev, "%d bits_per_word is not supported\n",
spi->bits_per_word);
ret = -EINVAL;
goto error;
}

/* translate common spi framework into our register
* following configure contents are same for tx and rx.
*/
Expand Down Expand Up @@ -778,6 +771,7 @@ static int bfin_sport_spi_probe(struct platform_device *pdev)
drv_data->pin_req = platform_info->pin_req;

master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
master->bus_num = pdev->id;
master->num_chipselect = platform_info->num_chipselect;
master->cleanup = bfin_sport_spi_cleanup;
Expand Down
21 changes: 5 additions & 16 deletions drivers/spi/spi-bfin5xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,21 +643,16 @@ static void bfin_spi_pump_transfers(unsigned long data)

/* Bits per word setup */
bits_per_word = transfer->bits_per_word;
if (bits_per_word % 16 == 0) {
if (bits_per_word == 16) {
drv_data->n_bytes = bits_per_word/8;
drv_data->len = (transfer->len) >> 1;
cr_width = BIT_CTL_WORDSIZE;
drv_data->ops = &bfin_bfin_spi_transfer_ops_u16;
} else if (bits_per_word % 8 == 0) {
} else if (bits_per_word == 8) {
drv_data->n_bytes = bits_per_word/8;
drv_data->len = transfer->len;
cr_width = 0;
drv_data->ops = &bfin_bfin_spi_transfer_ops_u8;
} else {
dev_err(&drv_data->pdev->dev, "transfer: unsupported bits_per_word\n");
message->status = -EINVAL;
bfin_spi_giveback(drv_data);
return;
}
cr = bfin_read(&drv_data->regs->ctl) & ~(BIT_CTL_TIMOD | BIT_CTL_WORDSIZE);
cr |= cr_width;
Expand Down Expand Up @@ -808,13 +803,13 @@ static void bfin_spi_pump_transfers(unsigned long data)
bfin_write(&drv_data->regs->tdbr, chip->idle_tx_val);
else {
int loop;
if (bits_per_word % 16 == 0) {
if (bits_per_word == 16) {
u16 *buf = (u16 *)drv_data->tx;
for (loop = 0; loop < bits_per_word / 16;
loop++) {
bfin_write(&drv_data->regs->tdbr, *buf++);
}
} else if (bits_per_word % 8 == 0) {
} else if (bits_per_word == 8) {
u8 *buf = (u8 *)drv_data->tx;
for (loop = 0; loop < bits_per_word / 8; loop++)
bfin_write(&drv_data->regs->tdbr, *buf++);
Expand Down Expand Up @@ -1033,12 +1028,6 @@ static int bfin_spi_setup(struct spi_device *spi)
chip->ctl_reg &= bfin_ctl_reg;
}

if (spi->bits_per_word % 8) {
dev_err(&spi->dev, "%d bits_per_word is not supported\n",
spi->bits_per_word);
goto error;
}

/* translate common spi framework into our register */
if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {
dev_err(&spi->dev, "unsupported spi modes detected\n");
Expand Down Expand Up @@ -1299,7 +1288,7 @@ static int bfin_spi_probe(struct platform_device *pdev)

/* the spi->mode bits supported by this driver: */
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;

master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
master->bus_num = pdev->id;
master->num_chipselect = platform_info->num_chipselect;
master->cleanup = bfin_spi_cleanup;
Expand Down
7 changes: 1 addition & 6 deletions drivers/spi/spi-clps711x.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ static int spi_clps711x_setup(struct spi_device *spi)
{
struct spi_clps711x_data *hw = spi_master_get_devdata(spi->master);

if (spi->bits_per_word != 8) {
dev_err(&spi->dev, "Unsupported master bus width %i\n",
spi->bits_per_word);
return -EINVAL;
}

/* We are expect that SPI-device is not selected */
gpio_direction_output(hw->chipselect[spi->chip_select],
!(spi->mode & SPI_CS_HIGH));
Expand Down Expand Up @@ -190,6 +184,7 @@ static int spi_clps711x_probe(struct platform_device *pdev)

master->bus_num = pdev->id;
master->mode_bits = SPI_CPHA | SPI_CS_HIGH;
master->bits_per_word_mask = SPI_BPW_MASK(8);
master->num_chipselect = pdata->num_chipselect;
master->setup = spi_clps711x_setup;
master->transfer_one_message = spi_clps711x_transfer_one_message;
Expand Down
11 changes: 2 additions & 9 deletions drivers/spi/spi-coldfire-qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ static int mcfqspi_transfer_one_message(struct spi_master *master,
bool cs_high = spi->mode & SPI_CS_HIGH;
u16 qmr = MCFQSPI_QMR_MSTR;

if (t->bits_per_word)
qmr |= t->bits_per_word << 10;
else
qmr |= spi->bits_per_word << 10;
qmr |= t->bits_per_word << 10;
if (spi->mode & SPI_CPHA)
qmr |= MCFQSPI_QMR_CPHA;
if (spi->mode & SPI_CPOL)
Expand Down Expand Up @@ -377,11 +374,6 @@ static int mcfqspi_unprepare_transfer_hw(struct spi_master *master)

static int mcfqspi_setup(struct spi_device *spi)
{
if ((spi->bits_per_word < 8) || (spi->bits_per_word > 16)) {
dev_dbg(&spi->dev, "%d bits per word is not supported\n",
spi->bits_per_word);
return -EINVAL;
}
if (spi->chip_select >= spi->master->num_chipselect) {
dev_dbg(&spi->dev, "%d chip select is out of range\n",
spi->chip_select);
Expand Down Expand Up @@ -477,6 +469,7 @@ static int mcfqspi_probe(struct platform_device *pdev)
mcfqspi->dev = &pdev->dev;

master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
master->setup = mcfqspi_setup;
master->transfer_one_message = mcfqspi_transfer_one_message;
master->prepare_transfer_hardware = mcfqspi_prepare_transfer_hw;
Expand Down
8 changes: 4 additions & 4 deletions drivers/spi/spi-davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,15 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
* Assign function pointer to appropriate transfer method
* 8bit, 16bit or 32bit transfer
*/
if (bits_per_word <= 8 && bits_per_word >= 2) {
if (bits_per_word <= 8) {
dspi->get_rx = davinci_spi_rx_buf_u8;
dspi->get_tx = davinci_spi_tx_buf_u8;
dspi->bytes_per_word[spi->chip_select] = 1;
} else if (bits_per_word <= 16 && bits_per_word >= 2) {
} else {
dspi->get_rx = davinci_spi_rx_buf_u16;
dspi->get_tx = davinci_spi_tx_buf_u16;
dspi->bytes_per_word[spi->chip_select] = 2;
} else
return -EINVAL;
}

if (!hz)
hz = spi->max_speed_hz;
Expand Down Expand Up @@ -933,6 +932,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
master->dev.of_node = pdev->dev.of_node;
master->bus_num = pdev->id;
master->num_chipselect = pdata->num_chipselect;
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(2, 16);
master->setup = davinci_spi_setup;

dspi->bitbang.chipselect = davinci_spi_chipselect;
Expand Down
26 changes: 4 additions & 22 deletions drivers/spi/spi-dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,7 @@ static void pump_transfers(unsigned long data)
}
if (transfer->bits_per_word) {
bits = transfer->bits_per_word;

switch (bits) {
case 8:
case 16:
dws->n_bytes = dws->dma_width = bits >> 3;
break;
default:
printk(KERN_ERR "MRST SPI0: unsupported bits:"
"%db\n", bits);
message->status = -EIO;
goto early_exit;
}

dws->n_bytes = dws->dma_width = bits >> 3;
cr0 = (bits - 1)
| (chip->type << SPI_FRF_OFFSET)
| (spi->mode << SPI_MODE_OFFSET)
Expand Down Expand Up @@ -629,9 +617,6 @@ static int dw_spi_setup(struct spi_device *spi)
struct dw_spi_chip *chip_info = NULL;
struct chip_data *chip;

if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
return -EINVAL;

/* Only alloc on first setup */
chip = spi_get_ctldata(spi);
if (!chip) {
Expand Down Expand Up @@ -660,16 +645,12 @@ static int dw_spi_setup(struct spi_device *spi)
chip->enable_dma = chip_info->enable_dma;
}

if (spi->bits_per_word <= 8) {
if (spi->bits_per_word == 8) {
chip->n_bytes = 1;
chip->dma_width = 1;
} else if (spi->bits_per_word <= 16) {
} else if (spi->bits_per_word == 16) {
chip->n_bytes = 2;
chip->dma_width = 2;
} else {
/* Never take >16b case for MRST SPIC */
dev_err(&spi->dev, "invalid wordsize\n");
return -EINVAL;
}
chip->bits_per_word = spi->bits_per_word;

Expand Down Expand Up @@ -824,6 +805,7 @@ int dw_spi_add_host(struct dw_spi *dws)
}

master->mode_bits = SPI_CPOL | SPI_CPHA;
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
master->bus_num = dws->bus_num;
master->num_chipselect = dws->num_cs;
master->cleanup = dw_spi_cleanup;
Expand Down
Loading

0 comments on commit 24778be

Please sign in to comment.