Home | History | Annotate | Line # | Download | only in acpi
thinkpad_acpi.c revision 1.25.2.2
      1  1.25.2.2  uebayasi /* $NetBSD: thinkpad_acpi.c,v 1.25.2.2 2010/11/06 08:08:28 uebayasi Exp $ */
      2       1.1  jmcneill 
      3       1.1  jmcneill /*-
      4       1.1  jmcneill  * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
      5       1.1  jmcneill  * All rights reserved.
      6       1.1  jmcneill  *
      7       1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8       1.1  jmcneill  * modification, are permitted provided that the following conditions
      9       1.1  jmcneill  * are met:
     10       1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11       1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12       1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15       1.1  jmcneill  *
     16       1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1  jmcneill  */
     28       1.1  jmcneill 
     29       1.1  jmcneill #include <sys/cdefs.h>
     30  1.25.2.2  uebayasi __KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.25.2.2 2010/11/06 08:08:28 uebayasi Exp $");
     31       1.1  jmcneill 
     32       1.1  jmcneill #include <sys/param.h>
     33       1.1  jmcneill #include <sys/device.h>
     34  1.25.2.1  uebayasi #include <sys/module.h>
     35  1.25.2.1  uebayasi #include <sys/systm.h>
     36       1.1  jmcneill 
     37      1.24    jruoho #include <dev/acpi/acpireg.h>
     38       1.1  jmcneill #include <dev/acpi/acpivar.h>
     39       1.5  jmcneill #include <dev/acpi/acpi_ecvar.h>
     40       1.1  jmcneill 
     41       1.1  jmcneill #if defined(__i386__) || defined(__amd64__)
     42      1.13  jmcneill #include <dev/isa/isareg.h>
     43       1.1  jmcneill #include <machine/pio.h>
     44       1.1  jmcneill #endif
     45       1.1  jmcneill 
     46      1.24    jruoho #define _COMPONENT		ACPI_RESOURCE_COMPONENT
     47      1.24    jruoho ACPI_MODULE_NAME		("thinkpad_acpi")
     48      1.24    jruoho 
     49      1.16  jmcneill #define	THINKPAD_NTEMPSENSORS	8
     50      1.16  jmcneill #define	THINKPAD_NFANSENSORS	1
     51      1.16  jmcneill #define	THINKPAD_NSENSORS	(THINKPAD_NTEMPSENSORS + THINKPAD_NFANSENSORS)
     52       1.5  jmcneill 
     53       1.1  jmcneill typedef struct thinkpad_softc {
     54       1.1  jmcneill 	device_t		sc_dev;
     55       1.5  jmcneill 	device_t		sc_ecdev;
     56       1.1  jmcneill 	struct acpi_devnode	*sc_node;
     57       1.1  jmcneill 	ACPI_HANDLE		sc_cmoshdl;
     58       1.1  jmcneill 	bool			sc_cmoshdl_valid;
     59       1.1  jmcneill 
     60      1.14    simonb #define	TP_PSW_SLEEP		0
     61       1.1  jmcneill #define	TP_PSW_HIBERNATE	1
     62       1.9  jmcneill #define	TP_PSW_DISPLAY_CYCLE	2
     63       1.9  jmcneill #define	TP_PSW_LOCK_SCREEN	3
     64       1.9  jmcneill #define	TP_PSW_BATTERY_INFO	4
     65       1.9  jmcneill #define	TP_PSW_EJECT_BUTTON	5
     66       1.9  jmcneill #define	TP_PSW_ZOOM_BUTTON	6
     67       1.9  jmcneill #define	TP_PSW_VENDOR_BUTTON	7
     68       1.9  jmcneill #define	TP_PSW_LAST		8
     69       1.9  jmcneill 	struct sysmon_pswitch	sc_smpsw[TP_PSW_LAST];
     70       1.1  jmcneill 	bool			sc_smpsw_valid;
     71       1.5  jmcneill 
     72       1.5  jmcneill 	struct sysmon_envsys	*sc_sme;
     73       1.5  jmcneill 	envsys_data_t		sc_sensor[THINKPAD_NSENSORS];
     74       1.8  jmcneill 
     75       1.8  jmcneill 	int			sc_display_state;
     76       1.1  jmcneill } thinkpad_softc_t;
     77       1.1  jmcneill 
     78       1.1  jmcneill /* Hotkey events */
     79       1.1  jmcneill #define	THINKPAD_NOTIFY_FnF1		0x001
     80       1.1  jmcneill #define	THINKPAD_NOTIFY_LockScreen	0x002
     81       1.1  jmcneill #define	THINKPAD_NOTIFY_BatteryInfo	0x003
     82       1.1  jmcneill #define	THINKPAD_NOTIFY_SleepButton	0x004
     83       1.1  jmcneill #define	THINKPAD_NOTIFY_WirelessSwitch	0x005
     84       1.1  jmcneill #define	THINKPAD_NOTIFY_FnF6		0x006
     85       1.1  jmcneill #define	THINKPAD_NOTIFY_DisplayCycle	0x007
     86       1.1  jmcneill #define	THINKPAD_NOTIFY_PointerSwitch	0x008
     87       1.1  jmcneill #define	THINKPAD_NOTIFY_EjectButton	0x009
     88       1.1  jmcneill #define	THINKPAD_NOTIFY_FnF10		0x00a
     89       1.1  jmcneill #define	THINKPAD_NOTIFY_FnF11		0x00b
     90       1.1  jmcneill #define	THINKPAD_NOTIFY_HibernateButton	0x00c
     91       1.1  jmcneill #define	THINKPAD_NOTIFY_BrightnessUp	0x010
     92       1.1  jmcneill #define	THINKPAD_NOTIFY_BrightnessDown	0x011
     93       1.1  jmcneill #define	THINKPAD_NOTIFY_ThinkLight	0x012
     94       1.1  jmcneill #define	THINKPAD_NOTIFY_Zoom		0x014
     95      1.23    jruoho #define	THINKPAD_NOTIFY_VolumeUp	0x015
     96      1.23    jruoho #define	THINKPAD_NOTIFY_VolumeDown	0x016
     97      1.23    jruoho #define	THINKPAD_NOTIFY_VolumeMute	0x017
     98       1.1  jmcneill #define	THINKPAD_NOTIFY_ThinkVantage	0x018
     99       1.1  jmcneill 
    100       1.1  jmcneill #define	THINKPAD_CMOS_BRIGHTNESS_UP	0x04
    101       1.1  jmcneill #define	THINKPAD_CMOS_BRIGHTNESS_DOWN	0x05
    102       1.1  jmcneill 
    103      1.14    simonb #define	THINKPAD_HKEY_VERSION		0x0100
    104       1.2  jmcneill 
    105       1.8  jmcneill #define	THINKPAD_DISPLAY_LCD		0x01
    106       1.8  jmcneill #define	THINKPAD_DISPLAY_CRT		0x02
    107       1.8  jmcneill #define	THINKPAD_DISPLAY_DVI		0x08
    108       1.8  jmcneill #define	THINKPAD_DISPLAY_ALL \
    109       1.8  jmcneill 	(THINKPAD_DISPLAY_LCD | THINKPAD_DISPLAY_CRT | THINKPAD_DISPLAY_DVI)
    110       1.8  jmcneill 
    111      1.19    cegger static int	thinkpad_match(device_t, cfdata_t, void *);
    112       1.1  jmcneill static void	thinkpad_attach(device_t, device_t, void *);
    113      1.25    jruoho static int	thinkpad_detach(device_t, int);
    114       1.1  jmcneill 
    115       1.1  jmcneill static ACPI_STATUS thinkpad_mask_init(thinkpad_softc_t *, uint32_t);
    116  1.25.2.1  uebayasi static void	thinkpad_notify_handler(ACPI_HANDLE, uint32_t, void *);
    117       1.4  jmcneill static void	thinkpad_get_hotkeys(void *);
    118       1.1  jmcneill 
    119      1.16  jmcneill static void	thinkpad_sensors_init(thinkpad_softc_t *);
    120      1.16  jmcneill static void	thinkpad_sensors_refresh(struct sysmon_envsys *, envsys_data_t *);
    121       1.5  jmcneill static void	thinkpad_temp_refresh(struct sysmon_envsys *, envsys_data_t *);
    122      1.16  jmcneill static void	thinkpad_fan_refresh(struct sysmon_envsys *, envsys_data_t *);
    123       1.5  jmcneill 
    124       1.6  jmcneill static void	thinkpad_wireless_toggle(thinkpad_softc_t *);
    125       1.6  jmcneill 
    126  1.25.2.1  uebayasi static bool	thinkpad_resume(device_t, const pmf_qual_t *);
    127       1.1  jmcneill static void	thinkpad_brightness_up(device_t);
    128       1.1  jmcneill static void	thinkpad_brightness_down(device_t);
    129       1.1  jmcneill static uint8_t	thinkpad_brightness_read(thinkpad_softc_t *sc);
    130       1.1  jmcneill static void	thinkpad_cmos(thinkpad_softc_t *, uint8_t);
    131       1.1  jmcneill 
    132       1.1  jmcneill CFATTACH_DECL_NEW(thinkpad, sizeof(thinkpad_softc_t),
    133      1.25    jruoho     thinkpad_match, thinkpad_attach, thinkpad_detach, NULL);
    134       1.1  jmcneill 
    135       1.1  jmcneill static const char * const thinkpad_ids[] = {
    136       1.1  jmcneill 	"IBM0068",
    137       1.1  jmcneill 	NULL
    138       1.1  jmcneill };
    139       1.1  jmcneill 
    140       1.1  jmcneill static int
    141      1.19    cegger thinkpad_match(device_t parent, cfdata_t match, void *opaque)
    142       1.1  jmcneill {
    143       1.1  jmcneill 	struct acpi_attach_args *aa = (struct acpi_attach_args *)opaque;
    144       1.2  jmcneill 	ACPI_INTEGER ver;
    145       1.1  jmcneill 
    146       1.1  jmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    147       1.1  jmcneill 		return 0;
    148       1.1  jmcneill 
    149       1.1  jmcneill 	if (!acpi_match_hid(aa->aa_node->ad_devinfo, thinkpad_ids))
    150       1.1  jmcneill 		return 0;
    151       1.1  jmcneill 
    152       1.2  jmcneill 	/* We only support hotkey version 0x0100 */
    153       1.3  jmcneill 	if (ACPI_FAILURE(acpi_eval_integer(aa->aa_node->ad_handle, "MHKV",
    154       1.3  jmcneill 	    &ver)))
    155       1.2  jmcneill 		return 0;
    156       1.2  jmcneill 
    157       1.2  jmcneill 	if (ver != THINKPAD_HKEY_VERSION)
    158       1.2  jmcneill 		return 0;
    159       1.2  jmcneill 
    160       1.1  jmcneill 	/* Cool, looks like we're good to go */
    161       1.1  jmcneill 	return 1;
    162       1.1  jmcneill }
    163       1.1  jmcneill 
    164       1.1  jmcneill static void
    165       1.1  jmcneill thinkpad_attach(device_t parent, device_t self, void *opaque)
    166       1.1  jmcneill {
    167       1.1  jmcneill 	thinkpad_softc_t *sc = device_private(self);
    168       1.1  jmcneill 	struct acpi_attach_args *aa = (struct acpi_attach_args *)opaque;
    169       1.9  jmcneill 	struct sysmon_pswitch *psw;
    170       1.5  jmcneill 	device_t curdev;
    171      1.20    dyoung 	deviter_t di;
    172       1.1  jmcneill 	ACPI_STATUS rv;
    173       1.1  jmcneill 	ACPI_INTEGER val;
    174       1.9  jmcneill 	int i;
    175       1.1  jmcneill 
    176       1.1  jmcneill 	sc->sc_node = aa->aa_node;
    177       1.1  jmcneill 	sc->sc_dev = self;
    178       1.8  jmcneill 	sc->sc_display_state = THINKPAD_DISPLAY_LCD;
    179       1.1  jmcneill 
    180       1.1  jmcneill 	aprint_naive("\n");
    181       1.1  jmcneill 	aprint_normal("\n");
    182       1.1  jmcneill 
    183       1.1  jmcneill 	/* T61 uses \UCMS method for issuing CMOS commands */
    184       1.1  jmcneill 	rv = AcpiGetHandle(NULL, "\\UCMS", &sc->sc_cmoshdl);
    185       1.1  jmcneill 	if (ACPI_FAILURE(rv))
    186       1.1  jmcneill 		sc->sc_cmoshdl_valid = false;
    187       1.1  jmcneill 	else {
    188      1.18  jmcneill 		aprint_debug_dev(self, "using CMOS at \\UCMS\n");
    189       1.1  jmcneill 		sc->sc_cmoshdl_valid = true;
    190       1.1  jmcneill 	}
    191       1.1  jmcneill 
    192       1.5  jmcneill 	sc->sc_ecdev = NULL;
    193      1.20    dyoung 	for (curdev = deviter_first(&di, DEVITER_F_ROOT_FIRST);
    194      1.20    dyoung 	     curdev != NULL; curdev = deviter_next(&di))
    195       1.5  jmcneill 		if (device_is_a(curdev, "acpiecdt") ||
    196       1.5  jmcneill 		    device_is_a(curdev, "acpiec")) {
    197       1.5  jmcneill 			sc->sc_ecdev = curdev;
    198       1.5  jmcneill 			break;
    199       1.5  jmcneill 		}
    200      1.20    dyoung 	deviter_release(&di);
    201      1.20    dyoung 
    202       1.5  jmcneill 	if (sc->sc_ecdev)
    203      1.18  jmcneill 		aprint_debug_dev(self, "using EC at %s\n",
    204       1.5  jmcneill 		    device_xname(sc->sc_ecdev));
    205       1.5  jmcneill 
    206       1.1  jmcneill 	/* Get the supported event mask */
    207       1.1  jmcneill 	rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKA", &val);
    208       1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    209       1.1  jmcneill 		aprint_error_dev(self, "couldn't evaluate MHKA: %s\n",
    210       1.1  jmcneill 		    AcpiFormatException(rv));
    211       1.1  jmcneill 		goto fail;
    212       1.1  jmcneill 	}
    213       1.1  jmcneill 
    214       1.1  jmcneill 	/* Enable all supported events */
    215       1.1  jmcneill 	rv = thinkpad_mask_init(sc, val);
    216       1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    217       1.1  jmcneill 		aprint_error_dev(self, "couldn't set event mask: %s\n",
    218       1.1  jmcneill 		    AcpiFormatException(rv));
    219       1.1  jmcneill 		goto fail;
    220       1.1  jmcneill 	}
    221       1.1  jmcneill 
    222  1.25.2.1  uebayasi 	(void)acpi_register_notify(sc->sc_node, thinkpad_notify_handler);
    223       1.1  jmcneill 
    224       1.5  jmcneill 	/* Register power switches with sysmon */
    225       1.9  jmcneill 	psw = sc->sc_smpsw;
    226       1.1  jmcneill 	sc->sc_smpsw_valid = true;
    227       1.1  jmcneill 
    228       1.9  jmcneill 	psw[TP_PSW_SLEEP].smpsw_name = device_xname(self);
    229       1.9  jmcneill 	psw[TP_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP;
    230       1.1  jmcneill #if notyet
    231       1.9  jmcneill 	psw[TP_PSW_HIBERNATE].smpsw_name = device_xname(self);
    232       1.9  jmcneill 	mpsw[TP_PSW_HIBERNATE].smpsw_type = PSWITCH_TYPE_HIBERNATE;
    233       1.1  jmcneill #endif
    234       1.9  jmcneill 	for (i = TP_PSW_DISPLAY_CYCLE; i < TP_PSW_LAST; i++)
    235       1.9  jmcneill 		sc->sc_smpsw[i].smpsw_type = PSWITCH_TYPE_HOTKEY;
    236       1.9  jmcneill 	psw[TP_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE;
    237       1.9  jmcneill 	psw[TP_PSW_LOCK_SCREEN].smpsw_name = PSWITCH_HK_LOCK_SCREEN;
    238       1.9  jmcneill 	psw[TP_PSW_BATTERY_INFO].smpsw_name = PSWITCH_HK_BATTERY_INFO;
    239       1.9  jmcneill 	psw[TP_PSW_EJECT_BUTTON].smpsw_name = PSWITCH_HK_EJECT_BUTTON;
    240       1.9  jmcneill 	psw[TP_PSW_ZOOM_BUTTON].smpsw_name = PSWITCH_HK_ZOOM_BUTTON;
    241       1.9  jmcneill 	psw[TP_PSW_VENDOR_BUTTON].smpsw_name = PSWITCH_HK_VENDOR_BUTTON;
    242       1.9  jmcneill 
    243       1.9  jmcneill 	for (i = 0; i < TP_PSW_LAST; i++) {
    244       1.9  jmcneill 		/* not supported yet */
    245       1.9  jmcneill 		if (i == TP_PSW_HIBERNATE)
    246       1.9  jmcneill 			continue;
    247       1.9  jmcneill 		if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) {
    248       1.9  jmcneill 			aprint_error_dev(self,
    249       1.9  jmcneill 			    "couldn't register with sysmon\n");
    250       1.9  jmcneill 			sc->sc_smpsw_valid = false;
    251       1.9  jmcneill 			break;
    252       1.9  jmcneill 		}
    253       1.1  jmcneill 	}
    254       1.1  jmcneill 
    255      1.16  jmcneill 	/* Register temperature and fan sensors with envsys */
    256      1.16  jmcneill 	thinkpad_sensors_init(sc);
    257       1.5  jmcneill 
    258       1.1  jmcneill fail:
    259      1.11  jmcneill 	if (!pmf_device_register(self, NULL, thinkpad_resume))
    260       1.1  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    261       1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP,
    262       1.1  jmcneill 	    thinkpad_brightness_up, true))
    263       1.1  jmcneill 		aprint_error_dev(self, "couldn't register event handler\n");
    264       1.1  jmcneill 	if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_DOWN,
    265       1.1  jmcneill 	    thinkpad_brightness_down, true))
    266       1.1  jmcneill 		aprint_error_dev(self, "couldn't register event handler\n");
    267       1.1  jmcneill }
    268       1.1  jmcneill 
    269      1.25    jruoho static int
    270      1.25    jruoho thinkpad_detach(device_t self, int flags)
    271      1.25    jruoho {
    272      1.25    jruoho 	struct thinkpad_softc *sc = device_private(self);
    273      1.25    jruoho 	int i;
    274      1.25    jruoho 
    275  1.25.2.1  uebayasi 	acpi_deregister_notify(sc->sc_node);
    276      1.25    jruoho 
    277      1.25    jruoho 	for (i = 0; i < TP_PSW_LAST; i++)
    278      1.25    jruoho 		sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
    279      1.25    jruoho 
    280      1.25    jruoho 	if (sc->sc_sme != NULL)
    281      1.25    jruoho 		sysmon_envsys_unregister(sc->sc_sme);
    282      1.25    jruoho 
    283      1.25    jruoho 	pmf_device_deregister(self);
    284      1.25    jruoho 
    285      1.25    jruoho 	pmf_event_deregister(self, PMFE_DISPLAY_BRIGHTNESS_UP,
    286      1.25    jruoho 	    thinkpad_brightness_up, true);
    287      1.25    jruoho 
    288      1.25    jruoho 	pmf_event_deregister(self, PMFE_DISPLAY_BRIGHTNESS_DOWN,
    289      1.25    jruoho 	    thinkpad_brightness_down, true);
    290      1.25    jruoho 
    291      1.25    jruoho 	return 0;
    292      1.25    jruoho }
    293      1.25    jruoho 
    294       1.1  jmcneill static void
    295  1.25.2.1  uebayasi thinkpad_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
    296       1.1  jmcneill {
    297  1.25.2.1  uebayasi 	device_t self = opaque;
    298  1.25.2.1  uebayasi 	thinkpad_softc_t *sc;
    299  1.25.2.1  uebayasi 
    300  1.25.2.1  uebayasi 	sc = device_private(self);
    301  1.25.2.1  uebayasi 
    302       1.1  jmcneill 	if (notify != 0x80) {
    303       1.1  jmcneill 		aprint_debug_dev(self, "unknown notify 0x%02x\n", notify);
    304       1.1  jmcneill 		return;
    305       1.1  jmcneill 	}
    306       1.1  jmcneill 
    307  1.25.2.1  uebayasi 	(void)AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
    308       1.4  jmcneill }
    309       1.4  jmcneill 
    310       1.4  jmcneill static void
    311       1.4  jmcneill thinkpad_get_hotkeys(void *opaque)
    312       1.4  jmcneill {
    313       1.4  jmcneill 	thinkpad_softc_t *sc = (thinkpad_softc_t *)opaque;
    314       1.4  jmcneill 	device_t self = sc->sc_dev;
    315       1.4  jmcneill 	ACPI_STATUS rv;
    316       1.4  jmcneill 	ACPI_INTEGER val;
    317       1.4  jmcneill 	int type, event;
    318       1.4  jmcneill 
    319       1.2  jmcneill 	for (;;) {
    320       1.2  jmcneill 		rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKP", &val);
    321       1.2  jmcneill 		if (ACPI_FAILURE(rv)) {
    322       1.2  jmcneill 			aprint_error_dev(self, "couldn't evaluate MHKP: %s\n",
    323       1.2  jmcneill 			    AcpiFormatException(rv));
    324       1.2  jmcneill 			return;
    325       1.2  jmcneill 		}
    326       1.2  jmcneill 
    327       1.2  jmcneill 		if (val == 0)
    328       1.2  jmcneill 			return;
    329       1.2  jmcneill 
    330       1.2  jmcneill 		type = (val & 0xf000) >> 12;
    331       1.2  jmcneill 		event = val & 0x0fff;
    332       1.2  jmcneill 
    333       1.2  jmcneill 		if (type != 1)
    334       1.2  jmcneill 			/* Only type 1 events are supported for now */
    335       1.2  jmcneill 			continue;
    336       1.2  jmcneill 
    337       1.2  jmcneill 		switch (event) {
    338       1.2  jmcneill 		case THINKPAD_NOTIFY_BrightnessUp:
    339       1.2  jmcneill 			thinkpad_brightness_up(self);
    340       1.2  jmcneill 			break;
    341       1.2  jmcneill 		case THINKPAD_NOTIFY_BrightnessDown:
    342       1.2  jmcneill 			thinkpad_brightness_down(self);
    343       1.2  jmcneill 			break;
    344       1.6  jmcneill 		case THINKPAD_NOTIFY_WirelessSwitch:
    345       1.6  jmcneill 			thinkpad_wireless_toggle(sc);
    346       1.6  jmcneill 			break;
    347       1.2  jmcneill 		case THINKPAD_NOTIFY_SleepButton:
    348       1.2  jmcneill 			if (sc->sc_smpsw_valid == false)
    349       1.2  jmcneill 				break;
    350       1.2  jmcneill 			sysmon_pswitch_event(&sc->sc_smpsw[TP_PSW_SLEEP],
    351       1.2  jmcneill 			    PSWITCH_EVENT_PRESSED);
    352       1.2  jmcneill 			break;
    353       1.2  jmcneill 		case THINKPAD_NOTIFY_HibernateButton:
    354       1.1  jmcneill #if notyet
    355       1.2  jmcneill 			if (sc->sc_smpsw_valid == false)
    356       1.2  jmcneill 				break;
    357       1.2  jmcneill 			sysmon_pswitch_event(&sc->sc_smpsw[TP_PSW_HIBERNATE],
    358       1.2  jmcneill 			    PSWITCH_EVENT_PRESSED);
    359       1.6  jmcneill #endif
    360       1.1  jmcneill 			break;
    361       1.9  jmcneill 		case THINKPAD_NOTIFY_DisplayCycle:
    362       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    363       1.9  jmcneill 				break;
    364       1.9  jmcneill 			sysmon_pswitch_event(
    365       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_DISPLAY_CYCLE],
    366       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    367       1.9  jmcneill 			break;
    368       1.2  jmcneill 		case THINKPAD_NOTIFY_LockScreen:
    369       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    370       1.9  jmcneill 				break;
    371       1.9  jmcneill 			sysmon_pswitch_event(
    372       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_LOCK_SCREEN],
    373       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    374       1.9  jmcneill 			break;
    375       1.2  jmcneill 		case THINKPAD_NOTIFY_BatteryInfo:
    376       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    377       1.9  jmcneill 				break;
    378       1.9  jmcneill 			sysmon_pswitch_event(
    379       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_BATTERY_INFO],
    380       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    381       1.9  jmcneill 			break;
    382       1.9  jmcneill 		case THINKPAD_NOTIFY_EjectButton:
    383       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    384       1.9  jmcneill 				break;
    385       1.9  jmcneill 			sysmon_pswitch_event(
    386       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_EJECT_BUTTON],
    387       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    388       1.9  jmcneill 			break;
    389       1.9  jmcneill 		case THINKPAD_NOTIFY_Zoom:
    390       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    391       1.9  jmcneill 				break;
    392       1.9  jmcneill 			sysmon_pswitch_event(
    393       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_ZOOM_BUTTON],
    394       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    395       1.9  jmcneill 			break;
    396       1.9  jmcneill 		case THINKPAD_NOTIFY_ThinkVantage:
    397       1.9  jmcneill 			if (sc->sc_smpsw_valid == false)
    398       1.9  jmcneill 				break;
    399       1.9  jmcneill 			sysmon_pswitch_event(
    400       1.9  jmcneill 			    &sc->sc_smpsw[TP_PSW_VENDOR_BUTTON],
    401       1.9  jmcneill 			    PSWITCH_EVENT_PRESSED);
    402       1.9  jmcneill 			break;
    403       1.9  jmcneill 		case THINKPAD_NOTIFY_FnF1:
    404       1.2  jmcneill 		case THINKPAD_NOTIFY_FnF6:
    405       1.2  jmcneill 		case THINKPAD_NOTIFY_PointerSwitch:
    406       1.2  jmcneill 		case THINKPAD_NOTIFY_FnF10:
    407       1.2  jmcneill 		case THINKPAD_NOTIFY_FnF11:
    408       1.2  jmcneill 		case THINKPAD_NOTIFY_ThinkLight:
    409      1.23    jruoho 		case THINKPAD_NOTIFY_VolumeUp:
    410      1.23    jruoho 		case THINKPAD_NOTIFY_VolumeDown:
    411      1.23    jruoho 		case THINKPAD_NOTIFY_VolumeMute:
    412       1.2  jmcneill 			/* XXXJDM we should deliver hotkeys as keycodes */
    413       1.2  jmcneill 			break;
    414       1.2  jmcneill 		default:
    415       1.2  jmcneill 			aprint_debug_dev(self, "notify event 0x%03x\n", event);
    416       1.2  jmcneill 			break;
    417       1.2  jmcneill 		}
    418       1.1  jmcneill 	}
    419       1.1  jmcneill }
    420       1.1  jmcneill 
    421       1.1  jmcneill static ACPI_STATUS
    422       1.1  jmcneill thinkpad_mask_init(thinkpad_softc_t *sc, uint32_t mask)
    423       1.1  jmcneill {
    424       1.1  jmcneill 	ACPI_OBJECT param[2];
    425       1.1  jmcneill 	ACPI_OBJECT_LIST params;
    426       1.1  jmcneill 	ACPI_STATUS rv;
    427       1.1  jmcneill 	int i;
    428       1.1  jmcneill 
    429       1.1  jmcneill 	/* Update hotkey mask */
    430       1.1  jmcneill 	params.Count = 2;
    431       1.1  jmcneill 	params.Pointer = param;
    432       1.1  jmcneill 	param[0].Type = param[1].Type = ACPI_TYPE_INTEGER;
    433       1.1  jmcneill 
    434       1.1  jmcneill 	for (i = 0; i < 32; i++) {
    435       1.1  jmcneill 		param[0].Integer.Value = i + 1;
    436       1.1  jmcneill 		param[1].Integer.Value = (((1 << i) & mask) != 0);
    437       1.1  jmcneill 
    438       1.1  jmcneill 		rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "MHKM",
    439       1.1  jmcneill 		    &params, NULL);
    440       1.1  jmcneill 		if (ACPI_FAILURE(rv))
    441       1.1  jmcneill 			return rv;
    442       1.1  jmcneill 	}
    443       1.1  jmcneill 
    444       1.1  jmcneill 	/* Enable hotkey events */
    445      1.21    cegger 	rv = acpi_eval_set_integer(sc->sc_node->ad_handle, "MHKC", 1);
    446       1.1  jmcneill 	if (ACPI_FAILURE(rv)) {
    447       1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "couldn't enable hotkeys: %s\n",
    448       1.1  jmcneill 		    AcpiFormatException(rv));
    449       1.1  jmcneill 		return rv;
    450       1.1  jmcneill 	}
    451       1.1  jmcneill 
    452       1.4  jmcneill 	/* Claim ownership of brightness control */
    453      1.21    cegger 	(void)acpi_eval_set_integer(sc->sc_node->ad_handle, "PWMS", 0);
    454       1.4  jmcneill 
    455       1.1  jmcneill 	return AE_OK;
    456       1.1  jmcneill }
    457       1.1  jmcneill 
    458       1.5  jmcneill static void
    459      1.16  jmcneill thinkpad_sensors_init(thinkpad_softc_t *sc)
    460       1.5  jmcneill {
    461      1.25    jruoho 	int i, j;
    462       1.5  jmcneill 
    463       1.5  jmcneill 	if (sc->sc_ecdev == NULL)
    464       1.5  jmcneill 		return;	/* no chance of this working */
    465       1.5  jmcneill 
    466       1.5  jmcneill 	sc->sc_sme = sysmon_envsys_create();
    467      1.25    jruoho 
    468      1.25    jruoho 	for (i = j = 0; i < THINKPAD_NTEMPSENSORS; i++) {
    469      1.25    jruoho 
    470       1.5  jmcneill 		sc->sc_sensor[i].units = ENVSYS_STEMP;
    471       1.5  jmcneill 
    472      1.25    jruoho 		(void)snprintf(sc->sc_sensor[i].desc,
    473      1.25    jruoho 		    sizeof(sc->sc_sensor[i].desc), "TMP%d", i);
    474      1.25    jruoho 
    475      1.25    jruoho 		if (sysmon_envsys_sensor_attach(sc->sc_sme,
    476      1.25    jruoho 			&sc->sc_sensor[i]) != 0)
    477      1.25    jruoho 			goto fail;
    478      1.25    jruoho 	}
    479      1.25    jruoho 
    480      1.25    jruoho 	for (i = THINKPAD_NTEMPSENSORS; i < THINKPAD_NSENSORS; i++, j++) {
    481      1.25    jruoho 
    482      1.16  jmcneill 		sc->sc_sensor[i].units = ENVSYS_SFANRPM;
    483      1.16  jmcneill 
    484      1.25    jruoho 		(void)snprintf(sc->sc_sensor[i].desc,
    485      1.25    jruoho 		    sizeof(sc->sc_sensor[i].desc), "FAN%d", j);
    486      1.25    jruoho 
    487      1.25    jruoho 		if (sysmon_envsys_sensor_attach(sc->sc_sme,
    488      1.25    jruoho 			&sc->sc_sensor[i]) != 0)
    489      1.25    jruoho 			goto fail;
    490      1.16  jmcneill 	}
    491       1.5  jmcneill 
    492       1.5  jmcneill 	sc->sc_sme->sme_name = device_xname(sc->sc_dev);
    493       1.5  jmcneill 	sc->sc_sme->sme_cookie = sc;
    494      1.16  jmcneill 	sc->sc_sme->sme_refresh = thinkpad_sensors_refresh;
    495       1.5  jmcneill 
    496      1.25    jruoho 	if (sysmon_envsys_register(sc->sc_sme) != 0)
    497      1.25    jruoho 		goto fail;
    498      1.25    jruoho 
    499      1.25    jruoho 	return;
    500      1.25    jruoho 
    501      1.25    jruoho fail:
    502      1.25    jruoho 	aprint_error_dev(sc->sc_dev, "failed to initialize sysmon\n");
    503      1.25    jruoho 	sysmon_envsys_destroy(sc->sc_sme);
    504      1.25    jruoho 	sc->sc_sme = NULL;
    505       1.5  jmcneill }
    506       1.5  jmcneill 
    507       1.5  jmcneill static void
    508      1.16  jmcneill thinkpad_sensors_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    509      1.16  jmcneill {
    510      1.16  jmcneill 	switch (edata->units) {
    511      1.16  jmcneill 	case ENVSYS_STEMP:
    512      1.16  jmcneill 		thinkpad_temp_refresh(sme, edata);
    513      1.16  jmcneill 		break;
    514      1.16  jmcneill 	case ENVSYS_SFANRPM:
    515      1.16  jmcneill 		thinkpad_fan_refresh(sme, edata);
    516      1.16  jmcneill 		break;
    517      1.16  jmcneill 	default:
    518      1.16  jmcneill 		break;
    519      1.16  jmcneill 	}
    520      1.16  jmcneill }
    521      1.16  jmcneill 
    522      1.16  jmcneill static void
    523       1.5  jmcneill thinkpad_temp_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    524       1.5  jmcneill {
    525       1.5  jmcneill 	thinkpad_softc_t *sc = sme->sme_cookie;
    526       1.5  jmcneill 	char sname[5] = "TMP?";
    527       1.5  jmcneill 	ACPI_INTEGER val;
    528       1.5  jmcneill 	ACPI_STATUS rv;
    529       1.5  jmcneill 	int temp;
    530       1.5  jmcneill 
    531       1.5  jmcneill 	sname[3] = '0' + edata->sensor;
    532       1.5  jmcneill 	rv = acpi_eval_integer(acpiec_get_handle(sc->sc_ecdev), sname, &val);
    533       1.5  jmcneill 	if (ACPI_FAILURE(rv)) {
    534       1.5  jmcneill 		edata->state = ENVSYS_SINVALID;
    535       1.5  jmcneill 		return;
    536       1.5  jmcneill 	}
    537       1.5  jmcneill 	temp = (int)val;
    538       1.5  jmcneill 	if (temp > 127 || temp < -127) {
    539       1.5  jmcneill 		edata->state = ENVSYS_SINVALID;
    540       1.5  jmcneill 		return;
    541       1.5  jmcneill 	}
    542       1.5  jmcneill 
    543       1.5  jmcneill 	edata->value_cur = temp * 1000000 + 273150000;
    544       1.5  jmcneill 	edata->state = ENVSYS_SVALID;
    545       1.5  jmcneill }
    546       1.5  jmcneill 
    547       1.6  jmcneill static void
    548      1.16  jmcneill thinkpad_fan_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    549      1.16  jmcneill {
    550      1.16  jmcneill 	thinkpad_softc_t *sc = sme->sme_cookie;
    551      1.16  jmcneill 	ACPI_INTEGER lo;
    552      1.16  jmcneill 	ACPI_INTEGER hi;
    553      1.16  jmcneill 	ACPI_STATUS rv;
    554      1.16  jmcneill 	int rpm;
    555      1.16  jmcneill 
    556      1.16  jmcneill 	/*
    557      1.16  jmcneill 	 * Read the low byte first to avoid a firmware bug.
    558      1.16  jmcneill 	 */
    559      1.16  jmcneill 	rv = acpiec_bus_read(sc->sc_ecdev, 0x84, &lo, 1);
    560      1.16  jmcneill 	if (ACPI_FAILURE(rv)) {
    561      1.16  jmcneill 		edata->state = ENVSYS_SINVALID;
    562      1.16  jmcneill 		return;
    563      1.16  jmcneill 	}
    564      1.16  jmcneill 	rv = acpiec_bus_read(sc->sc_ecdev, 0x85, &hi, 1);
    565      1.16  jmcneill 	if (ACPI_FAILURE(rv)) {
    566      1.16  jmcneill 		edata->state = ENVSYS_SINVALID;
    567      1.16  jmcneill 		return;
    568      1.16  jmcneill 	}
    569      1.16  jmcneill 	rpm = ((((int)hi) << 8) | ((int)lo));
    570      1.16  jmcneill 	if (rpm < 0) {
    571      1.16  jmcneill 		edata->state = ENVSYS_SINVALID;
    572      1.16  jmcneill 		return;
    573      1.16  jmcneill 	}
    574      1.16  jmcneill 
    575      1.16  jmcneill 	edata->value_cur = rpm;
    576      1.16  jmcneill 	if (rpm < edata->value_min || edata->value_min == -1)
    577      1.16  jmcneill 		edata->value_min = rpm;
    578      1.16  jmcneill 	if (rpm > edata->value_max || edata->value_max == -1)
    579      1.16  jmcneill 		edata->value_max = rpm;
    580      1.16  jmcneill 	edata->state = ENVSYS_SVALID;
    581      1.16  jmcneill }
    582      1.16  jmcneill 
    583      1.16  jmcneill static void
    584       1.6  jmcneill thinkpad_wireless_toggle(thinkpad_softc_t *sc)
    585       1.6  jmcneill {
    586       1.7  jmcneill 	/* Ignore return value, as the hardware may not support bluetooth */
    587       1.6  jmcneill 	(void)AcpiEvaluateObject(sc->sc_node->ad_handle, "BTGL", NULL, NULL);
    588       1.6  jmcneill }
    589       1.6  jmcneill 
    590       1.1  jmcneill static uint8_t
    591       1.1  jmcneill thinkpad_brightness_read(thinkpad_softc_t *sc)
    592       1.1  jmcneill {
    593       1.1  jmcneill #if defined(__i386__) || defined(__amd64__)
    594       1.1  jmcneill 	/*
    595       1.1  jmcneill 	 * We have two ways to get the current brightness -- either via
    596       1.1  jmcneill 	 * magic RTC registers, or using the EC. Since I don't dare mess
    597       1.1  jmcneill 	 * with the EC, and Thinkpads are x86-only, this will have to do
    598       1.1  jmcneill 	 * for now.
    599       1.1  jmcneill 	 */
    600      1.13  jmcneill 	outb(IO_RTC, 0x6c);
    601      1.13  jmcneill 	return inb(IO_RTC+1) & 7;
    602       1.1  jmcneill #else
    603       1.1  jmcneill 	return 0;
    604       1.1  jmcneill #endif
    605       1.1  jmcneill }
    606       1.1  jmcneill 
    607       1.1  jmcneill static void
    608       1.1  jmcneill thinkpad_brightness_up(device_t self)
    609       1.1  jmcneill {
    610       1.1  jmcneill 	thinkpad_softc_t *sc = device_private(self);
    611       1.1  jmcneill 
    612       1.1  jmcneill 	if (thinkpad_brightness_read(sc) == 7)
    613       1.1  jmcneill 		return;
    614       1.1  jmcneill 	thinkpad_cmos(sc, THINKPAD_CMOS_BRIGHTNESS_UP);
    615       1.1  jmcneill }
    616       1.1  jmcneill 
    617       1.1  jmcneill static void
    618       1.1  jmcneill thinkpad_brightness_down(device_t self)
    619       1.1  jmcneill {
    620       1.1  jmcneill 	thinkpad_softc_t *sc = device_private(self);
    621       1.1  jmcneill 
    622       1.1  jmcneill 	if (thinkpad_brightness_read(sc) == 0)
    623       1.1  jmcneill 		return;
    624       1.1  jmcneill 	thinkpad_cmos(sc, THINKPAD_CMOS_BRIGHTNESS_DOWN);
    625       1.1  jmcneill }
    626       1.1  jmcneill 
    627       1.1  jmcneill static void
    628       1.1  jmcneill thinkpad_cmos(thinkpad_softc_t *sc, uint8_t cmd)
    629       1.1  jmcneill {
    630       1.1  jmcneill 	ACPI_STATUS rv;
    631       1.1  jmcneill 
    632       1.1  jmcneill 	if (sc->sc_cmoshdl_valid == false)
    633       1.1  jmcneill 		return;
    634       1.1  jmcneill 
    635      1.21    cegger 	rv = acpi_eval_set_integer(sc->sc_cmoshdl, NULL, cmd);
    636       1.1  jmcneill 	if (ACPI_FAILURE(rv))
    637       1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "couldn't evalute CMOS: %s\n",
    638       1.1  jmcneill 		    AcpiFormatException(rv));
    639       1.1  jmcneill }
    640      1.11  jmcneill 
    641      1.11  jmcneill static bool
    642  1.25.2.1  uebayasi thinkpad_resume(device_t dv, const pmf_qual_t *qual)
    643      1.11  jmcneill {
    644      1.11  jmcneill 	ACPI_STATUS rv;
    645      1.11  jmcneill 	ACPI_HANDLE pubs;
    646      1.11  jmcneill 
    647      1.11  jmcneill 	rv = AcpiGetHandle(NULL, "\\_SB.PCI0.LPC.EC.PUBS", &pubs);
    648      1.11  jmcneill 	if (ACPI_FAILURE(rv))
    649      1.11  jmcneill 		return true;	/* not fatal */
    650      1.11  jmcneill 
    651      1.11  jmcneill 	rv = AcpiEvaluateObject(pubs, "_ON", NULL, NULL);
    652      1.11  jmcneill 	if (ACPI_FAILURE(rv))
    653      1.11  jmcneill 		aprint_error_dev(dv, "failed to execute PUBS._ON: %s\n",
    654      1.11  jmcneill 		    AcpiFormatException(rv));
    655      1.11  jmcneill 
    656      1.11  jmcneill 	return true;
    657      1.11  jmcneill }
    658  1.25.2.1  uebayasi 
    659  1.25.2.1  uebayasi #ifdef _MODULE
    660  1.25.2.1  uebayasi 
    661  1.25.2.1  uebayasi MODULE(MODULE_CLASS_DRIVER, thinkpad, NULL);
    662  1.25.2.1  uebayasi CFDRIVER_DECL(thinkpad, DV_DULL, NULL);
    663  1.25.2.1  uebayasi 
    664  1.25.2.1  uebayasi static int thinkpadloc[] = { -1 };
    665  1.25.2.1  uebayasi extern struct cfattach thinkpad_ca;
    666  1.25.2.1  uebayasi 
    667  1.25.2.1  uebayasi static struct cfparent acpiparent = {
    668  1.25.2.1  uebayasi 	"acpinodebus", NULL, DVUNIT_ANY
    669  1.25.2.1  uebayasi };
    670  1.25.2.1  uebayasi 
    671  1.25.2.1  uebayasi static struct cfdata thinkpad_cfdata[] = {
    672  1.25.2.1  uebayasi 	{
    673  1.25.2.1  uebayasi 		.cf_name = "thinkpad",
    674  1.25.2.1  uebayasi 		.cf_atname = "thinkpad",
    675  1.25.2.1  uebayasi 		.cf_unit = 0,
    676  1.25.2.1  uebayasi 		.cf_fstate = FSTATE_STAR,
    677  1.25.2.1  uebayasi 		.cf_loc = thinkpadloc,
    678  1.25.2.1  uebayasi 		.cf_flags = 0,
    679  1.25.2.1  uebayasi 		.cf_pspec = &acpiparent,
    680  1.25.2.1  uebayasi 	},
    681  1.25.2.1  uebayasi 
    682  1.25.2.2  uebayasi 	{ NULL, NULL, 0, 0, NULL, 0, NULL }
    683  1.25.2.1  uebayasi };
    684  1.25.2.1  uebayasi 
    685  1.25.2.1  uebayasi static int
    686  1.25.2.1  uebayasi thinkpad_modcmd(modcmd_t cmd, void *opaque)
    687  1.25.2.1  uebayasi {
    688  1.25.2.1  uebayasi 	int err;
    689  1.25.2.1  uebayasi 
    690  1.25.2.1  uebayasi 	switch (cmd) {
    691  1.25.2.1  uebayasi 
    692  1.25.2.1  uebayasi 	case MODULE_CMD_INIT:
    693  1.25.2.1  uebayasi 
    694  1.25.2.1  uebayasi 		err = config_cfdriver_attach(&thinkpad_cd);
    695  1.25.2.1  uebayasi 
    696  1.25.2.1  uebayasi 		if (err != 0)
    697  1.25.2.1  uebayasi 			return err;
    698  1.25.2.1  uebayasi 
    699  1.25.2.1  uebayasi 		err = config_cfattach_attach("thinkpad", &thinkpad_ca);
    700  1.25.2.1  uebayasi 
    701  1.25.2.1  uebayasi 		if (err != 0) {
    702  1.25.2.1  uebayasi 			config_cfdriver_detach(&thinkpad_cd);
    703  1.25.2.1  uebayasi 			return err;
    704  1.25.2.1  uebayasi 		}
    705  1.25.2.1  uebayasi 
    706  1.25.2.1  uebayasi 		err = config_cfdata_attach(thinkpad_cfdata, 1);
    707  1.25.2.1  uebayasi 
    708  1.25.2.1  uebayasi 		if (err != 0) {
    709  1.25.2.1  uebayasi 			config_cfattach_detach("thinkpad", &thinkpad_ca);
    710  1.25.2.1  uebayasi 			config_cfdriver_detach(&thinkpad_cd);
    711  1.25.2.1  uebayasi 			return err;
    712  1.25.2.1  uebayasi 		}
    713  1.25.2.1  uebayasi 
    714  1.25.2.1  uebayasi 		return 0;
    715  1.25.2.1  uebayasi 
    716  1.25.2.1  uebayasi 	case MODULE_CMD_FINI:
    717  1.25.2.1  uebayasi 
    718  1.25.2.1  uebayasi 		err = config_cfdata_detach(thinkpad_cfdata);
    719  1.25.2.1  uebayasi 
    720  1.25.2.1  uebayasi 		if (err != 0)
    721  1.25.2.1  uebayasi 			return err;
    722  1.25.2.1  uebayasi 
    723  1.25.2.1  uebayasi 		config_cfattach_detach("thinkpad", &thinkpad_ca);
    724  1.25.2.1  uebayasi 		config_cfdriver_detach(&thinkpad_cd);
    725  1.25.2.1  uebayasi 
    726  1.25.2.1  uebayasi 		return 0;
    727  1.25.2.1  uebayasi 
    728  1.25.2.1  uebayasi 	default:
    729  1.25.2.1  uebayasi 		return ENOTTY;
    730  1.25.2.1  uebayasi 	}
    731  1.25.2.1  uebayasi }
    732  1.25.2.1  uebayasi 
    733  1.25.2.1  uebayasi #endif	/* _MODULE */
    734