Commit 85085898ab0fefc6e181d3b495dc34034dda2fee

Authored by Gerhard Sittig
Committed by Mark Brown
1 parent 5df24ea63d

spi: mpc512x: use the SPI subsystem's message queue

the SPI subsystem recently grew support to queue messages before handing
them to the SPI master, and erroneously emitted deprecation warnings
when the SPI master's driver did not use the common logic (in fact the
master might queue messages, but implement the queue in the master
driver's source)

  [    0.823015] mpc512x-psc-spi 80011400.psc: master is unqueued, this is deprecated
  [    0.854913] mpc512x-psc-spi 80011500.psc: master is unqueued, this is deprecated

this change makes the MPC512x PSC SPI driver use the SPI subsystem's
support to queue SPI messages and removes the master driver's private
code for the queue support

Signed-off-by: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Mark Brown <broonie@linaro.org>

Showing 1 changed file with 73 additions and 110 deletions Side-by-side Diff

drivers/spi/spi-mpc512x-psc.c
... ... @@ -21,7 +21,6 @@
21 21 #include <linux/interrupt.h>
22 22 #include <linux/of_address.h>
23 23 #include <linux/of_platform.h>
24   -#include <linux/workqueue.h>
25 24 #include <linux/completion.h>
26 25 #include <linux/io.h>
27 26 #include <linux/delay.h>
28 27  
... ... @@ -39,15 +38,8 @@
39 38 struct mpc512x_psc_fifo __iomem *fifo;
40 39 unsigned int irq;
41 40 u8 bits_per_word;
42   - u8 busy;
43 41 u32 mclk;
44 42  
45   - struct workqueue_struct *workqueue;
46   - struct work_struct work;
47   -
48   - struct list_head queue;
49   - spinlock_t lock; /* Message queue lock */
50   -
51 43 struct completion txisrdone;
52 44 };
53 45  
... ... @@ -134,7 +126,6 @@
134 126 struct spi_transfer *t)
135 127 {
136 128 struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
137   - struct mpc52xx_psc __iomem *psc = mps->psc;
138 129 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo;
139 130 size_t tx_len = t->len;
140 131 size_t rx_len = t->len;
... ... @@ -144,13 +135,6 @@
144 135 if (!tx_buf && !rx_buf && t->len)
145 136 return -EINVAL;
146 137  
147   - /* Zero MR2 */
148   - in_8(&psc->mode);
149   - out_8(&psc->mode, 0x0);
150   -
151   - /* enable transmiter/receiver */
152   - out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
153   -
154 138 while (rx_len || tx_len) {
155 139 size_t txcount;
156 140 u8 data;
157 141  
158 142  
159 143  
160 144  
161 145  
162 146  
163 147  
164 148  
165 149  
166 150  
167 151  
168 152  
169 153  
170 154  
171 155  
172 156  
... ... @@ -275,76 +259,90 @@
275 259 }
276 260  
277 261 }
278   - /* disable transmiter/receiver and fifo interrupt */
279   - out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
280   - out_be32(&fifo->tximr, 0);
281 262 return 0;
282 263 }
283 264  
284   -static void mpc512x_psc_spi_work(struct work_struct *work)
  265 +static int mpc512x_psc_spi_msg_xfer(struct spi_master *master,
  266 + struct spi_message *m)
285 267 {
286   - struct mpc512x_psc_spi *mps = container_of(work,
287   - struct mpc512x_psc_spi,
288   - work);
  268 + struct spi_device *spi;
  269 + unsigned cs_change;
  270 + int status;
  271 + struct spi_transfer *t;
289 272  
290   - spin_lock_irq(&mps->lock);
291   - mps->busy = 1;
292   - while (!list_empty(&mps->queue)) {
293   - struct spi_message *m;
294   - struct spi_device *spi;
295   - struct spi_transfer *t = NULL;
296   - unsigned cs_change;
297   - int status;
  273 + spi = m->spi;
  274 + cs_change = 1;
  275 + status = 0;
  276 + list_for_each_entry(t, &m->transfers, transfer_list) {
  277 + if (t->bits_per_word || t->speed_hz) {
  278 + status = mpc512x_psc_spi_transfer_setup(spi, t);
  279 + if (status < 0)
  280 + break;
  281 + }
298 282  
299   - m = container_of(mps->queue.next, struct spi_message, queue);
300   - list_del_init(&m->queue);
301   - spin_unlock_irq(&mps->lock);
  283 + if (cs_change)
  284 + mpc512x_psc_spi_activate_cs(spi);
  285 + cs_change = t->cs_change;
302 286  
303   - spi = m->spi;
304   - cs_change = 1;
305   - status = 0;
306   - list_for_each_entry(t, &m->transfers, transfer_list) {
307   - if (t->bits_per_word || t->speed_hz) {
308   - status = mpc512x_psc_spi_transfer_setup(spi, t);
309   - if (status < 0)
310   - break;
311   - }
  287 + status = mpc512x_psc_spi_transfer_rxtx(spi, t);
  288 + if (status)
  289 + break;
  290 + m->actual_length += t->len;
312 291  
313   - if (cs_change)
314   - mpc512x_psc_spi_activate_cs(spi);
315   - cs_change = t->cs_change;
  292 + if (t->delay_usecs)
  293 + udelay(t->delay_usecs);
316 294  
317   - status = mpc512x_psc_spi_transfer_rxtx(spi, t);
318   - if (status)
319   - break;
320   - m->actual_length += t->len;
  295 + if (cs_change)
  296 + mpc512x_psc_spi_deactivate_cs(spi);
  297 + }
321 298  
322   - if (t->delay_usecs)
323   - udelay(t->delay_usecs);
  299 + m->status = status;
  300 + m->complete(m->context);
324 301  
325   - if (cs_change)
326   - mpc512x_psc_spi_deactivate_cs(spi);
327   - }
  302 + if (status || !cs_change)
  303 + mpc512x_psc_spi_deactivate_cs(spi);
328 304  
329   - m->status = status;
330   - m->complete(m->context);
  305 + mpc512x_psc_spi_transfer_setup(spi, NULL);
331 306  
332   - if (status || !cs_change)
333   - mpc512x_psc_spi_deactivate_cs(spi);
  307 + spi_finalize_current_message(master);
  308 + return status;
  309 +}
334 310  
335   - mpc512x_psc_spi_transfer_setup(spi, NULL);
  311 +static int mpc512x_psc_spi_prep_xfer_hw(struct spi_master *master)
  312 +{
  313 + struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
  314 + struct mpc52xx_psc __iomem *psc = mps->psc;
336 315  
337   - spin_lock_irq(&mps->lock);
338   - }
339   - mps->busy = 0;
340   - spin_unlock_irq(&mps->lock);
  316 + dev_dbg(&master->dev, "%s()\n", __func__);
  317 +
  318 + /* Zero MR2 */
  319 + in_8(&psc->mode);
  320 + out_8(&psc->mode, 0x0);
  321 +
  322 + /* enable transmitter/receiver */
  323 + out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
  324 +
  325 + return 0;
341 326 }
342 327  
  328 +static int mpc512x_psc_spi_unprep_xfer_hw(struct spi_master *master)
  329 +{
  330 + struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
  331 + struct mpc52xx_psc __iomem *psc = mps->psc;
  332 + struct mpc512x_psc_fifo __iomem *fifo = mps->fifo;
  333 +
  334 + dev_dbg(&master->dev, "%s()\n", __func__);
  335 +
  336 + /* disable transmitter/receiver and fifo interrupt */
  337 + out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
  338 + out_be32(&fifo->tximr, 0);
  339 +
  340 + return 0;
  341 +}
  342 +
343 343 static int mpc512x_psc_spi_setup(struct spi_device *spi)
344 344 {
345   - struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
346 345 struct mpc512x_psc_spi_cs *cs = spi->controller_state;
347   - unsigned long flags;
348 346 int ret;
349 347  
350 348 if (spi->bits_per_word % 8)
351 349  
... ... @@ -373,31 +371,9 @@
373 371 cs->bits_per_word = spi->bits_per_word;
374 372 cs->speed_hz = spi->max_speed_hz;
375 373  
376   - spin_lock_irqsave(&mps->lock, flags);
377   - if (!mps->busy)
378   - mpc512x_psc_spi_deactivate_cs(spi);
379   - spin_unlock_irqrestore(&mps->lock, flags);
380   -
381 374 return 0;
382 375 }
383 376  
384   -static int mpc512x_psc_spi_transfer(struct spi_device *spi,
385   - struct spi_message *m)
386   -{
387   - struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
388   - unsigned long flags;
389   -
390   - m->actual_length = 0;
391   - m->status = -EINPROGRESS;
392   -
393   - spin_lock_irqsave(&mps->lock, flags);
394   - list_add_tail(&m->queue, &mps->queue);
395   - queue_work(mps->workqueue, &mps->work);
396   - spin_unlock_irqrestore(&mps->lock, flags);
397   -
398   - return 0;
399   -}
400   -
401 377 static void mpc512x_psc_spi_cleanup(struct spi_device *spi)
402 378 {
403 379 if (gpio_is_valid(spi->cs_gpio))
... ... @@ -477,7 +453,7 @@
477 453 struct mpc512x_psc_spi *mps = (struct mpc512x_psc_spi *)dev_id;
478 454 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo;
479 455  
480   - /* clear interrupt and wake up the work queue */
  456 + /* clear interrupt and wake up the rx/tx routine */
481 457 if (in_be32(&fifo->txisr) &
482 458 in_be32(&fifo->tximr) & MPC512x_PSC_FIFO_EMPTY) {
483 459 out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY);
... ... @@ -523,7 +499,9 @@
523 499  
524 500 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
525 501 master->setup = mpc512x_psc_spi_setup;
526   - master->transfer = mpc512x_psc_spi_transfer;
  502 + master->prepare_transfer_hardware = mpc512x_psc_spi_prep_xfer_hw;
  503 + master->transfer_one_message = mpc512x_psc_spi_msg_xfer;
  504 + master->unprepare_transfer_hardware = mpc512x_psc_spi_unprep_xfer_hw;
527 505 master->cleanup = mpc512x_psc_spi_cleanup;
528 506 master->dev.of_node = dev->of_node;
529 507  
530 508  
531 509  
532 510  
... ... @@ -541,31 +519,18 @@
541 519 "mpc512x-psc-spi", mps);
542 520 if (ret)
543 521 goto free_master;
  522 + init_completion(&mps->txisrdone);
544 523  
545 524 ret = mpc512x_psc_spi_port_config(master, mps);
546 525 if (ret < 0)
547 526 goto free_irq;
548 527  
549   - spin_lock_init(&mps->lock);
550   - init_completion(&mps->txisrdone);
551   - INIT_WORK(&mps->work, mpc512x_psc_spi_work);
552   - INIT_LIST_HEAD(&mps->queue);
553   -
554   - mps->workqueue =
555   - create_singlethread_workqueue(dev_name(master->dev.parent));
556   - if (mps->workqueue == NULL) {
557   - ret = -EBUSY;
558   - goto free_irq;
559   - }
560   -
561 528 ret = spi_register_master(master);
562 529 if (ret < 0)
563   - goto unreg_master;
  530 + goto free_irq;
564 531  
565 532 return ret;
566 533  
567   -unreg_master:
568   - destroy_workqueue(mps->workqueue);
569 534 free_irq:
570 535 free_irq(mps->irq, mps);
571 536 free_master:
... ... @@ -581,8 +546,6 @@
581 546 struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
582 547 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
583 548  
584   - flush_workqueue(mps->workqueue);
585   - destroy_workqueue(mps->workqueue);
586 549 spi_unregister_master(master);
587 550 free_irq(mps->irq, mps);
588 551 if (mps->psc)