aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2009-06-18 19:49:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-19 19:46:05 -0400
commitb9b9af11fe35f509899fc5ff242b68d3299c3aef (patch)
tree037122c43eb67350eae4e0ce700afd5a2077f2e2 /drivers/spi
parent9effb959dee0919991362541048479d94bd1f6e0 (diff)
spi_mpc83xx: split mpc83xx_spi_work() into two routines
mpc83xx_spi_work() is quite large, with up to five indentation levels and is quite difficult to read. So, split the function in two parts: 1. mpc83xx_spi_work() now only traverse queued spi messages; 2. mpc83xx_spi_do_one_msg() only manages single messages. There should be no functional changes. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Cc: Kumar Gala <galak@gate.crashing.org> Cc: David Brownell <david-b@pacbell.net> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi_mpc83xx.c115
1 files changed, 60 insertions, 55 deletions
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index 273940d3938d..e854ac0d413a 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -350,71 +350,76 @@ static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
350 return mpc83xx_spi->count; 350 return mpc83xx_spi->count;
351} 351}
352 352
353static void mpc83xx_spi_work(struct work_struct *work) 353static void mpc83xx_spi_do_one_msg(struct spi_message *m)
354{ 354{
355 struct mpc83xx_spi *mpc83xx_spi = 355 struct spi_device *spi = m->spi;
356 container_of(work, struct mpc83xx_spi, work); 356 struct spi_transfer *t;
357 357 unsigned int cs_change;
358 spin_lock_irq(&mpc83xx_spi->lock); 358 const int nsecs = 50;
359 mpc83xx_spi->busy = 1; 359 int status;
360 while (!list_empty(&mpc83xx_spi->queue)) { 360
361 struct spi_message *m; 361 cs_change = 1;
362 struct spi_device *spi; 362 status = 0;
363 struct spi_transfer *t = NULL; 363 list_for_each_entry(t, &m->transfers, transfer_list) {
364 unsigned cs_change; 364 if (t->bits_per_word || t->speed_hz) {
365 int status, nsecs = 50; 365 /* Don't allow changes if CS is active */
366 366 status = -EINVAL;
367 m = container_of(mpc83xx_spi->queue.next, 367
368 struct spi_message, queue); 368 if (cs_change)
369 list_del_init(&m->queue); 369 status = mpc83xx_spi_setup_transfer(spi, t);
370 spin_unlock_irq(&mpc83xx_spi->lock); 370 if (status < 0)
371
372 spi = m->spi;
373 cs_change = 1;
374 status = 0;
375 list_for_each_entry(t, &m->transfers, transfer_list) {
376 if (t->bits_per_word || t->speed_hz) {
377 /* Don't allow changes if CS is active */
378 status = -EINVAL;
379
380 if (cs_change)
381 status = mpc83xx_spi_setup_transfer(spi, t);
382 if (status < 0)
383 break;
384 }
385
386 if (cs_change) {
387 mpc83xx_spi_chipselect(spi, BITBANG_CS_ACTIVE);
388 ndelay(nsecs);
389 }
390 cs_change = t->cs_change;
391 if (t->len)
392 status = mpc83xx_spi_bufs(spi, t);
393 if (status) {
394 status = -EMSGSIZE;
395 break; 371 break;
396 } 372 }
397 m->actual_length += t->len;
398
399 if (t->delay_usecs)
400 udelay(t->delay_usecs);
401 373
402 if (cs_change) { 374 if (cs_change) {
403 ndelay(nsecs); 375 mpc83xx_spi_chipselect(spi, BITBANG_CS_ACTIVE);
404 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 376 ndelay(nsecs);
405 ndelay(nsecs); 377 }
406 } 378 cs_change = t->cs_change;
379 if (t->len)
380 status = mpc83xx_spi_bufs(spi, t);
381 if (status) {
382 status = -EMSGSIZE;
383 break;
407 } 384 }
385 m->actual_length += t->len;
408 386
409 m->status = status; 387 if (t->delay_usecs)
410 m->complete(m->context); 388 udelay(t->delay_usecs);
411 389
412 if (status || !cs_change) { 390 if (cs_change) {
413 ndelay(nsecs); 391 ndelay(nsecs);
414 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 392 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
393 ndelay(nsecs);
415 } 394 }
395 }
396
397 m->status = status;
398 m->complete(m->context);
399
400 if (status || !cs_change) {
401 ndelay(nsecs);
402 mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE);
403 }
404
405 mpc83xx_spi_setup_transfer(spi, NULL);
406}
407
408static void mpc83xx_spi_work(struct work_struct *work)
409{
410 struct mpc83xx_spi *mpc83xx_spi = container_of(work, struct mpc83xx_spi,
411 work);
412
413 spin_lock_irq(&mpc83xx_spi->lock);
414 mpc83xx_spi->busy = 1;
415 while (!list_empty(&mpc83xx_spi->queue)) {
416 struct spi_message *m = container_of(mpc83xx_spi->queue.next,
417 struct spi_message, queue);
418
419 list_del_init(&m->queue);
420 spin_unlock_irq(&mpc83xx_spi->lock);
416 421
417 mpc83xx_spi_setup_transfer(spi, NULL); 422 mpc83xx_spi_do_one_msg(m);
418 423
419 spin_lock_irq(&mpc83xx_spi->lock); 424 spin_lock_irq(&mpc83xx_spi->lock);
420 } 425 }