1#- 2# Copyright (c) 2003 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/param.h> 28#include <sys/systm.h> 29#include <sys/lock.h> 30#include <sys/mutex.h> 31#include <sys/bus.h> 32#include <machine/bus.h> 33#include <dev/uart/uart.h> 34#include <dev/uart/uart_bus.h> 35 36# The UART hardware interface. The core UART code is hardware independent. 37# The details of the hardware are abstracted by the UART hardware interface. 38 39INTERFACE uart; 40 41CODE { 42 static uart_txbusy_t uart_default_txbusy; 43 44 static bool 45 uart_default_txbusy(struct uart_softc *this __unused) 46 { 47 48 return (false); 49 } 50}; 51 52# attach() - attach hardware. 53# This method is called when the device is being attached. All resources 54# have been allocated. The transmit and receive buffers exist, but no 55# high-level (ie tty) initialization has been done yet. 56# The intend of this method is to setup the hardware for normal operation. 57METHOD int attach { 58 struct uart_softc *this; 59}; 60 61# detach() - detach hardware. 62# This method is called when a device is being detached from its bus. It 63# is the first action performed, so even the high-level (ie tty) interface 64# is still operational. 65# The intend of this method is to disable the hardware. 66METHOD int detach { 67 struct uart_softc *this; 68}; 69 70# flush() - flush FIFOs. 71# This method is called to flush the transmitter and/or the receiver as 72# specified by the what argument. Characters are expected to be lost. 73METHOD int flush { 74 struct uart_softc *this; 75 int what; 76}; 77 78# getsig() - get line and modem signals. 79# This method retrieves the DTE and DCE signals and their corresponding 80# delta bits. The delta bits include those corresponding to DTE signals 81# when they were changed by a call to setsig. The delta bits maintained 82# by the hardware driver are cleared as a side-effect. A second call to 83# this function will not have any delta bits set, unless there was a 84# change in the signals in the mean time. 85METHOD int getsig { 86 struct uart_softc *this; 87}; 88 89# ioctl() - get or set miscellaneous parameters. 90# This method is the bitbucket method. It can (and will) be used when there's 91# something we need to set or get for which a new method is overkill. It's 92# used for example to set HW or SW flow-control. 93METHOD int ioctl { 94 struct uart_softc *this; 95 int request; 96 intptr_t data; 97}; 98 99# ipend() - query UART for pending interrupts. 100# When an interrupt is signalled, the handler will call this method to find 101# out which of the interrupt sources needs attention. The handler will use 102# this information to dispatch service routines that deal with each of the 103# interrupt sources. An advantage of this approach is that it allows multi- 104# port drivers (like puc(4)) to query multiple devices concurrently and 105# service them on an interrupt priority basis. If the hardware cannot provide 106# the information reliably, it is free to service the interrupt and return 0, 107# meaning that no attention is required. 108METHOD int ipend { 109 struct uart_softc *this; 110} 111 112# param() - set communication parameters. 113# This method is called to change the communication parameters. 114METHOD int param { 115 struct uart_softc *this; 116 int baudrate; 117 int databits; 118 int stopbits; 119 int parity; 120}; 121 122# probe() - detect hardware. 123# This method is called as part of the bus probe to make sure the 124# hardware exists. This function should also set the device description 125# to something that represents the hardware. 126METHOD int probe { 127 struct uart_softc *this; 128}; 129 130# receive() - move data from the receive FIFO to the receive buffer. 131# This method is called to move received data to the receive buffer and 132# additionally should make sure the receive interrupt should be cleared. 133METHOD int receive { 134 struct uart_softc *this; 135}; 136 137# setsig() - set line and modem signals. 138# This method allows changing DTE signals. The DTE delta bits indicate which 139# signals are to be changed and the DTE bits themselves indicate whether to 140# set or clear the signals. A subsequent call to getsig will return with the 141# DTE delta bits set of those DTE signals that did change by this method. 142METHOD int setsig { 143 struct uart_softc *this; 144 int sig; 145}; 146 147# transmit() - move data from the transmit buffer to the transmit FIFO. 148# This method is responsible for writing the Tx buffer to the UART and 149# additionally should make sure that a transmit interrupt is generated 150# when transmission is complete. 151METHOD int transmit { 152 struct uart_softc *this; 153}; 154 155# txbusy() - report if Tx is still busy. 156# This method is called by the tty glue for reporting upward that output is 157# still being drained despite sc_txbusy unset. Non-DEFAULT implementations 158# allow for extra checks, i. e. beyond what can be determined in ipend(), 159# that the Tx path actually is idle. For example, whether the last character 160# has left the transmit shift register in addition to the FIFO being empty. 161METHOD bool txbusy { 162 struct uart_softc *this; 163} DEFAULT uart_default_txbusy; 164 165# grab() - Up call from the console to the upper layers of the driver when 166# the kernel asks to grab the console. This is valid only for console 167# drivers. This method is responsible for transitioning the hardware 168# from an interrupt driven state to a polled state that works with the 169# low-level console interface defined for this device. The kernel 170# currently only calls this when it wants to grab input from the 171# console. Output can still happen asyncrhonously to these calls. 172METHOD void grab { 173 struct uart_softc *this; 174}; 175 176# ungrab() - Undoes the effects of grab(). 177METHOD void ungrab { 178 struct uart_softc *this; 179}; 180