aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi_bitbang.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2006-04-07 01:25:56 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-05-16 17:33:58 -0400
commit1e316d7566b63767aa18902235c719e9e95465d0 (patch)
tree506783a779e1b06b20de0bc03e4b0008f77704e8 /drivers/spi/spi_bitbang.c
parent9708c121c38fe864eb6f5a119f7525729686e095 (diff)
[PATCH] SPI: spi_bitbang: clocking fixes
This fixes two problems triggered by the MMC stack updating clocks: - SPI masters driver should accept a max clock speed of zero; that's one convention for marking idle devices. (Presumably that helps controllers that don't autogate clocks to "off" when not in use.) - There are more than 1000 nanoseconds per millisecond; setting the clock down to 125 KHz now works properly. Showing once again that Zero (http://en.wikipedia.org/wiki/Zero) is still an inexhaustible number of bugs. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/spi/spi_bitbang.c')
-rw-r--r--drivers/spi/spi_bitbang.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 0f7f5c64391c..dd2f950b21a7 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -167,9 +167,11 @@ int spi_bitbang_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
167 /* nsecs = (clock period)/2 */ 167 /* nsecs = (clock period)/2 */
168 if (!hz) 168 if (!hz)
169 hz = spi->max_speed_hz; 169 hz = spi->max_speed_hz;
170 cs->nsecs = (1000000000/2) / hz; 170 if (hz) {
171 if (cs->nsecs > MAX_UDELAY_MS * 1000) 171 cs->nsecs = (1000000000/2) / hz;
172 return -EINVAL; 172 if (cs->nsecs > (MAX_UDELAY_MS * 1000 * 1000))
173 return -EINVAL;
174 }
173 175
174 return 0; 176 return 0;
175} 177}
@@ -184,9 +186,6 @@ int spi_bitbang_setup(struct spi_device *spi)
184 struct spi_bitbang *bitbang; 186 struct spi_bitbang *bitbang;
185 int retval; 187 int retval;
186 188
187 if (!spi->max_speed_hz)
188 return -EINVAL;
189
190 bitbang = spi_master_get_devdata(spi->master); 189 bitbang = spi_master_get_devdata(spi->master);
191 190
192 /* REVISIT: some systems will want to support devices using lsb-first 191 /* REVISIT: some systems will want to support devices using lsb-first
@@ -216,7 +215,7 @@ int spi_bitbang_setup(struct spi_device *spi)
216 if (retval < 0) 215 if (retval < 0)
217 return retval; 216 return retval;
218 217
219 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec\n", 218 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
220 __FUNCTION__, spi->mode & (SPI_CPOL | SPI_CPHA), 219 __FUNCTION__, spi->mode & (SPI_CPOL | SPI_CPHA),
221 spi->bits_per_word, 2 * cs->nsecs); 220 spi->bits_per_word, 2 * cs->nsecs);
222 221
@@ -405,6 +404,7 @@ int spi_bitbang_transfer(struct spi_device *spi, struct spi_message *m)
405{ 404{
406 struct spi_bitbang *bitbang; 405 struct spi_bitbang *bitbang;
407 unsigned long flags; 406 unsigned long flags;
407 int status = 0;
408 408
409 m->actual_length = 0; 409 m->actual_length = 0;
410 m->status = -EINPROGRESS; 410 m->status = -EINPROGRESS;
@@ -414,11 +414,15 @@ int spi_bitbang_transfer(struct spi_device *spi, struct spi_message *m)
414 return -ESHUTDOWN; 414 return -ESHUTDOWN;
415 415
416 spin_lock_irqsave(&bitbang->lock, flags); 416 spin_lock_irqsave(&bitbang->lock, flags);
417 list_add_tail(&m->queue, &bitbang->queue); 417 if (!spi->max_speed_hz)
418 queue_work(bitbang->workqueue, &bitbang->work); 418 status = -ENETDOWN;
419 else {
420 list_add_tail(&m->queue, &bitbang->queue);
421 queue_work(bitbang->workqueue, &bitbang->work);
422 }
419 spin_unlock_irqrestore(&bitbang->lock, flags); 423 spin_unlock_irqrestore(&bitbang->lock, flags);
420 424
421 return 0; 425 return status;
422} 426}
423EXPORT_SYMBOL_GPL(spi_bitbang_transfer); 427EXPORT_SYMBOL_GPL(spi_bitbang_transfer);
424 428