diff options
author | Shubhrajyoti D <shubhrajyoti@ti.com> | 2012-09-11 02:43:20 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-12 09:52:30 -0400 |
commit | d7b4394e780b02511c8a7a499380cdd56316c770 (patch) | |
tree | de36a029f4881d4f1d075bc0580d552cc4074a34 /drivers/spi/spi-omap2-mcspi.c | |
parent | ac2cb30b4792340d932545f41a8335da2632027d (diff) |
spi: omap2-mcspi: Cleanup the omap2_mcspi_txrx_dma function
Currently in omap2_mcspi_txrx_dma the tx and the rx support is
interleaved. Make the rx related code in omap2_mcspi_rx_dma
and the tx related code omap2_mcspi_tx_dma and call the functions.
While at it remove the braces in the if statements which has only
one line.
Also fix ["foo * bar" to "foo *bar"] warn for the rx and tx variables.
Only a cleanup no functional change.
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Tested-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/spi/spi-omap2-mcspi.c')
-rw-r--r-- | drivers/spi/spi-omap2-mcspi.c | 256 |
1 files changed, 144 insertions, 112 deletions
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 164c15d6a1bb..5560b708e628 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c | |||
@@ -315,49 +315,27 @@ static void omap2_mcspi_tx_callback(void *data) | |||
315 | omap2_mcspi_set_dma_req(spi, 0, 0); | 315 | omap2_mcspi_set_dma_req(spi, 0, 0); |
316 | } | 316 | } |
317 | 317 | ||
318 | static unsigned | 318 | static void omap2_mcspi_tx_dma(struct spi_device *spi, |
319 | omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) | 319 | struct spi_transfer *xfer, |
320 | struct dma_slave_config cfg) | ||
320 | { | 321 | { |
321 | struct omap2_mcspi *mcspi; | 322 | struct omap2_mcspi *mcspi; |
322 | struct omap2_mcspi_cs *cs = spi->controller_state; | ||
323 | struct omap2_mcspi_dma *mcspi_dma; | 323 | struct omap2_mcspi_dma *mcspi_dma; |
324 | unsigned int count; | 324 | unsigned int count; |
325 | int word_len, element_count; | ||
326 | int elements = 0; | ||
327 | u32 l; | ||
328 | u8 * rx; | 325 | u8 * rx; |
329 | const u8 * tx; | 326 | const u8 * tx; |
330 | void __iomem *chstat_reg; | 327 | void __iomem *chstat_reg; |
331 | struct dma_slave_config cfg; | 328 | struct omap2_mcspi_cs *cs = spi->controller_state; |
332 | enum dma_slave_buswidth width; | ||
333 | unsigned es; | ||
334 | 329 | ||
335 | mcspi = spi_master_get_devdata(spi->master); | 330 | mcspi = spi_master_get_devdata(spi->master); |
336 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; | 331 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; |
337 | l = mcspi_cached_chconf0(spi); | 332 | count = xfer->len; |
338 | 333 | ||
334 | rx = xfer->rx_buf; | ||
335 | tx = xfer->tx_buf; | ||
339 | chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; | 336 | chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; |
340 | 337 | ||
341 | if (cs->word_len <= 8) { | 338 | if (mcspi_dma->dma_tx) { |
342 | width = DMA_SLAVE_BUSWIDTH_1_BYTE; | ||
343 | es = 1; | ||
344 | } else if (cs->word_len <= 16) { | ||
345 | width = DMA_SLAVE_BUSWIDTH_2_BYTES; | ||
346 | es = 2; | ||
347 | } else { | ||
348 | width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
349 | es = 4; | ||
350 | } | ||
351 | |||
352 | memset(&cfg, 0, sizeof(cfg)); | ||
353 | cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0; | ||
354 | cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; | ||
355 | cfg.src_addr_width = width; | ||
356 | cfg.dst_addr_width = width; | ||
357 | cfg.src_maxburst = 1; | ||
358 | cfg.dst_maxburst = 1; | ||
359 | |||
360 | if (xfer->tx_buf && mcspi_dma->dma_tx) { | ||
361 | struct dma_async_tx_descriptor *tx; | 339 | struct dma_async_tx_descriptor *tx; |
362 | struct scatterlist sg; | 340 | struct scatterlist sg; |
363 | 341 | ||
@@ -368,7 +346,7 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) | |||
368 | sg_dma_len(&sg) = xfer->len; | 346 | sg_dma_len(&sg) = xfer->len; |
369 | 347 | ||
370 | tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1, | 348 | tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1, |
371 | DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 349 | DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
372 | if (tx) { | 350 | if (tx) { |
373 | tx->callback = omap2_mcspi_tx_callback; | 351 | tx->callback = omap2_mcspi_tx_callback; |
374 | tx->callback_param = spi; | 352 | tx->callback_param = spi; |
@@ -377,8 +355,50 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) | |||
377 | /* FIXME: fall back to PIO? */ | 355 | /* FIXME: fall back to PIO? */ |
378 | } | 356 | } |
379 | } | 357 | } |
358 | dma_async_issue_pending(mcspi_dma->dma_tx); | ||
359 | omap2_mcspi_set_dma_req(spi, 0, 1); | ||
380 | 360 | ||
381 | if (xfer->rx_buf && mcspi_dma->dma_rx) { | 361 | wait_for_completion(&mcspi_dma->dma_tx_completion); |
362 | dma_unmap_single(mcspi->dev, xfer->tx_dma, count, | ||
363 | DMA_TO_DEVICE); | ||
364 | |||
365 | /* for TX_ONLY mode, be sure all words have shifted out */ | ||
366 | if (rx == NULL) { | ||
367 | if (mcspi_wait_for_reg_bit(chstat_reg, | ||
368 | OMAP2_MCSPI_CHSTAT_TXS) < 0) | ||
369 | dev_err(&spi->dev, "TXS timed out\n"); | ||
370 | else if (mcspi_wait_for_reg_bit(chstat_reg, | ||
371 | OMAP2_MCSPI_CHSTAT_EOT) < 0) | ||
372 | dev_err(&spi->dev, "EOT timed out\n"); | ||
373 | } | ||
374 | } | ||
375 | |||
376 | static unsigned | ||
377 | omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, | ||
378 | struct dma_slave_config cfg, | ||
379 | unsigned es) | ||
380 | { | ||
381 | struct omap2_mcspi *mcspi; | ||
382 | struct omap2_mcspi_dma *mcspi_dma; | ||
383 | unsigned int count; | ||
384 | u32 l; | ||
385 | int elements = 0; | ||
386 | int word_len, element_count; | ||
387 | struct omap2_mcspi_cs *cs = spi->controller_state; | ||
388 | mcspi = spi_master_get_devdata(spi->master); | ||
389 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; | ||
390 | count = xfer->len; | ||
391 | word_len = cs->word_len; | ||
392 | l = mcspi_cached_chconf0(spi); | ||
393 | |||
394 | if (word_len <= 8) | ||
395 | element_count = count; | ||
396 | else if (word_len <= 16) | ||
397 | element_count = count >> 1; | ||
398 | else /* word_len <= 32 */ | ||
399 | element_count = count >> 2; | ||
400 | |||
401 | if (mcspi_dma->dma_rx) { | ||
382 | struct dma_async_tx_descriptor *tx; | 402 | struct dma_async_tx_descriptor *tx; |
383 | struct scatterlist sg; | 403 | struct scatterlist sg; |
384 | size_t len = xfer->len - es; | 404 | size_t len = xfer->len - es; |
@@ -393,108 +413,120 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) | |||
393 | sg_dma_len(&sg) = len; | 413 | sg_dma_len(&sg) = len; |
394 | 414 | ||
395 | tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, | 415 | tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, |
396 | DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 416 | DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | |
417 | DMA_CTRL_ACK); | ||
397 | if (tx) { | 418 | if (tx) { |
398 | tx->callback = omap2_mcspi_rx_callback; | 419 | tx->callback = omap2_mcspi_rx_callback; |
399 | tx->callback_param = spi; | 420 | tx->callback_param = spi; |
400 | dmaengine_submit(tx); | 421 | dmaengine_submit(tx); |
401 | } else { | 422 | } else { |
402 | /* FIXME: fall back to PIO? */ | 423 | /* FIXME: fall back to PIO? */ |
403 | } | ||
404 | } | ||
405 | |||
406 | count = xfer->len; | ||
407 | word_len = cs->word_len; | ||
408 | |||
409 | rx = xfer->rx_buf; | ||
410 | tx = xfer->tx_buf; | ||
411 | |||
412 | if (word_len <= 8) { | ||
413 | element_count = count; | ||
414 | } else if (word_len <= 16) { | ||
415 | element_count = count >> 1; | ||
416 | } else /* word_len <= 32 */ { | ||
417 | element_count = count >> 2; | ||
418 | } | ||
419 | |||
420 | if (tx != NULL) { | ||
421 | dma_async_issue_pending(mcspi_dma->dma_tx); | ||
422 | omap2_mcspi_set_dma_req(spi, 0, 1); | ||
423 | } | ||
424 | |||
425 | if (rx != NULL) { | ||
426 | dma_async_issue_pending(mcspi_dma->dma_rx); | ||
427 | omap2_mcspi_set_dma_req(spi, 1, 1); | ||
428 | } | ||
429 | |||
430 | if (tx != NULL) { | ||
431 | wait_for_completion(&mcspi_dma->dma_tx_completion); | ||
432 | dma_unmap_single(mcspi->dev, xfer->tx_dma, count, | ||
433 | DMA_TO_DEVICE); | ||
434 | |||
435 | /* for TX_ONLY mode, be sure all words have shifted out */ | ||
436 | if (rx == NULL) { | ||
437 | if (mcspi_wait_for_reg_bit(chstat_reg, | ||
438 | OMAP2_MCSPI_CHSTAT_TXS) < 0) | ||
439 | dev_err(&spi->dev, "TXS timed out\n"); | ||
440 | else if (mcspi_wait_for_reg_bit(chstat_reg, | ||
441 | OMAP2_MCSPI_CHSTAT_EOT) < 0) | ||
442 | dev_err(&spi->dev, "EOT timed out\n"); | ||
443 | } | 424 | } |
444 | } | 425 | } |
445 | 426 | ||
446 | if (rx != NULL) { | 427 | dma_async_issue_pending(mcspi_dma->dma_rx); |
447 | wait_for_completion(&mcspi_dma->dma_rx_completion); | 428 | omap2_mcspi_set_dma_req(spi, 1, 1); |
448 | dma_unmap_single(mcspi->dev, xfer->rx_dma, count, | ||
449 | DMA_FROM_DEVICE); | ||
450 | omap2_mcspi_set_enable(spi, 0); | ||
451 | 429 | ||
452 | elements = element_count - 1; | 430 | wait_for_completion(&mcspi_dma->dma_rx_completion); |
431 | dma_unmap_single(mcspi->dev, xfer->rx_dma, count, | ||
432 | DMA_FROM_DEVICE); | ||
433 | omap2_mcspi_set_enable(spi, 0); | ||
453 | 434 | ||
454 | if (l & OMAP2_MCSPI_CHCONF_TURBO) { | 435 | elements = element_count - 1; |
455 | elements--; | ||
456 | 436 | ||
457 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) | 437 | if (l & OMAP2_MCSPI_CHCONF_TURBO) { |
458 | & OMAP2_MCSPI_CHSTAT_RXS)) { | 438 | elements--; |
459 | u32 w; | ||
460 | |||
461 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); | ||
462 | if (word_len <= 8) | ||
463 | ((u8 *)xfer->rx_buf)[elements++] = w; | ||
464 | else if (word_len <= 16) | ||
465 | ((u16 *)xfer->rx_buf)[elements++] = w; | ||
466 | else /* word_len <= 32 */ | ||
467 | ((u32 *)xfer->rx_buf)[elements++] = w; | ||
468 | } else { | ||
469 | dev_err(&spi->dev, | ||
470 | "DMA RX penultimate word empty"); | ||
471 | count -= (word_len <= 8) ? 2 : | ||
472 | (word_len <= 16) ? 4 : | ||
473 | /* word_len <= 32 */ 8; | ||
474 | omap2_mcspi_set_enable(spi, 1); | ||
475 | return count; | ||
476 | } | ||
477 | } | ||
478 | 439 | ||
479 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) | 440 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) |
480 | & OMAP2_MCSPI_CHSTAT_RXS)) { | 441 | & OMAP2_MCSPI_CHSTAT_RXS)) { |
481 | u32 w; | 442 | u32 w; |
482 | 443 | ||
483 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); | 444 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); |
484 | if (word_len <= 8) | 445 | if (word_len <= 8) |
485 | ((u8 *)xfer->rx_buf)[elements] = w; | 446 | ((u8 *)xfer->rx_buf)[elements++] = w; |
486 | else if (word_len <= 16) | 447 | else if (word_len <= 16) |
487 | ((u16 *)xfer->rx_buf)[elements] = w; | 448 | ((u16 *)xfer->rx_buf)[elements++] = w; |
488 | else /* word_len <= 32 */ | 449 | else /* word_len <= 32 */ |
489 | ((u32 *)xfer->rx_buf)[elements] = w; | 450 | ((u32 *)xfer->rx_buf)[elements++] = w; |
490 | } else { | 451 | } else { |
491 | dev_err(&spi->dev, "DMA RX last word empty"); | 452 | dev_err(&spi->dev, "DMA RX penultimate word empty"); |
492 | count -= (word_len <= 8) ? 1 : | 453 | count -= (word_len <= 8) ? 2 : |
493 | (word_len <= 16) ? 2 : | 454 | (word_len <= 16) ? 4 : |
494 | /* word_len <= 32 */ 4; | 455 | /* word_len <= 32 */ 8; |
456 | omap2_mcspi_set_enable(spi, 1); | ||
457 | return count; | ||
495 | } | 458 | } |
496 | omap2_mcspi_set_enable(spi, 1); | ||
497 | } | 459 | } |
460 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) | ||
461 | & OMAP2_MCSPI_CHSTAT_RXS)) { | ||
462 | u32 w; | ||
463 | |||
464 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); | ||
465 | if (word_len <= 8) | ||
466 | ((u8 *)xfer->rx_buf)[elements] = w; | ||
467 | else if (word_len <= 16) | ||
468 | ((u16 *)xfer->rx_buf)[elements] = w; | ||
469 | else /* word_len <= 32 */ | ||
470 | ((u32 *)xfer->rx_buf)[elements] = w; | ||
471 | } else { | ||
472 | dev_err(&spi->dev, "DMA RX last word empty"); | ||
473 | count -= (word_len <= 8) ? 1 : | ||
474 | (word_len <= 16) ? 2 : | ||
475 | /* word_len <= 32 */ 4; | ||
476 | } | ||
477 | omap2_mcspi_set_enable(spi, 1); | ||
478 | return count; | ||
479 | } | ||
480 | |||
481 | static unsigned | ||
482 | omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) | ||
483 | { | ||
484 | struct omap2_mcspi *mcspi; | ||
485 | struct omap2_mcspi_cs *cs = spi->controller_state; | ||
486 | struct omap2_mcspi_dma *mcspi_dma; | ||
487 | unsigned int count; | ||
488 | u32 l; | ||
489 | u8 *rx; | ||
490 | const u8 *tx; | ||
491 | struct dma_slave_config cfg; | ||
492 | enum dma_slave_buswidth width; | ||
493 | unsigned es; | ||
494 | |||
495 | mcspi = spi_master_get_devdata(spi->master); | ||
496 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; | ||
497 | l = mcspi_cached_chconf0(spi); | ||
498 | |||
499 | |||
500 | if (cs->word_len <= 8) { | ||
501 | width = DMA_SLAVE_BUSWIDTH_1_BYTE; | ||
502 | es = 1; | ||
503 | } else if (cs->word_len <= 16) { | ||
504 | width = DMA_SLAVE_BUSWIDTH_2_BYTES; | ||
505 | es = 2; | ||
506 | } else { | ||
507 | width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
508 | es = 4; | ||
509 | } | ||
510 | |||
511 | memset(&cfg, 0, sizeof(cfg)); | ||
512 | cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0; | ||
513 | cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; | ||
514 | cfg.src_addr_width = width; | ||
515 | cfg.dst_addr_width = width; | ||
516 | cfg.src_maxburst = 1; | ||
517 | cfg.dst_maxburst = 1; | ||
518 | |||
519 | rx = xfer->rx_buf; | ||
520 | tx = xfer->tx_buf; | ||
521 | |||
522 | count = xfer->len; | ||
523 | |||
524 | if (tx != NULL) | ||
525 | omap2_mcspi_tx_dma(spi, xfer, cfg); | ||
526 | |||
527 | if (rx != NULL) | ||
528 | return omap2_mcspi_rx_dma(spi, xfer, cfg, es); | ||
529 | |||
498 | return count; | 530 | return count; |
499 | } | 531 | } |
500 | 532 | ||