uart_bus_scc.c revision 157299
1/*- 2 * Copyright (c) 2004-2006 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_scc.c 157299 2006-03-30 18:33:22Z marcel $"); 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/conf.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36 37#include <machine/bus.h> 38#include <sys/rman.h> 39#include <machine/resource.h> 40 41#include <dev/scc/scc_bus.h> 42 43#include <dev/uart/uart.h> 44#include <dev/uart/uart_bus.h> 45 46static int uart_scc_attach(device_t dev); 47static int uart_scc_probe(device_t dev); 48 49static device_method_t uart_scc_methods[] = { 50 /* Device interface */ 51 DEVMETHOD(device_probe, uart_scc_probe), 52 DEVMETHOD(device_attach, uart_scc_attach), 53 DEVMETHOD(device_detach, uart_bus_detach), 54 /* Serdev interface */ 55 DEVMETHOD(serdev_ihand, uart_bus_ihand), 56 DEVMETHOD(serdev_sysdev, uart_bus_sysdev), 57 { 0, 0 } 58}; 59 60static driver_t uart_scc_driver = { 61 uart_driver_name, 62 uart_scc_methods, 63 sizeof(struct uart_softc), 64}; 65 66static int 67uart_scc_attach(device_t dev) 68{ 69 device_t parent; 70 struct uart_softc *sc; 71 uintptr_t mtx; 72 73 parent = device_get_parent(dev); 74 sc = device_get_softc(dev); 75 76 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_HWMTX, &mtx)) 77 return (ENXIO); 78 sc->sc_hwmtx = (struct mtx *)(void *)mtx; 79 return (uart_bus_attach(dev)); 80} 81 82static int 83uart_scc_probe(device_t dev) 84{ 85 device_t parent; 86 struct uart_softc *sc; 87 uintptr_t ch, cl, md, rs; 88 89 parent = device_get_parent(dev); 90 sc = device_get_softc(dev); 91 92 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_MODE, &md) || 93 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLASS, &cl)) 94 return (ENXIO); 95 if (md != SCC_MODE_ASYNC) 96 return (ENXIO); 97 switch (cl) { 98 case SCC_CLASS_SAB82532: 99 sc->sc_class = &uart_sab82532_class; 100 break; 101 case SCC_CLASS_Z8530: 102 sc->sc_class = &uart_z8530_class; 103 break; 104 default: 105 return (ENXIO); 106 } 107 if (BUS_READ_IVAR(parent, dev, SCC_IVAR_CHANNEL, &ch) || 108 BUS_READ_IVAR(parent, dev, SCC_IVAR_CLOCK, &cl) || 109 BUS_READ_IVAR(parent, dev, SCC_IVAR_REGSHFT, &rs)) 110 return (ENXIO); 111 112 return (uart_bus_probe(dev, rs, cl, 0, ch)); 113} 114 115DRIVER_MODULE(uart, scc, uart_scc_driver, uart_devclass, 0, 0); 116