spi: move more spi_setup() functionality into core
[linux-2.6-block.git] / drivers / spi / spi.c
index 0276bc37e2553d76637e0d8cadc2f10d999ce70e..a525a3a848c1580eba478059f8bb6812aa930061 100644 (file)
@@ -607,8 +607,19 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
  */
 int spi_setup(struct spi_device *spi)
 {
+       unsigned        bad_bits;
        int             status;
 
+       /* help drivers fail *cleanly* when they need options
+        * that aren't supported with their current master
+        */
+       bad_bits = spi->mode & ~spi->master->mode_bits;
+       if (bad_bits) {
+               dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
+                       bad_bits);
+               return -EINVAL;
+       }
+
        if (!spi->bits_per_word)
                spi->bits_per_word = 8;