• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* @file u12-ccd.c
2  * @brief here we have the whole code to initialize the CCD and DAC stuff
3  *
4  * based on sources acquired from Plustek Inc.
5  * Copyright (c) 2003-2004 Gerhard Jaeger <gerhard@gjaeger.de>
6  *
7  * History:
8  * - 0.01 - initial version
9  * - 0.02 - no changes
10  * .
11  * <hr>
12  * This file is part of the SANE package.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of the
17  * License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
26  *
27  * As a special exception, the authors of SANE give permission for
28  * additional uses of the libraries contained in this release of SANE.
29  *
30  * The exception is that, if you link a SANE library with other files
31  * to produce an executable, this does not by itself cause the
32  * resulting executable to be covered by the GNU General Public
33  * License.  Your use of that executable is in no way restricted on
34  * account of linking the SANE library code into it.
35  *
36  * This exception does not, however, invalidate any other reasons why
37  * the executable file might be covered by the GNU General Public
38  * License.
39  *
40  * If you submit changes to SANE to the maintainers to be included in
41  * a subsequent release, you agree by submitting the changes that
42  * those changes may be distributed with this exception intact.
43  *
44  * If you write modifications of your own for SANE, it is your choice
45  * whether to permit this exception to apply to your modifications.
46  * If you do not wish that, delete this exception notice.
47  * <hr>
48  */
49 
50 /*************************** some definitions ********************************/
51 
52 #define _REFLECTION     0
53 #define _TRANSPARENCY   1
54 #define _NEGATIVE       2
55 
56 #define _NUM_OF_CCDREGS_W8143    25
57 #define _NUM_OF_DACREGS_W8143    10
58 
59 #define _NUM_OF_CCDREGS_S1224    29
60 #define _NUM_OF_DACREGS_S1224    7
61 
62 #define _NUM_OF_CCDREGS_S8531    29
63 #define _NUM_OF_DACREGS_S8531    9
64 
65 /*************************** some local vars *********************************/
66 
67 static pFnVoid u12ccd_InitFunc = NULL;
68 
69 static RegDef W3797CCDParams[4][_NUM_OF_CCDREGS_W8143] = {
70     {
71         {0x2c, 0x02}, {0x39, 0x2a}, {0x3a, 0x0a}, {0x3b, 0x37},
72         {0x3c, 0x16}, {0x41, 0x0e}, {0x42, 0x90}, {0x43, 0x01},
73         {0x44, 0x27}, {0x45, 0x27}, {0x46, 0x01}, {0x47, 0x03},
74         {0x48, 0x27}, {0x49, 0x2f}, {0x4a, 0x09}, {0x4b, 0x03},
75         {0x4c, 0x07}, {0x4d, 0x06}, {0x4e, 0x06}, {0x67, 0x00},
76         {0x50, 0x08}, {0x51, 0x0e}, {0x52, 0x0c}, {0x53, 0x0b},
77         {0xf0, 0x00}
78     }, {
79         {0x2c, 0x02}, {0x39, 0x3d}, {0x3a, 0x04}, {0x3b, 0x46},
80         {0x3c, 0x06}, {0x41, 0x1f}, {0x42, 0x8c}, {0x43, 0x01},
81         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf2}, {0x47, 0x02},
82         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x00},
83         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x0e}, {0x67, 0x00},
84         {0x50, 0x01}, {0x51, 0x06}, {0x52, 0x09}, {0x53, 0x0b},
85         {0xf0, 0x00}
86     }, {
87         {0x2c, 0x00}, {0x39, 0x16}, {0x3a, 0x03}, {0x3b, 0x1f},
88         {0x3c, 0x07}, {0x41, 0x04}, {0x42, 0x1e}, {0x43, 0x01},
89         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x02},
90         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xf9}, {0x4b, 0x04},
91         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x03}, {0x67, 0x00},
92         {0x50, 0x06}, {0x51, 0x03}, {0x52, 0x09}, {0x53, 0x0b},
93         {0xf0, 0x00}
94     }, {
95         {0x2c, 0x02}, {0x39, 0x18}, {0x3a, 0x04}, {0x3b, 0x1d},
96         {0x3c, 0x03}, {0x41, 0x0c}, {0x42, 0x84}, {0x43, 0x03},
97         {0x44, 0x0a}, {0x45, 0x08}, {0x46, 0xfa}, {0x47, 0x04},
98         {0x48, 0x0a}, {0x49, 0x08}, {0x4a, 0xf2}, {0x4b, 0x02},
99         {0x4c, 0x03}, {0x4d, 0x02}, {0x4e, 0x0e}, {0x67, 0x00},
100         {0x50, 0x00}, {0x51, 0x09}, {0x52, 0x03}, {0x53, 0x03},
101         {0xf0, 0x00}
102     }
103 };
104 
105 static RegDef W3799CCDParams[4][_NUM_OF_CCDREGS_W8143] = {
106     {
107         {0x2c, 0x02}, {0x39, 0x2c}, {0x3a, 0x05}, {0x3b, 0x3c},
108         {0x3c, 0x0e}, {0x41, 0x0e}, {0x42, 0x90}, {0x43, 0x01},
109         {0x44, 0x27}, {0x45, 0x27}, {0x46, 0x01}, {0x47, 0x02},
110         {0x48, 0x27}, {0x49, 0x2f}, {0x4a, 0x09}, {0x4b, 0x05},
111         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x06}, {0x67, 0x00},
112         {0x50, 0x08}, {0x51, 0x0d}, {0x52, 0x0c}, {0x53, 0x0b},
113         {0xf0, 0x00}
114     }, {
115         {0x2c, 0x02}, {0x39, 0x3d}, {0x3a, 0x04}, {0x3b, 0x46},
116         {0x3c, 0x06}, {0x41, 0x1f}, {0x42, 0x8c}, {0x43, 0x01},
117         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf2}, {0x47, 0x01},
118         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x00},
119         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x0e}, {0x67, 0x00},
120         {0x50, 0x01}, {0x51, 0x06}, {0x52, 0x12}, {0x53, 0x0b},
121         {0xf0, 0x00}
122     }, {
123         {0x2c, 0x00}, {0x39, 0x16}, {0x3a, 0x02}, {0x3b, 0x1a},
124         {0x3c, 0x05}, {0x41, 0x04}, {0x42, 0x1e}, {0x43, 0x01},
125         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x01},
126         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xf9}, {0x4b, 0x04},
127         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x03}, {0x67, 0x00},
128         {0x50, 0x06}, {0x51, 0x03}, {0x52, 0x09}, {0x53, 0x0b},
129         {0xf0, 0x00}
130     }, {
131         {0x2c, 0x02}, {0x39, 0x18}, {0x3a, 0x04}, {0x3b, 0x1d},
132         {0x3c, 0x03}, {0x41, 0x0c}, {0x42, 0x84}, {0x43, 0x03},
133         {0x44, 0x0a}, {0x45, 0x08}, {0x46, 0xfa}, {0x47, 0x03},
134         {0x48, 0x0a}, {0x49, 0x08}, {0x4a, 0xf2}, {0x4b, 0x02},
135         {0x4c, 0x03}, {0x4d, 0x02}, {0x4e, 0x0e}, {0x67, 0x00},
136         {0x50, 0x00}, {0x51, 0x09}, {0x52, 0x03}, {0x53, 0x03},
137         {0xf0, 0x00}
138     }
139 };
140 
141 /* Genius ColorPage Vivid III */
142 static RegDef W548CCDParams[4][_NUM_OF_CCDREGS_W8143] = {
143     {
144         {0x2c, 0x02}, {0x39, 0x2c}, {0x3a, 0x05}, {0x3b, 0x3c},
145         {0x3c, 0x0e}, {0x41, 0x0e}, {0x42, 0x90}, {0x43, 0x01},
146         {0x44, 0x27}, {0x45, 0x27}, {0x46, 0x01}, {0x47, 0x02},
147         {0x48, 0x27}, {0x49, 0x2f}, {0x4a, 0x09}, {0x4b, 0x05},
148         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x06}, {0x67, 0x00},
149         {0x50, 0x08}, {0x51, 0x0d}, {0x52, 0x0c}, {0x53, 0x0b},
150         {0xf0, 0x00}
151     }, {
152         {0x2c, 0x02}, {0x39, 0x3d}, {0x3a, 0x04}, {0x3b, 0x46},
153         {0x3c, 0x06}, {0x41, 0x1f}, {0x42, 0x8c}, {0x43, 0x01},
154         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf2}, {0x47, 0x01},
155         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x00},
156         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x0e}, {0x67, 0x00},
157         {0x50, 0x01}, {0x51, 0x06}, {0x52, 0x12}, {0x53, 0x0b},
158         {0xf0, 0x00}
159     }, {
160         {0x2c, 0x00}, {0x39, 0x16}, {0x3a, 0x02}, {0x3b, 0x1a},
161         {0x3c, 0x05}, {0x41, 0x04}, {0x42, 0x1e}, {0x43, 0x01},
162         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x01},
163         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xf9}, {0x4b, 0x04},
164         {0x4c, 0x07}, {0x4d, 0x05}, {0x4e, 0x03}, {0x67, 0x00},
165         {0x50, 0x06}, {0x51, 0x03}, {0x52, 0x09}, {0x53, 0x0b},
166         {0xf0, 0x00}
167     }, {
168         {0x2c, 0x02}, {0x39, 0x18}, {0x3a, 0x04}, {0x3b, 0x1d},
169         {0x3c, 0x03}, {0x41, 0x0c}, {0x42, 0x84}, {0x43, 0x03},
170         {0x44, 0x0a}, {0x45, 0x08}, {0x46, 0xfa}, {0x47, 0x03},
171         {0x48, 0x0a}, {0x49, 0x08}, {0x4a, 0xf2}, {0x4b, 0x02},
172         {0x4c, 0x03}, {0x4d, 0x02}, {0x4e, 0x0e}, {0x67, 0x00},
173         {0x50, 0x00}, {0x51, 0x09}, {0x52, 0x03}, {0x53, 0x03},
174         {0xf0, 0x00}
175     }
176 };
177 
178 static RegDef S3797CCDParams[4][_NUM_OF_CCDREGS_S1224] = {
179     {
180         {0x2c, 0x00}, {0x39, 0x2a}, {0x3a, 0x0a}, {0x3b, 0x37},
181         {0x3c, 0x16}, {0x41, 0x2c}, {0x42, 0x9f}, {0x43, 0x01},
182         {0x44, 0x27}, {0x45, 0x27}, {0x46, 0x01}, {0x47, 0x03},
183         {0x48, 0x27}, {0x49, 0x27}, {0x4a, 0x09}, {0x4b, 0x0b},
184         {0x4c, 0x06}, {0x4d, 0x06}, {0x4e, 0x0b}, {0x50, 0x13},
185         {0x51, 0x06}, {0x52, 0x06}, {0x53, 0x0b}, {0x67, 0x00},
186         {0x6f, 0x20}, {0x70, 0x06}, {0x60, 0x07}, {0x61, 0x9f},
187         {0x65, 0x01}
188     }, {
189         {0x2c, 0x00}, {0x39, 0x3d}, {0x3a, 0x06}, {0x3b, 0x46},
190         {0x3c, 0x06}, {0x41, 0x3d}, {0x42, 0x92}, {0x43, 0x01},
191         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf2}, {0x47, 0x02},
192         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x1b},
193         {0x4c, 0x06}, {0x4d, 0x06}, {0x4e, 0x0b}, {0x50, 0x23},
194         {0x51, 0x06}, {0x52, 0x06}, {0x53, 0x0b}, {0x67, 0x00},
195         {0x6f, 0x30}, {0x70, 0x06}, {0x60, 0x17}, {0x61, 0x9f},
196         {0x65, 0x01}
197     }, {
198         {0x2c, 0x02}, {0x39, 0x16}, {0x3a, 0x03}, {0x3b, 0x1f},
199         {0x3c, 0x07}, {0x41, 0x1c}, {0x42, 0x99}, {0x43, 0x01},
200         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x02},
201         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x09},
202         {0x4c, 0x13}, {0x4d, 0x14}, {0x4e, 0x09}, {0x50, 0x09},
203         {0x51, 0x14}, {0x52, 0x13}, {0x53, 0x01}, {0x67, 0x00},
204         {0x6f, 0xff}, {0x70, 0x7f}, {0x60, 0x04}, {0x61, 0x8f},
205         {0x65, 0x01}
206     }, {
207         {0x2c, 0x02}, {0x39, 0x16}, {0x3a, 0x03}, {0x3b, 0x1f},
208         {0x3c, 0x07}, {0x41, 0x1c}, {0x42, 0x99}, {0x43, 0x01},
209         {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x02},
210         {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x09},
211         {0x4c, 0x13}, {0x4d, 0x14}, {0x4e, 0x09}, {0x50, 0x09},
212         {0x51, 0x14}, {0x52, 0x13}, {0x53, 0x01}, {0x67, 0x00},
213         {0x6f, 0xff}, {0x70, 0x7f}, {0x60, 0x04}, {0x61, 0x8f},
214         {0x65, 0x01}
215     }
216 };
217 
218 static RegDef S3799CCDParams[4][_NUM_OF_CCDREGS_S1224] = {
219     {
220         {0x2c, 0x00}, {0x39, 0x2a}, {0x3a, 0x0a}, {0x3b, 0x37},
221         {0x3c, 0x16}, {0x41, 0x2c}, {0x42, 0x8f}, {0x43, 0x01},
222 	    {0x44, 0x27}, {0x45, 0x27}, {0x46, 0x01}, {0x47, 0x01},
223 	    {0x48, 0x27}, {0x49, 0x27}, {0x4a, 0x09}, {0x4b, 0x0b},
224 	    {0x4c, 0x06}, {0x4d, 0x06}, {0x4e, 0x0b}, {0x50, 0x13},
225 	    {0x51, 0x06}, {0x52, 0x06}, {0x53, 0x0b}, {0x67, 0x00},
226 	    {0x6f, 0x20}, {0x70, 0x06}, {0x60, 0x07}, {0x61, 0x9f},
227 	    {0x65, 0x01}
228     }, {
229         {0x2c, 0x00}, {0x39, 0x3d}, {0x3a, 0x06}, {0x3b, 0x46},
230 	    {0x3c, 0x06}, {0x41, 0x3d}, {0x42, 0x92}, {0x43, 0x01},
231 	    {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf2}, {0x47, 0x01},
232 	    {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x1b},
233 	    {0x4c, 0x06}, {0x4d, 0x06}, {0x4e, 0x0b}, {0x50, 0x23},
234 	    {0x51, 0x06}, {0x52, 0x06}, {0x53, 0x0b}, {0x67, 0x00},
235 	    {0x6f, 0x30}, {0x70, 0x06}, {0x60, 0x17}, {0x61, 0x9f},
236 	    {0x65, 0x01}
237     }, {
238         {0x2c, 0x02}, {0x39, 0x16}, {0x3a, 0x03}, {0x3b, 0x1f},
239 	    {0x3c, 0x07}, {0x41, 0x1c}, {0x42, 0x99}, {0x43, 0x01},
240 	    {0x44, 0x13}, {0x45, 0x13}, {0x46, 0xf1}, {0x47, 0x01},
241 	    {0x48, 0x13}, {0x49, 0x13}, {0x4a, 0xfa}, {0x4b, 0x09},
242 	    {0x4c, 0x13}, {0x4d, 0x14}, {0x4e, 0x09}, {0x50, 0x09},
243 	    {0x51, 0x14}, {0x52, 0x13}, {0x53, 0x01}, {0x67, 0x00},
244 	    {0x6f, 0xff}, {0x70, 0x7f}, {0x60, 0x04}, {0x61, 0x8f},
245 	    {0x65, 0x01}
246     }, {
247         {0x2c, 0x00}, {0x39, 0x16}, {0x3a, 0x03}, {0x3b, 0x1f},
248 	    {0x3c, 0x07}, {0x41, 0x1c}, {0x42, 0x99}, {0x43, 0x03},
249 	    {0x44, 0x0a}, {0x45, 0x08}, {0x46, 0xfa}, {0x47, 0x03},
250 	    {0x48, 0x0a}, {0x49, 0x08}, {0x4a, 0xf2}, {0x4b, 0x02},
251 	    {0x4c, 0x03}, {0x4d, 0x02}, {0x4e, 0x0e}, {0x50, 0x00},
252 	    {0x51, 0x09}, {0x52, 0x03}, {0x53, 0x03}, {0x67, 0x00},
253 	    {0x6f, 0xff}, {0x70, 0x7f}, {0x60, 0x04}, {0x61, 0x8f},
254 	    {0x65, 0x01}
255     }
256 };
257 
258 static RegDef WolfsonDAC8143[_NUM_OF_DACREGS_W8143] = {
259     {0x01, 0x01}, {0x02, 0x04}, {0x03, 0x42}, {0x05, 0x10}, {0x20, 0xd0},
260     {0x21, 0xd0}, {0x22, 0xd0}, {0x24, 0x00}, {0x25, 0x00},	{0x26, 0x00}
261 };
262 
263 static RegDef SamsungDAC8531[_NUM_OF_DACREGS_S8531] = {
264     {0x00, 0x51}, {0x02, 0x01}, {0x01, 0x80},
265     {0x00, 0x55}, {0x02, 0x01}, {0x01, 0x80},
266     {0x00, 0x59}, {0x02, 0x01}, {0x01, 0x80}
267 };
268 
269 static RegDef SamsungDAC1224[_NUM_OF_DACREGS_S1224] ={
270     {0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80},
271     {0x03, 0x80}, {0x04, 0x06}, {0x05, 0x06}, {0x06, 0x06}
272 };
273 
274 static ShadingVarDef ShadingVar3797[3] = {
275     {
276         {{99, 100, 94}}, {{0x30, 0x30, 0x30}},
277         {{0x20, 0x20, 0x20}}, {{0x04, 0x00, 0x00}}, {{0xcc, 0xcc, 0xcc}}, 0
278     }, {
279         {{100, 90, 100}}, {{0x30, 0x30, 0x30}},
280         {{0x20, 0x20, 0x20}}, {{0x10, 0x10, 0x10}}, {{0xcc, 0xcc, 0xcc}}, 0
281     }, {
282         {{90, 90, 90}}, {{0x30, 0x30, 0x30}}, {{0x20, 0x20, 0x20}},
283         {{0x10, 0x10, 0x10}}, {{0x80, 0x80, 0x80}}, 0
284     }
285 };
286 
287 static ShadingVarDef ShadingVar3799[3] = {
288     {
289         {{100, 97, 92}}, {{0x90, 0xe0, 0x80}},
290         {{0x70, 0xc0, 0x60}}, {{0x90, 0x34, 0x3c}}, {{0x80, 0x80, 0x80}}, 0
291     }, {
292         {{75, 75, 75}}, {{0x30, 0x30, 0x30}},
293         {{0x10, 0x10, 0x10}}, {{0x20, 0x20, 0x20}}, {{0x80, 0x80, 0x80}}, 0
294     }, {
295         {{80, 75, 64}}, {{0x30, 0x30, 0x30}},
296         {{0x20, 0x20, 0x20}}, {{0x10, 0x10, 0x10}}, {{0x80, 0x80, 0x80}}, 0
297     }
298 };
299 
300 /* Genius ColorPage Vivid III */
301 static ShadingVarDef ShadingVar548[3] = {
302     {
303         {{100, 97, 92}}, {{0x90, 0xe0, 0x80}},
304         {{0x70, 0xc0, 0x60}}, {{0x90, 0x34, 0x3c}}, {{0x80, 0x80, 0x80}}, 0
305     }, {
306         {{75, 75, 75}}, {{0x30, 0x30, 0x30}},
307         {{0x10, 0x10, 0x10}}, {{0x20, 0x20, 0x20}}, {{0x80, 0x80, 0x80}}, 0
308     }, {
309         {{80, 75, 64}}, {{0x30, 0x30, 0x30}},
310         {{0x20, 0x20, 0x20}}, {{0x10, 0x10, 0x10}}, {{0x80, 0x80, 0x80}}, 0
311     }
312 };
313 
314 static ShadingVarDef ShadingVar3777[3] = {
315     {
316         {{100, 100, 100}}, {{0x90, 0xe0, 0x80}},
317         {{0x70, 0xc0, 0x60}}, {{0x90, 0x34, 0x3c}}, {{0x80, 0x80, 0x80}}, 0
318     }, {
319         {{75, 75, 75}}, {{0x30, 0x30, 0x30}},
320         {{0x10, 0x10, 0x10}}, {{0x20, 0x20, 0x20}}, {{0x80, 0x80, 0x80}}, 0
321     }, {
322         {{80, 75, 64}}, {{0x30, 0x30, 0x30}},
323         {{0x20, 0x20, 0x20}}, {{0x10, 0x10, 0x10}}, {{0x80, 0x80, 0x80}}, 0
324     }
325 };
326 
327 /*************************** local functions *********************************/
328 
329 /**
330  */
fnCCDInitWolfson3797(U12_Device * dev)331 static void fnCCDInitWolfson3797( U12_Device *dev )
332 {
333 	if( dev->shade.intermediate & _ScanMode_Mono )
334 		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xcc;
335 	else
336 		if( dev->shade.intermediate & _ScanMode_AverageOut)
337 			dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x68;
338 		else
339 			dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xa0;
340 
341 	if((dev->shade.intermediate & _ScanMode_AverageOut) ||
342 		                       (dev->DataInf.dwScanFlag & _SCANDEF_Negative)) {
343 		WolfsonDAC8143[3].val = 0x12;
344 	} else {
345 		WolfsonDAC8143[3].val = 0x10;
346 	}
347 }
348 
349 /**
350  */
fnCCDInitSamsung3797(U12_Device * dev)351 static void fnCCDInitSamsung3797( U12_Device *dev )
352 {
353 	if(!(dev->DataInf.dwScanFlag & _SCANDEF_TPA)) {
354 
355 		if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
356 
357 			if( dev->PCBID == _OPTICWORKS2000 ) {
358         		dev->shade.pCcdDac->GainResize.Colors.Red = 102;
359 	        	dev->shade.pCcdDac->GainResize.Colors.Green = 102;
360         		dev->shade.pCcdDac->GainResize.Colors.Blue = 97;
361         		dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x40;
362         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x40;
363         		dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x40;
364 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x48;
365         		dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x40;
366         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x40;
367         		dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x38;
368         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x30;
369         		dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x30;
370         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x48;
371         		dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x38;
372         		dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x40;
373 	        } else {
374         		dev->shade.pCcdDac->GainResize.Colors.Red = 99;
375         		dev->shade.pCcdDac->GainResize.Colors.Green = 101;
376 		        dev->shade.pCcdDac->GainResize.Colors.Blue = 94;
377         		dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x40;
378         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x40;
379 		        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x40;
380         		dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x30;
381         		dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x30;
382         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x30;
383         		dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x20;
384         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x20;
385 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x20;
386         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x04;
387 		        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x00;
388         		dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x00;
389 	        }
390     	} else {
391             if( dev->PCBID == _OPTICWORKS2000 ) {
392     	    	dev->shade.pCcdDac->GainResize.Colors.Red = 100;
393     	    	dev->shade.pCcdDac->GainResize.Colors.Green = 100;
394 	    	    dev->shade.pCcdDac->GainResize.Colors.Blue = 96;
395     	    	dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x30;
396         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x30;
397 	        	dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x30;
398     	    	dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x48;
399     	    	dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x48;
400         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x48;
401 	        	dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x38;
402         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x38;
403 	        	dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x38;
404     		    dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x48;
405         		dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x48;
406     	    	dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x48;
407 	        } else {
408     	    	dev->shade.pCcdDac->GainResize.Colors.Red = 100;   /*  98 */
409     	    	dev->shade.pCcdDac->GainResize.Colors.Green = 103; /* 106 */
410 	    	    dev->shade.pCcdDac->GainResize.Colors.Blue = 96;	  /*  96 */
411     	    	dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x20;
412 	    	    dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x10;
413     		    dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x10;
414         		dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x110;
415 	        	dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x1f0;
416     		    dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x190;
417         		dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x100;
418 	        	dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x1e0;
419     		    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x180;
420         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x20;
421 	        	dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x10;
422     		    dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x20;
423 	        }
424        	}
425     }
426 }
427 
428 /**
429  */
fnCCDInitWolfson3799(U12_Device * dev)430 static void fnCCDInitWolfson3799( U12_Device *dev )
431 {
432     if(!(dev->DataInf.dwScanFlag & _SCANDEF_Negative)) {
433 
434         if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
435 
436     	    dev->shade.pCcdDac->GainResize.Colors.Red = 103;
437 	        dev->shade.pCcdDac->GainResize.Colors.Green = 102;
438     	    dev->shade.pCcdDac->GainResize.Colors.Blue = 99;
439 	        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0xc8;
440 	        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xc8;
441     	    dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0xc8;
442 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x48;
443 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x30;
444     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x30;
445 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x40;
446 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x28;
447     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x28;
448 	        dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x48;
449     	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x18;
450 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x2c;
451     	} else {
452 	        dev->shade.pCcdDac->GainResize.Colors.Red = 100;
453     	    dev->shade.pCcdDac->GainResize.Colors.Green = 98;
454 	        dev->shade.pCcdDac->GainResize.Colors.Blue = 95;
455 	        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0xd0;
456     	    dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xd0;
457 	        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0xd0;
458 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x30;
459     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x30;
460 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x30;
461     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x28;
462 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x28;
463     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x28;
464 	        dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x0;
465     	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x0;
466 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x0;
467     	}
468     } else {
469     	dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x80;
470 	    dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x80;
471     	dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x80;
472 	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x28;
473     	dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x28;
474 	    dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x28;
475     	dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x20;
476 	    dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x20;
477     	dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x20;
478 	    dev->shade.pCcdDac->DarkOffSub.Colors.Red = -0x38;
479     	dev->shade.pCcdDac->DarkOffSub.Colors.Green = -0x108;
480 	    dev->shade.pCcdDac->DarkOffSub.Colors.Blue = -0x1c8;
481     }
482 }
483 
484 /**
485  */
fnCCDInitWolfson548(U12_Device * dev)486 static void fnCCDInitWolfson548( U12_Device *dev )
487 {
488     if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
489 
490  	    dev->shade.pCcdDac->GainResize.Colors.Red   = 103;
491         dev->shade.pCcdDac->GainResize.Colors.Green = 102;
492    	    dev->shade.pCcdDac->GainResize.Colors.Blue  = 99;
493         dev->shade.pCcdDac->DarkDAC.Colors.Red      = 0xc8;
494         dev->shade.pCcdDac->DarkDAC.Colors.Green    = 0xc8;
495    	    dev->shade.pCcdDac->DarkDAC.Colors.Blue     = 0xc8;
496         dev->shade.pCcdDac->DarkCmpHi.Colors.Red    = 0x48;
497         dev->shade.pCcdDac->DarkCmpHi.Colors.Green  = 0x30;
498    	    dev->shade.pCcdDac->DarkCmpHi.Colors.Blue   = 0x30;
499         dev->shade.pCcdDac->DarkCmpLo.Colors.Red    = 0x40;
500         dev->shade.pCcdDac->DarkCmpLo.Colors.Green  = 0x28;
501    	    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue   = 0x28;
502         dev->shade.pCcdDac->DarkOffSub.Colors.Red   = 0x48;
503    	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x18;
504         dev->shade.pCcdDac->DarkOffSub.Colors.Blue  = 0x2c;
505 
506    	} else {
507         dev->shade.pCcdDac->GainResize.Colors.Red   = 100;
508    	    dev->shade.pCcdDac->GainResize.Colors.Green = 98;
509         dev->shade.pCcdDac->GainResize.Colors.Blue  = 95;
510         dev->shade.pCcdDac->DarkDAC.Colors.Red      = 0xd0;
511    	    dev->shade.pCcdDac->DarkDAC.Colors.Green    = 0xd0;
512         dev->shade.pCcdDac->DarkDAC.Colors.Blue     = 0xd0;
513         dev->shade.pCcdDac->DarkCmpHi.Colors.Red    = 0x30;
514    	    dev->shade.pCcdDac->DarkCmpHi.Colors.Green  = 0x30;
515         dev->shade.pCcdDac->DarkCmpHi.Colors.Blue   = 0x30;
516    	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red    = 0x28;
517         dev->shade.pCcdDac->DarkCmpLo.Colors.Green  = 0x28;
518    	    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue   = 0x28;
519         dev->shade.pCcdDac->DarkOffSub.Colors.Red   = 0x0;
520    	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x0;
521         dev->shade.pCcdDac->DarkOffSub.Colors.Blue  = 0x0;
522    	}
523 }
524 
525 /**
526  */
fnCCDInitSamsung3777(U12_Device * dev)527 static void fnCCDInitSamsung3777( U12_Device *dev )
528 {
529     if(!(dev->DataInf.dwScanFlag & _SCANDEF_Negative)) {
530 
531         if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
532 
533     	    dev->shade.pCcdDac->GainResize.Colors.Red = 109;
534 	        dev->shade.pCcdDac->GainResize.Colors.Green = 108;
535 	        dev->shade.pCcdDac->GainResize.Colors.Blue = 105;
536     	    dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x4a;
537 	        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x4a;
538             dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x4a;
539 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x3c;
540     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x38;
541 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x38;
542 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x28;
543     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x2c;
544 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x28;
545 	        dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x30;
546     	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x30;
547 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x3C;
548     	} else {
549     	    dev->shade.pCcdDac->GainResize.Colors.Red = 108;
550 	        dev->shade.pCcdDac->GainResize.Colors.Green = 107;
551     	    dev->shade.pCcdDac->GainResize.Colors.Blue = 104;
552 	        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x50;
553 	        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x50;
554     	    dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x50;
555     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x40;
556 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x40;
557 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x40;
558     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x30;
559 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x30;
560 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x30;
561 	        dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x20;
562     	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x20;
563 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x20;
564 	    }
565     } else {
566     	dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x80;
567 	    dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x80;
568     	dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x80;
569 	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x28;
570     	dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x28;
571     	dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x28;
572 	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x20;
573     	dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x20;
574 	    dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x20;
575     	dev->shade.pCcdDac->DarkOffSub.Colors.Red = -0x38;
576 	    dev->shade.pCcdDac->DarkOffSub.Colors.Green = -0x108;
577     	dev->shade.pCcdDac->DarkOffSub.Colors.Blue = -0x1c8;
578     }
579 }
580 
581 /**
582  */
fnCCDInitSamsung3799(U12_Device * dev)583 static void fnCCDInitSamsung3799( U12_Device *dev )
584 {
585     if(!(dev->DataInf.dwScanFlag & _SCANDEF_TPA)) {
586 
587         if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
588 
589     	    if( dev->PCBID == _SCANNER2Button ) {
590         		dev->shade.pCcdDac->GainResize.Colors.Red = 109;
591         		dev->shade.pCcdDac->GainResize.Colors.Green = 109;
592 		        dev->shade.pCcdDac->GainResize.Colors.Blue = 105;
593         		dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x68;
594 		        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x68;
595         		dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x68;
596 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x30;
597         		dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x30;
598 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x30;
599         		dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x28;
600 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x28;
601         		dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x28;
602 		        dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x24;    /* 0 */
603         		dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x20;  /* 0 */
604 		        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x1c;   /* 0 */
605     	    } else {
606         		dev->shade.pCcdDac->GainResize.Colors.Red = 98;
607 		        dev->shade.pCcdDac->GainResize.Colors.Green = 97;
608         		dev->shade.pCcdDac->GainResize.Colors.Blue = 92;
609 		        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x90;
610         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x90;
611 		        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x90;
612         		dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0xc0;	    /* 0x90 */
613 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0xc0;   /* 0xe0 */
614         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0xc0;    /* 0x80 */
615 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0xb0;	    /* 0x70 */
616         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0xb0;   /* 0xc0 */
617 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0xb0;    /* 0x60 */
618         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x24;    /* 0x90 */
619 		        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x00;	/* 0x34 */
620         		dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x0c;	/* 0x3c */
621 	        }
622     	} else {
623     	    if( dev->PCBID == _SCANNER2Button ) {
624         		dev->shade.pCcdDac->GainResize.Colors.Red = 107;
625 		        dev->shade.pCcdDac->GainResize.Colors.Green = 106;
626         		dev->shade.pCcdDac->GainResize.Colors.Blue = 103;
627 		        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x48;
628         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x48;
629 		        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x48;
630         		dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x30;
631 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x30;
632         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x30;
633 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x28;
634         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x28;
635 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x28;
636         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x28;    /* 0 */
637 		        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x18;  /* 0 */
638         		dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x20;   /* 0 */
639 	        } else {
640         		dev->shade.pCcdDac->GainResize.Colors.Red = 104;
641 		        dev->shade.pCcdDac->GainResize.Colors.Green = 107;
642         		dev->shade.pCcdDac->GainResize.Colors.Blue = 99;
643 		        dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x30;	    /* 0x80 */
644         		dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x30;
645 		        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x30;	    /* 0x0a0 */
646         		dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x150;    /* 0x170 */
647 		        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x130;  /* 0x90  */
648         		dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x110;   /* 0x130 */
649 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x140;    /* 0x150 */
650         		dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x120;  /* 0x70  */
651 		        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x100;   /* 0x120 */
652         		dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0xF0;    /* 0x90  */
653 		        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0xD4;  /* 0x50  */
654         		dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0xCC;   /* 0x60  */
655 	        }
656         }
657     }
658 }
659 
660 /**
661  */
fnCCDInitESIC3799(U12_Device * dev)662 static void fnCCDInitESIC3799( U12_Device *dev )
663 {
664     if(!(dev->DataInf.dwScanFlag & _SCANDEF_Negative)) {
665 
666         if (!(dev->shade.intermediate & _ScanMode_AverageOut)) {
667 
668     	    dev->shade.pCcdDac->GainResize.Colors.Red = 100;
669 	        dev->shade.pCcdDac->GainResize.Colors.Green = 99;
670 	        dev->shade.pCcdDac->GainResize.Colors.Blue = 94;
671     	    dev->shade.pCcdDac->DarkDAC.Colors.Red = 0xc8;
672 	        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xc8;
673 	        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0xc8;
674     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x58;
675 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x38;
676 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x48;
677     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x48;
678 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x28;
679 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x38;
680     	    dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x58;
681 	        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0x38;
682 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0x48;
683     	} else {
684     	    dev->shade.pCcdDac->GainResize.Colors.Red = 100;
685 	        dev->shade.pCcdDac->GainResize.Colors.Green = 98;
686 	        dev->shade.pCcdDac->GainResize.Colors.Blue = 93;
687     	    dev->shade.pCcdDac->DarkDAC.Colors.Red = 0xd0;
688 	        dev->shade.pCcdDac->DarkDAC.Colors.Green = 0xd0;
689 	        dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0xd0;
690     	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x108;
691 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0xf8;
692 	        dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0xc8;
693     	    dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x100;
694 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0xf0;
695 	        dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0xc0;
696     	    dev->shade.pCcdDac->DarkOffSub.Colors.Red = 0x108;
697 	        dev->shade.pCcdDac->DarkOffSub.Colors.Green = 0xf8;
698 	        dev->shade.pCcdDac->DarkOffSub.Colors.Blue = 0xc8;
699     	}
700     } else {
701     	dev->shade.pCcdDac->DarkDAC.Colors.Red = 0x80;
702 	    dev->shade.pCcdDac->DarkDAC.Colors.Green = 0x80;
703     	dev->shade.pCcdDac->DarkDAC.Colors.Blue = 0x80;
704 	    dev->shade.pCcdDac->DarkCmpHi.Colors.Red = 0x28;
705     	dev->shade.pCcdDac->DarkCmpHi.Colors.Green = 0x28;
706 	    dev->shade.pCcdDac->DarkCmpHi.Colors.Blue = 0x28;
707     	dev->shade.pCcdDac->DarkCmpLo.Colors.Red = 0x20;
708 	    dev->shade.pCcdDac->DarkCmpLo.Colors.Green = 0x20;
709     	dev->shade.pCcdDac->DarkCmpLo.Colors.Blue = 0x20;
710 	    dev->shade.pCcdDac->DarkOffSub.Colors.Red = -0x38;
711     	dev->shade.pCcdDac->DarkOffSub.Colors.Green = -0x38;
712 	    dev->shade.pCcdDac->DarkOffSub.Colors.Blue = -0x38;
713     }
714 }
715 
716 /**
717  */
718 static void
fnDarkOffsetWolfson3797(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh)719 fnDarkOffsetWolfson3797( U12_Device *dev, ShadingVarDef *sTbl, u_long dwCh )
720 {
721 	if(( dev->shade.DarkOffset.wColors[dwCh] -=
722                 sTbl->DarkOffSub.wColors[dwCh]) > 0xfff ) {
723 		dev->shade.DarkOffset.wColors[dwCh] = 0;
724 	}
725 }
726 
727 /**
728  */
729 static void
fnDarkOffsetSamsung3777(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh)730 fnDarkOffsetSamsung3777( U12_Device *dev, ShadingVarDef *sTbl, u_long dwCh )
731 {
732 	dev->shade.DarkOffset.wColors[dwCh] += sTbl->DarkOffSub.wColors [dwCh];
733 }
734 
735 /**
736  */
737 static void
fnDarkOffsetSamsung3797(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh)738 fnDarkOffsetSamsung3797( U12_Device *dev, ShadingVarDef *sTbl, u_long dwCh )
739 {
740 	if( dev->shade.DarkOffset.wColors[dwCh] > sTbl->DarkOffSub.wColors[dwCh] )
741 		dev->shade.DarkOffset.wColors[dwCh] -= sTbl->DarkOffSub.wColors[dwCh];
742 	else
743 		dev->shade.DarkOffset.wColors[dwCh] = 0;
744 }
745 
746 /**
747  */
748 static void
fnDarkOffsetSamsung3799(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh)749 fnDarkOffsetSamsung3799( U12_Device *dev, ShadingVarDef *sTbl, u_long dwCh )
750 {
751 	if( dev->shade.DarkOffset.wColors[dwCh] > sTbl->DarkOffSub.wColors[dwCh])
752 		dev->shade.DarkOffset.wColors[dwCh] -= sTbl->DarkOffSub.wColors[dwCh];
753 	else
754 		dev->shade.DarkOffset.wColors[dwCh] = 0;
755 }
756 
757 /**
758  */
fnDACDarkWolfson(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh,u_short wDarkest)759 static void fnDACDarkWolfson( U12_Device *dev, ShadingVarDef *sTbl,
760                               u_long dwCh, u_short wDarkest )
761 {
762 	u_short w = dev->shade.DarkDAC.bColors[dwCh];
763 
764 	if( wDarkest > sTbl->DarkCmpHi.wColors[dwCh] ) {
765 
766 		wDarkest -= sTbl->DarkCmpHi.wColors[dwCh];
767 		if( wDarkest > dev->shade.wDarkLevels)
768 	        w += (u_short)wDarkest / dev->shade.wDarkLevels;
769 		else
770 			w++;
771 
772 		if (w > 0xff)
773 			w = 0xff;
774 
775 		if(w != (u_short)dev->shade.DarkDAC.bColors[dwCh] ) {
776 			dev->shade.DarkDAC.bColors[dwCh] = (SANE_Byte)w;
777 			dev->shade.fStop                 = SANE_FALSE;
778 		}
779 	} else {
780 		if((wDarkest < sTbl->DarkCmpLo.wColors[dwCh]) &&
781                                 	        dev->shade.DarkDAC.bColors[dwCh]) {
782 			if( wDarkest )
783 				w = (u_short)dev->shade.DarkDAC.bColors[dwCh] - 2U;
784 			else
785 				w = (u_short)dev->shade.DarkDAC.bColors[dwCh] - dev->shade.wDarkLevels;
786 
787 			if ((short) w < 0)
788 				w = 0;
789 
790 			if( w != (u_short)dev->shade.DarkDAC.bColors[dwCh] ) {
791 				dev->shade.DarkDAC.bColors [dwCh] = (SANE_Byte)w;
792 				dev->shade.fStop                  = SANE_FALSE;
793 			}
794 		}
795 	}
796 }
797 
798 /**
799  */
fnDACDarkSamsung(U12_Device * dev,ShadingVarDef * sTbl,u_long dwCh,u_short wDarkest)800 static void fnDACDarkSamsung( U12_Device *dev, ShadingVarDef *sTbl,
801                               u_long dwCh, u_short wDarkest )
802 {
803 	u_short w;
804 
805 	if( wDarkest > sTbl->DarkCmpHi.wColors[dwCh] ) {
806 
807 		wDarkest -= sTbl->DarkCmpHi.wColors[dwCh];
808 		if( wDarkest > dev->shade.wDarkLevels )
809 			w = (u_short)dev->shade.DarkDAC.bColors[dwCh] -
810 	                                        wDarkest / dev->shade.wDarkLevels;
811 		else
812 			w = (u_short)dev->shade.DarkDAC.bColors[dwCh] - 1U;
813 
814 		if((short) w < 0)
815 			w = 0;
816 
817 		if(w != (u_short)dev->shade.DarkDAC.bColors[dwCh]) {
818 			dev->shade.DarkDAC.bColors [dwCh] = (SANE_Byte)w;
819 	        dev->shade.fStop                  = SANE_FALSE;
820 		}
821 	} else {
822 		if((wDarkest < sTbl->DarkCmpLo.wColors[dwCh]) &&
823 		                                    dev->shade.DarkDAC.bColors[dwCh]) {
824 			if( wDarkest )
825 				w = (u_short)dev->shade.DarkDAC.bColors[dwCh] + 2U;
826 			else
827 				w = dev->shade.wDarkLevels + (u_short)dev->shade.DarkDAC.bColors[dwCh];
828 
829 			if (w > 0xff)
830 				w = 0xff;
831 
832 			if(w != (u_short)dev->shade.DarkDAC.bColors[dwCh]) {
833 				dev->shade.DarkDAC.bColors[dwCh] = (SANE_Byte)w;
834 				dev->shade.fStop                 = SANE_FALSE;
835 			}
836 		}
837 	}
838 }
839 
840 /************************ exported functions *********************************/
841 
842 /** according to detected CCD and DAC, we set their correct init values
843  *  and functions
844  */
u12ccd_InitCCDandDAC(U12_Device * dev,SANE_Bool shading)845 static void u12ccd_InitCCDandDAC( U12_Device *dev, SANE_Bool shading )
846 {
847 	u_short        w;
848 	ShadingVarDef *pDAC_CCD;
849 
850 	DBG( _DBG_INFO, "CCD & DAC init\n" );
851 
852 	/* some presets */
853 	dev->f0_8_16 = SANE_FALSE;
854 
855 	switch( dev->DACType ) {
856 
857 	case _DA_WOLFSON8143:
858 
859 		DBG( _DBG_INFO, "* DAC: WOLFSON 8143\n" );
860 		switch( dev->CCDID ) {
861 
862 		case _CCD_3797:
863 			DBG( _DBG_INFO, "* CCD-3797\n" );
864 			pDAC_CCD          = ShadingVar3797;
865 			u12ccd_InitFunc   = fnCCDInitWolfson3797;
866 			dev->fnDarkOffset = fnDarkOffsetWolfson3797;
867 			dev->fnDACDark    = fnDACDarkWolfson;
868 			dev->CCDRegs      = (RegDef*)W3797CCDParams;
869 			break;
870 
871 		case _CCD_548:
872 			DBG( _DBG_INFO, "* CCD-548\n" );
873 			pDAC_CCD          = ShadingVar548;
874 			u12ccd_InitFunc   = fnCCDInitWolfson548;
875 			dev->fnDarkOffset = fnDarkOffsetWolfson3797;
876 			dev->fnDACDark    = fnDACDarkWolfson;
877 			dev->CCDRegs      = (RegDef*)W548CCDParams;
878 			break;
879 
880 
881 		default:
882 			DBG( _DBG_INFO, "* CCD-3799\n" );
883 			pDAC_CCD          = ShadingVar3799;
884 			u12ccd_InitFunc   = fnCCDInitWolfson3799;
885 /* CHECK: org was to  fnDarkOffsetWolfson3797 */
886 			dev->fnDarkOffset = fnDarkOffsetWolfson3797;
887 			dev->fnDACDark    = fnDACDarkWolfson;
888 			dev->CCDRegs      = (RegDef*)W3799CCDParams;
889 		}
890 
891 		dev->numCCDRegs         = _NUM_OF_CCDREGS_W8143;
892 		dev->numDACRegs         = _NUM_OF_DACREGS_W8143;
893 		dev->DACRegs            = WolfsonDAC8143;
894 		dev->RegDACOffset.Red   = 0x20;
895 		dev->RegDACOffset.Green = 0x21;
896 		dev->RegDACOffset.Blue  = 0x22;
897 		dev->RegDACGain.Red     = 0x28;
898 		dev->RegDACGain.Green   = 0x29;
899 		dev->RegDACGain.Blue    = 0x2a;
900 
901 		if( dev->shade.intermediate & _ScanMode_AverageOut ) {
902 			dev->shade.bUniGain    = 1;
903 			dev->shade.bGainDouble = 1;
904 		} else {
905 			dev->shade.bUniGain    = 2;
906 			dev->shade.bGainDouble = 4;
907 		}
908 		dev->shade.bMinGain    = 1;
909 		dev->shade.bMaxGain    = 0x1f;
910 		dev->shade.wDarkLevels = 10;
911 
912 		if( dev->shade.intermediate == _ScanMode_Color )
913 			WolfsonDAC8143[2].val = 0x52;
914 		else
915 			WolfsonDAC8143[2].val = 0x42;
916 
917 		if (dev->shade.intermediate == _ScanMode_Mono )
918 			WolfsonDAC8143[0].val = 7;
919 		else
920 			WolfsonDAC8143[0].val = 3;
921 		break;
922 
923 	case _DA_SAMSUNG1224:
924 		DBG( _DBG_INFO, "* DAC: Samsung 1224\n" );
925 
926 		switch( dev->CCDID ) {
927 
928 		case _CCD_3797:
929 			DBG( _DBG_INFO, "* CCD-3797\n" );
930 			pDAC_CCD          = ShadingVar3797;
931 			u12ccd_InitFunc   = fnCCDInitSamsung3797;
932 			dev->fnDarkOffset = fnDarkOffsetSamsung3797;
933 			dev->fnDACDark    = fnDACDarkSamsung;
934 			dev->CCDRegs      = (RegDef*)S3797CCDParams;
935 			break;
936 
937 		default:
938 			DBG( _DBG_INFO, "* CCD-3799\n" );
939 			pDAC_CCD          = ShadingVar3799;
940 			u12ccd_InitFunc   = fnCCDInitSamsung3799;
941 			dev->fnDarkOffset = fnDarkOffsetSamsung3799;
942 			dev->fnDACDark    = fnDACDarkSamsung;
943 			dev->CCDRegs      = (RegDef*)S3799CCDParams;
944 		}
945 		dev->numCCDRegs         = _NUM_OF_CCDREGS_S1224;
946 		dev->numDACRegs         = _NUM_OF_DACREGS_S1224;
947 		dev->DACRegs            = SamsungDAC1224;
948 		dev->RegDACOffset.Red   = 1;
949 		dev->RegDACOffset.Green = 2;
950 		dev->RegDACOffset.Blue  = 3;
951 		dev->RegDACGain.Red     = 4;
952 		dev->RegDACGain.Green   = 5;
953 		dev->RegDACGain.Blue    = 6;
954 		dev->shade.bGainDouble  = 6;
955 		dev->shade.bUniGain     = 7;
956 		dev->shade.bMinGain     = 0;
957 		dev->shade.bMaxGain     = 0x1f;
958 		dev->shade.wDarkLevels  = 10;
959 
960 		if( dev->shade.intermediate & _ScanMode_Mono )
961 			SamsungDAC1224[0].val = 0x57;
962 		else
963 			SamsungDAC1224[0].val = 0x51;
964 		break;
965 
966 	case _DA_ESIC:
967 		DBG( _DBG_INFO, "* DAC: ESIC\n" );
968 
969 		switch( dev->CCDID ) {
970 
971 		case _CCD_3797:
972 			DBG( _DBG_INFO, "* CCD-3797\n" );
973 			pDAC_CCD          = ShadingVar3797;
974 			u12ccd_InitFunc   = fnCCDInitWolfson3797;
975 			dev->fnDarkOffset = fnDarkOffsetWolfson3797;
976 			dev->fnDACDark    = fnDACDarkWolfson;
977 			dev->CCDRegs      = (RegDef*)W3797CCDParams;
978 			break;
979 
980 		default:
981 			DBG( _DBG_INFO, "* CCD-3799\n" );
982 			pDAC_CCD          = ShadingVar3799;
983 			u12ccd_InitFunc   = fnCCDInitESIC3799;
984 			dev->fnDarkOffset = fnDarkOffsetWolfson3797;
985 			dev->fnDACDark    = fnDACDarkWolfson;
986 			dev->CCDRegs      = (RegDef*)W3799CCDParams;
987 		}
988 
989 		dev->numCCDRegs         = _NUM_OF_CCDREGS_W8143;
990 		dev->numDACRegs         = _NUM_OF_DACREGS_W8143;
991 		dev->DACRegs            = WolfsonDAC8143;
992 		dev->RegDACOffset.Red   = 0x20;
993 		dev->RegDACOffset.Green = 0x21;
994 		dev->RegDACOffset.Blue  = 0x22;
995 		dev->RegDACGain.Red     = 0x28;
996 		dev->RegDACGain.Green   = 0x29;
997 		dev->RegDACGain.Blue    = 0x2a;
998 
999 		if( dev->shade.intermediate & _ScanMode_AverageOut ) {
1000 			dev->shade.bUniGain    = 1;
1001 			dev->shade.bGainDouble = 1;
1002 		} else {
1003 			dev->shade.bUniGain    = 2;
1004 			dev->shade.bGainDouble = 4;
1005 		}
1006 		dev->shade.bMinGain    = 1;
1007 		dev->shade.bMaxGain    = 0x1f;
1008 		dev->shade.wDarkLevels = 10;
1009 
1010 		if( dev->shade.intermediate == _ScanMode_Color )
1011 			WolfsonDAC8143[2].val = 0x52;
1012 		else
1013 			WolfsonDAC8143[2].val = 0x42;
1014 
1015 		if(dev->shade.intermediate == _ScanMode_Mono )
1016 			WolfsonDAC8143[0].val = 7;
1017 		else
1018 			WolfsonDAC8143[0].val = 3;
1019 		break;
1020 
1021 	default:
1022 
1023 		DBG( _DBG_INFO, "* DAC: SAMSUNG 8531\n" );
1024 		switch( dev->CCDID ) {
1025 
1026 		case _CCD_3797:
1027 			DBG( _DBG_INFO, "* CCD-3797\n" );
1028 			pDAC_CCD          = ShadingVar3797;
1029 			u12ccd_InitFunc   = fnCCDInitSamsung3797;
1030 			dev->fnDarkOffset = fnDarkOffsetSamsung3797;
1031 			dev->fnDACDark    = fnDACDarkSamsung;
1032 			dev->CCDRegs      = (RegDef*)S3797CCDParams;
1033 			break;
1034 
1035 		case _CCD_3777:
1036 			DBG( _DBG_INFO, "* CCD-3777\n" );
1037 			pDAC_CCD          = ShadingVar3777;
1038 			u12ccd_InitFunc   = fnCCDInitSamsung3777;
1039 			dev->fnDarkOffset = fnDarkOffsetSamsung3777;
1040 			dev->fnDACDark    = fnDACDarkSamsung;
1041 			dev->CCDRegs      = (RegDef*)S3797CCDParams;
1042 			dev->f0_8_16      = SANE_TRUE;
1043 			break;
1044 
1045 		default:
1046 			DBG( _DBG_INFO, "* CCD-3799\n" );
1047 			pDAC_CCD          = ShadingVar3799;
1048 			u12ccd_InitFunc   = fnCCDInitSamsung3799;
1049 			dev->fnDarkOffset = fnDarkOffsetSamsung3799;
1050 			dev->fnDACDark    = fnDACDarkSamsung;
1051 			dev->CCDRegs      = (RegDef*)S3799CCDParams;
1052 		}
1053 
1054 		dev->numCCDRegs         = _NUM_OF_CCDREGS_S8531;
1055 		dev->numDACRegs         = _NUM_OF_DACREGS_S8531;
1056 		dev->DACRegs            = SamsungDAC8531;
1057 		dev->RegDACOffset.Red   = 1;
1058 		dev->RegDACOffset.Green = 1;
1059 		dev->RegDACOffset.Blue  = 1;
1060 		dev->RegDACGain.Red     = 2;
1061 		dev->RegDACGain.Green   = 2;
1062 		dev->RegDACGain.Blue    = 2;
1063 		dev->shade.bGainDouble  = 6;
1064 		dev->shade.bMinGain     = 1;
1065 		dev->shade.bMaxGain     = 0x1f;
1066 		if( dev->DataInf.dwScanFlag & _SCANDEF_TPA )
1067 			dev->shade.bUniGain = 2;
1068 		else
1069 			dev->shade.bUniGain = 7;
1070 
1071 		dev->shade.wDarkLevels = 10;
1072 
1073 		if( dev->shade.intermediate & _ScanMode_Mono ) {
1074 			SamsungDAC8531[0].val = 0x57;
1075 			SamsungDAC8531[3].val = 0x57;
1076 			SamsungDAC8531[6].val = 0x57;
1077 		} else {
1078 			SamsungDAC8531[0].val = 0x51;
1079 			SamsungDAC8531[3].val = 0x55;
1080 			SamsungDAC8531[6].val = 0x59;
1081 		}
1082 	}
1083 
1084 	if( shading ) {
1085 
1086 		if( !(dev->DataInf.dwScanFlag & _SCANDEF_TPA))
1087 			dev->shade.pCcdDac = &pDAC_CCD[_REFLECTION];
1088 		else {
1089 			if( dev->DataInf.dwScanFlag & _SCANDEF_Transparency )
1090 				dev->shade.pCcdDac = &pDAC_CCD[_TRANSPARENCY];
1091 			else
1092 				dev->shade.pCcdDac = &pDAC_CCD[_NEGATIVE];
1093 		}
1094 	} else {
1095 		dev->shade.pCcdDac = &pDAC_CCD[_REFLECTION];
1096 	}
1097 
1098 	/* as we now have the correct init function, call it */
1099 	u12ccd_InitFunc( dev );
1100 
1101 	DBG( _DBG_INFO, "* Programming DAC (%u regs)\n", dev->numDACRegs );
1102 
1103 	for( w = 0; w < dev->numDACRegs; w++ ) {
1104 
1105 		DBG( _DBG_INFO, "* [0x%02x] = 0x%02x\n", dev->DACRegs[w].reg,
1106 		                                         dev->DACRegs[w].val );
1107 #if 0
1108 		u12io_DataRegisterToDAC( dev, dev->DACRegs[w].reg,
1109 		                              dev->DACRegs[w].val );
1110 #else
1111 		u12io_DataToRegister( dev, REG_ADCADDR, dev->DACRegs[w].reg );
1112 		u12io_DataToRegister( dev, REG_ADCDATA, dev->DACRegs[w].val );
1113 		u12io_DataToRegister( dev, REG_ADCSERIALOUT, dev->DACRegs[w].val );
1114 #endif
1115 	}
1116 	DBG( _DBG_INFO, "CCD & DAC init done.\n" );
1117 }
1118 
1119 /* END U12-CCD.C ............................................................*/
1120