1 /** @file u12-hwdef.h
2  *  @brief Definitions for the ASIC.
3  *
4  * Copyright (c) 2003-2004 Gerhard Jaeger <gerhard@gjaeger.de>
5  *
6  * History:
7  * - 0.01 - initial version
8  * - 0.02 - change _DEF_BW_THRESHOLD
9  * .
10  * <hr>
11  * This file is part of the SANE package.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of the
16  * License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
25  *
26  * As a special exception, the authors of SANE give permission for
27  * additional uses of the libraries contained in this release of SANE.
28  *
29  * The exception is that, if you link a SANE library with other files
30  * to produce an executable, this does not by itself cause the
31  * resulting executable to be covered by the GNU General Public
32  * License.  Your use of that executable is in no way restricted on
33  * account of linking the SANE library code into it.
34  *
35  * This exception does not, however, invalidate any other reasons why
36  * the executable file might be covered by the GNU General Public
37  * License.
38  *
39  * If you submit changes to SANE to the maintainers to be included in
40  * a subsequent release, you agree by submitting the changes that
41  * those changes may be distributed with this exception intact.
42  *
43  * If you write modifications of your own for SANE, it is your choice
44  * whether to permit this exception to apply to your modifications.
45  * If you do not wish that, delete this exception notice.
46  * <hr>
47  */
48 #ifndef __U12_HWDEF_H__
49 #define __U12_HWDEF_H__
50 
51 #define _LOWORD(x)	((u_short)(x & 0xffff))
52 #define _HIWORD(x)	((u_short)(x >> 16))
53 #define _LOBYTE(x)  ((SANE_Byte)((x) & 0xFF))
54 #define _HIBYTE(x)  ((SANE_Byte)((x) >> 8))
55 
56 #define _SET_REG(b,c,r,v) {b[c*2]=r; b[(c*2)+1]=v;c++;}
57 
58 /** some magics for the ASIC */
59 #define _ID_TO_PRINTER  0x00
60 #define _ID1ST          0x69
61 #define _ID2ND          0x96
62 #define _ID3RD          0xa5
63 #define _ID4TH          0x5a
64 
65 /** some more for reset...
66  */
67 #define _RESET1ST       0x69
68 #define _RESET2ND       0x96
69 #define _RESET3RD       0xaa
70 #define _RESET4TH       0x55
71 
72 /** Printer Control Port: Definitions
73  */
74 #define _CTRL_STROBE        0x01
75 #define _CTRL_AUTOLF        0x02
76 #define _CTRL_NOT_INIT      0x04
77 #define _CTRL_SELECT_IN     0x08
78 #define _CTRL_ENABLE_IRQ    0x10
79 #define _CTRL_DIRECTION     0x20
80 #define _CTRL_RESERVED      0xc0
81 
82 /** for Asic I/O signal control
83  */
84 #define _CTRL_GENSIGNAL         (_CTRL_RESERVED + _CTRL_NOT_INIT)   /* 0xc4 */
85 #define _CTRL_SIGNAL_REGWRITE   (_CTRL_GENSIGNAL + _CTRL_SELECT_IN) /* 0xcc */
86 #define _CTRL_END_REGWRITE	    (_CTRL_GENSIGNAL)                   /* 0xc4 */
87 #define _CTRL_SIGNAL_DATAWRITE  (_CTRL_GENSIGNAL + _CTRL_AUTOLF)    /* 0xc6 */
88 #define _CTRL_END_DATAWRITE     (_CTRL_GENSIGNAL)                   /* 0xc4 */
89 
90 #define ASIC_ID 0x83
91 
92 /** the Register set
93  */
94 #define REG_SWITCHBUS           0x00
95 #define REG_EPPENABLE           0x01
96 
97 #define REG_READDATAMODE        0x03
98 #define REG_WRITEDATAMODE       0x04
99 #define REG_INITDATAFIFO        0x05
100 #define REG_FORCESTEP           0x06
101 
102 #define REG_REFRESHSCANSTATE    0x08
103 
104 #define REG_WAITSTATEINSERT     0x0a
105 #define REG_RFIFOOFFSET         0x0a
106 #define REG_GFIFOOFFSET         0x0b
107 #define REG_BFIFOOFFSET         0x0c
108 
109 #define REG_STEPCONTROL         0x14
110 #define REG_MOTOR0CONTROL       0x15
111 #define REG_XSTEPTIME           0x16
112 
113 #define REG_GETSCANSTATE        0x17
114 #define REG_ASICID              0x18
115 #define REG_MEMORYLO            0x19
116 #define REG_MEMORYHI            0x1a
117 #define REG_MODECONTROL         0x1b
118 #define REG_LINECONTROL         0x1c
119 #define REG_SCANCONTROL         0x1d
120 #define REG_CONFIG              0x1e
121 #define REG_MODELCONTROL        0x1f
122 #define REG_MODEL1CONTROL       0x20
123 #define REG_DPILO               0x21
124 #define REG_DPIHI               0x22
125 #define REG_SCANPOSLO           0x23
126 #define REG_SCANPOSHI           0x24
127 #define REG_WIDTHPIXELLO        0x25
128 #define REG_WIDTHPIXELHI        0x26
129 #define REG_THRESHOLDLO         0x27
130 #define REG_THRESHOLDHI         0x28
131 
132 #define REG_ADCADDR             0x2a
133 #define REG_ADCDATA             0x2b
134 #define REG_ADCSERIALOUT        0x2d
135 
136 #define REG_RESETCONFIG         0x2e
137 
138 #define REG_STATUS              0x30
139 #define REG_SCANSTATECONTROL    0x31
140 
141 #define REG_REDCHDARKOFFSETLO   0x33
142 #define REG_REDCHDARKOFFSETHI   0x34
143 #define REG_GREENCHDARKOFFSETLO 0x35
144 #define REG_GREENCHDARKOFFSETHI 0x36
145 #define REG_BLUECHDARKOFFSETLO  0x37
146 #define REG_BLUECHDARKOFFSETHI  0x38
147 
148 #define REG_FIFOFULLEN0         0x54
149 #define REG_FIFOFULLEN1         0x55
150 #define REG_FIFOFULLEN2         0x56
151 #define REG_MOTORTOTALSTEP0     0x57
152 #define REG_MOTORTOTALSTEP1     0x58
153 #define REG_MOTORFREERUNCOUNT0  0x59
154 #define REG_MOTORFREERUNCOUNT1  0x5a
155 #define REG_SCANCONTROL1        0x5b
156 #define REG_MOTORFREERUNTRIGGER 0x5c
157 #define REG_RESETMTSC           0x5d
158 
159 #define REG_MOTORDRVTYPE        0x64
160 
161 #define REG_STATUS2             0x66
162 
163 #define REG_EXTENDEDLINECONTROL 0x6d
164 #define REG_EXTENDEDXSTEP       0x6e
165 
166 #define REG_PLLPREDIV           0x71
167 #define REG_PLLMAINDIV          0x72
168 #define REG_PLLPOSTDIV          0x73
169 #define REG_CLOCKSELECTOR       0x74
170 
171 #define REG_TESTMODE            0xf0
172 
173 /* Register RegStepControl (Addr: 0x14) */
174 #define _MOTOR0_ONESTEP         0x01
175 #define _MOTOR0_SCANSTATE       0x02
176 #define _MOTOR_FREERUN          0x40
177 #define _MOTOR_NOFREERUN        0x00
178 
179 /* Register RegGetScanState (Addr: 0x17)*/
180 #define _SCANSTATE_MASK         0x3f	/* bit 0-5 */
181 #define _SCANSTATE_STOP         0x80
182 
183 /* Register RegMemoryLow/High (Addr: 0x19/0x1a)*/
184 #define _MAP_ADDR_RED           0x00
185 #define _MAP_ADDR_GREEN         0x40
186 #define _MAP_ADDR_BLUE          0x80
187 #define _MAP_ADDR_SIZE          0x40
188 
189 /* Register RegModeControl (Addr: 0x1b)*/
190 #define _ModeScan               0x00
191 #define _ModeIdle               0x01
192 #define _ModeShadingMem         0x02
193 #define _ModeMappingMem         0x03
194 #define _ModeReadMappingMem     0x07
195 #define _ModeFifoRSel           0x00
196 #define _ModeFifoGSel           0x08
197 #define _ModeFifoBSel           0x10
198 #define _ModeFifoClose          0x18
199 
200 /* Register RegLineControl (Addr: 0x1c) */
201 #define _LINE_SCANTIME_MASK     0x3f	/* bit 0-6              */
202 #define _LINE_CDSINVERSE        0x80	/* Color Drive Signal   */
203 
204 /* Register RegScanControl (Addr: 0x1d) */
205 #define _SCAN_BITMODE           0x00
206 #define _SCAN_BYTEMODE          0x01    /* Gray/Color mode                  */
207 #define _SCAN_12BITMODE         0x02
208 #define _SCAN_1ST_AVERAGE       0x04    /* first pixel is averaged pixel    */
209 #define _SCAN_BITDIRR2L         0x08    /* bit shift from right to left     */
210 #define _SCAN_NORMALLAMP_ON     0x10    /* normal Lamp  */
211 #define _SCAN_TPALAMP_ON        0x20
212 #define _SCAN_DATA_INVERT       0x40
213 #define _BITALIGN_LEFT          0x80
214 
215 #define _SCAN_LAMPS_ON          (_SCAN_NORMALLAMP_ON | _SCAN_TPALAMP_ON)
216 #define _SCAN_LAMP_MASK         _SCAN_LAMPS_ON
217 
218 /* Register RegMotor0Control (Addr: 0x15) */
219 #define _MotorDirForward        0x01
220 #define _MotorDirBackward       0x00
221 #define _MotorOn                0x02
222 #define _MotorHFullStepH        0x00
223 #define _MotorHHalfStep         0x04
224 #define _MotorHQuarterStep      0x08
225 #define _MotorPowerEnable       0x40
226 #define _MotorHHomeStop         0x80
227 
228 #define _DIR_FW   1
229 #define _DIR_BW   2
230 #define _DIR_NONE 0
231 
232 #define _FORWARD_MOTOR  (_MotorDirForward + _MotorOn + \
233                          _MotorHQuarterStep + _MotorPowerEnable)
234 #define _BACKWARD_MOTOR (_MotorDirBackward + _MotorOn + _MotorHHomeStop + \
235                          _MotorHQuarterStep + _MotorPowerEnable)
236 
237 /* Register RegConfiguration (Addr: 0x1e) */
238 #define _P98_CCD_TYPE_ID       0x07
239 #define _P98_NEC_MACHINE       0x08
240 #define _P98_PCBID             0xF0
241 
242 #define _DEF_BW_THRESHOLD      128      /* default B/W mode threshold value */
243 #define _NUMBER_OF_SCANSTEPS   64       /* Asic spec.: up to 64 scan steps  */
244 #define _SCANSTATE_BYTES      (_NUMBER_OF_SCANSTEPS/2)
245 
246 #define _CCD_3797               0
247 #define _CCD_3799               1
248 #define _CCD_535                2
249 #define _CCD_2556               3
250 #define _CCD_518                4
251 #define _CCD_539                5
252 #define _CCD_3777               6
253 #define _CCD_548                7
254 
255 /* PCB-IDs (from parport driver)...  */
256 #define _OPTICWORKS2000         0x00
257 #define _PLUSTEK_SCANNER        0x10
258 #define _SCANNER_WITH_TPA       0x20
259 #define _SCANNER4Button         0x30
260 #define _SCANNER4ButtonTPA      0x40
261 #define _SCANNER5Button         0x50
262 #define _SCANNER5ButtonTPA      0x60
263 #define _SCANNER1Button         0x70
264 #define _SCANNER1ButtonTPA      0x80
265 #define _SCANNER2Button         0x90
266 #define _AGFA_SCANNER           0xf0
267 #define _AGFA_PCB               0x1f
268 
269 /* Register RegModelControl (Addr: 0x1f) */
270 #define _HOME_SENSOR_POLARITY   0x01
271 #define _LED_CONTROL            0x02
272 #define _LED_ACTIVITY           0x04
273 #define _MODEL_DPI200           0x00
274 #define _MODEL_DPI300           0x08
275 #define _MODEL_DPI400           0x10
276 #define _MODEL_DPI600           0x18
277 #define _MODEL_DPI800           0x20
278 #define _MODEL_DPI1200          0x28
279 #define _DUMMY_12BIT            0x40
280 
281 /* Register RegModel1Control (Addr: 0x20) */
282 #define _SCAN_GRAYTYPE          0x01
283 #define _CCD_SHIFT_GATE         0x02
284 #define _CCD_SHIFT_PULSE        0x04
285 #define _BUTTON_MODE            0x08
286 #define _MOTOR_2003             0x00
287 #define _MOTOR_2916             0x10
288 #define _MOTOR_7042             0x20
289 
290 /* Register RegThresholdGapControl (Addr: 0x29) */
291 #define _THRESHOLDGAP_MASK      0x0f
292 
293 /* Register RegResetConfig (Addr: 0x2e) */
294 #define _ADC_MASK               0x07
295 #define _DA_WOLFSON8143         0x00
296 #define _DA_ESIC                0x04
297 #define _DA_SAMSUNG8531         0x05
298 #define _DA_WOLFSON8141         0x06
299 #define _DA_SAMSUNG1224         0x07
300 #define _MOTOR0_MASK            0x18
301 #define _MOTOR0_2003            0x00
302 #define _MOTOR0_2916            0x08
303 #define _MOTOR0_7042            0x10
304 #define _MOTOR1_MASK            0x60
305 #define _MOTOR1_2003            0x00
306 #define _MOTOR1_2916            0x20
307 #define _MOTOR1_7042            0x40
308 
309 /* Status Register (Addr: 0x30) */
310 #define _FLAG_PAPER             0x01
311 #define _FLAG_KEY               0x80
312 
313 /* Register RegFifoFullLength (Addr: 0x54) */
314 #define _RED_FULLSIZE           0x00
315 #define _GREEN_FULLSIZE         0x08
316 #define _BLUE_FULLSIZE          0x10
317 
318 /* Register RegScanControl1	(Addr: 0x5b) */
319 #define _MTSC_ENABLE            0x01
320 #define _SCANSTOPONBUFFULL      0x02
321 #define _MFRC_RUNSCANSTATE      0x04
322 #define _MFRC_BY_XSTEP          0x08
323 
324 /* Register RegMotorDriverType (Addr: 0x64) */
325 #define _MOTORS_MASK            0x33
326 #define _MOTORR_MASK            0xf3
327 #define _MOTORR_WEAK            0x04
328 #define _MOTORR_MEDIUM          0x08
329 #define _MOTORR_STRONG          0x0c
330 #define _MOTORT_WEAK            0x40
331 #define _MOTORT_MEDIUM          0x80
332 #define _MOTORT_STRONG          0xc0
333 #define _BUTTON_SELECT1         0x40
334 #define _BUTTON_SELECT2         0x80
335 #define _BUTTON_DISABLE         0xc0
336 
337 /** Register RegStatus2	(Addr: 0x66) */
338 #define _REFLECTIONLAMP_ON      0x01
339 #define _TPALAMP_ON             0x02
340 #define _STILL_FREE_RUNNING     0x04
341 #define _BUFFER_IS_FULL         0x08
342 
343 /** Register RegTestMode	(Addr: 0xf0) */
344 #define _SW_TESTMODE            0x20
345 
346 /** buffer sizes */
347 #define _BYTES_PER_CHANNEL    5500UL
348 #define _SIZE_DATA_BUF        (u_long)(_BYTES_PER_CHANNEL * 3 * 2)
349 #define _SIZE_TPA_DATA_BUF    (u_long)(_BYTES_PER_CHANNEL * 3 * 2)
350 #define _SIZE_SHADING_SUM_BUF (u_long)(_BYTES_PER_CHANNEL * 3 * 4)
351 #define _SIZE_TOTAL_BUF       (u_long)(_SIZE_DATA_BUF + _SIZE_SHADING_SUM_BUF)
352 #define _SIZE_TOTAL_BUF_TPA   (u_long)(_SIZE_TOTAL_BUF + _SIZE_TPA_DATA_BUF)
353 
354 /** internal FIFO buffers */
355 #define _SIZE_REDFIFO   196608UL    /* 192k */
356 #define _SIZE_GREENFIFO 147456UL    /* 144k */
357 #define _SIZE_BLUEFIFO  114688UL    /* 112k */
358 
359 #define _SIZE_GRAYFIFO  (_SIZE_REDFIFO + _SIZE_GREENFIFO + _SIZE_BLUEFIFO)
360 
361 /* Scan State Definitions */
362 #define _SS_STEP   0x08
363 #define _SS_RED    0x04
364 #define _SS_GREEN  0x02
365 #define _SS_BLUE   0x01
366 
367 #define _SS_MONO   _SS_GREEN
368 #define _SS_COLOR  (_SS_RED | _SS_GREEN | _SS_BLUE)
369 
370 /** some positioning stuff
371  */
372 #define _RFT_SCANNING_ORG  380U
373 #define _POS_SCANNING_ORG  2840U
374 #define _NEG_SCANNING_ORG  3000U
375 #define _TPA_SHADINGORG    2172U
376 
377 #define _DATA_ORIGIN_X     72
378 #define _YOFFSET           300
379 
380 #define _POS_PAGEWIDTH     450U
381 #define _POS_ORG_OFFSETX   0x41C
382 
383 #define _NEG_PAGEWIDTH     464U
384 #define _NEG_PAGEWIDTH600  992U
385 #define _NEG_ORG_OFFSETX   0x430
386 #define _NEG_EDGE_VALUE    0x800
387 #define _NEG_SHADING_OFFS  1500U
388 
389 #define _SHADING_BEGINX    4U
390 
391 
392 #define _DEFAULT_LINESCANTIME   96
393 
394 #define _LINE_TIMEOUT   (_SECOND * 5 )
395 
396 
397 /** for mirroring parts of the 98003 ASIC register set
398  */
399 typedef struct {
400 	SANE_Byte RD_Motor1Control;     /* 0x0b           */
401 	SANE_Byte RD_StepControl;       /* 0x14           */
402 	SANE_Byte RD_Motor0Control;     /* 0x15           */
403 	SANE_Byte RD_XStepTime;         /* 0x16           */
404 	SANE_Byte RD_ModeControl;       /* 0x1b           */
405 	SANE_Byte RD_LineControl;       /* 0x1c           */
406 	SANE_Byte RD_ScanControl;       /* 0x1d, init = 5 */
407 	SANE_Byte RD_ModelControl;      /* 0x1f           */
408 	SANE_Byte RD_Model1Control;     /* 0x20           */
409 	u_short   RD_Dpi;               /* 0x21           */
410 	u_short   RD_Origin;            /* 0x23           */
411 	u_short   RD_Pixels;            /* 0x25           */
412 	u_short   RD_ThresholdControl;  /* 0x27           */
413 	SANE_Byte RD_ThresholdGapCtrl;  /* 0x29           */
414 	u_short   RD_RedDarkOff;        /* 0x33           */
415 	u_short   RD_GreenDarkOff;      /* 0x35           */
416 	u_short   RD_BlueDarkOff;       /* 0x37           */
417 
418 	u_long    RD_BufFullSize;       /* 0x54   */
419 	u_short   RD_MotorTotalSteps;   /* 0x57   */
420 
421 	SANE_Byte RD_ScanControl1;      /* 0x5b   */
422 	SANE_Byte RD_MotorDriverType;   /* 0x64   */
423 	SANE_Byte RD_ExtLineControl;    /* 0x6d   */
424 	SANE_Byte RD_ExtXStepTime;      /* 0x6e   */
425 
426 } ShadowRegs;
427 
428 /** to hold all the shading stuff for calibrating a scanner
429  */
430 typedef struct svd
431 {
432 	ColorWord   GainResize;
433 	ColorWord   DarkCmpHi;
434 	ColorWord   DarkCmpLo;
435 	ColorWord   DarkOffSub;
436 	ColorByte   DarkDAC;
437 	SANE_Byte   Reserved;
438 } ShadingVarDef;
439 
440 typedef struct
441 {
442 	ShadingVarDef *pCcdDac;
443 	ColorByte      DarkDAC;
444 	ColorWord      DarkOffset;
445 	u_short        wDarkLevels;
446 	SANE_Byte      intermediate;
447 
448 	u_long         dwDiv;
449 	SANE_Byte      skipShadow;
450 
451 	SANE_Byte      skipHilight;
452 	ColorByte      Hilight;
453 	RGBUShortDef  *pHilight;
454 	ColorByte      Gain;
455 	SANE_Byte      bGainDouble;
456 	SANE_Byte      bUniGain;
457 	SANE_Byte      bMinGain;
458 	SANE_Byte      bMaxGain;
459 	SANE_Byte      bGainHigh;
460 	SANE_Byte      bGainLow;
461 
462 	SANE_Bool      fStop;
463 
464 	u_short        wExposure;
465 	u_short        wXStep;
466 
467 } ShadingDef;
468 
469 #endif	/* guard __U12_HWDEF_H__ */
470 
471 /* END U12-HWDEF.H ..........................................................*/
472