uart_bus_puc.c revision 119815
1119815Smarcel/*-
2119815Smarcel * Copyright (c) 2002 JF Hay.  All rights reserved.
3119815Smarcel * Copyright (c) 2001 M. Warner Losh.  All rights reserved.
4119815Smarcel *
5119815Smarcel * Redistribution and use in source and binary forms, with or without
6119815Smarcel * modification, are permitted provided that the following conditions
7119815Smarcel * are met:
8119815Smarcel * 1. Redistributions of source code must retain the above copyright
9119815Smarcel *    notice, this list of conditions and the following disclaimer.
10119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11119815Smarcel *    notice, this list of conditions and the following disclaimer in the
12119815Smarcel *    documentation and/or other materials provided with the distribution.
13119815Smarcel *
14119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24119815Smarcel */
25119815Smarcel
26119815Smarcel#include <sys/cdefs.h>
27119815Smarcel__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_puc.c 119815 2003-09-06 23:13:47Z marcel $");
28119815Smarcel
29119815Smarcel#include <sys/param.h>
30119815Smarcel#include <sys/systm.h>
31119815Smarcel#include <sys/bus.h>
32119815Smarcel#include <sys/conf.h>
33119815Smarcel#include <sys/kernel.h>
34119815Smarcel#include <sys/module.h>
35119815Smarcel#include <machine/bus.h>
36119815Smarcel#include <sys/rman.h>
37119815Smarcel#include <machine/resource.h>
38119815Smarcel
39119815Smarcel#include <dev/pci/pcivar.h>
40119815Smarcel#include <dev/puc/pucvar.h>
41119815Smarcel
42119815Smarcel#include <dev/uart/uart.h>
43119815Smarcel#include <dev/uart/uart_bus.h>
44119815Smarcel
45119815Smarcelstatic int uart_puc_probe(device_t dev);
46119815Smarcel
47119815Smarcelstatic device_method_t uart_puc_methods[] = {
48119815Smarcel	/* Device interface */
49119815Smarcel	DEVMETHOD(device_probe,		uart_puc_probe),
50119815Smarcel	DEVMETHOD(device_attach,	uart_bus_attach),
51119815Smarcel	DEVMETHOD(device_detach,	uart_bus_detach),
52119815Smarcel	{ 0, 0 }
53119815Smarcel};
54119815Smarcel
55119815Smarcelstatic driver_t uart_puc_driver = {
56119815Smarcel	uart_driver_name,
57119815Smarcel	uart_puc_methods,
58119815Smarcel	sizeof(struct uart_softc),
59119815Smarcel};
60119815Smarcel
61119815Smarcelstatic int
62119815Smarceluart_puc_probe(device_t dev)
63119815Smarcel{
64119815Smarcel	device_t parent;
65119815Smarcel	struct uart_softc *sc;
66119815Smarcel	uintptr_t rclk, regshft, type;
67119815Smarcel
68119815Smarcel	parent = device_get_parent(dev);
69119815Smarcel	sc = device_get_softc(dev);
70119815Smarcel
71119815Smarcel	if (BUS_READ_IVAR(parent, dev, PUC_IVAR_SUBTYPE, &type))
72119815Smarcel		return (ENXIO);
73119815Smarcel	switch (type) {
74119815Smarcel	case PUC_PORT_UART_NS8250:
75119815Smarcel		sc->sc_class = &uart_ns8250_class;
76119815Smarcel		break;
77119815Smarcel	case PUC_PORT_UART_SAB82532:
78119815Smarcel		sc->sc_class = &uart_sab82532_class;
79119815Smarcel		break;
80119815Smarcel	case PUC_PORT_UART_Z8530:
81119815Smarcel		sc->sc_class = &uart_z8530_class;
82119815Smarcel		break;
83119815Smarcel	default:
84119815Smarcel		return (ENXIO);
85119815Smarcel	}
86119815Smarcel
87119815Smarcel	if (BUS_READ_IVAR(parent, dev, PUC_IVAR_FREQ, &rclk))
88119815Smarcel		rclk = 0;
89119815Smarcel	if (BUS_READ_IVAR(parent, dev, PUC_IVAR_REGSHFT, &regshft))
90119815Smarcel		regshft = 0;
91119815Smarcel	return (uart_bus_probe(dev, regshft, rclk, 0));
92119815Smarcel}
93119815Smarcel
94119815SmarcelDRIVER_MODULE(uart, puc, uart_puc_driver, uart_devclass, 0, 0);
95