hpet_acpi.c revision 1.3
11.3Sxtraeme/* $NetBSD: hpet_acpi.c,v 1.3 2008/03/21 13:28:14 xtraeme Exp $ */
21.1Snjoly
31.1Snjoly/*
41.1Snjoly * Copyright (c) 2006 Nicolas Joly
51.1Snjoly * All rights reserved.
61.1Snjoly *
71.1Snjoly * Redistribution and use in source and binary forms, with or without
81.1Snjoly * modification, are permitted provided that the following conditions
91.1Snjoly * are met:
101.1Snjoly * 1. Redistributions of source code must retain the above copyright
111.1Snjoly *    notice, this list of conditions and the following disclaimer.
121.1Snjoly * 2. Redistributions in binary form must reproduce the above copyright
131.1Snjoly *    notice, this list of conditions and the following disclaimer in the
141.1Snjoly *    documentation and/or other materials provided with the distribution.
151.1Snjoly * 3. The name of the author may not be used to endorse or promote products
161.1Snjoly *    derived from this software without specific prior written permission.
171.1Snjoly *
181.1Snjoly * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
191.1Snjoly * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Snjoly * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Snjoly * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Snjoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Snjoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Snjoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Snjoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Snjoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Snjoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Snjoly * POSSIBILITY OF SUCH DAMAGE.
291.1Snjoly */
301.1Snjoly
311.1Snjoly#include <sys/cdefs.h>
321.3Sxtraeme__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.3 2008/03/21 13:28:14 xtraeme Exp $");
331.1Snjoly
341.1Snjoly#include <sys/param.h>
351.1Snjoly#include <sys/systm.h>
361.1Snjoly#include <sys/errno.h>
371.1Snjoly#include <sys/device.h>
381.1Snjoly
391.2Sad#include <sys/bus.h>
401.1Snjoly
411.1Snjoly#include <dev/acpi/acpica.h>
421.1Snjoly#include <dev/acpi/acpireg.h>
431.1Snjoly#include <dev/acpi/acpivar.h>
441.1Snjoly
451.1Snjoly#include <sys/time.h>
461.1Snjoly#include <sys/timetc.h>
471.1Snjoly
481.1Snjoly#include <dev/ic/hpetvar.h>
491.1Snjoly
501.3Sxtraemestatic int	hpet_acpi_match(device_t, cfdata_t, void *);
511.3Sxtraemestatic void	hpet_acpi_attach(device_t, device_t, void *);
521.1Snjoly
531.1Snjoly
541.3SxtraemeCFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
551.1Snjoly    hpet_acpi_attach, NULL, NULL);
561.1Snjoly
571.1Snjoly/*
581.1Snjoly * Supported device IDs
591.1Snjoly */
601.1Snjoly
611.1Snjolystatic const char * const hpet_acpi_ids[] = {
621.1Snjoly	"PNP0103",
631.1Snjoly	NULL
641.1Snjoly};
651.1Snjoly
661.1Snjoly/*
671.1Snjoly * hpet_acpi_match: autoconf(9) match routine
681.1Snjoly */
691.1Snjolystatic int
701.3Sxtraemehpet_acpi_match(device_t parent, cfdata_t match, void *aux)
711.1Snjoly{
721.1Snjoly	struct acpi_attach_args *aa = aux;
731.1Snjoly
741.1Snjoly	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
751.1Snjoly		return 0;
761.1Snjoly
771.1Snjoly	return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
781.1Snjoly}
791.1Snjoly
801.1Snjolystatic void
811.3Sxtraemehpet_acpi_attach(device_t parent, device_t self, void *aux)
821.1Snjoly{
831.3Sxtraeme	struct hpet_softc *sc = device_private(self);
841.1Snjoly	struct acpi_attach_args *aa = aux;
851.1Snjoly	struct acpi_resources res;
861.1Snjoly	struct acpi_mem *mem;
871.1Snjoly	ACPI_STATUS rv;
881.1Snjoly
891.1Snjoly	aprint_naive("\n");
901.1Snjoly	aprint_normal("\n");
911.1Snjoly
921.1Snjoly	/* parse resources */
931.3Sxtraeme	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
941.1Snjoly	    &res, &acpi_resource_parse_ops_default);
951.1Snjoly	if (ACPI_FAILURE(rv))
961.1Snjoly		return;
971.1Snjoly
981.1Snjoly	/* find our mem registers */
991.1Snjoly	mem = acpi_res_mem(&res, 0);
1001.1Snjoly	if (mem == NULL) {
1011.3Sxtraeme		aprint_error_dev(self,
1021.3Sxtraeme		    "unable to find mem register resource\n");
1031.1Snjoly		goto out;
1041.1Snjoly	}
1051.1Snjoly
1061.1Snjoly	sc->sc_memt = aa->aa_memt;
1071.1Snjoly	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
1081.1Snjoly		    0, &sc->sc_memh)) {
1091.3Sxtraeme		aprint_error_dev(self, "can't map mem space\n");
1101.1Snjoly		goto out;
1111.1Snjoly	}
1121.1Snjoly
1131.3Sxtraeme	hpet_attach_subr(self);
1141.1Snjoly
1151.1Snjoly out:
1161.1Snjoly	acpi_resource_cleanup(&res);
1171.1Snjoly}
118