1139749Simp#-
2119815Smarcel# Copyright (c) 2003 Marcel Moolenaar
3119815Smarcel# All rights reserved.
4119815Smarcel#
5119815Smarcel# Redistribution and use in source and binary forms, with or without
6119815Smarcel# modification, are permitted provided that the following conditions
7119815Smarcel# are met:
8119815Smarcel#
9119815Smarcel# 1. Redistributions of source code must retain the above copyright
10119815Smarcel#    notice, this list of conditions and the following disclaimer.
11119815Smarcel# 2. Redistributions in binary form must reproduce the above copyright
12119815Smarcel#    notice, this list of conditions and the following disclaimer in the
13119815Smarcel#    documentation and/or other materials provided with the distribution.
14119815Smarcel#
15119815Smarcel# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16119815Smarcel# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17119815Smarcel# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18119815Smarcel# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19119815Smarcel# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20119815Smarcel# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21119815Smarcel# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22119815Smarcel# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23119815Smarcel# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24119815Smarcel# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25119815Smarcel#
26119815Smarcel# $FreeBSD$
27119815Smarcel
28120143Smarcel#include <sys/param.h>
29120143Smarcel#include <sys/lock.h>
30120143Smarcel#include <sys/mutex.h>
31119815Smarcel#include <sys/bus.h>
32119815Smarcel#include <machine/bus.h>
33119815Smarcel#include <dev/uart/uart.h>
34119815Smarcel#include <dev/uart/uart_bus.h>
35119815Smarcel
36119815Smarcel# The UART hardware interface. The core UART code is hardware independent.
37119815Smarcel# The details of the hardware are abstracted by the UART hardware interface.
38119815Smarcel
39119815SmarcelINTERFACE uart;
40119815Smarcel
41119815Smarcel# attach() - attach hardware.
42119815Smarcel# This method is called when the device is being attached. All resources
43119815Smarcel# have been allocated. The transmit and receive buffers exist, but no
44119815Smarcel# high-level (ie tty) initialization has been done yet.
45119815Smarcel# The intend of this method is to setup the hardware for normal operation.
46119815SmarcelMETHOD int attach {
47119815Smarcel	struct uart_softc *this;
48119815Smarcel};
49119815Smarcel
50119815Smarcel# detach() - detach hardware.
51119815Smarcel# This method is called when a device is being detached from its bus. It
52119815Smarcel# is the first action performed, so even the high-level (ie tty) interface
53119815Smarcel# is still operational.
54119815Smarcel# The intend of this method is to disable the hardware.
55119815SmarcelMETHOD int detach {
56119815Smarcel	struct uart_softc *this;
57119815Smarcel};
58119815Smarcel
59119815Smarcel# flush() - flush FIFOs.
60119815Smarcel# This method is called to flush the transmitter and/or the receiver as
61119815Smarcel# specified by the what argument. Characters are expected to be lost.
62119815SmarcelMETHOD int flush {
63119815Smarcel	struct uart_softc *this;
64119815Smarcel	int	what;
65119815Smarcel};
66119815Smarcel
67119815Smarcel# getsig() - get line and modem signals.
68119815Smarcel# This method retrieves the DTE and DCE signals and their corresponding
69119815Smarcel# delta bits. The delta bits include those corresponding to DTE signals
70119815Smarcel# when they were changed by a call to setsig. The delta bits maintained
71119815Smarcel# by the hardware driver are cleared as a side-effect. A second call to
72119815Smarcel# this function will not have any delta bits set, unless there was a
73119815Smarcel# change in the signals in the mean time.
74119815SmarcelMETHOD int getsig {
75119815Smarcel	struct uart_softc *this;
76119815Smarcel};
77119815Smarcel
78119815Smarcel# ioctl() - get or set miscellaneous parameters.
79119815Smarcel# This method is the bitbucket method. It can (and will) be used when there's
80119815Smarcel# something we need to set or get for which a new method is overkill. It's
81119815Smarcel# used for example to set HW or SW flow-control.
82119815SmarcelMETHOD int ioctl {
83119815Smarcel	struct uart_softc *this;
84119815Smarcel	int request;
85119815Smarcel	intptr_t data;
86119815Smarcel};
87119815Smarcel
88119815Smarcel# ipend() - query UART for pending interrupts.
89119815Smarcel# When an interrupt is signalled, the handler will call this method to find
90119815Smarcel# out which of the interrupt sources needs attention. The handler will use
91119815Smarcel# this information to dispatch service routines that deal with each of the
92119815Smarcel# interrupt sources. An advantage of this approach is that it allows multi-
93119815Smarcel# port drivers (like puc(4)) to query multiple devices concurrently and
94119815Smarcel# service them on an interrupt priority basis. If the hardware cannot provide
95119815Smarcel# the information reliably, it is free to service the interrupt and return 0,
96119815Smarcel# meaning that no attention is required.
97119815SmarcelMETHOD int ipend {
98119815Smarcel	struct uart_softc *this;
99119815Smarcel}
100119815Smarcel
101119815Smarcel# param() - set communication parameters.
102119815Smarcel# This method is called to change the communication parameters.
103119815SmarcelMETHOD int param {
104119815Smarcel	struct uart_softc *this;
105119815Smarcel	int	baudrate;
106119815Smarcel	int	databits;
107119815Smarcel	int	stopbits;
108119815Smarcel	int	parity;
109119815Smarcel};
110119815Smarcel
111119815Smarcel# probe() - detect hardware.
112119815Smarcel# This method is called as part of the bus probe to make sure the
113119815Smarcel# hardware exists. This function should also set the device description
114119815Smarcel# to something that represents the hardware.
115119815SmarcelMETHOD int probe {
116119815Smarcel	struct uart_softc *this;
117119815Smarcel};
118119815Smarcel
119119815Smarcel# receive() - move data from the receive FIFO to the receive buffer.
120119815Smarcel# This method is called to move received data to the receive buffer and
121119815Smarcel# additionally should make sure the receive interrupt should be cleared.
122119815SmarcelMETHOD int receive {
123119815Smarcel	struct uart_softc *this;
124119815Smarcel};
125119815Smarcel
126119815Smarcel# setsig() - set line and modem signals.
127119815Smarcel# This method allows changing DTE signals. The DTE delta bits indicate which
128119815Smarcel# signals are to be changed and the DTE bits themselves indicate whether to
129119815Smarcel# set or clear the signals. A subsequent call to getsig will return with the
130119815Smarcel# DTE delta bits set of those DTE signals that did change by this method.
131119815SmarcelMETHOD int setsig {
132119815Smarcel	struct uart_softc *this;
133119815Smarcel	int	sig;
134119815Smarcel};
135119815Smarcel
136119815Smarcel# transmit() - move data from the transmit buffer to the transmit FIFO.
137119815Smarcel# This method is responsible for writing the Tx buffer to the UART and
138119815Smarcel# additionally should make sure that a transmit interrupt is generated
139119815Smarcel# when transmission is complete.
140119815SmarcelMETHOD int transmit {
141119815Smarcel	struct uart_softc *this;
142119815Smarcel};
143