hpet_acpi.c revision 1.5
11.5Sjruoho/* $NetBSD: hpet_acpi.c,v 1.5 2010/03/05 14:00:17 jruoho 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.5Sjruoho__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.5 2010/03/05 14:00:17 jruoho Exp $");
331.1Snjoly
341.1Snjoly#include <sys/param.h>
351.5Sjruoho#include <sys/device.h>
361.1Snjoly#include <sys/systm.h>
371.5Sjruoho#include <sys/time.h>
381.5Sjruoho#include <sys/timetc.h>
391.1Snjoly
401.1Snjoly#include <dev/acpi/acpivar.h>
411.1Snjoly
421.1Snjoly#include <dev/ic/hpetvar.h>
431.1Snjoly
441.3Sxtraemestatic int	hpet_acpi_match(device_t, cfdata_t, void *);
451.3Sxtraemestatic void	hpet_acpi_attach(device_t, device_t, void *);
461.1Snjoly
471.1Snjoly
481.3SxtraemeCFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
491.1Snjoly    hpet_acpi_attach, NULL, NULL);
501.1Snjoly
511.1Snjoly/*
521.1Snjoly * Supported device IDs
531.1Snjoly */
541.1Snjoly
551.1Snjolystatic const char * const hpet_acpi_ids[] = {
561.1Snjoly	"PNP0103",
571.1Snjoly	NULL
581.1Snjoly};
591.1Snjoly
601.1Snjoly/*
611.1Snjoly * hpet_acpi_match: autoconf(9) match routine
621.1Snjoly */
631.1Snjolystatic int
641.3Sxtraemehpet_acpi_match(device_t parent, cfdata_t match, void *aux)
651.1Snjoly{
661.1Snjoly	struct acpi_attach_args *aa = aux;
671.1Snjoly
681.1Snjoly	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
691.1Snjoly		return 0;
701.1Snjoly
711.1Snjoly	return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
721.1Snjoly}
731.1Snjoly
741.1Snjolystatic void
751.3Sxtraemehpet_acpi_attach(device_t parent, device_t self, void *aux)
761.1Snjoly{
771.3Sxtraeme	struct hpet_softc *sc = device_private(self);
781.1Snjoly	struct acpi_attach_args *aa = aux;
791.1Snjoly	struct acpi_resources res;
801.1Snjoly	struct acpi_mem *mem;
811.1Snjoly	ACPI_STATUS rv;
821.1Snjoly
831.1Snjoly	/* parse resources */
841.3Sxtraeme	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
851.1Snjoly	    &res, &acpi_resource_parse_ops_default);
861.1Snjoly	if (ACPI_FAILURE(rv))
871.1Snjoly		return;
881.1Snjoly
891.1Snjoly	/* find our mem registers */
901.1Snjoly	mem = acpi_res_mem(&res, 0);
911.1Snjoly	if (mem == NULL) {
921.3Sxtraeme		aprint_error_dev(self,
931.3Sxtraeme		    "unable to find mem register resource\n");
941.1Snjoly		goto out;
951.1Snjoly	}
961.1Snjoly
971.1Snjoly	sc->sc_memt = aa->aa_memt;
981.1Snjoly	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
991.1Snjoly		    0, &sc->sc_memh)) {
1001.3Sxtraeme		aprint_error_dev(self, "can't map mem space\n");
1011.1Snjoly		goto out;
1021.1Snjoly	}
1031.1Snjoly
1041.3Sxtraeme	hpet_attach_subr(self);
1051.1Snjoly
1061.1Snjoly out:
1071.1Snjoly	acpi_resource_cleanup(&res);
1081.1Snjoly}
109