acpi_timer.c revision 71872
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *	$FreeBSD: head/sys/dev/acpica/acpi_timer.c 71872 2001-01-31 09:30:57Z msmith $
28 */
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/bus.h>
34
35#include "acpi.h"
36
37#include <dev/acpica/acpivar.h>
38
39/*
40 * Hooks for the ACPI CA debugging infrastructure
41 */
42#define _COMPONENT	SYSTEM_CONTROL
43MODULE_NAME("TIMER")
44
45#define ACPITIMER_MAGIC 0x524d4954	/* "TIMR" */
46
47struct acpi_timer_softc {
48    device_t	tm_dev;
49};
50
51static void	acpi_timer_identify(driver_t *driver, device_t parent);
52static int	acpi_timer_probe(device_t dev);
53static int	acpi_timer_attach(device_t dev);
54
55static device_method_t acpi_timer_methods[] = {
56    /* Device interface */
57    DEVMETHOD(device_identify,	acpi_timer_identify),
58    DEVMETHOD(device_probe,	acpi_timer_probe),
59    DEVMETHOD(device_attach,	acpi_timer_attach),
60
61    {0, 0}
62};
63
64static driver_t acpi_timer_driver = {
65    "acpi_timer",
66    acpi_timer_methods,
67    sizeof(struct acpi_timer_softc),
68};
69
70devclass_t acpi_timer_devclass;
71DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0);
72
73static void
74acpi_timer_identify(driver_t *driver, device_t parent)
75{
76    device_t			dev;
77    char			desc[40];
78
79    FUNCTION_TRACE(__FUNCTION__);
80
81    if (acpi_disabled("timer"))
82	return_VOID;
83
84    if (AcpiGbl_FADT == NULL)
85	return_VOID;
86
87    if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_timer", 0)) == NULL) {
88	device_printf(parent, "could not add acpi_timer0\n");
89	return_VOID;
90    }
91    if (acpi_set_magic(dev, ACPITIMER_MAGIC)) {
92	device_printf(dev, "could not set magic\n");
93	return_VOID;
94    }
95
96    sprintf(desc, "%d-bit timer at 3.579545MHz", AcpiGbl_FADT->TmrValExt ? 32 : 24);
97    device_set_desc_copy(dev, desc);
98
99    return_VOID;
100}
101
102static int
103acpi_timer_probe(device_t dev)
104{
105    if (acpi_get_magic(dev) == ACPITIMER_MAGIC)
106	return(0);
107    return(ENXIO);
108}
109
110static int
111acpi_timer_attach(device_t dev)
112{
113    struct acpi_timer_softc		*sc;
114
115    FUNCTION_TRACE(__FUNCTION__);
116
117    sc = device_get_softc(dev);
118    sc->tm_dev = dev;
119
120    return_VALUE(0);
121}
122