]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/dev/uart/uart_bus_ocp.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / dev / uart / uart_bus_ocp.c
1 /*-
2  * Copyright 2006 by Juniper Networks.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35 #include <sys/conf.h>
36 #include <sys/kernel.h>
37 #include <sys/lock.h>
38 #include <sys/malloc.h>
39 #include <sys/module.h>
40 #include <sys/tty.h>
41 #include <machine/bus.h>
42
43 #include <machine/ocpbus.h>
44
45 #include <dev/uart/uart.h>
46 #include <dev/uart/uart_bus.h>
47
48 static int uart_ocp_probe(device_t);
49
50 static device_method_t uart_ocp_methods[] = {
51         /* Device interface */
52         DEVMETHOD(device_probe,         uart_ocp_probe),
53         DEVMETHOD(device_attach,        uart_bus_attach),
54         DEVMETHOD(device_detach,        uart_bus_detach),
55         { 0, 0 }
56 };
57
58 static driver_t uart_ocp_driver = {
59         uart_driver_name,
60         uart_ocp_methods,
61         sizeof(struct uart_softc),
62 };
63
64 static int
65 uart_ocp_probe(device_t dev)
66 {
67         device_t parent;
68         struct uart_softc *sc;
69         uintptr_t clock, devtype;
70         int error;
71
72         parent = device_get_parent(dev);
73
74         error = BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_DEVTYPE, &devtype);
75         if (error)
76                 return (error);
77         if (devtype != OCPBUS_DEVTYPE_UART)
78                 return (ENXIO);
79
80         sc = device_get_softc(dev);
81         sc->sc_class = &uart_ns8250_class;
82
83         if (BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_CLOCK, &clock))
84                 clock = 0;
85         return (uart_bus_probe(dev, 0, clock, 0, 0));
86 }
87
88 DRIVER_MODULE(uart, ocpbus, uart_ocp_driver, uart_devclass, 0, 0);