]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/spi/spi.c
Input: spitzkbd - fix the reversed Address and Calender keys
[linux-2.6-omap-h63xx.git] / drivers / spi / spi.c
index 3ecedccdb96cc7e605262fa318c17194b7ce381c..94f5e8ed83a7a8427105201aaa81f14ff5c710c7 100644 (file)
@@ -90,7 +90,7 @@ static int spi_suspend(struct device *dev, pm_message_t message)
        int                     value;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv->suspend)
+       if (!drv || !drv->suspend)
                return 0;
 
        /* suspend will stop irqs and dma; no more i/o */
@@ -105,7 +105,7 @@ static int spi_resume(struct device *dev)
        int                     value;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv->resume)
+       if (!drv || !drv->resume)
                return 0;
 
        /* resume may restart the i/o queue */
@@ -449,7 +449,6 @@ void spi_unregister_master(struct spi_master *master)
 {
        (void) device_for_each_child(master->cdev.dev, NULL, __unregister);
        class_device_unregister(&master->cdev);
-       master->cdev.dev = NULL;
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
 
@@ -480,6 +479,11 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
 
 /*-------------------------------------------------------------------------*/
 
+static void spi_complete(void *arg)
+{
+       complete(arg);
+}
+
 /**
  * spi_sync - blocking/synchronous SPI data transfers
  * @spi: device with which data will be exchanged
@@ -508,7 +512,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
        DECLARE_COMPLETION(done);
        int status;
 
-       message->complete = (void (*)(void *)) complete;
+       message->complete = spi_complete;
        message->context = &done;
        status = spi_async(spi, message);
        if (status == 0)
@@ -557,6 +561,17 @@ int spi_write_then_read(struct spi_device *spi,
        if ((n_tx + n_rx) > SPI_BUFSIZ)
                return -EINVAL;
 
+       spi_message_init(&message);
+       memset(x, 0, sizeof x);
+       if (n_tx) {
+               x[0].len = n_tx;
+               spi_message_add_tail(&x[0], &message);
+       }
+       if (n_rx) {
+               x[1].len = n_rx;
+               spi_message_add_tail(&x[1], &message);
+       }
+
        /* ... unless someone else is using the pre-allocated buffer */
        if (down_trylock(&lock)) {
                local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
@@ -565,18 +580,11 @@ int spi_write_then_read(struct spi_device *spi,
        } else
                local_buf = buf;
 
-       memset(x, 0, sizeof x);
-
        memcpy(local_buf, txbuf, n_tx);
        x[0].tx_buf = local_buf;
-       x[0].len = n_tx;
-
        x[1].rx_buf = local_buf + n_tx;
-       x[1].len = n_rx;
 
        /* do the i/o */
-       message.transfers = x;
-       message.n_transfer = ARRAY_SIZE(x);
        status = spi_sync(spi, &message);
        if (status == 0) {
                memcpy(rxbuf, x[1].rx_buf, n_rx);