imxuartvar.h revision 1.6 1 1.6 hkenken /* $NetBSD: imxuartvar.h,v 1.6 2017/09/08 05:29:12 hkenken 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.6 hkenken struct imxuart_softc {
39 1.6 hkenken device_t sc_dev;
40 1.6 hkenken
41 1.6 hkenken int sc_unit;
42 1.6 hkenken struct imxuart_regs {
43 1.6 hkenken bus_space_tag_t ur_iot;
44 1.6 hkenken bus_space_handle_t ur_ioh;
45 1.6 hkenken bus_addr_t ur_iobase;
46 1.6 hkenken #if 0
47 1.6 hkenken bus_size_t ur_nports;
48 1.6 hkenken bus_size_t ur_map[16];
49 1.6 hkenken #endif
50 1.6 hkenken } sc_regs;
51 1.6 hkenken
52 1.6 hkenken #define sc_bt sc_regs.ur_iot
53 1.6 hkenken #define sc_bh sc_regs.ur_ioh
54 1.6 hkenken
55 1.6 hkenken uint32_t sc_intrspec_enb;
56 1.6 hkenken uint32_t sc_ucr2_d; /* target value for UCR2 */
57 1.6 hkenken uint32_t sc_ucr[4]; /* cached value of UCRn */
58 1.6 hkenken #define sc_ucr1 sc_ucr[0]
59 1.6 hkenken #define sc_ucr2 sc_ucr[1]
60 1.6 hkenken #define sc_ucr3 sc_ucr[2]
61 1.6 hkenken #define sc_ucr4 sc_ucr[3]
62 1.6 hkenken
63 1.6 hkenken uint sc_init_cnt;
64 1.6 hkenken
65 1.6 hkenken bus_addr_t sc_addr;
66 1.6 hkenken bus_size_t sc_size;
67 1.6 hkenken int sc_intr;
68 1.6 hkenken
69 1.6 hkenken u_char sc_hwflags;
70 1.6 hkenken /* Hardware flag masks */
71 1.6 hkenken #define IMXUART_HW_FLOW __BIT(0)
72 1.6 hkenken #define IMXUART_HW_DEV_OK __BIT(1)
73 1.6 hkenken #define IMXUART_HW_CONSOLE __BIT(2)
74 1.6 hkenken #define IMXUART_HW_KGDB __BIT(3)
75 1.6 hkenken
76 1.6 hkenken bool enabled;
77 1.6 hkenken
78 1.6 hkenken u_char sc_swflags;
79 1.6 hkenken
80 1.6 hkenken u_char sc_rx_flags;
81 1.6 hkenken #define IMXUART_RX_TTY_BLOCKED __BIT(0)
82 1.6 hkenken #define IMXUART_RX_TTY_OVERFLOWED __BIT(1)
83 1.6 hkenken #define IMXUART_RX_IBUF_BLOCKED __BIT(2)
84 1.6 hkenken #define IMXUART_RX_IBUF_OVERFLOWED __BIT(3)
85 1.6 hkenken #define IMXUART_RX_ANY_BLOCK \
86 1.6 hkenken (IMXUART_RX_TTY_BLOCKED|IMXUART_RX_TTY_OVERFLOWED| \
87 1.6 hkenken IMXUART_RX_IBUF_BLOCKED|IMXUART_RX_IBUF_OVERFLOWED)
88 1.6 hkenken
89 1.6 hkenken bool sc_tx_busy, sc_tx_done, sc_tx_stopped;
90 1.6 hkenken bool sc_rx_ready,sc_st_check;
91 1.6 hkenken u_short sc_txfifo_len, sc_txfifo_thresh;
92 1.6 hkenken
93 1.6 hkenken uint16_t *sc_rbuf;
94 1.6 hkenken u_int sc_rbuf_size;
95 1.6 hkenken u_int sc_rbuf_in;
96 1.6 hkenken u_int sc_rbuf_out;
97 1.6 hkenken #define IMXUART_RBUF_AVAIL(sc) \
98 1.6 hkenken ((sc->sc_rbuf_out <= sc->sc_rbuf_in) ? \
99 1.6 hkenken (sc->sc_rbuf_in - sc->sc_rbuf_out) : \
100 1.6 hkenken (sc->sc_rbuf_size - (sc->sc_rbuf_out - sc->sc_rbuf_in)))
101 1.6 hkenken
102 1.6 hkenken #define IMXUART_RBUF_SPACE(sc) \
103 1.6 hkenken ((sc->sc_rbuf_in <= sc->sc_rbuf_out ? \
104 1.6 hkenken sc->sc_rbuf_size - (sc->sc_rbuf_out - sc->sc_rbuf_in) : \
105 1.6 hkenken sc->sc_rbuf_in - sc->sc_rbuf_out) - 1)
106 1.6 hkenken /* increment ringbuffer pointer */
107 1.6 hkenken #define IMXUART_RBUF_INC(sc,v,i) (((v) + (i))&((sc->sc_rbuf_size)-1))
108 1.6 hkenken u_int sc_r_lowat;
109 1.6 hkenken u_int sc_r_hiwat;
110 1.6 hkenken
111 1.6 hkenken /* output chunk */
112 1.6 hkenken u_char *sc_tba;
113 1.6 hkenken u_int sc_tbc;
114 1.6 hkenken u_int sc_heldtbc;
115 1.6 hkenken /* pending parameter changes */
116 1.6 hkenken u_char sc_pending;
117 1.6 hkenken #define IMXUART_PEND_PARAM __BIT(0)
118 1.6 hkenken #define IMXUART_PEND_SPEED __BIT(1)
119 1.6 hkenken
120 1.6 hkenken
121 1.6 hkenken struct callout sc_diag_callout;
122 1.6 hkenken kmutex_t sc_lock;
123 1.6 hkenken void *sc_ih; /* interrupt handler */
124 1.6 hkenken void *sc_si; /* soft interrupt */
125 1.6 hkenken struct tty *sc_tty;
126 1.6 hkenken
127 1.6 hkenken /* power management hooks */
128 1.6 hkenken int (*enable)(struct imxuart_softc *);
129 1.6 hkenken void (*disable)(struct imxuart_softc *);
130 1.6 hkenken
131 1.6 hkenken struct {
132 1.6 hkenken ulong err;
133 1.6 hkenken ulong brk;
134 1.6 hkenken ulong prerr;
135 1.6 hkenken ulong frmerr;
136 1.6 hkenken ulong ovrrun;
137 1.6 hkenken } sc_errors;
138 1.6 hkenken
139 1.6 hkenken struct imxuart_baudrate_ratio {
140 1.6 hkenken uint16_t numerator; /* UBIR */
141 1.6 hkenken uint16_t modulator; /* UBMR */
142 1.6 hkenken } sc_ratio;
143 1.6 hkenken
144 1.6 hkenken };
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.6 hkenken 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.5 chs int imxuart_match(device_t, cfdata_t, void *);
163 1.5 chs void imxuart_attach(device_t, device_t, void *);
164 1.2 matt
165 1.6 hkenken void imxuart_attach_subr(struct imxuart_softc *);
166 1.6 hkenken
167 1.6 hkenken int imxuintr(void *);
168 1.6 hkenken
169 1.3 bsh #endif /* _IMXUARTVAR_H */
170