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