Commit 1e316d7566b63767aa18902235c719e9e95465d0

Authored by David Brownell
Committed by Greg Kroah-Hartman
1 parent 9708c121c3

[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>

Showing 1 changed file with 14 additions and 10 deletions Side-by-side Diff

drivers/spi/spi_bitbang.c
... ... @@ -167,9 +167,11 @@
167 167 /* nsecs = (clock period)/2 */
168 168 if (!hz)
169 169 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 + }
173 175  
174 176 return 0;
175 177 }
... ... @@ -184,9 +186,6 @@
184 186 struct spi_bitbang *bitbang;
185 187 int retval;
186 188  
187   - if (!spi->max_speed_hz)
188   - return -EINVAL;
189   -
190 189 bitbang = spi_master_get_devdata(spi->master);
191 190  
192 191 /* REVISIT: some systems will want to support devices using lsb-first
... ... @@ -216,7 +215,7 @@
216 215 if (retval < 0)
217 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 219 __FUNCTION__, spi->mode & (SPI_CPOL | SPI_CPHA),
221 220 spi->bits_per_word, 2 * cs->nsecs);
222 221  
... ... @@ -405,6 +404,7 @@
405 404 {
406 405 struct spi_bitbang *bitbang;
407 406 unsigned long flags;
  407 + int status = 0;
408 408  
409 409 m->actual_length = 0;
410 410 m->status = -EINPROGRESS;
411 411  
... ... @@ -414,11 +414,15 @@
414 414 return -ESHUTDOWN;
415 415  
416 416 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 + }
419 423 spin_unlock_irqrestore(&bitbang->lock, flags);
420 424  
421   - return 0;
  425 + return status;
422 426 }
423 427 EXPORT_SYMBOL_GPL(spi_bitbang_transfer);
424 428