diff options
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r-- | drivers/spi/spi.c | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8eba98c8ed1e..0276bc37e255 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -265,7 +265,7 @@ int spi_add_device(struct spi_device *spi) | |||
265 | * normally rely on the device being setup. Devices | 265 | * normally rely on the device being setup. Devices |
266 | * using SPI_CS_HIGH can't coexist well otherwise... | 266 | * using SPI_CS_HIGH can't coexist well otherwise... |
267 | */ | 267 | */ |
268 | status = spi->master->setup(spi); | 268 | status = spi_setup(spi); |
269 | if (status < 0) { | 269 | if (status < 0) { |
270 | dev_err(dev, "can't %s %s, status %d\n", | 270 | dev_err(dev, "can't %s %s, status %d\n", |
271 | "setup", dev_name(&spi->dev), status); | 271 | "setup", dev_name(&spi->dev), status); |
@@ -583,6 +583,59 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master); | |||
583 | 583 | ||
584 | /*-------------------------------------------------------------------------*/ | 584 | /*-------------------------------------------------------------------------*/ |
585 | 585 | ||
586 | /* Core methods for SPI master protocol drivers. Some of the | ||
587 | * other core methods are currently defined as inline functions. | ||
588 | */ | ||
589 | |||
590 | /** | ||
591 | * spi_setup - setup SPI mode and clock rate | ||
592 | * @spi: the device whose settings are being modified | ||
593 | * Context: can sleep, and no requests are queued to the device | ||
594 | * | ||
595 | * SPI protocol drivers may need to update the transfer mode if the | ||
596 | * device doesn't work with its default. They may likewise need | ||
597 | * to update clock rates or word sizes from initial values. This function | ||
598 | * changes those settings, and must be called from a context that can sleep. | ||
599 | * Except for SPI_CS_HIGH, which takes effect immediately, the changes take | ||
600 | * effect the next time the device is selected and data is transferred to | ||
601 | * or from it. When this function returns, the spi device is deselected. | ||
602 | * | ||
603 | * Note that this call will fail if the protocol driver specifies an option | ||
604 | * that the underlying controller or its driver does not support. For | ||
605 | * example, not all hardware supports wire transfers using nine bit words, | ||
606 | * LSB-first wire encoding, or active-high chipselects. | ||
607 | */ | ||
608 | int spi_setup(struct spi_device *spi) | ||
609 | { | ||
610 | int status; | ||
611 | |||
612 | if (!spi->bits_per_word) | ||
613 | spi->bits_per_word = 8; | ||
614 | |||
615 | status = spi->master->setup(spi); | ||
616 | |||
617 | dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s" | ||
618 | "%u bits/w, %u Hz max --> %d\n", | ||
619 | (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), | ||
620 | (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", | ||
621 | (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", | ||
622 | (spi->mode & SPI_3WIRE) ? "3wire, " : "", | ||
623 | (spi->mode & SPI_LOOP) ? "loopback, " : "", | ||
624 | spi->bits_per_word, spi->max_speed_hz, | ||
625 | status); | ||
626 | |||
627 | return status; | ||
628 | } | ||
629 | EXPORT_SYMBOL_GPL(spi_setup); | ||
630 | |||
631 | |||
632 | /*-------------------------------------------------------------------------*/ | ||
633 | |||
634 | /* Utility methods for SPI master protocol drivers, layered on | ||
635 | * top of the core. Some other utility methods are defined as | ||
636 | * inline functions. | ||
637 | */ | ||
638 | |||
586 | static void spi_complete(void *arg) | 639 | static void spi_complete(void *arg) |
587 | { | 640 | { |
588 | complete(arg); | 641 | complete(arg); |