apple_smc_fan.c revision 1.2 1 1.1 riastrad /* $NetBSD: apple_smc_fan.c,v 1.2 2014/04/01 17:48:39 riastradh Exp $ */
2 1.1 riastrad
3 1.1 riastrad /*
4 1.1 riastrad * Apple System Management Controller: Fans
5 1.1 riastrad */
6 1.1 riastrad
7 1.1 riastrad /*-
8 1.1 riastrad * Copyright (c) 2013 The NetBSD Foundation, Inc.
9 1.1 riastrad * All rights reserved.
10 1.1 riastrad *
11 1.1 riastrad * This code is derived from software contributed to The NetBSD Foundation
12 1.1 riastrad * by Taylor R. Campbell.
13 1.1 riastrad *
14 1.1 riastrad * Redistribution and use in source and binary forms, with or without
15 1.1 riastrad * modification, are permitted provided that the following conditions
16 1.1 riastrad * are met:
17 1.1 riastrad * 1. Redistributions of source code must retain the above copyright
18 1.1 riastrad * notice, this list of conditions and the following disclaimer.
19 1.1 riastrad * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 riastrad * notice, this list of conditions and the following disclaimer in the
21 1.1 riastrad * documentation and/or other materials provided with the distribution.
22 1.1 riastrad *
23 1.1 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 riastrad * POSSIBILITY OF SUCH DAMAGE.
34 1.1 riastrad */
35 1.1 riastrad
36 1.1 riastrad #include <sys/cdefs.h>
37 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: apple_smc_fan.c,v 1.2 2014/04/01 17:48:39 riastradh Exp $");
38 1.1 riastrad
39 1.1 riastrad #include <sys/types.h>
40 1.1 riastrad #include <sys/param.h>
41 1.1 riastrad #include <sys/device.h>
42 1.1 riastrad #include <sys/kmem.h>
43 1.2 riastrad #include <sys/module.h>
44 1.1 riastrad #if 0 /* XXX sysctl */
45 1.1 riastrad #include <sys/sysctl.h>
46 1.1 riastrad #endif
47 1.1 riastrad #include <sys/systm.h>
48 1.1 riastrad
49 1.1 riastrad #include <dev/ic/apple_smc.h>
50 1.1 riastrad
51 1.1 riastrad #include <dev/sysmon/sysmonvar.h>
52 1.1 riastrad
53 1.2 riastrad #define APPLE_SMC_DEVICE "applesmcfan"
54 1.2 riastrad
55 1.1 riastrad #define APPLE_SMC_NFANS_KEY "FNum"
56 1.1 riastrad
57 1.1 riastrad static const struct fan_sensor {
58 1.1 riastrad const char *fs_name;
59 1.1 riastrad const char *fs_key_suffix;
60 1.1 riastrad } fan_sensors[] = {
61 1.1 riastrad { "actual", "Ac" },
62 1.1 riastrad { "minimum", "Mn" },
63 1.1 riastrad { "maximum", "Mx" },
64 1.1 riastrad { "safe", "Sf" },
65 1.1 riastrad { "target", "Tg" },
66 1.1 riastrad };
67 1.1 riastrad
68 1.1 riastrad struct apple_smc_fan_softc {
69 1.1 riastrad device_t sc_dev;
70 1.1 riastrad struct apple_smc_tag *sc_smc;
71 1.1 riastrad struct sysmon_envsys *sc_sme;
72 1.1 riastrad uint8_t sc_nfans;
73 1.1 riastrad struct {
74 1.1 riastrad struct {
75 1.1 riastrad struct apple_smc_key *sensor_key;
76 1.1 riastrad struct envsys_data sensor_data;
77 1.1 riastrad } sensors[__arraycount(fan_sensors)];
78 1.1 riastrad } *sc_fans;
79 1.1 riastrad
80 1.1 riastrad #if 0 /* XXX sysctl */
81 1.1 riastrad struct sysctllog *sc_sysctl_log;
82 1.1 riastrad const struct sysctlnode *sc_sysctl_node;
83 1.1 riastrad #endif
84 1.1 riastrad };
85 1.1 riastrad
86 1.1 riastrad struct fan_desc {
87 1.1 riastrad uint8_t fd_type;
88 1.1 riastrad uint8_t fd_zone;
89 1.1 riastrad uint8_t fd_location;
90 1.1 riastrad uint8_t fd_reserved0;
91 1.1 riastrad char fd_name[12];
92 1.1 riastrad } __packed;
93 1.1 riastrad
94 1.1 riastrad static int apple_smc_fan_match(device_t, cfdata_t, void *);
95 1.1 riastrad static void apple_smc_fan_attach(device_t, device_t, void *);
96 1.1 riastrad static int apple_smc_fan_detach(device_t, int);
97 1.1 riastrad static int apple_smc_fan_attach_sensors(struct apple_smc_fan_softc *);
98 1.1 riastrad static void apple_smc_fan_attach_sensor(struct apple_smc_fan_softc *,
99 1.1 riastrad uint8_t, const char *, uint8_t);
100 1.1 riastrad static void apple_smc_fan_refresh(struct sysmon_envsys *,
101 1.1 riastrad struct envsys_data *);
102 1.1 riastrad static void apple_smc_fan_release_keys(struct apple_smc_fan_softc *);
103 1.1 riastrad #if 0 /* XXX sysctl */
104 1.1 riastrad static int apple_smc_fan_sysctl_setup(struct apple_smc_fan_softc *);
105 1.1 riastrad static void apple_smc_fan_sysctl_setup_1(struct apple_smc_tag *,
106 1.1 riastrad uint8_t);
107 1.1 riastrad #endif
108 1.1 riastrad
109 1.1 riastrad CFATTACH_DECL_NEW(apple_smc_fan, sizeof(struct apple_smc_fan_softc),
110 1.1 riastrad apple_smc_fan_match, apple_smc_fan_attach, apple_smc_fan_detach, NULL);
111 1.1 riastrad
112 1.1 riastrad static int
113 1.1 riastrad apple_smc_fan_match(device_t parent, cfdata_t match, void *aux)
114 1.1 riastrad {
115 1.1 riastrad const struct apple_smc_attach_args *asa = aux;
116 1.1 riastrad struct apple_smc_key *nfans_key;
117 1.1 riastrad uint8_t nfans;
118 1.1 riastrad int rv = 0;
119 1.1 riastrad int error;
120 1.1 riastrad
121 1.2 riastrad if (strcmp(asa->asa_device, APPLE_SMC_DEVICE) != 0)
122 1.2 riastrad goto out0;
123 1.2 riastrad
124 1.1 riastrad error = apple_smc_named_key(asa->asa_smc, APPLE_SMC_NFANS_KEY,
125 1.1 riastrad APPLE_SMC_TYPE_UINT8, &nfans_key);
126 1.1 riastrad if (error)
127 1.1 riastrad goto out0;
128 1.1 riastrad
129 1.1 riastrad error = apple_smc_read_key_1(asa->asa_smc, nfans_key, &nfans);
130 1.1 riastrad if (error)
131 1.1 riastrad goto out1;
132 1.1 riastrad
133 1.1 riastrad if (nfans > 0)
134 1.1 riastrad rv = 1;
135 1.1 riastrad
136 1.1 riastrad out1: apple_smc_release_key(asa->asa_smc, nfans_key);
137 1.1 riastrad out0: return rv;
138 1.1 riastrad }
139 1.1 riastrad
140 1.1 riastrad static void
141 1.1 riastrad apple_smc_fan_attach(device_t parent, device_t self, void *aux)
142 1.1 riastrad {
143 1.1 riastrad struct apple_smc_fan_softc *sc = device_private(self);
144 1.1 riastrad const struct apple_smc_attach_args *asa = aux;
145 1.1 riastrad struct apple_smc_key *nfans_key;
146 1.1 riastrad int error;
147 1.1 riastrad
148 1.1 riastrad aprint_normal(": Apple SMC fan sensors\n");
149 1.1 riastrad
150 1.1 riastrad sc->sc_dev = self;
151 1.1 riastrad sc->sc_smc = asa->asa_smc;
152 1.1 riastrad
153 1.1 riastrad error = apple_smc_named_key(sc->sc_smc, APPLE_SMC_NFANS_KEY,
154 1.1 riastrad APPLE_SMC_TYPE_UINT8, &nfans_key);
155 1.1 riastrad if (error)
156 1.1 riastrad goto out0;
157 1.1 riastrad
158 1.1 riastrad error = apple_smc_read_key_1(sc->sc_smc, nfans_key, &sc->sc_nfans);
159 1.1 riastrad if (error)
160 1.1 riastrad goto out1;
161 1.1 riastrad
162 1.1 riastrad if (sc->sc_nfans == 0) { /* XXX */
163 1.1 riastrad aprint_error_dev(self, "no fans\n");
164 1.1 riastrad goto out1;
165 1.1 riastrad }
166 1.1 riastrad
167 1.1 riastrad /* Must fit in a single decimal digit. */
168 1.1 riastrad if (sc->sc_nfans >= 10) {
169 1.1 riastrad aprint_error_dev(self, "too many fans: %"PRIu8"\n",
170 1.1 riastrad sc->sc_nfans);
171 1.1 riastrad sc->sc_nfans = 9;
172 1.1 riastrad }
173 1.1 riastrad
174 1.1 riastrad #if 0 /* XXX sysctl */
175 1.1 riastrad error = apple_smc_fan_sysctl_setup(sc);
176 1.1 riastrad if (error)
177 1.1 riastrad goto fail0;
178 1.1 riastrad #endif
179 1.1 riastrad
180 1.1 riastrad error = apple_smc_fan_attach_sensors(sc);
181 1.1 riastrad if (error)
182 1.1 riastrad goto fail1;
183 1.1 riastrad
184 1.1 riastrad goto out1;
185 1.1 riastrad
186 1.1 riastrad #if 0
187 1.1 riastrad fail2:
188 1.1 riastrad apple_smc_fan_detach_sensors(sc);
189 1.1 riastrad #endif
190 1.1 riastrad
191 1.1 riastrad fail1:
192 1.1 riastrad #if 0 /* XXX sysctl */
193 1.1 riastrad sysctl_teardown(&sc->sc_sysctl_log);
194 1.1 riastrad fail0:
195 1.1 riastrad #endif
196 1.1 riastrad
197 1.1 riastrad out1: apple_smc_release_key(sc->sc_smc, nfans_key);
198 1.1 riastrad out0: return;
199 1.1 riastrad }
200 1.1 riastrad
201 1.1 riastrad static int
202 1.1 riastrad apple_smc_fan_detach(device_t self, int flags)
203 1.1 riastrad {
204 1.1 riastrad struct apple_smc_fan_softc *sc = device_private(self);
205 1.1 riastrad
206 1.1 riastrad if (sc->sc_sme != NULL) {
207 1.1 riastrad sysmon_envsys_unregister(sc->sc_sme);
208 1.1 riastrad sc->sc_sme = NULL;
209 1.1 riastrad
210 1.1 riastrad KASSERT(sc->sc_fans != NULL);
211 1.1 riastrad KASSERT(sc->sc_nfans > 0);
212 1.1 riastrad KASSERT(sc->sc_nfans < 10);
213 1.1 riastrad
214 1.1 riastrad apple_smc_fan_release_keys(sc);
215 1.1 riastrad kmem_free(sc->sc_fans,
216 1.1 riastrad (sizeof(sc->sc_fans[0]) * sc->sc_nfans));
217 1.1 riastrad sc->sc_fans = NULL;
218 1.1 riastrad sc->sc_nfans = 0;
219 1.1 riastrad }
220 1.1 riastrad
221 1.1 riastrad #if 0 /* XXX sysctl */
222 1.1 riastrad sysctl_teardown(&sc->sc_sysctl_log);
223 1.1 riastrad #endif
224 1.1 riastrad
225 1.1 riastrad return 0;
226 1.1 riastrad }
227 1.1 riastrad
228 1.1 riastrad static int
229 1.1 riastrad apple_smc_fan_attach_sensors(struct apple_smc_fan_softc *sc)
230 1.1 riastrad {
231 1.1 riastrad uint8_t fan, sensor;
232 1.1 riastrad char fan_desc_key_name[4 + 1];
233 1.1 riastrad struct apple_smc_key *fan_desc_key;
234 1.1 riastrad struct fan_desc fan_desc;
235 1.1 riastrad char name[sizeof(fan_desc.fd_name) + 1];
236 1.1 riastrad int error;
237 1.1 riastrad
238 1.1 riastrad sc->sc_sme = sysmon_envsys_create();
239 1.1 riastrad sc->sc_sme->sme_name = device_xname(sc->sc_dev);
240 1.1 riastrad sc->sc_sme->sme_cookie = sc;
241 1.1 riastrad sc->sc_sme->sme_refresh = apple_smc_fan_refresh;
242 1.1 riastrad
243 1.1 riastrad CTASSERT(10 <= (SIZE_MAX / sizeof(sc->sc_fans[0])));
244 1.1 riastrad sc->sc_fans = kmem_zalloc((sizeof(sc->sc_fans[0]) * sc->sc_nfans),
245 1.1 riastrad KM_SLEEP);
246 1.1 riastrad
247 1.1 riastrad for (fan = 0; fan < sc->sc_nfans; fan++) {
248 1.1 riastrad (void)snprintf(fan_desc_key_name, sizeof fan_desc_key_name,
249 1.1 riastrad "F%"PRIu8"ID", fan);
250 1.1 riastrad KASSERT(4 == strlen(fan_desc_key_name));
251 1.1 riastrad
252 1.1 riastrad error = apple_smc_named_key(sc->sc_smc, fan_desc_key_name,
253 1.1 riastrad APPLE_SMC_TYPE_FANDESC, &fan_desc_key);
254 1.1 riastrad if (error) {
255 1.1 riastrad aprint_error_dev(sc->sc_dev,
256 1.1 riastrad "error identifying fan %"PRIu8": %d\n",
257 1.1 riastrad fan, error);
258 1.1 riastrad continue;
259 1.1 riastrad }
260 1.1 riastrad
261 1.1 riastrad error = apple_smc_read_key(sc->sc_smc, fan_desc_key, &fan_desc,
262 1.1 riastrad sizeof fan_desc);
263 1.1 riastrad if (error) {
264 1.1 riastrad aprint_error_dev(sc->sc_dev,
265 1.1 riastrad "error identifying fan %"PRIu8": %d\n",
266 1.1 riastrad fan, error);
267 1.1 riastrad continue;
268 1.1 riastrad }
269 1.1 riastrad
270 1.1 riastrad /*
271 1.1 riastrad * XXX Do more with the fan description...
272 1.1 riastrad */
273 1.1 riastrad
274 1.1 riastrad (void)memcpy(name, fan_desc.fd_name, sizeof(fan_desc.fd_name));
275 1.1 riastrad name[sizeof(fan_desc.fd_name)] = 0;
276 1.1 riastrad
277 1.1 riastrad for (sensor = 0; sensor < __arraycount(fan_sensors); sensor++)
278 1.1 riastrad apple_smc_fan_attach_sensor(sc, fan, name, sensor);
279 1.1 riastrad
280 1.1 riastrad #if 0 /* XXX sysctl */
281 1.1 riastrad apple_smc_fan_sysctl_setup_1(sc, fan);
282 1.1 riastrad #endif
283 1.1 riastrad }
284 1.1 riastrad
285 1.1 riastrad error = sysmon_envsys_register(sc->sc_sme);
286 1.1 riastrad if (error)
287 1.1 riastrad goto fail;
288 1.1 riastrad
289 1.1 riastrad error = 0;
290 1.1 riastrad goto out;
291 1.1 riastrad
292 1.1 riastrad fail: sysmon_envsys_destroy(sc->sc_sme);
293 1.1 riastrad sc->sc_sme = NULL;
294 1.1 riastrad out: return error;
295 1.1 riastrad }
296 1.1 riastrad
297 1.1 riastrad static void
298 1.1 riastrad apple_smc_fan_attach_sensor(struct apple_smc_fan_softc *sc, uint8_t fan,
299 1.1 riastrad const char *name, uint8_t sensor)
300 1.1 riastrad {
301 1.1 riastrad char key_name[4 + 1];
302 1.1 riastrad struct apple_smc_key **keyp;
303 1.1 riastrad struct envsys_data *edata;
304 1.1 riastrad int error;
305 1.1 riastrad
306 1.1 riastrad KASSERT(fan < sc->sc_nfans);
307 1.1 riastrad KASSERT(sensor < __arraycount(fan_sensors));
308 1.1 riastrad
309 1.1 riastrad keyp = &sc->sc_fans[fan].sensors[sensor].sensor_key;
310 1.1 riastrad (void)snprintf(key_name, sizeof key_name, "F%d%s",
311 1.1 riastrad (int)sensor, fan_sensors[sensor].fs_key_suffix);
312 1.1 riastrad KASSERT(strlen(key_name) == 4);
313 1.1 riastrad error = apple_smc_named_key(sc->sc_smc, key_name, APPLE_SMC_TYPE_FPE2,
314 1.1 riastrad keyp);
315 1.1 riastrad if (error)
316 1.1 riastrad goto fail0;
317 1.1 riastrad
318 1.1 riastrad edata = &sc->sc_fans[fan].sensors[sensor].sensor_data;
319 1.1 riastrad edata->units = ENVSYS_SFANRPM;
320 1.1 riastrad edata->state = ENVSYS_SINVALID;
321 1.1 riastrad edata->flags = ENVSYS_FHAS_ENTROPY;
322 1.1 riastrad (void)snprintf(edata->desc, sizeof(edata->desc), "fan %s %s speed",
323 1.1 riastrad name, fan_sensors[sensor].fs_name);
324 1.1 riastrad
325 1.1 riastrad error = sysmon_envsys_sensor_attach(sc->sc_sme, edata);
326 1.1 riastrad if (error)
327 1.1 riastrad goto fail1;
328 1.1 riastrad
329 1.1 riastrad return;
330 1.1 riastrad
331 1.1 riastrad fail1: apple_smc_release_key(sc->sc_smc, *keyp);
332 1.1 riastrad fail0: *keyp = NULL;
333 1.1 riastrad aprint_error_dev(sc->sc_dev,
334 1.1 riastrad "failed to attach fan %s %s speed sensor: %d\n",
335 1.1 riastrad name, fan_sensors[sensor].fs_name, error);
336 1.1 riastrad }
337 1.1 riastrad
338 1.1 riastrad static void
339 1.1 riastrad apple_smc_fan_refresh(struct sysmon_envsys *sme, struct envsys_data *edata)
340 1.1 riastrad {
341 1.1 riastrad struct apple_smc_fan_softc *sc = sme->sme_cookie;
342 1.1 riastrad uint8_t fan, sensor;
343 1.1 riastrad struct apple_smc_key *key;
344 1.1 riastrad uint16_t rpm;
345 1.1 riastrad int error;
346 1.1 riastrad
347 1.1 riastrad CTASSERT(10 <= (SIZE_MAX / __arraycount(fan_sensors)));
348 1.1 riastrad KASSERT(sc->sc_nfans < 10);
349 1.1 riastrad if (edata->sensor >= (sc->sc_nfans * __arraycount(fan_sensors))) {
350 1.1 riastrad aprint_error_dev(sc->sc_dev, "unknown sensor %"PRIu32"\n",
351 1.1 riastrad edata->sensor);
352 1.1 riastrad return;
353 1.1 riastrad }
354 1.1 riastrad
355 1.1 riastrad fan = (edata->sensor / __arraycount(fan_sensors));
356 1.1 riastrad sensor = (edata->sensor % __arraycount(fan_sensors));
357 1.1 riastrad
358 1.1 riastrad KASSERT(fan < sc->sc_nfans);
359 1.1 riastrad KASSERT(sensor < __arraycount(fan_sensors));
360 1.1 riastrad KASSERT(edata == &sc->sc_fans[fan].sensors[sensor].sensor_data);
361 1.1 riastrad
362 1.1 riastrad /*
363 1.1 riastrad * If we're refreshing, this sensor got attached, so we ought
364 1.1 riastrad * to have a sensor key.
365 1.1 riastrad */
366 1.1 riastrad key = sc->sc_fans[fan].sensors[sensor].sensor_key;
367 1.1 riastrad KASSERT(key != NULL);
368 1.1 riastrad
369 1.1 riastrad error = apple_smc_read_key_2(sc->sc_smc, key, &rpm);
370 1.1 riastrad if (error) {
371 1.1 riastrad aprint_error_dev(sc->sc_dev,
372 1.1 riastrad "failed to read fan %d %s speed: %d\n",
373 1.1 riastrad fan, fan_sensors[sensor].fs_name, error);
374 1.1 riastrad edata->state = ENVSYS_SINVALID;
375 1.1 riastrad return;
376 1.1 riastrad }
377 1.1 riastrad
378 1.1 riastrad edata->value_cur = rpm;
379 1.1 riastrad edata->state = ENVSYS_SVALID;
380 1.1 riastrad }
381 1.1 riastrad
382 1.1 riastrad static void
383 1.1 riastrad apple_smc_fan_release_keys(struct apple_smc_fan_softc *sc)
384 1.1 riastrad {
385 1.1 riastrad uint8_t fan, sensor;
386 1.1 riastrad
387 1.1 riastrad for (fan = 0; fan < sc->sc_nfans; fan++) {
388 1.1 riastrad for (sensor = 0;
389 1.1 riastrad sensor < __arraycount(fan_sensors);
390 1.1 riastrad sensor++) {
391 1.1 riastrad struct apple_smc_key **const keyp =
392 1.1 riastrad &sc->sc_fans[fan].sensors[sensor].sensor_key;
393 1.1 riastrad if (*keyp != NULL) {
394 1.1 riastrad apple_smc_release_key(sc->sc_smc, *keyp);
395 1.1 riastrad *keyp = NULL;
396 1.1 riastrad }
397 1.1 riastrad }
398 1.1 riastrad }
399 1.1 riastrad }
400 1.1 riastrad
401 1.1 riastrad #if 0 /* XXX sysctl */
402 1.1 riastrad static int
403 1.1 riastrad apple_smc_fan_sysctl_setup(struct apple_smc_fan_softc *sc)
404 1.1 riastrad {
405 1.1 riastrad ...
406 1.1 riastrad }
407 1.1 riastrad
408 1.1 riastrad static void
409 1.1 riastrad apple_smc_fan_sysctl_setup_1(struct apple_smc_fan_softc *sc, uint8_t fan)
410 1.1 riastrad {
411 1.1 riastrad }
412 1.1 riastrad #endif
413 1.2 riastrad
414 1.2 riastrad MODULE(MODULE_CLASS_DRIVER, apple_smc_fan, "apple_smc");
415 1.2 riastrad
416 1.2 riastrad #ifdef _MODULE
417 1.2 riastrad #include "ioconf.c"
418 1.2 riastrad #endif
419 1.2 riastrad
420 1.2 riastrad static int
421 1.2 riastrad apple_smc_fan_modcmd(modcmd_t cmd, void *arg __unused)
422 1.2 riastrad {
423 1.2 riastrad int error;
424 1.2 riastrad
425 1.2 riastrad switch (cmd) {
426 1.2 riastrad case MODULE_CMD_INIT:
427 1.2 riastrad error = apple_smc_register_device(APPLE_SMC_DEVICE);
428 1.2 riastrad if (error)
429 1.2 riastrad return error;
430 1.2 riastrad #ifdef _MODULE
431 1.2 riastrad error = config_init_component(cfdriver_ioconf_apple_smc_fan,
432 1.2 riastrad cfattach_ioconf_apple_smc_fan,
433 1.2 riastrad cfdata_ioconf_apple_smc_fan);
434 1.2 riastrad if (error) {
435 1.2 riastrad apple_smc_unregister_device(APPLE_SMC_DEVICE);
436 1.2 riastrad return error;
437 1.2 riastrad }
438 1.2 riastrad #endif
439 1.2 riastrad return 0;
440 1.2 riastrad
441 1.2 riastrad case MODULE_CMD_FINI:
442 1.2 riastrad #ifdef _MODULE
443 1.2 riastrad error = config_fini_component(cfdriver_ioconf_apple_smc_fan,
444 1.2 riastrad cfattach_ioconf_apple_smc_fan,
445 1.2 riastrad cfdata_ioconf_apple_smc_fan);
446 1.2 riastrad if (error)
447 1.2 riastrad return error;
448 1.2 riastrad #endif
449 1.2 riastrad apple_smc_unregister_device(APPLE_SMC_DEVICE);
450 1.2 riastrad return 0;
451 1.2 riastrad
452 1.2 riastrad default:
453 1.2 riastrad return ENOTTY;
454 1.2 riastrad }
455 1.2 riastrad }
456