1 /* SANE - Scanner Access Now Easy.
2
3 Copyright (C) 2011-2020 Rolf Bensch <rolf at bensch hyphen online dot de>
4 Copyright (C) 2007-2009 Nicolas Martin, <nicols-guest at alioth dot debian dot org>
5 Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de>
6
7 This file is part of the SANE package.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22 As a special exception, the authors of SANE give permission for
23 additional uses of the libraries contained in this release of SANE.
24
25 The exception is that, if you link a SANE library with other files
26 to produce an executable, this does not by itself cause the
27 resulting executable to be covered by the GNU General Public
28 License. Your use of that executable is in no way restricted on
29 account of linking the SANE library code into it.
30
31 This exception does not, however, invalidate any other reasons why
32 the executable file might be covered by the GNU General Public
33 License.
34
35 If you submit changes to SANE to the maintainers to be included in
36 a subsequent release, you agree by submitting the changes that
37 those changes may be distributed with this exception intact.
38
39 If you write modifications of your own for SANE, it is your choice
40 whether to permit this exception to apply to your modifications.
41 If you do not wish that, delete this exception notice.
42 */
43 /* test cases
44 1. short USB packet (must be no -ETIMEDOUT)
45 2. cancel using button on the printer (look for abort command)
46 3. start scan while busy (status 0x1414)
47 4. cancel using ctrl-c (must send abort command)
48 */
49
50 #include "../include/sane/config.h"
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <time.h> /* localtime(C90) */
56
57 #include "pixma_rename.h"
58 #include "pixma_common.h"
59 #include "pixma_io.h"
60
61 /* Some macro code to enhance readability */
62 #define RET_IF_ERR(x) do { \
63 if ((error = (x)) < 0) \
64 return error; \
65 } while(0)
66
67 #define WAIT_INTERRUPT(x) do { \
68 error = handle_interrupt (s, x); \
69 if (s->cancel) \
70 return PIXMA_ECANCELED; \
71 if (error != PIXMA_ECANCELED && error < 0) \
72 return error; \
73 } while(0)
74
75 #ifdef __GNUC__
76 # define UNUSED(v) (void) v
77 #else
78 # define UNUSED(v)
79 #endif
80
81 /* Size of the command buffer should be multiple of wMaxPacketLength and
82 greater than 4096+24.
83 4096 = size of gamma table. 24 = header + checksum */
84 #define IMAGE_BLOCK_SIZE (512*1024)
85 #define CMDBUF_SIZE (4096 + 24)
86 #define UNKNOWN_PID 0xffff
87
88
89 #define CANON_VID 0x04a9
90
91 /* Generation 1 */
92 #define MP150_PID 0x1709
93 #define MP170_PID 0x170a
94 #define MP450_PID 0x170b
95 #define MP500_PID 0x170c
96 #define MP530_PID 0x1712
97
98 /* Generation 2 */
99 #define MP160_PID 0x1714
100 #define MP180_PID 0x1715
101 #define MP460_PID 0x1716
102 #define MP510_PID 0x1717
103 #define MP600_PID 0x1718
104 #define MP600R_PID 0x1719
105
106 #define MP140_PID 0x172b
107
108 /* Generation 3 */
109 /* PIXMA 2007 vintage */
110 #define MX7600_PID 0x171c
111 #define MP210_PID 0x1721
112 #define MP220_PID 0x1722
113 #define MP470_PID 0x1723
114 #define MP520_PID 0x1724
115 #define MP610_PID 0x1725
116 #define MX300_PID 0x1727
117 #define MX310_PID 0x1728
118 #define MX700_PID 0x1729
119 #define MX850_PID 0x172c
120
121 /* PIXMA 2008 vintage */
122 #define MP630_PID 0x172e
123 #define MP620_PID 0x172f
124 #define MP540_PID 0x1730
125 #define MP480_PID 0x1731
126 #define MP240_PID 0x1732
127 #define MP260_PID 0x1733
128 #define MP190_PID 0x1734
129
130 /* PIXMA 2009 vintage */
131 #define MX860_PID 0x1735
132 #define MX320_PID 0x1736 /* untested */
133 #define MX330_PID 0x1737
134
135 /* Generation 4 */
136 #define MP250_PID 0x173a
137 #define MP270_PID 0x173b
138 #define MP490_PID 0x173c
139 #define MP550_PID 0x173d
140 #define MP560_PID 0x173e
141 #define MP640_PID 0x173f
142
143 /* PIXMA 2010 vintage */
144 #define MX340_PID 0x1741
145 #define MX350_PID 0x1742
146 #define MX870_PID 0x1743
147
148 /* 2010 new devices (untested) */
149 #define MP280_PID 0x1746
150 #define MP495_PID 0x1747
151 #define MG5100_PID 0x1748
152 #define MG5200_PID 0x1749
153 #define MG6100_PID 0x174a
154
155 /* PIXMA 2011 vintage */
156 #define MX360_PID 0x174d
157 #define MX410_PID 0x174e
158 #define MX420_PID 0x174f
159 #define MX880_PID 0x1750
160
161 /* Generation 5 */
162 /* 2011 new devices (untested) */
163 #define MG2100_PID 0x1751
164 #define MG3100_PID 0x1752
165 #define MG4100_PID 0x1753
166 #define MG5300_PID 0x1754
167 #define MG6200_PID 0x1755
168 #define MP493_PID 0x1757
169 #define E500_PID 0x1758
170
171 /* 2012 new devices (untested) */
172 #define MX370_PID 0x1759
173 #define MX430_PID 0x175B
174 #define MX510_PID 0x175C
175 #define MX710_PID 0x175D
176 #define MX890_PID 0x175E
177 #define E600_PID 0x175A
178 #define MG4200_PID 0x1763
179
180 /* 2013 new devices */
181 #define MP230_PID 0x175F
182 #define MG6300_PID 0x1765
183
184 /* 2013 new devices (untested) */
185 #define MG2200_PID 0x1760
186 #define E510_PID 0x1761
187 #define MG3200_PID 0x1762
188 #define MG5400_PID 0x1764
189 #define MX390_PID 0x1766
190 #define E610_PID 0x1767
191 #define MX450_PID 0x1768
192 #define MX520_PID 0x1769
193 #define MX720_PID 0x176a
194 #define MX920_PID 0x176b
195 #define MG2400_PID 0x176c
196 #define MG2500_PID 0x176d
197 #define MG3500_PID 0x176e
198 #define MG6500_PID 0x176f
199 #define MG6400_PID 0x1770
200 #define MG5500_PID 0x1771
201 #define MG7100_PID 0x1772
202
203 /* 2014 new devices (untested) */
204 #define MX470_PID 0x1774
205 #define MX530_PID 0x1775
206 #define MB5000_PID 0x1776
207 #define MB5300_PID 0x1777
208 #define MB2000_PID 0x1778
209 #define MB2300_PID 0x1779
210 #define E400_PID 0x177a
211 #define E560_PID 0x177b
212 #define MG7500_PID 0x177c
213 #define MG6600_PID 0x177e
214 #define MG5600_PID 0x177f
215 #define MG2900_PID 0x1780
216 #define E460_PID 0x1788
217
218 /* 2015 new devices (untested) */
219 #define MX490_PID 0x1787
220 #define E480_PID 0x1789
221 #define MG3600_PID 0x178a
222 #define MG7700_PID 0x178b
223 #define MG6900_PID 0x178c
224 #define MG6800_PID 0x178d
225 #define MG5700_PID 0x178e
226
227 /* 2016 new devices (untested) */
228 #define MB2700_PID 0x1792
229 #define MB2100_PID 0x1793
230 #define G3000_PID 0x1794
231 #define G2000_PID 0x1795
232 #define TS9000_PID 0x179f
233 #define TS8000_PID 0x1800 /* tested: TS8030 */
234 #define TS6000_PID 0x1801
235 #define TS5000_PID 0x1802
236 #define MG3000_PID 0x180b
237 #define E470_PID 0x180c
238 #define E410_PID 0x181e
239
240 /* 2017 new devices (untested) */
241 #define G4000_PID 0x181d
242 #define TS6100_PID 0x1822
243 #define TS5100_PID 0x1825
244 #define TS3100_PID 0x1827
245 #define E3100_PID 0x1828
246
247 /* 2018 new devices (untested) */
248 #define MB5400_PID 0x178f
249 #define MB5100_PID 0x1790
250 #define TS9100_PID 0x1820
251 #define TR8500_PID 0x1823
252 #define TR7500_PID 0x1824
253 #define TS9500_PID 0x185c
254 #define LIDE400_PID 0x1912 /* tested */
255 #define LIDE300_PID 0x1913 /* tested */
256
257 /* 2019 new devices (untested) */
258 #define TS8100_PID 0x1821
259 #define G2010_PID 0x183a
260 #define G3010_PID 0x183b
261 #define G4010_PID 0x183d
262 #define TS9180_PID 0x183e
263 #define TS8180_PID 0x183f
264 #define TS6180_PID 0x1840
265 #define TR8580_PID 0x1841
266 #define TS8130_PID 0x1842
267 #define TS6130_PID 0x1843
268 #define TR8530_PID 0x1844
269 #define TR7530_PID 0x1845
270 #define XK50_PID 0x1846
271 #define XK70_PID 0x1847
272 #define TR4500_PID 0x1854
273 #define E4200_PID 0x1855
274 #define TS6200_PID 0x1856
275 #define TS6280_PID 0x1857
276 #define TS6230_PID 0x1858
277 #define TS8200_PID 0x1859
278 #define TS8280_PID 0x185a
279 #define TS8230_PID 0x185b
280 #define TS9580_PID 0x185d
281 #define TR9530_PID 0x185e
282 #define G7000_PID 0x1863
283 #define G6000_PID 0x1865
284 #define G6080_PID 0x1866
285 #define GM4000_PID 0x1869
286 #define XK80_PID 0x1873
287 #define TS5300_PID 0x188b
288 #define TS5380_PID 0x188c
289 #define TS6300_PID 0x188d
290 #define TS6380_PID 0x188e
291 #define TS7330_PID 0x188f
292 #define TS8300_PID 0x1890
293 #define TS8380_PID 0x1891
294 #define TS8330_PID 0x1892
295 #define XK60_PID 0x1893
296 #define TS6330_PID 0x1894
297 #define TS3300_PID 0x18a2
298 #define E3300_PID 0x18a3
299
300 /* 2020 new devices (untested) */
301 #define G7080_PID 0x1864
302 #define GM4080_PID 0x186A
303 #define TS3400_PID 0x18B7
304 #define E3400_PID 0x18B8
305 #define TR7000_PID 0x18B9
306 #define G2020_PID 0x18BD
307 #define G3060_PID 0x18C3
308 #define G2060_PID 0x18C1
309 #define G3020_PID 0x18BF
310 #define TS7430_PID 0x18B2
311 #define XK90_PID 0x18B6 /* tested */
312 #define TS8430_PID 0x18B5
313 #define TR7600_PID 0x18AA
314 #define TR8600_PID 0x18AD
315 #define TR8630_PID 0x18AF
316 #define TS6400_PID 0x18D3
317 #define TS7400_PID 0x18D7
318
319 /* 2021 new device (untested) */
320 #define TS5350i_PID 0x18D9
321 #define G600_PID 0x18D5
322 #define TS3500_PID 0x18D4
323 #define TR4600_PID 0x18DA
324 #define E4500_PID 0x18DB
325 #define TR4700_PID 0x18DC
326 #define XK500_PID 0x18DF
327 #define TS8530_PID 0x18E0
328 #define XK100_PID 0x18E2
329 #define TS7530_PID 0x18E1
330 #define TS7450i_PID 0x18F7
331 #define GX6000_PID 0x18A6
332 #define GX7000_PID 0x18A8
333 #define TS5400_PID 0x18D8
334
335 /* 2022 new device (untested) */
336 #define TS2400_PID 0x1108
337 #define TS2600_PID 0x1107
338
339 #define TS8630_PID 0x18F8
340 #define XK110_PID 0x18F9
341 #define GX3000_PID 0x18F1
342 #define GX4000_PID 0x18F2
343
344 /* 2023 new device (untested) */
345 #define G3070_PID 0x18F4
346 #define G2070_PID 0x18F5
347 #define G4070_PID 0x18F3
348 #define G3030_PID 0x1105
349 #define G2030_PID 0x1106
350 #define TC20M_PID 0x18FC
351 #define TC5200M_PID 0x18FF
352
353 #define TS8700_PID 0x1118
354 #define XK120_PID 0x1119
355 #define GX1000_PID 0x110B
356 #define GX2000_PID 0x110D
357 #define TS6630_PID 0x114E
358 #define TS7700_PID 0x110F
359 #define TS7600i_PID 0x114F
360 #define TS6730_PID 0x1150
361 #define TR7800_PID 0x1151
362 #define TS7700i_PID 0x1152
363 #define TS7700A_PID 0x1111
364 #define GX6500_PID 0x1148
365
366 /* Generation 4 XML messages that encapsulates the Pixma protocol messages */
367 #define XML_START_1 \
368 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\
369 <cmd xmlns:ivec=\"http://www.canon.com/ns/cmd/2008/07/common/\">\
370 <ivec:contents><ivec:operation>StartJob</ivec:operation>\
371 <ivec:param_set servicetype=\"scan\"><ivec:jobID>00000001</ivec:jobID>\
372 <ivec:bidi>1</ivec:bidi></ivec:param_set></ivec:contents></cmd>"
373
374 #define XML_START_2 \
375 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\
376 <cmd xmlns:ivec=\"http://www.canon.com/ns/cmd/2008/07/common/\" xmlns:vcn=\"http://www.canon.com/ns/cmd/2008/07/canon/\">\
377 <ivec:contents><ivec:operation>VendorCmd</ivec:operation>\
378 <ivec:param_set servicetype=\"scan\"><ivec:jobID>00000001</ivec:jobID>\
379 <vcn:ijoperation>ModeShift</vcn:ijoperation><vcn:ijmode>1</vcn:ijmode>\
380 </ivec:param_set></ivec:contents></cmd>"
381
382 #define XML_END \
383 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\
384 <cmd xmlns:ivec=\"http://www.canon.com/ns/cmd/2008/07/common/\">\
385 <ivec:contents><ivec:operation>EndJob</ivec:operation>\
386 <ivec:param_set servicetype=\"scan\"><ivec:jobID>00000001</ivec:jobID>\
387 </ivec:param_set></ivec:contents></cmd>"
388
389 #if !defined(HAVE_LIBXML2)
390 #define XML_OK "<ivec:response>OK</ivec:response>"
391 #endif
392
393 enum mp150_state_t
394 {
395 state_idle,
396 state_warmup,
397 state_scanning,
398 state_transfering,
399 state_finished
400 };
401
402 enum mp150_cmd_t
403 {
404 cmd_start_session = 0xdb20,
405 cmd_select_source = 0xdd20,
406 cmd_gamma = 0xee20,
407 cmd_scan_param = 0xde20,
408 cmd_status = 0xf320,
409 cmd_abort_session = 0xef20,
410 cmd_time = 0xeb80,
411 cmd_read_image = 0xd420,
412 cmd_error_info = 0xff20,
413
414 cmd_scan_param_3 = 0xd820,
415 cmd_scan_start_3 = 0xd920,
416 cmd_status_3 = 0xda20,
417 };
418
419 typedef struct mp150_t
420 {
421 enum mp150_state_t state;
422 pixma_cmdbuf_t cb;
423 uint8_t *imgbuf;
424 uint8_t current_status[16];
425 unsigned last_block;
426 uint8_t generation;
427 /* for Generation 3 shift */
428 uint8_t *linebuf;
429 uint8_t *data_left_ofs;
430 unsigned data_left_len;
431 uint8_t adf_state; /* handle adf scanning */
432 unsigned scale; /* Scale factor for lower resolutions, the
433 * scanner doesn't support. We scale down the
434 * image after scanning minimum possible
435 * resolution.
436 */
437
438 } mp150_t;
439
440 /*
441 STAT: 0x0606 = ok,
442 0x1515 = failed (PIXMA_ECANCELED),
443 0x1414 = busy (PIXMA_EBUSY)
444
445 Transaction scheme
446 1. command_header/data | result_header
447 2. command_header | result_header/data
448 3. command_header | result_header/image_data
449
450 - data has checksum in the last byte.
451 - image_data has no checksum.
452 - data and image_data begins in the same USB packet as
453 command_header or result_header.
454
455 command format #1:
456 u16be cmd
457 u8[6] 0
458 u8[4] 0
459 u32be PLEN parameter length
460 u8[PLEN-1] parameter
461 u8 parameter check sum
462 result:
463 u16be STAT
464 u8 0
465 u8 0 or 0x21 if STAT == 0x1414
466 u8[4] 0
467
468 command format #2:
469 u16be cmd
470 u8[6] 0
471 u8[4] 0
472 u32be RLEN result length
473 result:
474 u16be STAT
475 u8[6] 0
476 u8[RLEN-1] result
477 u8 result check sum
478
479 command format #3: (only used by read_image_block)
480 u16be 0xd420
481 u8[6] 0
482 u8[4] 0
483 u32be max. block size + 8
484 result:
485 u16be STAT
486 u8[6] 0
487 u8 block info bitfield: 0x8 = end of scan, 0x10 = no more paper, 0x20 = no more data
488 u8[3] 0
489 u32be ILEN image data size
490 u8[ILEN] image data
491 */
492
493 static void mp150_finish_scan (pixma_t * s);
494
495 static int
is_scanning_from_adf(pixma_t * s)496 is_scanning_from_adf (pixma_t * s)
497 {
498 return (s->param->source == PIXMA_SOURCE_ADF
499 || s->param->source == PIXMA_SOURCE_ADFDUP);
500 }
501
502 static int
is_scanning_from_adfdup(pixma_t * s)503 is_scanning_from_adfdup (pixma_t * s)
504 {
505 return (s->param->source == PIXMA_SOURCE_ADFDUP);
506 }
507
508 static int
is_scanning_jpeg(pixma_t * s)509 is_scanning_jpeg (pixma_t *s)
510 {
511 return s->param->mode_jpeg;
512 }
513
514 static int
send_xml_dialog(pixma_t * s,const char * xml_message)515 send_xml_dialog (pixma_t * s, const char * xml_message)
516 {
517 mp150_t *mp = (mp150_t *) s->subdriver;
518 int datalen;
519
520 datalen = pixma_cmd_transaction (s, xml_message, strlen (xml_message),
521 mp->cb.buf, 1024);
522 if (datalen < 0)
523 return datalen;
524
525 mp->cb.buf[datalen] = 0;
526
527 PDBG (pixma_dbg (10, "XML message sent to scanner:\n%s\n", xml_message));
528 PDBG (pixma_dbg (10, "XML response back from scanner:\n%s\n", mp->cb.buf));
529
530 #if defined(HAVE_LIBXML2)
531 return pixma_parse_xml_response((const char*)mp->cb.buf) == PIXMA_STATUS_OK;
532 #else
533 return (strcasestr ((const char *) mp->cb.buf, XML_OK) != NULL);
534 #endif
535 }
536
537 static int
start_session(pixma_t * s)538 start_session (pixma_t * s)
539 {
540 mp150_t *mp = (mp150_t *) s->subdriver;
541
542 pixma_newcmd (&mp->cb, cmd_start_session, 0, 0);
543 mp->cb.buf[3] = 0x00;
544 return pixma_exec (s, &mp->cb);
545 }
546
547 static int
start_scan_3(pixma_t * s)548 start_scan_3 (pixma_t * s)
549 {
550 mp150_t *mp = (mp150_t *) s->subdriver;
551
552 pixma_newcmd (&mp->cb, cmd_scan_start_3, 0, 0);
553 mp->cb.buf[3] = 0x00;
554 return pixma_exec (s, &mp->cb);
555 }
556
557 static int
is_calibrated(pixma_t * s)558 is_calibrated (pixma_t * s)
559 {
560 mp150_t *mp = (mp150_t *) s->subdriver;
561 if (mp->generation >= 3)
562 {
563 return ((mp->current_status[0] & 0x01) == 1 || (mp->current_status[0] & 0x02) == 2);
564 }
565 if (mp->generation == 1)
566 {
567 return (mp->current_status[8] == 1);
568 }
569 else
570 {
571 return (mp->current_status[9] == 1);
572 }
573 }
574
575 static int
has_paper(pixma_t * s)576 has_paper (pixma_t * s)
577 {
578 mp150_t *mp = (mp150_t *) s->subdriver;
579
580 if (is_scanning_from_adfdup (s))
581 return (mp->current_status[1] == 0 || mp->current_status[2] == 0);
582 else
583 return (mp->current_status[1] == 0);
584 }
585
586 static void
drain_bulk_in(pixma_t * s)587 drain_bulk_in (pixma_t * s)
588 {
589 mp150_t *mp = (mp150_t *) s->subdriver;
590 while (pixma_read (s->io, mp->imgbuf, IMAGE_BLOCK_SIZE) >= 0);
591 }
592
593 static int
abort_session(pixma_t * s)594 abort_session (pixma_t * s)
595 {
596 mp150_t *mp = (mp150_t *) s->subdriver;
597 mp->adf_state = state_idle; /* reset adf scanning */
598 return pixma_exec_short_cmd (s, &mp->cb, cmd_abort_session);
599 }
600
601 static int
select_source(pixma_t * s)602 select_source (pixma_t * s)
603 {
604 mp150_t *mp = (mp150_t *) s->subdriver;
605 uint8_t *data;
606
607 data = pixma_newcmd (&mp->cb, cmd_select_source, 12, 0);
608 data[5] = ((mp->generation == 2) ? 1 : 0);
609 switch (s->param->source)
610 {
611 case PIXMA_SOURCE_FLATBED:
612 data[0] = 1;
613 data[1] = 1;
614 break;
615
616 case PIXMA_SOURCE_ADF:
617 data[0] = 2;
618 data[5] = 1;
619 data[6] = 1;
620 break;
621
622 case PIXMA_SOURCE_ADFDUP:
623 data[0] = 2;
624 data[5] = 3;
625 data[6] = 3;
626 break;
627
628 default:
629 return PIXMA_EPROTO;
630 }
631 return pixma_exec (s, &mp->cb);
632 }
633
634 static int
send_gamma_table(pixma_t * s)635 send_gamma_table (pixma_t * s)
636 {
637 mp150_t *mp = (mp150_t *) s->subdriver;
638 const uint8_t *lut = s->param->gamma_table;
639 uint8_t *data;
640
641 if (s->cfg->cap & PIXMA_CAP_GT_4096)
642 {
643 data = pixma_newcmd (&mp->cb, cmd_gamma, 4096 + 8, 0);
644 data[0] = (s->param->channels == 3) ? 0x10 : 0x01;
645 pixma_set_be16 (0x1004, data + 2);
646 if (lut)
647 {
648 /* PDBG (pixma_dbg (4, "*send_gamma_table***** Use 4096 bytes from LUT ***** \n")); */
649 /* PDBG (pixma_hexdump (4, lut, 4096)); */
650 memcpy (data + 4, lut, 4096);
651 }
652 else
653 {
654 /* fallback: we should never see this */
655 PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 4096 bytes Table with %f ***** \n",
656 s->param->gamma));
657 pixma_fill_gamma_table (s->param->gamma, data + 4, 4096);
658 /* PDBG (pixma_hexdump (4, data + 4, 4096)); */
659 }
660 }
661 else
662 {
663 /* Gamma table for 2nd+ generation: 1024 * uint16_le */
664 data = pixma_newcmd (&mp->cb, cmd_gamma, 1024 * 2 + 8, 0);
665 data[0] = 0x10;
666 pixma_set_be16 (0x0804, data + 2);
667 if (lut)
668 {
669 /* PDBG (pixma_dbg (4, "*send_gamma_table***** Use 1024 * 2 bytes from LUT ***** \n")); */
670 /* PDBG (pixma_hexdump (4, lut, 1024 * 2)); */
671 memcpy (data + 4, lut, 1024 * 2);
672 }
673 else
674 {
675 /* fallback: we should never see this */
676 PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 1024 * 2 Table with %f ***** \n",
677 s->param->gamma));
678 pixma_fill_gamma_table (s->param->gamma, data + 4, 1024);
679 /* PDBG (pixma_hexdump (4, data + 4, 1024 * 2)); */
680 }
681 }
682 return pixma_exec (s, &mp->cb);
683 }
684
685 static unsigned
calc_raw_width(const mp150_t * mp,const pixma_scan_param_t * param)686 calc_raw_width (const mp150_t * mp, const pixma_scan_param_t * param)
687 {
688 unsigned raw_width;
689 /* NOTE: Actually, we can send arbitrary width to MP150. Lines returned
690 are always padded to multiple of 4 or 12 pixels. Is this valid for
691 other models, too? */
692 if (mp->generation >= 2)
693 {
694 raw_width = ALIGN_SUP ((param->w * mp->scale) + param->xs, 32);
695 /* PDBG (pixma_dbg (4, "*calc_raw_width***** width %i extended by %i and rounded to %i *****\n", param->w, param->xs, raw_width)); */
696 }
697 else if (param->channels == 1)
698 {
699 raw_width = ALIGN_SUP (param->w + param->xs, 12);
700 }
701 else
702 {
703 raw_width = ALIGN_SUP (param->w + param->xs, 4);
704 }
705 return raw_width;
706 }
707
708 static int
is_gray_16(pixma_t * s)709 is_gray_16 (pixma_t * s)
710 {
711 return (s->param->mode == PIXMA_SCAN_MODE_GRAY_16);
712 }
713
714 static unsigned
get_cis_line_size(pixma_t * s)715 get_cis_line_size (pixma_t * s)
716 {
717 mp150_t *mp = (mp150_t *) s->subdriver;
718
719 /*PDBG (pixma_dbg (4, "%s: line_size=%ld, w=%d, wx=%d, scale=%d\n",
720 __func__, s->param->line_size, s->param->w, s->param->wx, mp->scale));*/
721
722 return (s->param->wx ? s->param->line_size / s->param->w * s->param->wx
723 : s->param->line_size)
724 * mp->scale
725 * (is_gray_16(s) ? 3 : 1);
726 }
727
728 static int
send_scan_param(pixma_t * s)729 send_scan_param (pixma_t * s)
730 {
731 mp150_t *mp = (mp150_t *) s->subdriver;
732 uint8_t *data;
733 unsigned xdpi = s->param->xdpi * mp->scale;
734 unsigned ydpi = s->param->xdpi * mp->scale;
735 unsigned x = s->param->x * mp->scale;
736 unsigned xs = s->param->xs;
737 unsigned y = s->param->y * mp->scale;
738 unsigned wx = calc_raw_width (mp, s->param);
739 unsigned h = MIN (s->param->h, s->cfg->height * s->param->ydpi / 75) * mp->scale;
740
741 if (mp->generation <= 2)
742 {
743 PDBG (pixma_dbg (4, "*send_scan_param gen. 1-2 ***** Setting: xdpi=%u ydpi=%u x=%i y=%i wx=%i ***** \n",
744 xdpi, ydpi, x-xs, y, wx));
745 data = pixma_newcmd (&mp->cb, cmd_scan_param, 0x30, 0);
746 pixma_set_be16 (xdpi | 0x8000, data + 0x04);
747 pixma_set_be16 (ydpi | 0x8000, data + 0x06);
748 pixma_set_be32 (x, data + 0x08);
749 if (mp->generation == 2)
750 pixma_set_be32 (x - s->param->xs, data + 0x08);
751 pixma_set_be32 (y, data + 0x0c);
752 pixma_set_be32 (wx, data + 0x10);
753 pixma_set_be32 (h, data + 0x14);
754 data[0x18] = (s->param->channels != 1) ? 0x08 : 0x04;
755 data[0x19] = ((s->param->software_lineart) ? 8 : s->param->depth)
756 * s->param->channels; /* bits per pixel */
757 data[0x1a] = 0;
758 data[0x20] = 0xff;
759 data[0x23] = 0x81;
760 data[0x26] = 0x02;
761 data[0x27] = 0x01;
762 }
763 else
764 {
765 PDBG (pixma_dbg (4, "*send_scan_param gen. 3+ ***** Setting: xdpi=%u ydpi=%u x=%i xs=%i y=%i wx=%i h=%i ***** \n",
766 xdpi, ydpi, x, xs, y, wx, h));
767 data = pixma_newcmd (&mp->cb, cmd_scan_param_3, 0x38, 0);
768 data[0x00] = (is_scanning_from_adf (s)) ? 0x02 : 0x01;
769 data[0x01] = 0x01;
770 data[0x02] = 0x01;
771 if (is_scanning_from_adfdup (s))
772 {
773 data[0x02] = 0x03;
774 data[0x03] = 0x03;
775 }
776 if (is_scanning_jpeg (s))
777 {
778 data[0x03] = 0x01;
779 }
780 data[0x05] = pixma_calc_calibrate (s);
781 pixma_set_be16 (xdpi | 0x8000, data + 0x08);
782 pixma_set_be16 (ydpi | 0x8000, data + 0x0a);
783 pixma_set_be32 (x - xs, data + 0x0c);
784 pixma_set_be32 (y, data + 0x10);
785 pixma_set_be32 (wx, data + 0x14);
786 pixma_set_be32 (h, data + 0x18);
787 /*PDBG (pixma_dbg (4, "*send_scan_param gen. 3+ ***** Setting: channels=%hi depth=%hi ***** \n",
788 s->param->channels, s->param->depth));*/
789 data[0x1c] = ((s->param->channels != 1) || (is_gray_16(s)) ? 0x08 : 0x04);
790
791 data[0x1d] = ((s->param->software_lineart) ? 8 : s->param->depth)
792 * (is_gray_16(s) ? 3 : s->param->channels); /* bits per pixel */
793
794 data[0x1f] = 0x01; /* This one also seen at 0. Don't know yet what's used for */
795 data[0x20] = 0xff;
796 if (is_scanning_jpeg (s))
797 {
798 data[0x21] = 0x83;
799 }
800 else
801 {
802 data[0x21] = 0x81;
803 }
804 data[0x23] = 0x02;
805 data[0x24] = 0x01;
806
807 switch (s->cfg->pid)
808 {
809 case MG5300_PID:
810 /* unknown values (perhaps counter) for MG5300 series---values must be 0x30-0x39: decimal 0-9 */
811 data[0x26] = 0x32; /* using example values from a real scan here */
812 data[0x27] = 0x31;
813 data[0x28] = 0x34;
814 data[0x29] = 0x35;
815 break;
816
817 default:
818 break;
819 }
820
821 data[0x30] = 0x01;
822 }
823 return pixma_exec (s, &mp->cb);
824 }
825
826 static int
query_status_3(pixma_t * s)827 query_status_3 (pixma_t * s)
828 {
829 mp150_t *mp = (mp150_t *) s->subdriver;
830 uint8_t *data;
831 int error, status_len;
832
833 status_len = 8;
834 data = pixma_newcmd (&mp->cb, cmd_status_3, 0, status_len);
835 RET_IF_ERR (pixma_exec (s, &mp->cb));
836 memcpy (mp->current_status, data, status_len);
837 return error;
838 }
839
840 static int
query_status(pixma_t * s)841 query_status (pixma_t * s)
842 {
843 mp150_t *mp = (mp150_t *) s->subdriver;
844 uint8_t *data;
845 int error, status_len;
846
847 status_len = (mp->generation == 1) ? 12 : 16;
848 data = pixma_newcmd (&mp->cb, cmd_status, 0, status_len);
849 RET_IF_ERR (pixma_exec (s, &mp->cb));
850 memcpy (mp->current_status, data, status_len);
851 PDBG (pixma_dbg (3, "Current status: paper=%u cal=%u lamp=%u busy=%u\n",
852 data[1], data[8], data[7], data[9]));
853 return error;
854 }
855
856 #if 0
857 static int
858 send_time (pixma_t * s)
859 {
860 /* Why does a scanner need a time? */
861 time_t now;
862 struct tm *t;
863 uint8_t *data;
864 mp150_t *mp = (mp150_t *) s->subdriver;
865
866 data = pixma_newcmd (&mp->cb, cmd_time, 20, 0);
867 pixma_get_time (&now, NULL);
868 t = localtime (&now);
869 strftime ((char *) data, 16, "%y/%m/%d %H:%M", t);
870 PDBG (pixma_dbg (3, "Sending time: '%s'\n", (char *) data));
871 return pixma_exec (s, &mp->cb);
872 }
873 #endif
874
875 /* TODO: Simplify this function. Read the whole data packet in one shot. */
876 static int
read_image_block(pixma_t * s,uint8_t * header,uint8_t * data)877 read_image_block (pixma_t * s, uint8_t * header, uint8_t * data)
878 {
879 uint8_t cmd[16];
880 mp150_t *mp = (mp150_t *) s->subdriver;
881 const int hlen = 8 + 8;
882 int error, datalen;
883
884 memset (cmd, 0, sizeof (cmd));
885 pixma_set_be16 (cmd_read_image, cmd);
886 if ((mp->last_block & 0x20) == 0)
887 pixma_set_be32 ((IMAGE_BLOCK_SIZE / 65536) * 65536 + 8, cmd + 0xc);
888 else
889 pixma_set_be32 (32 + 8, cmd + 0xc);
890
891 mp->state = state_transfering;
892 mp->cb.reslen =
893 pixma_cmd_transaction (s, cmd, sizeof (cmd), mp->cb.buf, 512);
894 datalen = mp->cb.reslen;
895 if (datalen < 0)
896 return datalen;
897
898 memcpy (header, mp->cb.buf, hlen);
899
900 if (datalen >= hlen)
901 {
902 datalen -= hlen;
903 memcpy (data, mp->cb.buf + hlen, datalen);
904 data += datalen;
905 if (mp->cb.reslen == 512)
906 {
907 error = pixma_read (s->io, data, IMAGE_BLOCK_SIZE - 512 + hlen);
908 RET_IF_ERR (error);
909 datalen += error;
910 }
911 }
912
913 mp->state = state_scanning;
914 mp->cb.expected_reslen = 0;
915 RET_IF_ERR (pixma_check_result (&mp->cb));
916 if (mp->cb.reslen < hlen)
917 return PIXMA_EPROTO;
918 return datalen;
919 }
920
921 static int
read_error_info(pixma_t * s,void * buf,unsigned size)922 read_error_info (pixma_t * s, void *buf, unsigned size)
923 {
924 unsigned len = 16;
925 mp150_t *mp = (mp150_t *) s->subdriver;
926 uint8_t *data;
927 int error;
928
929 data = pixma_newcmd (&mp->cb, cmd_error_info, 0, len);
930 RET_IF_ERR (pixma_exec (s, &mp->cb));
931 if (buf && len < size)
932 {
933 size = len;
934 /* NOTE: I've absolutely no idea what the returned data mean. */
935 memcpy (buf, data, size);
936 error = len;
937 }
938 return error;
939 }
940
941 /*
942 handle_interrupt() waits until it receives an interrupt packet or times out.
943 It calls send_time() and query_status() if necessary. Therefore, make sure
944 that handle_interrupt() is only called from a safe context for send_time()
945 and query_status().
946
947 Returns:
948 0 timed out
949 1 an interrupt packet received
950 PIXMA_ECANCELED interrupted by signal
951 <0 error
952 */
953 static int
handle_interrupt(pixma_t * s,int timeout)954 handle_interrupt (pixma_t * s, int timeout)
955 {
956 uint8_t buf[64];
957 int len;
958
959 len = pixma_wait_interrupt (s->io, buf, sizeof (buf), timeout);
960 if (len == PIXMA_ETIMEDOUT)
961 return 0;
962 if (len < 0)
963 return len;
964 if (len%16) /* len must be a multiple of 16 bytes */
965 {
966 PDBG (pixma_dbg
967 (1, "WARNING:unexpected interrupt packet length %d\n", len));
968 return PIXMA_EPROTO;
969 }
970
971 /* s->event = 0x0brroott
972 * b: button
973 * oo: original
974 * tt: target
975 * rr: scan resolution
976 * poll event with 'scanimage -A' */
977 if (s->cfg->pid == MG5300_PID
978 || s->cfg->pid == MG5400_PID
979 || s->cfg->pid == MG5700_PID
980 || s->cfg->pid == MG6200_PID
981 || s->cfg->pid == MG6300_PID
982 || s->cfg->pid == MX340_PID
983 || s->cfg->pid == MX520_PID
984 || s->cfg->pid == MX720_PID
985 || s->cfg->pid == MX920_PID
986 || s->cfg->pid == MB2300_PID
987 || s->cfg->pid == MB5000_PID
988 || s->cfg->pid == MB5400_PID
989 || s->cfg->pid == TR4500_PID)
990 /* button no. in buf[7]
991 * size in buf[10] 01=A4; 02=Letter; 08=10x15; 09=13x18; 0b=auto
992 * format in buf[11] 01=JPEG; 02=TIFF; 03=PDF; 04=Kompakt-PDF
993 * dpi in buf[12] 01=75; 02=150; 03=300; 04=600
994 * target = format; original = size; scan-resolution = dpi */
995 {
996 if (buf[7] & 1)
997 {
998 /* color scan */
999 s->events = PIXMA_EV_BUTTON1 | (buf[11] & 0x0f) | (buf[10] & 0x0f) << 8
1000 | (buf[12] & 0x0f) << 16;
1001 }
1002 if (buf[7] & 2)
1003 {
1004 /* b/w scan */
1005 s->events = PIXMA_EV_BUTTON2 | (buf[11] & 0x0f) | (buf[10] & 0x0f) << 8
1006 | (buf[12] & 0x0f) << 16;
1007 }
1008
1009 /* some scanners provide additional information:
1010 * document type in buf[6] 01=Document; 02=Photo; 03=Auto Scan
1011 * ADF status in buf[8] 01 = ADF empty; 02 = ADF filled
1012 * ADF orientation in buf[16] 01=Portrait; 02=Landscape
1013 *
1014 * ToDo: maybe this if isn't needed
1015 */
1016 if (s->cfg->pid == TR4500_PID || s->cfg->pid == MX340_PID)
1017 {
1018 s->events |= (buf[6] & 0x0f) << 12;
1019 s->events |= (buf[8] & 0x0f) << 20;
1020 s->events |= (buf[16] & 0x0f) << 4;
1021 }
1022 }
1023 else if (s->cfg->pid == LIDE300_PID
1024 || s->cfg->pid == LIDE400_PID)
1025 /* unknown value in buf[4]
1026 * target in buf[0x13] 01=copy; 02=auto; 03=send; 05=start PDF; 06=finish PDF
1027 * "Finish PDF" is Button-2, all others are Button-1 */
1028 {
1029 if (buf[0x13] == 0x06)
1030 {
1031 /* button 2 = cancel / end scan */
1032 s->events = PIXMA_EV_BUTTON2 | (buf[0x13] & 0x0f);
1033 }
1034 else if (buf[0x13])
1035 {
1036 /* button 1 = start scan */
1037 s->events = PIXMA_EV_BUTTON1 | (buf[0x13] & 0x0f);
1038 }
1039 }
1040 else
1041 /* button no. in buf[0]
1042 * original in buf[0]
1043 * target in buf[1] */
1044 {
1045 /* More than one event can be reported at the same time. */
1046 if (buf[3] & 1)
1047 /* FIXME: This function makes trouble with a lot of scanners
1048 send_time (s);
1049 */
1050 PDBG (pixma_dbg (1, "WARNING:send_time() disabled!\n"));
1051 if (buf[9] & 2)
1052 query_status (s);
1053 if (buf[0] & 2)
1054 {
1055 /* b/w scan */
1056 s->events = PIXMA_EV_BUTTON2 | (buf[1] & 0x0f) | (buf[0] & 0xf0) << 4;
1057 }
1058 if (buf[0] & 1)
1059 {
1060 /* color scan */
1061 s->events = PIXMA_EV_BUTTON1 | (buf[1] & 0x0f) | ((buf[0] & 0xf0) << 4);
1062 }
1063 }
1064 return 1;
1065 }
1066
1067 static int
wait_until_ready(pixma_t * s)1068 wait_until_ready (pixma_t * s)
1069 {
1070 mp150_t *mp = (mp150_t *) s->subdriver;
1071 int error, tmo = 120; /* some scanners need a long timeout */
1072
1073 RET_IF_ERR ((mp->generation >= 3) ? query_status_3 (s)
1074 : query_status (s));
1075 while (!is_calibrated (s))
1076 {
1077 WAIT_INTERRUPT (1000);
1078 if (mp->generation >= 3)
1079 RET_IF_ERR (query_status_3 (s));
1080 else if (s->cfg->pid == MP600_PID ||
1081 s->cfg->pid == MP600R_PID)
1082 RET_IF_ERR (query_status (s));
1083 if (--tmo == 0)
1084 {
1085 PDBG (pixma_dbg (1, "WARNING:Timed out in wait_until_ready()\n"));
1086 PDBG (query_status (s));
1087 return PIXMA_ETIMEDOUT;
1088 }
1089 }
1090 return 0;
1091 }
1092
1093 static void
reorder_pixels(uint8_t * linebuf,uint8_t * sptr,unsigned c,unsigned n,unsigned m,unsigned w,unsigned line_size)1094 reorder_pixels (uint8_t * linebuf, uint8_t * sptr, unsigned c, unsigned n,
1095 unsigned m, unsigned w, unsigned line_size)
1096 {
1097 unsigned i;
1098
1099 for (i = 0; i < w; i++)
1100 {
1101 memcpy (linebuf + c * (n * (i % m) + i / m), sptr + c * i, c);
1102 }
1103 memcpy (sptr, linebuf, line_size);
1104 }
1105
1106 /* the scanned image must be shrunk by factor "scale"
1107 * the image can be formatted as rgb (c=3) or gray (c=1)
1108 * we need to crop the left side (xs)
1109 * we ignore more pixels inside scanned line (wx), behind needed line (w)
1110 *
1111 * example (scale=2):
1112 * line | pixel[0] | pixel[1] | ... | pixel[w-1]
1113 * ---------
1114 * 0 | rgbrgb | rgbrgb | ... | rgbrgb
1115 * wx*c | rgbrgb | rgbrgb | ... | rgbrgb
1116 */
1117 uint8_t *
shrink_image(uint8_t * dptr,uint8_t * sptr,unsigned xs,unsigned w,unsigned wx,unsigned scale,unsigned c)1118 shrink_image (uint8_t * dptr, uint8_t * sptr, unsigned xs, unsigned w,
1119 unsigned wx, unsigned scale, unsigned c)
1120 {
1121 unsigned i, ic;
1122 uint16_t pixel;
1123 uint8_t *dst = dptr; /* don't change dptr */
1124 uint8_t *src = sptr; /* don't change sptr */
1125
1126 /*PDBG (pixma_dbg (4, "%s: w=%d, wx=%d, c=%d, scale=%d\n",
1127 __func__, w, wx, c, scale));
1128 PDBG (pixma_dbg (4, "\tdptr=%ld, sptr=%ld\n",
1129 dptr, sptr));*/
1130
1131 /* crop left side */
1132 src += c * xs;
1133
1134 /* process line */
1135 for (i = 0; i < w; i++)
1136 {
1137 /* process rgb or gray pixel */
1138 for (ic = 0; ic < c; ic++)
1139 {
1140 #if 0
1141 dst[ic] = src[ic];
1142 #else
1143 pixel = 0;
1144
1145 /* sum shrink pixels */
1146 for (unsigned m = 0; m < scale; m++) /* get pixels from shrunk lines */
1147 {
1148 for (unsigned n = 0; n < scale; n++) /* get pixels from same line */
1149 {
1150 pixel += src[ic + c * n + wx * c * m];
1151 }
1152 }
1153 dst[ic] = pixel / (scale * scale);
1154 #endif
1155 }
1156
1157 /* jump over shrunk data */
1158 src += c * scale;
1159 /* next pixel */
1160 dst += c;
1161 }
1162
1163 return dst;
1164 }
1165
1166 /* This function deals with Generation >= 3 high dpi images.
1167 * Each complete line in mp->imgbuf is processed for reordering pixels above
1168 * 600 dpi for Generation >= 3. */
1169 static unsigned
post_process_image_data(pixma_t * s,pixma_imagebuf_t * ib)1170 post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib)
1171 {
1172 mp150_t *mp = (mp150_t *) s->subdriver;
1173 unsigned c, lines, line_size, n, m, cw, cx;
1174 uint8_t *sptr, *dptr, *gptr, *cptr;
1175
1176 if (s->param->mode_jpeg)
1177 {
1178 /* No post-processing, send raw JPEG data to main */
1179 ib->rptr = mp->imgbuf;
1180 ib->rend = mp->data_left_ofs;
1181 return 0; /* # of non processed bytes */
1182 }
1183
1184 /* process image sizes */
1185 c = (is_gray_16(s) ? 3 : s->param->channels)
1186 * ((s->param->software_lineart) ? 8 : s->param->depth) / 8; /* color channels count */
1187 cw = c * s->param->w; /* image width */
1188 cx = c * s->param->xs; /* x-offset */
1189
1190 /* special image format parameters
1191 * n: no. of sub-images
1192 * m: sub-image width
1193 */
1194 if (mp->generation >= 3)
1195 n = s->param->xdpi / 600;
1196 else
1197 n = s->param->xdpi / 2400;
1198 if (s->cfg->pid == MP600_PID || s->cfg->pid == MP600R_PID || s->cfg->pid == XK90_PID)
1199 n = s->param->xdpi / 1200;
1200 m = (n > 0) ? s->param->wx / n : 1;
1201
1202 /* Initialize pointers */
1203 sptr = dptr = gptr = cptr = mp->imgbuf;
1204
1205 /* walk through complete received lines */
1206 line_size = get_cis_line_size (s);
1207 lines = (mp->data_left_ofs - mp->imgbuf) / line_size;
1208 if (lines > 0)
1209 {
1210 unsigned i;
1211
1212 /*PDBG (pixma_dbg (4, "*post_process_image_data***** Processing with c=%u, n=%u, m=%u, wx=%i, line_size=%u, cx=%u, cw=%u ***** \n",
1213 c, n, m, s->param->wx, line_size, cx, cw));*/
1214 /*PDBG (pixma_dbg (4, "*post_process_image_data***** lines = %i ***** \n", lines));*/
1215
1216 for (i = 0; i < lines; i++, sptr += line_size)
1217 {
1218 /*PDBG (pixma_dbg (4, "*post_process_image_data***** Processing with c=%u, n=%u, m=%u, w=%i, line_size=%u ***** \n",
1219 c, n, m, s->param->wx, line_size));*/
1220 /*PDBG (pixma_dbg (4, "*post_process_image_data***** Pointers: sptr=%lx, dptr=%lx, linebuf=%lx ***** \n",
1221 sptr, dptr, mp->linebuf));*/
1222
1223 /* special image format for *most* devices at high dpi.
1224 * MP220, MX360 and generation 5 scanners are exceptions */
1225 if (n > 1
1226 && s->cfg->pid != MP220_PID
1227 && s->cfg->pid != MX360_PID
1228 && (mp->generation < 5
1229 /* generation 5 scanners *with* special image format */
1230 || s->cfg->pid == MG2200_PID
1231 || s->cfg->pid == MG3200_PID
1232 || s->cfg->pid == MG4200_PID
1233 || s->cfg->pid == MG5600_PID
1234 || s->cfg->pid == MG5700_PID
1235 || s->cfg->pid == MG6200_PID
1236 || s->cfg->pid == MP230_PID
1237 || s->cfg->pid == MX470_PID
1238 || s->cfg->pid == MX510_PID
1239 || s->cfg->pid == XK90_PID
1240 || s->cfg->pid == MX520_PID))
1241 reorder_pixels (mp->linebuf, sptr, c, n, m, s->param->wx, line_size);
1242
1243
1244 /* scale image */
1245 if (mp->scale > 1)
1246 {
1247 /* Crop line inside shrink_image() */
1248 shrink_image(cptr, sptr, s->param->xs, s->param->w, s->param->wx, mp->scale, c);
1249 }
1250 else
1251 {
1252 /* Crop line to selected borders */
1253 memmove(cptr, sptr + cx, cw);
1254 }
1255
1256 /* Color / Gray to Lineart convert */
1257 if (s->param->software_lineart)
1258 cptr = gptr = pixma_binarize_line (s->param, gptr, cptr, s->param->w, c);
1259 /* Color to Grayscale convert for 16bit gray */
1260 else if (is_gray_16(s))
1261 cptr = gptr = pixma_rgb_to_gray (gptr, cptr, s->param->w, c);
1262 else
1263 cptr += cw;
1264 }
1265 }
1266 ib->rptr = mp->imgbuf;
1267 ib->rend = cptr;
1268 return mp->data_left_ofs - sptr; /* # of non processed bytes */
1269 }
1270
1271 static int
mp150_open(pixma_t * s)1272 mp150_open (pixma_t * s)
1273 {
1274 mp150_t *mp;
1275 uint8_t *buf;
1276
1277 mp = (mp150_t *) calloc (1, sizeof (*mp));
1278 if (!mp)
1279 return PIXMA_ENOMEM;
1280
1281 buf = (uint8_t *) malloc (CMDBUF_SIZE + IMAGE_BLOCK_SIZE);
1282 if (!buf)
1283 {
1284 free (mp);
1285 return PIXMA_ENOMEM;
1286 }
1287
1288 s->subdriver = mp;
1289 mp->state = state_idle;
1290
1291 mp->cb.buf = buf;
1292 mp->cb.size = CMDBUF_SIZE;
1293 mp->cb.res_header_len = 8;
1294 mp->cb.cmd_header_len = 16;
1295 mp->cb.cmd_len_field_ofs = 14;
1296
1297 mp->imgbuf = buf + CMDBUF_SIZE;
1298
1299 /* General rules for setting Pixma protocol generation # */
1300 mp->generation = (s->cfg->pid >= MP160_PID) ? 2 : 1;
1301
1302 if (s->cfg->pid >= MX7600_PID)
1303 mp->generation = 3;
1304
1305 if (s->cfg->pid >= MP250_PID)
1306 mp->generation = 4;
1307
1308 if (s->cfg->pid >= MG2100_PID) /* this scanners generation doesn't need */
1309 mp->generation = 5; /* special image conversion @ high dpi */
1310
1311 /* And exceptions to be added here */
1312 if (s->cfg->pid == MP140_PID)
1313 mp->generation = 2;
1314
1315 PDBG (pixma_dbg (3, "*mp150_open***** This is a generation %d scanner. *****\n", mp->generation));
1316
1317 /* adf scanning */
1318 mp->adf_state = state_idle;
1319
1320 if (mp->generation < 4)
1321 {
1322 query_status (s);
1323 handle_interrupt (s, 200);
1324 }
1325 return 0;
1326 }
1327
1328 static void
mp150_close(pixma_t * s)1329 mp150_close (pixma_t * s)
1330 {
1331 mp150_t *mp = (mp150_t *) s->subdriver;
1332
1333 mp150_finish_scan (s);
1334 free (mp->cb.buf);
1335 free (mp);
1336 s->subdriver = NULL;
1337 }
1338
1339 static int
mp150_check_param(pixma_t * s,pixma_scan_param_t * sp)1340 mp150_check_param (pixma_t * s, pixma_scan_param_t * sp)
1341 {
1342 mp150_t *mp = (mp150_t *) s->subdriver;
1343
1344 /* PDBG (pixma_dbg (4, "*mp150_check_param***** Initially: channels=%u, depth=%u, x=%u, y=%u, w=%u, h=%u, xs=%u, wx=%u, gamma=%f *****\n",
1345 sp->channels, sp->depth, sp->x, sp->y, sp->w, sp->h, sp->xs, sp->wx, sp->gamma)); */
1346
1347 sp->channels = 3;
1348 sp->software_lineart = 0;
1349 switch (sp->mode)
1350 {
1351 /* standard scan modes
1352 * 8 bit per channel in color and grayscale mode */
1353 case PIXMA_SCAN_MODE_GRAY:
1354 sp->channels = 1;
1355 /* fall through */
1356 case PIXMA_SCAN_MODE_COLOR:
1357 sp->depth = 8;
1358 break;
1359 /* extended scan modes for 48 bit flatbed scanners
1360 * 16 bit per channel in color and grayscale mode */
1361 case PIXMA_SCAN_MODE_GRAY_16:
1362 sp->channels = 1;
1363 sp->depth = 16;
1364 break;
1365 case PIXMA_SCAN_MODE_COLOR_48:
1366 sp->channels = 3;
1367 sp->depth = 16;
1368 break;
1369 /* software lineart
1370 * 1 bit per channel */
1371 case PIXMA_SCAN_MODE_LINEART:
1372 sp->software_lineart = 1;
1373 sp->channels = 1;
1374 sp->depth = 1;
1375 break;
1376 default:
1377 break;
1378 }
1379
1380 /* for software lineart w must be a multiple of 8 */
1381 if (sp->software_lineart == 1 && sp->w % 8)
1382 {
1383 unsigned w_max;
1384
1385 sp->w += 8 - (sp->w % 8);
1386
1387 /* do not exceed the scanner capability */
1388 w_max = s->cfg->width * s->cfg->xdpi / 75;
1389 w_max -= w_max % 8;
1390 if (sp->w > w_max)
1391 sp->w = w_max;
1392 }
1393
1394 if (mp->generation >= 2)
1395 {
1396 /* mod 32 and expansion of the X scan limits */
1397 /*PDBG (pixma_dbg (4, "*mp150_check_param***** ----- Initially: x=%i, y=%i, w=%i, h=%i *****\n", sp->x, sp->y, sp->w, sp->h));*/
1398 sp->xs = (sp->x * mp->scale) % 32;
1399 }
1400 else
1401 sp->xs = 0;
1402 /*PDBG (pixma_dbg (4, "*mp150_check_param***** Selected origin, origin shift: %i, %i *****\n", sp->x, sp->xs));*/
1403 sp->wx = calc_raw_width (mp, sp);
1404 sp->line_size = sp->w * sp->channels * (((sp->software_lineart) ? 8 : sp->depth) / 8); /* bytes per line per color after cropping */
1405 /*PDBG (pixma_dbg (4, "*mp150_check_param***** Final scan width and line-size: %i, %li *****\n", sp->wx, sp->line_size));*/
1406
1407 /* Some exceptions here for particular devices */
1408 /* Those devices can scan up to legal 14" with ADF, but A4 11.7" in flatbed */
1409 /* PIXMA_CAP_ADF also works for PIXMA_CAP_ADFDUP */
1410 if ((s->cfg->cap & PIXMA_CAP_ADF) && sp->source == PIXMA_SOURCE_FLATBED)
1411 sp->h = MIN (sp->h, 877 * sp->xdpi / 75);
1412
1413 if (sp->source == PIXMA_SOURCE_ADF || sp->source == PIXMA_SOURCE_ADFDUP)
1414 {
1415 uint8_t k = 1;
1416
1417 /* ADF/ADF duplex mode: max scan res is 600 dpi, at least for generation 4+ */
1418 if (mp->generation >= 4)
1419 k = sp->xdpi / MIN (sp->xdpi, 600);
1420 sp->x /= k;
1421 sp->xs /= k;
1422 sp->y /= k;
1423 sp->w /= k;
1424 sp->wx /= k;
1425 sp->h /= k;
1426 sp->xdpi /= k;
1427 sp->ydpi = sp->xdpi;
1428 }
1429
1430 sp->mode_jpeg = (s->cfg->cap & PIXMA_CAP_ADF_JPEG) &&
1431 (sp->source == PIXMA_SOURCE_ADF ||
1432 sp->source == PIXMA_SOURCE_ADFDUP);
1433
1434 mp->scale = 1;
1435 if (s->cfg->min_xdpi && sp->xdpi < s->cfg->min_xdpi)
1436 {
1437 mp->scale = s->cfg->min_xdpi / sp->xdpi;
1438 }
1439 /*PDBG (pixma_dbg (4, "*mp150_check_param***** xdpi=%u, min_xdpi=%u, scale=%u *****\n",
1440 sp->xdpi, s->cfg->min_xdpi, mp->scale));*/
1441
1442 /*PDBG (pixma_dbg (4, "*mp150_check_param***** Finally: channels=%u, depth=%u, x=%u, y=%u, w=%u, h=%u, xs=%u, wx=%u *****\n",
1443 sp->channels, sp->depth, sp->x, sp->y, sp->w, sp->h, sp->xs, sp->wx));*/
1444 return 0;
1445 }
1446
1447 static int
mp150_scan(pixma_t * s)1448 mp150_scan (pixma_t * s)
1449 {
1450 int error = 0, tmo;
1451 mp150_t *mp = (mp150_t *) s->subdriver;
1452
1453 if (mp->state != state_idle)
1454 return PIXMA_EBUSY;
1455
1456 /* no paper inserted after first adf page => abort session */
1457 if (s->param->adf_pageid && is_scanning_from_adf(s) && mp->adf_state == state_idle)
1458 {
1459 return PIXMA_ENO_PAPER;
1460 }
1461
1462 /* Generation 4+: send XML dialog */
1463 /* adf: first page or idle */
1464 if (mp->generation >= 4 && mp->adf_state == state_idle)
1465 {
1466 if (!send_xml_dialog (s, XML_START_1))
1467 return PIXMA_EPROTO;
1468 if (!send_xml_dialog (s, XML_START_2))
1469 return PIXMA_EPROTO;
1470 }
1471
1472 /* clear interrupt packets buffer */
1473 while (handle_interrupt (s, 0) > 0)
1474 {
1475 }
1476
1477 /* FIXME: Duplex ADF: check paper status only before odd pages (1,3,5,...). */
1478 if (is_scanning_from_adf (s))
1479 {
1480 if ((error = query_status (s)) < 0)
1481 return error;
1482
1483 /* wait for inserted paper
1484 * timeout: 10 sec */
1485 tmo = 10;
1486 while (!has_paper (s) && --tmo >= 0)
1487 {
1488 if ((error = query_status (s)) < 0)
1489 return error;
1490 WAIT_INTERRUPT (1000);
1491 PDBG (pixma_dbg
1492 (2, "No paper in ADF. Timed out in %d sec.\n", tmo));
1493 }
1494
1495 /* no paper inserted
1496 * => abort session */
1497 if (!has_paper (s))
1498 {
1499 PDBG (pixma_dbg (4, "*mp150_scan***** no paper in ADF *****\n"));
1500 error = abort_session (s);
1501 if (error < 0)
1502 return error;
1503
1504 /* Generation 4+: send XML dialog */
1505 /* adf: first page or idle */
1506 if (mp->generation >= 4 && mp->adf_state == state_idle)
1507 {
1508 if (!send_xml_dialog (s, XML_END))
1509 return PIXMA_EPROTO;
1510 }
1511
1512 return PIXMA_ENO_PAPER;
1513 }
1514 }
1515
1516 tmo = 10;
1517 /* adf: first page or idle */
1518 if (mp->generation <= 2 || mp->adf_state == state_idle)
1519 { /* single sheet or first sheet from ADF */
1520 PDBG (pixma_dbg (4, "*mp150_scan***** start scanning *****\n"));
1521 error = start_session (s);
1522 while (error == PIXMA_EBUSY && --tmo >= 0)
1523 {
1524 if (s->cancel)
1525 {
1526 error = PIXMA_ECANCELED;
1527 break;
1528 }
1529 PDBG (pixma_dbg
1530 (2, "Scanner is busy. Timed out in %d sec.\n", tmo + 1));
1531 pixma_sleep (1000000);
1532 error = start_session (s);
1533 }
1534 if (error == PIXMA_EBUSY || error == PIXMA_ETIMEDOUT)
1535 {
1536 /* The scanner maybe hangs. We try to empty output buffer of the
1537 * scanner and issue the cancel command. */
1538 PDBG (pixma_dbg (2, "Scanner hangs? Sending abort_session command.\n"));
1539 drain_bulk_in (s);
1540 abort_session (s);
1541 pixma_sleep (500000);
1542 error = start_session (s);
1543 }
1544 if ((error >= 0) || (mp->generation >= 3))
1545 mp->state = state_warmup;
1546 if ((error >= 0) && (mp->generation <= 2))
1547 error = select_source (s);
1548 if ((error >= 0) && !is_scanning_jpeg (s))
1549 {
1550 int i;
1551
1552 for (i = (mp->generation >= 3) ? 3 : 1 ; i > 0 && error >= 0; i--)
1553 error = send_gamma_table (s);
1554 }
1555 }
1556 else /* ADF pageid != 0 and gen3 or above */
1557 { /* next sheet from ADF */
1558 PDBG (pixma_dbg (4, "*mp150_scan***** scan next sheet from ADF *****\n"));
1559 pixma_sleep (1000000);
1560 }
1561 if ((error >= 0) || (mp->generation >= 3))
1562 mp->state = state_warmup;
1563 if (error >= 0)
1564 error = send_scan_param (s);
1565 if ((error >= 0) && (mp->generation >= 3))
1566 error = start_scan_3 (s);
1567 if (error < 0)
1568 {
1569 mp->last_block = 0x38; /* Force abort session if ADF scan */
1570 mp150_finish_scan (s);
1571 return error;
1572 }
1573
1574 /* ADF scanning active */
1575 if (is_scanning_from_adf (s))
1576 mp->adf_state = state_scanning;
1577 return 0;
1578 }
1579
1580 static int
mp150_fill_buffer(pixma_t * s,pixma_imagebuf_t * ib)1581 mp150_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib)
1582 {
1583 int error;
1584 mp150_t *mp = (mp150_t *) s->subdriver;
1585 unsigned block_size, bytes_received, proc_buf_size, line_size;
1586 uint8_t header[16];
1587
1588 if (mp->state == state_warmup)
1589 {
1590 RET_IF_ERR (wait_until_ready (s));
1591 pixma_sleep (1000000); /* No need to sleep, actually, but Window's driver
1592 * sleep 1.5 sec. */
1593 mp->state = state_scanning;
1594 mp->last_block = 0;
1595
1596 line_size = get_cis_line_size (s);
1597 proc_buf_size = 2 * line_size;
1598 mp->cb.buf = realloc (mp->cb.buf,
1599 CMDBUF_SIZE + IMAGE_BLOCK_SIZE + proc_buf_size);
1600 if (!mp->cb.buf)
1601 return PIXMA_ENOMEM;
1602 mp->linebuf = mp->cb.buf + CMDBUF_SIZE;
1603 mp->imgbuf = mp->data_left_ofs = mp->linebuf + line_size;
1604 mp->data_left_len = 0;
1605 }
1606
1607 do
1608 {
1609 if (s->cancel)
1610 {
1611 PDBG (pixma_dbg (4, "*mp150_fill_buffer***** s->cancel *****\n"));
1612 return PIXMA_ECANCELED;
1613 }
1614 if ((mp->last_block & 0x28) == 0x28)
1615 { /* end of image */
1616 PDBG (pixma_dbg (4, "*mp150_fill_buffer***** end of image *****\n"));
1617 mp->state = state_finished;
1618 return 0;
1619 }
1620 /*PDBG (pixma_dbg (4, "*mp150_fill_buffer***** moving %u bytes into buffer *****\n", mp->data_left_len));*/
1621 memmove (mp->imgbuf, mp->data_left_ofs, mp->data_left_len);
1622 error = read_image_block (s, header, mp->imgbuf + mp->data_left_len);
1623 if (error < 0)
1624 {
1625 PDBG (pixma_dbg (4, "*mp150_fill_buffer***** scanner error (%d): end scan *****\n", error));
1626 mp->last_block = 0x38; /* end scan in mp150_finish_scan() */
1627 if (error == PIXMA_ECANCELED)
1628 {
1629 /* NOTE: I see this in traffic logs but I don't know its meaning. */
1630 read_error_info (s, NULL, 0);
1631 }
1632 return error;
1633 }
1634
1635 bytes_received = error;
1636 /*PDBG (pixma_dbg (4, "*mp150_fill_buffer***** %u bytes received by read_image_block *****\n", bytes_received));*/
1637 block_size = pixma_get_be32 (header + 12);
1638 mp->last_block = header[8] & 0x38;
1639 if ((header[8] & ~0x38) != 0)
1640 {
1641 PDBG (pixma_dbg (1, "WARNING: Unexpected result header\n"));
1642 PDBG (pixma_hexdump (1, header, 16));
1643 }
1644 PASSERT (bytes_received == block_size);
1645
1646 if (block_size == 0)
1647 { /* no image data at this moment. */
1648 pixma_sleep (10000);
1649 }
1650 /* Post-process the image data */
1651 mp->data_left_ofs = mp->imgbuf + mp->data_left_len + bytes_received;
1652 mp->data_left_len = post_process_image_data (s, ib);
1653 mp->data_left_ofs -= mp->data_left_len;
1654 }
1655 while (ib->rend == ib->rptr);
1656
1657 return ib->rend - ib->rptr;
1658 }
1659
1660 static void
mp150_finish_scan(pixma_t * s)1661 mp150_finish_scan (pixma_t * s)
1662 {
1663 int error;
1664 mp150_t *mp = (mp150_t *) s->subdriver;
1665
1666 switch (mp->state)
1667 {
1668 case state_transfering:
1669 drain_bulk_in (s);
1670 /* fall through */
1671 case state_scanning:
1672 case state_warmup:
1673 case state_finished:
1674 /* FIXME: to process several pages ADF scan, must not send
1675 * abort_session and start_session between pages (last_block=0x28) */
1676 if (mp->generation <= 2 || !is_scanning_from_adf (s) || mp->last_block == 0x38)
1677 {
1678 PDBG (pixma_dbg (4, "*mp150_finish_scan***** abort session *****\n"));
1679 error = abort_session (s); /* FIXME: it probably doesn't work in duplex mode! */
1680 if (error < 0)
1681 PDBG (pixma_dbg (1, "WARNING:abort_session() failed %d\n", error));
1682
1683 /* Generation 4+: send XML end of scan dialog */
1684 if (mp->generation >= 4)
1685 {
1686 if (!send_xml_dialog (s, XML_END))
1687 PDBG (pixma_dbg (1, "WARNING:XML_END dialog failed \n"));
1688 }
1689 }
1690 else
1691 PDBG (pixma_dbg (4, "*mp150_finish_scan***** wait for next page from ADF *****\n"));
1692
1693 mp->state = state_idle;
1694 /* fall through */
1695 case state_idle:
1696 break;
1697 }
1698 }
1699
1700 static void
mp150_wait_event(pixma_t * s,int timeout)1701 mp150_wait_event (pixma_t * s, int timeout)
1702 {
1703 /* FIXME: timeout is not correct. See usbGetCompleteUrbNoIntr() for
1704 * instance. */
1705 while (s->events == 0 && handle_interrupt (s, timeout) > 0)
1706 {
1707 }
1708 }
1709
1710 static int
mp150_get_status(pixma_t * s,pixma_device_status_t * status)1711 mp150_get_status (pixma_t * s, pixma_device_status_t * status)
1712 {
1713 int error;
1714
1715 RET_IF_ERR (query_status (s));
1716 status->hardware = PIXMA_HARDWARE_OK;
1717 status->adf = (has_paper (s)) ? PIXMA_ADF_OK : PIXMA_ADF_NO_PAPER;
1718 status->cal =
1719 (is_calibrated (s)) ? PIXMA_CALIBRATION_OK : PIXMA_CALIBRATION_OFF;
1720 return 0;
1721 }
1722
1723 static const pixma_scan_ops_t pixma_mp150_ops = {
1724 mp150_open,
1725 mp150_close,
1726 mp150_scan,
1727 mp150_fill_buffer,
1728 mp150_finish_scan,
1729 mp150_wait_event,
1730 mp150_check_param,
1731 mp150_get_status
1732 };
1733
1734 #define DEVICE(name, model, pid, min_dpi, dpi, adftpu_min_dpi, adftpu_max_dpi, w, h, cap) { \
1735 name, /* name */ \
1736 model, /* model */ \
1737 CANON_VID, pid, /* vid pid */ \
1738 0, /* iface */ \
1739 &pixma_mp150_ops, /* ops */ \
1740 min_dpi, /* min_xdpi */ \
1741 0, /* min_xdpi_16 not used in this subdriver */ \
1742 dpi, 2*(dpi), /* xdpi, ydpi */ \
1743 adftpu_min_dpi, adftpu_max_dpi, /* adftpu_min_dpi, adftpu_max_dpi */ \
1744 0, 0, /* tpuir_min_dpi & tpuir_max_dpi not used in this subdriver */ \
1745 w, h, /* width, height */ \
1746 PIXMA_CAP_EASY_RGB| \
1747 PIXMA_CAP_GRAY| /* CIS with native grayscale */ \
1748 PIXMA_CAP_LINEART| /* all scanners with software lineart */ \
1749 PIXMA_CAP_GAMMA_TABLE|PIXMA_CAP_EVENTS|cap \
1750 }
1751
1752 #define END_OF_DEVICE_LIST DEVICE(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0)
1753
1754 const pixma_config_t pixma_mp150_devices[] = {
1755 /* Generation 1: CIS */
1756 DEVICE ("Canon PIXMA MP150", "MP150", MP150_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096),
1757 DEVICE ("Canon PIXMA MP170", "MP170", MP170_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096),
1758 DEVICE ("Canon PIXMA MP450", "MP450", MP450_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096),
1759 DEVICE ("Canon PIXMA MP500", "MP500", MP500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096),
1760 DEVICE ("Canon PIXMA MP530", "MP530", MP530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096 | PIXMA_CAP_ADF),
1761
1762 /* Generation 2: CIS */
1763 DEVICE ("Canon PIXMA MP140", "MP140", MP140_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1764 DEVICE ("Canon PIXMA MP160", "MP160", MP160_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1765 DEVICE ("Canon PIXMA MP180", "MP180", MP180_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1766 DEVICE ("Canon PIXMA MP460", "MP460", MP460_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1767 DEVICE ("Canon PIXMA MP510", "MP510", MP510_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1768 DEVICE ("Canon PIXMA MP600", "MP600", MP600_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1769 DEVICE ("Canon PIXMA MP600R", "MP600R", MP600R_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1770
1771 /* Generation 3: CIS */
1772 DEVICE ("Canon PIXMA MP210", "MP210", MP210_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1773 DEVICE ("Canon PIXMA MP220", "MP220", MP220_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1774 DEVICE ("Canon PIXMA MP470", "MP470", MP470_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1775 DEVICE ("Canon PIXMA MP520", "MP520", MP520_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1776 DEVICE ("Canon PIXMA MP610", "MP610", MP610_PID, 0, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS),
1777
1778 DEVICE ("Canon PIXMA MX300", "MX300", MX300_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1779 DEVICE ("Canon PIXMA MX310", "MX310", MX310_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1780 DEVICE ("Canon PIXMA MX700", "MX700", MX700_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1781 DEVICE ("Canon PIXMA MX850", "MX850", MX850_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1782 DEVICE ("Canon PIXMA MX7600", "MX7600", MX7600_PID, 0, 4800, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1783
1784 DEVICE ("Canon PIXMA MP630", "MP630", MP630_PID, 0, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS),
1785 DEVICE ("Canon PIXMA MP620", "MP620", MP620_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1786 DEVICE ("Canon PIXMA MP540", "MP540", MP540_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1787 DEVICE ("Canon PIXMA MP480", "MP480", MP480_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1788 DEVICE ("Canon PIXMA MP240", "MP240", MP240_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1789 DEVICE ("Canon PIXMA MP260", "MP260", MP260_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1790 DEVICE ("Canon PIXMA MP190", "MP190", MP190_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1791
1792 /* PIXMA 2009 vintage */
1793 DEVICE ("Canon PIXMA MX320", "MX320", MX320_PID, 0, 1200, 0, 600, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1794 DEVICE ("Canon PIXMA MX330", "MX330", MX330_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1795 DEVICE ("Canon PIXMA MX860", "MX860", MX860_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1796 /* width and height adjusted to flatbed size 21.8 x 30.2 cm^2 respective
1797 * Not sure if anything's going wrong here, leaving as is
1798 DEVICE ("Canon PIXMA MX860", "MX860", MX860_PID, 0, 2400, 0, 0, 638, 880, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),*/
1799
1800 /* PIXMA 2010 vintage */
1801 DEVICE ("Canon PIXMA MX340", "MX340", MX340_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1802 DEVICE ("Canon PIXMA MX350", "MX350", MX350_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1803 DEVICE ("Canon PIXMA MX870", "MX870", MX870_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1804
1805 /* PIXMA 2011 vintage */
1806 DEVICE ("Canon PIXMA MX360", "MX360", MX360_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1807 DEVICE ("Canon PIXMA MX410", "MX410", MX410_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1808 DEVICE ("Canon PIXMA MX420", "MX420", MX420_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1809 DEVICE ("Canon PIXMA MX880 Series", "MX880", MX880_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1810
1811 /* Generation 4: CIS */
1812 DEVICE ("Canon PIXMA MP640", "MP640", MP640_PID, 0, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS),
1813 DEVICE ("Canon PIXMA MP560", "MP560", MP560_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1814 DEVICE ("Canon PIXMA MP550", "MP550", MP550_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1815 DEVICE ("Canon PIXMA MP490", "MP490", MP490_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1816 DEVICE ("Canon PIXMA MP250", "MP250", MP250_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1817 DEVICE ("Canon PIXMA MP270", "MP270", MP270_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1818
1819 /* Latest devices (2010) Generation 4 CIS */
1820 DEVICE ("Canon PIXMA MP280", "MP280", MP280_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), /* TODO: 1200dpi doesn't work yet */
1821 DEVICE ("Canon PIXMA MP495", "MP495", MP495_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), /* ToDo: max. scan resolution = 1200x600dpi */
1822 DEVICE ("Canon PIXMA MG5100", "MG5100", MG5100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1823 DEVICE ("Canon PIXMA MG5200", "MG5200", MG5200_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1824 DEVICE ("Canon PIXMA MG6100", "MG6100", MG6100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1825
1826 /* Latest devices (2011) Generation 5 CIS */
1827 DEVICE ("Canon PIXMA MG2100", "MG2100", MG2100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1828 DEVICE ("Canon PIXMA MG3100", "MG3100", MG3100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1829 DEVICE ("Canon PIXMA MG4100", "MG4100", MG4100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1830 DEVICE ("Canon PIXMA MG5300", "MG5300", MG5300_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1831 DEVICE ("Canon PIXMA MG6200", "MG6200", MG6200_PID, 0, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS),
1832 DEVICE ("Canon PIXMA MP493", "MP493", MP493_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1833 DEVICE ("Canon PIXMA E500", "E500", E500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1834
1835 /* Latest devices (2012) Generation 5 CIS */
1836 DEVICE ("Canon PIXMA MX370 Series", "MX370", MX370_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1837 DEVICE ("Canon PIXMA MX430 Series", "MX430", MX430_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1838 DEVICE ("Canon PIXMA MX510 Series", "MX510", MX510_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1839 DEVICE ("Canon PIXMA MX710 Series", "MX710", MX710_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1840 DEVICE ("Canon PIXMA MX890 Series", "MX890", MX890_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1841 DEVICE ("Canon PIXMA E600 Series", "E600", E600_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1842 DEVICE ("Canon PIXMA MG4200", "MG4200", MG4200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1843
1844 /* Latest devices (2013) Generation 5 CIS */
1845 DEVICE ("Canon PIXMA E510", "E510", E510_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1846 DEVICE ("Canon PIXMA E610", "E610", E610_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1847 DEVICE ("Canon PIXMA MP230", "MP230", MP230_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1848 DEVICE ("Canon PIXMA MG2200 Series", "MG2200", MG2200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1849 DEVICE ("Canon PIXMA MG3200 Series", "MG3200", MG3200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1850 DEVICE ("Canon PIXMA MG5400 Series", "MG5400", MG5400_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1851 DEVICE ("Canon PIXMA MG6300 Series", "MG6300", MG6300_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1852 DEVICE ("Canon PIXMA MX390 Series", "MX390", MX390_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1853 DEVICE ("Canon PIXMA MX450 Series", "MX450", MX450_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1854 DEVICE ("Canon PIXMA MX520 Series", "MX520", MX520_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1855 DEVICE ("Canon PIXMA MX720 Series", "MX720", MX720_PID, 0, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1856 DEVICE ("Canon PIXMA MX920 Series", "MX920", MX920_PID, 0, 2400, 0, 600, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1857 DEVICE ("Canon PIXMA MG2400 Series", "MG2400", MG2400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1858 DEVICE ("Canon PIXMA MG2500 Series", "MG2500", MG2500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1859 DEVICE ("Canon PIXMA MG3500 Series", "MG3500", MG3500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1860 DEVICE ("Canon PIXMA MG5500 Series", "MG5500", MG5500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1861 DEVICE ("Canon PIXMA MG6400 Series", "MG6400", MG6400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1862 DEVICE ("Canon PIXMA MG6500 Series", "MG6500", MG6500_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1863 DEVICE ("Canon PIXMA MG7100 Series", "MG7100", MG7100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1864
1865 /* Latest devices (2014) Generation 5 CIS */
1866 DEVICE ("Canon PIXMA MX470 Series", "MX470", MX470_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1867 DEVICE ("Canon PIXMA MX530 Series", "MX530", MX530_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1868 DEVICE ("Canon MAXIFY MB5000 Series", "MB5000", MB5000_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1869 DEVICE ("Canon MAXIFY MB5300 Series", "MB5300", MB5300_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP),
1870 DEVICE ("Canon MAXIFY MB2000 Series", "MB2000", MB2000_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP | PIXMA_CAP_ADF_JPEG),
1871 DEVICE ("Canon MAXIFY MB2100 Series", "MB2100", MB2100_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1872 DEVICE ("Canon MAXIFY MB2300 Series", "MB2300", MB2300_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1873 DEVICE ("Canon MAXIFY MB2700 Series", "MB2700", MB2700_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1874 DEVICE ("Canon PIXMA E400", "E400", E400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1875 DEVICE ("Canon PIXMA E560", "E560", E560_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1876 DEVICE ("Canon PIXMA MG7500 Series", "MG7500", MG7500_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1877 DEVICE ("Canon PIXMA MG6600 Series", "MG6600", MG6600_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1878 DEVICE ("Canon PIXMA MG5600 Series", "MG5600", MG5600_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1879 DEVICE ("Canon PIXMA MG2900 Series", "MG2900", MG2900_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1880 DEVICE ("Canon PIXMA E460 Series", "E460", E460_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1881
1882 /* Latest devices (2015) Generation 5 CIS */
1883 DEVICE ("Canon PIXMA MX490 Series", "MX490", MX490_PID, 0, 600, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1884 DEVICE ("Canon PIXMA E480 Series", "E480", E480_PID, 0, 600, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1885 DEVICE ("Canon PIXMA MG3600 Series", "MG3600", MG3600_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1886 DEVICE ("Canon PIXMA MG7700 Series", "MG7700", MG7700_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1887 DEVICE ("Canon PIXMA MG6900 Series", "MG6900", MG6900_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1888 DEVICE ("Canon PIXMA MG6800 Series", "MG6800", MG6800_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1889 DEVICE ("Canon PIXMA MG5700 Series", "MG5700", MG5700_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1890
1891 /* Latest devices (2016) Generation 5 CIS */
1892 DEVICE ("Canon PIXMA G3000", "G3000", G3000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1893 DEVICE ("Canon PIXMA G2000", "G2000", G2000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1894 DEVICE ("Canon PIXMA TS9000 Series", "TS9000", TS9000_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1895 DEVICE ("Canon PIXMA TS8000 Series", "TS8000", TS8000_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1896 DEVICE ("Canon PIXMA TS6000 Series", "TS6000", TS6000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1897 DEVICE ("Canon PIXMA TS5000 Series", "TS5000", TS5000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1898 DEVICE ("Canon PIXMA MG3000 Series", "MG3000", MG3000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1899 DEVICE ("Canon PIXMA E470 Series", "E470", E470_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1900 DEVICE ("Canon PIXMA E410 Series", "E410", E410_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1901
1902 /* Latest devices (2017) Generation 5 CIS */
1903 DEVICE ("Canon PIXMA G4000", "G4000", G4000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1904 DEVICE ("Canon PIXMA TS6100 Series", "TS6100", TS6100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1905 DEVICE ("Canon PIXMA TS5100 Series", "TS5100", TS5100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1906 DEVICE ("Canon PIXMA TS3100 Series", "TS3100", TS3100_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1907 DEVICE ("Canon PIXMA E3100 Series", "E3100", E3100_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1908
1909 /* Latest devices (2018) Generation 5 CIS */
1910 DEVICE ("Canon MAXIFY MB5400 Series", "MB5400", MB5400_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP | PIXMA_CAP_ADF_JPEG),
1911 DEVICE ("Canon MAXIFY MB5100 Series", "MB5100", MB5100_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP | PIXMA_CAP_ADF_JPEG),
1912 DEVICE ("Canon PIXMA TS9100 Series", "TS9100", TS9100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1913 DEVICE ("Canon PIXMA TR8500 Series", "TR8500", TR8500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1914 DEVICE ("Canon PIXMA TR7500 Series", "TR7500", TR7500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1915 DEVICE ("Canon PIXMA TS9500 Series", "TS9500", TS9500_PID, 0, 1200, 0, 600, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1916 DEVICE ("CanoScan LiDE 400", "LIDE400", LIDE400_PID, 300, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_48BIT),
1917 DEVICE ("CanoScan LiDE 300", "LIDE300", LIDE300_PID, 300, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1918
1919 /* Latest devices (2019) Generation 5 CIS */
1920 DEVICE ("Canon PIXMA TS8100 Series", "TS8100", TS8100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1921 DEVICE ("Canon PIXMA G2010 Series", "G2010", G2010_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1922 DEVICE ("Canon PIXMA G3010 Series", "G3010", G3010_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1923 DEVICE ("Canon PIXMA G4010 Series", "G4010", G4010_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1924 DEVICE ("Canon PIXMA TS9180 Series", "TS9180", TS9180_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1925 DEVICE ("Canon PIXMA TS8180 Series", "TS8180", TS8180_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1926 DEVICE ("Canon PIXMA TS6180 Series", "TS6180", TS6180_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1927 DEVICE ("Canon PIXMA TR8580 Series", "TR8580", TR8580_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1928 DEVICE ("Canon PIXMA TS8130 Series", "TS8130", TS8130_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS),
1929 DEVICE ("Canon PIXMA TS6130 Series", "TS6130", TS6130_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1930 DEVICE ("Canon PIXMA TR8530 Series", "TR8530", TR8530_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1931 DEVICE ("Canon PIXMA TR7530 Series", "TR7530", TR7530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1932 DEVICE ("Canon PIXUS XK50 Series", "XK50", XK50_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1933 DEVICE ("Canon PIXUS XK70 Series", "XK70", XK70_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1934 DEVICE ("Canon PIXMA TR4500 Series", "TR4500", TR4500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG), /* ToDo: max. scan resolution = 600x1200dpi */
1935 DEVICE ("Canon PIXMA E4200 Series", "E4200", E4200_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1936 DEVICE ("Canon PIXMA TS6200 Series", "TS6200", TS6200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1937 DEVICE ("Canon PIXMA TS6280 Series", "TS6280", TS6280_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1938 DEVICE ("Canon PIXMA TS6230 Series", "TS6230", TS6230_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1939 DEVICE ("Canon PIXMA TS8200 Series", "TS8200", TS8200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1940 DEVICE ("Canon PIXMA TS8280 Series", "TS8280", TS8280_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1941 DEVICE ("Canon PIXMA TS8230 Series", "TS8230", TS8230_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1942 DEVICE ("Canon PIXMA TS9580 Series", "TS9580", TS9580_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1943 DEVICE ("Canon PIXMA TR9530 Series", "TR9530", TR9530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1944 DEVICE ("Canon PIXMA G7000 Series", "G7000", G7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), /* ToDo: ADF has legal paper length */
1945 DEVICE ("Canon PIXMA G6000 Series", "G6000", G6000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1946 DEVICE ("Canon PIXMA G6080 Series", "G6080", G6080_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1947 DEVICE ("Canon PIXMA GM4000 Series", "GM4000", GM4000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), /* ToDo: ADF has legal paper length */
1948 DEVICE ("Canon PIXUS XK80 Series", "XK80", XK80_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1949 DEVICE ("Canon PIXMA TS5300 Series", "TS5300", TS5300_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1950 DEVICE ("Canon PIXMA TS5380 Series", "TS5380", TS5380_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1951 DEVICE ("Canon PIXMA TS6300 Series", "TS6300", TS6300_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1952 DEVICE ("Canon PIXMA TS6380 Series", "TS6380", TS6380_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1953 DEVICE ("Canon PIXMA TS7330 Series", "TS7330", TS7330_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1954 DEVICE ("Canon PIXMA TS8380 Series", "TS8380", TS8380_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1955 DEVICE ("Canon PIXMA TS8330 Series", "TS8330", TS8330_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1956 DEVICE ("Canon PIXMA XK60 Series", "XK60", XK60_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1957 DEVICE ("Canon PIXMA TS6330 Series", "TS6330", TS6330_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1958 DEVICE ("Canon PIXMA TS3300 Series", "TS3300", TS3300_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1959 DEVICE ("Canon PIXMA E3300 Series", "E3300", E3300_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1960 DEVICE ("Canon PIXMA TS3400 Series", "TS3400", TS3400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1961 DEVICE ("Canon PIXMA E3400 Series", "E3400", E3400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1962 DEVICE ("Canon PIXMA TR7000 Series", "TR7000", TR7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1963 DEVICE ("Canon PIXMA G2020", "G2020", G2020_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1964 DEVICE ("Canon PIXMA G3060", "G3060", G3060_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1965 DEVICE ("Canon PIXMA G2060", "G2060", G2060_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1966 DEVICE ("Canon PIXMA G3020", "G3020", G3020_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1967 DEVICE ("Canon PIXMA TS7430 Series", "TS7430", TS7430_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1968 DEVICE ("Canon PIXUS XK90 Series", "XK90", XK90_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1969 DEVICE ("Canon PIXMA TS8430 Series", "TS8430", TS8430_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1970 DEVICE ("Canon PIXMA TR7600 Series", "TR7600", TR7600_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1971 DEVICE ("Canon PIXMA TR8600 Series", "TR8600", TR8600_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1972 DEVICE ("Canon PIXMA TR8630 Series", "TR8630", TR8630_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1973 DEVICE ("Canon PIXMA TS6400 Series", "TS6400", TS6400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1974 DEVICE ("Canon PIXMA TS7400 Series", "TS7400", TS7400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1975 DEVICE ("Canon PIXMA G7080 Series", "G7080", G7080_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1976 DEVICE ("Canon PIXMA GM4080", "GM4080", GM4080_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1977 DEVICE ("Canon PIXMA TS5350i Series", "TS5350i", TS5350i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1978 DEVICE ("Canon PIXMA G600", "G600", G600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1979 DEVICE ("Canon PIXMA TS3500 Series", "TS3500", TS3500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1980 /* ToDo: max. scan resolution = 600x1200dpi */
1981 DEVICE ("Canon PIXMA TR4600 Series", "TR4600", TR4600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1982 /* ToDo: max. scan resolution = 600x1200dpi */
1983 DEVICE ("Canon PIXMA TR4700 Series", "TR4700", TR4700_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
1984 DEVICE ("Canon PIXMA E4500 Series", "E4500", E4500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1985 DEVICE ("Canon PIXUS XK500 Series", "XK500", XK500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1986 DEVICE ("Canon PIXMA TS8530 Series", "TS8530", TS8530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1987 DEVICE ("Canon PIXUS XK100 Series", "XK100", XK100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1988 DEVICE ("Canon PIXMA TS7530 Series", "TS7530", TS7530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1989 DEVICE ("Canon PIXMA TS7450i Series", "TS7450i", TS7450i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1990 DEVICE ("Canon PIXMA GX6000 Series", "GX6000", GX6000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1991 DEVICE ("Canon PIXMA GX7000 Series", "GX7000", GX7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1992 DEVICE ("Canon PIXMA TS5400 Series", "TS5400", TS5400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1993 DEVICE ("Canon PIXMA TS2400 Series", "TS2400", TS2400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1994 DEVICE ("Canon PIXMA TS2600 Series", "TS2600", TS2600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
1995 DEVICE ("Canon PIXMA TS8630 Series", "TS8630", TS8630_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1996 DEVICE ("Canon PIXUS XK110 Series", "XK110", XK110_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
1997 DEVICE ("Canon PIXMA GX3000 Series", "GX3000", GX3000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1998 DEVICE ("Canon PIXMA GX4000 Series", "GX4000", GX4000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
1999 DEVICE ("Canon PIXMA G3070", "G3070", G3070_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
2000 DEVICE ("Canon PIXMA G2070", "G2070", G2070_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
2001 DEVICE ("Canon PIXMA G4070", "G4070", G4070_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
2002 DEVICE ("Canon PIXMA G3030", "G3030", G3030_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
2003 DEVICE ("Canon PIXMA G2030", "G2030", G2030_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS),
2004 DEVICE ("Canon PIXMA TC-20M", "TC-20M", TC20M_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2005 DEVICE ("Canon PIXMA TC-5200M", "TC-5200M", TC5200M_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2006
2007 DEVICE ("Canon PIXMA TS8700 series", "TS8700", TS8700_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2008 DEVICE ("Canon PIXMA XK120 series", "XK120", XK120_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2009 DEVICE ("Canon PIXMA GX1000 series", "GX1000", GX1000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
2010 DEVICE ("Canon PIXMA GX2000 series", "GX2000", GX2000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
2011 DEVICE ("Canon PIXMA TS6630 series", "TS6630", TS6630_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2012 DEVICE ("Canon PIXMA TS7700 series", "TS7700", TS7700_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2013 DEVICE ("Canon PIXMA TS7600i series", "TS7600i", TS7600i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2014 DEVICE ("Canon PIXMA TS6730 series", "TS6730", TS6730_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2015 DEVICE ("Canon PIXMA TR7800 series", "TR7800", TR7800_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG),
2016 DEVICE ("Canon PIXMA TS7700i series", "TS7700i", TS7700i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2017 DEVICE ("Canon PIXMA TS7700A series", "TS7700A", TS7700A_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS),
2018 DEVICE ("Canon PIXMA GX6500 series", "GX6500", GX6500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF),
2019
2020 END_OF_DEVICE_LIST
2021 };
2022