1178173Simp/*-
2178173Simp * Copyright (c) 2007 Bruce M. Simpson.
3178173Simp * All rights reserved.
4178173Simp *
5178173Simp * Redistribution and use in source and binary forms, with or without
6178173Simp * modification, are permitted provided that the following conditions
7178173Simp * are met:
8178173Simp * 1. Redistributions of source code must retain the above copyright
9178173Simp *    notice, this list of conditions and the following disclaimer.
10178173Simp * 2. Redistributions in binary form must reproduce the above copyright
11178173Simp *    notice, this list of conditions and the following disclaimer in the
12178173Simp *    documentation and/or other materials provided with the distribution.
13178173Simp *
14178173Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15178173Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16178173Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17178173Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18178173Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19178173Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20178173Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21178173Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22178173Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23178173Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24178173Simp * $Id$
25178173Simp */
26178173Simp/*
27178173Simp * Skeleton of this file was based on respective code for ARM
28178173Simp * code written by Olivier Houchard.
29178173Simp */
30178173Simp
31178173Simp/*
32178173Simp * XXXMIPS: This file is hacked from arm/... . XXXMIPS here means this file is
33178173Simp * experimental and was written for MIPS32 port.
34178173Simp */
35178173Simp#include "opt_uart.h"
36178173Simp
37178173Simp#include <sys/cdefs.h>
38178173Simp__FBSDID("$FreeBSD: stable/11/sys/mips/idt/uart_bus_rc32434.c 340145 2018-11-04 23:28:56Z mmacy $");
39178173Simp
40178173Simp#include <sys/param.h>
41178173Simp#include <sys/systm.h>
42178173Simp#include <sys/bus.h>
43178173Simp#include <sys/conf.h>
44178173Simp#include <sys/kernel.h>
45178173Simp#include <sys/module.h>
46178173Simp#include <machine/bus.h>
47178173Simp#include <sys/rman.h>
48178173Simp#include <machine/resource.h>
49182901Sgonzo#include <mips/idt/idtreg.h>
50178173Simp
51178173Simp#include <dev/pci/pcivar.h>
52178173Simp
53178173Simp#include <dev/uart/uart.h>
54178173Simp#include <dev/uart/uart_bus.h>
55178173Simp#include <dev/uart/uart_cpu.h>
56178173Simp
57178173Simp#include <dev/ic/ns16550.h>
58178173Simp
59178173Simp#include "uart_if.h"
60178173Simp
61178173Simpstatic int uart_rc32434_probe(device_t dev);
62178173Simp
63178173Simpextern struct uart_class uart_rc32434_uart_class;
64178173Simp
65178173Simpstatic device_method_t uart_rc32434_methods[] = {
66178173Simp	/* Device interface */
67178173Simp	DEVMETHOD(device_probe,		uart_rc32434_probe),
68178173Simp	DEVMETHOD(device_attach,	uart_bus_attach),
69178173Simp	DEVMETHOD(device_detach,	uart_bus_detach),
70178173Simp	{ 0, 0 }
71178173Simp};
72178173Simp
73178173Simpstatic driver_t uart_rc32434_driver = {
74178173Simp	uart_driver_name,
75178173Simp	uart_rc32434_methods,
76178173Simp	sizeof(struct uart_softc),
77178173Simp};
78178173Simp
79178173Simpextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
80178173Simp
81178173Simpstatic int
82178173Simpuart_rc32434_probe(device_t dev)
83178173Simp{
84178173Simp	struct uart_softc *sc;
85178173Simp
86178173Simp	sc = device_get_softc(dev);
87178173Simp	sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs);
88178173Simp	sc->sc_class = &uart_ns8250_class;
89178173Simp	bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas));
90178173Simp	sc->sc_sysdev->bas.regshft = 2;
91202027Simp	sc->sc_sysdev->bas.bst = mips_bus_space_generic;
92178173Simp	sc->sc_sysdev->bas.bsh = MIPS_PHYS_TO_KSEG1(IDT_BASE_UART0);
93178173Simp	sc->sc_bas.regshft = 2;
94202027Simp	sc->sc_bas.bst = mips_bus_space_generic;
95178173Simp	sc->sc_bas.bsh = MIPS_PHYS_TO_KSEG1(IDT_BASE_UART0);
96178173Simp
97340145Smmacy	return (uart_bus_probe(dev, 2, 0, 330000000UL/2, 0, 0, 0));
98178173Simp}
99178173Simp
100178173SimpDRIVER_MODULE(uart, obio, uart_rc32434_driver, uart_devclass, 0, 0);
101