Home | History | Annotate | Line # | Download | only in acpi
hpacel_acpi.c revision 1.1
      1 /*	$NetBSD: hpacel_acpi.c,v 1.1 2011/07/13 07:52:48 jruoho Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2009, 2011 Jukka Ruohonen <jruohonen (at) iki.fi>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  *
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     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
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     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
     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
     27  * SUCH DAMAGE.
     28  */
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: hpacel_acpi.c,v 1.1 2011/07/13 07:52:48 jruoho Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/module.h>
     34 
     35 #include <dev/acpi/acpireg.h>
     36 #include <dev/acpi/acpivar.h>
     37 #include <dev/acpi/acpi_power.h>
     38 
     39 #include <dev/sysmon/sysmonvar.h>
     40 
     41 #define _COMPONENT	ACPI_RESOURCE_COMPONENT
     42 ACPI_MODULE_NAME	("hpacel_acpi")
     43 
     44 /*
     45  * An ACPI driver for Hewlett-Packard 3D DriveGuard accelerometer.
     46  *
     47  * The supported chipset is LIS3LV02DL from STMicroelectronics:
     48  *
     49  *    http://www.st.com/stonline/products/literature/anp/12441.pdf
     50  *
     51  *    (Obtained on Sat Apr 25 00:32:04 EEST 2009.)
     52  *
     53  * The chip is a three axes digital output linear accelerometer
     54  * that is controllable through I2C / SPI serial interface. This
     55  * implementation however supports only indirect connection through
     56  * ACPI. Other chips from the same family, such as LIS3LV02DQ, may
     57  * also work with the driver, provided that there is a suitable DSDT.
     58  *
     59  * The chip can generate wake-up, direction detection and free-fall
     60  * interrupts. The latter could be used to evoke emergency action.
     61  * None of this is however supported. Only sysmon_envsys(9) is used.
     62  */
     63 enum {
     64 	HPACEL_SENSOR_X = 0,
     65 	HPACEL_SENSOR_Y,
     66 	HPACEL_SENSOR_Z,
     67 	HPACEL_SENSOR_COUNT
     68 };
     69 
     70 #define LIS3LV02DL_ID     0x3A
     71 
     72 enum lis3lv02dl_reg {
     73 	WHO_AM_I        = 0x0F,	/* r  */
     74 	OFFSET_X        = 0x16,	/* rw */
     75 	OFFSET_Y        = 0x17,	/* rw */
     76 	OFFSET_Z        = 0x18,	/* rw */
     77 	GAIN_X          = 0x19,	/* rw */
     78 	GAIN_Y          = 0x1A,	/* rw */
     79 	GAIN_Z          = 0x1B,	/* rw */
     80 	CTRL_REG1       = 0x20,	/* rw */
     81 	CTRL_REG2       = 0x21,	/* rw */
     82 	CTRL_REG3       = 0x22,	/* rw */
     83 	HP_FILTER_RESET = 0x23,	/* r  */
     84 	STATUS_REG      = 0x27,	/* rw */
     85 	OUTX_L          = 0x28,	/* r  */
     86 	OUTX_H          = 0x29,	/* r  */
     87 	OUTY_L          = 0x2A,	/* r  */
     88 	OUTY_H          = 0x2B,	/* r  */
     89 	OUTZ_L          = 0x2C,	/* r  */
     90 	OUTZ_H          = 0x2D,	/* r  */
     91 	FF_WU_CFG       = 0x30,	/* r  */
     92 	FF_WU_SRC       = 0x31,	/* rw */
     93 	FF_WU_ACK       = 0x32,	/* r  */
     94 	FF_WU_THS_L     = 0x34,	/* rw */
     95 	FF_WU_THS_H     = 0x35,	/* rw */
     96 	FF_WU_DURATION  = 0x36,	/* rw */
     97 	DD_CFG          = 0x38,	/* rw */
     98 	DD_SRC          = 0x39,	/* rw */
     99 	DD_ACK          = 0x3A,	/* r  */
    100 	DD_THSI_L       = 0x3C,	/* rw */
    101 	DD_THSI_H       = 0x3D,	/* rw */
    102 	DD_THSE_L       = 0x3E,	/* rw */
    103 	DD_THSE_H       = 0x3F	/* rw */
    104 };
    105 
    106 enum lis3lv02dl_ctrl1 {
    107 	CTRL1_Xen  = (1 << 0),	/* X-axis enable */
    108 	CTRL1_Yen  = (1 << 1),	/* Y-axis enable */
    109 	CTRL1_Zen  = (1 << 2),	/* Z-axis enable */
    110 	CTRL1_ST   = (1 << 3),	/* Self test enable */
    111 	CTRL1_DF0  = (1 << 4),	/* Decimation factor control */
    112 	CTRL1_DF1  = (1 << 5),	/* Decimation factor control */
    113 	CTRL1_PD0  = (1 << 6),	/* Power down control */
    114 	CTRL1_PD1  = (1 << 7)	/* Power down control */
    115 };
    116 
    117 enum lis3lv02dl_ctrl2 {
    118 	CTRL2_DAS  = (1 << 0),  /* Data alignment selection */
    119 	CTRL2_SIM  = (1 << 1),  /* SPI serial interface mode */
    120 	CTRL2_DRDY = (1 << 2),  /* Enable data-ready generation */
    121 	CTRL2_IEN  = (1 << 3),  /* Enable interrupt mode */
    122 	CTRL2_BOOT = (1 << 4),  /* Reboot memory contents */
    123 	CTRL2_BLE  = (1 << 5),  /* Endian mode */
    124 	CTRL2_BDU  = (1 << 6),  /* Block data update */
    125 	CTRL2_FS   = (1 << 7)   /* Full scale selection */
    126 };
    127 
    128 enum lis3lv02dl_ctrl3 {
    129 	CTRL3_CFS0 = (1 << 0),	/* High-pass filter cut-off frequency */
    130 	CTRL3_CFS1 = (1 << 1),  /* High-pass filter cut-off frequency */
    131 	CTRL3_FDS  = (1 << 4),  /* Filtered data selection */
    132 	CTRL3_HPFF = (1 << 5),  /* High pass filter for free-fall */
    133 	CTRL3_HPDD = (1 << 6),  /* High pass filter for DD */
    134 	CTRL3_ECK  = (1 << 7)   /* External clock */
    135 };
    136 
    137 struct hpacel_softc {
    138 	device_t		 sc_dev;
    139 	struct acpi_devnode	*sc_node;
    140 	struct sysmon_envsys	*sc_sme;
    141 	bool			 sc_state;
    142 	uint8_t			 sc_whoami;
    143 	uint8_t			 sc_ctrl[3];
    144 	envsys_data_t		 sc_sensor[HPACEL_SENSOR_COUNT];
    145 };
    146 
    147 const char * const hpacel_ids[] = {
    148 	"HPQ0004",
    149 	NULL
    150 };
    151 
    152 static int		hpacel_match(device_t, cfdata_t, void *);
    153 static void		hpacel_attach(device_t, device_t, void *);
    154 static int		hpacel_detach(device_t, int);
    155 static bool		hpacel_reg_init(device_t);
    156 static bool		hpacel_suspend(device_t, const pmf_qual_t *);
    157 static bool		hpacel_resume(device_t, const pmf_qual_t *);
    158 static ACPI_STATUS	hpacel_reg_info(device_t);
    159 static ACPI_STATUS	hpacel_reg_read(ACPI_HANDLE, ACPI_INTEGER, uint8_t *);
    160 static ACPI_STATUS	hpacel_reg_write(ACPI_HANDLE, ACPI_INTEGER, uint8_t);
    161 static ACPI_STATUS	hpacel_reg_xyz(ACPI_HANDLE, const int, int16_t *);
    162 static ACPI_STATUS	hpacel_power(device_t, bool);
    163 static bool		hpacel_sensor_init(device_t);
    164 static void		hpacel_sensor_refresh(struct sysmon_envsys *,
    165 					      envsys_data_t *);
    166 
    167 CFATTACH_DECL_NEW(hpacel, sizeof(struct hpacel_softc),
    168     hpacel_match, hpacel_attach, hpacel_detach, NULL);
    169 
    170 static int
    171 hpacel_match(device_t parent, cfdata_t match, void *aux)
    172 {
    173 	struct acpi_attach_args *aa = aux;
    174 
    175 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    176 		return 0;
    177 
    178 	return acpi_match_hid(aa->aa_node->ad_devinfo, hpacel_ids);
    179 }
    180 
    181 static void
    182 hpacel_attach(device_t parent, device_t self, void *aux)
    183 {
    184 	struct hpacel_softc *sc = device_private(self);
    185 	struct acpi_attach_args *aa = aux;
    186 
    187 	sc->sc_sme = NULL;
    188 	sc->sc_dev = self;
    189 	sc->sc_state = false;
    190 	sc->sc_node = aa->aa_node;
    191 
    192 	aprint_naive("\n");
    193 	aprint_normal(": HP 3D DriveGuard accelerometer (rev. 0x%02x)\n",
    194 	    sc->sc_whoami);
    195 
    196 	if (hpacel_reg_init(self) != true)
    197 		return;
    198 
    199 	(void)pmf_device_register(self, hpacel_suspend, hpacel_resume);
    200 
    201 	if (hpacel_sensor_init(self) != false)
    202 		(void)hpacel_power(self, true);
    203 
    204 	sc->sc_state = true;
    205 }
    206 
    207 static int
    208 hpacel_detach(device_t self, int flags)
    209 {
    210 	struct hpacel_softc *sc = device_private(self);
    211 
    212 	if (sc->sc_state != false)
    213 		(void)hpacel_power(self, false);
    214 
    215 	if (sc->sc_sme != NULL)
    216 		sysmon_envsys_unregister(sc->sc_sme);
    217 
    218 	return 0;
    219 }
    220 
    221 static bool
    222 hpacel_suspend(device_t self, const pmf_qual_t *qual)
    223 {
    224 	struct hpacel_softc *sc = device_private(self);
    225 
    226 	if (sc->sc_state != false)
    227 		(void)hpacel_power(self, false);
    228 
    229 	return true;
    230 }
    231 
    232 static bool
    233 hpacel_resume(device_t self, const pmf_qual_t *qual)
    234 {
    235 	struct hpacel_softc *sc = device_private(self);
    236 
    237 	if (sc->sc_state != false)
    238 		(void)hpacel_power(self, true);
    239 
    240 	return true;
    241 }
    242 
    243 static bool
    244 hpacel_reg_init(device_t self)
    245 {
    246 	struct hpacel_softc *sc = device_private(self);
    247 	ACPI_HANDLE hdl = sc->sc_node->ad_handle;
    248 	ACPI_STATUS rv;
    249 	uint8_t val;
    250 
    251 	rv = AcpiEvaluateObject(hdl, "_INI", NULL, NULL);
    252 
    253 	if (ACPI_FAILURE(rv))
    254 		goto out;
    255 
    256         /*
    257 	 * Since the "_INI" is practically
    258 	 * a black box, it is better to verify
    259 	 * the control registers manually.
    260 	 */
    261 	rv = hpacel_reg_info(self);
    262 
    263 	if (ACPI_FAILURE(rv))
    264 		goto out;
    265 
    266 	val = sc->sc_ctrl[0];
    267 
    268 	if ((sc->sc_ctrl[0] & CTRL1_Xen) == 0)
    269 		val |= CTRL1_Xen;
    270 
    271 	if ((sc->sc_ctrl[0] & CTRL1_Yen) == 0)
    272 		val |= CTRL1_Yen;
    273 
    274 	if ((sc->sc_ctrl[0] & CTRL1_Zen) == 0)
    275 		val |= CTRL1_Zen;
    276 
    277 	if (val != sc->sc_ctrl[0]) {
    278 
    279 		rv = hpacel_reg_write(hdl, CTRL_REG1, val);
    280 
    281 		if (ACPI_FAILURE(rv))
    282 			return rv;
    283 	}
    284 
    285         val = sc->sc_ctrl[1];
    286 
    287 	if ((sc->sc_ctrl[1] & CTRL2_BDU) == 0)
    288 		val |= CTRL2_BDU;
    289 
    290 	if ((sc->sc_ctrl[1] & CTRL2_BLE) != 0)
    291 		val &= ~CTRL2_BLE;
    292 
    293 	if ((sc->sc_ctrl[1] & CTRL2_DAS) != 0)
    294 		val &= ~CTRL2_DAS;
    295 
    296 	/*
    297 	 * Given the use of sysmon_envsys(9),
    298 	 * there is no need for the data-ready pin.
    299 	 */
    300 	if ((sc->sc_ctrl[1] & CTRL2_DRDY) != 0)
    301 		val &= ~CTRL2_DRDY;
    302 
    303 	/*
    304 	 * Disable interrupt mode.
    305 	 */
    306 	if ((sc->sc_ctrl[1] & CTRL2_IEN) != 0)
    307 		val &= ~CTRL2_IEN;
    308 
    309 	if (val != sc->sc_ctrl[1]) {
    310 
    311 		rv = hpacel_reg_write(hdl, CTRL_REG2, val);
    312 
    313 		if (ACPI_FAILURE(rv))
    314 			return rv;
    315 	}
    316 
    317 	/*
    318 	 * Clear possible interrupt setups from
    319 	 * the direction-detection register and
    320 	 * from the free-fall-wake-up register.
    321 	 */
    322 	(void)hpacel_reg_write(hdl, DD_CFG, 0x00);
    323 	(void)hpacel_reg_write(hdl, FF_WU_CFG, 0x00);
    324 
    325 	/*
    326 	 * Update the register information.
    327 	 */
    328 	(void)hpacel_reg_info(hdl);
    329 
    330 out:
    331 	if (ACPI_FAILURE(rv))
    332 		aprint_error_dev(self, "failed to initialize "
    333 		    "device: %s\n", AcpiFormatException(rv));
    334 
    335 	return (rv != AE_OK) ? false : true;
    336 }
    337 
    338 static ACPI_STATUS
    339 hpacel_reg_info(device_t self)
    340 {
    341 	struct hpacel_softc *sc = device_private(self);
    342 	ACPI_HANDLE hdl = sc->sc_node->ad_handle;
    343 	ACPI_STATUS rv;
    344 	size_t i;
    345 
    346 	rv = hpacel_reg_read(hdl, WHO_AM_I, &sc->sc_whoami);
    347 
    348 	if (ACPI_FAILURE(rv))
    349 		return rv;
    350 
    351 	for (i = 0; i < __arraycount(sc->sc_sensor); i++) {
    352 
    353 		rv = hpacel_reg_read(hdl, CTRL_REG1 + i, &sc->sc_ctrl[i]);
    354 
    355 		if (ACPI_FAILURE(rv))
    356 			return rv;
    357 	}
    358 
    359 	return AE_OK;
    360 }
    361 
    362 static ACPI_STATUS
    363 hpacel_reg_read(ACPI_HANDLE hdl, ACPI_INTEGER reg, uint8_t *valp)
    364 {
    365 	ACPI_OBJECT_LIST arg;
    366 	ACPI_OBJECT obj, val;
    367 	ACPI_BUFFER buf;
    368 	ACPI_STATUS rv;
    369 
    370 	obj.Type = ACPI_TYPE_INTEGER;
    371 	obj.Integer.Value = reg;
    372 
    373 	buf.Pointer = &val;
    374 	buf.Length = sizeof(val);
    375 
    376 	arg.Count = 1;
    377 	arg.Pointer = &obj;
    378 
    379 	rv = AcpiEvaluateObjectTyped(hdl, "ALRD",
    380 	    &arg, &buf, ACPI_TYPE_INTEGER);
    381 
    382 	if (ACPI_FAILURE(rv))
    383 		return rv;
    384 
    385 	if (val.Integer.Value > UINT8_MAX)
    386 		return AE_AML_NUMERIC_OVERFLOW;
    387 
    388 	*valp = val.Integer.Value;
    389 
    390 	return AE_OK;
    391 }
    392 
    393 static ACPI_STATUS
    394 hpacel_reg_write(ACPI_HANDLE hdl, ACPI_INTEGER reg, uint8_t val)
    395 {
    396 	ACPI_OBJECT_LIST arg;
    397 	ACPI_OBJECT obj[2];
    398 
    399 	obj[0].Type = obj[1].Type = ACPI_TYPE_INTEGER;
    400 
    401 	obj[0].Integer.Value = reg;
    402 	obj[1].Integer.Value = val;
    403 
    404 	arg.Count = 2;
    405 	arg.Pointer = obj;
    406 
    407 	return AcpiEvaluateObject(hdl, "ALWR", &arg, NULL);
    408 }
    409 
    410 static ACPI_STATUS
    411 hpacel_reg_xyz(ACPI_HANDLE hdl, const int xyz, int16_t *out)
    412 {
    413 	ACPI_INTEGER reg[2];
    414 	ACPI_STATUS rv[2];
    415 	uint8_t hi, lo;
    416 
    417 	switch (xyz) {
    418 
    419 	case HPACEL_SENSOR_X:
    420 		reg[0] = OUTX_L;
    421 		reg[1] = OUTX_H;
    422 		break;
    423 
    424 	case HPACEL_SENSOR_Y:
    425 		reg[0] = OUTY_L;
    426 		reg[1] = OUTY_H;
    427 		break;
    428 
    429 	case HPACEL_SENSOR_Z:
    430 		reg[0] = OUTZ_L;
    431 		reg[1] = OUTZ_H;
    432 		break;
    433 
    434 	default:
    435 		return AE_BAD_PARAMETER;
    436 	}
    437 
    438 	rv[0] = hpacel_reg_read(hdl, reg[0], &lo);
    439 	rv[1] = hpacel_reg_read(hdl, reg[1], &hi);
    440 
    441 	if (ACPI_FAILURE(rv[0]) || ACPI_FAILURE(rv[1]))
    442 		return AE_ERROR;
    443 
    444 	/*
    445 	 * These registers are read in "12 bit right
    446 	 * justified mode", meaning that the four
    447 	 * most significant bits are replaced with
    448 	 * the value of bit 12. Note the signed type.
    449 	 */
    450 	hi = (hi & 0x10) ? hi | 0xE0 : hi & ~0xE0;
    451 
    452 	*out = (hi << 8) | lo;
    453 
    454 	return AE_OK;
    455 }
    456 
    457 static ACPI_STATUS
    458 hpacel_power(device_t self, bool enable)
    459 {
    460 	struct hpacel_softc *sc = device_private(self);
    461 	ACPI_HANDLE hdl = sc->sc_node->ad_handle;
    462 	ACPI_OBJECT_LIST arg;
    463 	ACPI_OBJECT obj;
    464 	ACPI_STATUS rv;
    465 	uint8_t val;
    466 
    467 	rv = hpacel_reg_info(self);
    468 
    469 	if (ACPI_FAILURE(rv))
    470 		return rv;
    471 
    472 	val = sc->sc_ctrl[0];
    473 
    474 	if (enable != false)
    475 		val |= CTRL1_PD0 | CTRL1_PD1;
    476 	else {
    477 		val &= ~(CTRL1_PD0 | CTRL1_PD1);
    478 	}
    479 
    480 	if (val != sc->sc_ctrl[0]) {
    481 
    482 		rv = hpacel_reg_write(hdl, CTRL_REG1, val);
    483 
    484 		if (ACPI_FAILURE(rv))
    485 			return rv;
    486 	}
    487 
    488 	obj.Type = ACPI_TYPE_INTEGER;
    489 	obj.Integer.Value = enable;
    490 
    491 	arg.Count = 1;
    492 	arg.Pointer = &obj;
    493 
    494 	/*
    495 	 * This should turn on/off a led, if available.
    496 	 */
    497 	(void)AcpiEvaluateObject(hdl, "ALED", &arg, NULL);
    498 
    499 	return rv;
    500 }
    501 
    502 static bool
    503 hpacel_sensor_init(device_t self)
    504 {
    505 	const char zyx[HPACEL_SENSOR_COUNT] = { 'x', 'y', 'z' };
    506 	struct hpacel_softc *sc = device_private(self);
    507 	size_t i;
    508 	int rv;
    509 
    510 	CTASSERT(HPACEL_SENSOR_X == 0);
    511 	CTASSERT(HPACEL_SENSOR_Y == 1);
    512 	CTASSERT(HPACEL_SENSOR_Z == 2);
    513 
    514 	sc->sc_sme = sysmon_envsys_create();
    515 
    516 	for (i = 0; i < __arraycount(sc->sc_sensor); i++) {
    517 
    518 		sc->sc_sensor[i].units = ENVSYS_INTEGER;
    519 		sc->sc_sensor[i].state = ENVSYS_SINVALID;
    520 
    521 		(void)snprintf(sc->sc_sensor[i].desc,
    522 		    ENVSYS_DESCLEN, "%c-acceleration", zyx[i]);
    523 
    524 		rv = sysmon_envsys_sensor_attach(sc->sc_sme,&sc->sc_sensor[i]);
    525 
    526 		if (rv != 0)
    527 			goto fail;
    528 	}
    529 
    530 	/*
    531 	 * We only do polling, given the hopelessly
    532 	 * slow way of reading registers with ACPI.
    533 	 */
    534 	sc->sc_sme->sme_cookie = sc;
    535 	sc->sc_sme->sme_flags = SME_POLL_ONLY;
    536 	sc->sc_sme->sme_name = device_xname(self);
    537 	sc->sc_sme->sme_refresh = hpacel_sensor_refresh;
    538 
    539 	rv = sysmon_envsys_register(sc->sc_sme);
    540 
    541 	if (rv != 0)
    542 		goto fail;
    543 
    544 	return true;
    545 
    546 fail:
    547 	aprint_error_dev(self, "failed to initialize sensors\n");
    548 
    549 	sysmon_envsys_destroy(sc->sc_sme);
    550 	sc->sc_sme = NULL;
    551 
    552 	return false;
    553 }
    554 
    555 static void
    556 hpacel_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    557 {
    558         struct hpacel_softc *sc = sme->sme_cookie;
    559 	ACPI_STATUS rv;
    560 	int16_t val;
    561 	size_t i;
    562 
    563 	for (i = 0; i < __arraycount(sc->sc_sensor); i++) {
    564 
    565 		rv = hpacel_reg_xyz(sc->sc_node->ad_handle, i, &val);
    566 
    567 		if (ACPI_SUCCESS(rv)) {
    568 			sc->sc_sensor[i].value_cur = val;
    569 			sc->sc_sensor[i].state = ENVSYS_SVALID;
    570 			continue;
    571 		}
    572 
    573 		sc->sc_sensor[i].state = ENVSYS_SINVALID;
    574 	}
    575 }
    576 
    577 MODULE(MODULE_CLASS_DRIVER, hpacel, NULL);
    578 
    579 #ifdef _MODULE
    580 #include "ioconf.c"
    581 #endif
    582 
    583 static int
    584 hpacel_modcmd(modcmd_t cmd, void *aux)
    585 {
    586 	int rv = 0;
    587 
    588 	switch (cmd) {
    589 
    590 	case MODULE_CMD_INIT:
    591 
    592 #ifdef _MODULE
    593 		rv = config_init_component(cfdriver_ioconf_hpacel,
    594 		    cfattach_ioconf_hpacel, cfdata_ioconf_hpacel);
    595 #endif
    596 		break;
    597 
    598 	case MODULE_CMD_FINI:
    599 
    600 #ifdef _MODULE
    601 		rv = config_fini_component(cfdriver_ioconf_hpacel,
    602 		    cfattach_ioconf_hpacel, cfdata_ioconf_hpacel);
    603 #endif
    604 		break;
    605 
    606 	default:
    607 		rv = ENOTTY;
    608 	}
    609 
    610 	return rv;
    611 }
    612