uart_cpu.h revision 120378
1218885Sdim/*
2218885Sdim * Copyright (c) 2003 Marcel Moolenaar
3218885Sdim * All rights reserved.
4218885Sdim *
5218885Sdim * Redistribution and use in source and binary forms, with or without
6218885Sdim * modification, are permitted provided that the following conditions
7218885Sdim * are met:
8218885Sdim *
9218885Sdim * 1. Redistributions of source code must retain the above copyright
10249423Sdim *    notice, this list of conditions and the following disclaimer.
11218885Sdim * 2. Redistributions in binary form must reproduce the above copyright
12218885Sdim *    notice, this list of conditions and the following disclaimer in the
13249423Sdim *    documentation and/or other materials provided with the distribution.
14218885Sdim *
15218885Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16218885Sdim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17218885Sdim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18218885Sdim * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19218885Sdim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20218885Sdim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21218885Sdim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22218885Sdim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23218885Sdim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24218885Sdim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25218885Sdim *
26218885Sdim * $FreeBSD: head/sys/dev/uart/uart_cpu.h 120378 2003-09-23 09:25:38Z nyan $
27218885Sdim */
28218885Sdim
29218885Sdim#ifndef _DEV_UART_CPU_H_
30218885Sdim#define _DEV_UART_CPU_H_
31218885Sdim
32218885Sdim/*
33218885Sdim * Low-level operations for use by console and/or debug port support.
34218885Sdim */
35218885Sdimstruct uart_ops {
36218885Sdim	int (*probe)(struct uart_bas *);
37218885Sdim	void (*init)(struct uart_bas *, int, int, int, int);
38218885Sdim	void (*term)(struct uart_bas *);
39218885Sdim	void (*putc)(struct uart_bas *, int);
40218885Sdim	int (*poll)(struct uart_bas *);
41218885Sdim	int (*getc)(struct uart_bas *);
42218885Sdim};
43218885Sdim
44218885Sdimextern struct uart_ops uart_i8251_ops;
45218885Sdimextern struct uart_ops uart_ns8250_ops;
46218885Sdimextern struct uart_ops uart_sab82532_ops;
47218885Sdimextern struct uart_ops uart_z8530_ops;
48218885Sdim
49218885Sdim/*
50218885Sdim * Console and debug port device info.
51218885Sdim */
52218885Sdimstruct uart_softc;
53218885Sdimstruct uart_devinfo {
54218885Sdim	SLIST_ENTRY(uart_devinfo) next;
55218885Sdim	struct uart_ops ops;
56218885Sdim	struct uart_bas bas;
57218885Sdim	int	baudrate;
58218885Sdim	int	databits;
59218885Sdim	int	stopbits;
60218885Sdim	int	parity;
61218885Sdim	int	type;
62218885Sdim#define	UART_DEV_CONSOLE	0
63218885Sdim#define	UART_DEV_DBGPORT	1
64218885Sdim#define	UART_DEV_KEYBOARD	2
65218885Sdim	int	(*attach)(struct uart_softc*);
66218885Sdim	int	(*detach)(struct uart_softc*);
67218885Sdim	void	*cookie;		/* Type dependent use. */
68218885Sdim};
69218885Sdim
70218885Sdimint uart_cpu_eqres(struct uart_bas *, struct uart_bas *);
71218885Sdimint uart_cpu_getdev(int, struct uart_devinfo *);
72218885Sdim
73218885Sdimvoid uart_add_sysdev(struct uart_devinfo*);
74218885Sdim
75218885Sdim/*
76218885Sdim * Operations for low-level access to the UART. Primarily for use
77218885Sdim * by console and debug port logic.
78218885Sdim */
79218885Sdimstatic __inline int
80218885Sdimuart_probe(struct uart_devinfo *di)
81218885Sdim{
82218885Sdim	return (di->ops.probe(&di->bas));
83218885Sdim}
84218885Sdim
85218885Sdimstatic __inline void
86218885Sdimuart_init(struct uart_devinfo *di)
87218885Sdim{
88218885Sdim	di->ops.init(&di->bas, di->baudrate, di->databits, di->stopbits,
89218885Sdim	    di->parity);
90218885Sdim}
91218885Sdim
92218885Sdimstatic __inline void
93218885Sdimuart_term(struct uart_devinfo *di)
94218885Sdim{
95218885Sdim	di->ops.term(&di->bas);
96218885Sdim}
97218885Sdim
98218885Sdimstatic __inline void
99218885Sdimuart_putc(struct uart_devinfo *di, int c)
100218885Sdim{
101218885Sdim	di->ops.putc(&di->bas, c);
102218885Sdim}
103218885Sdim
104218885Sdimstatic __inline int
105218885Sdimuart_poll(struct uart_devinfo *di)
106218885Sdim{
107218885Sdim	return (di->ops.poll(&di->bas));
108218885Sdim}
109218885Sdim
110218885Sdimstatic __inline int
111218885Sdimuart_getc(struct uart_devinfo *di)
112218885Sdim{
113218885Sdim	return (di->ops.getc(&di->bas));
114218885Sdim}
115218885Sdim
116218885Sdim#endif /* _DEV_UART_CPU_H_ */
117218885Sdim