Merge branch 'master'
[sfrench/cifs-2.6.git] / drivers / pcmcia / ds.c
index 0252582b91cd7f6ef2d050dbf7c05d4440d3c762..bb96ce1db08c314507d333a1c6145ebfb09006bf 100644 (file)
@@ -311,8 +311,6 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
        /* initialize common fields */
        driver->drv.bus = &pcmcia_bus_type;
        driver->drv.owner = driver->owner;
-       driver->drv.probe = pcmcia_device_probe;
-       driver->drv.remove = pcmcia_device_remove;
 
        return driver_register(&driver->drv);
 }
@@ -354,11 +352,20 @@ static void pcmcia_release_dev(struct device *dev)
        kfree(p_dev);
 }
 
+static void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
+{
+       if (!s->pcmcia_state.device_add_pending) {
+               s->pcmcia_state.device_add_pending = 1;
+               schedule_work(&s->device_add);
+       }
+       return;
+}
 
 static int pcmcia_device_probe(struct device * dev)
 {
        struct pcmcia_device *p_dev;
        struct pcmcia_driver *p_drv;
+       struct pcmcia_device_id *did;
        struct pcmcia_socket *s;
        int ret = 0;
 
@@ -394,6 +401,19 @@ static int pcmcia_device_probe(struct device * dev)
        }
 
        ret = p_drv->probe(p_dev);
+       if (ret)
+               goto put_module;
+
+       /* handle pseudo multifunction devices:
+        * there are at most two pseudo multifunction devices.
+        * if we're matching against the first, schedule a
+        * call which will then check whether there are two
+        * pseudo devices, and if not, add the second one.
+        */
+       did = (struct pcmcia_device_id *) p_dev->dev.driver_data;
+       if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
+           (p_dev->socket->device_count == 1) && (p_dev->device_no == 0))
+               pcmcia_add_pseudo_device(p_dev->socket);
 
  put_module:
        if (ret)
@@ -662,15 +682,6 @@ static void pcmcia_delayed_add_pseudo_device(void *data)
        s->pcmcia_state.device_add_pending = 0;
 }
 
-static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
-{
-       if (!s->pcmcia_state.device_add_pending) {
-               s->pcmcia_state.device_add_pending = 1;
-               schedule_work(&s->device_add);
-       }
-       return;
-}
-
 static int pcmcia_requery(struct device *dev, void * _data)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
@@ -757,15 +768,6 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
        }
 
        if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
-               /* handle pseudo multifunction devices:
-                * there are at most two pseudo multifunction devices.
-                * if we're matching against the first, schedule a
-                * call which will then check whether there are two
-                * pseudo devices, and if not, add the second one.
-                */
-               if (dev->device_no == 0)
-                       pcmcia_add_pseudo_device(dev->socket);
-
                if (dev->device_no != did->device_no)
                        return 0;
        }
@@ -920,6 +922,37 @@ pcmcia_device_stringattr(prod_id2, prod_id[1]);
 pcmcia_device_stringattr(prod_id3, prod_id[2]);
 pcmcia_device_stringattr(prod_id4, prod_id[3]);
 
+
+static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
+
+       if (p_dev->dev.power.power_state.event != PM_EVENT_ON)
+               return sprintf(buf, "off\n");
+       else
+               return sprintf(buf, "on\n");
+}
+
+static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
+       int ret = 0;
+
+        if (!count)
+                return -EINVAL;
+
+       if ((p_dev->dev.power.power_state.event == PM_EVENT_ON) &&
+           (!strncmp(buf, "off", 3)))
+               ret = dpm_runtime_suspend(dev, PMSG_SUSPEND);
+       else if ((p_dev->dev.power.power_state.event != PM_EVENT_ON) &&
+                (!strncmp(buf, "on", 2)))
+               dpm_runtime_resume(dev);
+
+       return ret ? ret : count;
+}
+
+
 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
@@ -945,8 +978,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
-        if (!count)
-                return -EINVAL;
+
+       if (!count)
+               return -EINVAL;
 
        down(&p_dev->socket->skt_sem);
        p_dev->allow_func_id_match = 1;
@@ -959,6 +993,7 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
 
 static struct device_attribute pcmcia_dev_attrs[] = {
        __ATTR(function, 0444, func_show, NULL),
+       __ATTR(pm_state, 0644, pcmcia_show_pm_state, pcmcia_store_pm_state),
        __ATTR_RO(func_id),
        __ATTR_RO(manf_id),
        __ATTR_RO(card_id),
@@ -1167,6 +1202,8 @@ struct bus_type pcmcia_bus_type = {
        .uevent = pcmcia_bus_uevent,
        .match = pcmcia_bus_match,
        .dev_attrs = pcmcia_dev_attrs,
+       .probe = pcmcia_device_probe,
+       .remove = pcmcia_device_remove,
        .suspend = pcmcia_dev_suspend,
        .resume = pcmcia_dev_resume,
 };