imxuartvar.h revision 1.4.18.2 1 1.4.18.2 jdolecek /* $NetBSD: imxuartvar.h,v 1.4.18.2 2017/12/03 11:35:53 jdolecek Exp $ */
2 1.2 matt /*
3 1.2 matt * driver include for Freescale i.MX31 and i.MX31L UARTs
4 1.2 matt */
5 1.3 bsh /*
6 1.3 bsh * Copyright (c) 2009, 2010 Genetec Corporation. All rights reserved.
7 1.3 bsh * Written by Hiroyuki Bessho for Genetec Corporation.
8 1.3 bsh *
9 1.3 bsh * Redistribution and use in source and binary forms, with or without
10 1.3 bsh * modification, are permitted provided that the following conditions
11 1.3 bsh * are met:
12 1.3 bsh * 1. Redistributions of source code must retain the above copyright
13 1.3 bsh * notice, this list of conditions and the following disclaimer.
14 1.3 bsh * 2. Redistributions in binary form must reproduce the above copyright
15 1.3 bsh * notice, this list of conditions and the following disclaimer in the
16 1.3 bsh * documentation and/or other materials provided with the distribution.
17 1.3 bsh *
18 1.3 bsh * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
19 1.3 bsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.3 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.3 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
22 1.3 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.3 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.3 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.3 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.3 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.3 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.3 bsh * POSSIBILITY OF SUCH DAMAGE.
29 1.3 bsh *
30 1.3 bsh */
31 1.3 bsh #ifndef _IMXUARTVAR_H
32 1.3 bsh #define _IMXUARTVAR_H
33 1.3 bsh
34 1.3 bsh
35 1.3 bsh #include <sys/cdefs.h>
36 1.3 bsh #include <sys/termios.h> /* for tcflag_t */
37 1.3 bsh
38 1.4.18.2 jdolecek struct imxuart_softc {
39 1.4.18.2 jdolecek device_t sc_dev;
40 1.4.18.2 jdolecek
41 1.4.18.2 jdolecek int sc_unit;
42 1.4.18.2 jdolecek struct imxuart_regs {
43 1.4.18.2 jdolecek bus_space_tag_t ur_iot;
44 1.4.18.2 jdolecek bus_space_handle_t ur_ioh;
45 1.4.18.2 jdolecek bus_addr_t ur_iobase;
46 1.4.18.2 jdolecek #if 0
47 1.4.18.2 jdolecek bus_size_t ur_nports;
48 1.4.18.2 jdolecek bus_size_t ur_map[16];
49 1.4.18.2 jdolecek #endif
50 1.4.18.2 jdolecek } sc_regs;
51 1.4.18.2 jdolecek
52 1.4.18.2 jdolecek #define sc_bt sc_regs.ur_iot
53 1.4.18.2 jdolecek #define sc_bh sc_regs.ur_ioh
54 1.4.18.2 jdolecek
55 1.4.18.2 jdolecek uint32_t sc_intrspec_enb;
56 1.4.18.2 jdolecek uint32_t sc_ucr2_d; /* target value for UCR2 */
57 1.4.18.2 jdolecek uint32_t sc_ucr[4]; /* cached value of UCRn */
58 1.4.18.2 jdolecek #define sc_ucr1 sc_ucr[0]
59 1.4.18.2 jdolecek #define sc_ucr2 sc_ucr[1]
60 1.4.18.2 jdolecek #define sc_ucr3 sc_ucr[2]
61 1.4.18.2 jdolecek #define sc_ucr4 sc_ucr[3]
62 1.4.18.2 jdolecek
63 1.4.18.2 jdolecek uint sc_init_cnt;
64 1.4.18.2 jdolecek
65 1.4.18.2 jdolecek bus_addr_t sc_addr;
66 1.4.18.2 jdolecek bus_size_t sc_size;
67 1.4.18.2 jdolecek int sc_intr;
68 1.4.18.2 jdolecek
69 1.4.18.2 jdolecek u_char sc_hwflags;
70 1.4.18.2 jdolecek /* Hardware flag masks */
71 1.4.18.2 jdolecek #define IMXUART_HW_FLOW __BIT(0)
72 1.4.18.2 jdolecek #define IMXUART_HW_DEV_OK __BIT(1)
73 1.4.18.2 jdolecek #define IMXUART_HW_CONSOLE __BIT(2)
74 1.4.18.2 jdolecek #define IMXUART_HW_KGDB __BIT(3)
75 1.4.18.2 jdolecek
76 1.4.18.2 jdolecek bool enabled;
77 1.4.18.2 jdolecek
78 1.4.18.2 jdolecek u_char sc_swflags;
79 1.4.18.2 jdolecek
80 1.4.18.2 jdolecek u_char sc_rx_flags;
81 1.4.18.2 jdolecek #define IMXUART_RX_TTY_BLOCKED __BIT(0)
82 1.4.18.2 jdolecek #define IMXUART_RX_TTY_OVERFLOWED __BIT(1)
83 1.4.18.2 jdolecek #define IMXUART_RX_IBUF_BLOCKED __BIT(2)
84 1.4.18.2 jdolecek #define IMXUART_RX_IBUF_OVERFLOWED __BIT(3)
85 1.4.18.2 jdolecek #define IMXUART_RX_ANY_BLOCK \
86 1.4.18.2 jdolecek (IMXUART_RX_TTY_BLOCKED|IMXUART_RX_TTY_OVERFLOWED| \
87 1.4.18.2 jdolecek IMXUART_RX_IBUF_BLOCKED|IMXUART_RX_IBUF_OVERFLOWED)
88 1.4.18.2 jdolecek
89 1.4.18.2 jdolecek bool sc_tx_busy, sc_tx_done, sc_tx_stopped;
90 1.4.18.2 jdolecek bool sc_rx_ready,sc_st_check;
91 1.4.18.2 jdolecek u_short sc_txfifo_len, sc_txfifo_thresh;
92 1.4.18.2 jdolecek
93 1.4.18.2 jdolecek uint16_t *sc_rbuf;
94 1.4.18.2 jdolecek u_int sc_rbuf_size;
95 1.4.18.2 jdolecek u_int sc_rbuf_in;
96 1.4.18.2 jdolecek u_int sc_rbuf_out;
97 1.4.18.2 jdolecek #define IMXUART_RBUF_AVAIL(sc) \
98 1.4.18.2 jdolecek ((sc->sc_rbuf_out <= sc->sc_rbuf_in) ? \
99 1.4.18.2 jdolecek (sc->sc_rbuf_in - sc->sc_rbuf_out) : \
100 1.4.18.2 jdolecek (sc->sc_rbuf_size - (sc->sc_rbuf_out - sc->sc_rbuf_in)))
101 1.4.18.2 jdolecek
102 1.4.18.2 jdolecek #define IMXUART_RBUF_SPACE(sc) \
103 1.4.18.2 jdolecek ((sc->sc_rbuf_in <= sc->sc_rbuf_out ? \
104 1.4.18.2 jdolecek sc->sc_rbuf_size - (sc->sc_rbuf_out - sc->sc_rbuf_in) : \
105 1.4.18.2 jdolecek sc->sc_rbuf_in - sc->sc_rbuf_out) - 1)
106 1.4.18.2 jdolecek /* increment ringbuffer pointer */
107 1.4.18.2 jdolecek #define IMXUART_RBUF_INC(sc,v,i) (((v) + (i))&((sc->sc_rbuf_size)-1))
108 1.4.18.2 jdolecek u_int sc_r_lowat;
109 1.4.18.2 jdolecek u_int sc_r_hiwat;
110 1.4.18.2 jdolecek
111 1.4.18.2 jdolecek /* output chunk */
112 1.4.18.2 jdolecek u_char *sc_tba;
113 1.4.18.2 jdolecek u_int sc_tbc;
114 1.4.18.2 jdolecek u_int sc_heldtbc;
115 1.4.18.2 jdolecek /* pending parameter changes */
116 1.4.18.2 jdolecek u_char sc_pending;
117 1.4.18.2 jdolecek #define IMXUART_PEND_PARAM __BIT(0)
118 1.4.18.2 jdolecek #define IMXUART_PEND_SPEED __BIT(1)
119 1.4.18.2 jdolecek
120 1.4.18.2 jdolecek
121 1.4.18.2 jdolecek struct callout sc_diag_callout;
122 1.4.18.2 jdolecek kmutex_t sc_lock;
123 1.4.18.2 jdolecek void *sc_ih; /* interrupt handler */
124 1.4.18.2 jdolecek void *sc_si; /* soft interrupt */
125 1.4.18.2 jdolecek struct tty *sc_tty;
126 1.4.18.2 jdolecek
127 1.4.18.2 jdolecek /* power management hooks */
128 1.4.18.2 jdolecek int (*enable)(struct imxuart_softc *);
129 1.4.18.2 jdolecek void (*disable)(struct imxuart_softc *);
130 1.4.18.2 jdolecek
131 1.4.18.2 jdolecek struct {
132 1.4.18.2 jdolecek ulong err;
133 1.4.18.2 jdolecek ulong brk;
134 1.4.18.2 jdolecek ulong prerr;
135 1.4.18.2 jdolecek ulong frmerr;
136 1.4.18.2 jdolecek ulong ovrrun;
137 1.4.18.2 jdolecek } sc_errors;
138 1.4.18.2 jdolecek
139 1.4.18.2 jdolecek struct imxuart_baudrate_ratio {
140 1.4.18.2 jdolecek uint16_t numerator; /* UBIR */
141 1.4.18.2 jdolecek uint16_t modulator; /* UBMR */
142 1.4.18.2 jdolecek } sc_ratio;
143 1.4.18.2 jdolecek
144 1.4.18.2 jdolecek };
145 1.3 bsh
146 1.4 bsh void imxuart_attach_common(device_t parent, device_t self,
147 1.3 bsh bus_space_tag_t, paddr_t, size_t, int, int);
148 1.3 bsh
149 1.3 bsh int imxuart_kgdb_attach(bus_space_tag_t, paddr_t, u_int, tcflag_t);
150 1.4.18.2 jdolecek int imxuart_cnattach(bus_space_tag_t, paddr_t, u_int, tcflag_t);
151 1.2 matt
152 1.3 bsh int imxuart_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
153 1.3 bsh
154 1.3 bsh /*
155 1.3 bsh * Set platform dependent values
156 1.3 bsh */
157 1.3 bsh void imxuart_set_frequency(u_int, u_int);
158 1.3 bsh
159 1.3 bsh /*
160 1.3 bsh * defined in imx51uart.c and imx31uart.c
161 1.3 bsh */
162 1.4.18.1 tls int imxuart_match(device_t, cfdata_t, void *);
163 1.4.18.1 tls void imxuart_attach(device_t, device_t, void *);
164 1.2 matt
165 1.4.18.2 jdolecek void imxuart_attach_subr(struct imxuart_softc *);
166 1.4.18.2 jdolecek
167 1.4.18.2 jdolecek int imxuintr(void *);
168 1.4.18.2 jdolecek
169 1.3 bsh #endif /* _IMXUARTVAR_H */
170