attimer_acpi.c revision 1.13
11.13Sdyoung/* $NetBSD: attimer_acpi.c,v 1.13 2009/04/07 17:59:18 dyoung 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 *
191.1Scube * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Scube * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Scube * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Scube * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Scube * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Scube * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Scube * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Scube * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Scube * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Scube * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Scube * POSSIBILITY OF SUCH DAMAGE.
301.1Scube */
311.1Scube
321.1Scube/*
331.1Scube * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
341.1Scube * All rights reserved.
351.1Scube *
361.1Scube * Redistribution and use in source and binary forms, with or without
371.1Scube * modification, are permitted provided that the following conditions
381.1Scube * are met:
391.1Scube * 1. Redistributions of source code must retain the above copyright
401.1Scube *    notice, this list of conditions and the following disclaimer.
411.1Scube * 2. The name of the author may not be used to endorse or promote products
421.1Scube *    derived from this software without specific prior written permission.
431.1Scube *
441.1Scube * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
451.1Scube * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
461.1Scube * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
471.1Scube * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
481.1Scube * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
491.1Scube * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
501.1Scube * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
511.1Scube * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
521.1Scube * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
531.1Scube * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
541.1Scube * SUCH DAMAGE.
551.1Scube */
561.1Scube
571.1Scube/*
581.1Scube * ACPI attimer(4) attachment based on lpt_acpi.c by Jared D. McNeill.
591.1Scube */
601.1Scube
611.1Scube#include <sys/cdefs.h>
621.13Sdyoung__KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.13 2009/04/07 17:59:18 dyoung Exp $");
631.1Scube
641.1Scube#include <sys/param.h>
651.1Scube#include <sys/systm.h>
661.1Scube#include <sys/errno.h>
671.1Scube#include <sys/ioctl.h>
681.1Scube#include <sys/device.h>
691.1Scube#include <sys/proc.h>
701.1Scube
711.7Sad#include <sys/bus.h>
721.1Scube
731.1Scube#include <dev/acpi/acpica.h>
741.1Scube#include <dev/acpi/acpireg.h>
751.1Scube#include <dev/acpi/acpivar.h>
761.1Scube
771.1Scube#include <dev/ic/attimervar.h>
781.1Scube
791.10Scubestatic int	attimer_acpi_match(device_t, cfdata_t, void *);
801.8Sdyoungstatic void	attimer_acpi_attach(device_t, device_t, void *);
811.1Scube
821.13SdyoungCFATTACH_DECL3_NEW(attimer_acpi, sizeof(struct attimer_softc),
831.13Sdyoung    attimer_acpi_match, attimer_acpi_attach, attimer_detach, NULL, NULL, NULL,
841.13Sdyoung    DVF_DETACH_SHUTDOWN);
851.1Scube
861.1Scube/*
871.1Scube * Supported device IDs
881.1Scube */
891.1Scube
901.1Scubestatic const char * const attimer_acpi_ids[] = {
911.1Scube	"PNP0100",	/* AT Timer */
921.1Scube	NULL
931.1Scube};
941.1Scube
951.1Scube/*
961.1Scube * attimer_acpi_match: autoconf(9) match routine
971.1Scube */
981.1Scubestatic int
991.10Scubeattimer_acpi_match(device_t parent, cfdata_t match, void *aux)
1001.1Scube{
1011.1Scube	struct acpi_attach_args *aa = aux;
1021.1Scube
1031.1Scube	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
1041.1Scube		return 0;
1051.1Scube
1061.1Scube	return acpi_match_hid(aa->aa_node->ad_devinfo, attimer_acpi_ids);
1071.1Scube}
1081.1Scube
1091.1Scube/*
1101.1Scube * attimer_acpi_attach: autoconf(9) attach routine
1111.1Scube */
1121.1Scubestatic void
1131.8Sdyoungattimer_acpi_attach(device_t parent, device_t self, void *aux)
1141.1Scube{
1151.8Sdyoung	struct attimer_softc *sc = device_private(self);
1161.1Scube	struct acpi_attach_args *aa = aux;
1171.1Scube	struct acpi_resources res;
1181.1Scube	struct acpi_io *io;
1191.1Scube	ACPI_STATUS rv;
1201.1Scube
1211.10Scube	sc->sc_dev = self;
1221.10Scube
1231.1Scube	/* parse resources */
1241.10Scube	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
1251.1Scube	    &res, &acpi_resource_parse_ops_default);
1261.1Scube	if (ACPI_FAILURE(rv))
1271.1Scube		return;
1281.1Scube
1291.1Scube	/* find our i/o registers */
1301.1Scube	io = acpi_res_io(&res, 0);
1311.1Scube	if (io == NULL) {
1321.10Scube		aprint_error_dev(self,
1331.10Scube		    "unable to find i/o register resource\n");
1341.1Scube		goto out;
1351.1Scube	}
1361.1Scube
1371.1Scube	sc->sc_iot = aa->aa_iot;
1381.9Sdyoung	sc->sc_size = io->ar_length;
1391.9Sdyoung	if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size,
1401.9Sdyoung		    0, &sc->sc_ioh) != 0) {
1411.10Scube		aprint_error_dev(self, "can't map i/o space\n");
1421.1Scube		goto out;
1431.1Scube	}
1441.1Scube
1451.1Scube	attimer_attach(sc);
1461.1Scube
1471.1Scube out:
1481.1Scube	acpi_resource_cleanup(&res);
1491.1Scube}
150