]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/s626.h
Merge branch 'next' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[karo-tx-linux.git] / drivers / staging / comedi / drivers / s626.h
1 /*
2   comedi/drivers/s626.h
3   Sensoray s626 Comedi driver, header file
4
5   COMEDI - Linux Control and Measurement Device Interface
6   Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7
8   Based on Sensoray Model 626 Linux driver Version 0.2
9   Copyright (C) 2002-2004 Sensoray Co., Inc.
10
11   This program is free software; you can redistribute it and/or modify
12   it under the terms of the GNU General Public License as published by
13   the Free Software Foundation; either version 2 of the License, or
14   (at your option) any later version.
15
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20 */
21
22 /*
23   Driver: s626.o (s626.ko)
24   Description: Sensoray 626 driver
25   Devices: Sensoray s626
26   Authors: Gianluca Palli <gpalli@deis.unibo.it>,
27   Updated: Thu, 12 Jul 2005
28   Status: experimental
29
30   Configuration Options:
31   analog input:
32    none
33
34   analog output:
35    none
36
37   digital channel:
38    s626 has 3 dio subdevices (2,3 and 4) each with 16 i/o channels
39    supported configuration options:
40    INSN_CONFIG_DIO_QUERY
41    COMEDI_INPUT
42    COMEDI_OUTPUT
43
44   encoder:
45    Every channel must be configured before reading.
46
47    Example code
48
49    insn.insn=INSN_CONFIG;   // configuration instruction
50    insn.n=1;                // number of operation (must be 1)
51    insn.data=&initialvalue; // initial value loaded into encoder
52                             // during configuration
53    insn.subdev=5;           // encoder subdevice
54    insn.chanspec=CR_PACK(encoder_channel,0,AREF_OTHER); // encoder_channel
55                                                         // to configure
56
57    comedi_do_insn(cf,&insn); // executing configuration
58 */
59
60 #if !defined(TRUE)
61 #define TRUE    (1)
62 #endif
63
64 #if !defined(FALSE)
65 #define FALSE   (0)
66 #endif
67
68 #define S626_SIZE 0x0200
69 #define DMABUF_SIZE                     4096    /*  4k pages */
70
71 #define S626_ADC_CHANNELS       16
72 #define S626_DAC_CHANNELS       4
73 #define S626_ENCODER_CHANNELS   6
74 #define S626_DIO_CHANNELS       48
75 #define S626_DIO_BANKS          3       /*  Number of DIO groups. */
76 #define S626_DIO_EXTCHANS       40      /*  Number of */
77                                         /*  extended-capability */
78                                         /*  DIO channels. */
79
80 #define NUM_TRIMDACS    12      /*  Number of valid TrimDAC channels. */
81
82 /*  PCI bus interface types. */
83 #define INTEL                           1       /*  Intel bus type. */
84 #define MOTOROLA                        2       /*  Motorola bus type. */
85
86 #define PLATFORM                INTEL   /*  *** SELECT PLATFORM TYPE *** */
87
88 #define RANGE_5V                0x10    /*  +/-5V range */
89 #define RANGE_10V               0x00    /*  +/-10V range */
90
91 #define EOPL                    0x80    /*  End of ADC poll list marker. */
92 #define GSEL_BIPOLAR5V          0x00F0  /*  LP_GSEL setting for 5V bipolar range. */
93 #define GSEL_BIPOLAR10V         0x00A0  /*  LP_GSEL setting for 10V bipolar range. */
94
95 /*  Error codes that must be visible to this base class. */
96 #define ERR_ILLEGAL_PARM        0x00010000      /*  Illegal function parameter value was specified. */
97 #define ERR_I2C                 0x00020000      /*  I2C error. */
98 #define ERR_COUNTERSETUP        0x00200000      /*  Illegal setup specified for counter channel. */
99 #define ERR_DEBI_TIMEOUT        0x00400000      /*  DEBI transfer timed out. */
100
101 /*  Organization (physical order) and size (in DWORDs) of logical DMA buffers contained by ANA_DMABUF. */
102 #define ADC_DMABUF_DWORDS       40      /*  ADC DMA buffer must hold 16 samples, plus pre/post garbage samples. */
103 #define DAC_WDMABUF_DWORDS      1       /*  DAC output DMA buffer holds a single sample. */
104
105 /*  All remaining space in 4KB DMA buffer is available for the RPS1 program. */
106
107 /*  Address offsets, in DWORDS, from base of DMA buffer. */
108 #define DAC_WDMABUF_OS          ADC_DMABUF_DWORDS
109
110 /*  Interrupt enab bit in ISR and IER. */
111 #define IRQ_GPIO3               0x00000040      /*  IRQ enable for GPIO3. */
112 #define IRQ_RPS1                0x10000000
113 #define ISR_AFOU                0x00000800
114 /* Audio fifo under/overflow  detected. */
115
116 #define IRQ_COINT1A             0x0400  /* conter 1A overflow interrupt mask */
117 #define IRQ_COINT1B             0x0800  /* conter 1B overflow interrupt mask */
118 #define IRQ_COINT2A             0x1000  /* conter 2A overflow interrupt mask */
119 #define IRQ_COINT2B             0x2000  /* conter 2B overflow interrupt mask */
120 #define IRQ_COINT3A             0x4000  /* conter 3A overflow interrupt mask */
121 #define IRQ_COINT3B             0x8000  /* conter 3B overflow interrupt mask */
122
123 /*  RPS command codes. */
124 #define RPS_CLRSIGNAL           0x00000000      /*  CLEAR SIGNAL */
125 #define RPS_SETSIGNAL           0x10000000      /*  SET SIGNAL */
126 #define RPS_NOP                 0x00000000      /*  NOP */
127 #define RPS_PAUSE               0x20000000      /*  PAUSE */
128 #define RPS_UPLOAD              0x40000000      /*  UPLOAD */
129 #define RPS_JUMP                0x80000000      /*  JUMP */
130 #define RPS_LDREG               0x90000100      /*  LDREG (1 uint32_t only) */
131 #define RPS_STREG               0xA0000100      /*  STREG (1 uint32_t only) */
132 #define RPS_STOP                0x50000000      /*  STOP */
133 #define RPS_IRQ                 0x60000000      /*  IRQ */
134
135 #define RPS_LOGICAL_OR          0x08000000      /*  Logical OR conditionals. */
136 #define RPS_INVERT              0x04000000      /*  Test for negated semaphores. */
137 #define RPS_DEBI                0x00000002      /*  DEBI done */
138
139 #define RPS_SIG0                0x00200000      /*  RPS semaphore 0 (used by ADC). */
140 #define RPS_SIG1                0x00400000      /*  RPS semaphore 1 (used by DAC). */
141 #define RPS_SIG2                0x00800000      /*  RPS semaphore 2 (not used). */
142 #define RPS_GPIO2               0x00080000      /*  RPS GPIO2 */
143 #define RPS_GPIO3               0x00100000      /*  RPS GPIO3 */
144
145 #define RPS_SIGADC              RPS_SIG0        /*  Trigger/status for ADC's RPS program. */
146 #define RPS_SIGDAC              RPS_SIG1        /*  Trigger/status for DAC's RPS program. */
147
148 /*  RPS clock parameters. */
149 #define RPSCLK_SCALAR           8       /*  This is apparent ratio of PCI/RPS clks (undocumented!!). */
150 #define RPSCLK_PER_US           (33 / RPSCLK_SCALAR)    /*  Number of RPS clocks in one microsecond. */
151
152 /*  Event counter source addresses. */
153 #define SBA_RPS_A0              0x27    /*  Time of RPS0 busy, in PCI clocks. */
154
155 /*  GPIO constants. */
156 #define GPIO_BASE               0x10004000      /*  GPIO 0,2,3 = inputs, GPIO3 = IRQ; GPIO1 = out. */
157 #define GPIO1_LO                0x00000000      /*  GPIO1 set to LOW. */
158 #define GPIO1_HI                0x00001000      /*  GPIO1 set to HIGH. */
159
160 /*  Primary Status Register (PSR) constants. */
161 #define PSR_DEBI_E              0x00040000      /*  DEBI event flag. */
162 #define PSR_DEBI_S              0x00080000      /*  DEBI status flag. */
163 #define PSR_A2_IN               0x00008000      /*  Audio output DMA2 protection address reached. */
164 #define PSR_AFOU                0x00000800      /*  Audio FIFO under/overflow detected. */
165 #define PSR_GPIO2               0x00000020      /*  GPIO2 input pin: 0=AdcBusy, 1=AdcIdle. */
166 #define PSR_EC0S                0x00000001      /*  Event counter 0 threshold reached. */
167
168 /*  Secondary Status Register (SSR) constants. */
169 #define SSR_AF2_OUT             0x00000200      /*  Audio 2 output FIFO under/overflow detected. */
170
171 /*  Master Control Register 1 (MC1) constants. */
172 #define MC1_SOFT_RESET          0x80000000      /*  Invoke 7146 soft reset. */
173 #define MC1_SHUTDOWN            0x3FFF0000      /*  Shut down all MC1-controlled enables. */
174
175 #define MC1_ERPS1               0x2000  /*  enab/disable RPS task 1. */
176 #define MC1_ERPS0               0x1000  /*  enab/disable RPS task 0. */
177 #define MC1_DEBI                0x0800  /*  enab/disable DEBI pins. */
178 #define MC1_AUDIO               0x0200  /*  enab/disable audio port pins. */
179 #define MC1_I2C                 0x0100  /*  enab/disable I2C interface. */
180 #define MC1_A2OUT               0x0008  /*  enab/disable transfer on A2 out. */
181 #define MC1_A2IN                0x0004  /*  enab/disable transfer on A2 in. */
182 #define MC1_A1IN                0x0001  /*  enab/disable transfer on A1 in. */
183
184 /*  Master Control Register 2 (MC2) constants. */
185 #define MC2_UPLD_DEBIq          0x00020002      /*  Upload DEBI registers. */
186 #define MC2_UPLD_IICq           0x00010001      /*  Upload I2C registers. */
187 #define MC2_RPSSIG2_ONq         0x20002000      /*  Assert RPS_SIG2. */
188 #define MC2_RPSSIG1_ONq         0x10001000      /*  Assert RPS_SIG1. */
189 #define MC2_RPSSIG0_ONq         0x08000800      /*  Assert RPS_SIG0. */
190 #define MC2_UPLD_DEBI_MASKq     0x00000002      /*  Upload DEBI mask. */
191 #define MC2_UPLD_IIC_MASKq      0x00000001      /*  Upload I2C mask. */
192 #define MC2_RPSSIG2_MASKq       0x00002000      /*  RPS_SIG2 bit mask. */
193 #define MC2_RPSSIG1_MASKq       0x00001000      /*  RPS_SIG1 bit mask. */
194 #define MC2_RPSSIG0_MASKq       0x00000800      /*  RPS_SIG0 bit mask. */
195
196 #define MC2_DELAYTRIG_4USq      MC2_RPSSIG1_ON
197 #define MC2_DELAYBUSY_4USq      MC2_RPSSIG1_MASK
198
199 #define MC2_DELAYTRIG_6USq      MC2_RPSSIG2_ON
200 #define MC2_DELAYBUSY_6USq      MC2_RPSSIG2_MASK
201
202 #define MC2_UPLD_DEBI           0x0002  /*  Upload DEBI. */
203 #define MC2_UPLD_IIC            0x0001  /*  Upload I2C. */
204 #define MC2_RPSSIG2             0x2000  /*  RPS signal 2 (not used). */
205 #define MC2_RPSSIG1             0x1000  /*  RPS signal 1 (DAC RPS busy). */
206 #define MC2_RPSSIG0             0x0800  /*  RPS signal 0 (ADC RPS busy). */
207
208 #define MC2_ADC_RPS             MC2_RPSSIG0     /*  ADC RPS busy. */
209 #define MC2_DAC_RPS             MC2_RPSSIG1     /*  DAC RPS busy. */
210
211 /* ***** oldies ***** */
212 #define MC2_UPLD_DEBIQ          0x00020002      /*  Upload DEBI registers. */
213 #define MC2_UPLD_IICQ           0x00010001      /*  Upload I2C registers. */
214
215 /*  PCI BUS (SAA7146) REGISTER ADDRESS OFFSETS */
216 #define P_PCI_BT_A              0x004C  /* Audio DMA burst/threshold control. */
217 #define P_DEBICFG               0x007C  /* DEBI configuration. */
218 #define P_DEBICMD               0x0080  /* DEBI command. */
219 #define P_DEBIPAGE              0x0084  /* DEBI page. */
220 #define P_DEBIAD                0x0088  /* DEBI target address. */
221 #define P_I2CCTRL               0x008C  /* I2C control. */
222 #define P_I2CSTAT               0x0090  /* I2C status. */
223 #define P_BASEA2_IN             0x00AC  /* Audio input 2 base physical DMAbuf
224                                          * address. */
225 #define P_PROTA2_IN             0x00B0  /* Audio input 2 physical DMAbuf
226                                          * protection address. */
227 #define P_PAGEA2_IN             0x00B4  /* Audio input 2 paging attributes. */
228 #define P_BASEA2_OUT            0x00B8  /* Audio output 2 base physical DMAbuf
229                                          * address. */
230 #define P_PROTA2_OUT            0x00BC  /* Audio output 2 physical DMAbuf
231                                          * protection address. */
232 #define P_PAGEA2_OUT            0x00C0  /* Audio output 2 paging attributes. */
233 #define P_RPSPAGE0              0x00C4  /* RPS0 page. */
234 #define P_RPSPAGE1              0x00C8  /* RPS1 page. */
235 #define P_RPS0_TOUT             0x00D4  /* RPS0 time-out. */
236 #define P_RPS1_TOUT             0x00D8  /* RPS1 time-out. */
237 #define P_IER                   0x00DC  /* Interrupt enable. */
238 #define P_GPIO                  0x00E0  /* General-purpose I/O. */
239 #define P_EC1SSR                0x00E4  /* Event counter set 1 source select. */
240 #define P_ECT1R                 0x00EC  /* Event counter threshold set 1. */
241 #define P_ACON1                 0x00F4  /* Audio control 1. */
242 #define P_ACON2                 0x00F8  /* Audio control 2. */
243 #define P_MC1                   0x00FC  /* Master control 1. */
244 #define P_MC2                   0x0100  /* Master control 2. */
245 #define P_RPSADDR0              0x0104  /* RPS0 instruction pointer. */
246 #define P_RPSADDR1              0x0108  /* RPS1 instruction pointer. */
247 #define P_ISR                   0x010C  /* Interrupt status. */
248 #define P_PSR                   0x0110  /* Primary status. */
249 #define P_SSR                   0x0114  /* Secondary status. */
250 #define P_EC1R                  0x0118  /* Event counter set 1. */
251 #define P_ADP4                  0x0138  /* Logical audio DMA pointer of audio
252                                          * input FIFO A2_IN. */
253 #define P_FB_BUFFER1            0x0144  /* Audio feedback buffer 1. */
254 #define P_FB_BUFFER2            0x0148  /* Audio feedback buffer 2. */
255 #define P_TSL1                  0x0180  /* Audio time slot list 1. */
256 #define P_TSL2                  0x01C0  /* Audio time slot list 2. */
257
258 /*  LOCAL BUS (GATE ARRAY) REGISTER ADDRESS OFFSETS */
259 /*  Analog I/O registers: */
260 #define LP_DACPOL               0x0082  /*   Write DAC polarity. */
261 #define LP_GSEL                 0x0084  /*   Write ADC gain. */
262 #define LP_ISEL                 0x0086  /*   Write ADC channel select. */
263
264 /* Digital I/O registers */
265 #define LP_RDDIN(x)             (0x0040 + (x) * 0x10)   /* R: digital input */
266 #define LP_WRINTSEL(x)          (0x0042 + (x) * 0x10)   /* W: int enable */
267 #define LP_WREDGSEL(x)          (0x0044 + (x) * 0x10)   /* W: edge selection */
268 #define LP_WRCAPSEL(x)          (0x0046 + (x) * 0x10)   /* W: capture enable */
269 #define LP_RDCAPFLG(x)          (0x0048 + (x) * 0x10)   /* R: edges captured */
270 #define LP_WRDOUT(x)            (0x0048 + (x) * 0x10)   /* W: digital output */
271 #define LP_RDINTSEL(x)          (0x004a + (x) * 0x10)   /* R: int enable */
272 #define LP_RDEDGSEL(x)          (0x004c + (x) * 0x10)   /* R: edge selection */
273 #define LP_RDCAPSEL(x)          (0x004e + (x) * 0x10)   /* R: capture enable */
274
275 /*  Counter Registers (read/write): */
276 #define LP_CR0A                 0x0000  /*   0A setup register. */
277 #define LP_CR0B                 0x0002  /*   0B setup register. */
278 #define LP_CR1A                 0x0004  /*   1A setup register. */
279 #define LP_CR1B                 0x0006  /*   1B setup register. */
280 #define LP_CR2A                 0x0008  /*   2A setup register. */
281 #define LP_CR2B                 0x000A  /*   2B setup register. */
282
283 /*  Counter PreLoad (write) and Latch (read) Registers: */
284 #define LP_CNTR0ALSW            0x000C  /*   0A lsw. */
285 #define LP_CNTR0AMSW            0x000E  /*   0A msw. */
286 #define LP_CNTR0BLSW            0x0010  /*   0B lsw. */
287 #define LP_CNTR0BMSW            0x0012  /*   0B msw. */
288 #define LP_CNTR1ALSW            0x0014  /*   1A lsw. */
289 #define LP_CNTR1AMSW            0x0016  /*   1A msw. */
290 #define LP_CNTR1BLSW            0x0018  /*   1B lsw. */
291 #define LP_CNTR1BMSW            0x001A  /*   1B msw. */
292 #define LP_CNTR2ALSW            0x001C  /*   2A lsw. */
293 #define LP_CNTR2AMSW            0x001E  /*   2A msw. */
294 #define LP_CNTR2BLSW            0x0020  /*   2B lsw. */
295 #define LP_CNTR2BMSW            0x0022  /*   2B msw. */
296
297 /*  Miscellaneous Registers (read/write): */
298 #define LP_MISC1                0x0088  /*   Read/write Misc1. */
299 #define LP_WRMISC2              0x0090  /*   Write Misc2. */
300 #define LP_RDMISC2              0x0082  /*   Read Misc2. */
301
302 /*  Bit masks for MISC1 register that are the same for reads and writes. */
303 #define MISC1_WENABLE           0x8000  /* enab writes to MISC2 (except Clear
304                                          * Watchdog bit). */
305 #define MISC1_WDISABLE          0x0000  /* Disable writes to MISC2. */
306 #define MISC1_EDCAP             0x1000  /* enab edge capture on DIO chans
307                                          * specified by  LP_WRCAPSELx. */
308 #define MISC1_NOEDCAP           0x0000  /* Disable edge capture on specified
309                                          * DIO chans. */
310
311 /*  Bit masks for MISC1 register reads. */
312 #define RDMISC1_WDTIMEOUT       0x4000  /*  Watchdog timer timed out. */
313
314 /*  Bit masks for MISC2 register writes. */
315 #define WRMISC2_WDCLEAR         0x8000  /*  Reset watchdog timer to zero. */
316 #define WRMISC2_CHARGE_ENABLE   0x4000  /*  enab battery trickle charging. */
317
318 /*  Bit masks for MISC2 register that are the same for reads and writes. */
319 #define MISC2_BATT_ENABLE       0x0008  /*  Backup battery enable. */
320 #define MISC2_WDENABLE          0x0004  /*  Watchdog timer enable. */
321 #define MISC2_WDPERIOD_MASK     0x0003  /*  Watchdog interval */
322                                                 /*  select mask. */
323
324 /*  Bit masks for ACON1 register. */
325 #define A2_RUN                  0x40000000      /*  Run A2 based on TSL2. */
326 #define A1_RUN                  0x20000000      /*  Run A1 based on TSL1. */
327 #define A1_SWAP                 0x00200000      /*  Use big-endian for A1. */
328 #define A2_SWAP                 0x00100000      /*  Use big-endian for A2. */
329 #define WS_MODES                0x00019999      /*  WS0 = TSL1 trigger */
330                                                 /*  input, WS1-WS4 = */
331                                                 /*  CS* outputs. */
332
333 #if PLATFORM == INTEL           /* Base ACON1 config: always run A1 based
334                                  * on TSL1. */
335 #define ACON1_BASE              (WS_MODES | A1_RUN)
336 #elif PLATFORM == MOTOROLA
337 #define ACON1_BASE              (WS_MODES | A1_RUN | A1_SWAP | A2_SWAP)
338 #endif
339
340 #define ACON1_ADCSTART          ACON1_BASE      /* Start ADC: run A1
341                                                  *  based on TSL1. */
342 #define ACON1_DACSTART          (ACON1_BASE | A2_RUN)
343 /* Start transmit to DAC: run A2 based on TSL2. */
344 #define ACON1_DACSTOP           ACON1_BASE      /*  Halt A2. */
345
346 /*  Bit masks for ACON2 register. */
347 #define A1_CLKSRC_BCLK1         0x00000000      /*  A1 bit rate = BCLK1 (ADC). */
348 #define A2_CLKSRC_X1            0x00800000      /*  A2 bit rate = ACLK/1 (DACs). */
349 #define A2_CLKSRC_X2            0x00C00000      /*  A2 bit rate = ACLK/2 (DACs). */
350 #define A2_CLKSRC_X4            0x01400000      /*  A2 bit rate = ACLK/4 (DACs). */
351 #define INVERT_BCLK2            0x00100000      /*  Invert BCLK2 (DACs). */
352 #define BCLK2_OE                0x00040000      /*  enab BCLK2 (DACs). */
353 #define ACON2_XORMASK           0x000C0000      /*  XOR mask for ACON2 */
354                                                 /*  active-low bits. */
355
356 #define ACON2_INIT              (ACON2_XORMASK ^ (A1_CLKSRC_BCLK1 | A2_CLKSRC_X2 | INVERT_BCLK2 | BCLK2_OE))
357
358 /*  Bit masks for timeslot records. */
359 #define WS1                     0x40000000      /*  WS output to assert. */
360 #define WS2                     0x20000000
361 #define WS3                     0x10000000
362 #define WS4                     0x08000000
363 #define RSD1                    0x01000000      /* Shift A1 data in on SD1. */
364 #define SDW_A1                  0x00800000      /* Store rcv'd char at next
365                                                  * char slot of DWORD1 buffer. */
366 #define SIB_A1                  0x00400000      /* Store rcv'd char at next
367                                                  * char slot of FB1 buffer. */
368 #define SF_A1                   0x00200000      /* Write unsigned long
369                                                  * buffer to input FIFO. */
370
371 /* Select parallel-to-serial converter's data source: */
372 #define XFIFO_0                 0x00000000      /*    Data fifo byte 0. */
373 #define XFIFO_1                 0x00000010      /*    Data fifo byte 1. */
374 #define XFIFO_2                 0x00000020      /*    Data fifo byte 2. */
375 #define XFIFO_3                 0x00000030      /*    Data fifo byte 3. */
376 #define XFB0                    0x00000040      /*    FB_BUFFER byte 0. */
377 #define XFB1                    0x00000050      /*    FB_BUFFER byte 1. */
378 #define XFB2                    0x00000060      /*    FB_BUFFER byte 2. */
379 #define XFB3                    0x00000070      /*    FB_BUFFER byte 3. */
380 #define SIB_A2                  0x00000200      /* Store next dword from A2's
381                                                  * input shifter to FB2 buffer. */
382 #define SF_A2                   0x00000100      /* Store next dword from A2's
383                                                  * input shifter to its input
384                                                  * fifo. */
385 #define LF_A2                   0x00000080      /* Load next dword from A2's
386                                                  * output fifo into its
387                                                  * output dword buffer. */
388 #define XSD2                    0x00000008      /*  Shift data out on SD2. */
389 #define RSD3                    0x00001800      /*  Shift data in on SD3. */
390 #define RSD2                    0x00001000      /*  Shift data in on SD2. */
391 #define LOW_A2                  0x00000002      /*  Drive last SD low */
392                                                 /*  for 7 clks, then */
393                                                 /*  tri-state. */
394 #define EOS                     0x00000001      /*  End of superframe. */
395
396 /*  I2C configuration constants. */
397 #define I2C_CLKSEL              0x0400
398 /* I2C bit rate = PCIclk/480 = 68.75 KHz. */
399
400 #define I2C_BITRATE             68.75
401 /* I2C bus data bit rate (determined by I2C_CLKSEL) in KHz. */
402
403 #define I2C_WRTIME              15.0
404 /* Worst case time, in msec, for EEPROM internal write op. */
405
406 /*  I2C manifest constants. */
407
408 /*  Max retries to wait for EEPROM write. */
409 #define I2C_RETRIES             (I2C_WRTIME * I2C_BITRATE / 9.0)
410 #define I2C_ERR                 0x0002  /*  I2C control/status */
411                                                 /*  flag ERROR. */
412 #define I2C_BUSY                0x0001  /*  I2C control/status */
413                                                 /*  flag BUSY. */
414 #define I2C_ABORT               0x0080  /*  I2C status flag ABORT. */
415 #define I2C_ATTRSTART           0x3     /*  I2C attribute START. */
416 #define I2C_ATTRCONT            0x2     /*  I2C attribute CONT. */
417 #define I2C_ATTRSTOP            0x1     /*  I2C attribute STOP. */
418 #define I2C_ATTRNOP             0x0     /*  I2C attribute NOP. */
419
420 /*  I2C read command  | EEPROM address. */
421 #define I2CR                    (devpriv->I2CAdrs | 1)
422
423 /*  I2C write command | EEPROM address. */
424 #define I2CW                    (devpriv->I2CAdrs)
425
426 /*  Code macros used for constructing I2C command bytes. */
427 #define I2C_B2(ATTR, VAL)       (((ATTR) << 6) | ((VAL) << 24))
428 #define I2C_B1(ATTR, VAL)       (((ATTR) << 4) | ((VAL) << 16))
429 #define I2C_B0(ATTR, VAL)       (((ATTR) << 2) | ((VAL) <<  8))
430
431 /* oldest */
432 #define P_DEBICFGq              0x007C  /*  DEBI configuration. */
433 #define P_DEBICMDq              0x0080  /*  DEBI command. */
434 #define P_DEBIPAGEq             0x0084  /*  DEBI page. */
435 #define P_DEBIADq               0x0088  /*  DEBI target address. */
436
437 #define DEBI_CFG_TOQ            0x03C00000      /*  timeout (15 PCI cycles) */
438 #define DEBI_CFG_FASTQ          0x10000000      /*  fast mode enable */
439 #define DEBI_CFG_16Q            0x00080000      /*  16-bit access enable */
440 #define DEBI_CFG_INCQ           0x00040000      /*  enable address increment */
441 #define DEBI_CFG_TIMEROFFQ      0x00010000      /*  disable timer */
442 #define DEBI_CMD_RDQ            0x00050000      /*  read immediate 2 bytes */
443 #define DEBI_CMD_WRQ            0x00040000      /*  write immediate 2 bytes */
444 #define DEBI_PAGE_DISABLEQ      0x00000000      /*  paging disable */
445
446 /*  DEBI command constants. */
447 #define DEBI_CMD_SIZE16         (2 << 17)       /*  Transfer size is */
448                                                 /*  always 2 bytes. */
449 #define DEBI_CMD_READ           0x00010000      /*  Read operation. */
450 #define DEBI_CMD_WRITE          0x00000000      /*  Write operation. */
451
452 /*  Read immediate 2 bytes. */
453 #define DEBI_CMD_RDWORD         (DEBI_CMD_READ  | DEBI_CMD_SIZE16)
454
455 /*  Write immediate 2 bytes. */
456 #define DEBI_CMD_WRWORD         (DEBI_CMD_WRITE | DEBI_CMD_SIZE16)
457
458 /*  DEBI configuration constants. */
459 #define DEBI_CFG_XIRQ_EN        0x80000000      /*  enab external */
460                                                 /*  interrupt on GPIO3. */
461 #define DEBI_CFG_XRESUME        0x40000000      /*  Resume block */
462                                                 /*  transfer when XIRQ */
463                                                 /*  deasserted. */
464 #define DEBI_CFG_FAST           0x10000000      /*  Fast mode enable. */
465
466 /*  4-bit field that specifies DEBI timeout value in PCI clock cycles: */
467 #define DEBI_CFG_TOUT_BIT       22      /*    Finish DEBI cycle after */
468                                         /*    this many clocks. */
469
470 /*  2-bit field that specifies Endian byte lane steering: */
471 #define DEBI_CFG_SWAP_NONE      0x00000000      /*    Straight - don't */
472                                                 /*    swap any bytes */
473                                                 /*    (Intel). */
474 #define DEBI_CFG_SWAP_2         0x00100000      /*    2-byte swap (Motorola). */
475 #define DEBI_CFG_SWAP_4         0x00200000      /*    4-byte swap. */
476 #define DEBI_CFG_16             0x00080000      /*  Slave is able to */
477                                                 /*  serve 16-bit */
478                                                 /*  cycles. */
479
480 #define DEBI_CFG_SLAVE16        0x00080000      /*  Slave is able to */
481                                                 /*  serve 16-bit */
482                                                 /*  cycles. */
483 #define DEBI_CFG_INC            0x00040000      /*  enab address */
484                                                 /*  increment for block */
485                                                 /*  transfers. */
486 #define DEBI_CFG_INTEL          0x00020000      /*  Intel style local bus. */
487 #define DEBI_CFG_TIMEROFF       0x00010000      /*  Disable timer. */
488
489 #if PLATFORM == INTEL
490
491 #define DEBI_TOUT               7       /*  Wait 7 PCI clocks */
492                                                 /*  (212 ns) before */
493                                                 /*  polling RDY. */
494
495 /*  Intel byte lane steering (pass through all byte lanes). */
496 #define DEBI_SWAP               DEBI_CFG_SWAP_NONE
497
498 #elif PLATFORM == MOTOROLA
499
500 #define DEBI_TOUT               15      /*  Wait 15 PCI clocks (454 ns) */
501                                         /*  maximum before timing out. */
502 #define DEBI_SWAP               DEBI_CFG_SWAP_2 /*  Motorola byte lane steering. */
503
504 #endif
505
506 /*  DEBI page table constants. */
507 #define DEBI_PAGE_DISABLE       0x00000000      /*  Paging disable. */
508
509 /* ******* EXTRA FROM OTHER SANSORAY  * .h  ******* */
510
511 /*  LoadSrc values: */
512 #define LOADSRC_INDX            0       /*  Preload core in response to */
513                                         /*  Index. */
514 #define LOADSRC_OVER            1       /*  Preload core in response to */
515                                         /*  Overflow. */
516 #define LOADSRCB_OVERA          2       /*  Preload B core in response */
517                                         /*  to A Overflow. */
518 #define LOADSRC_NONE            3       /*  Never preload core. */
519
520 /*  IntSrc values: */
521 #define INTSRC_NONE             0       /*  Interrupts disabled. */
522 #define INTSRC_OVER             1       /*  Interrupt on Overflow. */
523 #define INTSRC_INDX             2       /*  Interrupt on Index. */
524 #define INTSRC_BOTH             3       /*  Interrupt on Index or Overflow. */
525
526 /*  LatchSrc values: */
527 #define LATCHSRC_AB_READ        0       /*  Latch on read. */
528 #define LATCHSRC_A_INDXA        1       /*  Latch A on A Index. */
529 #define LATCHSRC_B_INDXB        2       /*  Latch B on B Index. */
530 #define LATCHSRC_B_OVERA        3       /*  Latch B on A Overflow. */
531
532 /*  IndxSrc values: */
533 #define INDXSRC_HARD            0       /*  Hardware or software index. */
534 #define INDXSRC_SOFT            1       /*  Software index only. */
535
536 /*  IndxPol values: */
537 #define INDXPOL_POS             0       /*  Index input is active high. */
538 #define INDXPOL_NEG             1       /*  Index input is active low. */
539
540 /*  ClkSrc values: */
541 #define CLKSRC_COUNTER          0       /*  Counter mode. */
542 #define CLKSRC_TIMER            2       /*  Timer mode. */
543 #define CLKSRC_EXTENDER         3       /*  Extender mode. */
544
545 /*  ClkPol values: */
546 #define CLKPOL_POS              0       /*  Counter/Extender clock is */
547                                         /*  active high. */
548 #define CLKPOL_NEG              1       /*  Counter/Extender clock is */
549                                         /*  active low. */
550 #define CNTDIR_UP               0       /*  Timer counts up. */
551 #define CNTDIR_DOWN             1       /*  Timer counts down. */
552
553 /*  ClkEnab values: */
554 #define CLKENAB_ALWAYS          0       /*  Clock always enabled. */
555 #define CLKENAB_INDEX           1       /*  Clock is enabled by index. */
556
557 /*  ClkMult values: */
558 #define CLKMULT_4X              0       /*  4x clock multiplier. */
559 #define CLKMULT_2X              1       /*  2x clock multiplier. */
560 #define CLKMULT_1X              2       /*  1x clock multiplier. */
561
562 /*  Bit Field positions in COUNTER_SETUP structure: */
563 #define BF_LOADSRC              9       /*  Preload trigger. */
564 #define BF_INDXSRC              7       /*  Index source. */
565 #define BF_INDXPOL              6       /*  Index polarity. */
566 #define BF_CLKSRC               4       /*  Clock source. */
567 #define BF_CLKPOL               3       /*  Clock polarity/count direction. */
568 #define BF_CLKMULT              1       /*  Clock multiplier. */
569 #define BF_CLKENAB              0       /*  Clock enable. */
570
571 /*  Enumerated counter operating modes specified by ClkSrc bit field in */
572 /*  a COUNTER_SETUP. */
573
574 #define CLKSRC_COUNTER          0       /*  Counter: ENC_C clock, ENC_D */
575                                         /*  direction. */
576 #define CLKSRC_TIMER            2       /*  Timer: SYS_C clock, */
577                                         /*  direction specified by */
578                                         /*  ClkPol. */
579 #define CLKSRC_EXTENDER         3       /*  Extender: OVR_A clock, */
580                                         /*  ENC_D direction. */
581
582 /*  Enumerated counter clock multipliers. */
583
584 #define MULT_X0                 0x0003  /*  Supports no multipliers; */
585                                         /*  fixed physical multiplier = */
586                                         /*  3. */
587 #define MULT_X1                 0x0002  /*  Supports multiplier x1; */
588                                         /*  fixed physical multiplier = */
589                                         /*  2. */
590 #define MULT_X2                 0x0001  /*  Supports multipliers x1, */
591                                         /*  x2; physical multipliers = */
592                                         /*  1 or 2. */
593 #define MULT_X4                 0x0000  /*  Supports multipliers x1, */
594                                         /*  x2, x4; physical */
595                                         /*  multipliers = 0, 1 or 2. */
596
597 /*  Sanity-check limits for parameters. */
598
599 #define NUM_COUNTERS            6       /*  Maximum valid counter */
600                                         /*  logical channel number. */
601 #define NUM_INTSOURCES          4
602 #define NUM_LATCHSOURCES        4
603 #define NUM_CLKMULTS            4
604 #define NUM_CLKSOURCES          4
605 #define NUM_CLKPOLS             2
606 #define NUM_INDEXPOLS           2
607 #define NUM_INDEXSOURCES        2
608 #define NUM_LOADTRIGS           4
609
610 /*  Bit field positions in CRA and CRB counter control registers. */
611
612 /*  Bit field positions in CRA: */
613 #define CRABIT_INDXSRC_B        14      /*    B index source. */
614 #define CRABIT_CLKSRC_B         12      /*    B clock source. */
615 #define CRABIT_INDXPOL_A        11      /*    A index polarity. */
616 #define CRABIT_LOADSRC_A         9      /*    A preload trigger. */
617 #define CRABIT_CLKMULT_A         7      /*    A clock multiplier. */
618 #define CRABIT_INTSRC_A          5      /*    A interrupt source. */
619 #define CRABIT_CLKPOL_A          4      /*    A clock polarity. */
620 #define CRABIT_INDXSRC_A         2      /*    A index source. */
621 #define CRABIT_CLKSRC_A          0      /*    A clock source. */
622
623 /*  Bit field positions in CRB: */
624 #define CRBBIT_INTRESETCMD      15      /*    Interrupt reset command. */
625 #define CRBBIT_INTRESET_B       14      /*    B interrupt reset enable. */
626 #define CRBBIT_INTRESET_A       13      /*    A interrupt reset enable. */
627 #define CRBBIT_CLKENAB_A        12      /*    A clock enable. */
628 #define CRBBIT_INTSRC_B         10      /*    B interrupt source. */
629 #define CRBBIT_LATCHSRC          8      /*    A/B latch source. */
630 #define CRBBIT_LOADSRC_B         6      /*    B preload trigger. */
631 #define CRBBIT_CLKMULT_B         3      /*    B clock multiplier. */
632 #define CRBBIT_CLKENAB_B         2      /*    B clock enable. */
633 #define CRBBIT_INDXPOL_B         1      /*    B index polarity. */
634 #define CRBBIT_CLKPOL_B          0      /*    B clock polarity. */
635
636 /*  Bit field masks for CRA and CRB. */
637
638 #define CRAMSK_INDXSRC_B        (3 << CRABIT_INDXSRC_B)
639 #define CRAMSK_CLKSRC_B         (3 << CRABIT_CLKSRC_B)
640 #define CRAMSK_INDXPOL_A        (1 << CRABIT_INDXPOL_A)
641 #define CRAMSK_LOADSRC_A        (3 << CRABIT_LOADSRC_A)
642 #define CRAMSK_CLKMULT_A        (3 << CRABIT_CLKMULT_A)
643 #define CRAMSK_INTSRC_A         (3 << CRABIT_INTSRC_A)
644 #define CRAMSK_CLKPOL_A         (3 << CRABIT_CLKPOL_A)
645 #define CRAMSK_INDXSRC_A        (3 << CRABIT_INDXSRC_A)
646 #define CRAMSK_CLKSRC_A         (3 << CRABIT_CLKSRC_A)
647
648 #define CRBMSK_INTRESETCMD      (1 << CRBBIT_INTRESETCMD)
649 #define CRBMSK_INTRESET_B       (1 << CRBBIT_INTRESET_B)
650 #define CRBMSK_INTRESET_A       (1 << CRBBIT_INTRESET_A)
651 #define CRBMSK_CLKENAB_A        (1 << CRBBIT_CLKENAB_A)
652 #define CRBMSK_INTSRC_B         (3 << CRBBIT_INTSRC_B)
653 #define CRBMSK_LATCHSRC         (3 << CRBBIT_LATCHSRC)
654 #define CRBMSK_LOADSRC_B        (3 << CRBBIT_LOADSRC_B)
655 #define CRBMSK_CLKMULT_B        (3 << CRBBIT_CLKMULT_B)
656 #define CRBMSK_CLKENAB_B        (1 << CRBBIT_CLKENAB_B)
657 #define CRBMSK_INDXPOL_B        (1 << CRBBIT_INDXPOL_B)
658 #define CRBMSK_CLKPOL_B         (1 << CRBBIT_CLKPOL_B)
659
660 #define CRBMSK_INTCTRL          (CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A | CRBMSK_INTRESET_B)    /*  Interrupt reset control bits. */
661
662 /*  Bit field positions for standardized SETUP structure. */
663
664 #define STDBIT_INTSRC           13
665 #define STDBIT_LATCHSRC         11
666 #define STDBIT_LOADSRC           9
667 #define STDBIT_INDXSRC           7
668 #define STDBIT_INDXPOL           6
669 #define STDBIT_CLKSRC            4
670 #define STDBIT_CLKPOL            3
671 #define STDBIT_CLKMULT           1
672 #define STDBIT_CLKENAB           0
673
674 /*  Bit field masks for standardized SETUP structure. */
675
676 #define STDMSK_INTSRC           (3 << STDBIT_INTSRC)
677 #define STDMSK_LATCHSRC         (3 << STDBIT_LATCHSRC)
678 #define STDMSK_LOADSRC          (3 << STDBIT_LOADSRC)
679 #define STDMSK_INDXSRC          (1 << STDBIT_INDXSRC)
680 #define STDMSK_INDXPOL          (1 << STDBIT_INDXPOL)
681 #define STDMSK_CLKSRC           (3 << STDBIT_CLKSRC)
682 #define STDMSK_CLKPOL           (1 << STDBIT_CLKPOL)
683 #define STDMSK_CLKMULT          (3 << STDBIT_CLKMULT)
684 #define STDMSK_CLKENAB          (1 << STDBIT_CLKENAB)
685
686 struct bufferDMA {
687         dma_addr_t PhysicalBase;
688         void *LogicalBase;
689         uint32_t DMAHandle;
690 };