Skip to content

Commit 1e316d7

Browse files
David Brownellgregkh
authored andcommitted
[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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9708c12 commit 1e316d7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

drivers/spi/spi_bitbang.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ int spi_bitbang_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
167167
/* nsecs = (clock period)/2 */
168168
if (!hz)
169169
hz = spi->max_speed_hz;
170-
cs->nsecs = (1000000000/2) / hz;
171-
if (cs->nsecs > MAX_UDELAY_MS * 1000)
172-
return -EINVAL;
170+
if (hz) {
171+
cs->nsecs = (1000000000/2) / hz;
172+
if (cs->nsecs > (MAX_UDELAY_MS * 1000 * 1000))
173+
return -EINVAL;
174+
}
173175

174176
return 0;
175177
}
@@ -184,9 +186,6 @@ int spi_bitbang_setup(struct spi_device *spi)
184186
struct spi_bitbang *bitbang;
185187
int retval;
186188

187-
if (!spi->max_speed_hz)
188-
return -EINVAL;
189-
190189
bitbang = spi_master_get_devdata(spi->master);
191190

192191
/* REVISIT: some systems will want to support devices using lsb-first
@@ -216,7 +215,7 @@ int spi_bitbang_setup(struct spi_device *spi)
216215
if (retval < 0)
217216
return retval;
218217

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",
220219
__FUNCTION__, spi->mode & (SPI_CPOL | SPI_CPHA),
221220
spi->bits_per_word, 2 * cs->nsecs);
222221

@@ -405,6 +404,7 @@ int spi_bitbang_transfer(struct spi_device *spi, struct spi_message *m)
405404
{
406405
struct spi_bitbang *bitbang;
407406
unsigned long flags;
407+
int status = 0;
408408

409409
m->actual_length = 0;
410410
m->status = -EINPROGRESS;
@@ -414,11 +414,15 @@ int spi_bitbang_transfer(struct spi_device *spi, struct spi_message *m)
414414
return -ESHUTDOWN;
415415

416416
spin_lock_irqsave(&bitbang->lock, flags);
417-
list_add_tail(&m->queue, &bitbang->queue);
418-
queue_work(bitbang->workqueue, &bitbang->work);
417+
if (!spi->max_speed_hz)
418+
status = -ENETDOWN;
419+
else {
420+
list_add_tail(&m->queue, &bitbang->queue);
421+
queue_work(bitbang->workqueue, &bitbang->work);
422+
}
419423
spin_unlock_irqrestore(&bitbang->lock, flags);
420424

421-
return 0;
425+
return status;
422426
}
423427
EXPORT_SYMBOL_GPL(spi_bitbang_transfer);
424428

0 commit comments

Comments
 (0)