aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/stradis.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/stradis.c')
-rw-r--r--drivers/media/video/stradis.c1138
1 files changed, 554 insertions, 584 deletions
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 6ee54a45411f..54fc33011ffb 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -49,9 +49,9 @@
49#include "saa7121.h" 49#include "saa7121.h"
50#include "cs8420.h" 50#include "cs8420.h"
51 51
52#define DEBUG(x) /* debug driver */ 52#define DEBUG(x) /* debug driver */
53#undef IDEBUG /* debug irq handler */ 53#undef IDEBUG /* debug irq handler */
54#undef MDEBUG /* debug memory management */ 54#undef MDEBUG /* debug memory management */
55 55
56#define SAA7146_MAX 6 56#define SAA7146_MAX 6
57 57
@@ -63,7 +63,6 @@ static int video_nr = -1;
63module_param(video_nr, int, 0); 63module_param(video_nr, int, 0);
64MODULE_LICENSE("GPL"); 64MODULE_LICENSE("GPL");
65 65
66
67#define nDebNormal 0x00480000 66#define nDebNormal 0x00480000
68#define nDebNoInc 0x00480000 67#define nDebNoInc 0x00480000
69#define nDebVideo 0xd0480000 68#define nDebVideo 0xd0480000
@@ -99,7 +98,12 @@ MODULE_LICENSE("GPL");
99 98
100#ifdef USE_RESCUE_EEPROM_SDM275 99#ifdef USE_RESCUE_EEPROM_SDM275
101static unsigned char rescue_eeprom[64] = { 100static unsigned char rescue_eeprom[64] = {
1020x00,0x01,0x04,0x13,0x26,0x0f,0x10,0x00,0x00,0x00,0x43,0x63,0x22,0x01,0x29,0x15,0x73,0x00,0x1f, 'd', 'e', 'c', 'x', 'l', 'd', 'v', 'a',0x02,0x00,0x01,0x00,0xcc,0xa4,0x63,0x09,0xe2,0x10,0x00,0x0a,0x00,0x02,0x02, 'd', 'e', 'c', 'x', 'l', 'a',0x00,0x00,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 101 0x00, 0x01, 0x04, 0x13, 0x26, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x43, 0x63,
102 0x22, 0x01, 0x29, 0x15, 0x73, 0x00, 0x1f, 'd', 'e', 'c', 'x', 'l',
103 'd', 'v', 'a', 0x02, 0x00, 0x01, 0x00, 0xcc, 0xa4, 0x63, 0x09, 0xe2,
104 0x10, 0x00, 0x0a, 0x00, 0x02, 0x02, 'd', 'e', 'c', 'x', 'l', 'a',
105 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00,
103}; 107};
104#endif 108#endif
105 109
@@ -140,17 +144,18 @@ static int I2CRead(struct saa7146 *saa, unsigned char addr,
140 144
141 if (saaread(SAA7146_I2C_STATUS) & 0x3c) 145 if (saaread(SAA7146_I2C_STATUS) & 0x3c)
142 I2CWipe(saa); 146 I2CWipe(saa);
143 for (i = 0; i < 1000 && 147 for (i = 0;
144 (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY); i++) 148 i < 1000 && (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY);
149 i++)
145 schedule(); 150 schedule();
146 if (i == 1000) 151 if (i == 1000)
147 I2CWipe(saa); 152 I2CWipe(saa);
148 if (dosub) 153 if (dosub)
149 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 8) | 154 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 8) |
150 ((subaddr & 0xff) << 16) | 0xed, SAA7146_I2C_TRANSFER); 155 ((subaddr & 0xff) << 16) | 0xed, SAA7146_I2C_TRANSFER);
151 else 156 else
152 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 16) | 157 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 16) |
153 0xf1, SAA7146_I2C_TRANSFER); 158 0xf1, SAA7146_I2C_TRANSFER);
154 saawrite((SAA7146_MC2_UPLD_I2C << 16) | 159 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
155 SAA7146_MC2_UPLD_I2C, SAA7146_MC2); 160 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
156 /* wait for i2c registers to be programmed */ 161 /* wait for i2c registers to be programmed */
@@ -163,7 +168,7 @@ static int I2CRead(struct saa7146 *saa, unsigned char addr,
163 schedule(); 168 schedule();
164 if (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_ERR) 169 if (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_ERR)
165 return -1; 170 return -1;
166 if (i == 1000) 171 if (i == 1000)
167 printk("i2c setup read timeout\n"); 172 printk("i2c setup read timeout\n");
168 saawrite(0x41, SAA7146_I2C_TRANSFER); 173 saawrite(0x41, SAA7146_I2C_TRANSFER);
169 saawrite((SAA7146_MC2_UPLD_I2C << 16) | 174 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
@@ -178,7 +183,7 @@ static int I2CRead(struct saa7146 *saa, unsigned char addr,
178 schedule(); 183 schedule();
179 if (saaread(SAA7146_I2C_TRANSFER) & SAA7146_I2C_ERR) 184 if (saaread(SAA7146_I2C_TRANSFER) & SAA7146_I2C_ERR)
180 return -1; 185 return -1;
181 if (i == 1000) 186 if (i == 1000)
182 printk("i2c read timeout\n"); 187 printk("i2c read timeout\n");
183 return ((saaread(SAA7146_I2C_TRANSFER) >> 24) & 0xff); 188 return ((saaread(SAA7146_I2C_TRANSFER) >> 24) & 0xff);
184} 189}
@@ -213,20 +218,22 @@ static void attach_inform(struct saa7146 *saa, int id)
213{ 218{
214 int i; 219 int i;
215 220
216 DEBUG(printk(KERN_DEBUG "stradis%d: i2c: device found=%02x\n", saa->nr, id)); 221 DEBUG(printk(KERN_DEBUG "stradis%d: i2c: device found=%02x\n", saa->nr,
217 if (id == 0xa0) { /* we have rev2 or later board, fill in info */ 222 id));
223 if (id == 0xa0) { /* we have rev2 or later board, fill in info */
218 for (i = 0; i < 64; i++) 224 for (i = 0; i < 64; i++)
219 saa->boardcfg[i] = I2CRead(saa, 0xa0, i, 1); 225 saa->boardcfg[i] = I2CRead(saa, 0xa0, i, 1);
220#ifdef USE_RESCUE_EEPROM_SDM275 226#ifdef USE_RESCUE_EEPROM_SDM275
221 if (saa->boardcfg[0] != 0) { 227 if (saa->boardcfg[0] != 0) {
222 printk("stradis%d: WARNING: EEPROM STORED VALUES HAVE BEEN IGNORED\n", saa->nr); 228 printk("stradis%d: WARNING: EEPROM STORED VALUES HAVE "
229 "BEEN IGNORED\n", saa->nr);
223 for (i = 0; i < 64; i++) 230 for (i = 0; i < 64; i++)
224 saa->boardcfg[i] = rescue_eeprom[i]; 231 saa->boardcfg[i] = rescue_eeprom[i];
225 } 232 }
226#endif 233#endif
227 printk("stradis%d: config =", saa->nr); 234 printk("stradis%d: config =", saa->nr);
228 for (i = 0; i < 51; i++) { 235 for (i = 0; i < 51; i++) {
229 printk(" %02x",saa->boardcfg[i]); 236 printk(" %02x", saa->boardcfg[i]);
230 } 237 }
231 printk("\n"); 238 printk("\n");
232 } 239 }
@@ -254,17 +261,19 @@ static int wait_for_debi_done(struct saa7146 *saa)
254 for (i = 0; i < 500000 && 261 for (i = 0; i < 500000 &&
255 (saaread(SAA7146_PSR) & SAA7146_PSR_DEBI_S); i++) 262 (saaread(SAA7146_PSR) & SAA7146_PSR_DEBI_S); i++)
256 saaread(SAA7146_MC2); 263 saaread(SAA7146_MC2);
264
257 if (i > debiwait_maxwait) 265 if (i > debiwait_maxwait)
258 printk("wait-for-debi-done maxwait: %d\n", 266 printk("wait-for-debi-done maxwait: %d\n",
259 debiwait_maxwait = i); 267 debiwait_maxwait = i);
260 268
261 if (i == 500000) 269 if (i == 500000)
262 return -1; 270 return -1;
271
263 return 0; 272 return 0;
264} 273}
265 274
266static int debiwrite(struct saa7146 *saa, u32 config, int addr, 275static int debiwrite(struct saa7146 *saa, u32 config, int addr,
267 u32 val, int count) 276 u32 val, int count)
268{ 277{
269 u32 cmd; 278 u32 cmd;
270 if (count <= 0 || count > 32764) 279 if (count <= 0 || count > 32764)
@@ -309,41 +318,6 @@ static u32 debiread(struct saa7146 *saa, u32 config, int addr, int count)
309 return result; 318 return result;
310} 319}
311 320
312#if 0 /* unused */
313/* MUST be a multiple of 8 bytes and 8-byte aligned and < 32768 bytes */
314/* data copied into saa->dmadebi buffer, caller must re-enable interrupts */
315static void ibm_block_dram_read(struct saa7146 *saa, int address, int bytes)
316{
317 int i, j;
318 u32 *buf;
319 buf = (u32 *) saa->dmadebi;
320 if (bytes > 0x7000)
321 bytes = 0x7000;
322 saawrite(0, SAA7146_IER); /* disable interrupts */
323 for (i=0; i < 10000 &&
324 (debiread(saa, debNormal, IBM_MP2_DRAM_CMD_STAT, 2)
325 & 0x8000); i++)
326 saaread(SAA7146_MC2);
327 if (i == 10000)
328 printk(KERN_ERR "stradis%d: dram_busy never cleared\n",
329 saa->nr);
330 debiwrite(saa, debNormal, IBM_MP2_SRC_ADDR, (address<<16) |
331 (address>>16), 4);
332 debiwrite(saa, debNormal, IBM_MP2_BLOCK_SIZE, bytes, 2);
333 debiwrite(saa, debNormal, IBM_MP2_CMD_STAT, 0x8a10, 2);
334 for (j = 0; j < bytes/4; j++) {
335 for (i = 0; i < 10000 &&
336 (!(debiread(saa, debNormal, IBM_MP2_DRAM_CMD_STAT, 2)
337 & 0x4000)); i++)
338 saaread(SAA7146_MC2);
339 if (i == 10000)
340 printk(KERN_ERR "stradis%d: dram_ready never set\n",
341 saa->nr);
342 buf[j] = debiread(saa, debNormal, IBM_MP2_DRAM_DATA, 4);
343 }
344}
345#endif /* unused */
346
347static void do_irq_send_data(struct saa7146 *saa) 321static void do_irq_send_data(struct saa7146 *saa)
348{ 322{
349 int split, audbytes, vidbytes; 323 int split, audbytes, vidbytes;
@@ -365,16 +339,15 @@ static void do_irq_send_data(struct saa7146 *saa)
365 return; 339 return;
366 } 340 }
367 /* if at least 1 block audio waiting and audio fifo isn't full */ 341 /* if at least 1 block audio waiting and audio fifo isn't full */
368 if (audbytes >= 2048 && (debiread(saa, debNormal, 342 if (audbytes >= 2048 && (debiread(saa, debNormal, IBM_MP2_AUD_FIFO, 2)
369 IBM_MP2_AUD_FIFO, 2) & 0xff) < 60) { 343 & 0xff) < 60) {
370 if (saa->audhead > saa->audtail) 344 if (saa->audhead > saa->audtail)
371 split = 65536 - saa->audhead; 345 split = 65536 - saa->audhead;
372 else 346 else
373 split = 0; 347 split = 0;
374 audbytes = 2048; 348 audbytes = 2048;
375 if (split > 0 && split < 2048) { 349 if (split > 0 && split < 2048) {
376 memcpy(saa->dmadebi, saa->audbuf + saa->audhead, 350 memcpy(saa->dmadebi, saa->audbuf + saa->audhead, split);
377 split);
378 saa->audhead = 0; 351 saa->audhead = 0;
379 audbytes -= split; 352 audbytes -= split;
380 } else 353 } else
@@ -383,20 +356,19 @@ static void do_irq_send_data(struct saa7146 *saa)
383 audbytes); 356 audbytes);
384 saa->audhead += audbytes; 357 saa->audhead += audbytes;
385 saa->audhead &= 0xffff; 358 saa->audhead &= 0xffff;
386 debiwrite(saa, debAudio, (NewCard? IBM_MP2_AUD_FIFO : 359 debiwrite(saa, debAudio, (NewCard ? IBM_MP2_AUD_FIFO :
387 IBM_MP2_AUD_FIFOW), 0, 2048); 360 IBM_MP2_AUD_FIFOW), 0, 2048);
388 wake_up_interruptible(&saa->audq); 361 wake_up_interruptible(&saa->audq);
389 /* if at least 1 block video waiting and video fifo isn't full */ 362 /* if at least 1 block video waiting and video fifo isn't full */
390 } else if (vidbytes >= 30720 && (debiread(saa, debNormal, 363 } else if (vidbytes >= 30720 && (debiread(saa, debNormal,
391 IBM_MP2_FIFO, 2)) < 16384) { 364 IBM_MP2_FIFO, 2)) < 16384) {
392 if (saa->vidhead > saa->vidtail) 365 if (saa->vidhead > saa->vidtail)
393 split = 524288 - saa->vidhead; 366 split = 524288 - saa->vidhead;
394 else 367 else
395 split = 0; 368 split = 0;
396 vidbytes = 30720; 369 vidbytes = 30720;
397 if (split > 0 && split < 30720) { 370 if (split > 0 && split < 30720) {
398 memcpy(saa->dmadebi, saa->vidbuf + saa->vidhead, 371 memcpy(saa->dmadebi, saa->vidbuf + saa->vidhead, split);
399 split);
400 saa->vidhead = 0; 372 saa->vidhead = 0;
401 vidbytes -= split; 373 vidbytes -= split;
402 } else 374 } else
@@ -406,7 +378,7 @@ static void do_irq_send_data(struct saa7146 *saa)
406 saa->vidhead += vidbytes; 378 saa->vidhead += vidbytes;
407 saa->vidhead &= 0x7ffff; 379 saa->vidhead &= 0x7ffff;
408 debiwrite(saa, debVideo, (NewCard ? IBM_MP2_FIFO : 380 debiwrite(saa, debVideo, (NewCard ? IBM_MP2_FIFO :
409 IBM_MP2_FIFOW), 0, 30720); 381 IBM_MP2_FIFOW), 0, 30720);
410 wake_up_interruptible(&saa->vidq); 382 wake_up_interruptible(&saa->vidq);
411 } 383 }
412 saawrite(SAA7146_PSR_DEBI_S | SAA7146_PSR_PIN1, SAA7146_IER); 384 saawrite(SAA7146_PSR_DEBI_S | SAA7146_PSR_PIN1, SAA7146_IER);
@@ -418,10 +390,10 @@ static void send_osd_data(struct saa7146 *saa)
418 if (size > 30720) 390 if (size > 30720)
419 size = 30720; 391 size = 30720;
420 /* ensure some multiple of 8 bytes is transferred */ 392 /* ensure some multiple of 8 bytes is transferred */
421 size = 8 * ((size + 8)>>3); 393 size = 8 * ((size + 8) >> 3);
422 if (size) { 394 if (size) {
423 debiwrite(saa, debNormal, IBM_MP2_OSD_ADDR, 395 debiwrite(saa, debNormal, IBM_MP2_OSD_ADDR,
424 (saa->osdhead>>3), 2); 396 (saa->osdhead >> 3), 2);
425 memcpy(saa->dmadebi, &saa->osdbuf[saa->osdhead], size); 397 memcpy(saa->dmadebi, &saa->osdbuf[saa->osdhead], size);
426 saa->osdhead += size; 398 saa->osdhead += size;
427 /* block transfer of next 8 bytes to ~32k bytes */ 399 /* block transfer of next 8 bytes to ~32k bytes */
@@ -435,7 +407,7 @@ static void send_osd_data(struct saa7146 *saa)
435 407
436static irqreturn_t saa7146_irq(int irq, void *dev_id, struct pt_regs *regs) 408static irqreturn_t saa7146_irq(int irq, void *dev_id, struct pt_regs *regs)
437{ 409{
438 struct saa7146 *saa = (struct saa7146 *) dev_id; 410 struct saa7146 *saa = dev_id;
439 u32 stat, astat; 411 u32 stat, astat;
440 int count; 412 int count;
441 int handled = 0; 413 int handled = 0;
@@ -484,7 +456,7 @@ static irqreturn_t saa7146_irq(int irq, void *dev_id, struct pt_regs *regs)
484 saa->vidinfo.v_size = 480; 456 saa->vidinfo.v_size = 480;
485#if 0 457#if 0
486 if (saa->endmarkhead != saa->endmarktail) { 458 if (saa->endmarkhead != saa->endmarktail) {
487 saa->audhead = 459 saa->audhead =
488 saa->endmark[saa->endmarkhead]; 460 saa->endmark[saa->endmarkhead];
489 saa->endmarkhead++; 461 saa->endmarkhead++;
490 if (saa->endmarkhead >= MAX_MARKS) 462 if (saa->endmarkhead >= MAX_MARKS)
@@ -494,7 +466,7 @@ static irqreturn_t saa7146_irq(int irq, void *dev_id, struct pt_regs *regs)
494 } 466 }
495 if (istat & 0x4000) { /* Sequence Error Code */ 467 if (istat & 0x4000) { /* Sequence Error Code */
496 if (saa->endmarkhead != saa->endmarktail) { 468 if (saa->endmarkhead != saa->endmarktail) {
497 saa->audhead = 469 saa->audhead =
498 saa->endmark[saa->endmarkhead]; 470 saa->endmark[saa->endmarkhead];
499 saa->endmarkhead++; 471 saa->endmarkhead++;
500 if (saa->endmarkhead >= MAX_MARKS) 472 if (saa->endmarkhead >= MAX_MARKS)
@@ -613,7 +585,7 @@ static int ibm_send_command(struct saa7146 *saa,
613 int i; 585 int i;
614 586
615 if (chain) 587 if (chain)
616 debiwrite(saa, debNormal, IBM_MP2_COMMAND, (command << 1) | 1, 2); 588 debiwrite(saa, debNormal, IBM_MP2_COMMAND, (command << 1)| 1,2);
617 else 589 else
618 debiwrite(saa, debNormal, IBM_MP2_COMMAND, command << 1, 2); 590 debiwrite(saa, debNormal, IBM_MP2_COMMAND, command << 1, 2);
619 debiwrite(saa, debNormal, IBM_MP2_CMD_DATA, data, 2); 591 debiwrite(saa, debNormal, IBM_MP2_CMD_DATA, data, 2);
@@ -663,11 +635,9 @@ static void initialize_cs8420(struct saa7146 *saa, int pro)
663 else 635 else
664 sequence = mode8420con; 636 sequence = mode8420con;
665 for (i = 0; i < INIT8420LEN; i++) 637 for (i = 0; i < INIT8420LEN; i++)
666 I2CWrite(saa, 0x20, init8420[i * 2], 638 I2CWrite(saa, 0x20, init8420[i * 2], init8420[i * 2 + 1], 2);
667 init8420[i * 2 + 1], 2);
668 for (i = 0; i < MODE8420LEN; i++) 639 for (i = 0; i < MODE8420LEN; i++)
669 I2CWrite(saa, 0x20, sequence[i * 2], 640 I2CWrite(saa, 0x20, sequence[i * 2], sequence[i * 2 + 1], 2);
670 sequence[i * 2 + 1], 2);
671 printk("stradis%d: CS8420 initialized\n", saa->nr); 641 printk("stradis%d: CS8420 initialized\n", saa->nr);
672} 642}
673 643
@@ -683,35 +653,36 @@ static void initialize_saa7121(struct saa7146 *saa, int dopal)
683 /* initialize PAL/NTSC video encoder */ 653 /* initialize PAL/NTSC video encoder */
684 for (i = 0; i < INIT7121LEN; i++) { 654 for (i = 0; i < INIT7121LEN; i++) {
685 if (NewCard) { /* handle new card encoder differences */ 655 if (NewCard) { /* handle new card encoder differences */
686 if (sequence[i*2] == 0x3a) 656 if (sequence[i * 2] == 0x3a)
687 I2CWrite(saa, 0x88, 0x3a, 0x13, 2); 657 I2CWrite(saa, 0x88, 0x3a, 0x13, 2);
688 else if (sequence[i*2] == 0x6b) 658 else if (sequence[i * 2] == 0x6b)
689 I2CWrite(saa, 0x88, 0x6b, 0x20, 2); 659 I2CWrite(saa, 0x88, 0x6b, 0x20, 2);
690 else if (sequence[i*2] == 0x6c) 660 else if (sequence[i * 2] == 0x6c)
691 I2CWrite(saa, 0x88, 0x6c, 661 I2CWrite(saa, 0x88, 0x6c,
692 dopal ? 0x09 : 0xf5, 2); 662 dopal ? 0x09 : 0xf5, 2);
693 else if (sequence[i*2] == 0x6d) 663 else if (sequence[i * 2] == 0x6d)
694 I2CWrite(saa, 0x88, 0x6d, 664 I2CWrite(saa, 0x88, 0x6d,
695 dopal ? 0x20 : 0x00, 2); 665 dopal ? 0x20 : 0x00, 2);
696 else if (sequence[i*2] == 0x7a) 666 else if (sequence[i * 2] == 0x7a)
697 I2CWrite(saa, 0x88, 0x7a, 667 I2CWrite(saa, 0x88, 0x7a,
698 dopal ? (PALFirstActive - 1) : 668 dopal ? (PALFirstActive - 1) :
699 (NTSCFirstActive - 4), 2); 669 (NTSCFirstActive - 4), 2);
700 else if (sequence[i*2] == 0x7b) 670 else if (sequence[i * 2] == 0x7b)
701 I2CWrite(saa, 0x88, 0x7b, 671 I2CWrite(saa, 0x88, 0x7b,
702 dopal ? PALLastActive : 672 dopal ? PALLastActive :
703 NTSCLastActive, 2); 673 NTSCLastActive, 2);
704 else I2CWrite(saa, 0x88, sequence[i * 2], 674 else
705 sequence[i * 2 + 1], 2); 675 I2CWrite(saa, 0x88, sequence[i * 2],
676 sequence[i * 2 + 1], 2);
706 } else { 677 } else {
707 if (sequence[i*2] == 0x6b && mod) 678 if (sequence[i * 2] == 0x6b && mod)
708 I2CWrite(saa, 0x88, 0x6b, 679 I2CWrite(saa, 0x88, 0x6b,
709 (sequence[i * 2 + 1] ^ 0x09), 2); 680 (sequence[i * 2 + 1] ^ 0x09), 2);
710 else if (sequence[i*2] == 0x7a) 681 else if (sequence[i * 2] == 0x7a)
711 I2CWrite(saa, 0x88, 0x7a, 682 I2CWrite(saa, 0x88, 0x7a,
712 dopal ? (PALFirstActive - 1) : 683 dopal ? (PALFirstActive - 1) :
713 (NTSCFirstActive - 4), 2); 684 (NTSCFirstActive - 4), 2);
714 else if (sequence[i*2] == 0x7b) 685 else if (sequence[i * 2] == 0x7b)
715 I2CWrite(saa, 0x88, 0x7b, 686 I2CWrite(saa, 0x88, 0x7b,
716 dopal ? PALLastActive : 687 dopal ? PALLastActive :
717 NTSCLastActive, 2); 688 NTSCLastActive, 2);
@@ -735,7 +706,8 @@ static void set_genlock_offset(struct saa7146 *saa, int noffset)
735 nCode = noffset + 0x100; 706 nCode = noffset + 0x100;
736 if (nCode == 1) 707 if (nCode == 1)
737 nCode = 0x401; 708 nCode = 0x401;
738 else if (nCode < 1) nCode = 0x400 + PixelsPerLine + nCode; 709 else if (nCode < 1)
710 nCode = 0x400 + PixelsPerLine + nCode;
739 debiwrite(saa, debNormal, XILINX_GLDELAY, nCode, 2); 711 debiwrite(saa, debNormal, XILINX_GLDELAY, nCode, 2);
740} 712}
741 713
@@ -745,33 +717,31 @@ static void set_out_format(struct saa7146 *saa, int mode)
745 saa->boardcfg[2] = mode; 717 saa->boardcfg[2] = mode;
746 /* do not adjust analog video parameters here, use saa7121 init */ 718 /* do not adjust analog video parameters here, use saa7121 init */
747 /* you will affect the SDI output on the new card */ 719 /* you will affect the SDI output on the new card */
748 if (mode == VIDEO_MODE_PAL) { /* PAL */ 720 if (mode == VIDEO_MODE_PAL) { /* PAL */
749 debiwrite(saa, debNormal, XILINX_CTL0, 0x0808, 2); 721 debiwrite(saa, debNormal, XILINX_CTL0, 0x0808, 2);
750 mdelay(50); 722 mdelay(50);
751 saawrite(0x012002c0, SAA7146_NUM_LINE_BYTE1); 723 saawrite(0x012002c0, SAA7146_NUM_LINE_BYTE1);
752 if (NewCard) { 724 if (NewCard) {
753 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 725 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 0xe100, 2);
754 0xe100, 2);
755 mdelay(50); 726 mdelay(50);
756 } 727 }
757 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 728 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
758 NewCard ? 0xe500: 0x6500, 2); 729 NewCard ? 0xe500 : 0x6500, 2);
759 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY, 730 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
760 (1 << 8) | 731 (1 << 8) |
761 (NewCard ? PALFirstActive : PALFirstActive-6), 2); 732 (NewCard ? PALFirstActive : PALFirstActive - 6), 2);
762 } else { /* NTSC */ 733 } else { /* NTSC */
763 debiwrite(saa, debNormal, XILINX_CTL0, 0x0800, 2); 734 debiwrite(saa, debNormal, XILINX_CTL0, 0x0800, 2);
764 mdelay(50); 735 mdelay(50);
765 saawrite(0x00f002c0, SAA7146_NUM_LINE_BYTE1); 736 saawrite(0x00f002c0, SAA7146_NUM_LINE_BYTE1);
766 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 737 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
767 NewCard ? 0xe100: 0x6100, 2); 738 NewCard ? 0xe100 : 0x6100, 2);
768 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY, 739 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
769 (1 << 8) | 740 (1 << 8) |
770 (NewCard ? NTSCFirstActive : NTSCFirstActive-6), 2); 741 (NewCard ? NTSCFirstActive : NTSCFirstActive - 6), 2);
771 } 742 }
772} 743}
773 744
774
775/* Intialize bitmangler to map from a byte value to the mangled word that 745/* Intialize bitmangler to map from a byte value to the mangled word that
776 * must be output to program the Xilinx part through the DEBI port. 746 * must be output to program the Xilinx part through the DEBI port.
777 * Xilinx Data Bit->DEBI Bit: 0->15 1->7 2->6 3->12 4->11 5->2 6->1 7->0 747 * Xilinx Data Bit->DEBI Bit: 0->15 1->7 2->6 3->12 4->11 5->2 6->1 7->0
@@ -799,43 +769,41 @@ static int initialize_fpga(struct video_code *bitdata)
799 for (num = 0; num < saa_num; num++) { 769 for (num = 0; num < saa_num; num++) {
800 saa = &saa7146s[num]; 770 saa = &saa7146s[num];
801 if (saa->boardcfg[0] > 20) 771 if (saa->boardcfg[0] > 20)
802 continue; /* card was programmed */ 772 continue; /* card was programmed */
803 loadtwo = (saa->boardcfg[18] & 0x10); 773 loadtwo = (saa->boardcfg[18] & 0x10);
804 if (!NewCard) /* we have an old board */ 774 if (!NewCard) /* we have an old board */
805 for (i = 0; i < 256; i++) 775 for (i = 0; i < 256; i++)
806 bitmangler[i] = ((i & 0x01) << 15) | 776 bitmangler[i] = ((i & 0x01) << 15) |
807 ((i & 0x02) << 6) | ((i & 0x04) << 4) | 777 ((i & 0x02) << 6) | ((i & 0x04) << 4) |
808 ((i & 0x08) << 9) | ((i & 0x10) << 7) | 778 ((i & 0x08) << 9) | ((i & 0x10) << 7) |
809 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) | 779 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
810 ((i & 0x80) >> 7); 780 ((i & 0x80) >> 7);
811 else /* else we have a new board */ 781 else /* else we have a new board */
812 for (i = 0; i < 256; i++) 782 for (i = 0; i < 256; i++)
813 bitmangler[i] = ((i & 0x01) << 7) | 783 bitmangler[i] = ((i & 0x01) << 7) |
814 ((i & 0x02) << 5) | ((i & 0x04) << 3) | 784 ((i & 0x02) << 5) | ((i & 0x04) << 3) |
815 ((i & 0x08) << 1) | ((i & 0x10) >> 1) | 785 ((i & 0x08) << 1) | ((i & 0x10) >> 1) |
816 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) | 786 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
817 ((i & 0x80) >> 7); 787 ((i & 0x80) >> 7);
818 788
819 dmabuf = (u16 *) saa->dmadebi; 789 dmabuf = (u16 *) saa->dmadebi;
820 newdma = (u8 *) saa->dmadebi; 790 newdma = (u8 *) saa->dmadebi;
821 if (NewCard) { /* SDM2xxx */ 791 if (NewCard) { /* SDM2xxx */
822 if (!strncmp(bitdata->loadwhat, "decoder2", 8)) 792 if (!strncmp(bitdata->loadwhat, "decoder2", 8))
823 continue; /* fpga not for this card */ 793 continue; /* fpga not for this card */
824 if (!strncmp(&saa->boardcfg[42], 794 if (!strncmp(&saa->boardcfg[42], bitdata->loadwhat, 8))
825 bitdata->loadwhat, 8)) {
826 loadfile = 1; 795 loadfile = 1;
827 } else if (loadtwo && !strncmp(&saa->boardcfg[19], 796 else if (loadtwo && !strncmp(&saa->boardcfg[19],
828 bitdata->loadwhat, 8)) { 797 bitdata->loadwhat, 8))
829 loadfile = 2; 798 loadfile = 2;
830 } else if (!saa->boardcfg[42] && /* special */ 799 else if (!saa->boardcfg[42] && !strncmp("decxl",
831 !strncmp("decxl", bitdata->loadwhat, 8)) { 800 bitdata->loadwhat, 8))
832 loadfile = 1; 801 loadfile = 1; /* special */
833 } else 802 else
834 continue; /* fpga not for this card */ 803 continue; /* fpga not for this card */
835 if (loadfile != 1 && loadfile != 2) { 804 if (loadfile != 1 && loadfile != 2)
836 continue; /* skip to next card */ 805 continue; /* skip to next card */
837 } 806 if (saa->boardcfg[0] && loadfile == 1)
838 if (saa->boardcfg[0] && loadfile == 1 )
839 continue; /* skip to next card */ 807 continue; /* skip to next card */
840 if (saa->boardcfg[0] != 1 && loadfile == 2) 808 if (saa->boardcfg[0] != 1 && loadfile == 2)
841 continue; /* skip to next card */ 809 continue; /* skip to next card */
@@ -870,8 +838,9 @@ static int initialize_fpga(struct video_code *bitdata)
870 /* Release Xilinx INIT signal (WS2) */ 838 /* Release Xilinx INIT signal (WS2) */
871 saawrite(0x00000000, SAA7146_GPIO_CTRL); 839 saawrite(0x00000000, SAA7146_GPIO_CTRL);
872 /* Wait for the INIT to go High */ 840 /* Wait for the INIT to go High */
873 for (i = 0; i < 10000 && 841 for (i = 0;
874 !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2); i++) 842 i < 10000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
843 i++)
875 schedule(); 844 schedule();
876 if (i == 1000) { 845 if (i == 1000) {
877 printk(KERN_INFO "stradis%d: no fpga INIT\n", saa->nr); 846 printk(KERN_INFO "stradis%d: no fpga INIT\n", saa->nr);
@@ -881,17 +850,13 @@ send_fpga_stuff:
881 if (NewCard) { 850 if (NewCard) {
882 for (i = startindex; i < bitdata->datasize; i++) 851 for (i = startindex; i < bitdata->datasize; i++)
883 newdma[i - startindex] = 852 newdma[i - startindex] =
884 bitmangler[bitdata->data[i]]; 853 bitmangler[bitdata->data[i]];
885 debiwrite(saa, 0x01420000, 0, 0, 854 debiwrite(saa, 0x01420000, 0, 0,
886 ((bitdata->datasize - startindex) + 5)); 855 ((bitdata->datasize - startindex) + 5));
887 if (loadtwo) { 856 if (loadtwo && loadfile == 1) {
888 if (loadfile == 1) { 857 printk("stradis%d: awaiting 2nd FPGA bitfile\n",
889 printk("stradis%d: " 858 saa->nr);
890 "awaiting 2nd FPGA bitfile\n", 859 continue; /* skip to next card */
891 saa->nr);
892 continue; /* skip to next card */
893 }
894
895 } 860 }
896 } else { 861 } else {
897 for (i = startindex; i < bitdata->datasize; i++) 862 for (i = startindex; i < bitdata->datasize; i++)
@@ -900,8 +865,9 @@ send_fpga_stuff:
900 debiwrite(saa, 0x014a0000, 0, 0, 865 debiwrite(saa, 0x014a0000, 0, 0,
901 ((bitdata->datasize - startindex) + 5) * 2); 866 ((bitdata->datasize - startindex) + 5) * 2);
902 } 867 }
903 for (i = 0; i < 1000 && 868 for (i = 0;
904 !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2); i++) 869 i < 1000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
870 i++)
905 schedule(); 871 schedule();
906 if (i == 1000) { 872 if (i == 1000) {
907 printk(KERN_INFO "stradis%d: FPGA load failed\n", 873 printk(KERN_INFO "stradis%d: FPGA load failed\n",
@@ -925,14 +891,14 @@ send_fpga_stuff:
925 /* mute CS3310 */ 891 /* mute CS3310 */
926 if (HaveCS3310) 892 if (HaveCS3310)
927 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, 893 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
928 0, 2); 894 0, 2);
929 /* set VXCO to PWM mode, release reset, blank on */ 895 /* set VXCO to PWM mode, release reset, blank on */
930 debiwrite(saa, debNormal, XILINX_CTL0, 0xffc4, 2); 896 debiwrite(saa, debNormal, XILINX_CTL0, 0xffc4, 2);
931 mdelay(10); 897 mdelay(10);
932 /* unmute CS3310 */ 898 /* unmute CS3310 */
933 if (HaveCS3310) 899 if (HaveCS3310)
934 debiwrite(saa, debNormal, XILINX_CTL0, 900 debiwrite(saa, debNormal, XILINX_CTL0,
935 0x2020, 2); 901 0x2020, 2);
936 } 902 }
937 /* set source Black */ 903 /* set source Black */
938 debiwrite(saa, debNormal, XILINX_CTL0, 0x1707, 2); 904 debiwrite(saa, debNormal, XILINX_CTL0, 0x1707, 2);
@@ -958,10 +924,10 @@ send_fpga_stuff:
958 /* we must init CS8420 first since rev b pulls i2s */ 924 /* we must init CS8420 first since rev b pulls i2s */
959 /* master clock low and CS4341 needs i2s master to */ 925 /* master clock low and CS4341 needs i2s master to */
960 /* run the i2c port. */ 926 /* run the i2c port. */
961 if (HaveCS8420) { 927 if (HaveCS8420)
962 /* 0=consumer, 1=pro */ 928 /* 0=consumer, 1=pro */
963 initialize_cs8420(saa, 0); 929 initialize_cs8420(saa, 0);
964 } 930
965 mdelay(5); 931 mdelay(5);
966 if (HaveCS4341) 932 if (HaveCS4341)
967 initialize_cs4341(saa); 933 initialize_cs4341(saa);
@@ -981,6 +947,7 @@ send_fpga_stuff:
981 debiwrite(saa, debNormal, XILINX_CTL0, 0x8080, 2); 947 debiwrite(saa, debNormal, XILINX_CTL0, 0x8080, 2);
982#endif 948#endif
983 } 949 }
950
984 return failure; 951 return failure;
985} 952}
986 953
@@ -1021,10 +988,10 @@ static int do_ibm_reset(struct saa7146 *saa)
1021 /* we must init CS8420 first since rev b pulls i2s */ 988 /* we must init CS8420 first since rev b pulls i2s */
1022 /* master clock low and CS4341 needs i2s master to */ 989 /* master clock low and CS4341 needs i2s master to */
1023 /* run the i2c port. */ 990 /* run the i2c port. */
1024 if (HaveCS8420) { 991 if (HaveCS8420)
1025 /* 0=consumer, 1=pro */ 992 /* 0=consumer, 1=pro */
1026 initialize_cs8420(saa, 1); 993 initialize_cs8420(saa, 1);
1027 } 994
1028 mdelay(5); 995 mdelay(5);
1029 if (HaveCS4341) 996 if (HaveCS4341)
1030 initialize_cs4341(saa); 997 initialize_cs4341(saa);
@@ -1039,12 +1006,12 @@ static int do_ibm_reset(struct saa7146 *saa)
1039 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2); 1006 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
1040 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2); 1007 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
1041 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER, 1008 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
1042 (ChipControl == 0x43 ? 0xe800 : 0xe000), 1)) { 1009 (ChipControl == 0x43 ? 0xe800 : 0xe000), 1)) {
1043 printk(KERN_ERR "stradis%d: IBM config failed\n", saa->nr); 1010 printk(KERN_ERR "stradis%d: IBM config failed\n", saa->nr);
1044 } 1011 }
1045 if (HaveCS3310) { 1012 if (HaveCS3310) {
1046 int i = CS3310MaxLvl; 1013 int i = CS3310MaxLvl;
1047 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, ((i<<8)|i), 2); 1014 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, ((i << 8)| i),2);
1048 } 1015 }
1049 /* start video decoder */ 1016 /* start video decoder */
1050 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, ChipControl, 2); 1017 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, ChipControl, 2);
@@ -1057,6 +1024,7 @@ static int do_ibm_reset(struct saa7146 *saa)
1057 /* clear pending interrupts */ 1024 /* clear pending interrupts */
1058 debiread(saa, debNormal, IBM_MP2_HOST_INT, 2); 1025 debiread(saa, debNormal, IBM_MP2_HOST_INT, 2);
1059 debiwrite(saa, debNormal, XILINX_CTL0, 0x1711, 2); 1026 debiwrite(saa, debNormal, XILINX_CTL0, 0x1711, 2);
1027
1060 return 0; 1028 return 0;
1061} 1029}
1062 1030
@@ -1070,8 +1038,8 @@ static int initialize_ibmmpeg2(struct video_code *microcode)
1070 saa = &saa7146s[num]; 1038 saa = &saa7146s[num];
1071 /* check that FPGA is loaded */ 1039 /* check that FPGA is loaded */
1072 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0xa55a, 2); 1040 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0xa55a, 2);
1073 if ((i = debiread(saa, debNormal, IBM_MP2_OSD_SIZE, 2)) != 1041 i = debiread(saa, debNormal, IBM_MP2_OSD_SIZE, 2);
1074 0xa55a) { 1042 if (i != 0xa55a) {
1075 printk(KERN_INFO "stradis%d: %04x != 0xa55a\n", 1043 printk(KERN_INFO "stradis%d: %04x != 0xa55a\n",
1076 saa->nr, i); 1044 saa->nr, i);
1077#if 0 1045#if 0
@@ -1082,17 +1050,17 @@ static int initialize_ibmmpeg2(struct video_code *microcode)
1082 if (saa->boardcfg[0] > 27) 1050 if (saa->boardcfg[0] > 27)
1083 continue; /* skip to next card */ 1051 continue; /* skip to next card */
1084 /* load video control store */ 1052 /* load video control store */
1085 saa->boardcfg[1] = 0x13; /* no-sync default */ 1053 saa->boardcfg[1] = 0x13; /* no-sync default */
1086 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 1, 2); 1054 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 1, 2);
1087 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2); 1055 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
1088 for (i = 0; i < microcode->datasize / 2; i++) 1056 for (i = 0; i < microcode->datasize / 2; i++)
1089 debiwrite(saa, debNormal, IBM_MP2_PROC_IDATA, 1057 debiwrite(saa, debNormal, IBM_MP2_PROC_IDATA,
1090 (microcode->data[i * 2] << 8) | 1058 (microcode->data[i * 2] << 8) |
1091 microcode->data[i * 2 + 1], 2); 1059 microcode->data[i * 2 + 1], 2);
1092 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2); 1060 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
1093 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 0, 2); 1061 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 0, 2);
1094 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 1062 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1095 ChipControl, 2); 1063 ChipControl, 2);
1096 saa->boardcfg[0] = 28; 1064 saa->boardcfg[0] = 28;
1097 } 1065 }
1098 if (!strncmp(microcode->loadwhat, "decoder.aud", 11)) { 1066 if (!strncmp(microcode->loadwhat, "decoder.aud", 11)) {
@@ -1109,34 +1077,32 @@ static int initialize_ibmmpeg2(struct video_code *microcode)
1109 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2); 1077 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
1110 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2); 1078 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
1111 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER, 1079 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
1112 0xe000, 1)) { 1080 0xe000, 1)) {
1113 printk(KERN_ERR 1081 printk(KERN_ERR "stradis%d: IBM config "
1114 "stradis%d: IBM config failed\n", 1082 "failed\n", saa->nr);
1115 saa->nr);
1116 return -1; 1083 return -1;
1117 } 1084 }
1118 /* set PWM to center value */ 1085 /* set PWM to center value */
1119 if (NewCard) { 1086 if (NewCard) {
1120 debiwrite(saa, debNormal, XILINX_PWM, 1087 debiwrite(saa, debNormal, XILINX_PWM,
1121 saa->boardcfg[14] + 1088 saa->boardcfg[14] +
1122 (saa->boardcfg[13]<<8), 2); 1089 (saa->boardcfg[13] << 8), 2);
1123 } else 1090 } else
1124 debiwrite(saa, debNormal, XILINX_PWM, 1091 debiwrite(saa, debNormal, XILINX_PWM, 0x46, 2);
1125 0x46, 2); 1092
1126 if (HaveCS3310) { 1093 if (HaveCS3310) {
1127 i = CS3310MaxLvl; 1094 i = CS3310MaxLvl;
1128 debiwrite(saa, debNormal, 1095 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
1129 XILINX_CS3310_CMPLT, ((i<<8)|i), 2); 1096 (i << 8) | i, 2);
1130 } 1097 }
1131 printk(KERN_INFO 1098 printk(KERN_INFO "stradis%d: IBM MPEGCD%d Inited\n",
1132 "stradis%d: IBM MPEGCD%d Initialized\n", 1099 saa->nr, 18 + (debiread(saa, debNormal,
1133 saa->nr, 18 + (debiread(saa, debNormal, 1100 IBM_MP2_CHIP_CONTROL, 2) >> 12));
1134 IBM_MP2_CHIP_CONTROL, 2) >> 12));
1135 /* start video decoder */ 1101 /* start video decoder */
1136 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 1102 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1137 ChipControl, 2); 1103 ChipControl, 2);
1138 debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD, 1104 debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD, 0x4037,
1139 0x4037, 2); /* 256k vid, 3520 bytes aud */ 1105 2); /* 256k vid, 3520 bytes aud */
1140 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4573, 2); 1106 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4573, 2);
1141 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0); 1107 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1142 /* enable buffer threshold irq */ 1108 /* enable buffer threshold irq */
@@ -1149,52 +1115,48 @@ static int initialize_ibmmpeg2(struct video_code *microcode)
1149 saa->boardcfg[0] = 37; 1115 saa->boardcfg[0] = 37;
1150 } 1116 }
1151 } 1117 }
1118
1152 return 0; 1119 return 0;
1153} 1120}
1154 1121
1155static u32 palette2fmt[] = 1122static u32 palette2fmt[] = { /* some of these YUV translations are wrong */
1156{ /* some of these YUV translations are wrong */ 1123 0xffffffff, 0x86000000, 0x87000000, 0x80000000, 0x8100000, 0x82000000,
1157 0xffffffff, 0x86000000, 0x87000000, 0x80000000, 0x8100000, 0x82000000, 1124 0x83000000, 0x00000000, 0x03000000, 0x03000000, 0x0a00000, 0x03000000,
1158 0x83000000, 0x00000000, 0x03000000, 0x03000000, 0x0a00000, 0x03000000, 1125 0x06000000, 0x00000000, 0x03000000, 0x0a000000, 0x0300000
1159 0x06000000, 0x00000000, 0x03000000, 0x0a000000, 0x0300000
1160}; 1126};
1161static int bpp2fmt[4] = 1127static int bpp2fmt[4] = {
1162{
1163 VIDEO_PALETTE_HI240, VIDEO_PALETTE_RGB565, VIDEO_PALETTE_RGB24, 1128 VIDEO_PALETTE_HI240, VIDEO_PALETTE_RGB565, VIDEO_PALETTE_RGB24,
1164 VIDEO_PALETTE_RGB32 1129 VIDEO_PALETTE_RGB32
1165}; 1130};
1166 1131
1167/* I wish I could find a formula to calculate these... */ 1132/* I wish I could find a formula to calculate these... */
1168static u32 h_prescale[64] = 1133static u32 h_prescale[64] = {
1169{ 1134 0x10000000, 0x18040202, 0x18080000, 0x380c0606, 0x38100204, 0x38140808,
1170 0x10000000, 0x18040202, 0x18080000, 0x380c0606, 0x38100204, 0x38140808, 1135 0x38180000, 0x381c0000, 0x3820161c, 0x38242a3b, 0x38281230, 0x382c4460,
1171 0x38180000, 0x381c0000, 0x3820161c, 0x38242a3b, 0x38281230, 0x382c4460, 1136 0x38301040, 0x38340080, 0x38380000, 0x383c0000, 0x3840fefe, 0x3844ee9f,
1172 0x38301040, 0x38340080, 0x38380000, 0x383c0000, 0x3840fefe, 0x3844ee9f, 1137 0x3848ee9f, 0x384cee9f, 0x3850ee9f, 0x38542a3b, 0x38581230, 0x385c0000,
1173 0x3848ee9f, 0x384cee9f, 0x3850ee9f, 0x38542a3b, 0x38581230, 0x385c0000, 1138 0x38600000, 0x38640000, 0x38680000, 0x386c0000, 0x38700000, 0x38740000,
1174 0x38600000, 0x38640000, 0x38680000, 0x386c0000, 0x38700000, 0x38740000, 1139 0x38780000, 0x387c0000, 0x30800000, 0x38840000, 0x38880000, 0x388c0000,
1175 0x38780000, 0x387c0000, 0x30800000, 0x38840000, 0x38880000, 0x388c0000, 1140 0x38900000, 0x38940000, 0x38980000, 0x389c0000, 0x38a00000, 0x38a40000,
1176 0x38900000, 0x38940000, 0x38980000, 0x389c0000, 0x38a00000, 0x38a40000, 1141 0x38a80000, 0x38ac0000, 0x38b00000, 0x38b40000, 0x38b80000, 0x38bc0000,
1177 0x38a80000, 0x38ac0000, 0x38b00000, 0x38b40000, 0x38b80000, 0x38bc0000, 1142 0x38c00000, 0x38c40000, 0x38c80000, 0x38cc0000, 0x38d00000, 0x38d40000,
1178 0x38c00000, 0x38c40000, 0x38c80000, 0x38cc0000, 0x38d00000, 0x38d40000, 1143 0x38d80000, 0x38dc0000, 0x38e00000, 0x38e40000, 0x38e80000, 0x38ec0000,
1179 0x38d80000, 0x38dc0000, 0x38e00000, 0x38e40000, 0x38e80000, 0x38ec0000, 1144 0x38f00000, 0x38f40000, 0x38f80000, 0x38fc0000,
1180 0x38f00000, 0x38f40000, 0x38f80000, 0x38fc0000,
1181}; 1145};
1182static u32 v_gain[64] = 1146static u32 v_gain[64] = {
1183{ 1147 0x016000ff, 0x016100ff, 0x016100ff, 0x016200ff, 0x016200ff, 0x016200ff,
1184 0x016000ff, 0x016100ff, 0x016100ff, 0x016200ff, 0x016200ff, 0x016200ff, 1148 0x016200ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff,
1185 0x016200ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 1149 0x016300ff, 0x016300ff, 0x016300ff, 0x016400ff, 0x016400ff, 0x016400ff,
1186 0x016300ff, 0x016300ff, 0x016300ff, 0x016400ff, 0x016400ff, 0x016400ff, 1150 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1187 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1151 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1188 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1152 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1189 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1153 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1190 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1154 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1191 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1155 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1192 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1156 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1193 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 1157 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1194 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1195}; 1158};
1196 1159
1197
1198static void saa7146_set_winsize(struct saa7146 *saa) 1160static void saa7146_set_winsize(struct saa7146 *saa)
1199{ 1161{
1200 u32 format; 1162 u32 format;
@@ -1209,24 +1171,23 @@ static void saa7146_set_winsize(struct saa7146 *saa)
1209 saawrite(saa->win.vidadr + saa->win.bpl * saa->win.sheight, 1171 saawrite(saa->win.vidadr + saa->win.bpl * saa->win.sheight,
1210 SAA7146_PROT_ADDR1); 1172 SAA7146_PROT_ADDR1);
1211 saawrite(0, SAA7146_PAGE1); 1173 saawrite(0, SAA7146_PAGE1);
1212 saawrite(format|0x60, SAA7146_CLIP_FORMAT_CTRL); 1174 saawrite(format | 0x60, SAA7146_CLIP_FORMAT_CTRL);
1213 offset = (704 / (saa->win.width - 1)) & 0x3f; 1175 offset = (704 / (saa->win.width - 1)) & 0x3f;
1214 saawrite(h_prescale[offset], SAA7146_HPS_H_PRESCALE); 1176 saawrite(h_prescale[offset], SAA7146_HPS_H_PRESCALE);
1215 offset = (720896 / saa->win.width) / (offset + 1); 1177 offset = (720896 / saa->win.width) / (offset + 1);
1216 saawrite((offset<<12)|0x0c, SAA7146_HPS_H_SCALE); 1178 saawrite((offset << 12) | 0x0c, SAA7146_HPS_H_SCALE);
1217 if (CurrentMode == VIDEO_MODE_NTSC) { 1179 if (CurrentMode == VIDEO_MODE_NTSC) {
1218 yacl = /*(480 / saa->win.height - 1) & 0x3f*/ 0; 1180 yacl = /*(480 / saa->win.height - 1) & 0x3f */ 0;
1219 ysci = 1024 - (saa->win.height * 1024 / 480); 1181 ysci = 1024 - (saa->win.height * 1024 / 480);
1220 } else { 1182 } else {
1221 yacl = /*(576 / saa->win.height - 1) & 0x3f*/ 0; 1183 yacl = /*(576 / saa->win.height - 1) & 0x3f */ 0;
1222 ysci = 1024 - (saa->win.height * 1024 / 576); 1184 ysci = 1024 - (saa->win.height * 1024 / 576);
1223 } 1185 }
1224 saawrite((1<<31)|(ysci<<21)|(yacl<<15), SAA7146_HPS_V_SCALE); 1186 saawrite((1 << 31) | (ysci << 21) | (yacl << 15), SAA7146_HPS_V_SCALE);
1225 saawrite(v_gain[yacl], SAA7146_HPS_V_GAIN); 1187 saawrite(v_gain[yacl], SAA7146_HPS_V_GAIN);
1226 saawrite(((SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_HPS_V | 1188 saawrite(((SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_HPS_V |
1227 SAA7146_MC2_UPLD_HPS_H) << 16) | (SAA7146_MC2_UPLD_DMA1 | 1189 SAA7146_MC2_UPLD_HPS_H) << 16) | (SAA7146_MC2_UPLD_DMA1 |
1228 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_HPS_H), 1190 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_HPS_H), SAA7146_MC2);
1229 SAA7146_MC2);
1230} 1191}
1231 1192
1232/* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area 1193/* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area
@@ -1261,8 +1222,8 @@ static void clip_draw_rectangle(u32 *clipmap, int x, int y, int w, int h)
1261 startword = (x >> 5); 1222 startword = (x >> 5);
1262 endword = ((x + w) >> 5); 1223 endword = ((x + w) >> 5);
1263 bitsleft = (0xffffffff >> (x & 31)); 1224 bitsleft = (0xffffffff >> (x & 31));
1264 bitsright = (0xffffffff << (~((x + w) - (endword<<5)))); 1225 bitsright = (0xffffffff << (~((x + w) - (endword << 5))));
1265 temp = &clipmap[(y<<5) + startword]; 1226 temp = &clipmap[(y << 5) + startword];
1266 w = endword - startword; 1227 w = endword - startword;
1267 if (!w) { 1228 if (!w) {
1268 bitsleft |= bitsright; 1229 bitsleft |= bitsright;
@@ -1287,13 +1248,13 @@ static void make_clip_tab(struct saa7146 *saa, struct video_clip *cr, int ncr)
1287 u32 *clipmap; 1248 u32 *clipmap;
1288 1249
1289 clipmap = saa->dmavid2; 1250 clipmap = saa->dmavid2;
1290 if((width=saa->win.width)>1023) 1251 if ((width = saa->win.width) > 1023)
1291 width = 1023; /* sanity check */ 1252 width = 1023; /* sanity check */
1292 if((height=saa->win.height)>640) 1253 if ((height = saa->win.height) > 640)
1293 height = 639; /* sanity check */ 1254 height = 639; /* sanity check */
1294 if (ncr > 0) { /* rectangles pased */ 1255 if (ncr > 0) { /* rectangles pased */
1295 /* convert rectangular clips to a bitmap */ 1256 /* convert rectangular clips to a bitmap */
1296 memset(clipmap, 0, VIDEO_CLIPMAP_SIZE); /* clear map */ 1257 memset(clipmap, 0, VIDEO_CLIPMAP_SIZE); /* clear map */
1297 for (i = 0; i < ncr; i++) 1258 for (i = 0; i < ncr; i++)
1298 clip_draw_rectangle(clipmap, cr[i].x, cr[i].y, 1259 clip_draw_rectangle(clipmap, cr[i].x, cr[i].y,
1299 cr[i].width, cr[i].height); 1260 cr[i].width, cr[i].height);
@@ -1301,14 +1262,15 @@ static void make_clip_tab(struct saa7146 *saa, struct video_clip *cr, int ncr)
1301 /* clip against viewing window AND screen 1262 /* clip against viewing window AND screen
1302 so we do not have to rely on the user program 1263 so we do not have to rely on the user program
1303 */ 1264 */
1304 clip_draw_rectangle(clipmap,(saa->win.x+width>saa->win.swidth) ? 1265 clip_draw_rectangle(clipmap, (saa->win.x + width > saa->win.swidth) ?
1305 (saa->win.swidth-saa->win.x) : width, 0, 1024, 768); 1266 (saa->win.swidth - saa->win.x) : width, 0, 1024, 768);
1306 clip_draw_rectangle(clipmap,0,(saa->win.y+height>saa->win.sheight) ? 1267 clip_draw_rectangle(clipmap, 0,
1307 (saa->win.sheight-saa->win.y) : height,1024,768); 1268 (saa->win.y + height > saa->win.sheight) ?
1308 if (saa->win.x<0) 1269 (saa->win.sheight - saa->win.y) : height, 1024, 768);
1309 clip_draw_rectangle(clipmap, 0, 0, -(saa->win.x), 768); 1270 if (saa->win.x < 0)
1310 if (saa->win.y<0) 1271 clip_draw_rectangle(clipmap, 0, 0, -saa->win.x, 768);
1311 clip_draw_rectangle(clipmap, 0, 0, 1024, -(saa->win.y)); 1272 if (saa->win.y < 0)
1273 clip_draw_rectangle(clipmap, 0, 0, 1024, -saa->win.y);
1312} 1274}
1313 1275
1314static int saa_ioctl(struct inode *inode, struct file *file, 1276static int saa_ioctl(struct inode *inode, struct file *file,
@@ -1322,11 +1284,9 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1322 { 1284 {
1323 struct video_capability b; 1285 struct video_capability b;
1324 strcpy(b.name, saa->video_dev.name); 1286 strcpy(b.name, saa->video_dev.name);
1325 b.type = VID_TYPE_CAPTURE | 1287 b.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY |
1326 VID_TYPE_OVERLAY | 1288 VID_TYPE_CLIPPING | VID_TYPE_FRAMERAM |
1327 VID_TYPE_CLIPPING | 1289 VID_TYPE_SCALES;
1328 VID_TYPE_FRAMERAM |
1329 VID_TYPE_SCALES;
1330 b.channels = 1; 1290 b.channels = 1;
1331 b.audios = 1; 1291 b.audios = 1;
1332 b.maxwidth = 768; 1292 b.maxwidth = 768;
@@ -1363,17 +1323,18 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1363 if (p.palette < sizeof(palette2fmt) / sizeof(u32)) { 1323 if (p.palette < sizeof(palette2fmt) / sizeof(u32)) {
1364 format = palette2fmt[p.palette]; 1324 format = palette2fmt[p.palette];
1365 saa->win.color_fmt = format; 1325 saa->win.color_fmt = format;
1366 saawrite(format|0x60, SAA7146_CLIP_FORMAT_CTRL); 1326 saawrite(format | 0x60,
1327 SAA7146_CLIP_FORMAT_CTRL);
1367 } 1328 }
1368 saawrite(((p.brightness & 0xff00) << 16) | 1329 saawrite(((p.brightness & 0xff00) << 16) |
1369 ((p.contrast & 0xfe00) << 7) | 1330 ((p.contrast & 0xfe00) << 7) |
1370 ((p.colour & 0xfe00) >> 9), SAA7146_BCS_CTRL); 1331 ((p.colour & 0xfe00) >> 9), SAA7146_BCS_CTRL);
1371 saa->picture = p; 1332 saa->picture = p;
1372 /* upload changed registers */ 1333 /* upload changed registers */
1373 saawrite(((SAA7146_MC2_UPLD_HPS_H | 1334 saawrite(((SAA7146_MC2_UPLD_HPS_H |
1374 SAA7146_MC2_UPLD_HPS_V) << 16) | 1335 SAA7146_MC2_UPLD_HPS_V) << 16) |
1375 SAA7146_MC2_UPLD_HPS_H | SAA7146_MC2_UPLD_HPS_V, 1336 SAA7146_MC2_UPLD_HPS_H |
1376 SAA7146_MC2); 1337 SAA7146_MC2_UPLD_HPS_V, SAA7146_MC2);
1377 return 0; 1338 return 0;
1378 } 1339 }
1379 case VIDIOCSWIN: 1340 case VIDIOCSWIN:
@@ -1384,11 +1345,14 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1384 if (copy_from_user(&vw, arg, sizeof(vw))) 1345 if (copy_from_user(&vw, arg, sizeof(vw)))
1385 return -EFAULT; 1346 return -EFAULT;
1386 1347
1387 if (vw.flags || vw.width < 16 || vw.height < 16) { /* stop capture */ 1348 /* stop capture */
1388 saawrite((SAA7146_MC1_TR_E_1 << 16), SAA7146_MC1); 1349 if (vw.flags || vw.width < 16 || vw.height < 16) {
1350 saawrite((SAA7146_MC1_TR_E_1 << 16),
1351 SAA7146_MC1);
1389 return -EINVAL; 1352 return -EINVAL;
1390 } 1353 }
1391 if (saa->win.bpp < 4) { /* 32-bit align start and adjust width */ 1354 /* 32-bit align start and adjust width */
1355 if (saa->win.bpp < 4) {
1392 int i = vw.x; 1356 int i = vw.x;
1393 vw.x = (vw.x + 3) & ~3; 1357 vw.x = (vw.x + 3) & ~3;
1394 i = vw.x - i; 1358 i = vw.x - i;
@@ -1417,23 +1381,24 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1417 */ 1381 */
1418 if (vw.clipcount < 0) { 1382 if (vw.clipcount < 0) {
1419 if (copy_from_user(saa->dmavid2, vw.clips, 1383 if (copy_from_user(saa->dmavid2, vw.clips,
1420 VIDEO_CLIPMAP_SIZE)) 1384 VIDEO_CLIPMAP_SIZE))
1421 return -EFAULT; 1385 return -EFAULT;
1422 } 1386 } else if (vw.clipcount > 16384) {
1423 else if (vw.clipcount > 16384) {
1424 return -EINVAL; 1387 return -EINVAL;
1425 } else if (vw.clipcount > 0) { 1388 } else if (vw.clipcount > 0) {
1426 if ((vcp = vmalloc(sizeof(struct video_clip) * 1389 vcp = vmalloc(sizeof(struct video_clip) *
1427 (vw.clipcount))) == NULL) 1390 vw.clipcount);
1428 return -ENOMEM; 1391 if (vcp == NULL)
1392 return -ENOMEM;
1429 if (copy_from_user(vcp, vw.clips, 1393 if (copy_from_user(vcp, vw.clips,
1430 sizeof(struct video_clip) * 1394 sizeof(struct video_clip) *
1431 vw.clipcount)) { 1395 vw.clipcount)) {
1432 vfree(vcp); 1396 vfree(vcp);
1433 return -EFAULT; 1397 return -EFAULT;
1434 } 1398 }
1435 } else /* nothing clipped */ 1399 } else /* nothing clipped */
1436 memset(saa->dmavid2, 0, VIDEO_CLIPMAP_SIZE); 1400 memset(saa->dmavid2, 0, VIDEO_CLIPMAP_SIZE);
1401
1437 make_clip_tab(saa, vcp, vw.clipcount); 1402 make_clip_tab(saa, vcp, vw.clipcount);
1438 if (vw.clipcount > 0) 1403 if (vw.clipcount > 0)
1439 vfree(vcp); 1404 vfree(vcp);
@@ -1466,21 +1431,21 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1466 if (v == 0) { 1431 if (v == 0) {
1467 saa->cap &= ~1; 1432 saa->cap &= ~1;
1468 saawrite((SAA7146_MC1_TR_E_1 << 16), 1433 saawrite((SAA7146_MC1_TR_E_1 << 16),
1469 SAA7146_MC1); 1434 SAA7146_MC1);
1470 } else { 1435 } else {
1471 if (saa->win.vidadr == 0 || saa->win.width == 0 1436 if (saa->win.vidadr == 0 || saa->win.width == 0
1472 || saa->win.height == 0) 1437 || saa->win.height == 0)
1473 return -EINVAL; 1438 return -EINVAL;
1474 saa->cap |= 1; 1439 saa->cap |= 1;
1475 saawrite((SAA7146_MC1_TR_E_1 << 16) | 0xffff, 1440 saawrite((SAA7146_MC1_TR_E_1 << 16) | 0xffff,
1476 SAA7146_MC1); 1441 SAA7146_MC1);
1477 } 1442 }
1478 return 0; 1443 return 0;
1479 } 1444 }
1480 case VIDIOCGFBUF: 1445 case VIDIOCGFBUF:
1481 { 1446 {
1482 struct video_buffer v; 1447 struct video_buffer v;
1483 v.base = (void *) saa->win.vidadr; 1448 v.base = (void *)saa->win.vidadr;
1484 v.height = saa->win.sheight; 1449 v.height = saa->win.sheight;
1485 v.width = saa->win.swidth; 1450 v.width = saa->win.swidth;
1486 v.depth = saa->win.depth; 1451 v.depth = saa->win.depth;
@@ -1498,19 +1463,20 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1498 if (copy_from_user(&v, arg, sizeof(v))) 1463 if (copy_from_user(&v, arg, sizeof(v)))
1499 return -EFAULT; 1464 return -EFAULT;
1500 if (v.depth != 8 && v.depth != 15 && v.depth != 16 && 1465 if (v.depth != 8 && v.depth != 15 && v.depth != 16 &&
1501 v.depth != 24 && v.depth != 32 && v.width > 16 && 1466 v.depth != 24 && v.depth != 32 && v.width > 16 &&
1502 v.height > 16 && v.bytesperline > 16) 1467 v.height > 16 && v.bytesperline > 16)
1503 return -EINVAL; 1468 return -EINVAL;
1504 if (v.base) 1469 if (v.base)
1505 saa->win.vidadr = (unsigned long) v.base; 1470 saa->win.vidadr = (unsigned long)v.base;
1506 saa->win.sheight = v.height; 1471 saa->win.sheight = v.height;
1507 saa->win.swidth = v.width; 1472 saa->win.swidth = v.width;
1508 saa->win.bpp = ((v.depth + 7) & 0x38) / 8; 1473 saa->win.bpp = ((v.depth + 7) & 0x38) / 8;
1509 saa->win.depth = v.depth; 1474 saa->win.depth = v.depth;
1510 saa->win.bpl = v.bytesperline; 1475 saa->win.bpl = v.bytesperline;
1511 1476
1512 DEBUG(printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n", 1477 DEBUG(printk("Display at %p is %d by %d, bytedepth %d, "
1513 v.base, v.width, v.height, saa->win.bpp, saa->win.bpl)); 1478 "bpl %d\n", v.base, v.width, v.height,
1479 saa->win.bpp, saa->win.bpl));
1514 saa7146_set_winsize(saa); 1480 saa7146_set_winsize(saa);
1515 return 0; 1481 return 0;
1516 } 1482 }
@@ -1538,21 +1504,18 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1538 int i; 1504 int i;
1539 if (copy_from_user(&v, arg, sizeof(v))) 1505 if (copy_from_user(&v, arg, sizeof(v)))
1540 return -EFAULT; 1506 return -EFAULT;
1541 i = (~(v.volume>>8))&0xff; 1507 i = (~(v.volume >> 8)) & 0xff;
1542 if (!HaveCS4341) { 1508 if (!HaveCS4341) {
1543 if (v.flags & VIDEO_AUDIO_MUTE) { 1509 if (v.flags & VIDEO_AUDIO_MUTE)
1544 debiwrite(saa, debNormal, 1510 debiwrite(saa, debNormal,
1545 IBM_MP2_FRNT_ATTEN, 1511 IBM_MP2_FRNT_ATTEN, 0xffff, 2);
1546 0xffff, 2);
1547 }
1548 if (!(v.flags & VIDEO_AUDIO_MUTE)) 1512 if (!(v.flags & VIDEO_AUDIO_MUTE))
1549 debiwrite(saa, debNormal, 1513 debiwrite(saa, debNormal,
1550 IBM_MP2_FRNT_ATTEN, 1514 IBM_MP2_FRNT_ATTEN, 0x0000, 2);
1551 0x0000, 2);
1552 if (v.flags & VIDEO_AUDIO_VOLUME) 1515 if (v.flags & VIDEO_AUDIO_VOLUME)
1553 debiwrite(saa, debNormal, 1516 debiwrite(saa, debNormal,
1554 IBM_MP2_FRNT_ATTEN, 1517 IBM_MP2_FRNT_ATTEN,
1555 (i<<8)|i, 2); 1518 (i << 8) | i, 2);
1556 } else { 1519 } else {
1557 if (v.flags & VIDEO_AUDIO_MUTE) 1520 if (v.flags & VIDEO_AUDIO_MUTE)
1558 cs4341_setlevel(saa, 0xff, 0xff); 1521 cs4341_setlevel(saa, 0xff, 0xff);
@@ -1580,163 +1543,138 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1580 case VIDIOCSPLAYMODE: 1543 case VIDIOCSPLAYMODE:
1581 { 1544 {
1582 struct video_play_mode pmode; 1545 struct video_play_mode pmode;
1583 if (copy_from_user((void *) &pmode, arg, 1546 if (copy_from_user((void *)&pmode, arg,
1584 sizeof(struct video_play_mode))) 1547 sizeof(struct video_play_mode)))
1585 return -EFAULT; 1548 return -EFAULT;
1586 switch (pmode.mode) { 1549 switch (pmode.mode) {
1587 case VID_PLAY_VID_OUT_MODE: 1550 case VID_PLAY_VID_OUT_MODE:
1588 if (pmode.p1 != VIDEO_MODE_NTSC && 1551 if (pmode.p1 != VIDEO_MODE_NTSC &&
1589 pmode.p1 != VIDEO_MODE_PAL) 1552 pmode.p1 != VIDEO_MODE_PAL)
1590 return -EINVAL; 1553 return -EINVAL;
1591 set_out_format(saa, pmode.p1); 1554 set_out_format(saa, pmode.p1);
1592 return 0; 1555 return 0;
1593 case VID_PLAY_GENLOCK: 1556 case VID_PLAY_GENLOCK:
1594 debiwrite(saa, debNormal, 1557 debiwrite(saa, debNormal, XILINX_CTL0,
1595 XILINX_CTL0, 1558 pmode.p1 ? 0x8000 : 0x8080, 2);
1596 (pmode.p1 ? 0x8000 : 0x8080), 1559 if (NewCard)
1597 2); 1560 set_genlock_offset(saa, pmode.p2);
1598 if (NewCard) 1561 return 0;
1599 set_genlock_offset(saa, 1562 case VID_PLAY_NORMAL:
1600 pmode.p2); 1563 debiwrite(saa, debNormal,
1601 return 0; 1564 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1602 case VID_PLAY_NORMAL: 1565 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1603 debiwrite(saa, debNormal, 1566 saa->playmode = pmode.mode;
1604 IBM_MP2_CHIP_CONTROL, 1567 return 0;
1605 ChipControl, 2); 1568 case VID_PLAY_PAUSE:
1606 ibm_send_command(saa, 1569 /* IBM removed the PAUSE command */
1607 IBM_MP2_PLAY, 0, 0); 1570 /* they say use SINGLE_FRAME now */
1608 saa->playmode = pmode.mode; 1571 case VID_PLAY_SINGLE_FRAME:
1609 return 0; 1572 ibm_send_command(saa, IBM_MP2_SINGLE_FRAME,0,0);
1610 case VID_PLAY_PAUSE: 1573 if (saa->playmode == pmode.mode) {
1611 /* IBM removed the PAUSE command */
1612 /* they say use SINGLE_FRAME now */
1613 case VID_PLAY_SINGLE_FRAME:
1614 ibm_send_command(saa,
1615 IBM_MP2_SINGLE_FRAME,
1616 0, 0);
1617 if (saa->playmode == pmode.mode) {
1618 debiwrite(saa, debNormal,
1619 IBM_MP2_CHIP_CONTROL,
1620 ChipControl, 2);
1621 }
1622 saa->playmode = pmode.mode;
1623 return 0;
1624 case VID_PLAY_FAST_FORWARD:
1625 ibm_send_command(saa,
1626 IBM_MP2_FAST_FORWARD, 0, 0);
1627 saa->playmode = pmode.mode;
1628 return 0;
1629 case VID_PLAY_SLOW_MOTION:
1630 ibm_send_command(saa,
1631 IBM_MP2_SLOW_MOTION,
1632 pmode.p1, 0);
1633 saa->playmode = pmode.mode;
1634 return 0;
1635 case VID_PLAY_IMMEDIATE_NORMAL:
1636 /* ensure transfers resume */
1637 debiwrite(saa, debNormal,
1638 IBM_MP2_CHIP_CONTROL,
1639 ChipControl, 2);
1640 ibm_send_command(saa,
1641 IBM_MP2_IMED_NORM_PLAY, 0, 0);
1642 saa->playmode = VID_PLAY_NORMAL;
1643 return 0;
1644 case VID_PLAY_SWITCH_CHANNELS:
1645 saa->audhead = saa->audtail = 0;
1646 saa->vidhead = saa->vidtail = 0;
1647 ibm_send_command(saa,
1648 IBM_MP2_FREEZE_FRAME, 0, 1);
1649 ibm_send_command(saa,
1650 IBM_MP2_RESET_AUD_RATE, 0, 1);
1651 debiwrite(saa, debNormal,
1652 IBM_MP2_CHIP_CONTROL, 0, 2);
1653 ibm_send_command(saa,
1654 IBM_MP2_CHANNEL_SWITCH, 0, 1);
1655 debiwrite(saa, debNormal, 1574 debiwrite(saa, debNormal,
1656 IBM_MP2_CHIP_CONTROL, 1575 IBM_MP2_CHIP_CONTROL,
1657 ChipControl, 2); 1576 ChipControl, 2);
1658 ibm_send_command(saa, 1577 }
1659 IBM_MP2_PLAY, 0, 0); 1578 saa->playmode = pmode.mode;
1660 saa->playmode = VID_PLAY_NORMAL; 1579 return 0;
1661 return 0; 1580 case VID_PLAY_FAST_FORWARD:
1662 case VID_PLAY_FREEZE_FRAME: 1581 ibm_send_command(saa, IBM_MP2_FAST_FORWARD,0,0);
1663 ibm_send_command(saa, 1582 saa->playmode = pmode.mode;
1664 IBM_MP2_FREEZE_FRAME, 0, 0); 1583 return 0;
1665 saa->playmode = pmode.mode; 1584 case VID_PLAY_SLOW_MOTION:
1666 return 0; 1585 ibm_send_command(saa, IBM_MP2_SLOW_MOTION,
1667 case VID_PLAY_STILL_MODE: 1586 pmode.p1, 0);
1668 ibm_send_command(saa, 1587 saa->playmode = pmode.mode;
1669 IBM_MP2_SET_STILL_MODE, 0, 0); 1588 return 0;
1670 saa->playmode = pmode.mode; 1589 case VID_PLAY_IMMEDIATE_NORMAL:
1671 return 0; 1590 /* ensure transfers resume */
1672 case VID_PLAY_MASTER_MODE: 1591 debiwrite(saa, debNormal,
1673 if (pmode.p1 == VID_PLAY_MASTER_NONE) 1592 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1674 saa->boardcfg[1] = 0x13; 1593 ibm_send_command(saa, IBM_MP2_IMED_NORM_PLAY,
1675 else if (pmode.p1 == 1594 0, 0);
1676 VID_PLAY_MASTER_VIDEO) 1595 saa->playmode = VID_PLAY_NORMAL;
1677 saa->boardcfg[1] = 0x23; 1596 return 0;
1678 else if (pmode.p1 == 1597 case VID_PLAY_SWITCH_CHANNELS:
1679 VID_PLAY_MASTER_AUDIO) 1598 saa->audhead = saa->audtail = 0;
1680 saa->boardcfg[1] = 0x43; 1599 saa->vidhead = saa->vidtail = 0;
1681 else 1600 ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,1);
1601 ibm_send_command(saa, IBM_MP2_RESET_AUD_RATE,
1602 0, 1);
1603 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1604 0, 2);
1605 ibm_send_command(saa, IBM_MP2_CHANNEL_SWITCH,
1606 0, 1);
1607 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1608 ChipControl, 2);
1609 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1610 saa->playmode = VID_PLAY_NORMAL;
1611 return 0;
1612 case VID_PLAY_FREEZE_FRAME:
1613 ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,0);
1614 saa->playmode = pmode.mode;
1615 return 0;
1616 case VID_PLAY_STILL_MODE:
1617 ibm_send_command(saa, IBM_MP2_SET_STILL_MODE,
1618 0, 0);
1619 saa->playmode = pmode.mode;
1620 return 0;
1621 case VID_PLAY_MASTER_MODE:
1622 if (pmode.p1 == VID_PLAY_MASTER_NONE)
1623 saa->boardcfg[1] = 0x13;
1624 else if (pmode.p1 == VID_PLAY_MASTER_VIDEO)
1625 saa->boardcfg[1] = 0x23;
1626 else if (pmode.p1 == VID_PLAY_MASTER_AUDIO)
1627 saa->boardcfg[1] = 0x43;
1628 else
1629 return -EINVAL;
1630 debiwrite(saa, debNormal,
1631 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1632 return 0;
1633 case VID_PLAY_ACTIVE_SCANLINES:
1634 if (CurrentMode == VIDEO_MODE_PAL) {
1635 if (pmode.p1 < 1 || pmode.p2 > 625)
1682 return -EINVAL; 1636 return -EINVAL;
1683 debiwrite(saa, debNormal, 1637 saa->boardcfg[5] = pmode.p1;
1684 IBM_MP2_CHIP_CONTROL, 1638 saa->boardcfg[55] = (pmode.p1 +
1685 ChipControl, 2); 1639 (pmode.p2 / 2) - 1) & 0xff;
1686 return 0; 1640 } else {
1687 case VID_PLAY_ACTIVE_SCANLINES: 1641 if (pmode.p1 < 4 || pmode.p2 > 525)
1688 if (CurrentMode == VIDEO_MODE_PAL) { 1642 return -EINVAL;
1689 if (pmode.p1 < 1 || 1643 saa->boardcfg[4] = pmode.p1;
1690 pmode.p2 > 625) 1644 saa->boardcfg[54] = (pmode.p1 +
1691 return -EINVAL; 1645 (pmode.p2 / 2) - 4) & 0xff;
1692 saa->boardcfg[5] = pmode.p1; 1646 }
1693 saa->boardcfg[55] = (pmode.p1 + 1647 set_out_format(saa, CurrentMode);
1694 (pmode.p2/2) - 1) & 1648 case VID_PLAY_RESET:
1695 0xff; 1649 return do_ibm_reset(saa);
1696 } else { 1650 case VID_PLAY_END_MARK:
1697 if (pmode.p1 < 4 || 1651 if (saa->endmarktail < saa->endmarkhead) {
1698 pmode.p2 > 525) 1652 if (saa->endmarkhead -
1699 return -EINVAL;
1700 saa->boardcfg[4] = pmode.p1;
1701 saa->boardcfg[54] = (pmode.p1 +
1702 (pmode.p2/2) - 4) &
1703 0xff;
1704 }
1705 set_out_format(saa, CurrentMode);
1706 case VID_PLAY_RESET:
1707 return do_ibm_reset(saa);
1708 case VID_PLAY_END_MARK:
1709 if (saa->endmarktail <
1710 saa->endmarkhead) {
1711 if (saa->endmarkhead -
1712 saa->endmarktail < 2) 1653 saa->endmarktail < 2)
1713 return -ENOSPC;
1714 } else if (saa->endmarkhead <=
1715 saa->endmarktail) {
1716 if (saa->endmarktail -
1717 saa->endmarkhead >
1718 (MAX_MARKS - 2))
1719 return -ENOSPC;
1720 } else
1721 return -ENOSPC; 1654 return -ENOSPC;
1722 saa->endmark[saa->endmarktail] = 1655 } else if (saa->endmarkhead <=saa->endmarktail){
1723 saa->audtail; 1656 if (saa->endmarktail - saa->endmarkhead
1724 saa->endmarktail++; 1657 > (MAX_MARKS - 2))
1725 if (saa->endmarktail >= MAX_MARKS) 1658 return -ENOSPC;
1726 saa->endmarktail = 0; 1659 } else
1660 return -ENOSPC;
1661 saa->endmark[saa->endmarktail] = saa->audtail;
1662 saa->endmarktail++;
1663 if (saa->endmarktail >= MAX_MARKS)
1664 saa->endmarktail = 0;
1727 } 1665 }
1728 return -EINVAL; 1666 return -EINVAL;
1729 } 1667 }
1730 case VIDIOCSWRITEMODE: 1668 case VIDIOCSWRITEMODE:
1731 { 1669 {
1732 int mode; 1670 int mode;
1733 if (copy_from_user((void *) &mode, arg, sizeof(int))) 1671 if (copy_from_user((void *)&mode, arg, sizeof(int)))
1734 return -EFAULT; 1672 return -EFAULT;
1735 if (mode == VID_WRITE_MPEG_AUD || 1673 if (mode == VID_WRITE_MPEG_AUD ||
1736 mode == VID_WRITE_MPEG_VID || 1674 mode == VID_WRITE_MPEG_VID ||
1737 mode == VID_WRITE_CC || 1675 mode == VID_WRITE_CC ||
1738 mode == VID_WRITE_TTX || 1676 mode == VID_WRITE_TTX ||
1739 mode == VID_WRITE_OSD) { 1677 mode == VID_WRITE_OSD) {
1740 saa->writemode = mode; 1678 saa->writemode = mode;
1741 return 0; 1679 return 0;
1742 } 1680 }
@@ -1750,7 +1688,7 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1750 if (copy_from_user(&ucode, arg, sizeof(ucode))) 1688 if (copy_from_user(&ucode, arg, sizeof(ucode)))
1751 return -EFAULT; 1689 return -EFAULT;
1752 if (ucode.datasize > 65536 || ucode.datasize < 1024 || 1690 if (ucode.datasize > 65536 || ucode.datasize < 1024 ||
1753 strncmp(ucode.loadwhat, "dec", 3)) 1691 strncmp(ucode.loadwhat, "dec", 3))
1754 return -EINVAL; 1692 return -EINVAL;
1755 if ((udata = vmalloc(ucode.datasize)) == NULL) 1693 if ((udata = vmalloc(ucode.datasize)) == NULL)
1756 return -ENOMEM; 1694 return -ENOMEM;
@@ -1759,8 +1697,8 @@ static int saa_ioctl(struct inode *inode, struct file *file,
1759 return -EFAULT; 1697 return -EFAULT;
1760 } 1698 }
1761 ucode.data = udata; 1699 ucode.data = udata;
1762 if (!strncmp(ucode.loadwhat, "decoder.aud", 11) 1700 if (!strncmp(ucode.loadwhat, "decoder.aud", 11) ||
1763 || !strncmp(ucode.loadwhat, "decoder.vid", 11)) 1701 !strncmp(ucode.loadwhat, "decoder.vid", 11))
1764 i = initialize_ibmmpeg2(&ucode); 1702 i = initialize_ibmmpeg2(&ucode);
1765 else 1703 else
1766 i = initialize_fpga(&ucode); 1704 i = initialize_fpga(&ucode);
@@ -1805,14 +1743,14 @@ static int saa_mmap(struct file *file, struct vm_area_struct *vma)
1805 return -EINVAL; 1743 return -EINVAL;
1806} 1744}
1807 1745
1808static ssize_t saa_read(struct file *file, char __user *buf, 1746static ssize_t saa_read(struct file *file, char __user * buf,
1809 size_t count, loff_t *ppos) 1747 size_t count, loff_t * ppos)
1810{ 1748{
1811 return -EINVAL; 1749 return -EINVAL;
1812} 1750}
1813 1751
1814static ssize_t saa_write(struct file *file, const char __user *buf, 1752static ssize_t saa_write(struct file *file, const char __user * buf,
1815 size_t count, loff_t *ppos) 1753 size_t count, loff_t * ppos)
1816{ 1754{
1817 struct saa7146 *saa = file->private_data; 1755 struct saa7146 *saa = file->private_data;
1818 unsigned long todo = count; 1756 unsigned long todo = count;
@@ -1823,20 +1761,22 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1823 if (saa->writemode == VID_WRITE_MPEG_AUD) { 1761 if (saa->writemode == VID_WRITE_MPEG_AUD) {
1824 spin_lock_irqsave(&saa->lock, flags); 1762 spin_lock_irqsave(&saa->lock, flags);
1825 if (saa->audhead <= saa->audtail) 1763 if (saa->audhead <= saa->audtail)
1826 blocksize = 65536-(saa->audtail - saa->audhead); 1764 blocksize = 65536 -
1765 (saa->audtail - saa->audhead);
1827 else 1766 else
1828 blocksize = saa->audhead - saa->audtail; 1767 blocksize = saa->audhead - saa->audtail;
1829 spin_unlock_irqrestore(&saa->lock, flags); 1768 spin_unlock_irqrestore(&saa->lock, flags);
1830 if (blocksize < 16384) { 1769 if (blocksize < 16384) {
1831 saawrite(SAA7146_PSR_DEBI_S | 1770 saawrite(SAA7146_PSR_DEBI_S |
1832 SAA7146_PSR_PIN1, SAA7146_IER); 1771 SAA7146_PSR_PIN1, SAA7146_IER);
1833 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR); 1772 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
1834 /* wait for buffer space to open */ 1773 /* wait for buffer space to open */
1835 interruptible_sleep_on(&saa->audq); 1774 interruptible_sleep_on(&saa->audq);
1836 } 1775 }
1837 spin_lock_irqsave(&saa->lock, flags); 1776 spin_lock_irqsave(&saa->lock, flags);
1838 if (saa->audhead <= saa->audtail) { 1777 if (saa->audhead <= saa->audtail) {
1839 blocksize = 65536-(saa->audtail - saa->audhead); 1778 blocksize = 65536 -
1779 (saa->audtail - saa->audhead);
1840 split = 65536 - saa->audtail; 1780 split = 65536 - saa->audtail;
1841 } else { 1781 } else {
1842 blocksize = saa->audhead - saa->audtail; 1782 blocksize = saa->audhead - saa->audtail;
@@ -1851,7 +1791,7 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1851 return -ENOSPC; 1791 return -ENOSPC;
1852 if (split < blocksize) { 1792 if (split < blocksize) {
1853 if (copy_from_user(saa->audbuf + 1793 if (copy_from_user(saa->audbuf +
1854 saa->audtail, buf, split)) 1794 saa->audtail, buf, split))
1855 return -EFAULT; 1795 return -EFAULT;
1856 buf += split; 1796 buf += split;
1857 todo -= split; 1797 todo -= split;
@@ -1859,7 +1799,7 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1859 saa->audtail = 0; 1799 saa->audtail = 0;
1860 } 1800 }
1861 if (copy_from_user(saa->audbuf + saa->audtail, buf, 1801 if (copy_from_user(saa->audbuf + saa->audtail, buf,
1862 blocksize)) 1802 blocksize))
1863 return -EFAULT; 1803 return -EFAULT;
1864 saa->audtail += blocksize; 1804 saa->audtail += blocksize;
1865 todo -= blocksize; 1805 todo -= blocksize;
@@ -1868,20 +1808,22 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1868 } else if (saa->writemode == VID_WRITE_MPEG_VID) { 1808 } else if (saa->writemode == VID_WRITE_MPEG_VID) {
1869 spin_lock_irqsave(&saa->lock, flags); 1809 spin_lock_irqsave(&saa->lock, flags);
1870 if (saa->vidhead <= saa->vidtail) 1810 if (saa->vidhead <= saa->vidtail)
1871 blocksize=524288-(saa->vidtail - saa->vidhead); 1811 blocksize = 524288 -
1812 (saa->vidtail - saa->vidhead);
1872 else 1813 else
1873 blocksize = saa->vidhead - saa->vidtail; 1814 blocksize = saa->vidhead - saa->vidtail;
1874 spin_unlock_irqrestore(&saa->lock, flags); 1815 spin_unlock_irqrestore(&saa->lock, flags);
1875 if (blocksize < 65536) { 1816 if (blocksize < 65536) {
1876 saawrite(SAA7146_PSR_DEBI_S | 1817 saawrite(SAA7146_PSR_DEBI_S |
1877 SAA7146_PSR_PIN1, SAA7146_IER); 1818 SAA7146_PSR_PIN1, SAA7146_IER);
1878 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR); 1819 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
1879 /* wait for buffer space to open */ 1820 /* wait for buffer space to open */
1880 interruptible_sleep_on(&saa->vidq); 1821 interruptible_sleep_on(&saa->vidq);
1881 } 1822 }
1882 spin_lock_irqsave(&saa->lock, flags); 1823 spin_lock_irqsave(&saa->lock, flags);
1883 if (saa->vidhead <= saa->vidtail) { 1824 if (saa->vidhead <= saa->vidtail) {
1884 blocksize=524288-(saa->vidtail - saa->vidhead); 1825 blocksize = 524288 -
1826 (saa->vidtail - saa->vidhead);
1885 split = 524288 - saa->vidtail; 1827 split = 524288 - saa->vidtail;
1886 } else { 1828 } else {
1887 blocksize = saa->vidhead - saa->vidtail; 1829 blocksize = saa->vidhead - saa->vidtail;
@@ -1896,7 +1838,7 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1896 return -ENOSPC; 1838 return -ENOSPC;
1897 if (split < blocksize) { 1839 if (split < blocksize) {
1898 if (copy_from_user(saa->vidbuf + 1840 if (copy_from_user(saa->vidbuf +
1899 saa->vidtail, buf, split)) 1841 saa->vidtail, buf, split))
1900 return -EFAULT; 1842 return -EFAULT;
1901 buf += split; 1843 buf += split;
1902 todo -= split; 1844 todo -= split;
@@ -1904,7 +1846,7 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1904 saa->vidtail = 0; 1846 saa->vidtail = 0;
1905 } 1847 }
1906 if (copy_from_user(saa->vidbuf + saa->vidtail, buf, 1848 if (copy_from_user(saa->vidbuf + saa->vidtail, buf,
1907 blocksize)) 1849 blocksize))
1908 return -EFAULT; 1850 return -EFAULT;
1909 saa->vidtail += blocksize; 1851 saa->vidtail += blocksize;
1910 todo -= blocksize; 1852 todo -= blocksize;
@@ -1922,8 +1864,8 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1922 debiwrite(saa, debNormal, IBM_MP2_OSD_LINK_ADDR, 0, 2); 1864 debiwrite(saa, debNormal, IBM_MP2_OSD_LINK_ADDR, 0, 2);
1923 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00d, 2); 1865 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00d, 2);
1924 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 1866 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
1925 debiread(saa, debNormal, 1867 debiread(saa, debNormal,
1926 IBM_MP2_DISP_MODE, 2) | 1, 2); 1868 IBM_MP2_DISP_MODE, 2) | 1, 2);
1927 /* trigger osd data transfer */ 1869 /* trigger osd data transfer */
1928 saawrite(SAA7146_PSR_DEBI_S | 1870 saawrite(SAA7146_PSR_DEBI_S |
1929 SAA7146_PSR_PIN1, SAA7146_IER); 1871 SAA7146_PSR_PIN1, SAA7146_IER);
@@ -1935,21 +1877,11 @@ static ssize_t saa_write(struct file *file, const char __user *buf,
1935 1877
1936static int saa_open(struct inode *inode, struct file *file) 1878static int saa_open(struct inode *inode, struct file *file)
1937{ 1879{
1938 struct saa7146 *saa = NULL; 1880 struct video_device *vdev = video_devdata(file);
1939 unsigned int minor = iminor(inode); 1881 struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev);
1940 int i;
1941 1882
1942 for (i = 0; i < SAA7146_MAX; i++) {
1943 if (saa7146s[i].video_dev.minor == minor) {
1944 saa = &saa7146s[i];
1945 }
1946 }
1947 if (saa == NULL) {
1948 return -ENODEV;
1949 }
1950 file->private_data = saa; 1883 file->private_data = saa;
1951 1884
1952 //saa->video_dev.busy = 0; /* old hack to support multiple open */
1953 saa->user++; 1885 saa->user++;
1954 if (saa->user > 1) 1886 if (saa->user > 1)
1955 return 0; /* device open already, don't reset */ 1887 return 0; /* device open already, don't reset */
@@ -1961,43 +1893,39 @@ static int saa_release(struct inode *inode, struct file *file)
1961{ 1893{
1962 struct saa7146 *saa = file->private_data; 1894 struct saa7146 *saa = file->private_data;
1963 saa->user--; 1895 saa->user--;
1964 //saa->video_dev.busy = 0; /* old hack to support multiple open */ 1896
1965 if (saa->user > 0) /* still someone using device */ 1897 if (saa->user > 0) /* still someone using device */
1966 return 0; 1898 return 0;
1967 saawrite(0x007f0000, SAA7146_MC1); /* stop all overlay dma */ 1899 saawrite(0x007f0000, SAA7146_MC1); /* stop all overlay dma */
1968 return 0; 1900 return 0;
1969} 1901}
1970 1902
1971static struct file_operations saa_fops = 1903static struct file_operations saa_fops = {
1972{ 1904 .owner = THIS_MODULE,
1973 .owner = THIS_MODULE, 1905 .open = saa_open,
1974 .open = saa_open, 1906 .release = saa_release,
1975 .release = saa_release, 1907 .ioctl = saa_ioctl,
1976 .ioctl = saa_ioctl, 1908 .compat_ioctl = v4l_compat_ioctl32,
1977 .compat_ioctl = v4l_compat_ioctl32, 1909 .read = saa_read,
1978 .read = saa_read, 1910 .llseek = no_llseek,
1979 .llseek = no_llseek, 1911 .write = saa_write,
1980 .write = saa_write, 1912 .mmap = saa_mmap,
1981 .mmap = saa_mmap,
1982}; 1913};
1983 1914
1984/* template for video_device-structure */ 1915/* template for video_device-structure */
1985static struct video_device saa_template = 1916static struct video_device saa_template = {
1986{ 1917 .name = "SAA7146A",
1987 .name = "SAA7146A", 1918 .type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY,
1988 .type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY, 1919 .hardware = VID_HARDWARE_SAA7146,
1989 .hardware = VID_HARDWARE_SAA7146, 1920 .fops = &saa_fops,
1990 .fops = &saa_fops, 1921 .minor = -1,
1991 .minor = -1,
1992}; 1922};
1993 1923
1994static int configure_saa7146(struct pci_dev *dev, int num) 1924static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
1995{ 1925{
1996 int result; 1926 int retval;
1997 struct saa7146 *saa; 1927 struct saa7146 *saa = pci_get_drvdata(pdev);
1998 1928
1999 saa = &saa7146s[num];
2000
2001 saa->endmarkhead = saa->endmarktail = 0; 1929 saa->endmarkhead = saa->endmarktail = 0;
2002 saa->win.x = saa->win.y = 0; 1930 saa->win.x = saa->win.y = 0;
2003 saa->win.width = saa->win.cropwidth = 720; 1931 saa->win.width = saa->win.cropwidth = 720;
@@ -2013,7 +1941,6 @@ static int configure_saa7146(struct pci_dev *dev, int num)
2013 saa->picture.contrast = 38768; 1941 saa->picture.contrast = 38768;
2014 saa->picture.colour = 32768; 1942 saa->picture.colour = 32768;
2015 saa->cap = 0; 1943 saa->cap = 0;
2016 saa->dev = dev;
2017 saa->nr = num; 1944 saa->nr = num;
2018 saa->playmode = VID_PLAY_NORMAL; 1945 saa->playmode = VID_PLAY_NORMAL;
2019 memset(saa->boardcfg, 0, 64); /* clear board config area */ 1946 memset(saa->boardcfg, 0, 64); /* clear board config area */
@@ -2033,45 +1960,59 @@ static int configure_saa7146(struct pci_dev *dev, int num)
2033 init_waitqueue_head(&saa->vidq); 1960 init_waitqueue_head(&saa->vidq);
2034 spin_lock_init(&saa->lock); 1961 spin_lock_init(&saa->lock);
2035 1962
2036 if (pci_enable_device(dev)) 1963 retval = pci_enable_device(pdev);
2037 return -EIO; 1964 if (retval) {
2038 1965 dev_err(&pdev->dev, "%d: pci_enable_device failed!\n", num);
2039 saa->id = dev->device; 1966 goto err;
2040 saa->irq = dev->irq; 1967 }
1968
1969 saa->id = pdev->device;
1970 saa->irq = pdev->irq;
2041 saa->video_dev.minor = -1; 1971 saa->video_dev.minor = -1;
2042 saa->saa7146_adr = pci_resource_start(dev, 0); 1972 saa->saa7146_adr = pci_resource_start(pdev, 0);
2043 pci_read_config_byte(dev, PCI_CLASS_REVISION, &saa->revision); 1973 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &saa->revision);
2044 1974
2045 saa->saa7146_mem = ioremap(saa->saa7146_adr, 0x200); 1975 saa->saa7146_mem = ioremap(saa->saa7146_adr, 0x200);
2046 if (!saa->saa7146_mem) 1976 if (saa->saa7146_mem == NULL) {
2047 return -EIO; 1977 dev_err(&pdev->dev, "%d: ioremap failed!\n", num);
1978 retval = -EIO;
1979 goto err;
1980 }
2048 1981
2049 memcpy(&saa->video_dev, &saa_template, sizeof(saa_template)); 1982 memcpy(&saa->video_dev, &saa_template, sizeof(saa_template));
2050 saawrite(0, SAA7146_IER); /* turn off all interrupts */ 1983 saawrite(0, SAA7146_IER); /* turn off all interrupts */
2051 result = request_irq(saa->irq, saa7146_irq, 1984
2052 SA_SHIRQ | SA_INTERRUPT, "stradis", (void *) saa); 1985 retval = request_irq(saa->irq, saa7146_irq, SA_SHIRQ | SA_INTERRUPT,
2053 if (result == -EINVAL) 1986 "stradis", saa);
2054 printk(KERN_ERR "stradis%d: Bad irq number or handler\n", 1987 if (retval == -EINVAL)
2055 num); 1988 dev_err(&pdev->dev, "%d: Bad irq number or handler\n", num);
2056 if (result == -EBUSY) 1989 else if (retval == -EBUSY)
2057 printk(KERN_ERR "stradis%d: IRQ %ld busy, change your PnP" 1990 dev_err(&pdev->dev, "%d: IRQ %ld busy, change your PnP config "
2058 " config in BIOS\n", num, saa->irq); 1991 "in BIOS\n", num, saa->irq);
2059 if (result < 0) { 1992 if (retval < 0)
2060 iounmap(saa->saa7146_mem); 1993 goto errio;
2061 return result; 1994
2062 } 1995 pci_set_master(pdev);
2063 pci_set_master(dev); 1996 retval = video_register_device(&saa->video_dev, VFL_TYPE_GRABBER,
2064 if (video_register_device(&saa->video_dev, VFL_TYPE_GRABBER, video_nr) < 0) { 1997 video_nr);
2065 iounmap(saa->saa7146_mem); 1998 if (retval < 0) {
2066 return -1; 1999 dev_err(&pdev->dev, "%d: error in registering video device!\n",
2000 num);
2001 goto errio;
2067 } 2002 }
2003
2068 return 0; 2004 return 0;
2005errio:
2006 iounmap(saa->saa7146_mem);
2007err:
2008 return retval;
2069} 2009}
2070 2010
2071static int init_saa7146(int i) 2011static int __devinit init_saa7146(struct pci_dev *pdev)
2072{ 2012{
2073 struct saa7146 *saa = &saa7146s[i]; 2013 struct saa7146 *saa = pci_get_drvdata(pdev);
2074 2014
2015 memset(saa, 0, sizeof(*saa));
2075 saa->user = 0; 2016 saa->user = 0;
2076 /* reset the saa7146 */ 2017 /* reset the saa7146 */
2077 saawrite(0xffff0000, SAA7146_MC1); 2018 saawrite(0xffff0000, SAA7146_MC1);
@@ -2089,23 +2030,23 @@ static int init_saa7146(int i)
2089 saawrite(0x00000000, SAA7146_DD1_STREAM_A); 2030 saawrite(0x00000000, SAA7146_DD1_STREAM_A);
2090 saawrite(0x00000000, SAA7146_BRS_CTRL); 2031 saawrite(0x00000000, SAA7146_BRS_CTRL);
2091 saawrite(0x80400040, SAA7146_BCS_CTRL); 2032 saawrite(0x80400040, SAA7146_BCS_CTRL);
2092 saawrite(0x0000e000 /*| (1<<29)*/, SAA7146_HPS_CTRL); 2033 saawrite(0x0000e000 /*| (1<<29) */ , SAA7146_HPS_CTRL);
2093 saawrite(0x00000060, SAA7146_CLIP_FORMAT_CTRL); 2034 saawrite(0x00000060, SAA7146_CLIP_FORMAT_CTRL);
2094 saawrite(0x00000000, SAA7146_ACON1); 2035 saawrite(0x00000000, SAA7146_ACON1);
2095 saawrite(0x00000000, SAA7146_ACON2); 2036 saawrite(0x00000000, SAA7146_ACON2);
2096 saawrite(0x00000600, SAA7146_I2C_STATUS); 2037 saawrite(0x00000600, SAA7146_I2C_STATUS);
2097 saawrite(((SAA7146_MC2_UPLD_D1_B | SAA7146_MC2_UPLD_D1_A | 2038 saawrite(((SAA7146_MC2_UPLD_D1_B | SAA7146_MC2_UPLD_D1_A |
2098 SAA7146_MC2_UPLD_BRS | SAA7146_MC2_UPLD_HPS_H | 2039 SAA7146_MC2_UPLD_BRS | SAA7146_MC2_UPLD_HPS_H |
2099 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_DMA2 | 2040 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_DMA2 |
2100 SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_I2C) << 16) | 0xffff, 2041 SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_I2C) << 16) | 0xffff,
2101 SAA7146_MC2); 2042 SAA7146_MC2);
2102 /* setup arbitration control registers */ 2043 /* setup arbitration control registers */
2103 saawrite(0x1412121a, SAA7146_PCI_BT_V1); 2044 saawrite(0x1412121a, SAA7146_PCI_BT_V1);
2104 2045
2105 /* allocate 32k dma buffer + 4k for page table */ 2046 /* allocate 32k dma buffer + 4k for page table */
2106 if ((saa->dmadebi = kmalloc(32768 + 4096, GFP_KERNEL)) == NULL) { 2047 if ((saa->dmadebi = kmalloc(32768 + 4096, GFP_KERNEL)) == NULL) {
2107 printk(KERN_ERR "stradis%d: debi kmalloc failed\n", i); 2048 dev_err(&pdev->dev, "%d: debi kmalloc failed\n", saa->nr);
2108 return -1; 2049 goto err;
2109 } 2050 }
2110#if 0 2051#if 0
2111 saa->pagedebi = saa->dmadebi + 32768; /* top 4k is for mmu */ 2052 saa->pagedebi = saa->dmadebi + 32768; /* top 4k is for mmu */
@@ -2115,133 +2056,162 @@ static int init_saa7146(int i)
2115#endif 2056#endif
2116 saa->audhead = saa->vidhead = saa->osdhead = 0; 2057 saa->audhead = saa->vidhead = saa->osdhead = 0;
2117 saa->audtail = saa->vidtail = saa->osdtail = 0; 2058 saa->audtail = saa->vidtail = saa->osdtail = 0;
2118 if (saa->vidbuf == NULL) 2059 if (saa->vidbuf == NULL && (saa->vidbuf = vmalloc(524288)) == NULL) {
2119 if ((saa->vidbuf = vmalloc(524288)) == NULL) { 2060 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2120 printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr); 2061 goto err;
2121 return -ENOMEM; 2062 }
2122 } 2063 if (saa->audbuf == NULL && (saa->audbuf = vmalloc(65536)) == NULL) {
2123 if (saa->audbuf == NULL) 2064 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2124 if ((saa->audbuf = vmalloc(65536)) == NULL) { 2065 goto errvid;
2125 printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr); 2066 }
2126 vfree(saa->vidbuf); 2067 if (saa->osdbuf == NULL && (saa->osdbuf = vmalloc(131072)) == NULL) {
2127 saa->vidbuf = NULL; 2068 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2128 return -ENOMEM; 2069 goto erraud;
2129 } 2070 }
2130 if (saa->osdbuf == NULL)
2131 if ((saa->osdbuf = vmalloc(131072)) == NULL) {
2132 printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
2133 vfree(saa->vidbuf);
2134 vfree(saa->audbuf);
2135 saa->vidbuf = saa->audbuf = NULL;
2136 return -ENOMEM;
2137 }
2138 /* allocate 81920 byte buffer for clipping */ 2071 /* allocate 81920 byte buffer for clipping */
2139 if ((saa->dmavid2 = kmalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) { 2072 if ((saa->dmavid2 = kzalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) {
2140 printk(KERN_ERR "stradis%d: clip kmalloc failed\n", saa->nr); 2073 dev_err(&pdev->dev, "%d: clip kmalloc failed\n", saa->nr);
2141 vfree(saa->vidbuf); 2074 goto errosd;
2142 vfree(saa->audbuf);
2143 vfree(saa->osdbuf);
2144 saa->vidbuf = saa->audbuf = saa->osdbuf = NULL;
2145 saa->dmavid2 = NULL;
2146 return -1;
2147 } 2075 }
2148 memset(saa->dmavid2, 0x00, VIDEO_CLIPMAP_SIZE); /* clip everything */
2149 /* setup clipping registers */ 2076 /* setup clipping registers */
2150 saawrite(virt_to_bus(saa->dmavid2), SAA7146_BASE_EVEN2); 2077 saawrite(virt_to_bus(saa->dmavid2), SAA7146_BASE_EVEN2);
2151 saawrite(virt_to_bus(saa->dmavid2) + 128, SAA7146_BASE_ODD2); 2078 saawrite(virt_to_bus(saa->dmavid2) + 128, SAA7146_BASE_ODD2);
2152 saawrite(virt_to_bus(saa->dmavid2) + VIDEO_CLIPMAP_SIZE, 2079 saawrite(virt_to_bus(saa->dmavid2) + VIDEO_CLIPMAP_SIZE,
2153 SAA7146_PROT_ADDR2); 2080 SAA7146_PROT_ADDR2);
2154 saawrite(256, SAA7146_PITCH2); 2081 saawrite(256, SAA7146_PITCH2);
2155 saawrite(4, SAA7146_PAGE2); /* dma direction: read, no byteswap */ 2082 saawrite(4, SAA7146_PAGE2); /* dma direction: read, no byteswap */
2156 saawrite(((SAA7146_MC2_UPLD_DMA2) << 16) | SAA7146_MC2_UPLD_DMA2, 2083 saawrite(((SAA7146_MC2_UPLD_DMA2) << 16) | SAA7146_MC2_UPLD_DMA2,
2157 SAA7146_MC2); 2084 SAA7146_MC2);
2158 I2CBusScan(saa); 2085 I2CBusScan(saa);
2086
2159 return 0; 2087 return 0;
2088errosd:
2089 vfree(saa->osdbuf);
2090 saa->osdbuf = NULL;
2091erraud:
2092 vfree(saa->audbuf);
2093 saa->audbuf = NULL;
2094errvid:
2095 vfree(saa->vidbuf);
2096 saa->vidbuf = NULL;
2097err:
2098 return -ENOMEM;
2160} 2099}
2161 2100
2162static void release_saa(void) 2101static void stradis_release_saa(struct pci_dev *pdev)
2163{ 2102{
2164 u8 command; 2103 u8 command;
2165 int i; 2104 struct saa7146 *saa = pci_get_drvdata(pdev);
2166 struct saa7146 *saa;
2167 2105
2168 for (i = 0; i < saa_num; i++) { 2106 /* turn off all capturing, DMA and IRQs */
2169 saa = &saa7146s[i]; 2107 saawrite(0xffff0000, SAA7146_MC1); /* reset chip */
2108 saawrite(0, SAA7146_MC2);
2109 saawrite(0, SAA7146_IER);
2110 saawrite(0xffffffffUL, SAA7146_ISR);
2111
2112 /* disable PCI bus-mastering */
2113 pci_read_config_byte(pdev, PCI_COMMAND, &command);
2114 command &= ~PCI_COMMAND_MASTER;
2115 pci_write_config_byte(pdev, PCI_COMMAND, command);
2116
2117 /* unmap and free memory */
2118 saa->audhead = saa->audtail = saa->osdhead = 0;
2119 saa->vidhead = saa->vidtail = saa->osdtail = 0;
2120 vfree(saa->vidbuf);
2121 vfree(saa->audbuf);
2122 vfree(saa->osdbuf);
2123 kfree(saa->dmavid2);
2124 saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
2125 saa->dmavid2 = NULL;
2126 kfree(saa->dmadebi);
2127 kfree(saa->dmavid1);
2128 kfree(saa->dmavid3);
2129 kfree(saa->dmaa1in);
2130 kfree(saa->dmaa1out);
2131 kfree(saa->dmaa2in);
2132 kfree(saa->dmaa2out);
2133 kfree(saa->dmaRPS1);
2134 kfree(saa->dmaRPS2);
2135 free_irq(saa->irq, saa);
2136 if (saa->saa7146_mem)
2137 iounmap(saa->saa7146_mem);
2138 if (saa->video_dev.minor != -1)
2139 video_unregister_device(&saa->video_dev);
2140}
2170 2141
2171 /* turn off all capturing, DMA and IRQs */ 2142static int __devinit stradis_probe(struct pci_dev *pdev,
2172 saawrite(0xffff0000, SAA7146_MC1); /* reset chip */ 2143 const struct pci_device_id *ent)
2173 saawrite(0, SAA7146_MC2); 2144{
2174 saawrite(0, SAA7146_IER); 2145 int retval = -EINVAL;
2175 saawrite(0xffffffffUL, SAA7146_ISR); 2146
2176 2147 if (saa_num >= SAA7146_MAX)
2177 /* disable PCI bus-mastering */ 2148 goto err;
2178 pci_read_config_byte(saa->dev, PCI_COMMAND, &command); 2149
2179 command &= ~PCI_COMMAND_MASTER; 2150 if (!pdev->subsystem_vendor)
2180 pci_write_config_byte(saa->dev, PCI_COMMAND, command); 2151 dev_info(&pdev->dev, "%d: rev1 decoder\n", saa_num);
2181 2152 else
2182 /* unmap and free memory */ 2153 dev_info(&pdev->dev, "%d: SDM2xx found\n", saa_num);
2183 saa->audhead = saa->audtail = saa->osdhead = 0; 2154
2184 saa->vidhead = saa->vidtail = saa->osdtail = 0; 2155 pci_set_drvdata(pdev, &saa7146s[saa_num]);
2185 vfree(saa->vidbuf); 2156
2186 vfree(saa->audbuf); 2157 retval = configure_saa7146(pdev, saa_num);
2187 vfree(saa->osdbuf); 2158 if (retval) {
2188 kfree(saa->dmavid2); 2159 dev_err(&pdev->dev, "%d: error in configuring\n", saa_num);
2189 saa->audbuf = saa->vidbuf = saa->osdbuf = NULL; 2160 goto err;
2190 saa->dmavid2 = NULL; 2161 }
2191 kfree(saa->dmadebi); 2162
2192 kfree(saa->dmavid1); 2163 if (init_saa7146(pdev) < 0) {
2193 kfree(saa->dmavid3); 2164 dev_err(&pdev->dev, "%d: error in initialization\n", saa_num);
2194 kfree(saa->dmaa1in); 2165 retval = -EIO;
2195 kfree(saa->dmaa1out); 2166 goto errrel;
2196 kfree(saa->dmaa2in);
2197 kfree(saa->dmaa2out);
2198 kfree(saa->dmaRPS1);
2199 kfree(saa->dmaRPS2);
2200 free_irq(saa->irq, saa);
2201 if (saa->saa7146_mem)
2202 iounmap(saa->saa7146_mem);
2203 if (saa->video_dev.minor != -1)
2204 video_unregister_device(&saa->video_dev);
2205 } 2167 }
2168
2169 saa_num++;
2170
2171 return 0;
2172errrel:
2173 stradis_release_saa(pdev);
2174err:
2175 return retval;
2176}
2177
2178static void __devexit stradis_remove(struct pci_dev *pdev)
2179{
2180 stradis_release_saa(pdev);
2206} 2181}
2207 2182
2183static struct pci_device_id stradis_pci_tbl[] = {
2184 { PCI_DEVICE(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146) },
2185 { 0 }
2186};
2187
2188MODULE_DEVICE_TABLE(pci, stradis_pci_tbl);
2189
2190static struct pci_driver stradis_driver = {
2191 .name = "stradis",
2192 .id_table = stradis_pci_tbl,
2193 .probe = stradis_probe,
2194 .remove = __devexit_p(stradis_remove)
2195};
2208 2196
2209static int __init stradis_init (void) 2197int __init stradis_init(void)
2210{ 2198{
2211 struct pci_dev *dev = NULL; 2199 int retval;
2212 int result = 0, i;
2213 2200
2214 saa_num = 0; 2201 saa_num = 0;
2215 2202
2216 while ((dev = pci_find_device(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146, dev))) { 2203 retval = pci_register_driver(&stradis_driver);
2217 if (!dev->subsystem_vendor) 2204 if (retval)
2218 printk(KERN_INFO "stradis%d: rev1 decoder\n", saa_num); 2205 printk(KERN_ERR "stradis: Unable to register pci driver.\n");
2219 else
2220 printk(KERN_INFO "stradis%d: SDM2xx found\n", saa_num);
2221 result = configure_saa7146(dev, saa_num++);
2222 if (result)
2223 return result;
2224 }
2225 if (saa_num)
2226 printk(KERN_INFO "stradis: %d card(s) found.\n", saa_num);
2227 else
2228 return -EINVAL;
2229 for (i = 0; i < saa_num; i++)
2230 if (init_saa7146(i) < 0) {
2231 release_saa();
2232 return -EIO;
2233 }
2234 return 0;
2235}
2236 2206
2207 return retval;
2208}
2237 2209
2238static void __exit stradis_exit (void) 2210void __exit stradis_exit(void)
2239{ 2211{
2240 release_saa(); 2212 pci_unregister_driver(&stradis_driver);
2241 printk(KERN_INFO "stradis: module cleanup complete\n"); 2213 printk(KERN_INFO "stradis: module cleanup complete\n");
2242} 2214}
2243 2215
2244
2245module_init(stradis_init); 2216module_init(stradis_init);
2246module_exit(stradis_exit); 2217module_exit(stradis_exit);
2247