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# $FreeBSD$ 2727d5dc18SMarcel Moolenaar 2806287620SMarcel Moolenaar#include <sys/param.h> 29332cda07SPeter Grehan#include <sys/systm.h> 3006287620SMarcel Moolenaar#include <sys/lock.h> 3106287620SMarcel Moolenaar#include <sys/mutex.h> 3227d5dc18SMarcel Moolenaar#include <sys/bus.h> 3327d5dc18SMarcel Moolenaar#include <machine/bus.h> 3427d5dc18SMarcel Moolenaar#include <dev/uart/uart.h> 3527d5dc18SMarcel Moolenaar#include <dev/uart/uart_bus.h> 3627d5dc18SMarcel Moolenaar 3727d5dc18SMarcel Moolenaar# The UART hardware interface. The core UART code is hardware independent. 3827d5dc18SMarcel Moolenaar# The details of the hardware are abstracted by the UART hardware interface. 3927d5dc18SMarcel Moolenaar 4027d5dc18SMarcel MoolenaarINTERFACE uart; 4127d5dc18SMarcel Moolenaar 4227d5dc18SMarcel Moolenaar# attach() - attach hardware. 4327d5dc18SMarcel Moolenaar# This method is called when the device is being attached. All resources 4427d5dc18SMarcel Moolenaar# have been allocated. The transmit and receive buffers exist, but no 4527d5dc18SMarcel Moolenaar# high-level (ie tty) initialization has been done yet. 4627d5dc18SMarcel Moolenaar# The intend of this method is to setup the hardware for normal operation. 4727d5dc18SMarcel MoolenaarMETHOD int attach { 4827d5dc18SMarcel Moolenaar struct uart_softc *this; 4927d5dc18SMarcel Moolenaar}; 5027d5dc18SMarcel Moolenaar 5127d5dc18SMarcel Moolenaar# detach() - detach hardware. 5227d5dc18SMarcel Moolenaar# This method is called when a device is being detached from its bus. It 5327d5dc18SMarcel Moolenaar# is the first action performed, so even the high-level (ie tty) interface 5427d5dc18SMarcel Moolenaar# is still operational. 5527d5dc18SMarcel Moolenaar# The intend of this method is to disable the hardware. 5627d5dc18SMarcel MoolenaarMETHOD int detach { 5727d5dc18SMarcel Moolenaar struct uart_softc *this; 5827d5dc18SMarcel Moolenaar}; 5927d5dc18SMarcel Moolenaar 6027d5dc18SMarcel Moolenaar# flush() - flush FIFOs. 6127d5dc18SMarcel Moolenaar# This method is called to flush the transmitter and/or the receiver as 6227d5dc18SMarcel Moolenaar# specified by the what argument. Characters are expected to be lost. 6327d5dc18SMarcel MoolenaarMETHOD int flush { 6427d5dc18SMarcel Moolenaar struct uart_softc *this; 6527d5dc18SMarcel Moolenaar int what; 6627d5dc18SMarcel Moolenaar}; 6727d5dc18SMarcel Moolenaar 6827d5dc18SMarcel Moolenaar# getsig() - get line and modem signals. 6927d5dc18SMarcel Moolenaar# This method retrieves the DTE and DCE signals and their corresponding 7027d5dc18SMarcel Moolenaar# delta bits. The delta bits include those corresponding to DTE signals 7127d5dc18SMarcel Moolenaar# when they were changed by a call to setsig. The delta bits maintained 7227d5dc18SMarcel Moolenaar# by the hardware driver are cleared as a side-effect. A second call to 7327d5dc18SMarcel Moolenaar# this function will not have any delta bits set, unless there was a 7427d5dc18SMarcel Moolenaar# change in the signals in the mean time. 7527d5dc18SMarcel MoolenaarMETHOD int getsig { 7627d5dc18SMarcel Moolenaar struct uart_softc *this; 7727d5dc18SMarcel Moolenaar}; 7827d5dc18SMarcel Moolenaar 7927d5dc18SMarcel Moolenaar# ioctl() - get or set miscellaneous parameters. 8027d5dc18SMarcel Moolenaar# This method is the bitbucket method. It can (and will) be used when there's 8127d5dc18SMarcel Moolenaar# something we need to set or get for which a new method is overkill. It's 8227d5dc18SMarcel Moolenaar# used for example to set HW or SW flow-control. 8327d5dc18SMarcel MoolenaarMETHOD int ioctl { 8427d5dc18SMarcel Moolenaar struct uart_softc *this; 8527d5dc18SMarcel Moolenaar int request; 8627d5dc18SMarcel Moolenaar intptr_t data; 8727d5dc18SMarcel Moolenaar}; 8827d5dc18SMarcel Moolenaar 8927d5dc18SMarcel Moolenaar# ipend() - query UART for pending interrupts. 9027d5dc18SMarcel Moolenaar# When an interrupt is signalled, the handler will call this method to find 9127d5dc18SMarcel Moolenaar# out which of the interrupt sources needs attention. The handler will use 9227d5dc18SMarcel Moolenaar# this information to dispatch service routines that deal with each of the 9327d5dc18SMarcel Moolenaar# interrupt sources. An advantage of this approach is that it allows multi- 9427d5dc18SMarcel Moolenaar# port drivers (like puc(4)) to query multiple devices concurrently and 9527d5dc18SMarcel Moolenaar# service them on an interrupt priority basis. If the hardware cannot provide 9627d5dc18SMarcel Moolenaar# the information reliably, it is free to service the interrupt and return 0, 9727d5dc18SMarcel Moolenaar# meaning that no attention is required. 9827d5dc18SMarcel MoolenaarMETHOD int ipend { 9927d5dc18SMarcel Moolenaar struct uart_softc *this; 10027d5dc18SMarcel Moolenaar} 10127d5dc18SMarcel Moolenaar 10227d5dc18SMarcel Moolenaar# param() - set communication parameters. 10327d5dc18SMarcel Moolenaar# This method is called to change the communication parameters. 10427d5dc18SMarcel MoolenaarMETHOD int param { 10527d5dc18SMarcel Moolenaar struct uart_softc *this; 10627d5dc18SMarcel Moolenaar int baudrate; 10727d5dc18SMarcel Moolenaar int databits; 10827d5dc18SMarcel Moolenaar int stopbits; 10927d5dc18SMarcel Moolenaar int parity; 11027d5dc18SMarcel Moolenaar}; 11127d5dc18SMarcel Moolenaar 11227d5dc18SMarcel Moolenaar# probe() - detect hardware. 11327d5dc18SMarcel Moolenaar# This method is called as part of the bus probe to make sure the 11427d5dc18SMarcel Moolenaar# hardware exists. This function should also set the device description 11527d5dc18SMarcel Moolenaar# to something that represents the hardware. 11627d5dc18SMarcel MoolenaarMETHOD int probe { 11727d5dc18SMarcel Moolenaar struct uart_softc *this; 11827d5dc18SMarcel Moolenaar}; 11927d5dc18SMarcel Moolenaar 12027d5dc18SMarcel Moolenaar# receive() - move data from the receive FIFO to the receive buffer. 12127d5dc18SMarcel Moolenaar# This method is called to move received data to the receive buffer and 12227d5dc18SMarcel Moolenaar# additionally should make sure the receive interrupt should be cleared. 12327d5dc18SMarcel MoolenaarMETHOD int receive { 12427d5dc18SMarcel Moolenaar struct uart_softc *this; 12527d5dc18SMarcel Moolenaar}; 12627d5dc18SMarcel Moolenaar 12727d5dc18SMarcel Moolenaar# setsig() - set line and modem signals. 12827d5dc18SMarcel Moolenaar# This method allows changing DTE signals. The DTE delta bits indicate which 12927d5dc18SMarcel Moolenaar# signals are to be changed and the DTE bits themselves indicate whether to 13027d5dc18SMarcel Moolenaar# set or clear the signals. A subsequent call to getsig will return with the 13127d5dc18SMarcel Moolenaar# DTE delta bits set of those DTE signals that did change by this method. 13227d5dc18SMarcel MoolenaarMETHOD int setsig { 13327d5dc18SMarcel Moolenaar struct uart_softc *this; 13427d5dc18SMarcel Moolenaar int sig; 13527d5dc18SMarcel Moolenaar}; 13627d5dc18SMarcel Moolenaar 13727d5dc18SMarcel Moolenaar# transmit() - move data from the transmit buffer to the transmit FIFO. 13827d5dc18SMarcel Moolenaar# This method is responsible for writing the Tx buffer to the UART and 13927d5dc18SMarcel Moolenaar# additionally should make sure that a transmit interrupt is generated 14027d5dc18SMarcel Moolenaar# when transmission is complete. 14127d5dc18SMarcel MoolenaarMETHOD int transmit { 14227d5dc18SMarcel Moolenaar struct uart_softc *this; 14327d5dc18SMarcel Moolenaar}; 144*d76a1ef4SWarner Losh 145*d76a1ef4SWarner Losh# grab() - Up call from the console to the upper layers of the driver when 146*d76a1ef4SWarner Losh# the kernel asks to grab the console. This is valid only for console 147*d76a1ef4SWarner Losh# drivers. This method is responsible for transitioning the hardware 148*d76a1ef4SWarner Losh# from an interrupt driven state to a polled state that works with the 149*d76a1ef4SWarner Losh# low-level console interface defined for this device. The kernel 150*d76a1ef4SWarner Losh# currently only calls this when it wants to grab input from the 151*d76a1ef4SWarner Losh# console. Output can still happen asyncrhonously to these calls. 152*d76a1ef4SWarner LoshMETHOD void grab { 153*d76a1ef4SWarner Losh struct uart_softc *this; 154*d76a1ef4SWarner Losh}; 155*d76a1ef4SWarner Losh 156*d76a1ef4SWarner Losh# ungrab() - Undoes the effects of grab(). 157*d76a1ef4SWarner LoshMETHOD void ungrab { 158*d76a1ef4SWarner Losh struct uart_softc *this; 159*d76a1ef4SWarner Losh}; 160