uart_iobus.c revision 103620
1103620Sgrehan/*
2103620Sgrehan * Copyright 2002 by Peter Grehan. All rights reserved.
3103620Sgrehan *
4103620Sgrehan * Redistribution and use in source and binary forms, with or without
5103620Sgrehan * modification, are permitted provided that the following conditions
6103620Sgrehan * are met:
7103620Sgrehan * 1. Redistributions of source code must retain the above copyright
8103620Sgrehan *    notice, this list of conditions and the following disclaimer.
9103620Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
10103620Sgrehan *    notice, this list of conditions and the following disclaimer in the
11103620Sgrehan *    documentation and/or other materials provided with the distribution.
12103620Sgrehan * 3. The name of the author may not be used to endorse or promote products
13103620Sgrehan *    derived from this software without specific prior written permission.
14103620Sgrehan *
15103620Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16103620Sgrehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17103620Sgrehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18103620Sgrehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19103620Sgrehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20103620Sgrehan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21103620Sgrehan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22103620Sgrehan * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23103620Sgrehan * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24103620Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25103620Sgrehan * SUCH DAMAGE.
26103620Sgrehan *
27103620Sgrehan * $FreeBSD: head/sys/powerpc/psim/uart_iobus.c 103620 2002-09-19 04:57:10Z grehan $
28103620Sgrehan */
29103620Sgrehan
30103620Sgrehan/*
31103620Sgrehan * PSIM local bus 16550
32103620Sgrehan */
33103620Sgrehan
34103620Sgrehan#include <sys/param.h>
35103620Sgrehan#include <sys/systm.h>
36103620Sgrehan#include <sys/bus.h>
37103620Sgrehan#include <sys/conf.h>
38103620Sgrehan#include <sys/kernel.h>
39103620Sgrehan#include <sys/lock.h>
40103620Sgrehan#include <sys/malloc.h>
41103620Sgrehan#include <sys/mutex.h>
42103620Sgrehan#include <sys/module.h>
43103620Sgrehan#include <sys/tty.h>
44103620Sgrehan#include <machine/bus_pio.h>
45103620Sgrehan#include <machine/bus.h>
46103620Sgrehan#include <sys/timepps.h>
47103620Sgrehan
48103620Sgrehan#include <dev/ofw/openfirm.h>
49103620Sgrehan#include <powerpc/psim/iobusvar.h>
50103620Sgrehan
51103620Sgrehan#include <dev/sio/sioreg.h>
52103620Sgrehan#include <dev/sio/siovar.h>
53103620Sgrehan
54103620Sgrehan#include <isa/isavar.h>  /* for isa_irq_pending() prototype */
55103620Sgrehan
56103620Sgrehanstatic  int     sio_iobus_attach(device_t dev);
57103620Sgrehanstatic  int     sio_iobus_probe(device_t dev);
58103620Sgrehan
59103620Sgrehanstatic device_method_t sio_iobus_methods[] = {
60103620Sgrehan        /* Device interface */
61103620Sgrehan	DEVMETHOD(device_probe,         sio_iobus_probe),
62103620Sgrehan	DEVMETHOD(device_attach,        sio_iobus_attach),
63103620Sgrehan
64103620Sgrehan	{ 0, 0 }
65103620Sgrehan};
66103620Sgrehan
67103620Sgrehanstatic driver_t sio_iobus_driver = {
68103620Sgrehan	sio_driver_name,
69103620Sgrehan	sio_iobus_methods,
70103620Sgrehan	0,
71103620Sgrehan};
72103620Sgrehan
73103620Sgrehanstatic int
74103620Sgrehansio_iobus_attach(device_t dev)
75103620Sgrehan{
76103620Sgrehan	return (sioattach(dev, 0, DEFAULT_RCLK));
77103620Sgrehan}
78103620Sgrehan
79103620Sgrehanstatic int
80103620Sgrehansio_iobus_probe(device_t dev)
81103620Sgrehan{
82103620Sgrehan	char *type = iobus_get_name(dev);
83103620Sgrehan
84103620Sgrehan	if (strncmp(type, "com", 3) != 0)
85103620Sgrehan		return (ENXIO);
86103620Sgrehan
87103620Sgrehan
88103620Sgrehan	device_set_desc(dev, "PSIM serial port");
89103620Sgrehan
90103620Sgrehan	/*
91103620Sgrehan	 * Call sioprobe with noprobe=1, to avoid hitting a psim bug
92103620Sgrehan	 */
93103620Sgrehan	return (sioprobe(dev, 0, 0, 1));
94103620Sgrehan}
95103620Sgrehan
96103620SgrehanDRIVER_MODULE(sio, iobus, sio_iobus_driver, sio_devclass, 0, 0);
97103620Sgrehan
98103620Sgrehan/*
99103620Sgrehan * Stub function. Perhaps a way to get this to work correctly would
100103620Sgrehan * be for child devices to set a field in the dev structure to
101103620Sgrehan * inform the parent that they are isa devices, and then use a
102103620Sgrehan * intr_pending() call which would propagate up to nexus to see
103103620Sgrehan * if the interrupt controller had any intrs in the isa group set
104103620Sgrehan */
105103620Sgrehanintrmask_t
106103620Sgrehanisa_irq_pending(void)
107103620Sgrehan{
108103620Sgrehan	return (0);
109103620Sgrehan}
110