attimer_acpi.c revision 1.10
11.10Scube/* $NetBSD: attimer_acpi.c,v 1.10 2008/03/04 16:35:18 cube Exp $ */
21.1Scube
31.1Scube/*
41.1Scube * Copyright (c) 2005 The NetBSD Foundation, Inc.
51.1Scube * All rights reserved.
61.1Scube *
71.1Scube * This code is derived from software contributed to The NetBSD Foundation
81.6Sxtraeme * by Quentin Garnier.
91.1Scube *
101.1Scube * Redistribution and use in source and binary forms, with or without
111.1Scube * modification, are permitted provided that the following conditions
121.1Scube * are met:
131.1Scube * 1. Redistributions of source code must retain the above copyright
141.1Scube *    notice, this list of conditions and the following disclaimer.
151.1Scube * 2. Redistributions in binary form must reproduce the above copyright
161.1Scube *    notice, this list of conditions and the following disclaimer in the
171.1Scube *    documentation and/or other materials provided with the distribution.
181.1Scube * 3. All advertising materials mentioning features or use of this software
191.1Scube *    must display the following acknowledgement:
201.1Scube *      This product includes software developed by the NetBSD
211.1Scube *      Foundation, Inc. and its contributors.
221.1Scube * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Scube *    contributors may be used to endorse or promote products derived
241.1Scube *    from this software without specific prior written permission.
251.1Scube *
261.1Scube * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Scube * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Scube * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Scube * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Scube * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Scube * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Scube * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Scube * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Scube * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Scube * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Scube * POSSIBILITY OF SUCH DAMAGE.
371.1Scube */
381.1Scube
391.1Scube/*
401.1Scube * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
411.1Scube * All rights reserved.
421.1Scube *
431.1Scube * Redistribution and use in source and binary forms, with or without
441.1Scube * modification, are permitted provided that the following conditions
451.1Scube * are met:
461.1Scube * 1. Redistributions of source code must retain the above copyright
471.1Scube *    notice, this list of conditions and the following disclaimer.
481.1Scube * 2. The name of the author may not be used to endorse or promote products
491.1Scube *    derived from this software without specific prior written permission.
501.1Scube *
511.1Scube * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
521.1Scube * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
531.1Scube * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
541.1Scube * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
551.1Scube * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
561.1Scube * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
571.1Scube * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
581.1Scube * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
591.1Scube * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
601.1Scube * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
611.1Scube * SUCH DAMAGE.
621.1Scube */
631.1Scube
641.1Scube/*
651.1Scube * ACPI attimer(4) attachment based on lpt_acpi.c by Jared D. McNeill.
661.1Scube */
671.1Scube
681.1Scube#include <sys/cdefs.h>
691.10Scube__KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.10 2008/03/04 16:35:18 cube Exp $");
701.1Scube
711.1Scube#include <sys/param.h>
721.1Scube#include <sys/systm.h>
731.1Scube#include <sys/errno.h>
741.1Scube#include <sys/ioctl.h>
751.1Scube#include <sys/device.h>
761.1Scube#include <sys/proc.h>
771.1Scube
781.7Sad#include <sys/bus.h>
791.1Scube
801.1Scube#include <dev/acpi/acpica.h>
811.1Scube#include <dev/acpi/acpireg.h>
821.1Scube#include <dev/acpi/acpivar.h>
831.1Scube
841.1Scube#include <dev/ic/attimervar.h>
851.1Scube
861.10Scubestatic int	attimer_acpi_match(device_t, cfdata_t, void *);
871.8Sdyoungstatic void	attimer_acpi_attach(device_t, device_t, void *);
881.1Scube
891.10ScubeCFATTACH_DECL_NEW(attimer_acpi, sizeof(struct attimer_softc),
901.10Scube    attimer_acpi_match, attimer_acpi_attach, attimer_detach, NULL);
911.1Scube
921.1Scube/*
931.1Scube * Supported device IDs
941.1Scube */
951.1Scube
961.1Scubestatic const char * const attimer_acpi_ids[] = {
971.1Scube	"PNP0100",	/* AT Timer */
981.1Scube	NULL
991.1Scube};
1001.1Scube
1011.1Scube/*
1021.1Scube * attimer_acpi_match: autoconf(9) match routine
1031.1Scube */
1041.1Scubestatic int
1051.10Scubeattimer_acpi_match(device_t parent, cfdata_t match, void *aux)
1061.1Scube{
1071.1Scube	struct acpi_attach_args *aa = aux;
1081.1Scube
1091.1Scube	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
1101.1Scube		return 0;
1111.1Scube
1121.1Scube	return acpi_match_hid(aa->aa_node->ad_devinfo, attimer_acpi_ids);
1131.1Scube}
1141.1Scube
1151.1Scube/*
1161.1Scube * attimer_acpi_attach: autoconf(9) attach routine
1171.1Scube */
1181.1Scubestatic void
1191.8Sdyoungattimer_acpi_attach(device_t parent, device_t self, void *aux)
1201.1Scube{
1211.8Sdyoung	struct attimer_softc *sc = device_private(self);
1221.1Scube	struct acpi_attach_args *aa = aux;
1231.1Scube	struct acpi_resources res;
1241.1Scube	struct acpi_io *io;
1251.1Scube	ACPI_STATUS rv;
1261.1Scube
1271.10Scube	sc->sc_dev = self;
1281.10Scube
1291.3Skochi	aprint_naive(": AT Timer\n");
1301.3Skochi	aprint_normal(": AT Timer\n");
1311.1Scube
1321.1Scube	/* parse resources */
1331.10Scube	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
1341.1Scube	    &res, &acpi_resource_parse_ops_default);
1351.1Scube	if (ACPI_FAILURE(rv))
1361.1Scube		return;
1371.1Scube
1381.1Scube	/* find our i/o registers */
1391.1Scube	io = acpi_res_io(&res, 0);
1401.1Scube	if (io == NULL) {
1411.10Scube		aprint_error_dev(self,
1421.10Scube		    "unable to find i/o register resource\n");
1431.1Scube		goto out;
1441.1Scube	}
1451.1Scube
1461.1Scube	sc->sc_iot = aa->aa_iot;
1471.9Sdyoung	sc->sc_size = io->ar_length;
1481.9Sdyoung	if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size,
1491.9Sdyoung		    0, &sc->sc_ioh) != 0) {
1501.10Scube		aprint_error_dev(self, "can't map i/o space\n");
1511.1Scube		goto out;
1521.1Scube	}
1531.1Scube
1541.1Scube	attimer_attach(sc);
1551.1Scube
1561.1Scube out:
1571.1Scube	acpi_resource_cleanup(&res);
1581.1Scube}
159