1098ca2bdSWarner Losh#- 227d5dc18SMarcel Moolenaar# Copyright (c) 2003 Marcel Moolenaar 327d5dc18SMarcel Moolenaar# All rights reserved. 427d5dc18SMarcel Moolenaar# 527d5dc18SMarcel Moolenaar# Redistribution and use in source and binary forms, with or without 627d5dc18SMarcel Moolenaar# modification, are permitted provided that the following conditions 727d5dc18SMarcel Moolenaar# are met: 827d5dc18SMarcel Moolenaar# 927d5dc18SMarcel Moolenaar# 1. Redistributions of source code must retain the above copyright 1027d5dc18SMarcel Moolenaar# notice, this list of conditions and the following disclaimer. 1127d5dc18SMarcel Moolenaar# 2. Redistributions in binary form must reproduce the above copyright 1227d5dc18SMarcel Moolenaar# notice, this list of conditions and the following disclaimer in the 1327d5dc18SMarcel Moolenaar# documentation and/or other materials provided with the distribution. 1427d5dc18SMarcel Moolenaar# 1527d5dc18SMarcel Moolenaar# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1627d5dc18SMarcel Moolenaar# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1727d5dc18SMarcel Moolenaar# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1827d5dc18SMarcel Moolenaar# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1927d5dc18SMarcel Moolenaar# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2027d5dc18SMarcel Moolenaar# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2127d5dc18SMarcel Moolenaar# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2227d5dc18SMarcel Moolenaar# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2327d5dc18SMarcel Moolenaar# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2427d5dc18SMarcel Moolenaar# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2527d5dc18SMarcel Moolenaar# 2627d5dc18SMarcel Moolenaar 2706287620SMarcel Moolenaar#include <sys/param.h> 28332cda07SPeter Grehan#include <sys/systm.h> 2906287620SMarcel Moolenaar#include <sys/lock.h> 3006287620SMarcel Moolenaar#include <sys/mutex.h> 3127d5dc18SMarcel Moolenaar#include <sys/bus.h> 3227d5dc18SMarcel Moolenaar#include <machine/bus.h> 3327d5dc18SMarcel Moolenaar#include <dev/uart/uart.h> 3427d5dc18SMarcel Moolenaar#include <dev/uart/uart_bus.h> 3527d5dc18SMarcel Moolenaar 3627d5dc18SMarcel Moolenaar# The UART hardware interface. The core UART code is hardware independent. 3727d5dc18SMarcel Moolenaar# The details of the hardware are abstracted by the UART hardware interface. 3827d5dc18SMarcel Moolenaar 3927d5dc18SMarcel MoolenaarINTERFACE uart; 4027d5dc18SMarcel Moolenaar 41*353e4c5aSMarius StroblCODE { 42*353e4c5aSMarius Strobl static uart_txbusy_t uart_default_txbusy; 43*353e4c5aSMarius Strobl 44*353e4c5aSMarius Strobl static bool 45*353e4c5aSMarius Strobl uart_default_txbusy(struct uart_softc *this __unused) 46*353e4c5aSMarius Strobl { 47*353e4c5aSMarius Strobl 48*353e4c5aSMarius Strobl return (false); 49*353e4c5aSMarius Strobl } 50*353e4c5aSMarius Strobl}; 51*353e4c5aSMarius Strobl 5227d5dc18SMarcel Moolenaar# attach() - attach hardware. 5327d5dc18SMarcel Moolenaar# This method is called when the device is being attached. All resources 5427d5dc18SMarcel Moolenaar# have been allocated. The transmit and receive buffers exist, but no 5527d5dc18SMarcel Moolenaar# high-level (ie tty) initialization has been done yet. 5627d5dc18SMarcel Moolenaar# The intend of this method is to setup the hardware for normal operation. 5727d5dc18SMarcel MoolenaarMETHOD int attach { 5827d5dc18SMarcel Moolenaar struct uart_softc *this; 5927d5dc18SMarcel Moolenaar}; 6027d5dc18SMarcel Moolenaar 6127d5dc18SMarcel Moolenaar# detach() - detach hardware. 6227d5dc18SMarcel Moolenaar# This method is called when a device is being detached from its bus. It 6327d5dc18SMarcel Moolenaar# is the first action performed, so even the high-level (ie tty) interface 6427d5dc18SMarcel Moolenaar# is still operational. 6527d5dc18SMarcel Moolenaar# The intend of this method is to disable the hardware. 6627d5dc18SMarcel MoolenaarMETHOD int detach { 6727d5dc18SMarcel Moolenaar struct uart_softc *this; 6827d5dc18SMarcel Moolenaar}; 6927d5dc18SMarcel Moolenaar 7027d5dc18SMarcel Moolenaar# flush() - flush FIFOs. 7127d5dc18SMarcel Moolenaar# This method is called to flush the transmitter and/or the receiver as 7227d5dc18SMarcel Moolenaar# specified by the what argument. Characters are expected to be lost. 7327d5dc18SMarcel MoolenaarMETHOD int flush { 7427d5dc18SMarcel Moolenaar struct uart_softc *this; 7527d5dc18SMarcel Moolenaar int what; 7627d5dc18SMarcel Moolenaar}; 7727d5dc18SMarcel Moolenaar 7827d5dc18SMarcel Moolenaar# getsig() - get line and modem signals. 7927d5dc18SMarcel Moolenaar# This method retrieves the DTE and DCE signals and their corresponding 8027d5dc18SMarcel Moolenaar# delta bits. The delta bits include those corresponding to DTE signals 8127d5dc18SMarcel Moolenaar# when they were changed by a call to setsig. The delta bits maintained 8227d5dc18SMarcel Moolenaar# by the hardware driver are cleared as a side-effect. A second call to 8327d5dc18SMarcel Moolenaar# this function will not have any delta bits set, unless there was a 8427d5dc18SMarcel Moolenaar# change in the signals in the mean time. 8527d5dc18SMarcel MoolenaarMETHOD int getsig { 8627d5dc18SMarcel Moolenaar struct uart_softc *this; 8727d5dc18SMarcel Moolenaar}; 8827d5dc18SMarcel Moolenaar 8927d5dc18SMarcel Moolenaar# ioctl() - get or set miscellaneous parameters. 9027d5dc18SMarcel Moolenaar# This method is the bitbucket method. It can (and will) be used when there's 9127d5dc18SMarcel Moolenaar# something we need to set or get for which a new method is overkill. It's 9227d5dc18SMarcel Moolenaar# used for example to set HW or SW flow-control. 9327d5dc18SMarcel MoolenaarMETHOD int ioctl { 9427d5dc18SMarcel Moolenaar struct uart_softc *this; 9527d5dc18SMarcel Moolenaar int request; 9627d5dc18SMarcel Moolenaar intptr_t data; 9727d5dc18SMarcel Moolenaar}; 9827d5dc18SMarcel Moolenaar 9927d5dc18SMarcel Moolenaar# ipend() - query UART for pending interrupts. 10027d5dc18SMarcel Moolenaar# When an interrupt is signalled, the handler will call this method to find 10127d5dc18SMarcel Moolenaar# out which of the interrupt sources needs attention. The handler will use 10227d5dc18SMarcel Moolenaar# this information to dispatch service routines that deal with each of the 10327d5dc18SMarcel Moolenaar# interrupt sources. An advantage of this approach is that it allows multi- 10427d5dc18SMarcel Moolenaar# port drivers (like puc(4)) to query multiple devices concurrently and 10527d5dc18SMarcel Moolenaar# service them on an interrupt priority basis. If the hardware cannot provide 10627d5dc18SMarcel Moolenaar# the information reliably, it is free to service the interrupt and return 0, 10727d5dc18SMarcel Moolenaar# meaning that no attention is required. 10827d5dc18SMarcel MoolenaarMETHOD int ipend { 10927d5dc18SMarcel Moolenaar struct uart_softc *this; 11027d5dc18SMarcel Moolenaar} 11127d5dc18SMarcel Moolenaar 11227d5dc18SMarcel Moolenaar# param() - set communication parameters. 11327d5dc18SMarcel Moolenaar# This method is called to change the communication parameters. 11427d5dc18SMarcel MoolenaarMETHOD int param { 11527d5dc18SMarcel Moolenaar struct uart_softc *this; 11627d5dc18SMarcel Moolenaar int baudrate; 11727d5dc18SMarcel Moolenaar int databits; 11827d5dc18SMarcel Moolenaar int stopbits; 11927d5dc18SMarcel Moolenaar int parity; 12027d5dc18SMarcel Moolenaar}; 12127d5dc18SMarcel Moolenaar 12227d5dc18SMarcel Moolenaar# probe() - detect hardware. 12327d5dc18SMarcel Moolenaar# This method is called as part of the bus probe to make sure the 12427d5dc18SMarcel Moolenaar# hardware exists. This function should also set the device description 12527d5dc18SMarcel Moolenaar# to something that represents the hardware. 12627d5dc18SMarcel MoolenaarMETHOD int probe { 12727d5dc18SMarcel Moolenaar struct uart_softc *this; 12827d5dc18SMarcel Moolenaar}; 12927d5dc18SMarcel Moolenaar 13027d5dc18SMarcel Moolenaar# receive() - move data from the receive FIFO to the receive buffer. 13127d5dc18SMarcel Moolenaar# This method is called to move received data to the receive buffer and 13227d5dc18SMarcel Moolenaar# additionally should make sure the receive interrupt should be cleared. 13327d5dc18SMarcel MoolenaarMETHOD int receive { 13427d5dc18SMarcel Moolenaar struct uart_softc *this; 13527d5dc18SMarcel Moolenaar}; 13627d5dc18SMarcel Moolenaar 13727d5dc18SMarcel Moolenaar# setsig() - set line and modem signals. 13827d5dc18SMarcel Moolenaar# This method allows changing DTE signals. The DTE delta bits indicate which 13927d5dc18SMarcel Moolenaar# signals are to be changed and the DTE bits themselves indicate whether to 14027d5dc18SMarcel Moolenaar# set or clear the signals. A subsequent call to getsig will return with the 14127d5dc18SMarcel Moolenaar# DTE delta bits set of those DTE signals that did change by this method. 14227d5dc18SMarcel MoolenaarMETHOD int setsig { 14327d5dc18SMarcel Moolenaar struct uart_softc *this; 14427d5dc18SMarcel Moolenaar int sig; 14527d5dc18SMarcel Moolenaar}; 14627d5dc18SMarcel Moolenaar 14727d5dc18SMarcel Moolenaar# transmit() - move data from the transmit buffer to the transmit FIFO. 14827d5dc18SMarcel Moolenaar# This method is responsible for writing the Tx buffer to the UART and 14927d5dc18SMarcel Moolenaar# additionally should make sure that a transmit interrupt is generated 15027d5dc18SMarcel Moolenaar# when transmission is complete. 15127d5dc18SMarcel MoolenaarMETHOD int transmit { 15227d5dc18SMarcel Moolenaar struct uart_softc *this; 15327d5dc18SMarcel Moolenaar}; 154d76a1ef4SWarner Losh 155*353e4c5aSMarius Strobl# txbusy() - report if Tx is still busy. 156*353e4c5aSMarius Strobl# This method is called by the tty glue for reporting upward that output is 157*353e4c5aSMarius Strobl# still being drained despite sc_txbusy unset. Non-DEFAULT implementations 158*353e4c5aSMarius Strobl# allow for extra checks, i. e. beyond what can be determined in ipend(), 159*353e4c5aSMarius Strobl# that the Tx path actually is idle. For example, whether the last character 160*353e4c5aSMarius Strobl# has left the transmit shift register in addition to the FIFO being empty. 161*353e4c5aSMarius StroblMETHOD bool txbusy { 162*353e4c5aSMarius Strobl struct uart_softc *this; 163*353e4c5aSMarius Strobl} DEFAULT uart_default_txbusy; 164*353e4c5aSMarius Strobl 165d76a1ef4SWarner Losh# grab() - Up call from the console to the upper layers of the driver when 166d76a1ef4SWarner Losh# the kernel asks to grab the console. This is valid only for console 167d76a1ef4SWarner Losh# drivers. This method is responsible for transitioning the hardware 168d76a1ef4SWarner Losh# from an interrupt driven state to a polled state that works with the 169d76a1ef4SWarner Losh# low-level console interface defined for this device. The kernel 170d76a1ef4SWarner Losh# currently only calls this when it wants to grab input from the 171d76a1ef4SWarner Losh# console. Output can still happen asyncrhonously to these calls. 172d76a1ef4SWarner LoshMETHOD void grab { 173d76a1ef4SWarner Losh struct uart_softc *this; 174d76a1ef4SWarner Losh}; 175d76a1ef4SWarner Losh 176d76a1ef4SWarner Losh# ungrab() - Undoes the effects of grab(). 177d76a1ef4SWarner LoshMETHOD void ungrab { 178d76a1ef4SWarner Losh struct uart_softc *this; 179d76a1ef4SWarner Losh}; 180