[patches 2/13] pcmcia: rescan bus always upon echoing into setup_done

Dominik Brodowski linux at dominikbrodowski.net
Sun Mar 6 10:39:48 EST 2005


Always rescan the devices upon echo'ing something to 
available_resources_setup_done. This is needed for proper
"coldplug" support.

Signed-off-by: Dominik Brodowski <linux at dominikbrodowski.net>

Index: 2.6.11+/drivers/pcmcia/cs_internal.h
===================================================================
--- 2.6.11+.orig/drivers/pcmcia/cs_internal.h	2005-03-06 14:51:33.000000000 +0100
+++ 2.6.11+/drivers/pcmcia/cs_internal.h	2005-03-06 15:33:57.000000000 +0100
@@ -159,8 +159,7 @@
 struct pcmcia_callback{
 	struct module	*owner;
 	int		(*event) (struct pcmcia_socket *s, event_t event, int priority);
-	int		(*resources_done) (struct pcmcia_socket *s);
-	void		(*replace_cis) (void);
+	void		(*requery) (struct pcmcia_socket *s);
 };
 
 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
Index: 2.6.11+/drivers/pcmcia/ds.c
===================================================================
--- 2.6.11+.orig/drivers/pcmcia/ds.c	2005-03-06 14:47:35.000000000 +0100
+++ 2.6.11+/drivers/pcmcia/ds.c	2005-03-06 15:42:00.000000000 +0100
@@ -717,9 +717,42 @@
 	return;
 }
 
-static void pcmcia_bus_rescan(void)
+static int pcmcia_requery(struct device *dev, void * _data)
 {
+	struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
+	if (!p_dev->dev.driver)
+		pcmcia_device_query(p_dev);
+
+	return 0;
+}
+
+static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
+{
+	int no_devices=0;
+	unsigned long flags;
+
 	/* must be called with skt_sem held */
+	spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
+	if (list_empty(&skt->pcmcia->devices_list))
+		no_devices=1;
+	spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
+
+	/* if no devices were added for this socket yet because of
+	 * missing resource information or other trouble, we need to
+	 * do this now. */
+	if (no_devices) {
+		int ret = pcmcia_card_add(skt);
+		if (ret)
+			return;
+	}
+
+	/* some device information might have changed because of a CIS
+	 * update or because we can finally read it correctly... so
+	 * determine it again, overwriting old values if necessary. */
+	bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery);
+
+	/* we re-scan all devices, not just the ones connected to this
+	 * socket. This does not matter, though. */
 	bus_rescan_devices(&pcmcia_bus_type);
 }
 
@@ -1858,8 +1891,7 @@
 	/* Set up hotline to Card Services */
 	s->callback.owner = THIS_MODULE;
 	s->callback.event = &ds_event;
-	s->callback.resources_done = &pcmcia_card_add;
-	s->callback.replace_cis = &pcmcia_bus_rescan;
+	s->callback.requery = &pcmcia_bus_rescan;
 	socket->pcmcia = s;
 
 	ret = pccard_register_pcmcia(socket, &s->callback);
Index: 2.6.11+/drivers/pcmcia/socket_sysfs.c
===================================================================
--- 2.6.11+.orig/drivers/pcmcia/socket_sysfs.c	2005-03-06 14:47:45.000000000 +0100
+++ 2.6.11+/drivers/pcmcia/socket_sysfs.c	2005-03-06 15:33:47.000000000 +0100
@@ -163,24 +163,20 @@
 		return -EINVAL;
 
 	spin_lock_irqsave(&s->lock, flags);
-	if (!s->resource_setup_done) {
+	if (!s->resource_setup_done)
 		s->resource_setup_done = 1;
-		spin_unlock_irqrestore(&s->lock, flags);
+	spin_unlock_irqrestore(&s->lock, flags);
 
-		down(&s->skt_sem);
-		if ((s->callback) &&
-		    (s->state & SOCKET_PRESENT) &&
-		    !(s->state & SOCKET_CARDBUS)) {
-			if (try_module_get(s->callback->owner)) {
-				s->callback->resources_done(s);
-				module_put(s->callback->owner);
-			}
+	down(&s->skt_sem);
+	if ((s->callback) &&
+	    (s->state & SOCKET_PRESENT) &&
+	    !(s->state & SOCKET_CARDBUS)) {
+		if (try_module_get(s->callback->owner)) {
+			s->callback->requery(s);
+			module_put(s->callback->owner);
 		}
-		up(&s->skt_sem);
-
-		return count;
 	}
-	spin_unlock_irqrestore(&s->lock, flags);
+	up(&s->skt_sem);
 
 	return count;
 }
@@ -315,7 +311,7 @@
 		if ((s->callback) && (s->state & SOCKET_PRESENT) &&
 		    !(s->state & SOCKET_CARDBUS)) {
 			if (try_module_get(s->callback->owner)) {
-				s->callback->replace_cis();
+				s->callback->requery(s);
 				module_put(s->callback->owner);
 			}
 		}



More information about the linux-pcmcia mailing list