xref: /freebsd/sys/dev/uart/uart_if.m (revision 098ca2bda93c701c5331d4e6aace072495b4caaa)
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>
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
4127d5dc18SMarcel Moolenaar# attach() - attach hardware.
4227d5dc18SMarcel Moolenaar# This method is called when the device is being attached. All resources
4327d5dc18SMarcel Moolenaar# have been allocated. The transmit and receive buffers exist, but no
4427d5dc18SMarcel Moolenaar# high-level (ie tty) initialization has been done yet.
4527d5dc18SMarcel Moolenaar# The intend of this method is to setup the hardware for normal operation.
4627d5dc18SMarcel MoolenaarMETHOD int attach {
4727d5dc18SMarcel Moolenaar	struct uart_softc *this;
4827d5dc18SMarcel Moolenaar};
4927d5dc18SMarcel Moolenaar
5027d5dc18SMarcel Moolenaar# detach() - detach hardware.
5127d5dc18SMarcel Moolenaar# This method is called when a device is being detached from its bus. It
5227d5dc18SMarcel Moolenaar# is the first action performed, so even the high-level (ie tty) interface
5327d5dc18SMarcel Moolenaar# is still operational.
5427d5dc18SMarcel Moolenaar# The intend of this method is to disable the hardware.
5527d5dc18SMarcel MoolenaarMETHOD int detach {
5627d5dc18SMarcel Moolenaar	struct uart_softc *this;
5727d5dc18SMarcel Moolenaar};
5827d5dc18SMarcel Moolenaar
5927d5dc18SMarcel Moolenaar# flush() - flush FIFOs.
6027d5dc18SMarcel Moolenaar# This method is called to flush the transmitter and/or the receiver as
6127d5dc18SMarcel Moolenaar# specified by the what argument. Characters are expected to be lost.
6227d5dc18SMarcel MoolenaarMETHOD int flush {
6327d5dc18SMarcel Moolenaar	struct uart_softc *this;
6427d5dc18SMarcel Moolenaar	int	what;
6527d5dc18SMarcel Moolenaar};
6627d5dc18SMarcel Moolenaar
6727d5dc18SMarcel Moolenaar# getsig() - get line and modem signals.
6827d5dc18SMarcel Moolenaar# This method retrieves the DTE and DCE signals and their corresponding
6927d5dc18SMarcel Moolenaar# delta bits. The delta bits include those corresponding to DTE signals
7027d5dc18SMarcel Moolenaar# when they were changed by a call to setsig. The delta bits maintained
7127d5dc18SMarcel Moolenaar# by the hardware driver are cleared as a side-effect. A second call to
7227d5dc18SMarcel Moolenaar# this function will not have any delta bits set, unless there was a
7327d5dc18SMarcel Moolenaar# change in the signals in the mean time.
7427d5dc18SMarcel MoolenaarMETHOD int getsig {
7527d5dc18SMarcel Moolenaar	struct uart_softc *this;
7627d5dc18SMarcel Moolenaar};
7727d5dc18SMarcel Moolenaar
7827d5dc18SMarcel Moolenaar# ioctl() - get or set miscellaneous parameters.
7927d5dc18SMarcel Moolenaar# This method is the bitbucket method. It can (and will) be used when there's
8027d5dc18SMarcel Moolenaar# something we need to set or get for which a new method is overkill. It's
8127d5dc18SMarcel Moolenaar# used for example to set HW or SW flow-control.
8227d5dc18SMarcel MoolenaarMETHOD int ioctl {
8327d5dc18SMarcel Moolenaar	struct uart_softc *this;
8427d5dc18SMarcel Moolenaar	int request;
8527d5dc18SMarcel Moolenaar	intptr_t data;
8627d5dc18SMarcel Moolenaar};
8727d5dc18SMarcel Moolenaar
8827d5dc18SMarcel Moolenaar# ipend() - query UART for pending interrupts.
8927d5dc18SMarcel Moolenaar# When an interrupt is signalled, the handler will call this method to find
9027d5dc18SMarcel Moolenaar# out which of the interrupt sources needs attention. The handler will use
9127d5dc18SMarcel Moolenaar# this information to dispatch service routines that deal with each of the
9227d5dc18SMarcel Moolenaar# interrupt sources. An advantage of this approach is that it allows multi-
9327d5dc18SMarcel Moolenaar# port drivers (like puc(4)) to query multiple devices concurrently and
9427d5dc18SMarcel Moolenaar# service them on an interrupt priority basis. If the hardware cannot provide
9527d5dc18SMarcel Moolenaar# the information reliably, it is free to service the interrupt and return 0,
9627d5dc18SMarcel Moolenaar# meaning that no attention is required.
9727d5dc18SMarcel MoolenaarMETHOD int ipend {
9827d5dc18SMarcel Moolenaar	struct uart_softc *this;
9927d5dc18SMarcel Moolenaar}
10027d5dc18SMarcel Moolenaar
10127d5dc18SMarcel Moolenaar# param() - set communication parameters.
10227d5dc18SMarcel Moolenaar# This method is called to change the communication parameters.
10327d5dc18SMarcel MoolenaarMETHOD int param {
10427d5dc18SMarcel Moolenaar	struct uart_softc *this;
10527d5dc18SMarcel Moolenaar	int	baudrate;
10627d5dc18SMarcel Moolenaar	int	databits;
10727d5dc18SMarcel Moolenaar	int	stopbits;
10827d5dc18SMarcel Moolenaar	int	parity;
10927d5dc18SMarcel Moolenaar};
11027d5dc18SMarcel Moolenaar
11127d5dc18SMarcel Moolenaar# probe() - detect hardware.
11227d5dc18SMarcel Moolenaar# This method is called as part of the bus probe to make sure the
11327d5dc18SMarcel Moolenaar# hardware exists. This function should also set the device description
11427d5dc18SMarcel Moolenaar# to something that represents the hardware.
11527d5dc18SMarcel MoolenaarMETHOD int probe {
11627d5dc18SMarcel Moolenaar	struct uart_softc *this;
11727d5dc18SMarcel Moolenaar};
11827d5dc18SMarcel Moolenaar
11927d5dc18SMarcel Moolenaar# receive() - move data from the receive FIFO to the receive buffer.
12027d5dc18SMarcel Moolenaar# This method is called to move received data to the receive buffer and
12127d5dc18SMarcel Moolenaar# additionally should make sure the receive interrupt should be cleared.
12227d5dc18SMarcel MoolenaarMETHOD int receive {
12327d5dc18SMarcel Moolenaar	struct uart_softc *this;
12427d5dc18SMarcel Moolenaar};
12527d5dc18SMarcel Moolenaar
12627d5dc18SMarcel Moolenaar# setsig() - set line and modem signals.
12727d5dc18SMarcel Moolenaar# This method allows changing DTE signals. The DTE delta bits indicate which
12827d5dc18SMarcel Moolenaar# signals are to be changed and the DTE bits themselves indicate whether to
12927d5dc18SMarcel Moolenaar# set or clear the signals. A subsequent call to getsig will return with the
13027d5dc18SMarcel Moolenaar# DTE delta bits set of those DTE signals that did change by this method.
13127d5dc18SMarcel MoolenaarMETHOD int setsig {
13227d5dc18SMarcel Moolenaar	struct uart_softc *this;
13327d5dc18SMarcel Moolenaar	int	sig;
13427d5dc18SMarcel Moolenaar};
13527d5dc18SMarcel Moolenaar
13627d5dc18SMarcel Moolenaar# transmit() - move data from the transmit buffer to the transmit FIFO.
13727d5dc18SMarcel Moolenaar# This method is responsible for writing the Tx buffer to the UART and
13827d5dc18SMarcel Moolenaar# additionally should make sure that a transmit interrupt is generated
13927d5dc18SMarcel Moolenaar# when transmission is complete.
14027d5dc18SMarcel MoolenaarMETHOD int transmit {
14127d5dc18SMarcel Moolenaar	struct uart_softc *this;
14227d5dc18SMarcel Moolenaar};
143