gtmpscvar.h revision 1.7.88.1 1 1.7.88.1 uebayasi /* $NetBSD: gtmpscvar.h,v 1.7.88.1 2010/04/30 14:43:27 uebayasi Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Redistribution and use in source and binary forms, with or without
8 1.1 matt * modification, are permitted provided that the following conditions
9 1.1 matt * are met:
10 1.1 matt * 1. Redistributions of source code must retain the above copyright
11 1.1 matt * notice, this list of conditions and the following disclaimer.
12 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer in the
14 1.1 matt * documentation and/or other materials provided with the distribution.
15 1.1 matt * 3. All advertising materials mentioning features or use of this software
16 1.1 matt * must display the following acknowledgement:
17 1.1 matt * This product includes software developed for the NetBSD Project by
18 1.1 matt * Allegro Networks, Inc., and Wasabi Systems, Inc.
19 1.1 matt * 4. The name of Allegro Networks, Inc. may not be used to endorse
20 1.1 matt * or promote products derived from this software without specific prior
21 1.1 matt * written permission.
22 1.1 matt * 5. The name of Wasabi Systems, Inc. may not be used to endorse
23 1.1 matt * or promote products derived from this software without specific prior
24 1.1 matt * written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
27 1.1 matt * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 1.1 matt * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 1.1 matt * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 1.1 matt * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
31 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
38 1.1 matt */
39 1.1 matt
40 1.1 matt /*
41 1.1 matt * gtmpscvar.h - includes for gtmpsctty GT-64260 UART-mode serial driver
42 1.1 matt *
43 1.1 matt * creation Mon Apr 9 19:54:33 PDT 2001 cliff
44 1.1 matt */
45 1.2 matt #ifndef _DEV_MARVELL_GTMPSCVAR_H
46 1.2 matt #define _DEV_MARVELL_GTMPSCVAR_H
47 1.1 matt
48 1.1 matt #include "opt_marvell.h"
49 1.1 matt
50 1.5 perry #ifndef GT_MPSC_DEFAULT_BAUD_RATE
51 1.2 matt #define GT_MPSC_DEFAULT_BAUD_RATE 115200
52 1.1 matt #endif
53 1.2 matt #define GTMPSC_CLOCK_DIVIDER 8
54 1.2 matt #define GTMPSC_MMCR_HI_TCDV_DEFAULT GTMPSC_MMCR_HI_TCDV_8X
55 1.2 matt #define GTMPSC_MMCR_HI_RCDV_DEFAULT GTMPSC_MMCR_HI_RCDV_8X
56 1.2 matt #define BRG_BCR_CDV_MAX 0xffff
57 1.1 matt
58 1.1 matt /*
59 1.5 perry * gtmpsc_poll_dmapage_t - used for MPSC getchar/putchar polled console
60 1.1 matt *
61 1.1 matt * sdma descriptors must be 16 byte aligned
62 1.1 matt * sdma RX buffer pointers must be 8 byte aligned
63 1.1 matt */
64 1.2 matt #define GTMPSC_NTXDESC 64
65 1.2 matt #define GTMPSC_NRXDESC 64
66 1.2 matt #define GTMPSC_TXBUFSZ 16
67 1.2 matt #define GTMPSC_RXBUFSZ 16
68 1.1 matt
69 1.1 matt typedef struct gtmpsc_polltx {
70 1.1 matt sdma_desc_t txdesc;
71 1.1 matt unsigned char txbuf[GTMPSC_TXBUFSZ];
72 1.1 matt } gtmpsc_polltx_t;
73 1.1 matt
74 1.1 matt typedef struct gtmpsc_pollrx {
75 1.1 matt sdma_desc_t rxdesc;
76 1.1 matt unsigned char rxbuf[GTMPSC_RXBUFSZ];
77 1.1 matt } gtmpsc_pollrx_t;
78 1.1 matt
79 1.1 matt typedef struct {
80 1.1 matt gtmpsc_polltx_t tx[GTMPSC_NTXDESC];
81 1.1 matt gtmpsc_pollrx_t rx[GTMPSC_NRXDESC];
82 1.5 perry } gtmpsc_poll_sdma_t;
83 1.1 matt
84 1.1 matt
85 1.7.88.1 uebayasi #include <sys/timepps.h>
86 1.7.88.1 uebayasi #include <sys/tty.h>
87 1.1 matt
88 1.1 matt typedef struct gtmpsc_softc {
89 1.7.88.1 uebayasi device_t sc_dev;
90 1.7.88.1 uebayasi int sc_unit;
91 1.7.88.1 uebayasi bus_space_tag_t sc_iot;
92 1.7.88.1 uebayasi bus_space_handle_t sc_mpsch;
93 1.7.88.1 uebayasi bus_space_handle_t sc_sdmah;
94 1.7.88.1 uebayasi bus_dma_tag_t sc_dmat;
95 1.7.88.1 uebayasi gtmpsc_poll_sdma_t *sc_poll_sdmapage;
96 1.7.88.1 uebayasi bus_dmamap_t sc_rxdma_map;
97 1.7.88.1 uebayasi bus_dmamap_t sc_txdma_map;
98 1.7.88.1 uebayasi int sc_brg; /* using Baud Rate Generator */
99 1.7.88.1 uebayasi int sc_baudrate;
100 1.7.88.1 uebayasi tcflag_t sc_cflag;
101 1.2 matt void *sc_si; /* softintr cookie */
102 1.7.88.1 uebayasi struct tty *sc_tty; /* our tty */
103 1.7.88.1 uebayasi uint32_t sc_flags;
104 1.7.88.1 uebayasi #define GTMPSC_CONSOLE (1 << 0)
105 1.7.88.1 uebayasi #define GTMPSC_KGDB (1 << 1)
106 1.7.88.1 uebayasi
107 1.7.88.1 uebayasi volatile int sc_rcvcnt; /* byte count of RX buffer */
108 1.7.88.1 uebayasi volatile int sc_roffset; /* offset of RX buffer */
109 1.7.88.1 uebayasi volatile int sc_rcvrx; /* receive rx xfer index */
110 1.7.88.1 uebayasi volatile int sc_rcvdrx; /* received rx xfer index */
111 1.7.88.1 uebayasi volatile int sc_readrx; /* read rx xfer index */
112 1.7.88.1 uebayasi volatile int sc_nexttx; /* "next" tx xfer index */
113 1.7.88.1 uebayasi volatile int sc_lasttx; /* "last" tx xfer index */
114 1.7.88.1 uebayasi volatile u_char sc_rx_ready;
115 1.1 matt volatile u_char sc_tx_busy;
116 1.1 matt volatile u_char sc_tx_done;
117 1.1 matt volatile u_char sc_tx_stopped;
118 1.7.88.1 uebayasi volatile u_char sc_heldchange; /* new params wait for output */
119 1.7.88.1 uebayasi u_char *sc_tba; /* Tx buf ptr */
120 1.7.88.1 uebayasi u_int sc_tbc; /* Tx buf cnt */
121 1.7.88.1 uebayasi u_int sc_heldtbc;
122 1.7.88.1 uebayasi
123 1.7.88.1 uebayasi kmutex_t sc_lock;
124 1.7.88.1 uebayasi struct pps_state sc_pps_state;
125 1.1 matt } gtmpsc_softc_t;
126 1.1 matt
127 1.1 matt /* Make receiver interrupt 8 times a second */
128 1.7.88.1 uebayasi /* There are 10 bits in a frame */
129 1.7.88.1 uebayasi #define GTMPSC_MAXIDLE(baudrate) ((baudrate) / (10 * 8))
130 1.7.88.1 uebayasi
131 1.7.88.1 uebayasi
132 1.7.88.1 uebayasi static __inline int
133 1.7.88.1 uebayasi compute_cdv(unsigned int baud)
134 1.7.88.1 uebayasi {
135 1.7.88.1 uebayasi unsigned int cdv;
136 1.7.88.1 uebayasi
137 1.7.88.1 uebayasi if (baud == 0)
138 1.7.88.1 uebayasi return 0;
139 1.7.88.1 uebayasi cdv = (GT_MPSC_FREQUENCY / (baud * GTMPSC_CLOCK_DIVIDER) + 1) / 2 - 1;
140 1.7.88.1 uebayasi if (cdv > BRG_BCR_CDV_MAX)
141 1.7.88.1 uebayasi return -1;
142 1.7.88.1 uebayasi return cdv;
143 1.7.88.1 uebayasi }
144 1.2 matt
145 1.7.88.1 uebayasi
146 1.7.88.1 uebayasi int gtmpsc_intr(void *);
147 1.7.88.1 uebayasi
148 1.7.88.1 uebayasi #ifdef MPSC_CONSOLE
149 1.7.88.1 uebayasi extern gtmpsc_softc_t gtmpsc_cn_softc;
150 1.7.88.1 uebayasi
151 1.7.88.1 uebayasi int gtmpsccnattach(bus_space_tag_t, bus_dma_tag_t, bus_addr_t, int, int, int,
152 1.7.88.1 uebayasi tcflag_t);
153 1.7.88.1 uebayasi #endif
154 1.2 matt
155 1.2 matt #endif /* _DEV_MARVELL_GTPSCVAR_H */
156