attimer_acpi.c revision 1.1
11.1Scube/* $NetBSD: attimer_acpi.c,v 1.1 2005/03/25 23:06:19 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.1Scube * by Juan Romero Pardines <xtraeme@NetBSD.org> and 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.1Scube__KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.1 2005/03/25 23:06:19 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.1Scube#include <machine/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.1Scubestatic int	attimer_acpi_match(struct device *, struct cfdata *, void *);
871.1Scubestatic void	attimer_acpi_attach(struct device *, struct device *, void *);
881.1Scube
891.1ScubeCFATTACH_DECL(attimer_acpi, sizeof(struct attimer_softc), attimer_acpi_match,
901.1Scube    attimer_acpi_attach, NULL, 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.1Scubeattimer_acpi_match(struct device *parent, struct cfdata *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.1Scubeattimer_acpi_attach(struct device *parent, struct device *self, void *aux)
1201.1Scube{
1211.1Scube	struct attimer_softc *sc = (struct attimer_softc *)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.1Scube	printf(": AT Timer\n");
1281.1Scube
1291.1Scube	/* parse resources */
1301.1Scube	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
1311.1Scube	    &res, &acpi_resource_parse_ops_default);
1321.1Scube	if (ACPI_FAILURE(rv))
1331.1Scube		return;
1341.1Scube
1351.1Scube	/* find our i/o registers */
1361.1Scube	io = acpi_res_io(&res, 0);
1371.1Scube	if (io == NULL) {
1381.1Scube		printf("%s: unable to find i/o register resource\n",
1391.1Scube		    sc->sc_dev.dv_xname);
1401.1Scube		goto out;
1411.1Scube	}
1421.1Scube
1431.1Scube	sc->sc_iot = aa->aa_iot;
1441.1Scube	if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length,
1451.1Scube		    0, &sc->sc_ioh)) {
1461.1Scube		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
1471.1Scube		goto out;
1481.1Scube	}
1491.1Scube
1501.1Scube	attimer_attach(sc);
1511.1Scube
1521.1Scube out:
1531.1Scube	acpi_resource_cleanup(&res);
1541.1Scube}
155