1 /*********************************************************************
2  *
3  * Filename:      nsc-ircc.h
4  * Version:
5  * Description:
6  * Status:        Experimental.
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Fri Nov 13 14:37:40 1998
9  * Modified at:   Sun Jan 23 17:47:00 2000
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  *
12  *     Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
13  *     Copyright (c) 1998 Lichen Wang, <lwang@actisys.com>
14  *     Copyright (c) 1998 Actisys Corp., www.actisys.com
15  *     All Rights Reserved
16  *
17  *     This program is free software; you can redistribute it and/or
18  *     modify it under the terms of the GNU General Public License as
19  *     published by the Free Software Foundation; either version 2 of
20  *     the License, or (at your option) any later version.
21  *
22  *     Neither Dag Brattli nor University of Troms� admit liability nor
23  *     provide warranty for any of this software. This material is
24  *     provided "AS-IS" and at no charge.
25  *
26  ********************************************************************/
27 
28 #ifndef NSC_IRCC_H
29 #define NSC_IRCC_H
30 
31 #include <linux/time.h>
32 
33 #include <linux/spinlock.h>
34 #include <linux/pm.h>
35 #include <asm/io.h>
36 
37 /* DMA modes needed */
38 #define DMA_TX_MODE     0x08    /* Mem to I/O, ++, demand. */
39 #define DMA_RX_MODE     0x04    /* I/O to mem, ++, demand. */
40 
41 /* Config registers for the '108 */
42 #define CFG_108_BAIC 0x00
43 #define CFG_108_CSRT 0x01
44 #define CFG_108_MCTL 0x02
45 
46 /* Config registers for the '338 */
47 #define CFG_338_FER  0x00
48 #define CFG_338_FAR  0x01
49 #define CFG_338_PTR  0x02
50 #define CFG_338_PNP0 0x1b
51 #define CFG_338_PNP1 0x1c
52 #define CFG_338_PNP3 0x4f
53 
54 /* Config registers for the '39x (in the logical device bank) */
55 #define CFG_39X_LDN	0x07	/* Logical device number (Super I/O bank) */
56 #define CFG_39X_SIOCF1	0x21	/* SuperI/O Config */
57 #define CFG_39X_ACT	0x30	/* Device activation */
58 #define CFG_39X_BASEH	0x60	/* Device base address (high bits) */
59 #define CFG_39X_BASEL	0x61	/* Device base address (low bits) */
60 #define CFG_39X_IRQNUM	0x70	/* Interrupt number & wake up enable */
61 #define CFG_39X_IRQSEL	0x71	/* Interrupt select (edge/level + polarity) */
62 #define CFG_39X_DMA0	0x74	/* DMA 0 configuration */
63 #define CFG_39X_DMA1	0x75	/* DMA 1 configuration */
64 #define CFG_39X_SPC	0xF0	/* Serial port configuration register */
65 
66 /* Flags for configuration register CRF0 */
67 #define APEDCRC		0x02
68 #define ENBNKSEL	0x01
69 
70 /* Set 0 */
71 #define TXD             0x00 /* Transmit data port */
72 #define RXD             0x00 /* Receive data port */
73 
74 /* Register 1 */
75 #define IER		0x01 /* Interrupt Enable Register*/
76 #define IER_RXHDL_IE    0x01 /* Receiver high data level interrupt */
77 #define IER_TXLDL_IE    0x02 /* Transeiver low data level interrupt */
78 #define IER_LS_IE	0x04//* Link Status Interrupt */
79 #define IER_ETXURI      0x04 /* Tx underrun */
80 #define IER_DMA_IE	0x10 /* DMA finished interrupt */
81 #define IER_TXEMP_IE    0x20
82 #define IER_SFIF_IE     0x40 /* Frame status FIFO intr */
83 #define IER_TMR_IE      0x80 /* Timer event */
84 
85 #define FCR		0x02 /* (write only) */
86 #define FCR_FIFO_EN     0x01 /* Enable FIFO's */
87 #define FCR_RXSR        0x02 /* Rx FIFO soft reset */
88 #define FCR_TXSR        0x04 /* Tx FIFO soft reset */
89 #define FCR_RXTH	0x40 /* Rx FIFO threshold (set to 16) */
90 #define FCR_TXTH	0x20 /* Tx FIFO threshold (set to 17) */
91 
92 #define EIR		0x02 /* (read only) */
93 #define EIR_RXHDL_EV	0x01
94 #define EIR_TXLDL_EV    0x02
95 #define EIR_LS_EV	0x04
96 #define EIR_DMA_EV	0x10
97 #define EIR_TXEMP_EV	0x20
98 #define EIR_SFIF_EV     0x40
99 #define EIR_TMR_EV      0x80
100 
101 #define LCR             0x03 /* Link control register */
102 #define LCR_WLS_8       0x03 /* 8 bits */
103 
104 #define BSR 	        0x03 /* Bank select register */
105 #define BSR_BKSE        0x80
106 #define BANK0 	        LCR_WLS_8 /* Must make sure that we set 8N1 */
107 #define BANK1	        0x80
108 #define BANK2	        0xe0
109 #define BANK3	        0xe4
110 #define BANK4	        0xe8
111 #define BANK5	        0xec
112 #define BANK6	        0xf0
113 #define BANK7     	0xf4
114 
115 #define MCR		0x04 /* Mode Control Register */
116 #define MCR_MODE_MASK	~(0xd0)
117 #define MCR_UART        0x00
118 #define MCR_RESERVED  	0x20
119 #define MCR_SHARP_IR    0x40
120 #define MCR_SIR         0x60
121 #define MCR_MIR  	0x80
122 #define MCR_FIR		0xa0
123 #define MCR_CEIR        0xb0
124 #define MCR_IR_PLS      0x10
125 #define MCR_DMA_EN	0x04
126 #define MCR_EN_IRQ	0x08
127 #define MCR_TX_DFR	0x08
128 
129 #define LSR             0x05 /* Link status register */
130 #define LSR_RXDA        0x01 /* Receiver data available */
131 #define LSR_TXRDY       0x20 /* Transmitter ready */
132 #define LSR_TXEMP       0x40 /* Transmitter empty */
133 
134 #define ASCR            0x07 /* Auxillary Status and Control Register */
135 #define ASCR_RXF_TOUT   0x01 /* Rx FIFO timeout */
136 #define ASCR_FEND_INF   0x02 /* Frame end bytes in rx FIFO */
137 #define ASCR_S_EOT      0x04 /* Set end of transmission */
138 #define ASCT_RXBSY      0x20 /* Rx busy */
139 #define ASCR_TXUR       0x40 /* Transeiver underrun */
140 #define ASCR_CTE        0x80 /* Clear timer event */
141 
142 /* Bank 2 */
143 #define BGDL            0x00 /* Baud Generator Divisor Port (Low Byte) */
144 #define BGDH            0x01 /* Baud Generator Divisor Port (High Byte) */
145 
146 #define ECR1		0x02 /* Extended Control Register 1 */
147 #define ECR1_EXT_SL	0x01 /* Extended Mode Select */
148 #define ECR1_DMANF	0x02 /* DMA Fairness */
149 #define ECR1_DMATH      0x04 /* DMA Threshold */
150 #define ECR1_DMASWP	0x08 /* DMA Swap */
151 
152 #define EXCR2		0x04
153 #define EXCR2_TFSIZ	0x01 /* Rx FIFO size = 32 */
154 #define EXCR2_RFSIZ	0x04 /* Tx FIFO size = 32 */
155 
156 #define TXFLV           0x06 /* Tx FIFO level */
157 #define RXFLV           0x07 /* Rx FIFO level */
158 
159 /* Bank 3 */
160 #define MID		0x00
161 
162 /* Bank 4 */
163 #define TMRL            0x00 /* Timer low byte */
164 #define TMRH            0x01 /* Timer high byte */
165 #define IRCR1           0x02 /* Infrared control register 1 */
166 #define IRCR1_TMR_EN    0x01 /* Timer enable */
167 
168 #define TFRLL		0x04
169 #define TFRLH		0x05
170 #define RFRLL		0x06
171 #define RFRLH		0x07
172 
173 /* Bank 5 */
174 #define IRCR2           0x04 /* Infrared control register 2 */
175 #define IRCR2_MDRS      0x04 /* MIR data rate select */
176 #define IRCR2_FEND_MD   0x20 /* */
177 
178 #define FRM_ST          0x05 /* Frame status FIFO */
179 #define FRM_ST_VLD      0x80 /* Frame status FIFO data valid */
180 #define FRM_ST_ERR_MSK  0x5f
181 #define FRM_ST_LOST_FR  0x40 /* Frame lost */
182 #define FRM_ST_MAX_LEN  0x10 /* Max frame len exceeded */
183 #define FRM_ST_PHY_ERR  0x08 /* Physical layer error */
184 #define FRM_ST_BAD_CRC  0x04
185 #define FRM_ST_OVR1     0x02 /* Rx FIFO overrun */
186 #define FRM_ST_OVR2     0x01 /* Frame status FIFO overrun */
187 
188 #define RFLFL           0x06
189 #define RFLFH           0x07
190 
191 /* Bank 6 */
192 #define IR_CFG2		0x00
193 #define IR_CFG2_DIS_CRC	0x02
194 
195 /* Bank 7 */
196 #define IRM_CR		0x07 /* Infrared module control register */
197 #define IRM_CR_IRX_MSL	0x40
198 #define IRM_CR_AF_MNT   0x80 /* Automatic format */
199 
200 /* NSC chip information */
201 struct nsc_chip {
202 	char *name;          /* Name of chipset */
203 	int cfg[3];          /* Config registers */
204 	u_int8_t cid_index;  /* Chip identification index reg */
205 	u_int8_t cid_value;  /* Chip identification expected value */
206 	u_int8_t cid_mask;   /* Chip identification revision mask */
207 
208 	/* Functions for probing and initializing the specific chip */
209 	int (*probe)(struct nsc_chip *chip, chipio_t *info);
210 	int (*init)(struct nsc_chip *chip, chipio_t *info);
211 };
212 typedef struct nsc_chip nsc_chip_t;
213 
214 /* For storing entries in the status FIFO */
215 struct st_fifo_entry {
216 	int status;
217 	int len;
218 };
219 
220 #define MAX_TX_WINDOW 7
221 #define MAX_RX_WINDOW 7
222 
223 struct st_fifo {
224 	struct st_fifo_entry entries[MAX_RX_WINDOW];
225 	int pending_bytes;
226 	int head;
227 	int tail;
228 	int len;
229 };
230 
231 struct frame_cb {
232 	void *start; /* Start of frame in DMA mem */
233 	int len;     /* Lenght of frame in DMA mem */
234 };
235 
236 struct tx_fifo {
237 	struct frame_cb queue[MAX_TX_WINDOW]; /* Info about frames in queue */
238 	int             ptr;                  /* Currently being sent */
239 	int             len;                  /* Lenght of queue */
240 	int             free;                 /* Next free slot */
241 	void           *tail;                 /* Next free start in DMA mem */
242 };
243 
244 /* Private data for each instance */
245 struct nsc_ircc_cb {
246 	struct st_fifo st_fifo;    /* Info about received frames */
247 	struct tx_fifo tx_fifo;    /* Info about frames to be transmitted */
248 
249 	struct net_device *netdev;     /* Yes! we are some kind of netdevice */
250 	struct net_device_stats stats;
251 
252 	struct irlap_cb *irlap;    /* The link layer we are binded to */
253 	struct qos_info qos;       /* QoS capabilities for this device */
254 
255 	chipio_t io;               /* IrDA controller information */
256 	iobuff_t tx_buff;          /* Transmit buffer */
257 	iobuff_t rx_buff;          /* Receive buffer */
258 
259 	__u8 ier;                  /* Interrupt enable register */
260 
261 	struct timeval stamp;
262 	struct timeval now;
263 
264 	spinlock_t lock;           /* For serializing operations */
265 
266 	__u32 flags;               /* Interface flags */
267 	__u32 new_speed;
268 	int index;                 /* Instance index */
269 
270         struct pm_dev *dev;
271 };
272 
switch_bank(int iobase,int bank)273 static inline void switch_bank(int iobase, int bank)
274 {
275 		outb(bank, iobase+BSR);
276 }
277 
278 #endif /* NSC_IRCC_H */
279