1194140Simp/*- 2194140Simp * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org> 3194140Simp * All rights reserved. 4194140Simp * 5194140Simp * Redistribution and use in source and binary forms, with or without 6194140Simp * modification, are permitted provided that the following conditions 7194140Simp * are met: 8194140Simp * 1. Redistributions of source code must retain the above copyright 9194140Simp * notice, this list of conditions and the following disclaimer. 10194140Simp * 2. Redistributions in binary form must reproduce the above copyright 11194140Simp * notice, this list of conditions and the following disclaimer in the 12194140Simp * documentation and/or other materials provided with the distribution. 13194140Simp * 14194140Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15194140Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16194140Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17194140Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18194140Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19194140Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20194140Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21194140Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22194140Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23194140Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24194140Simp * $Id$ 25194140Simp */ 26194140Simp/* 27194140Simp * Skeleton of this file was based on respective code for ARM 28194140Simp * code written by Olivier Houchard. 29194140Simp */ 30194140Simp 31194140Simp/* 32194140Simp * XXXMIPS: This file is hacked from arm/... . XXXMIPS here means this file is 33194140Simp * experimental and was written for MIPS32 port. 34194140Simp */ 35194140Simp#include "opt_uart.h" 36194140Simp 37194140Simp#include <sys/cdefs.h> 38194140Simp__FBSDID("$FreeBSD$"); 39194140Simp 40194140Simp#include <sys/param.h> 41194140Simp#include <sys/systm.h> 42194140Simp#include <sys/bus.h> 43194140Simp#include <sys/conf.h> 44194140Simp#include <sys/kernel.h> 45194140Simp#include <sys/module.h> 46194140Simp#include <machine/bus.h> 47194140Simp#include <sys/rman.h> 48194140Simp#include <machine/resource.h> 49194140Simp 50194140Simp#include <dev/pci/pcivar.h> 51194140Simp 52194140Simp#include <dev/uart/uart.h> 53194140Simp#include <dev/uart/uart_bus.h> 54194140Simp#include <dev/uart/uart_cpu.h> 55194140Simp 56202867Simp#include <mips/cavium/octeon_pcmap_regs.h> 57194140Simp 58210311Sjmallett#include <contrib/octeon-sdk/cvmx.h> 59210311Sjmallett 60194140Simp#include "uart_if.h" 61194140Simp 62194175Simpextern struct uart_class uart_oct16550_class; 63194175Simp 64194140Simpstatic int uart_octeon_probe(device_t dev); 65194140Simp 66194140Simpstatic device_method_t uart_octeon_methods[] = { 67194140Simp /* Device interface */ 68194175Simp DEVMETHOD(device_probe, uart_octeon_probe), 69194175Simp DEVMETHOD(device_attach, uart_bus_attach), 70194175Simp DEVMETHOD(device_detach, uart_bus_detach), 71194175Simp {0, 0} 72194140Simp}; 73194140Simp 74194140Simpstatic driver_t uart_octeon_driver = { 75194140Simp uart_driver_name, 76194140Simp uart_octeon_methods, 77194140Simp sizeof(struct uart_softc), 78194140Simp}; 79194140Simp 80194175Simpextern 81194175SimpSLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; 82199592Simp 83199592Simpstatic int 84199592Simpuart_octeon_probe(device_t dev) 85194140Simp{ 86194140Simp struct uart_softc *sc; 87194175Simp int unit; 88194140Simp 89194175Simp unit = device_get_unit(dev); 90194140Simp sc = device_get_softc(dev); 91199738Simp sc->sc_class = &uart_oct16550_class; 92199738Simp 93199738Simp /* 94199738Simp * We inherit the settings from the systme console. Note, the bst 95199738Simp * bad bus_space_map are bogus here, but obio doesn't yet support 96199738Simp * them, it seems. 97199738Simp */ 98194175Simp sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs); 99194175Simp bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas)); 100199738Simp sc->sc_bas.bst = uart_bus_space_mem; 101210311Sjmallett /* 102210311Sjmallett * XXX 103213345Sjmallett * RBR isn't really a great base address. 104210311Sjmallett */ 105213345Sjmallett if (bus_space_map(sc->sc_bas.bst, CVMX_MIO_UARTX_RBR(0), 106213345Sjmallett uart_getrange(sc->sc_class), 0, &sc->sc_bas.bsh) != 0) 107199738Simp return (ENXIO); 108194175Simp return (uart_bus_probe(dev, sc->sc_bas.regshft, 0, 0, unit)); 109194140Simp} 110194140Simp 111194140SimpDRIVER_MODULE(uart, obio, uart_octeon_driver, uart_devclass, 0, 0); 112