acpi_timer.c revision 77432
167761Smsmith/*-
267761Smsmith * Copyright (c) 2000 Michael Smith
367761Smsmith * Copyright (c) 2000 BSDi
467761Smsmith * All rights reserved.
567761Smsmith *
667761Smsmith * Redistribution and use in source and binary forms, with or without
767761Smsmith * modification, are permitted provided that the following conditions
867761Smsmith * are met:
967761Smsmith * 1. Redistributions of source code must retain the above copyright
1067761Smsmith *    notice, this list of conditions and the following disclaimer.
1167761Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1267761Smsmith *    notice, this list of conditions and the following disclaimer in the
1367761Smsmith *    documentation and/or other materials provided with the distribution.
1467761Smsmith *
1567761Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1667761Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1767761Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1867761Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1967761Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2067761Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2167761Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2267761Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2367761Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2467761Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2567761Smsmith * SUCH DAMAGE.
2667761Smsmith *
2767761Smsmith *	$FreeBSD: head/sys/dev/acpica/acpi_timer.c 77432 2001-05-29 20:13:42Z msmith $
2867761Smsmith */
2967761Smsmith
3067761Smsmith#include "opt_acpi.h"
3167761Smsmith#include <sys/param.h>
3267761Smsmith#include <sys/kernel.h>
3367761Smsmith#include <sys/bus.h>
3467761Smsmith
3567761Smsmith#include "acpi.h"
3667761Smsmith
3767761Smsmith#include <dev/acpica/acpivar.h>
3867761Smsmith
3969744Smsmith/*
4069744Smsmith * Hooks for the ACPI CA debugging infrastructure
4169744Smsmith */
4277432Smsmith#define _COMPONENT	ACPI_SYSTEM
4369744SmsmithMODULE_NAME("TIMER")
4469744Smsmith
4567761Smsmith#define ACPITIMER_MAGIC 0x524d4954	/* "TIMR" */
4667761Smsmith
4767761Smsmithstruct acpi_timer_softc {
4867761Smsmith    device_t	tm_dev;
4967761Smsmith};
5067761Smsmith
5167761Smsmithstatic void	acpi_timer_identify(driver_t *driver, device_t parent);
5267761Smsmithstatic int	acpi_timer_probe(device_t dev);
5367761Smsmithstatic int	acpi_timer_attach(device_t dev);
5467761Smsmith
5567761Smsmithstatic device_method_t acpi_timer_methods[] = {
5667761Smsmith    /* Device interface */
5767761Smsmith    DEVMETHOD(device_identify,	acpi_timer_identify),
5867761Smsmith    DEVMETHOD(device_probe,	acpi_timer_probe),
5967761Smsmith    DEVMETHOD(device_attach,	acpi_timer_attach),
6067761Smsmith
6167761Smsmith    {0, 0}
6267761Smsmith};
6367761Smsmith
6467761Smsmithstatic driver_t acpi_timer_driver = {
6567761Smsmith    "acpi_timer",
6667761Smsmith    acpi_timer_methods,
6767761Smsmith    sizeof(struct acpi_timer_softc),
6867761Smsmith};
6967761Smsmith
7067761Smsmithdevclass_t acpi_timer_devclass;
7167761SmsmithDRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0);
7267761Smsmith
7367761Smsmithstatic void
7467761Smsmithacpi_timer_identify(driver_t *driver, device_t parent)
7567761Smsmith{
7669458Smsmith    device_t			dev;
7769458Smsmith    char			desc[40];
7867761Smsmith
7977432Smsmith    FUNCTION_TRACE(__func__);
8069744Smsmith
8169744Smsmith    if (acpi_disabled("timer"))
8269744Smsmith	return_VOID;
8369744Smsmith
8471872Smsmith    if (AcpiGbl_FADT == NULL)
8569744Smsmith	return_VOID;
8671872Smsmith
8767761Smsmith    if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_timer", 0)) == NULL) {
8867761Smsmith	device_printf(parent, "could not add acpi_timer0\n");
8969744Smsmith	return_VOID;
9067761Smsmith    }
9167761Smsmith    if (acpi_set_magic(dev, ACPITIMER_MAGIC)) {
9267761Smsmith	device_printf(dev, "could not set magic\n");
9369744Smsmith	return_VOID;
9467761Smsmith    }
9567761Smsmith
9671872Smsmith    sprintf(desc, "%d-bit timer at 3.579545MHz", AcpiGbl_FADT->TmrValExt ? 32 : 24);
9767761Smsmith    device_set_desc_copy(dev, desc);
9869744Smsmith
9969744Smsmith    return_VOID;
10067761Smsmith}
10167761Smsmith
10267761Smsmithstatic int
10367761Smsmithacpi_timer_probe(device_t dev)
10467761Smsmith{
10567761Smsmith    if (acpi_get_magic(dev) == ACPITIMER_MAGIC)
10667761Smsmith	return(0);
10767761Smsmith    return(ENXIO);
10867761Smsmith}
10967761Smsmith
11067761Smsmithstatic int
11167761Smsmithacpi_timer_attach(device_t dev)
11267761Smsmith{
11367761Smsmith    struct acpi_timer_softc		*sc;
11467761Smsmith
11577432Smsmith    FUNCTION_TRACE(__func__);
11669744Smsmith
11767761Smsmith    sc = device_get_softc(dev);
11867761Smsmith    sc->tm_dev = dev;
11967761Smsmith
12069744Smsmith    return_VALUE(0);
12167761Smsmith}
122