]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/spi/spi.c
iget: stop the MINIX filesystem from using iget() and read_inode()
[linux-2.6-omap-h63xx.git] / drivers / spi / spi.c
index bcb8dd5fb0b48f745e13b5a9430d432360d5c2c8..1ad12afc6ba0ace916c817c571b265dc49cc1398 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/autoconf.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/init.h>
@@ -77,39 +76,33 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 #ifdef CONFIG_PM
 
-/*
- * NOTE:  the suspend() method for an spi_master controller driver
- * should verify that all its child devices are marked as suspended;
- * suspend requests delivered through sysfs power/state files don't
- * enforce such constraints.
- */
 static int spi_suspend(struct device *dev, pm_message_t message)
 {
-       int                     value;
+       int                     value = 0;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv || !drv->suspend)
-               return 0;
-
        /* suspend will stop irqs and dma; no more i/o */
-       value = drv->suspend(to_spi_device(dev), message);
-       if (value == 0)
-               dev->power.power_state = message;
+       if (drv) {
+               if (drv->suspend)
+                       value = drv->suspend(to_spi_device(dev), message);
+               else
+                       dev_dbg(dev, "... can't suspend\n");
+       }
        return value;
 }
 
 static int spi_resume(struct device *dev)
 {
-       int                     value;
+       int                     value = 0;
        struct spi_driver       *drv = to_spi_driver(dev->driver);
 
-       if (!drv || !drv->resume)
-               return 0;
-
        /* resume may restart the i/o queue */
-       value = drv->resume(to_spi_device(dev));
-       if (value == 0)
-               dev->power.power_state = PMSG_ON;
+       if (drv) {
+               if (drv->resume)
+                       value = drv->resume(to_spi_device(dev));
+               else
+                       dev_dbg(dev, "... can't resume\n");
+       }
        return value;
 }
 
@@ -204,7 +197,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
                                  struct spi_board_info *chip)
 {
        struct spi_device       *proxy;
-       struct device           *dev = master->cdev.dev;
+       struct device           *dev = master->dev.parent;
        int                     status;
 
        /* NOTE:  caller did any chip->bus_num checks necessary.
@@ -239,7 +232,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
        proxy->modalias = chip->modalias;
 
        snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id,
-                       "%s.%u", master->cdev.class_id,
+                       "%s.%u", master->dev.bus_id,
                        chip->chip_select);
        proxy->dev.parent = dev;
        proxy->dev.bus = &spi_bus_type;
@@ -338,18 +331,18 @@ static void scan_boardinfo(struct spi_master *master)
 
 /*-------------------------------------------------------------------------*/
 
-static void spi_master_release(struct class_device *cdev)
+static void spi_master_release(struct device *dev)
 {
        struct spi_master *master;
 
-       master = container_of(cdev, struct spi_master, cdev);
+       master = container_of(dev, struct spi_master, dev);
        kfree(master);
 }
 
 static struct class spi_master_class = {
        .name           = "spi_master",
        .owner          = THIS_MODULE,
-       .release        = spi_master_release,
+       .dev_release    = spi_master_release,
 };
 
 
@@ -357,7 +350,7 @@ static struct class spi_master_class = {
  * spi_alloc_master - allocate SPI master controller
  * @dev: the controller, possibly using the platform_bus
  * @size: how much zeroed driver-private data to allocate; the pointer to this
- *     memory is in the class_data field of the returned class_device,
+ *     memory is in the driver_data field of the returned device,
  *     accessible with spi_master_get_devdata().
  * Context: can sleep
  *
@@ -383,9 +376,9 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
        if (!master)
                return NULL;
 
-       class_device_initialize(&master->cdev);
-       master->cdev.class = &spi_master_class;
-       master->cdev.dev = get_device(dev);
+       device_initialize(&master->dev);
+       master->dev.class = &spi_master_class;
+       master->dev.parent = get_device(dev);
        spi_master_set_devdata(master, &master[1]);
 
        return master;
@@ -415,7 +408,7 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
 int spi_register_master(struct spi_master *master)
 {
        static atomic_t         dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
-       struct device           *dev = master->cdev.dev;
+       struct device           *dev = master->dev.parent;
        int                     status = -ENODEV;
        int                     dynamic = 0;
 
@@ -440,12 +433,12 @@ int spi_register_master(struct spi_master *master)
        /* register the device, then userspace will see it.
         * registration fails if the bus ID is in use.
         */
-       snprintf(master->cdev.class_id, sizeof master->cdev.class_id,
+       snprintf(master->dev.bus_id, sizeof master->dev.bus_id,
                "spi%u", master->bus_num);
-       status = class_device_add(&master->cdev);
+       status = device_add(&master->dev);
        if (status < 0)
                goto done;
-       dev_dbg(dev, "registered master %s%s\n", master->cdev.class_id,
+       dev_dbg(dev, "registered master %s%s\n", master->dev.bus_id,
                        dynamic ? " (dynamic)" : "");
 
        /* populate children from any spi device tables */
@@ -457,10 +450,11 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *unused)
+static int __unregister(struct device *dev, void *master_dev)
 {
        /* note: before about 2.6.14-rc1 this would corrupt memory: */
-       spi_unregister_device(to_spi_device(dev));
+       if (dev != master_dev)
+               spi_unregister_device(to_spi_device(dev));
        return 0;
 }
 
@@ -478,11 +472,21 @@ void spi_unregister_master(struct spi_master *master)
 {
        int dummy;
 
-       dummy = device_for_each_child(master->cdev.dev, NULL, __unregister);
-       class_device_unregister(&master->cdev);
+       dummy = device_for_each_child(master->dev.parent, &master->dev,
+                                       __unregister);
+       device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
 
+static int __spi_master_match(struct device *dev, void *data)
+{
+       struct spi_master *m;
+       u16 *bus_num = data;
+
+       m = container_of(dev, struct spi_master, dev);
+       return m->bus_num == *bus_num;
+}
+
 /**
  * spi_busnum_to_master - look up master associated with bus_num
  * @bus_num: the master's bus number
@@ -495,19 +499,14 @@ EXPORT_SYMBOL_GPL(spi_unregister_master);
  */
 struct spi_master *spi_busnum_to_master(u16 bus_num)
 {
-       struct class_device     *cdev;
+       struct device           *dev;
        struct spi_master       *master = NULL;
-       struct spi_master       *m;
-
-       down(&spi_master_class.sem);
-       list_for_each_entry(cdev, &spi_master_class.children, node) {
-               m = container_of(cdev, struct spi_master, cdev);
-               if (m->bus_num == bus_num) {
-                       master = spi_master_get(m);
-                       break;
-               }
-       }
-       up(&spi_master_class.sem);
+
+       dev = class_find_device(&spi_master_class, &bus_num,
+                               __spi_master_match);
+       if (dev)
+               master = container_of(dev, struct spi_master, dev);
+       /* reference got in class_find_device */
        return master;
 }
 EXPORT_SYMBOL_GPL(spi_busnum_to_master);
@@ -539,10 +538,7 @@ static void spi_complete(void *arg)
  * Also, the caller is guaranteeing that the memory associated with the
  * message will not be freed before this call returns.
  *
- * The return value is a negative error code if the message could not be
- * submitted, else zero.  When the value is zero, then message->status is
- * also defined;  it's the completion code for the transfer, either zero
- * or a negative error code from the controller driver.
+ * It returns zero on success, else a negative error code.
  */
 int spi_sync(struct spi_device *spi, struct spi_message *message)
 {
@@ -552,8 +548,10 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
        message->complete = spi_complete;
        message->context = &done;
        status = spi_async(spi, message);
-       if (status == 0)
+       if (status == 0) {
                wait_for_completion(&done);
+               status = message->status;
+       }
        message->context = NULL;
        return status;
 }
@@ -587,7 +585,7 @@ int spi_write_then_read(struct spi_device *spi,
                const u8 *txbuf, unsigned n_tx,
                u8 *rxbuf, unsigned n_rx)
 {
-       static DECLARE_MUTEX(lock);
+       static DEFINE_MUTEX(lock);
 
        int                     status;
        struct spi_message      message;
@@ -613,7 +611,7 @@ int spi_write_then_read(struct spi_device *spi,
        }
 
        /* ... unless someone else is using the pre-allocated buffer */
-       if (down_trylock(&lock)) {
+       if (!mutex_trylock(&lock)) {
                local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
                if (!local_buf)
                        return -ENOMEM;
@@ -626,13 +624,11 @@ int spi_write_then_read(struct spi_device *spi,
 
        /* do the i/o */
        status = spi_sync(spi, &message);
-       if (status == 0) {
+       if (status == 0)
                memcpy(rxbuf, x[1].rx_buf, n_rx);
-               status = message.status;
-       }
 
        if (x[0].tx_buf == buf)
-               up(&lock);
+               mutex_unlock(&lock);
        else
                kfree(local_buf);