190731Sjhay/*- 290731Sjhay * Copyright (c) 2002 JF Hay. All rights reserved. 390731Sjhay * Copyright (c) 2001 M. Warner Losh. All rights reserved. 490731Sjhay * 590731Sjhay * Redistribution and use in source and binary forms, with or without 690731Sjhay * modification, are permitted provided that the following conditions 790731Sjhay * are met: 890731Sjhay * 1. Redistributions of source code must retain the above copyright 990731Sjhay * notice, this list of conditions and the following disclaimer. 1090731Sjhay * 2. Redistributions in binary form must reproduce the above copyright 1190731Sjhay * notice, this list of conditions and the following disclaimer in the 1290731Sjhay * documentation and/or other materials provided with the distribution. 1390731Sjhay * 1490731Sjhay * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1590731Sjhay * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1690731Sjhay * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1790731Sjhay * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1890731Sjhay * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1990731Sjhay * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2090731Sjhay * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2190731Sjhay * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2290731Sjhay * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2390731Sjhay * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2490731Sjhay */ 2590731Sjhay 2690731Sjhay#include <sys/cdefs.h> 2790731Sjhay__FBSDID("$FreeBSD$"); 2890731Sjhay 2990731Sjhay#include <sys/param.h> 3090731Sjhay#include <sys/systm.h> 3190731Sjhay#include <sys/bus.h> 3290731Sjhay#include <sys/conf.h> 3390731Sjhay#include <sys/kernel.h> 3490731Sjhay#include <sys/lock.h> 3590731Sjhay#include <sys/malloc.h> 3690731Sjhay#include <sys/mutex.h> 3790731Sjhay#include <sys/module.h> 3890731Sjhay#include <sys/tty.h> 3990731Sjhay#include <machine/bus.h> 4090731Sjhay#include <sys/timepps.h> 4190731Sjhay 42158124Smarcel#include <dev/puc/puc_bus.h> 43158124Smarcel 4490731Sjhay#include <dev/sio/siovar.h> 4590731Sjhay#include <dev/sio/sioreg.h> 4690731Sjhay 4792739Salfredstatic int sio_puc_attach(device_t dev); 4892739Salfredstatic int sio_puc_probe(device_t dev); 4990731Sjhay 5090731Sjhaystatic device_method_t sio_puc_methods[] = { 5190731Sjhay /* Device interface */ 5290731Sjhay DEVMETHOD(device_probe, sio_puc_probe), 5390731Sjhay DEVMETHOD(device_attach, sio_puc_attach), 54123910Simp DEVMETHOD(device_detach, siodetach), 5590731Sjhay 5690731Sjhay { 0, 0 } 5790731Sjhay}; 5890731Sjhay 5990731Sjhaystatic driver_t sio_puc_driver = { 6090731Sjhay sio_driver_name, 6190731Sjhay sio_puc_methods, 6290731Sjhay 0, 6390731Sjhay}; 6490731Sjhay 6590731Sjhaystatic int 66158124Smarcelsio_puc_attach(device_t dev) 6790731Sjhay{ 68106590Sjhb uintptr_t rclk; 6990731Sjhay 70158124Smarcel if (BUS_READ_IVAR(device_get_parent(dev), dev, PUC_IVAR_CLOCK, 7190731Sjhay &rclk) != 0) 7290731Sjhay rclk = DEFAULT_RCLK; 7390731Sjhay return (sioattach(dev, 0, rclk)); 7490731Sjhay} 7590731Sjhay 7690731Sjhaystatic int 77158124Smarcelsio_puc_probe(device_t dev) 7890731Sjhay{ 79158124Smarcel device_t parent; 80158124Smarcel uintptr_t rclk, type; 81158124Smarcel int error; 8290731Sjhay 83158124Smarcel parent = device_get_parent(dev); 84158124Smarcel 85158124Smarcel if (BUS_READ_IVAR(parent, dev, PUC_IVAR_TYPE, &type)) 86158124Smarcel return (ENXIO); 87158124Smarcel if (type != PUC_TYPE_SERIAL) 88158124Smarcel return (ENXIO); 89158124Smarcel 90158124Smarcel if (BUS_READ_IVAR(parent, dev, PUC_IVAR_CLOCK, &rclk)) 9190731Sjhay rclk = DEFAULT_RCLK; 9291875Snyan#ifdef PC98 9391875Snyan SET_FLAG(dev, SET_IFTYPE(COM_IF_NS16550)); 9491875Snyan#endif 95158124Smarcel error = sioprobe(dev, 0, rclk, 1); 96158124Smarcel return ((error > 0) ? error : BUS_PROBE_LOW_PRIORITY); 9790731Sjhay} 9890731Sjhay 9990731SjhayDRIVER_MODULE(sio, puc, sio_puc_driver, sio_devclass, 0, 0); 100