Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Sep 2002 14:51:18 +0200
From:      Mark Santcroos <marks@ripe.net>
To:        mobile@freebsd.org
Subject:   pccard re-attach after ACPI S1 resume
Message-ID:  <20020912125118.GA1343@laptop.6bone.nl>

next in thread | raw e-mail | index | archive | help

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

This patch fixes the re-attaching of pccards after suspending(S1) with 
ACPI on my laptop.

Although it is tested it might not be the most clean solution. The same
thing could be done for cardbus also, but I don't have any hardware to
test that.

Please let me know if this should be fixed differently.

Mark


diff -u -r /usr/src/sys/dev/pccard/pccard.c ./pccard.c
--- /usr/src/sys/dev/pccard/pccard.c	Thu Sep 12 12:46:13 2002
+++ ./pccard.c	Thu Sep 12 14:05:10 2002
@@ -155,6 +155,8 @@
 	device_t child;
 	int i;
 
+	sc->suspended = 0; /* XXX initialize, maybe not here */
+
 	/*
 	 * this is here so that when socket_enable calls gettype, trt happens
 	 */
@@ -251,6 +253,7 @@
 	return (0);
 }
 
+#define PCCARD_DETACH_FOR_SUSPEND	0x01
 static int
 pccard_detach_card(device_t dev, int flags)
 {
@@ -265,8 +268,11 @@
 	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
 		int state = device_get_state(pf->dev);
 
-		if (state == DS_ATTACHED || state == DS_BUSY)
+		if (state == DS_ATTACHED || state == DS_BUSY) {
 			device_detach(pf->dev);
+			if(flags & PCCARD_DETACH_FOR_SUSPEND)
+				sc->suspended = 1;
+		}
 		if (pf->cfe != NULL)
 			pccard_function_disable(pf);
 		pccard_function_free(pf);
@@ -776,14 +782,18 @@
 static int
 pccard_suspend(device_t self)
 {
-	pccard_detach_card(self, 0);
+	pccard_detach_card(self, PCCARD_DETACH_FOR_SUSPEND);
 	return (0);
 }
 
 static
 int
-pccard_resume(device_t self)
+pccard_resume(device_t dev)
 {
+	struct pccard_softc *sc = PCCARD_SOFTC(dev);
+
+	if (sc->suspended == 1)
+		pccard_attach_card(dev);
 	return (0);
 }
 
diff -u -r /usr/src/sys/dev/pccard/pccardvar.h ./pccardvar.h
--- /usr/src/sys/dev/pccard/pccardvar.h	Wed Jul 17 07:20:43 2002
+++ ./pccardvar.h	Thu Sep 12 14:06:42 2002
@@ -205,6 +205,8 @@
 	/* this stuff is for the card */
 	struct pccard_card card;
 	int		sc_enabled_count;	/* num functions enabled */
+	/* was there a device active on time of suspension */
+	int		suspended;
 };
 
 void


-- 
Mark Santcroos				RIPE Network Coordination Centre
http://www.ripe.net/home/mark/		New Projects Group/TTM

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pccard_resume.diff"

diff -u -r /usr/src/sys/dev/pccard/pccard.c ./pccard.c
--- /usr/src/sys/dev/pccard/pccard.c	Thu Sep 12 12:46:13 2002
+++ ./pccard.c	Thu Sep 12 14:05:10 2002
@@ -155,6 +155,8 @@
 	device_t child;
 	int i;
 
+	sc->suspended = 0; /* XXX initialize, maybe not here */
+
 	/*
 	 * this is here so that when socket_enable calls gettype, trt happens
 	 */
@@ -251,6 +253,7 @@
 	return (0);
 }
 
+#define PCCARD_DETACH_FOR_SUSPEND	0x01
 static int
 pccard_detach_card(device_t dev, int flags)
 {
@@ -265,8 +268,11 @@
 	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
 		int state = device_get_state(pf->dev);
 
-		if (state == DS_ATTACHED || state == DS_BUSY)
+		if (state == DS_ATTACHED || state == DS_BUSY) {
 			device_detach(pf->dev);
+			if(flags & PCCARD_DETACH_FOR_SUSPEND)
+				sc->suspended = 1;
+		}
 		if (pf->cfe != NULL)
 			pccard_function_disable(pf);
 		pccard_function_free(pf);
@@ -776,14 +782,18 @@
 static int
 pccard_suspend(device_t self)
 {
-	pccard_detach_card(self, 0);
+	pccard_detach_card(self, PCCARD_DETACH_FOR_SUSPEND);
 	return (0);
 }
 
 static
 int
-pccard_resume(device_t self)
+pccard_resume(device_t dev)
 {
+	struct pccard_softc *sc = PCCARD_SOFTC(dev);
+
+	if (sc->suspended == 1)
+		pccard_attach_card(dev);
 	return (0);
 }
 
diff -u -r /usr/src/sys/dev/pccard/pccardvar.h ./pccardvar.h
--- /usr/src/sys/dev/pccard/pccardvar.h	Wed Jul 17 07:20:43 2002
+++ ./pccardvar.h	Thu Sep 12 14:06:42 2002
@@ -205,6 +205,8 @@
 	/* this stuff is for the card */
 	struct pccard_card card;
 	int		sc_enabled_count;	/* num functions enabled */
+	/* was there a device active on time of suspension */
+	int		suspended;
 };
 
 void

--jRHKVT23PllUwdXP--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-mobile" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020912125118.GA1343>