diff options
Diffstat (limited to 'drivers/spi/spi_bitbang.c')
-rw-r--r-- | drivers/spi/spi_bitbang.c | 24 |
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 | } |
423 | EXPORT_SYMBOL_GPL(spi_bitbang_transfer); | 427 | EXPORT_SYMBOL_GPL(spi_bitbang_transfer); |
424 | 428 | ||