xref: /freebsd/sys/powerpc/psim/uart_iobus.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
160727d8bSWarner Losh /*-
271e3c308SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
371e3c308SPedro F. Giffuni  *
48860e8c6SPeter Grehan  * Copyright 2002 by Peter Grehan. All rights reserved.
58860e8c6SPeter Grehan  *
68860e8c6SPeter Grehan  * Redistribution and use in source and binary forms, with or without
78860e8c6SPeter Grehan  * modification, are permitted provided that the following conditions
88860e8c6SPeter Grehan  * are met:
98860e8c6SPeter Grehan  * 1. Redistributions of source code must retain the above copyright
108860e8c6SPeter Grehan  *    notice, this list of conditions and the following disclaimer.
118860e8c6SPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
128860e8c6SPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
138860e8c6SPeter Grehan  *    documentation and/or other materials provided with the distribution.
148860e8c6SPeter Grehan  * 3. The name of the author may not be used to endorse or promote products
158860e8c6SPeter Grehan  *    derived from this software without specific prior written permission.
168860e8c6SPeter Grehan  *
178860e8c6SPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188860e8c6SPeter Grehan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198860e8c6SPeter Grehan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
208860e8c6SPeter Grehan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
218860e8c6SPeter Grehan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
228860e8c6SPeter Grehan  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
238860e8c6SPeter Grehan  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
248860e8c6SPeter Grehan  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
258860e8c6SPeter Grehan  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
268860e8c6SPeter Grehan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
278860e8c6SPeter Grehan  * SUCH DAMAGE.
288860e8c6SPeter Grehan  */
298860e8c6SPeter Grehan 
308860e8c6SPeter Grehan /*
318860e8c6SPeter Grehan  * PSIM local bus 16550
328860e8c6SPeter Grehan  */
338860e8c6SPeter Grehan 
348860e8c6SPeter Grehan #include <sys/param.h>
358860e8c6SPeter Grehan #include <sys/systm.h>
368860e8c6SPeter Grehan #include <sys/bus.h>
378860e8c6SPeter Grehan #include <sys/conf.h>
388860e8c6SPeter Grehan #include <sys/kernel.h>
398860e8c6SPeter Grehan #include <sys/lock.h>
408860e8c6SPeter Grehan #include <sys/malloc.h>
418860e8c6SPeter Grehan #include <sys/mutex.h>
428860e8c6SPeter Grehan #include <sys/module.h>
438860e8c6SPeter Grehan #include <machine/bus.h>
448860e8c6SPeter Grehan #include <sys/timepps.h>
458860e8c6SPeter Grehan 
468860e8c6SPeter Grehan #include <dev/ofw/openfirm.h>
478860e8c6SPeter Grehan #include <powerpc/psim/iobusvar.h>
488860e8c6SPeter Grehan 
493c1cfa96SMarcel Moolenaar #include <dev/uart/uart.h>
503c1cfa96SMarcel Moolenaar #include <dev/uart/uart_bus.h>
518860e8c6SPeter Grehan 
523c1cfa96SMarcel Moolenaar static int uart_iobus_probe(device_t dev);
538860e8c6SPeter Grehan 
543c1cfa96SMarcel Moolenaar static device_method_t uart_iobus_methods[] = {
558860e8c6SPeter Grehan         /* Device interface */
563c1cfa96SMarcel Moolenaar 	DEVMETHOD(device_probe,		uart_iobus_probe),
573c1cfa96SMarcel Moolenaar 	DEVMETHOD(device_attach,	uart_bus_attach),
583c1cfa96SMarcel Moolenaar 	DEVMETHOD(device_detach,	uart_bus_detach),
598860e8c6SPeter Grehan 	{ 0, 0 }
608860e8c6SPeter Grehan };
618860e8c6SPeter Grehan 
623c1cfa96SMarcel Moolenaar static driver_t uart_iobus_driver = {
633c1cfa96SMarcel Moolenaar 	uart_driver_name,
643c1cfa96SMarcel Moolenaar 	uart_iobus_methods,
653c1cfa96SMarcel Moolenaar 	sizeof(struct uart_softc),
668860e8c6SPeter Grehan };
678860e8c6SPeter Grehan 
688860e8c6SPeter Grehan static int
uart_iobus_probe(device_t dev)693c1cfa96SMarcel Moolenaar uart_iobus_probe(device_t dev)
708860e8c6SPeter Grehan {
713c1cfa96SMarcel Moolenaar 	struct uart_softc *sc;
723c1cfa96SMarcel Moolenaar 	char *type;
738860e8c6SPeter Grehan 
743c1cfa96SMarcel Moolenaar 	type = iobus_get_name(dev);
758860e8c6SPeter Grehan 	if (strncmp(type, "com", 3) != 0)
768860e8c6SPeter Grehan 		return (ENXIO);
778860e8c6SPeter Grehan 
783c1cfa96SMarcel Moolenaar 	sc = device_get_softc(dev);
793c1cfa96SMarcel Moolenaar 	sc->sc_class = &uart_ns8250_class;
808860e8c6SPeter Grehan 
818860e8c6SPeter Grehan 	device_set_desc(dev, "PSIM serial port");
82381388b9SMatt Macy 	return (uart_bus_probe(dev, 0, 0, 0, 0, 0, 0));
838860e8c6SPeter Grehan }
848860e8c6SPeter Grehan 
85*c90ea831SJohn Baldwin DRIVER_MODULE(uart, iobus, uart_iobus_driver, 0, 0);
86