diff options
author | Vitaly Wool <vwool@ru.mvista.com> | 2006-01-08 16:34:28 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-13 19:29:56 -0500 |
commit | 8275c642ccdce09a2146d0a9eb022e3698ee927e (patch) | |
tree | ea330810f665fcbdf36d31b0da1643db528ad83f /drivers/spi/spi.c | |
parent | 2f9f762879015d738a5ec2ac8a16be94b3a4a06d (diff) |
[PATCH] spi: use linked lists rather than an array
This makes the SPI core and its users access transfers in the SPI message
structure as linked list not as an array, as discussed on LKML.
From: David Brownell <dbrownell@users.sourceforge.net>
Updates including doc, bugfixes to the list code, add
spi_message_add_tail(). Plus, initialize things _before_ grabbing the
locks in some cases (in case it grows more expensive). This also merges
some bitbang updates of mine that didn't yet make it into the mm tree.
Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: Dmitry Pervushin <dpervushin@gmail.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r-- | drivers/spi/spi.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 3ecedccdb96..cdb242de901 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -557,6 +557,17 @@ int spi_write_then_read(struct spi_device *spi, | |||
557 | if ((n_tx + n_rx) > SPI_BUFSIZ) | 557 | if ((n_tx + n_rx) > SPI_BUFSIZ) |
558 | return -EINVAL; | 558 | return -EINVAL; |
559 | 559 | ||
560 | spi_message_init(&message); | ||
561 | memset(x, 0, sizeof x); | ||
562 | if (n_tx) { | ||
563 | x[0].len = n_tx; | ||
564 | spi_message_add_tail(&x[0], &message); | ||
565 | } | ||
566 | if (n_rx) { | ||
567 | x[1].len = n_rx; | ||
568 | spi_message_add_tail(&x[1], &message); | ||
569 | } | ||
570 | |||
560 | /* ... unless someone else is using the pre-allocated buffer */ | 571 | /* ... unless someone else is using the pre-allocated buffer */ |
561 | if (down_trylock(&lock)) { | 572 | if (down_trylock(&lock)) { |
562 | local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); | 573 | local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); |
@@ -565,18 +576,11 @@ int spi_write_then_read(struct spi_device *spi, | |||
565 | } else | 576 | } else |
566 | local_buf = buf; | 577 | local_buf = buf; |
567 | 578 | ||
568 | memset(x, 0, sizeof x); | ||
569 | |||
570 | memcpy(local_buf, txbuf, n_tx); | 579 | memcpy(local_buf, txbuf, n_tx); |
571 | x[0].tx_buf = local_buf; | 580 | x[0].tx_buf = local_buf; |
572 | x[0].len = n_tx; | ||
573 | |||
574 | x[1].rx_buf = local_buf + n_tx; | 581 | x[1].rx_buf = local_buf + n_tx; |
575 | x[1].len = n_rx; | ||
576 | 582 | ||
577 | /* do the i/o */ | 583 | /* do the i/o */ |
578 | message.transfers = x; | ||
579 | message.n_transfer = ARRAY_SIZE(x); | ||
580 | status = spi_sync(spi, &message); | 584 | status = spi_sync(spi, &message); |
581 | if (status == 0) { | 585 | if (status == 0) { |
582 | memcpy(rxbuf, x[1].rx_buf, n_rx); | 586 | memcpy(rxbuf, x[1].rx_buf, n_rx); |