Skip to content

Commit 24778be

Browse files
swarrenbroonie
authored andcommitted
spi: convert drivers to use bits_per_word_mask
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 <[email protected]> Acked-by: H Hartley Sweeten <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 2922a8d commit 24778be

28 files changed

+46
-280
lines changed

drivers/spi/spi-altera.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ static void altera_spi_chipsel(struct spi_device *spi, int value)
103103
}
104104
}
105105

106-
static int altera_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
107-
{
108-
return 0;
109-
}
110-
111-
static int altera_spi_setup(struct spi_device *spi)
112-
{
113-
return 0;
114-
}
115-
116106
static inline unsigned int hw_txbyte(struct altera_spi *hw, int count)
117107
{
118108
if (hw->tx) {
@@ -231,7 +221,6 @@ static int altera_spi_probe(struct platform_device *pdev)
231221
master->bus_num = pdev->id;
232222
master->num_chipselect = 16;
233223
master->mode_bits = SPI_CS_HIGH;
234-
master->setup = altera_spi_setup;
235224

236225
hw = spi_master_get_devdata(master);
237226
platform_set_drvdata(pdev, hw);
@@ -240,7 +229,6 @@ static int altera_spi_probe(struct platform_device *pdev)
240229
hw->bitbang.master = spi_master_get(master);
241230
if (!hw->bitbang.master)
242231
return err;
243-
hw->bitbang.setup_transfer = altera_spi_setupxfer;
244232
hw->bitbang.chipselect = altera_spi_chipsel;
245233
hw->bitbang.txrx_bufs = altera_spi_txrx;
246234

drivers/spi/spi-ath79.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ static int ath79_spi_setup(struct spi_device *spi)
155155
{
156156
int status = 0;
157157

158-
if (spi->bits_per_word > 32)
159-
return -EINVAL;
160-
161158
if (!spi->controller_state) {
162159
status = ath79_spi_setup_cs(spi);
163160
if (status)
@@ -226,6 +223,7 @@ static int ath79_spi_probe(struct platform_device *pdev)
226223

227224
pdata = pdev->dev.platform_data;
228225

226+
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
229227
master->setup = ath79_spi_setup;
230228
master->cleanup = ath79_spi_cleanup;
231229
if (pdata) {

drivers/spi/spi-atmel.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,13 +1268,6 @@ static int atmel_spi_setup(struct spi_device *spi)
12681268
return -EINVAL;
12691269
}
12701270

1271-
if (bits < 8 || bits > 16) {
1272-
dev_dbg(&spi->dev,
1273-
"setup: invalid bits_per_word %u (8 to 16)\n",
1274-
bits);
1275-
return -EINVAL;
1276-
}
1277-
12781271
/* see notes above re chipselect */
12791272
if (!atmel_spi_is_v2(as)
12801273
&& spi->chip_select == 0
@@ -1515,7 +1508,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
15151508

15161509
/* the spi->mode bits understood by this driver: */
15171510
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1518-
1511+
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
15191512
master->dev.of_node = pdev->dev.of_node;
15201513
master->bus_num = pdev->id;
15211514
master->num_chipselect = master->dev.of_node ? 0 : 4;

drivers/spi/spi-au1550.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
248248
hz = t->speed_hz;
249249
}
250250

251-
if (bpw < 4 || bpw > 24) {
252-
dev_err(&spi->dev, "setupxfer: invalid bits_per_word=%d\n",
253-
bpw);
254-
return -EINVAL;
255-
}
256251
if (hz > spi->max_speed_hz || hz > hw->freq_max || hz < hw->freq_min) {
257252
dev_err(&spi->dev, "setupxfer: clock rate=%d out of range\n",
258253
hz);
@@ -296,12 +291,6 @@ static int au1550_spi_setup(struct spi_device *spi)
296291
{
297292
struct au1550_spi *hw = spi_master_get_devdata(spi->master);
298293

299-
if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
300-
dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
301-
spi->bits_per_word);
302-
return -EINVAL;
303-
}
304-
305294
if (spi->max_speed_hz == 0)
306295
spi->max_speed_hz = hw->freq_max;
307296
if (spi->max_speed_hz > hw->freq_max
@@ -782,6 +771,7 @@ static int au1550_spi_probe(struct platform_device *pdev)
782771

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

786776
hw = spi_master_get_devdata(master);
787777

drivers/spi/spi-bcm63xx.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ static void bcm63xx_spi_setup_transfer(struct spi_device *spi,
124124
/* the spi->mode bits understood by this driver: */
125125
#define MODEBITS (SPI_CPOL | SPI_CPHA)
126126

127-
static int bcm63xx_spi_setup(struct spi_device *spi)
128-
{
129-
if (spi->bits_per_word != 8) {
130-
dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
131-
__func__, spi->bits_per_word);
132-
return -EINVAL;
133-
}
134-
135-
return 0;
136-
}
137-
138127
static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *first,
139128
unsigned int num_transfers)
140129
{
@@ -277,13 +266,6 @@ static int bcm63xx_spi_transfer_one(struct spi_master *master,
277266
* full-duplex transfers.
278267
*/
279268
list_for_each_entry(t, &m->transfers, transfer_list) {
280-
if (t->bits_per_word != 8) {
281-
dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
282-
__func__, t->bits_per_word);
283-
status = -EINVAL;
284-
goto exit;
285-
}
286-
287269
if (!first)
288270
first = t;
289271

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

431413
master->bus_num = pdata->bus_num;
432414
master->num_chipselect = pdata->num_chipselect;
433-
master->setup = bcm63xx_spi_setup;
434415
master->prepare_transfer_hardware = bcm63xx_spi_prepare_transfer;
435416
master->unprepare_transfer_hardware = bcm63xx_spi_unprepare_transfer;
436417
master->transfer_one_message = bcm63xx_spi_transfer_one;
437418
master->mode_bits = MODEBITS;
419+
master->bits_per_word_mask = SPI_BPW_MASK(8);
438420
bs->msg_type_shift = pdata->msg_type_shift;
439421
bs->msg_ctl_width = pdata->msg_ctl_width;
440422
bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA));

drivers/spi/spi-bfin-sport.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ bfin_sport_spi_pump_transfers(unsigned long data)
417417

418418
/* Bits per word setup */
419419
bits_per_word = transfer->bits_per_word;
420-
if (bits_per_word % 16 == 0)
420+
if (bits_per_word == 16)
421421
drv_data->ops = &bfin_sport_transfer_ops_u16;
422422
else
423423
drv_data->ops = &bfin_sport_transfer_ops_u8;
@@ -600,13 +600,6 @@ bfin_sport_spi_setup(struct spi_device *spi)
600600
}
601601
}
602602

603-
if (spi->bits_per_word % 8) {
604-
dev_err(&spi->dev, "%d bits_per_word is not supported\n",
605-
spi->bits_per_word);
606-
ret = -EINVAL;
607-
goto error;
608-
}
609-
610603
/* translate common spi framework into our register
611604
* following configure contents are same for tx and rx.
612605
*/
@@ -778,6 +771,7 @@ static int bfin_sport_spi_probe(struct platform_device *pdev)
778771
drv_data->pin_req = platform_info->pin_req;
779772

780773
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
774+
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
781775
master->bus_num = pdev->id;
782776
master->num_chipselect = platform_info->num_chipselect;
783777
master->cleanup = bfin_sport_spi_cleanup;

drivers/spi/spi-bfin5xx.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,16 @@ static void bfin_spi_pump_transfers(unsigned long data)
643643

644644
/* Bits per word setup */
645645
bits_per_word = transfer->bits_per_word;
646-
if (bits_per_word % 16 == 0) {
646+
if (bits_per_word == 16) {
647647
drv_data->n_bytes = bits_per_word/8;
648648
drv_data->len = (transfer->len) >> 1;
649649
cr_width = BIT_CTL_WORDSIZE;
650650
drv_data->ops = &bfin_bfin_spi_transfer_ops_u16;
651-
} else if (bits_per_word % 8 == 0) {
651+
} else if (bits_per_word == 8) {
652652
drv_data->n_bytes = bits_per_word/8;
653653
drv_data->len = transfer->len;
654654
cr_width = 0;
655655
drv_data->ops = &bfin_bfin_spi_transfer_ops_u8;
656-
} else {
657-
dev_err(&drv_data->pdev->dev, "transfer: unsupported bits_per_word\n");
658-
message->status = -EINVAL;
659-
bfin_spi_giveback(drv_data);
660-
return;
661656
}
662657
cr = bfin_read(&drv_data->regs->ctl) & ~(BIT_CTL_TIMOD | BIT_CTL_WORDSIZE);
663658
cr |= cr_width;
@@ -808,13 +803,13 @@ static void bfin_spi_pump_transfers(unsigned long data)
808803
bfin_write(&drv_data->regs->tdbr, chip->idle_tx_val);
809804
else {
810805
int loop;
811-
if (bits_per_word % 16 == 0) {
806+
if (bits_per_word == 16) {
812807
u16 *buf = (u16 *)drv_data->tx;
813808
for (loop = 0; loop < bits_per_word / 16;
814809
loop++) {
815810
bfin_write(&drv_data->regs->tdbr, *buf++);
816811
}
817-
} else if (bits_per_word % 8 == 0) {
812+
} else if (bits_per_word == 8) {
818813
u8 *buf = (u8 *)drv_data->tx;
819814
for (loop = 0; loop < bits_per_word / 8; loop++)
820815
bfin_write(&drv_data->regs->tdbr, *buf++);
@@ -1033,12 +1028,6 @@ static int bfin_spi_setup(struct spi_device *spi)
10331028
chip->ctl_reg &= bfin_ctl_reg;
10341029
}
10351030

1036-
if (spi->bits_per_word % 8) {
1037-
dev_err(&spi->dev, "%d bits_per_word is not supported\n",
1038-
spi->bits_per_word);
1039-
goto error;
1040-
}
1041-
10421031
/* translate common spi framework into our register */
10431032
if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {
10441033
dev_err(&spi->dev, "unsupported spi modes detected\n");
@@ -1299,7 +1288,7 @@ static int bfin_spi_probe(struct platform_device *pdev)
12991288

13001289
/* the spi->mode bits supported by this driver: */
13011290
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
1302-
1291+
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
13031292
master->bus_num = pdev->id;
13041293
master->num_chipselect = platform_info->num_chipselect;
13051294
master->cleanup = bfin_spi_cleanup;

drivers/spi/spi-clps711x.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ static int spi_clps711x_setup(struct spi_device *spi)
4242
{
4343
struct spi_clps711x_data *hw = spi_master_get_devdata(spi->master);
4444

45-
if (spi->bits_per_word != 8) {
46-
dev_err(&spi->dev, "Unsupported master bus width %i\n",
47-
spi->bits_per_word);
48-
return -EINVAL;
49-
}
50-
5145
/* We are expect that SPI-device is not selected */
5246
gpio_direction_output(hw->chipselect[spi->chip_select],
5347
!(spi->mode & SPI_CS_HIGH));
@@ -190,6 +184,7 @@ static int spi_clps711x_probe(struct platform_device *pdev)
190184

191185
master->bus_num = pdev->id;
192186
master->mode_bits = SPI_CPHA | SPI_CS_HIGH;
187+
master->bits_per_word_mask = SPI_BPW_MASK(8);
193188
master->num_chipselect = pdata->num_chipselect;
194189
master->setup = spi_clps711x_setup;
195190
master->transfer_one_message = spi_clps711x_transfer_one_message;

drivers/spi/spi-coldfire-qspi.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,7 @@ static int mcfqspi_transfer_one_message(struct spi_master *master,
312312
bool cs_high = spi->mode & SPI_CS_HIGH;
313313
u16 qmr = MCFQSPI_QMR_MSTR;
314314

315-
if (t->bits_per_word)
316-
qmr |= t->bits_per_word << 10;
317-
else
318-
qmr |= spi->bits_per_word << 10;
315+
qmr |= t->bits_per_word << 10;
319316
if (spi->mode & SPI_CPHA)
320317
qmr |= MCFQSPI_QMR_CPHA;
321318
if (spi->mode & SPI_CPOL)
@@ -377,11 +374,6 @@ static int mcfqspi_unprepare_transfer_hw(struct spi_master *master)
377374

378375
static int mcfqspi_setup(struct spi_device *spi)
379376
{
380-
if ((spi->bits_per_word < 8) || (spi->bits_per_word > 16)) {
381-
dev_dbg(&spi->dev, "%d bits per word is not supported\n",
382-
spi->bits_per_word);
383-
return -EINVAL;
384-
}
385377
if (spi->chip_select >= spi->master->num_chipselect) {
386378
dev_dbg(&spi->dev, "%d chip select is out of range\n",
387379
spi->chip_select);
@@ -477,6 +469,7 @@ static int mcfqspi_probe(struct platform_device *pdev)
477469
mcfqspi->dev = &pdev->dev;
478470

479471
master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
472+
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
480473
master->setup = mcfqspi_setup;
481474
master->transfer_one_message = mcfqspi_transfer_one_message;
482475
master->prepare_transfer_hardware = mcfqspi_prepare_transfer_hw;

drivers/spi/spi-davinci.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,15 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
299299
* Assign function pointer to appropriate transfer method
300300
* 8bit, 16bit or 32bit transfer
301301
*/
302-
if (bits_per_word <= 8 && bits_per_word >= 2) {
302+
if (bits_per_word <= 8) {
303303
dspi->get_rx = davinci_spi_rx_buf_u8;
304304
dspi->get_tx = davinci_spi_tx_buf_u8;
305305
dspi->bytes_per_word[spi->chip_select] = 1;
306-
} else if (bits_per_word <= 16 && bits_per_word >= 2) {
306+
} else {
307307
dspi->get_rx = davinci_spi_rx_buf_u16;
308308
dspi->get_tx = davinci_spi_tx_buf_u16;
309309
dspi->bytes_per_word[spi->chip_select] = 2;
310-
} else
311-
return -EINVAL;
310+
}
312311

313312
if (!hz)
314313
hz = spi->max_speed_hz;
@@ -933,6 +932,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
933932
master->dev.of_node = pdev->dev.of_node;
934933
master->bus_num = pdev->id;
935934
master->num_chipselect = pdata->num_chipselect;
935+
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(2, 16);
936936
master->setup = davinci_spi_setup;
937937

938938
dspi->bitbang.chipselect = davinci_spi_chipselect;

drivers/spi/spi-dw.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,7 @@ static void pump_transfers(unsigned long data)
457457
}
458458
if (transfer->bits_per_word) {
459459
bits = transfer->bits_per_word;
460-
461-
switch (bits) {
462-
case 8:
463-
case 16:
464-
dws->n_bytes = dws->dma_width = bits >> 3;
465-
break;
466-
default:
467-
printk(KERN_ERR "MRST SPI0: unsupported bits:"
468-
"%db\n", bits);
469-
message->status = -EIO;
470-
goto early_exit;
471-
}
472-
460+
dws->n_bytes = dws->dma_width = bits >> 3;
473461
cr0 = (bits - 1)
474462
| (chip->type << SPI_FRF_OFFSET)
475463
| (spi->mode << SPI_MODE_OFFSET)
@@ -629,9 +617,6 @@ static int dw_spi_setup(struct spi_device *spi)
629617
struct dw_spi_chip *chip_info = NULL;
630618
struct chip_data *chip;
631619

632-
if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
633-
return -EINVAL;
634-
635620
/* Only alloc on first setup */
636621
chip = spi_get_ctldata(spi);
637622
if (!chip) {
@@ -660,16 +645,12 @@ static int dw_spi_setup(struct spi_device *spi)
660645
chip->enable_dma = chip_info->enable_dma;
661646
}
662647

663-
if (spi->bits_per_word <= 8) {
648+
if (spi->bits_per_word == 8) {
664649
chip->n_bytes = 1;
665650
chip->dma_width = 1;
666-
} else if (spi->bits_per_word <= 16) {
651+
} else if (spi->bits_per_word == 16) {
667652
chip->n_bytes = 2;
668653
chip->dma_width = 2;
669-
} else {
670-
/* Never take >16b case for MRST SPIC */
671-
dev_err(&spi->dev, "invalid wordsize\n");
672-
return -EINVAL;
673654
}
674655
chip->bits_per_word = spi->bits_per_word;
675656

@@ -824,6 +805,7 @@ int dw_spi_add_host(struct dw_spi *dws)
824805
}
825806

826807
master->mode_bits = SPI_CPOL | SPI_CPHA;
808+
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
827809
master->bus_num = dws->bus_num;
828810
master->num_chipselect = dws->num_cs;
829811
master->cleanup = dw_spi_cleanup;

0 commit comments

Comments
 (0)