diff options
| author | Steven King <sfking@fdwdc.com> | 2012-05-10 12:26:55 -0400 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2012-05-20 00:57:27 -0400 |
| commit | bc98d13f5cce1b617305966c3e95f7b2e62aa820 (patch) | |
| tree | 1c2d889dd2a3758aea8ff7793ded48ee37b443ac | |
| parent | 5fda88f5e17ea0e767360a3f09eac80f83296ea9 (diff) | |
spi: refactor spi-coldfire-qspi to use SPI queue framework.
Use the new SPI queue framework; remove use of workqueue, replace
mcfqspi_transfer with mcfqspi_transfer_one_message, add
mcfqspi_prepare_transfer_hw and mcfqspi_unprepare_transfer_hw, update power
management routines.
Signed-off-by: Steven King <sfking@fdwdc.com>
Acked-by: Greg Ungerer <gerg@snapgear.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
| -rw-r--r-- | drivers/spi/spi-coldfire-qspi.c | 255 |
1 files changed, 114 insertions, 141 deletions
diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c index 6eee64a5d240..b2d4b9e4e010 100644 --- a/drivers/spi/spi-coldfire-qspi.c +++ b/drivers/spi/spi-coldfire-qspi.c | |||
| @@ -25,12 +25,12 @@ | |||
| 25 | #include <linux/errno.h> | 25 | #include <linux/errno.h> |
| 26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
| 28 | #include <linux/workqueue.h> | ||
| 29 | #include <linux/delay.h> | 28 | #include <linux/delay.h> |
| 30 | #include <linux/io.h> | 29 | #include <linux/io.h> |
| 31 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
| 32 | #include <linux/err.h> | 31 | #include <linux/err.h> |
| 33 | #include <linux/spi/spi.h> | 32 | #include <linux/spi/spi.h> |
| 33 | #include <linux/pm_runtime.h> | ||
| 34 | 34 | ||
| 35 | #include <asm/coldfire.h> | 35 | #include <asm/coldfire.h> |
| 36 | #include <asm/mcfsim.h> | 36 | #include <asm/mcfsim.h> |
| @@ -78,10 +78,7 @@ struct mcfqspi { | |||
| 78 | 78 | ||
| 79 | wait_queue_head_t waitq; | 79 | wait_queue_head_t waitq; |
| 80 | 80 | ||
| 81 | struct work_struct work; | 81 | struct device *dev; |
| 82 | struct workqueue_struct *workq; | ||
| 83 | spinlock_t lock; | ||
| 84 | struct list_head msgq; | ||
| 85 | }; | 82 | }; |
| 86 | 83 | ||
| 87 | static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val) | 84 | static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val) |
| @@ -303,120 +300,80 @@ static void mcfqspi_transfer_msg16(struct mcfqspi *mcfqspi, unsigned count, | |||
| 303 | } | 300 | } |
| 304 | } | 301 | } |
| 305 | 302 | ||
| 306 | static void mcfqspi_work(struct work_struct *work) | 303 | static int mcfqspi_transfer_one_message(struct spi_master *master, |
| 304 | struct spi_message *msg) | ||
| 307 | { | 305 | { |
| 308 | struct mcfqspi *mcfqspi = container_of(work, struct mcfqspi, work); | 306 | struct mcfqspi *mcfqspi = spi_master_get_devdata(master); |
| 309 | unsigned long flags; | 307 | struct spi_device *spi = msg->spi; |
| 310 | 308 | struct spi_transfer *t; | |
| 311 | spin_lock_irqsave(&mcfqspi->lock, flags); | 309 | int status = 0; |
| 312 | while (!list_empty(&mcfqspi->msgq)) { | 310 | |
| 313 | struct spi_message *msg; | 311 | list_for_each_entry(t, &msg->transfers, transfer_list) { |
| 314 | struct spi_device *spi; | 312 | bool cs_high = spi->mode & SPI_CS_HIGH; |
| 315 | struct spi_transfer *xfer; | 313 | u16 qmr = MCFQSPI_QMR_MSTR; |
| 316 | int status = 0; | 314 | |
| 317 | 315 | if (t->bits_per_word) | |
| 318 | msg = container_of(mcfqspi->msgq.next, struct spi_message, | 316 | qmr |= t->bits_per_word << 10; |
| 319 | queue); | 317 | else |
| 320 | 318 | qmr |= spi->bits_per_word << 10; | |
| 321 | list_del_init(&msg->queue); | 319 | if (spi->mode & SPI_CPHA) |
| 322 | spin_unlock_irqrestore(&mcfqspi->lock, flags); | 320 | qmr |= MCFQSPI_QMR_CPHA; |
| 323 | 321 | if (spi->mode & SPI_CPOL) | |
| 324 | spi = msg->spi; | 322 | qmr |= MCFQSPI_QMR_CPOL; |
| 325 | 323 | if (t->speed_hz) | |
| 326 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 324 | qmr |= mcfqspi_qmr_baud(t->speed_hz); |
| 327 | bool cs_high = spi->mode & SPI_CS_HIGH; | 325 | else |
| 328 | u16 qmr = MCFQSPI_QMR_MSTR; | 326 | qmr |= mcfqspi_qmr_baud(spi->max_speed_hz); |
| 329 | 327 | mcfqspi_wr_qmr(mcfqspi, qmr); | |
| 330 | if (xfer->bits_per_word) | 328 | |
| 331 | qmr |= xfer->bits_per_word << 10; | 329 | mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high); |
| 332 | else | 330 | |
| 333 | qmr |= spi->bits_per_word << 10; | 331 | mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE); |
| 334 | if (spi->mode & SPI_CPHA) | 332 | if ((t->bits_per_word ? t->bits_per_word : |
| 335 | qmr |= MCFQSPI_QMR_CPHA; | 333 | spi->bits_per_word) == 8) |
| 336 | if (spi->mode & SPI_CPOL) | 334 | mcfqspi_transfer_msg8(mcfqspi, t->len, t->tx_buf, |
| 337 | qmr |= MCFQSPI_QMR_CPOL; | 335 | t->rx_buf); |
| 338 | if (xfer->speed_hz) | 336 | else |
| 339 | qmr |= mcfqspi_qmr_baud(xfer->speed_hz); | 337 | mcfqspi_transfer_msg16(mcfqspi, t->len / 2, t->tx_buf, |
| 340 | else | 338 | t->rx_buf); |
| 341 | qmr |= mcfqspi_qmr_baud(spi->max_speed_hz); | 339 | mcfqspi_wr_qir(mcfqspi, 0); |
| 342 | mcfqspi_wr_qmr(mcfqspi, qmr); | 340 | |
| 343 | 341 | if (t->delay_usecs) | |
| 344 | mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high); | 342 | udelay(t->delay_usecs); |
| 345 | 343 | if (t->cs_change) { | |
| 346 | mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE); | 344 | if (!list_is_last(&t->transfer_list, &msg->transfers)) |
| 347 | if ((xfer->bits_per_word ? xfer->bits_per_word : | 345 | mcfqspi_cs_deselect(mcfqspi, spi->chip_select, |
| 348 | spi->bits_per_word) == 8) | 346 | cs_high); |
| 349 | mcfqspi_transfer_msg8(mcfqspi, xfer->len, | 347 | } else { |
| 350 | xfer->tx_buf, | 348 | if (list_is_last(&t->transfer_list, &msg->transfers)) |
| 351 | xfer->rx_buf); | 349 | mcfqspi_cs_deselect(mcfqspi, spi->chip_select, |
| 352 | else | 350 | cs_high); |
| 353 | mcfqspi_transfer_msg16(mcfqspi, xfer->len / 2, | ||
| 354 | xfer->tx_buf, | ||
| 355 | xfer->rx_buf); | ||
| 356 | mcfqspi_wr_qir(mcfqspi, 0); | ||
| 357 | |||
| 358 | if (xfer->delay_usecs) | ||
| 359 | udelay(xfer->delay_usecs); | ||
| 360 | if (xfer->cs_change) { | ||
| 361 | if (!list_is_last(&xfer->transfer_list, | ||
| 362 | &msg->transfers)) | ||
| 363 | mcfqspi_cs_deselect(mcfqspi, | ||
| 364 | spi->chip_select, | ||
| 365 | cs_high); | ||
| 366 | } else { | ||
| 367 | if (list_is_last(&xfer->transfer_list, | ||
| 368 | &msg->transfers)) | ||
| 369 | mcfqspi_cs_deselect(mcfqspi, | ||
| 370 | spi->chip_select, | ||
| 371 | cs_high); | ||
| 372 | } | ||
| 373 | msg->actual_length += xfer->len; | ||
| 374 | } | 351 | } |
| 375 | msg->status = status; | 352 | msg->actual_length += t->len; |
| 376 | msg->complete(msg->context); | ||
| 377 | |||
| 378 | spin_lock_irqsave(&mcfqspi->lock, flags); | ||
| 379 | } | 353 | } |
| 380 | spin_unlock_irqrestore(&mcfqspi->lock, flags); | 354 | msg->status = status; |
| 355 | spi_finalize_current_message(master); | ||
| 356 | |||
| 357 | return status; | ||
| 358 | |||
| 381 | } | 359 | } |
| 382 | 360 | ||
| 383 | static int mcfqspi_transfer(struct spi_device *spi, struct spi_message *msg) | 361 | static int mcfqspi_prepare_transfer_hw(struct spi_master *master) |
| 384 | { | 362 | { |
| 385 | struct mcfqspi *mcfqspi; | 363 | struct mcfqspi *mcfqspi = spi_master_get_devdata(master); |
| 386 | struct spi_transfer *xfer; | ||
| 387 | unsigned long flags; | ||
| 388 | |||
| 389 | mcfqspi = spi_master_get_devdata(spi->master); | ||
| 390 | |||
| 391 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | ||
| 392 | if (xfer->bits_per_word && ((xfer->bits_per_word < 8) | ||
| 393 | || (xfer->bits_per_word > 16))) { | ||
| 394 | dev_dbg(&spi->dev, | ||
| 395 | "%d bits per word is not supported\n", | ||
| 396 | xfer->bits_per_word); | ||
| 397 | goto fail; | ||
| 398 | } | ||
| 399 | if (xfer->speed_hz) { | ||
| 400 | u32 real_speed = MCFQSPI_BUSCLK / | ||
| 401 | mcfqspi_qmr_baud(xfer->speed_hz); | ||
| 402 | if (real_speed != xfer->speed_hz) | ||
| 403 | dev_dbg(&spi->dev, | ||
| 404 | "using speed %d instead of %d\n", | ||
| 405 | real_speed, xfer->speed_hz); | ||
| 406 | } | ||
| 407 | } | ||
| 408 | msg->status = -EINPROGRESS; | ||
| 409 | msg->actual_length = 0; | ||
| 410 | 364 | ||
