1119815Smarcel/*-
2158124Smarcel * Copyright (c) 2006 Marcel Moolenaar.  All rights reserved.
3119815Smarcel * Copyright (c) 2002 JF Hay.  All rights reserved.
4119815Smarcel * Copyright (c) 2001 M. Warner Losh.  All rights reserved.
5119815Smarcel *
6119815Smarcel * Redistribution and use in source and binary forms, with or without
7119815Smarcel * modification, are permitted provided that the following conditions
8119815Smarcel * are met:
9119815Smarcel * 1. Redistributions of source code must retain the above copyright
10119815Smarcel *    notice, this list of conditions and the following disclaimer.
11119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12119815Smarcel *    notice, this list of conditions and the following disclaimer in the
13119815Smarcel *    documentation and/or other materials provided with the distribution.
14119815Smarcel *
15119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25119815Smarcel */
26119815Smarcel
27119815Smarcel#include <sys/cdefs.h>
28119815Smarcel__FBSDID("$FreeBSD$");
29119815Smarcel
30119815Smarcel#include <sys/param.h>
31119815Smarcel#include <sys/systm.h>
32119815Smarcel#include <sys/bus.h>
33119815Smarcel#include <sys/conf.h>
34119815Smarcel#include <sys/kernel.h>
35119815Smarcel#include <sys/module.h>
36158124Smarcel
37119815Smarcel#include <machine/bus.h>
38119815Smarcel#include <sys/rman.h>
39119815Smarcel#include <machine/resource.h>
40119815Smarcel
41158124Smarcel#include <dev/puc/puc_bus.h>
42119815Smarcel
43119815Smarcel#include <dev/uart/uart.h>
44119815Smarcel#include <dev/uart/uart_bus.h>
45119815Smarcel
46119815Smarcelstatic int uart_puc_probe(device_t dev);
47119815Smarcel
48119815Smarcelstatic device_method_t uart_puc_methods[] = {
49119815Smarcel	/* Device interface */
50119815Smarcel	DEVMETHOD(device_probe,		uart_puc_probe),
51119815Smarcel	DEVMETHOD(device_attach,	uart_bus_attach),
52119815Smarcel	DEVMETHOD(device_detach,	uart_bus_detach),
53158124Smarcel	/* Serdev interface */
54158124Smarcel	DEVMETHOD(serdev_ihand,		uart_bus_ihand),
55158124Smarcel	DEVMETHOD(serdev_ipend,		uart_bus_ipend),
56119815Smarcel	{ 0, 0 }
57119815Smarcel};
58119815Smarcel
59119815Smarcelstatic driver_t uart_puc_driver = {
60119815Smarcel	uart_driver_name,
61119815Smarcel	uart_puc_methods,
62119815Smarcel	sizeof(struct uart_softc),
63119815Smarcel};
64119815Smarcel
65119815Smarcelstatic int
66119815Smarceluart_puc_probe(device_t dev)
67119815Smarcel{
68119815Smarcel	device_t parent;
69119815Smarcel	struct uart_softc *sc;
70158124Smarcel	uintptr_t rclk, type;
71119815Smarcel
72119815Smarcel	parent = device_get_parent(dev);
73119815Smarcel	sc = device_get_softc(dev);
74119815Smarcel
75158124Smarcel	if (BUS_READ_IVAR(parent, dev, PUC_IVAR_TYPE, &type))
76119815Smarcel		return (ENXIO);
77158124Smarcel	if (type != PUC_TYPE_SERIAL)
78119815Smarcel		return (ENXIO);
79119815Smarcel
80158124Smarcel	sc->sc_class = &uart_ns8250_class;
81158124Smarcel
82158124Smarcel	if (BUS_READ_IVAR(parent, dev, PUC_IVAR_CLOCK, &rclk))
83119815Smarcel		rclk = 0;
84158124Smarcel	return (uart_bus_probe(dev, 0, rclk, 0, 0));
85119815Smarcel}
86119815Smarcel
87119815SmarcelDRIVER_MODULE(uart, puc, uart_puc_driver, uart_devclass, 0, 0);
88