Sun Jan 9 15:43:21 2011 UTC ()
After consulting jmcneill@, set the state to D0 ("on") upon shutdown and
detach. A safety measure so that we do not accidentally fry anything.


(jruoho)
diff -r1.1 -r1.2 src/sys/dev/acpi/acpi_fan.c

cvs diff -r1.1 -r1.2 src/sys/dev/acpi/acpi_fan.c (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi_fan.c 2011/01/09 15:12:34 1.1
+++ src/sys/dev/acpi/acpi_fan.c 2011/01/09 15:43:20 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_fan.c,v 1.1 2011/01/09 15:12:34 jruoho Exp $ */ 1/* $NetBSD: acpi_fan.c,v 1.2 2011/01/09 15:43:20 jruoho Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi> 4 * Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: acpi_fan.c,v 1.1 2011/01/09 15:12:34 jruoho Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: acpi_fan.c,v 1.2 2011/01/09 15:43:20 jruoho Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/module.h> 33#include <sys/module.h>
34 34
35#include <dev/acpi/acpireg.h> 35#include <dev/acpi/acpireg.h>
36#include <dev/acpi/acpivar.h> 36#include <dev/acpi/acpivar.h>
37#include <dev/acpi/acpi_power.h> 37#include <dev/acpi/acpi_power.h>
38 38
39#include <dev/sysmon/sysmonvar.h> 39#include <dev/sysmon/sysmonvar.h>
40 40
41#define _COMPONENT ACPI_RESOURCE_COMPONENT 41#define _COMPONENT ACPI_RESOURCE_COMPONENT
42ACPI_MODULE_NAME ("acpi_fan") 42ACPI_MODULE_NAME ("acpi_fan")
43 43
@@ -102,26 +102,29 @@ acpifan_attach(device_t parent, device_t @@ -102,26 +102,29 @@ acpifan_attach(device_t parent, device_t
102 acpifan_resume, acpifan_shutdown); 102 acpifan_resume, acpifan_shutdown);
103 103
104 rv = AcpiGetHandle(sc->sc_node->ad_handle, "_FIF", &tmp); 104 rv = AcpiGetHandle(sc->sc_node->ad_handle, "_FIF", &tmp);
105 105
106 if (ACPI_SUCCESS(rv)) 106 if (ACPI_SUCCESS(rv))
107 aprint_verbose_dev(self, "ACPI 4.0 functionality present\n"); 107 aprint_verbose_dev(self, "ACPI 4.0 functionality present\n");
108} 108}
109 109
110static int 110static int
111acpifan_detach(device_t self, int flags) 111acpifan_detach(device_t self, int flags)
112{ 112{
113 struct acpifan_softc *sc = device_private(self); 113 struct acpifan_softc *sc = device_private(self);
114 114
 115 if (sc->sc_state != ACPI_STATE_ERROR)
 116 (void)acpi_power_set(sc->sc_node->ad_handle, ACPI_STATE_D0);
 117
115 pmf_device_deregister(self); 118 pmf_device_deregister(self);
116 acpi_power_deregister(sc->sc_node->ad_handle); 119 acpi_power_deregister(sc->sc_node->ad_handle);
117 120
118 if (sc->sc_sme != NULL) 121 if (sc->sc_sme != NULL)
119 sysmon_envsys_unregister(sc->sc_sme); 122 sysmon_envsys_unregister(sc->sc_sme);
120 123
121 return 0; 124 return 0;
122} 125}
123 126
124static bool 127static bool
125acpifan_suspend(device_t self, const pmf_qual_t *qual) 128acpifan_suspend(device_t self, const pmf_qual_t *qual)
126{ 129{
127 struct acpifan_softc *sc = device_private(self); 130 struct acpifan_softc *sc = device_private(self);
@@ -142,27 +145,27 @@ acpifan_resume(device_t self, const pmf_ @@ -142,27 +145,27 @@ acpifan_resume(device_t self, const pmf_
142 145
143 if (sc->sc_state != ACPI_STATE_ERROR) 146 if (sc->sc_state != ACPI_STATE_ERROR)
144 (void)acpi_power_set(sc->sc_node->ad_handle, sc->sc_state); 147 (void)acpi_power_set(sc->sc_node->ad_handle, sc->sc_state);
145 148
146 return true; 149 return true;
147} 150}
148 151
149static bool 152static bool
150acpifan_shutdown(device_t self, int how) 153acpifan_shutdown(device_t self, int how)
151{ 154{
152 struct acpifan_softc *sc = device_private(self); 155 struct acpifan_softc *sc = device_private(self);
153 156
154 if (sc->sc_state != ACPI_STATE_ERROR) 157 if (sc->sc_state != ACPI_STATE_ERROR)
155 (void)acpi_power_set(sc->sc_node->ad_handle, ACPI_STATE_D3); 158 (void)acpi_power_set(sc->sc_node->ad_handle, ACPI_STATE_D0);
156 159
157 return true; 160 return true;
158} 161}
159 162
160static bool 163static bool
161acpifan_sensor_init(device_t self) 164acpifan_sensor_init(device_t self)
162{ 165{
163 struct acpifan_softc *sc = device_private(self); 166 struct acpifan_softc *sc = device_private(self);
164 167
165 if (acpi_power_get(sc->sc_node->ad_handle, &sc->sc_state) != true) 168 if (acpi_power_get(sc->sc_node->ad_handle, &sc->sc_state) != true)
166 return false; 169 return false;
167 170
168 sc->sc_sme = sysmon_envsys_create(); 171 sc->sc_sme = sysmon_envsys_create();