Module Name:    src
Committed By:   riz
Date:           Sun Nov 21 21:44:07 UTC 2010

Modified Files:
        src/sys/dev/acpi [netbsd-5]: wb_acpi.c
        src/sys/dev/ic [netbsd-5]: w83l518d.c w83l518d_sdmmc.c w83l518d_sdmmc.h
            w83l518dvar.h

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1462):
        sys/dev/acpi/wb_acpi.c: revision 1.3
        sys/dev/ic/w83l518d_sdmmc.c: revision 1.2
        sys/dev/ic/w83l518d_sdmmc.h: revision 1.2
        sys/dev/ic/w83l518d.c: revision 1.2
        sys/dev/ic/w83l518dvar.h: revision 1.2
add suspend/resume support
add pmf support


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/dev/acpi/wb_acpi.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/dev/ic/w83l518d.c \
    src/sys/dev/ic/w83l518d_sdmmc.c src/sys/dev/ic/w83l518d_sdmmc.h \
    src/sys/dev/ic/w83l518dvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/wb_acpi.c
diff -u src/sys/dev/acpi/wb_acpi.c:1.1.2.2 src/sys/dev/acpi/wb_acpi.c:1.1.2.3
--- src/sys/dev/acpi/wb_acpi.c:1.1.2.2	Thu Oct  8 09:47:09 2009
+++ src/sys/dev/acpi/wb_acpi.c	Sun Nov 21 21:44:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wb_acpi.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $ */
+/* $NetBSD: wb_acpi.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -26,38 +26,39 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wb_acpi.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wb_acpi.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $");
 
 #include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/syslog.h>
 #include <sys/device.h>
-#include <sys/proc.h>
-
-#include <sys/bus.h>
-
-#include <dev/isa/isavar.h>
-#include <dev/isa/isadmavar.h>
+#include <sys/systm.h>
 
-#include <dev/acpi/acpica.h>
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
 
-#include <dev/sdmmc/sdmmcvar.h>
 #include <dev/ic/w83l518dvar.h>
 #include <dev/ic/w83l518dreg.h>
 
+#include <dev/isa/isadmavar.h>
+
+#include <dev/sdmmc/sdmmcvar.h>
+
+#define _COMPONENT	ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME	("wb_acpi")
+
 static int	wb_acpi_match(device_t, cfdata_t, void *);
 static void	wb_acpi_attach(device_t, device_t, void *);
 static int	wb_acpi_detach(device_t, int);
+static bool	wb_acpi_suspend(device_t PMF_FN_PROTO);
+static bool	wb_acpi_resume(device_t PMF_FN_PROTO);
 
 struct wb_acpi_softc {
 	struct wb_softc sc_wb;
 	isa_chipset_tag_t sc_ic;
 	void *sc_ih;
 	int sc_ioh_length;
+
+	ACPI_HANDLE sc_crs, sc_srs;
+	ACPI_BUFFER sc_crs_buffer;
 };
 
 CFATTACH_DECL_NEW(wb_acpi, sizeof(struct wb_acpi_softc),
@@ -104,6 +105,16 @@
 	if (ACPI_FAILURE(rv))
 		return;
 
+	AcpiGetHandle(aa->aa_node->ad_handle, "_CRS", &sc->sc_crs);
+	AcpiGetHandle(aa->aa_node->ad_handle, "_SRS", &sc->sc_srs);
+	if (sc->sc_crs && sc->sc_srs) {
+		sc->sc_crs_buffer.Pointer = NULL;
+		sc->sc_crs_buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+		rv = AcpiGetCurrentResources(sc->sc_crs, &sc->sc_crs_buffer);
+		if (ACPI_FAILURE(rv))
+			sc->sc_crs = sc->sc_srs = NULL;
+	}
+
 	io = acpi_res_io(&res, 0);
 	irq = acpi_res_irq(&res, 0);
 	if (io == NULL || irq == NULL) {
@@ -133,6 +144,8 @@
 	sc->sc_wb.wb_irq = irq->ar_irq;
 	sc->sc_wb.wb_base = io->ar_base;
 	wb_attach(&sc->sc_wb);
+
+	pmf_device_register(self, wb_acpi_suspend, wb_acpi_resume);
 	
 cleanup:
 	acpi_resource_cleanup(&res);
@@ -144,6 +157,11 @@
 	struct wb_acpi_softc *sc = device_private(self);
 	int rv;
 
+	pmf_device_deregister(self);
+
+	if (sc->sc_crs_buffer.Pointer)
+		ACPI_FREE(sc->sc_crs_buffer.Pointer);
+
 	rv = wb_detach(&sc->sc_wb, flags);
 	if (rv)
 		return rv;
@@ -157,3 +175,27 @@
 
 	return 0;
 }
+
+static bool
+wb_acpi_suspend(device_t self PMF_FN_ARGS)
+{
+	struct wb_acpi_softc *sc = device_private(self);
+
+	return wb_suspend(&sc->sc_wb);
+}
+
+static bool
+wb_acpi_resume(device_t self PMF_FN_ARGS)
+{
+	struct wb_acpi_softc *sc = device_private(self);
+	ACPI_STATUS rv;
+
+	if (sc->sc_crs && sc->sc_srs) {
+		rv = AcpiSetCurrentResources(sc->sc_srs, &sc->sc_crs_buffer);
+		if (ACPI_FAILURE(rv))
+			printf("%s: _SRS failed: %s\n",
+			    device_xname(self), AcpiFormatException(rv));
+	}
+
+	return wb_resume(&sc->sc_wb);
+}

Index: src/sys/dev/ic/w83l518d.c
diff -u src/sys/dev/ic/w83l518d.c:1.1.2.2 src/sys/dev/ic/w83l518d.c:1.1.2.3
--- src/sys/dev/ic/w83l518d.c:1.1.2.2	Thu Oct  8 09:47:09 2009
+++ src/sys/dev/ic/w83l518d.c	Sun Nov 21 21:44:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518d.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $ */
+/* $NetBSD: w83l518d.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -137,3 +137,24 @@
 
 	return 0;
 }
+
+/*
+ * pmf
+ */
+bool
+wb_suspend(struct wb_softc *wb)
+{
+	if (wb->wb_type == WB_DEVNO_SD)	
+		return wb_sdmmc_suspend(wb);
+
+	return false;
+}
+
+bool
+wb_resume(struct wb_softc *wb)
+{
+	if (wb->wb_type == WB_DEVNO_SD)
+		return wb_sdmmc_resume(wb);
+
+	return false;
+}
Index: src/sys/dev/ic/w83l518d_sdmmc.c
diff -u src/sys/dev/ic/w83l518d_sdmmc.c:1.1.2.2 src/sys/dev/ic/w83l518d_sdmmc.c:1.1.2.3
--- src/sys/dev/ic/w83l518d_sdmmc.c:1.1.2.2	Thu Oct  8 09:47:09 2009
+++ src/sys/dev/ic/w83l518d_sdmmc.c	Sun Nov 21 21:44:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518d_sdmmc.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $ */
+/* $NetBSD: w83l518d_sdmmc.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: w83l518d_sdmmc.c,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: w83l518d_sdmmc.c,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -126,12 +126,12 @@
 	/* put the device in a known state */
 	wb_idx_write(wb, WB_INDEX_SETUP, WB_SETUP_SOFT_RST);
 	while (--i > 0 && wb_idx_read(wb, WB_INDEX_SETUP) & WB_SETUP_SOFT_RST)
-		delay(10);
+		delay(100);
 	if (i == 0) {
 		aprint_error_dev(wb->wb_dev, "timeout resetting device\n");
 		return false;
 	}
-	wb_idx_write(wb, WB_INDEX_CLK, WB_CLK_375K);
+	wb_idx_write(wb, WB_INDEX_CLK, wb->wb_sdmmc_clk);
 	wb_idx_write(wb, WB_INDEX_FIFOEN, 0);
 	wb_idx_write(wb, WB_INDEX_DMA, 0);
 	wb_idx_write(wb, WB_INDEX_PBSMSB, 0);
@@ -172,6 +172,7 @@
 	callout_setfunc(&wb->wb_sdmmc_callout, wb_sdmmc_discover, wb);
 
 	wb->wb_sdmmc_width = 1;
+	wb->wb_sdmmc_clk = WB_CLK_375K;
 
 	if (wb_sdmmc_enable(wb) == false)
 		return;
@@ -287,6 +288,8 @@
 	else
 		clk = WB_CLK_375K;
 
+	wb->wb_sdmmc_clk = clk;
+
 	if (wb_idx_read(wb, WB_INDEX_CLK) != clk)
 		wb_idx_write(wb, WB_INDEX_CLK, clk);
 
@@ -308,7 +311,6 @@
 	return 0;
 }
 
-
 static void
 wb_sdmmc_rsp_read_long(struct wb_softc *wb, struct sdmmc_command *cmd)
 {
@@ -574,3 +576,30 @@
 
 	return 1;
 }
+
+/*
+ * pmf
+ */
+bool
+wb_sdmmc_suspend(struct wb_softc *wb)
+{
+	return wb_sdmmc_disable(wb);
+}
+
+bool
+wb_sdmmc_resume(struct wb_softc *wb)
+{
+	uint8_t val;
+
+	val = wb_read(wb, WB_SD_CSR);
+	val &= ~WB_CSR_POWER_N;
+	wb_write(wb, WB_SD_CSR, val);
+
+	if (wb_sdmmc_enable(wb) == false)
+		return false;
+
+	if (wb_idx_read(wb, WB_INDEX_CLK) != wb->wb_sdmmc_clk)
+		wb_idx_write(wb, WB_INDEX_CLK, wb->wb_sdmmc_clk);
+
+	return true;
+}
Index: src/sys/dev/ic/w83l518d_sdmmc.h
diff -u src/sys/dev/ic/w83l518d_sdmmc.h:1.1.2.2 src/sys/dev/ic/w83l518d_sdmmc.h:1.1.2.3
--- src/sys/dev/ic/w83l518d_sdmmc.h:1.1.2.2	Thu Oct  8 09:47:09 2009
+++ src/sys/dev/ic/w83l518d_sdmmc.h	Sun Nov 21 21:44:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518d_sdmmc.h,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $ */
+/* $NetBSD: w83l518d_sdmmc.h,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -31,5 +31,7 @@
 void	wb_sdmmc_attach(struct wb_softc *);
 int	wb_sdmmc_detach(struct wb_softc *, int);
 int	wb_sdmmc_intr(struct wb_softc *);
+bool	wb_sdmmc_suspend(struct wb_softc *);
+bool	wb_sdmmc_resume(struct wb_softc *);
 
 #endif
Index: src/sys/dev/ic/w83l518dvar.h
diff -u src/sys/dev/ic/w83l518dvar.h:1.1.2.2 src/sys/dev/ic/w83l518dvar.h:1.1.2.3
--- src/sys/dev/ic/w83l518dvar.h:1.1.2.2	Thu Oct  8 09:47:09 2009
+++ src/sys/dev/ic/w83l518dvar.h	Sun Nov 21 21:44:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518dvar.h,v 1.1.2.2 2009/10/08 09:47:09 sborrill Exp $ */
+/* $NetBSD: w83l518dvar.h,v 1.1.2.3 2010/11/21 21:44:07 riz Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -41,6 +41,7 @@
 	/* private */
 	device_t		wb_sdmmc_dev;
 	int			wb_sdmmc_width;
+	uint8_t			wb_sdmmc_clk;
 	uint8_t			wb_sdmmc_intsts;
 	callout_t		wb_sdmmc_callout;
 };
@@ -56,4 +57,7 @@
 
 void	wb_led(struct wb_softc *, bool);
 
+bool	wb_suspend(struct wb_softc *);
+bool	wb_resume(struct wb_softc *);
+
 #endif

Reply via email to