1171626Scognet/*-
2171626Scognet * Copyright (c) 2004 Olivier Houchard.  All rights reserved.
3171626Scognet *
4171626Scognet * Redistribution and use in source and binary forms, with or without
5171626Scognet * modification, are permitted provided that the following conditions
6171626Scognet * are met:
7171626Scognet * 1. Redistributions of source code must retain the above copyright
8171626Scognet *    notice, this list of conditions and the following disclaimer.
9171626Scognet * 2. Redistributions in binary form must reproduce the above copyright
10171626Scognet *    notice, this list of conditions and the following disclaimer in the
11171626Scognet *    documentation and/or other materials provided with the distribution.
12171626Scognet *
13171626Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14171626Scognet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15171626Scognet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16171626Scognet * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17171626Scognet * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18171626Scognet * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19171626Scognet * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20171626Scognet * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21171626Scognet * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22171626Scognet * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23171626Scognet */
24171626Scognet
25171626Scognet#include <sys/cdefs.h>
26171626Scognet__FBSDID("$FreeBSD$");
27171626Scognet
28171626Scognet#include <sys/param.h>
29171626Scognet#include <sys/systm.h>
30171626Scognet#include <sys/bus.h>
31171626Scognet#include <sys/conf.h>
32171626Scognet#include <sys/kernel.h>
33171626Scognet#include <sys/module.h>
34171626Scognet#include <machine/bus.h>
35171626Scognet#include <sys/rman.h>
36171626Scognet#include <machine/resource.h>
37171626Scognet
38171626Scognet#include <dev/pci/pcivar.h>
39171626Scognet
40171626Scognet#include <dev/uart/uart.h>
41171626Scognet#include <dev/uart/uart_bus.h>
42171626Scognet#include <dev/uart/uart_cpu.h>
43171626Scognet
44171626Scognet#include <dev/ic/ns16550.h>
45171626Scognet
46171626Scognet#include "uart_if.h"
47171626Scognet
48171626Scognetstatic int uart_i81342_probe(device_t dev);
49171626Scognet
50171626Scognetstatic device_method_t uart_i81342_methods[] = {
51171626Scognet	/* Device interface */
52171626Scognet	DEVMETHOD(device_probe,		uart_i81342_probe),
53171626Scognet	DEVMETHOD(device_attach,	uart_bus_attach),
54171626Scognet	DEVMETHOD(device_detach,	uart_bus_detach),
55171626Scognet	{ 0, 0 }
56171626Scognet};
57171626Scognet
58171626Scognetstatic driver_t uart_i81342_driver = {
59171626Scognet	uart_driver_name,
60171626Scognet	uart_i81342_methods,
61171626Scognet	sizeof(struct uart_softc),
62171626Scognet};
63171626Scognet
64171626Scognetextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
65171626Scognetstatic int
66171626Scognetuart_i81342_probe(device_t dev)
67171626Scognet{
68171626Scognet	struct uart_softc *sc;
69171626Scognet	int err;
70171626Scognet
71171626Scognet	sc = device_get_softc(dev);
72171626Scognet	sc->sc_class = &uart_ns8250_class;
73171626Scognet	if (device_get_unit(dev) == 0) {
74171626Scognet		sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs);
75171626Scognet		bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas));
76171626Scognet	}
77171626Scognet	sc->sc_rres = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->sc_rrid,
78171626Scognet            0, ~0, uart_getrange(sc->sc_class), RF_ACTIVE);
79171626Scognet
80171626Scognet	sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres);
81171626Scognet	sc->sc_bas.bst = rman_get_bustag(sc->sc_rres);
82171626Scognet	bus_space_write_4(sc->sc_bas.bst, sc->sc_bas.bsh, REG_IER << 2,
83171626Scognet	    0x40 | 0x10);
84171626Scognet        bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres);
85171626Scognet
86171626Scognet	err = uart_bus_probe(dev, 2, 33334000, 0, device_get_unit(dev));
87171626Scognet	sc->sc_rxfifosz = sc->sc_txfifosz = 1;
88171626Scognet	return (err);
89171626Scognet}
90171626Scognet
91171626Scognet
92171626ScognetDRIVER_MODULE(uart, obio, uart_i81342_driver, uart_devclass, 0, 0);
93