aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/pci/cx88
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-11-19 16:27:30 -0500
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-11-25 04:50:20 -0500
commit399426cadf5b0539a5b2a4d805257ce8acc6aba2 (patch)
tree40dec68657fbd2904ec6da9c2082fd29d0f3b437 /drivers/media/pci/cx88
parent1d38971438157dc57f0a4be89abf23b472458633 (diff)
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging drivers, as it could be a mess pretty easy, and could become like a snow ball. That's the case of recent changes on two changesets: they disalign some statements. Yet, a care a lot with cx88 driver, as it was the first driver I touched at the Kernel, and I've been maintaining it since 2005. So, several of the coding style issues were due to my code. Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with fixed several other issues, did some function alinments, but broke other alinments. So, I had to manually apply another round of manual fixes to make sure that everything is ok, and to make checkpatch happy with this patch. With this patch, checkpatch.pl is now happy when called with: ./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL Also, the 80-cols violations that made sense were fixed. Checkpatch would be happier if we convert it to use dev_foo(), but this is a more complex change. NOTE: there are some places with msleep(1). As this driver was written at the time that the default was to sleep at least 10ms on such calls (e. g. CONFIG_HZ=100), I replaced those calls by usleep_range(10000, 20000), with should be safe to avoid breakages. Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros") Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier") Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/pci/cx88')
-rw-r--r--drivers/media/pci/cx88/cx88-alsa.c206
-rw-r--r--drivers/media/pci/cx88/cx88-blackbird.c169
-rw-r--r--drivers/media/pci/cx88/cx88-cards.c313
-rw-r--r--drivers/media/pci/cx88/cx88-core.c205
-rw-r--r--drivers/media/pci/cx88/cx88-dsp.c50
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c154
-rw-r--r--drivers/media/pci/cx88/cx88-i2c.c25
-rw-r--r--drivers/media/pci/cx88/cx88-input.c45
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c114
-rw-r--r--drivers/media/pci/cx88/cx88-reg.h110
-rw-r--r--drivers/media/pci/cx88/cx88-tvaudio.c63
-rw-r--r--drivers/media/pci/cx88/cx88-vbi.c19
-rw-r--r--drivers/media/pci/cx88/cx88-video.c155
-rw-r--r--drivers/media/pci/cx88/cx88-vp3054-i2c.c10
-rw-r--r--drivers/media/pci/cx88/cx88-vp3054-i2c.h38
-rw-r--r--drivers/media/pci/cx88/cx88.h171
16 files changed, 975 insertions, 872 deletions
diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
index 56770e84b3d5..c81fe4681d14 100644
--- a/drivers/media/pci/cx88/cx88-alsa.c
+++ b/drivers/media/pci/cx88/cx88-alsa.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/delay.h>
27#include <linux/device.h> 28#include <linux/device.h>
28#include <linux/interrupt.h> 29#include <linux/interrupt.h>
29#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
@@ -31,7 +32,6 @@
31#include <linux/pci.h> 32#include <linux/pci.h>
32#include <linux/slab.h> 33#include <linux/slab.h>
33 34
34#include <asm/delay.h>
35#include <sound/core.h> 35#include <sound/core.h>
36#include <sound/pcm.h> 36#include <sound/pcm.h>
37#include <sound/pcm_params.h> 37#include <sound/pcm_params.h>
@@ -46,9 +46,9 @@
46 chip->core->name, ##arg); \ 46 chip->core->name, ##arg); \
47} while (0) 47} while (0)
48 48
49/**************************************************************************** 49/*
50 Data type declarations - Can be moded to a header file later 50 * Data type declarations - Can be moded to a header file later
51 ****************************************************************************/ 51 */
52 52
53struct cx88_audio_buffer { 53struct cx88_audio_buffer {
54 unsigned int bpl; 54 unsigned int bpl;
@@ -82,13 +82,10 @@ struct cx88_audio_dev {
82 82
83 struct snd_pcm_substream *substream; 83 struct snd_pcm_substream *substream;
84}; 84};
85typedef struct cx88_audio_dev snd_cx88_card_t;
86
87
88 85
89/**************************************************************************** 86/*
90 Module global static vars 87 * Module global static vars
91 ****************************************************************************/ 88 */
92 89
93static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 90static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
94static const char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 91static const char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
@@ -100,10 +97,9 @@ MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled.");
100module_param_array(index, int, NULL, 0444); 97module_param_array(index, int, NULL, 0444);
101MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s)."); 98MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s).");
102 99
103 100/*
104/**************************************************************************** 101 * Module macros
105 Module macros 102 */
106 ****************************************************************************/
107 103
108MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards"); 104MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards");
109MODULE_AUTHOR("Ricardo Cerqueira"); 105MODULE_AUTHOR("Ricardo Cerqueira");
@@ -116,15 +112,15 @@ static unsigned int debug;
116module_param(debug, int, 0644); 112module_param(debug, int, 0644);
117MODULE_PARM_DESC(debug, "enable debug messages"); 113MODULE_PARM_DESC(debug, "enable debug messages");
118 114
119/**************************************************************************** 115/*
120 Module specific funtions 116 * Module specific functions
121 ****************************************************************************/ 117 */
122 118
123/* 119/*
124 * BOARD Specific: Sets audio DMA 120 * BOARD Specific: Sets audio DMA
125 */ 121 */
126 122
127static int _cx88_start_audio_dma(snd_cx88_card_t *chip) 123static int _cx88_start_audio_dma(struct cx88_audio_dev *chip)
128{ 124{
129 struct cx88_audio_buffer *buf = chip->buf; 125 struct cx88_audio_buffer *buf = chip->buf;
130 struct cx88_core *core = chip->core; 126 struct cx88_core *core = chip->core;
@@ -143,8 +139,9 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
143 cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET); 139 cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET);
144 atomic_set(&chip->count, 0); 140 atomic_set(&chip->count, 0);
145 141
146 dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d byte buffer\n", 142 dprintk(1,
147 buf->bpl, cx_read(audio_ch->cmds_start + 8)>>1, 143 "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d byte buffer\n",
144 buf->bpl, cx_read(audio_ch->cmds_start + 8) >> 1,
148 chip->num_periods, buf->bpl * chip->num_periods); 145 chip->num_periods, buf->bpl * chip->num_periods);
149 146
150 /* Enables corresponding bits at AUD_INT_STAT */ 147 /* Enables corresponding bits at AUD_INT_STAT */
@@ -158,8 +155,11 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
158 cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT); 155 cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT);
159 156
160 /* start dma */ 157 /* start dma */
161 cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */ 158
162 cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */ 159 /* Enables Risc Processor */
160 cx_set(MO_DEV_CNTRL2, (1 << 5));
161 /* audio downstream FIFO and RISC enable */
162 cx_set(MO_AUD_DMACNTRL, 0x11);
163 163
164 if (debug) 164 if (debug)
165 cx88_sram_channel_dump(chip->core, audio_ch); 165 cx88_sram_channel_dump(chip->core, audio_ch);
@@ -170,7 +170,7 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
170/* 170/*
171 * BOARD Specific: Resets audio DMA 171 * BOARD Specific: Resets audio DMA
172 */ 172 */
173static int _cx88_stop_audio_dma(snd_cx88_card_t *chip) 173static int _cx88_stop_audio_dma(struct cx88_audio_dev *chip)
174{ 174{
175 struct cx88_core *core = chip->core; 175 struct cx88_core *core = chip->core;
176 176
@@ -185,7 +185,8 @@ static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
185 AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1); 185 AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
186 186
187 if (debug) 187 if (debug)
188 cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); 188 cx88_sram_channel_dump(chip->core,
189 &cx88_sram_channels[SRAM_CH25]);
189 190
190 return 0; 191 return 0;
191} 192}
@@ -211,7 +212,7 @@ static const char *cx88_aud_irqs[32] = {
211/* 212/*
212 * BOARD Specific: Threats IRQ audio specific calls 213 * BOARD Specific: Threats IRQ audio specific calls
213 */ 214 */
214static void cx8801_aud_irq(snd_cx88_card_t *chip) 215static void cx8801_aud_irq(struct cx88_audio_dev *chip)
215{ 216{
216 struct cx88_core *core = chip->core; 217 struct cx88_core *core = chip->core;
217 u32 status, mask; 218 u32 status, mask;
@@ -249,7 +250,7 @@ static void cx8801_aud_irq(snd_cx88_card_t *chip)
249 */ 250 */
250static irqreturn_t cx8801_irq(int irq, void *dev_id) 251static irqreturn_t cx8801_irq(int irq, void *dev_id)
251{ 252{
252 snd_cx88_card_t *chip = dev_id; 253 struct cx88_audio_dev *chip = dev_id;
253 struct cx88_core *core = chip->core; 254 struct cx88_core *core = chip->core;
254 u32 status; 255 u32 status;
255 int loop, handled = 0; 256 int loop, handled = 0;
@@ -286,26 +287,25 @@ static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages)
286 int i; 287 int i;
287 288
288 buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); 289 buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
289 if (buf->vaddr == NULL) { 290 if (!buf->vaddr) {
290 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); 291 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
291 return -ENOMEM; 292 return -ENOMEM;
292 } 293 }
293 294
294 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", 295 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
295 (unsigned long)buf->vaddr, 296 (unsigned long)buf->vaddr, nr_pages << PAGE_SHIFT);
296 nr_pages << PAGE_SHIFT);
297 297
298 memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); 298 memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT);
299 buf->nr_pages = nr_pages; 299 buf->nr_pages = nr_pages;
300 300
301 buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); 301 buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist));
302 if (buf->sglist == NULL) 302 if (!buf->sglist)
303 goto vzalloc_err; 303 goto vzalloc_err;
304 304
305 sg_init_table(buf->sglist, buf->nr_pages); 305 sg_init_table(buf->sglist, buf->nr_pages);
306 for (i = 0; i < buf->nr_pages; i++) { 306 for (i = 0; i < buf->nr_pages; i++) {
307 pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); 307 pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE);
308 if (pg == NULL) 308 if (!pg)
309 goto vmalloc_to_page_err; 309 goto vmalloc_to_page_err;
310 sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); 310 sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0);
311 } 311 }
@@ -341,7 +341,8 @@ static int cx88_alsa_dma_unmap(struct cx88_audio_dev *dev)
341 if (!buf->sglen) 341 if (!buf->sglen)
342 return 0; 342 return 0;
343 343
344 dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE); 344 dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen,
345 PCI_DMA_FROMDEVICE);
345 buf->sglen = 0; 346 buf->sglen = 0;
346 return 0; 347 return 0;
347} 348}
@@ -355,18 +356,18 @@ static int cx88_alsa_dma_free(struct cx88_audio_buffer *buf)
355 return 0; 356 return 0;
356} 357}
357 358
358 359static int dsp_buffer_free(struct cx88_audio_dev *chip)
359static int dsp_buffer_free(snd_cx88_card_t *chip)
360{ 360{
361 struct cx88_riscmem *risc = &chip->buf->risc; 361 struct cx88_riscmem *risc = &chip->buf->risc;
362 362
363 BUG_ON(!chip->dma_size); 363 WARN_ON(!chip->dma_size);
364 364
365 dprintk(2, "Freeing buffer\n"); 365 dprintk(2, "Freeing buffer\n");
366 cx88_alsa_dma_unmap(chip); 366 cx88_alsa_dma_unmap(chip);
367 cx88_alsa_dma_free(chip->buf); 367 cx88_alsa_dma_free(chip->buf);
368 if (risc->cpu) 368 if (risc->cpu)
369 pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma); 369 pci_free_consistent(chip->pci, risc->size,
370 risc->cpu, risc->dma);
370 kfree(chip->buf); 371 kfree(chip->buf);
371 372
372 chip->buf = NULL; 373 chip->buf = NULL;
@@ -374,9 +375,9 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
374 return 0; 375 return 0;
375} 376}
376 377
377/**************************************************************************** 378/*
378 ALSA PCM Interface 379 * ALSA PCM Interface
379 ****************************************************************************/ 380 */
380 381
381/* 382/*
382 * Digital hardware definition 383 * Digital hardware definition
@@ -394,13 +395,15 @@ static const struct snd_pcm_hardware snd_cx88_digital_hw = {
394 .rate_max = 48000, 395 .rate_max = 48000,
395 .channels_min = 2, 396 .channels_min = 2,
396 .channels_max = 2, 397 .channels_max = 2,
397 /* Analog audio output will be full of clicks and pops if there 398 /*
398 are not exactly four lines in the SRAM FIFO buffer. */ 399 * Analog audio output will be full of clicks and pops if there
399 .period_bytes_min = DEFAULT_FIFO_SIZE/4, 400 * are not exactly four lines in the SRAM FIFO buffer.
400 .period_bytes_max = DEFAULT_FIFO_SIZE/4, 401 */
402 .period_bytes_min = DEFAULT_FIFO_SIZE / 4,
403 .period_bytes_max = DEFAULT_FIFO_SIZE / 4,
401 .periods_min = 1, 404 .periods_min = 1,
402 .periods_max = 1024, 405 .periods_max = 1024,
403 .buffer_bytes_max = (1024*1024), 406 .buffer_bytes_max = (1024 * 1024),
404}; 407};
405 408
406/* 409/*
@@ -408,7 +411,7 @@ static const struct snd_pcm_hardware snd_cx88_digital_hw = {
408 */ 411 */
409static int snd_cx88_pcm_open(struct snd_pcm_substream *substream) 412static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
410{ 413{
411 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 414 struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
412 struct snd_pcm_runtime *runtime = substream->runtime; 415 struct snd_pcm_runtime *runtime = substream->runtime;
413 int err; 416 int err;
414 417
@@ -417,7 +420,8 @@ static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
417 return -ENODEV; 420 return -ENODEV;
418 } 421 }
419 422
420 err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS); 423 err = snd_pcm_hw_constraint_pow2(runtime, 0,
424 SNDRV_PCM_HW_PARAM_PERIODS);
421 if (err < 0) 425 if (err < 0)
422 goto _error; 426 goto _error;
423 427
@@ -453,7 +457,7 @@ static int snd_cx88_close(struct snd_pcm_substream *substream)
453static int snd_cx88_hw_params(struct snd_pcm_substream *substream, 457static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
454 struct snd_pcm_hw_params *hw_params) 458 struct snd_pcm_hw_params *hw_params)
455{ 459{
456 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 460 struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
457 461
458 struct cx88_audio_buffer *buf; 462 struct cx88_audio_buffer *buf;
459 int ret; 463 int ret;
@@ -467,18 +471,18 @@ static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
467 chip->num_periods = params_periods(hw_params); 471 chip->num_periods = params_periods(hw_params);
468 chip->dma_size = chip->period_size * params_periods(hw_params); 472 chip->dma_size = chip->period_size * params_periods(hw_params);
469 473
470 BUG_ON(!chip->dma_size); 474 WARN_ON(!chip->dma_size);
471 BUG_ON(chip->num_periods & (chip->num_periods-1)); 475 WARN_ON(chip->num_periods & (chip->num_periods - 1));
472 476
473 buf = kzalloc(sizeof(*buf), GFP_KERNEL); 477 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
474 if (buf == NULL) 478 if (!buf)
475 return -ENOMEM; 479 return -ENOMEM;
476 480
477 chip->buf = buf; 481 chip->buf = buf;
478 buf->bpl = chip->period_size; 482 buf->bpl = chip->period_size;
479 483
480 ret = cx88_alsa_dma_init(chip, 484 ret = cx88_alsa_dma_init(chip,
481 (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); 485 (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
482 if (ret < 0) 486 if (ret < 0)
483 goto error; 487 goto error;
484 488
@@ -492,7 +496,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
492 goto error; 496 goto error;
493 497
494 /* Loop back to start of program */ 498 /* Loop back to start of program */
495 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); 499 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
496 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 500 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
497 501
498 substream->runtime->dma_area = chip->buf->vaddr; 502 substream->runtime->dma_area = chip->buf->vaddr;
@@ -510,8 +514,7 @@ error:
510 */ 514 */
511static int snd_cx88_hw_free(struct snd_pcm_substream *substream) 515static int snd_cx88_hw_free(struct snd_pcm_substream *substream)
512{ 516{
513 517 struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
514 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
515 518
516 if (substream->runtime->dma_area) { 519 if (substream->runtime->dma_area) {
517 dsp_buffer_free(chip); 520 dsp_buffer_free(chip);
@@ -534,7 +537,7 @@ static int snd_cx88_prepare(struct snd_pcm_substream *substream)
534 */ 537 */
535static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd) 538static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
536{ 539{
537 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 540 struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
538 int err; 541 int err;
539 542
540 /* Local interrupts are already disabled by ALSA */ 543 /* Local interrupts are already disabled by ALSA */
@@ -562,7 +565,7 @@ static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
562 */ 565 */
563static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream) 566static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
564{ 567{
565 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 568 struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
566 struct snd_pcm_runtime *runtime = substream->runtime; 569 struct snd_pcm_runtime *runtime = substream->runtime;
567 u16 count; 570 u16 count;
568 571
@@ -571,14 +574,14 @@ static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
571// dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__, 574// dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__,
572// count, new, count & (runtime->periods-1), 575// count, new, count & (runtime->periods-1),
573// runtime->period_size * (count & (runtime->periods-1))); 576// runtime->period_size * (count & (runtime->periods-1)));
574 return runtime->period_size * (count & (runtime->periods-1)); 577 return runtime->period_size * (count & (runtime->periods - 1));
575} 578}
576 579
577/* 580/*
578 * page callback (needed for mmap) 581 * page callback (needed for mmap)
579 */ 582 */
580static struct page *snd_cx88_page(struct snd_pcm_substream *substream, 583static struct page *snd_cx88_page(struct snd_pcm_substream *substream,
581 unsigned long offset) 584 unsigned long offset)
582{ 585{
583 void *pageptr = substream->runtime->dma_area + offset; 586 void *pageptr = substream->runtime->dma_area + offset;
584 587
@@ -603,7 +606,8 @@ static const struct snd_pcm_ops snd_cx88_pcm_ops = {
603/* 606/*
604 * create a PCM device 607 * create a PCM device
605 */ 608 */
606static int snd_cx88_pcm(snd_cx88_card_t *chip, int device, const char *name) 609static int snd_cx88_pcm(struct cx88_audio_dev *chip, int device,
610 const char *name)
607{ 611{
608 int err; 612 int err;
609 struct snd_pcm *pcm; 613 struct snd_pcm *pcm;
@@ -618,9 +622,9 @@ static int snd_cx88_pcm(snd_cx88_card_t *chip, int device, const char *name)
618 return 0; 622 return 0;
619} 623}
620 624
621/**************************************************************************** 625/*
622 CONTROL INTERFACE 626 * CONTROL INTERFACE
623 ****************************************************************************/ 627 */
624static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol, 628static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *info) 629 struct snd_ctl_elem_info *info)
626{ 630{
@@ -635,7 +639,7 @@ static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol,
635static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol, 639static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_value *value) 640 struct snd_ctl_elem_value *value)
637{ 641{
638 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 642 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
639 struct cx88_core *core = chip->core; 643 struct cx88_core *core = chip->core;
640 int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f), 644 int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f),
641 bal = cx_read(AUD_BAL_CTL); 645 bal = cx_read(AUD_BAL_CTL);
@@ -648,9 +652,9 @@ static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol,
648} 652}
649 653
650static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol, 654static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *value) 655 struct snd_ctl_elem_value *value)
652{ 656{
653 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 657 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
654 struct cx88_core *core = chip->core; 658 struct cx88_core *core = chip->core;
655 int left = value->value.integer.value[0]; 659 int left = value->value.integer.value[0];
656 int right = value->value.integer.value[1]; 660 int right = value->value.integer.value[1];
@@ -672,7 +676,7 @@ static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol,
672static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol, 676static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *value) 677 struct snd_ctl_elem_value *value)
674{ 678{
675 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 679 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
676 struct cx88_core *core = chip->core; 680 struct cx88_core *core = chip->core;
677 int left, right, v, b; 681 int left, right, v, b;
678 int changed = 0; 682 int changed = 0;
@@ -722,7 +726,7 @@ static const struct snd_kcontrol_new snd_cx88_volume = {
722static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol, 726static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *value) 727 struct snd_ctl_elem_value *value)
724{ 728{
725 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 729 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
726 struct cx88_core *core = chip->core; 730 struct cx88_core *core = chip->core;
727 u32 bit = kcontrol->private_value; 731 u32 bit = kcontrol->private_value;
728 732
@@ -731,9 +735,9 @@ static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol,
731} 735}
732 736
733static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol, 737static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
734 struct snd_ctl_elem_value *value) 738 struct snd_ctl_elem_value *value)
735{ 739{
736 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 740 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
737 struct cx88_core *core = chip->core; 741 struct cx88_core *core = chip->core;
738 u32 bit = kcontrol->private_value; 742 u32 bit = kcontrol->private_value;
739 int ret = 0; 743 int ret = 0;
@@ -745,8 +749,9 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
745 vol ^= bit; 749 vol ^= bit;
746 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol); 750 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol);
747 /* Pass mute onto any WM8775 */ 751 /* Pass mute onto any WM8775 */
748 if (core->sd_wm8775 && ((1<<6) == bit)) 752 if (core->sd_wm8775 && ((1 << 6) == bit))
749 wm8775_s_ctrl(core, V4L2_CID_AUDIO_MUTE, 0 != (vol & bit)); 753 wm8775_s_ctrl(core,
754 V4L2_CID_AUDIO_MUTE, 0 != (vol & bit));
750 ret = 1; 755 ret = 1;
751 } 756 }
752 spin_unlock_irq(&chip->reg_lock); 757 spin_unlock_irq(&chip->reg_lock);
@@ -759,7 +764,7 @@ static const struct snd_kcontrol_new snd_cx88_dac_switch = {
759 .info = snd_ctl_boolean_mono_info, 764 .info = snd_ctl_boolean_mono_info,
760 .get = snd_cx88_switch_get, 765 .get = snd_cx88_switch_get,
761 .put = snd_cx88_switch_put, 766 .put = snd_cx88_switch_put,
762 .private_value = (1<<8), 767 .private_value = (1 << 8),
763}; 768};
764 769
765static const struct snd_kcontrol_new snd_cx88_source_switch = { 770static const struct snd_kcontrol_new snd_cx88_source_switch = {
@@ -768,13 +773,13 @@ static const struct snd_kcontrol_new snd_cx88_source_switch = {
768 .info = snd_ctl_boolean_mono_info, 773 .info = snd_ctl_boolean_mono_info,
769 .get = snd_cx88_switch_get, 774 .get = snd_cx88_switch_get,
770 .put = snd_cx88_switch_put, 775 .put = snd_cx88_switch_put,
771 .private_value = (1<<6), 776 .private_value = (1 << 6),
772}; 777};
773 778
774static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol, 779static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_value *value) 780 struct snd_ctl_elem_value *value)
776{ 781{
777 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 782 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
778 struct cx88_core *core = chip->core; 783 struct cx88_core *core = chip->core;
779 s32 val; 784 s32 val;
780 785
@@ -784,9 +789,9 @@ static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
784} 789}
785 790
786static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol, 791static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *value) 792 struct snd_ctl_elem_value *value)
788{ 793{
789 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 794 struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
790 struct cx88_core *core = chip->core; 795 struct cx88_core *core = chip->core;
791 796
792 wm8775_s_ctrl(core, V4L2_CID_AUDIO_LOUDNESS, 797 wm8775_s_ctrl(core, V4L2_CID_AUDIO_LOUDNESS,
@@ -802,9 +807,9 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
802 .put = snd_cx88_alc_put, 807 .put = snd_cx88_alc_put,
803}; 808};
804 809
805/**************************************************************************** 810/*
806 Basic Flow for Sound Devices 811 * Basic Flow for Sound Devices
807 ****************************************************************************/ 812 */
808 813
809/* 814/*
810 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio 815 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
@@ -822,9 +827,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
822 * Chip-specific destructor 827 * Chip-specific destructor
823 */ 828 */
824 829
825static int snd_cx88_free(snd_cx88_card_t *chip) 830static int snd_cx88_free(struct cx88_audio_dev *chip)
826{ 831{
827
828 if (chip->irq >= 0) 832 if (chip->irq >= 0)
829 free_irq(chip->irq, chip); 833 free_irq(chip->irq, chip);
830 834
@@ -839,25 +843,24 @@ static int snd_cx88_free(snd_cx88_card_t *chip)
839 */ 843 */
840static void snd_cx88_dev_free(struct snd_card *card) 844static void snd_cx88_dev_free(struct snd_card *card)
841{ 845{
842 snd_cx88_card_t *chip = card->private_data; 846 struct cx88_audio_dev *chip = card->private_data;
843 847
844 snd_cx88_free(chip); 848 snd_cx88_free(chip);
845} 849}
846 850
847
848/* 851/*
849 * Alsa Constructor - Component probe 852 * Alsa Constructor - Component probe
850 */ 853 */
851 854
852static int devno; 855static int devno;
853static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci, 856static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
854 snd_cx88_card_t **rchip, 857 struct cx88_audio_dev **rchip,
855 struct cx88_core **core_ptr) 858 struct cx88_core **core_ptr)
856{ 859{
857 snd_cx88_card_t *chip; 860 struct cx88_audio_dev *chip;
858 struct cx88_core *core; 861 struct cx88_core *core;
859 int err; 862 int err;
860 unsigned char pci_lat; 863 unsigned char pci_lat;
861 864
862 *rchip = NULL; 865 *rchip = NULL;
863 866
@@ -870,7 +873,7 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
870 chip = card->private_data; 873 chip = card->private_data;
871 874
872 core = cx88_core_get(pci); 875 core = cx88_core_get(pci);
873 if (core == NULL) { 876 if (!core) {
874 err = -EINVAL; 877 err = -EINVAL;
875 return err; 878 return err;
876 } 879 }
@@ -882,7 +885,6 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
882 return err; 885 return err;
883 } 886 }
884 887
885
886 /* pci init */ 888 /* pci init */
887 chip->card = card; 889 chip->card = card;
888 chip->pci = pci; 890 chip->pci = pci;
@@ -896,17 +898,18 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
896 IRQF_SHARED, chip->core->name, chip); 898 IRQF_SHARED, chip->core->name, chip);
897 if (err < 0) { 899 if (err < 0) {
898 dprintk(0, "%s: can't get IRQ %d\n", 900 dprintk(0, "%s: can't get IRQ %d\n",
899 chip->core->name, chip->pci->irq); 901 chip->core->name, chip->pci->irq);
900 return err; 902 return err;
901 } 903 }
902 904
903 /* print pci info */ 905 /* print pci info */
904 pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat); 906 pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat);
905 907
906 dprintk(1, "ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n", 908 dprintk(1,
909 "ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
907 core->name, devno, 910 core->name, devno,
908 pci_name(pci), pci->revision, pci->irq, 911 pci_name(pci), pci->revision, pci->irq,
909 pci_lat, (unsigned long long)pci_resource_start(pci, 0)); 912 pci_lat, (unsigned long long)pci_resource_start(pci, 0));
910 913
911 chip->irq = pci->irq; 914 chip->irq = pci->irq;
912 synchronize_irq(chip->irq); 915 synchronize_irq(chip->irq);
@@ -920,10 +923,10 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
920static int cx88_audio_initdev(struct pci_dev *pci, 923static int cx88_audio_initdev(struct pci_dev *pci,
921 const struct pci_device_id *pci_id) 924 const struct pci_device_id *pci_id)
922{ 925{
923 struct snd_card *card; 926 struct snd_card *card;
924 snd_cx88_card_t *chip; 927 struct cx88_audio_dev *chip;
925 struct cx88_core *core = NULL; 928 struct cx88_core *core = NULL;
926 int err; 929 int err;
927 930
928 if (devno >= SNDRV_CARDS) 931 if (devno >= SNDRV_CARDS)
929 return (-ENODEV); 932 return (-ENODEV);
@@ -934,7 +937,7 @@ static int cx88_audio_initdev(struct pci_dev *pci,
934 } 937 }
935 938
936 err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE, 939 err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE,
937 sizeof(snd_cx88_card_t), &card); 940 sizeof(struct cx88_audio_dev), &card);
938 if (err < 0) 941 if (err < 0)
939 return err; 942 return err;
940 943
@@ -970,7 +973,7 @@ static int cx88_audio_initdev(struct pci_dev *pci,
970 strcpy(card->mixername, "CX88"); 973 strcpy(card->mixername, "CX88");
971 974
972 dprintk(0, "%s/%i: ALSA support for cx2388x boards\n", 975 dprintk(0, "%s/%i: ALSA support for cx2388x boards\n",
973 card->driver, devno); 976 card->driver, devno);
974 977
975 err = snd_card_register(card); 978 err = snd_card_register(card);
976 if (err < 0) 979 if (err < 0)
@@ -984,6 +987,7 @@ error:
984 snd_card_free(card); 987 snd_card_free(card);
985 return err; 988 return err;
986} 989}
990
987/* 991/*
988 * ALSA destructor 992 * ALSA destructor
989 */ 993 */
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index bffd064daff5..aa49c9597d9c 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -66,6 +66,7 @@ enum blackbird_capture_type {
66 BLACKBIRD_RAW_CAPTURE, 66 BLACKBIRD_RAW_CAPTURE,
67 BLACKBIRD_RAW_PASSTHRU_CAPTURE 67 BLACKBIRD_RAW_PASSTHRU_CAPTURE
68}; 68};
69
69enum blackbird_capture_bits { 70enum blackbird_capture_bits {
70 BLACKBIRD_RAW_BITS_NONE = 0x00, 71 BLACKBIRD_RAW_BITS_NONE = 0x00,
71 BLACKBIRD_RAW_BITS_YUV_CAPTURE = 0x01, 72 BLACKBIRD_RAW_BITS_YUV_CAPTURE = 0x01,
@@ -74,33 +75,40 @@ enum blackbird_capture_bits {
74 BLACKBIRD_RAW_BITS_PASSTHRU_CAPTURE = 0x08, 75 BLACKBIRD_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
75 BLACKBIRD_RAW_BITS_TO_HOST_CAPTURE = 0x10 76 BLACKBIRD_RAW_BITS_TO_HOST_CAPTURE = 0x10
76}; 77};
78
77enum blackbird_capture_end { 79enum blackbird_capture_end {
78 BLACKBIRD_END_AT_GOP, /* stop at the end of gop, generate irq */ 80 BLACKBIRD_END_AT_GOP, /* stop at the end of gop, generate irq */
79 BLACKBIRD_END_NOW, /* stop immediately, no irq */ 81 BLACKBIRD_END_NOW, /* stop immediately, no irq */
80}; 82};
83
81enum blackbird_framerate { 84enum blackbird_framerate {
82 BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */ 85 BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */
83 BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */ 86 BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */
84}; 87};
88
85enum blackbird_stream_port { 89enum blackbird_stream_port {
86 BLACKBIRD_OUTPUT_PORT_MEMORY, 90 BLACKBIRD_OUTPUT_PORT_MEMORY,
87 BLACKBIRD_OUTPUT_PORT_STREAMING, 91 BLACKBIRD_OUTPUT_PORT_STREAMING,
88 BLACKBIRD_OUTPUT_PORT_SERIAL 92 BLACKBIRD_OUTPUT_PORT_SERIAL
89}; 93};
94
90enum blackbird_data_xfer_status { 95enum blackbird_data_xfer_status {
91 BLACKBIRD_MORE_BUFFERS_FOLLOW, 96 BLACKBIRD_MORE_BUFFERS_FOLLOW,
92 BLACKBIRD_LAST_BUFFER, 97 BLACKBIRD_LAST_BUFFER,
93}; 98};
99
94enum blackbird_picture_mask { 100enum blackbird_picture_mask {
95 BLACKBIRD_PICTURE_MASK_NONE, 101 BLACKBIRD_PICTURE_MASK_NONE,
96 BLACKBIRD_PICTURE_MASK_I_FRAMES, 102 BLACKBIRD_PICTURE_MASK_I_FRAMES,
97 BLACKBIRD_PICTURE_MASK_I_P_FRAMES = 0x3, 103 BLACKBIRD_PICTURE_MASK_I_P_FRAMES = 0x3,
98 BLACKBIRD_PICTURE_MASK_ALL_FRAMES = 0x7, 104 BLACKBIRD_PICTURE_MASK_ALL_FRAMES = 0x7,
99}; 105};
106
100enum blackbird_vbi_mode_bits { 107enum blackbird_vbi_mode_bits {
101 BLACKBIRD_VBI_BITS_SLICED, 108 BLACKBIRD_VBI_BITS_SLICED,
102 BLACKBIRD_VBI_BITS_RAW, 109 BLACKBIRD_VBI_BITS_RAW,
103}; 110};
111
104enum blackbird_vbi_insertion_bits { 112enum blackbird_vbi_insertion_bits {
105 BLACKBIRD_VBI_BITS_INSERT_IN_XTENSION_USR_DATA, 113 BLACKBIRD_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
106 BLACKBIRD_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1, 114 BLACKBIRD_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
@@ -108,56 +116,69 @@ enum blackbird_vbi_insertion_bits {
108 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1, 116 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
109 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1, 117 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
110}; 118};
119
111enum blackbird_dma_unit { 120enum blackbird_dma_unit {
112 BLACKBIRD_DMA_BYTES, 121 BLACKBIRD_DMA_BYTES,
113 BLACKBIRD_DMA_FRAMES, 122 BLACKBIRD_DMA_FRAMES,
114}; 123};
124
115enum blackbird_dma_transfer_status_bits { 125enum blackbird_dma_transfer_status_bits {
116 BLACKBIRD_DMA_TRANSFER_BITS_DONE = 0x01, 126 BLACKBIRD_DMA_TRANSFER_BITS_DONE = 0x01,
117 BLACKBIRD_DMA_TRANSFER_BITS_ERROR = 0x04, 127 BLACKBIRD_DMA_TRANSFER_BITS_ERROR = 0x04,
118 BLACKBIRD_DMA_TRANSFER_BITS_LL_ERROR = 0x10, 128 BLACKBIRD_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
119}; 129};
130
120enum blackbird_pause { 131enum blackbird_pause {
121 BLACKBIRD_PAUSE_ENCODING, 132 BLACKBIRD_PAUSE_ENCODING,
122 BLACKBIRD_RESUME_ENCODING, 133 BLACKBIRD_RESUME_ENCODING,
123}; 134};
135
124enum blackbird_copyright { 136enum blackbird_copyright {
125 BLACKBIRD_COPYRIGHT_OFF, 137 BLACKBIRD_COPYRIGHT_OFF,
126 BLACKBIRD_COPYRIGHT_ON, 138 BLACKBIRD_COPYRIGHT_ON,
127}; 139};
140
128enum blackbird_notification_type { 141enum blackbird_notification_type {
129 BLACKBIRD_NOTIFICATION_REFRESH, 142 BLACKBIRD_NOTIFICATION_REFRESH,
130}; 143};
144
131enum blackbird_notification_status { 145enum blackbird_notification_status {
132 BLACKBIRD_NOTIFICATION_OFF, 146 BLACKBIRD_NOTIFICATION_OFF,
133 BLACKBIRD_NOTIFICATION_ON, 147 BLACKBIRD_NOTIFICATION_ON,
134}; 148};
149
135enum blackbird_notification_mailbox { 150enum blackbird_notification_mailbox {
136 BLACKBIRD_NOTIFICATION_NO_MAILBOX = -1, 151 BLACKBIRD_NOTIFICATION_NO_MAILBOX = -1,
137}; 152};
153
138enum blackbird_field1_lines { 154enum blackbird_field1_lines {
139 BLACKBIRD_FIELD1_SAA7114 = 0x00EF, /* 239 */ 155 BLACKBIRD_FIELD1_SAA7114 = 0x00EF, /* 239 */
140 BLACKBIRD_FIELD1_SAA7115 = 0x00F0, /* 240 */ 156 BLACKBIRD_FIELD1_SAA7115 = 0x00F0, /* 240 */
141 BLACKBIRD_FIELD1_MICRONAS = 0x0105, /* 261 */ 157 BLACKBIRD_FIELD1_MICRONAS = 0x0105, /* 261 */
142}; 158};
159
143enum blackbird_field2_lines { 160enum blackbird_field2_lines {
144 BLACKBIRD_FIELD2_SAA7114 = 0x00EF, /* 239 */ 161 BLACKBIRD_FIELD2_SAA7114 = 0x00EF, /* 239 */
145 BLACKBIRD_FIELD2_SAA7115 = 0x00F0, /* 240 */ 162 BLACKBIRD_FIELD2_SAA7115 = 0x00F0, /* 240 */
146 BLACKBIRD_FIELD2_MICRONAS = 0x0106, /* 262 */ 163 BLACKBIRD_FIELD2_MICRONAS = 0x0106, /* 262 */
147}; 164};
165
148enum blackbird_custom_data_type { 166enum blackbird_custom_data_type {
149 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA, 167 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
150 BLACKBIRD_CUSTOM_PRIVATE_PACKET, 168 BLACKBIRD_CUSTOM_PRIVATE_PACKET,
151}; 169};
170
152enum blackbird_mute { 171enum blackbird_mute {
153 BLACKBIRD_UNMUTE, 172 BLACKBIRD_UNMUTE,
154 BLACKBIRD_MUTE, 173 BLACKBIRD_MUTE,
155}; 174};
175
156enum blackbird_mute_video_mask { 176enum blackbird_mute_video_mask {
157 BLACKBIRD_MUTE_VIDEO_V_MASK = 0x0000FF00, 177 BLACKBIRD_MUTE_VIDEO_V_MASK = 0x0000FF00,
158 BLACKBIRD_MUTE_VIDEO_U_MASK = 0x00FF0000, 178 BLACKBIRD_MUTE_VIDEO_U_MASK = 0x00FF0000,
159 BLACKBIRD_MUTE_VIDEO_Y_MASK = 0xFF000000, 179 BLACKBIRD_MUTE_VIDEO_Y_MASK = 0xFF000000,
160}; 180};
181
161enum blackbird_mute_video_shift { 182enum blackbird_mute_video_shift {
162 BLACKBIRD_MUTE_VIDEO_V_SHIFT = 8, 183 BLACKBIRD_MUTE_VIDEO_V_SHIFT = 8,
163 BLACKBIRD_MUTE_VIDEO_U_SHIFT = 16, 184 BLACKBIRD_MUTE_VIDEO_U_SHIFT = 16,
@@ -281,7 +302,6 @@ static int register_write(struct cx88_core *core, u32 address, u32 value)
281 return wait_ready_gpio0_bit1(core, 1); 302 return wait_ready_gpio0_bit1(core, 1);
282} 303}
283 304
284
285static int register_read(struct cx88_core *core, u32 address, u32 *value) 305static int register_read(struct cx88_core *core, u32 address, u32 *value)
286{ 306{
287 int retval; 307 int retval;
@@ -304,7 +324,8 @@ static int register_read(struct cx88_core *core, u32 address, u32 *value)
304 324
305/* ------------------------------------------------------------------ */ 325/* ------------------------------------------------------------------ */
306 326
307static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) 327static int blackbird_mbox_func(void *priv, u32 command, int in,
328 int out, u32 data[CX2341X_MBOX_MAX_DATA])
308{ 329{
309 struct cx8802_dev *dev = priv; 330 struct cx8802_dev *dev = priv;
310 unsigned long timeout; 331 unsigned long timeout;
@@ -313,11 +334,14 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat
313 334
314 dprintk(1, "%s: 0x%X\n", __func__, command); 335 dprintk(1, "%s: 0x%X\n", __func__, command);
315 336
316 /* this may not be 100% safe if we can't read any memory location 337 /*
317 without side effects */ 338 * this may not be 100% safe if we can't read any memory location
339 * without side effects
340 */
318 memory_read(dev->core, dev->mailbox - 4, &value); 341 memory_read(dev->core, dev->mailbox - 4, &value);
319 if (value != 0x12345678) { 342 if (value != 0x12345678) {
320 dprintk(0, "Firmware and/or mailbox pointer not initialized or corrupted\n"); 343 dprintk(0,
344 "Firmware and/or mailbox pointer not initialized or corrupted\n");
321 return -EIO; 345 return -EIO;
322 } 346 }
323 347
@@ -332,7 +356,8 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat
332 356
333 /* write command + args + fill remaining with zeros */ 357 /* write command + args + fill remaining with zeros */
334 memory_write(dev->core, dev->mailbox + 1, command); /* command code */ 358 memory_write(dev->core, dev->mailbox + 1, command); /* command code */
335 memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */ 359 /* timeout */
360 memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT);
336 for (i = 0; i < in; i++) { 361 for (i = 0; i < in; i++) {
337 memory_write(dev->core, dev->mailbox + 4 + i, data[i]); 362 memory_write(dev->core, dev->mailbox + 4 + i, data[i]);
338 dprintk(1, "API Input %d = %d\n", i, data[i]); 363 dprintk(1, "API Input %d = %d\n", i, data[i]);
@@ -369,9 +394,13 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat
369 memory_write(dev->core, dev->mailbox, flag); 394 memory_write(dev->core, dev->mailbox, flag);
370 return retval; 395 return retval;
371} 396}
397
372/* ------------------------------------------------------------------ */ 398/* ------------------------------------------------------------------ */
373 399
374/* We don't need to call the API often, so using just one mailbox will probably suffice */ 400/*
401 * We don't need to call the API often, so using just one mailbox
402 * will probably suffice
403 */
375static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, 404static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command,
376 u32 inputcnt, u32 outputcnt, ...) 405 u32 inputcnt, u32 outputcnt, ...)
377{ 406{
@@ -381,9 +410,9 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command,
381 410
382 va_start(vargs, outputcnt); 411 va_start(vargs, outputcnt);
383 412
384 for (i = 0; i < inputcnt; i++) { 413 for (i = 0; i < inputcnt; i++)
385 data[i] = va_arg(vargs, int); 414 data[i] = va_arg(vargs, int);
386 } 415
387 err = blackbird_mbox_func(dev, command, inputcnt, outputcnt, data); 416 err = blackbird_mbox_func(dev, command, inputcnt, outputcnt, data);
388 for (i = 0; i < outputcnt; i++) { 417 for (i = 0; i < outputcnt; i++) {
389 int *vptr = va_arg(vargs, int *); 418 int *vptr = va_arg(vargs, int *);
@@ -408,7 +437,7 @@ static int blackbird_find_mailbox(struct cx8802_dev *dev)
408 signaturecnt = 0; 437 signaturecnt = 0;
409 if (signaturecnt == 4) { 438 if (signaturecnt == 4) {
410 dprintk(1, "Mailbox signature found\n"); 439 dprintk(1, "Mailbox signature found\n");
411 return i+1; 440 return i + 1;
412 } 441 }
413 } 442 }
414 dprintk(0, "Mailbox signature values not found!\n"); 443 dprintk(0, "Mailbox signature values not found!\n");
@@ -427,10 +456,13 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
427 __le32 *dataptr; 456 __le32 *dataptr;
428 457
429 retval = register_write(dev->core, IVTV_REG_VPU, 0xFFFFFFED); 458 retval = register_write(dev->core, IVTV_REG_VPU, 0xFFFFFFED);
430 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST); 459 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS,
431 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_REFRESH, 0x80000640); 460 IVTV_CMD_HW_BLOCKS_RST);
432 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_PRECHARGE, 0x1A); 461 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_REFRESH,
433 msleep(1); 462 0x80000640);
463 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_PRECHARGE,
464 0x1A);
465 usleep_range(10000, 20000);
434 retval |= register_write(dev->core, IVTV_REG_APU, 0); 466 retval |= register_write(dev->core, IVTV_REG_APU, 0);
435 467
436 if (retval < 0) 468 if (retval < 0)
@@ -439,7 +471,6 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
439 retval = request_firmware(&firmware, CX2341X_FIRM_ENC_FILENAME, 471 retval = request_firmware(&firmware, CX2341X_FIRM_ENC_FILENAME,
440 &dev->pci->dev); 472 &dev->pci->dev);
441 473
442
443 if (retval != 0) { 474 if (retval != 0) {
444 pr_err("Hotplug firmware request failed (%s).\n", 475 pr_err("Hotplug firmware request failed (%s).\n",
445 CX2341X_FIRM_ENC_FILENAME); 476 CX2341X_FIRM_ENC_FILENAME);
@@ -482,10 +513,11 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
482 } 513 }
483 dprintk(0, "Firmware upload successful.\n"); 514 dprintk(0, "Firmware upload successful.\n");
484 515
485 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST); 516 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS,
517 IVTV_CMD_HW_BLOCKS_RST);
486 retval |= register_read(dev->core, IVTV_REG_SPU, &value); 518 retval |= register_read(dev->core, IVTV_REG_SPU, &value);
487 retval |= register_write(dev->core, IVTV_REG_SPU, value & 0xFFFFFFFE); 519 retval |= register_write(dev->core, IVTV_REG_SPU, value & 0xFFFFFFFE);
488 msleep(1); 520 usleep_range(10000, 20000);
489 521
490 retval |= register_read(dev->core, IVTV_REG_VPU, &value); 522 retval |= register_read(dev->core, IVTV_REG_VPU, &value);
491 retval |= register_write(dev->core, IVTV_REG_VPU, value & 0xFFFFFFE8); 523 retval |= register_write(dev->core, IVTV_REG_VPU, value & 0xFFFFFFE8);
@@ -495,19 +527,19 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
495 return 0; 527 return 0;
496} 528}
497 529
498/** 530/*
499 Settings used by the windows tv app for PVR2000: 531 * Settings used by the windows tv app for PVR2000:
500================================================================================================================= 532 * =================================================================================================================
501Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode 533 * Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode
502----------------------------------------------------------------------------------------------------------------- 534 * -----------------------------------------------------------------------------------------------------------------
503MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo 535 * MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
504MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo 536 * MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
505VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo 537 * VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
506DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo 538 * DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
507DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo 539 * DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
508================================================================================================================= 540 * =================================================================================================================
509*DB: "DirectBurn" 541 * [*] DB: "DirectBurn"
510*/ 542 */
511 543
512static void blackbird_codec_settings(struct cx8802_dev *dev) 544static void blackbird_codec_settings(struct cx8802_dev *dev)
513{ 545{
@@ -515,11 +547,12 @@ static void blackbird_codec_settings(struct cx8802_dev *dev)
515 547
516 /* assign frame size */ 548 /* assign frame size */
517 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 549 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
518 core->height, core->width); 550 core->height, core->width);
519 551
520 dev->cxhdl.width = core->width; 552 dev->cxhdl.width = core->width;
521 dev->cxhdl.height = core->height; 553 dev->cxhdl.height = core->height;
522 cx2341x_handler_set_50hz(&dev->cxhdl, dev->core->tvnorm & V4L2_STD_625_50); 554 cx2341x_handler_set_50hz(&dev->cxhdl,
555 dev->core->tvnorm & V4L2_STD_625_50);
523 cx2341x_handler_setup(&dev->cxhdl); 556 cx2341x_handler_setup(&dev->cxhdl);
524} 557}
525 558
@@ -545,15 +578,18 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
545 578
546 dev->mailbox = retval; 579 dev->mailbox = retval;
547 580
548 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */ 581 /* ping */
582 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0);
549 if (retval < 0) { 583 if (retval < 0) {
550 dprintk(0, "ERROR: Firmware ping failed!\n"); 584 dprintk(0, "ERROR: Firmware ping failed!\n");
551 return -1; 585 return -1;
552 } 586 }
553 587
554 retval = blackbird_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1, &version); 588 retval = blackbird_api_cmd(dev, CX2341X_ENC_GET_VERSION,
589 0, 1, &version);
555 if (retval < 0) { 590 if (retval < 0) {
556 dprintk(0, "ERROR: Firmware get encoder version failed!\n"); 591 dprintk(0,
592 "ERROR: Firmware get encoder version failed!\n");
557 return -1; 593 return -1;
558 } 594 }
559 dprintk(0, "Firmware version is 0x%08x\n", version); 595 dprintk(0, "Firmware version is 0x%08x\n", version);
@@ -567,13 +603,11 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
567 blackbird_codec_settings(dev); 603 blackbird_codec_settings(dev);
568 604
569 blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0, 605 blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
570 BLACKBIRD_FIELD1_SAA7115, 606 BLACKBIRD_FIELD1_SAA7115, BLACKBIRD_FIELD2_SAA7115);
571 BLACKBIRD_FIELD2_SAA7115
572 );
573 607
574 blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0, 608 blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
575 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA, 609 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
576 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 610 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
577 611
578 return 0; 612 return 0;
579} 613}
@@ -611,9 +645,7 @@ static int blackbird_start_codec(struct cx8802_dev *dev)
611 645
612 /* start capturing to the host interface */ 646 /* start capturing to the host interface */
613 blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 647 blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
614 BLACKBIRD_MPEG_CAPTURE, 648 BLACKBIRD_MPEG_CAPTURE, BLACKBIRD_RAW_BITS_NONE);
615 BLACKBIRD_RAW_BITS_NONE
616 );
617 649
618 return 0; 650 return 0;
619} 651}
@@ -621,10 +653,9 @@ static int blackbird_start_codec(struct cx8802_dev *dev)
621static int blackbird_stop_codec(struct cx8802_dev *dev) 653static int blackbird_stop_codec(struct cx8802_dev *dev)
622{ 654{
623 blackbird_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 655 blackbird_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
624 BLACKBIRD_END_NOW, 656 BLACKBIRD_END_NOW,
625 BLACKBIRD_MPEG_CAPTURE, 657 BLACKBIRD_MPEG_CAPTURE,
626 BLACKBIRD_RAW_BITS_NONE 658 BLACKBIRD_RAW_BITS_NONE);
627 );
628 659
629 cx2341x_handler_set_busy(&dev->cxhdl, 0); 660 cx2341x_handler_set_busy(&dev->cxhdl, 0);
630 661
@@ -634,8 +665,8 @@ static int blackbird_stop_codec(struct cx8802_dev *dev)
634/* ------------------------------------------------------------------ */ 665/* ------------------------------------------------------------------ */
635 666
636static int queue_setup(struct vb2_queue *q, 667static int queue_setup(struct vb2_queue *q,
637 unsigned int *num_buffers, unsigned int *num_planes, 668 unsigned int *num_buffers, unsigned int *num_planes,
638 unsigned int sizes[], struct device *alloc_devs[]) 669 unsigned int sizes[], struct device *alloc_devs[])
639{ 670{
640 struct cx8802_dev *dev = q->drv_priv; 671 struct cx8802_dev *dev = q->drv_priv;
641 672
@@ -695,7 +726,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
695 726
696 err = drv->request_acquire(drv); 727 err = drv->request_acquire(drv);
697 if (err != 0) { 728 if (err != 0) {
698 dprintk(1, "%s: Unable to acquire hardware, %d\n", __func__, err); 729 dprintk(1, "%s: Unable to acquire hardware, %d\n", __func__,
730 err);
699 goto fail; 731 goto fail;
700 } 732 }
701 733
@@ -766,7 +798,7 @@ static const struct vb2_ops blackbird_qops = {
766/* ------------------------------------------------------------------ */ 798/* ------------------------------------------------------------------ */
767 799
768static int vidioc_querycap(struct file *file, void *priv, 800static int vidioc_querycap(struct file *file, void *priv,
769 struct v4l2_capability *cap) 801 struct v4l2_capability *cap)
770{ 802{
771 struct cx8802_dev *dev = video_drvdata(file); 803 struct cx8802_dev *dev = video_drvdata(file);
772 struct cx88_core *core = dev->core; 804 struct cx88_core *core = dev->core;
@@ -778,7 +810,7 @@ static int vidioc_querycap(struct file *file, void *priv,
778} 810}
779 811
780static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 812static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
781 struct v4l2_fmtdesc *f) 813 struct v4l2_fmtdesc *f)
782{ 814{
783 if (f->index != 0) 815 if (f->index != 0)
784 return -EINVAL; 816 return -EINVAL;
@@ -790,7 +822,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
790} 822}
791 823
792static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 824static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
793 struct v4l2_format *f) 825 struct v4l2_format *f)
794{ 826{
795 struct cx8802_dev *dev = video_drvdata(file); 827 struct cx8802_dev *dev = video_drvdata(file);
796 struct cx88_core *core = dev->core; 828 struct cx88_core *core = dev->core;
@@ -806,7 +838,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
806} 838}
807 839
808static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 840static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
809 struct v4l2_format *f) 841 struct v4l2_format *f)
810{ 842{
811 struct cx8802_dev *dev = video_drvdata(file); 843 struct cx8802_dev *dev = video_drvdata(file);
812 struct cx88_core *core = dev->core; 844 struct cx88_core *core = dev->core;
@@ -846,7 +878,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
846} 878}
847 879
848static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 880static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
849 struct v4l2_format *f) 881 struct v4l2_format *f)
850{ 882{
851 struct cx8802_dev *dev = video_drvdata(file); 883 struct cx8802_dev *dev = video_drvdata(file);
852 struct cx88_core *core = dev->core; 884 struct cx88_core *core = dev->core;
@@ -860,14 +892,15 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
860 core->width = f->fmt.pix.width; 892 core->width = f->fmt.pix.width;
861 core->height = f->fmt.pix.height; 893 core->height = f->fmt.pix.height;
862 core->field = f->fmt.pix.field; 894 core->field = f->fmt.pix.field;
863 cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); 895 cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height,
896 f->fmt.pix.field);
864 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 897 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
865 f->fmt.pix.height, f->fmt.pix.width); 898 f->fmt.pix.height, f->fmt.pix.width);
866 return 0; 899 return 0;
867} 900}
868 901
869static int vidioc_s_frequency(struct file *file, void *priv, 902static int vidioc_s_frequency(struct file *file, void *priv,
870 const struct v4l2_frequency *f) 903 const struct v4l2_frequency *f)
871{ 904{
872 struct cx8802_dev *dev = video_drvdata(file); 905 struct cx8802_dev *dev = video_drvdata(file);
873 struct cx88_core *core = dev->core; 906 struct cx88_core *core = dev->core;
@@ -883,8 +916,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
883 916
884 cx88_set_freq(core, f); 917 cx88_set_freq(core, f);
885 blackbird_initialize_codec(dev); 918 blackbird_initialize_codec(dev);
886 cx88_set_scale(core, core->width, core->height, 919 cx88_set_scale(core, core->width, core->height, core->field);
887 core->field);
888 if (streaming) 920 if (streaming)
889 blackbird_start_codec(dev); 921 blackbird_start_codec(dev);
890 return 0; 922 return 0;
@@ -903,7 +935,7 @@ static int vidioc_log_status(struct file *file, void *priv)
903} 935}
904 936
905static int vidioc_enum_input(struct file *file, void *priv, 937static int vidioc_enum_input(struct file *file, void *priv,
906 struct v4l2_input *i) 938 struct v4l2_input *i)
907{ 939{
908 struct cx8802_dev *dev = video_drvdata(file); 940 struct cx8802_dev *dev = video_drvdata(file);
909 struct cx88_core *core = dev->core; 941 struct cx88_core *core = dev->core;
@@ -912,7 +944,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
912} 944}
913 945
914static int vidioc_g_frequency(struct file *file, void *priv, 946static int vidioc_g_frequency(struct file *file, void *priv,
915 struct v4l2_frequency *f) 947 struct v4l2_frequency *f)
916{ 948{
917 struct cx8802_dev *dev = video_drvdata(file); 949 struct cx8802_dev *dev = video_drvdata(file);
918 struct cx88_core *core = dev->core; 950 struct cx88_core *core = dev->core;
@@ -944,7 +976,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
944 976
945 if (i >= 4) 977 if (i >= 4)
946 return -EINVAL; 978 return -EINVAL;
947 if (0 == INPUT(i).type) 979 if (!INPUT(i).type)
948 return -EINVAL; 980 return -EINVAL;
949 981
950 cx88_newstation(core); 982 cx88_newstation(core);
@@ -953,7 +985,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
953} 985}
954 986
955static int vidioc_g_tuner(struct file *file, void *priv, 987static int vidioc_g_tuner(struct file *file, void *priv,
956 struct v4l2_tuner *t) 988 struct v4l2_tuner *t)
957{ 989{
958 struct cx8802_dev *dev = video_drvdata(file); 990 struct cx8802_dev *dev = video_drvdata(file);
959 struct cx88_core *core = dev->core; 991 struct cx88_core *core = dev->core;
@@ -971,12 +1003,12 @@ static int vidioc_g_tuner(struct file *file, void *priv,
971 1003
972 cx88_get_stereo(core, t); 1004 cx88_get_stereo(core, t);
973 reg = cx_read(MO_DEVICE_STATUS); 1005 reg = cx_read(MO_DEVICE_STATUS);
974 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000; 1006 t->signal = (reg & (1 << 5)) ? 0xffff : 0x0000;
975 return 0; 1007 return 0;
976} 1008}
977 1009
978static int vidioc_s_tuner(struct file *file, void *priv, 1010static int vidioc_s_tuner(struct file *file, void *priv,
979 const struct v4l2_tuner *t) 1011 const struct v4l2_tuner *t)
980{ 1012{
981 struct cx8802_dev *dev = video_drvdata(file); 1013 struct cx8802_dev *dev = video_drvdata(file);
982 struct cx88_core *core = dev->core; 1014 struct cx88_core *core = dev->core;
@@ -1008,7 +1040,6 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
1008} 1040}
1009 1041
1010static const struct v4l2_file_operations mpeg_fops = { 1042static const struct v4l2_file_operations mpeg_fops = {
1011
1012 .owner = THIS_MODULE, 1043 .owner = THIS_MODULE,
1013 .open = v4l2_fh_open, 1044 .open = v4l2_fh_open,
1014 .release = vb2_fop_release, 1045 .release = vb2_fop_release,
@@ -1061,7 +1092,9 @@ static int cx8802_blackbird_advise_acquire(struct cx8802_driver *drv)
1061 1092
1062 switch (core->boardnr) { 1093 switch (core->boardnr) {
1063 case CX88_BOARD_HAUPPAUGE_HVR1300: 1094 case CX88_BOARD_HAUPPAUGE_HVR1300:
1064 /* By default, core setup will leave the cx22702 out of reset, on the bus. 1095 /*
1096 * By default, core setup will leave the cx22702 out of reset,
1097 * on the bus.
1065 * We left the hardware on power up with the cx22702 active. 1098 * We left the hardware on power up with the cx22702 active.
1066 * We're being given access to re-arrange the GPIOs. 1099 * We're being given access to re-arrange the GPIOs.
1067 * Take the bus off the cx22702 and put the cx23416 on it. 1100 * Take the bus off the cx22702 and put the cx23416 on it.
diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c
index 269179142cd8..cdfbde277b8b 100644
--- a/drivers/media/pci/cx88/cx88-cards.c
+++ b/drivers/media/pci/cx88/cx88-cards.c
@@ -51,7 +51,6 @@ MODULE_PARM_DESC(disable_ir, "Disable IR support");
51 __func__, ##arg); \ 51 __func__, ##arg); \
52} while (0) 52} while (0)
53 53
54
55/* ------------------------------------------------------------------ */ 54/* ------------------------------------------------------------------ */
56/* board config info */ 55/* board config info */
57 56
@@ -278,7 +277,6 @@ static const struct cx88_board cx88_boards[] = {
278 .gpio2 = 0x0035e700, 277 .gpio2 = 0x0035e700,
279 .gpio3 = 0x02000000, 278 .gpio3 = 0x02000000,
280 }, { 279 }, {
281
282 .type = CX88_VMUX_COMPOSITE1, 280 .type = CX88_VMUX_COMPOSITE1,
283 .vmux = 1, 281 .vmux = 1,
284 .gpio0 = 0x0035c700, 282 .gpio0 = 0x0035c700,
@@ -492,22 +490,22 @@ static const struct cx88_board cx88_boards[] = {
492 .tuner_addr = ADDR_UNSET, 490 .tuner_addr = ADDR_UNSET,
493 .radio_addr = ADDR_UNSET, 491 .radio_addr = ADDR_UNSET,
494 /* 492 /*
495 GPIO[0] resets DT3302 DTV receiver 493 * GPIO[0] resets DT3302 DTV receiver
496 0 - reset asserted 494 * 0 - reset asserted
497 1 - normal operation 495 * 1 - normal operation
498 GPIO[1] mutes analog audio output connector 496 * GPIO[1] mutes analog audio output connector
499 0 - enable selected source 497 * 0 - enable selected source
500 1 - mute 498 * 1 - mute
501 GPIO[2] selects source for analog audio output connector 499 * GPIO[2] selects source for analog audio output connector
502 0 - analog audio input connector on tab 500 * 0 - analog audio input connector on tab
503 1 - analog DAC output from CX23881 chip 501 * 1 - analog DAC output from CX23881 chip
504 GPIO[3] selects RF input connector on tuner module 502 * GPIO[3] selects RF input connector on tuner module
505 0 - RF connector labeled CABLE 503 * 0 - RF connector labeled CABLE
506 1 - RF connector labeled ANT 504 * 1 - RF connector labeled ANT
507 GPIO[4] selects high RF for QAM256 mode 505 * GPIO[4] selects high RF for QAM256 mode
508 0 - normal RF 506 * 0 - normal RF
509 1 - high RF 507 * 1 - high RF
510 */ 508 */
511 .input = { { 509 .input = { {
512 .type = CX88_VMUX_TELEVISION, 510 .type = CX88_VMUX_TELEVISION,
513 .vmux = 0, 511 .vmux = 0,
@@ -730,7 +728,10 @@ static const struct cx88_board cx88_boards[] = {
730 .radio_type = UNSET, 728 .radio_type = UNSET,
731 .tuner_addr = ADDR_UNSET, 729 .tuner_addr = ADDR_UNSET,
732 .radio_addr = ADDR_UNSET, 730 .radio_addr = ADDR_UNSET,
733 /* Some variants use a tda9874 and so need the tvaudio module. */ 731 /*
732 * Some variants use a tda9874 and so need the
733 * tvaudio module.
734 */
734 .audio_chip = CX88_AUDIO_TVAUDIO, 735 .audio_chip = CX88_AUDIO_TVAUDIO,
735 .input = { { 736 .input = { {
736 .type = CX88_VMUX_TELEVISION, 737 .type = CX88_VMUX_TELEVISION,
@@ -1196,8 +1197,10 @@ static const struct cx88_board cx88_boards[] = {
1196 .mpeg = CX88_MPEG_DVB, 1197 .mpeg = CX88_MPEG_DVB,
1197 }, 1198 },
1198 [CX88_BOARD_KWORLD_MCE200_DELUXE] = { 1199 [CX88_BOARD_KWORLD_MCE200_DELUXE] = {
1199 /* FIXME: tested TV input only, disabled composite, 1200 /*
1200 svideo and radio until they can be tested also. */ 1201 * FIXME: tested TV input only, disabled composite,
1202 * svideo and radio until they can be tested also.
1203 */
1201 .name = "Kworld MCE 200 Deluxe", 1204 .name = "Kworld MCE 200 Deluxe",
1202 .tuner_type = TUNER_TENA_9533_DI, 1205 .tuner_type = TUNER_TENA_9533_DI,
1203 .radio_type = UNSET, 1206 .radio_type = UNSET,
@@ -1708,16 +1711,24 @@ static const struct cx88_board cx88_boards[] = {
1708 }, 1711 },
1709 }, 1712 },
1710 [CX88_BOARD_POWERCOLOR_REAL_ANGEL] = { 1713 [CX88_BOARD_POWERCOLOR_REAL_ANGEL] = {
1711 .name = "PowerColor RA330", /* Long names may confuse LIRC. */ 1714 /* Long names may confuse LIRC. */
1715 .name = "PowerColor RA330",
1712 .tuner_type = TUNER_XC2028, 1716 .tuner_type = TUNER_XC2028,
1713 .tuner_addr = 0x61, 1717 .tuner_addr = 0x61,
1714 .input = { { 1718 .input = { {
1719 /*
1720 * Due to the way the cx88 driver is written,
1721 * there is no way to deactivate audio pass-
1722 * through without this entry. Furthermore, if
1723 * the TV mux entry is first, you get audio
1724 * from the tuner on boot for a little while.
1725 */
1715 .type = CX88_VMUX_DEBUG, 1726 .type = CX88_VMUX_DEBUG,
1716 .vmux = 3, /* Due to the way the cx88 driver is written, */ 1727 .vmux = 3,
1717 .gpio0 = 0x00ff, /* there is no way to deactivate audio pass- */ 1728 .gpio0 = 0x00ff,
1718 .gpio1 = 0xf39d, /* through without this entry. Furthermore, if */ 1729 .gpio1 = 0xf39d,
1719 .gpio3 = 0x0000, /* the TV mux entry is first, you get audio */ 1730 .gpio3 = 0x0000,
1720 }, { /* from the tuner on boot for a little while. */ 1731 }, {
1721 .type = CX88_VMUX_TELEVISION, 1732 .type = CX88_VMUX_TELEVISION,
1722 .vmux = 0, 1733 .vmux = 0,
1723 .gpio0 = 0x00ff, 1734 .gpio0 = 0x00ff,
@@ -1870,11 +1881,12 @@ static const struct cx88_board cx88_boards[] = {
1870 .gpio2 = 0x0cf7, 1881 .gpio2 = 0x0cf7,
1871 }, 1882 },
1872 }, 1883 },
1873 /* Both radio, analog and ATSC work with this board. 1884 /*
1874 However, for analog to work, s5h1409 gate should be open, 1885 * Both radio, analog and ATSC work with this board.
1875 otherwise, tuner-xc3028 won't be detected. 1886 * However, for analog to work, s5h1409 gate should be open,
1876 A proper fix require using the newer i2c methods to add 1887 * otherwise, tuner-xc3028 won't be detected.
1877 tuner-xc3028 without doing an i2c probe. 1888 * A proper fix require using the newer i2c methods to add
1889 * tuner-xc3028 without doing an i2c probe.
1878 */ 1890 */
1879 [CX88_BOARD_KWORLD_ATSC_120] = { 1891 [CX88_BOARD_KWORLD_ATSC_120] = {
1880 .name = "Kworld PlusTV HD PCI 120 (ATSC 120)", 1892 .name = "Kworld PlusTV HD PCI 120 (ATSC 120)",
@@ -2808,9 +2820,9 @@ static const struct cx88_subid cx88_subids[] = {
2808 }, 2820 },
2809}; 2821};
2810 2822
2811/* ----------------------------------------------------------------------- */ 2823/*
2812/* some leadtek specific stuff */ 2824 * some leadtek specific stuff
2813 2825 */
2814static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data) 2826static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
2815{ 2827{
2816 if (eeprom_data[4] != 0x7d || 2828 if (eeprom_data[4] != 0x7d ||
@@ -2849,8 +2861,7 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
2849 core->model = tv.model; 2861 core->model = tv.model;
2850 2862
2851 /* Make sure we support the board model */ 2863 /* Make sure we support the board model */
2852 switch (tv.model) 2864 switch (tv.model) {
2853 {
2854 case 14009: /* WinTV-HVR3000 (Retail, IR, b/panel video, 3.5mm audio in) */ 2865 case 14009: /* WinTV-HVR3000 (Retail, IR, b/panel video, 3.5mm audio in) */
2855 case 14019: /* WinTV-HVR3000 (Retail, IR Blaster, b/panel video, 3.5mm audio in) */ 2866 case 14019: /* WinTV-HVR3000 (Retail, IR Blaster, b/panel video, 3.5mm audio in) */
2856 case 14029: /* WinTV-HVR3000 (Retail, IR, b/panel video, 3.5mm audio in - 880 bridge) */ 2867 case 14029: /* WinTV-HVR3000 (Retail, IR, b/panel video, 3.5mm audio in - 880 bridge) */
@@ -2898,8 +2909,9 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
2898 pr_info("hauppauge eeprom: model=%d\n", tv.model); 2909 pr_info("hauppauge eeprom: model=%d\n", tv.model);
2899} 2910}
2900 2911
2901/* ----------------------------------------------------------------------- */ 2912/*
2902/* some GDI (was: Modular Technology) specific stuff */ 2913 * some GDI (was: Modular Technology) specific stuff
2914 */
2903 2915
2904static const struct { 2916static const struct {
2905 int id; 2917 int id;
@@ -2907,33 +2919,33 @@ static const struct {
2907 const char *name; 2919 const char *name;
2908} gdi_tuner[] = { 2920} gdi_tuner[] = {
2909 [0x01] = { .id = UNSET, 2921 [0x01] = { .id = UNSET,
2910 .name = "NTSC_M" }, 2922 .name = "NTSC_M" },
2911 [0x02] = { .id = UNSET, 2923 [0x02] = { .id = UNSET,
2912 .name = "PAL_B" }, 2924 .name = "PAL_B" },
2913 [0x03] = { .id = UNSET, 2925 [0x03] = { .id = UNSET,
2914 .name = "PAL_I" }, 2926 .name = "PAL_I" },
2915 [0x04] = { .id = UNSET, 2927 [0x04] = { .id = UNSET,
2916 .name = "PAL_D" }, 2928 .name = "PAL_D" },
2917 [0x05] = { .id = UNSET, 2929 [0x05] = { .id = UNSET,
2918 .name = "SECAM" }, 2930 .name = "SECAM" },
2919 2931
2920 [0x10] = { .id = UNSET, 2932 [0x10] = { .id = UNSET,
2921 .fm = 1, 2933 .fm = 1,
2922 .name = "TEMIC_4049" }, 2934 .name = "TEMIC_4049" },
2923 [0x11] = { .id = TUNER_TEMIC_4136FY5, 2935 [0x11] = { .id = TUNER_TEMIC_4136FY5,
2924 .name = "TEMIC_4136" }, 2936 .name = "TEMIC_4136" },
2925 [0x12] = { .id = UNSET, 2937 [0x12] = { .id = UNSET,
2926 .name = "TEMIC_4146" }, 2938 .name = "TEMIC_4146" },
2927 2939
2928 [0x20] = { .id = TUNER_PHILIPS_FQ1216ME, 2940 [0x20] = { .id = TUNER_PHILIPS_FQ1216ME,
2929 .fm = 1, 2941 .fm = 1,
2930 .name = "PHILIPS_FQ1216_MK3" }, 2942 .name = "PHILIPS_FQ1216_MK3" },
2931 [0x21] = { .id = UNSET, .fm = 1, 2943 [0x21] = { .id = UNSET, .fm = 1,
2932 .name = "PHILIPS_FQ1236_MK3" }, 2944 .name = "PHILIPS_FQ1236_MK3" },
2933 [0x22] = { .id = UNSET, 2945 [0x22] = { .id = UNSET,
2934 .name = "PHILIPS_FI1236_MK3" }, 2946 .name = "PHILIPS_FI1236_MK3" },
2935 [0x23] = { .id = UNSET, 2947 [0x23] = { .id = UNSET,
2936 .name = "PHILIPS_FI1216_MK3" }, 2948 .name = "PHILIPS_FI1216_MK3" },
2937}; 2949};
2938 2950
2939static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data) 2951static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
@@ -2942,15 +2954,16 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
2942 ? gdi_tuner[eeprom_data[0x0d]].name : NULL; 2954 ? gdi_tuner[eeprom_data[0x0d]].name : NULL;
2943 2955
2944 pr_info("GDI: tuner=%s\n", name ? name : "unknown"); 2956 pr_info("GDI: tuner=%s\n", name ? name : "unknown");
2945 if (name == NULL) 2957 if (!name)
2946 return; 2958 return;
2947 core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id; 2959 core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id;
2948 core->board.radio.type = gdi_tuner[eeprom_data[0x0d]].fm ? 2960 core->board.radio.type = gdi_tuner[eeprom_data[0x0d]].fm ?
2949 CX88_RADIO : 0; 2961 CX88_RADIO : 0;
2950} 2962}
2951 2963
2952/* ------------------------------------------------------------------- */ 2964/*
2953/* some Divco specific stuff */ 2965 * some Divco specific stuff
2966 */
2954static int cx88_dvico_xc2028_callback(struct cx88_core *core, 2967static int cx88_dvico_xc2028_callback(struct cx88_core *core,
2955 int command, int arg) 2968 int command, int arg)
2956{ 2969{
@@ -2979,9 +2992,9 @@ static int cx88_dvico_xc2028_callback(struct cx88_core *core,
2979 return 0; 2992 return 0;
2980} 2993}
2981 2994
2982 2995/*
2983/* ----------------------------------------------------------------------- */ 2996 * some Geniatech specific stuff
2984/* some Geniatech specific stuff */ 2997 */
2985 2998
2986static int cx88_xc3028_geniatech_tuner_callback(struct cx88_core *core, 2999static int cx88_xc3028_geniatech_tuner_callback(struct cx88_core *core,
2987 int command, int mode) 3000 int command, int mode)
@@ -3044,8 +3057,9 @@ static int cx88_xc4000_winfast2000h_plus_callback(struct cx88_core *core,
3044 return -EINVAL; 3057 return -EINVAL;
3045} 3058}
3046 3059
3047/* ------------------------------------------------------------------- */ 3060/*
3048/* some Divco specific stuff */ 3061 * some Divco specific stuff
3062 */
3049static int cx88_pv_8000gt_callback(struct cx88_core *core, 3063static int cx88_pv_8000gt_callback(struct cx88_core *core,
3050 int command, int arg) 3064 int command, int arg)
3051{ 3065{
@@ -3064,8 +3078,9 @@ static int cx88_pv_8000gt_callback(struct cx88_core *core,
3064 return 0; 3078 return 0;
3065} 3079}
3066 3080
3067/* ----------------------------------------------------------------------- */ 3081/*
3068/* some DViCO specific stuff */ 3082 * some DViCO specific stuff
3083 */
3069 3084
3070static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core) 3085static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core)
3071{ 3086{
@@ -3161,11 +3176,11 @@ static int cx88_xc4000_tuner_callback(struct cx88_core *core,
3161 return -EINVAL; 3176 return -EINVAL;
3162} 3177}
3163 3178
3164/* ----------------------------------------------------------------------- */ 3179/*
3165/* Tuner callback function. Currently only needed for the Pinnacle * 3180 * Tuner callback function. Currently only needed for the Pinnacle
3166 * PCTV HD 800i with an xc5000 sillicon tuner. This is used for both * 3181 * PCTV HD 800i with an xc5000 sillicon tuner. This is used for both
3167 * analog tuner attach (tuner-core.c) and dvb tuner attach (cx88-dvb.c) */ 3182 * analog tuner attach (tuner-core.c) and dvb tuner attach (cx88-dvb.c)
3168 3183 */
3169static int cx88_xc5000_tuner_callback(struct cx88_core *core, 3184static int cx88_xc5000_tuner_callback(struct cx88_core *core,
3170 int command, int arg) 3185 int command, int arg)
3171{ 3186{
@@ -3173,38 +3188,38 @@ static int cx88_xc5000_tuner_callback(struct cx88_core *core,
3173 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 3188 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
3174 if (command == 0) { /* This is the reset command from xc5000 */ 3189 if (command == 0) { /* This is the reset command from xc5000 */
3175 3190
3176 /* djh - According to the engineer at PCTV Systems, 3191 /*
3177 the xc5000 reset pin is supposed to be on GPIO12. 3192 * djh - According to the engineer at PCTV Systems,
3178 However, despite three nights of effort, pulling 3193 * the xc5000 reset pin is supposed to be on GPIO12.
3179 that GPIO low didn't reset the xc5000. While 3194 * However, despite three nights of effort, pulling
3180 pulling MO_SRST_IO low does reset the xc5000, this 3195 * that GPIO low didn't reset the xc5000. While
3181 also resets in the s5h1409 being reset as well. 3196 * pulling MO_SRST_IO low does reset the xc5000, this
3182 This causes tuning to always fail since the internal 3197 * also resets in the s5h1409 being reset as well.
3183 state of the s5h1409 does not match the driver's 3198 * This causes tuning to always fail since the internal
3184 state. Given that the only two conditions in which 3199 * state of the s5h1409 does not match the driver's
3185 the driver performs a reset is during firmware load 3200 * state. Given that the only two conditions in which
3186 and powering down the chip, I am taking out the 3201 * the driver performs a reset is during firmware load
3187 reset. We know that the chip is being reset 3202 * and powering down the chip, I am taking out the
3188 when the cx88 comes online, and not being able to 3203 * reset. We know that the chip is being reset
3189 do power management for this board is worse than 3204 * when the cx88 comes online, and not being able to
3190 not having any tuning at all. */ 3205 * do power management for this board is worse than
3206 * not having any tuning at all.
3207 */
3191 return 0; 3208 return 0;
3192 } else {
3193 dprintk(1, "xc5000: unknown tuner callback command.\n");
3194 return -EINVAL;
3195 } 3209 }
3196 break; 3210
3211 dprintk(1, "xc5000: unknown tuner callback command.\n");
3212 return -EINVAL;
3197 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: 3213 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
3198 if (command == 0) { /* This is the reset command from xc5000 */ 3214 if (command == 0) { /* This is the reset command from xc5000 */
3199 cx_clear(MO_GP0_IO, 0x00000010); 3215 cx_clear(MO_GP0_IO, 0x00000010);
3200 msleep(10); 3216 usleep_range(10000, 20000);
3201 cx_set(MO_GP0_IO, 0x00000010); 3217 cx_set(MO_GP0_IO, 0x00000010);
3202 return 0; 3218 return 0;
3203 } else {
3204 dprintk(1, "xc5000: unknown tuner callback command.\n");
3205 return -EINVAL;
3206 } 3219 }
3207 break; 3220
3221 dprintk(1, "xc5000: unknown tuner callback command.\n");
3222 return -EINVAL;
3208 } 3223 }
3209 return 0; /* Should never be here */ 3224 return 0; /* Should never be here */
3210} 3225}
@@ -3230,15 +3245,15 @@ int cx88_tuner_callback(void *priv, int component, int command, int arg)
3230 return -EINVAL; 3245 return -EINVAL;
3231 3246
3232 switch (core->board.tuner_type) { 3247 switch (core->board.tuner_type) {
3233 case TUNER_XC2028: 3248 case TUNER_XC2028:
3234 dprintk(1, "Calling XC2028/3028 callback\n"); 3249 dprintk(1, "Calling XC2028/3028 callback\n");
3235 return cx88_xc2028_tuner_callback(core, command, arg); 3250 return cx88_xc2028_tuner_callback(core, command, arg);
3236 case TUNER_XC4000: 3251 case TUNER_XC4000:
3237 dprintk(1, "Calling XC4000 callback\n"); 3252 dprintk(1, "Calling XC4000 callback\n");
3238 return cx88_xc4000_tuner_callback(core, command, arg); 3253 return cx88_xc4000_tuner_callback(core, command, arg);
3239 case TUNER_XC5000: 3254 case TUNER_XC5000:
3240 dprintk(1, "Calling XC5000 callback\n"); 3255 dprintk(1, "Calling XC5000 callback\n");
3241 return cx88_xc5000_tuner_callback(core, command, arg); 3256 return cx88_xc5000_tuner_callback(core, command, arg);
3242 } 3257 }
3243 pr_err("Error: Calling callback for tuner %d\n", 3258 pr_err("Error: Calling callback for tuner %d\n",
3244 core->board.tuner_type); 3259 core->board.tuner_type);
@@ -3252,8 +3267,7 @@ static void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
3252{ 3267{
3253 int i; 3268 int i;
3254 3269
3255 if (0 == pci->subsystem_vendor && 3270 if (!pci->subsystem_vendor && !pci->subsystem_device) {
3256 0 == pci->subsystem_device) {
3257 pr_err("Your board has no valid PCI Subsystem ID and thus can't\n"); 3271 pr_err("Your board has no valid PCI Subsystem ID and thus can't\n");
3258 pr_err("be autodetected. Please pass card=<n> insmod option to\n"); 3272 pr_err("be autodetected. Please pass card=<n> insmod option to\n");
3259 pr_err("workaround that. Redirect complaints to the vendor of\n"); 3273 pr_err("workaround that. Redirect complaints to the vendor of\n");
@@ -3274,7 +3288,9 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
3274 switch (core->boardnr) { 3288 switch (core->boardnr) {
3275 case CX88_BOARD_HAUPPAUGE_HVR1300: 3289 case CX88_BOARD_HAUPPAUGE_HVR1300:
3276 /* 3290 /*
3277 * Bring the 702 demod up before i2c scanning/attach or devices are hidden 3291 * Bring the 702 demod up before i2c scanning/attach or
3292 * devices are hidden.
3293 *
3278 * We leave here with the 702 on the bus 3294 * We leave here with the 702 on the bus
3279 * 3295 *
3280 * "reset the IR receiver on GPIO[3]" 3296 * "reset the IR receiver on GPIO[3]"
@@ -3295,7 +3311,7 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
3295 cx_write(MO_GP2_IO, 0xef5); 3311 cx_write(MO_GP2_IO, 0xef5);
3296 mdelay(50); 3312 mdelay(50);
3297 cx_write(MO_GP2_IO, 0xcf7); 3313 cx_write(MO_GP2_IO, 0xcf7);
3298 msleep(10); 3314 usleep_range(10000, 20000);
3299 break; 3315 break;
3300 3316
3301 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: 3317 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
@@ -3331,7 +3347,7 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
3331 case CX88_BOARD_TWINHAN_VP1027_DVBS: 3347 case CX88_BOARD_TWINHAN_VP1027_DVBS:
3332 cx_write(MO_GP0_IO, 0x00003230); 3348 cx_write(MO_GP0_IO, 0x00003230);
3333 cx_write(MO_GP0_IO, 0x00003210); 3349 cx_write(MO_GP0_IO, 0x00003210);
3334 msleep(1); 3350 usleep_range(10000, 20000);
3335 cx_write(MO_GP0_IO, 0x00001230); 3351 cx_write(MO_GP0_IO, 0x00001230);
3336 break; 3352 break;
3337 } 3353 }
@@ -3362,11 +3378,13 @@ void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl)
3362 ctl->demod = XC3028_FE_OREN538; 3378 ctl->demod = XC3028_FE_OREN538;
3363 break; 3379 break;
3364 case CX88_BOARD_GENIATECH_X8000_MT: 3380 case CX88_BOARD_GENIATECH_X8000_MT:
3365 /* FIXME: For this board, the xc3028 never recovers after being 3381 /*
3366 powered down (the reset GPIO probably is not set properly). 3382 * FIXME: For this board, the xc3028 never recovers after being
3367 We don't have access to the hardware so we cannot determine 3383 * powered down (the reset GPIO probably is not set properly).
3368 which GPIO is used for xc3028, so just disable power xc3028 3384 * We don't have access to the hardware so we cannot determine
3369 power management for now */ 3385 * which GPIO is used for xc3028, so just disable power xc3028
3386 * power management for now
3387 */
3370 ctl->disable_power_mgmt = 1; 3388 ctl->disable_power_mgmt = 1;
3371 break; 3389 break;
3372 case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL: 3390 case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
@@ -3396,7 +3414,7 @@ static void cx88_card_setup(struct cx88_core *core)
3396 3414
3397 memset(&tun_setup, 0, sizeof(tun_setup)); 3415 memset(&tun_setup, 0, sizeof(tun_setup));
3398 3416
3399 if (core->i2c_rc == 0) { 3417 if (!core->i2c_rc) {
3400 core->i2c_client.addr = 0xa0 >> 1; 3418 core->i2c_client.addr = 0xa0 >> 1;
3401 tveeprom_read(&core->i2c_client, eeprom, sizeof(eeprom)); 3419 tveeprom_read(&core->i2c_client, eeprom, sizeof(eeprom));
3402 } 3420 }
@@ -3404,17 +3422,17 @@ static void cx88_card_setup(struct cx88_core *core)
3404 switch (core->boardnr) { 3422 switch (core->boardnr) {
3405 case CX88_BOARD_HAUPPAUGE: 3423 case CX88_BOARD_HAUPPAUGE:
3406 case CX88_BOARD_HAUPPAUGE_ROSLYN: 3424 case CX88_BOARD_HAUPPAUGE_ROSLYN:
3407 if (core->i2c_rc == 0) 3425 if (!core->i2c_rc)
3408 hauppauge_eeprom(core, eeprom+8); 3426 hauppauge_eeprom(core, eeprom + 8);
3409 break; 3427 break;
3410 case CX88_BOARD_GDI: 3428 case CX88_BOARD_GDI:
3411 if (core->i2c_rc == 0) 3429 if (!core->i2c_rc)
3412 gdi_eeprom(core, eeprom); 3430 gdi_eeprom(core, eeprom);
3413 break; 3431 break;
3414 case CX88_BOARD_LEADTEK_PVR2000: 3432 case CX88_BOARD_LEADTEK_PVR2000:
3415 case CX88_BOARD_WINFAST_DV2000: 3433 case CX88_BOARD_WINFAST_DV2000:
3416 case CX88_BOARD_WINFAST2000XP_EXPERT: 3434 case CX88_BOARD_WINFAST2000XP_EXPERT:
3417 if (core->i2c_rc == 0) 3435 if (!core->i2c_rc)
3418 leadtek_eeprom(core, eeprom); 3436 leadtek_eeprom(core, eeprom);
3419 break; 3437 break;
3420 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 3438 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
@@ -3427,7 +3445,7 @@ static void cx88_card_setup(struct cx88_core *core)
3427 case CX88_BOARD_HAUPPAUGE_HVR4000: 3445 case CX88_BOARD_HAUPPAUGE_HVR4000:
3428 case CX88_BOARD_HAUPPAUGE_HVR4000LITE: 3446 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
3429 case CX88_BOARD_HAUPPAUGE_IRONLY: 3447 case CX88_BOARD_HAUPPAUGE_IRONLY:
3430 if (core->i2c_rc == 0) 3448 if (!core->i2c_rc)
3431 hauppauge_eeprom(core, eeprom); 3449 hauppauge_eeprom(core, eeprom);
3432 break; 3450 break;
3433 case CX88_BOARD_KWORLD_DVBS_100: 3451 case CX88_BOARD_KWORLD_DVBS_100:
@@ -3438,7 +3456,7 @@ static void cx88_card_setup(struct cx88_core *core)
3438 /* GPIO0:0 is hooked to demod reset */ 3456 /* GPIO0:0 is hooked to demod reset */
3439 /* GPIO0:4 is hooked to xc3028 reset */ 3457 /* GPIO0:4 is hooked to xc3028 reset */
3440 cx_write(MO_GP0_IO, 0x00111100); 3458 cx_write(MO_GP0_IO, 0x00111100);
3441 msleep(1); 3459 usleep_range(10000, 20000);
3442 cx_write(MO_GP0_IO, 0x00111111); 3460 cx_write(MO_GP0_IO, 0x00111111);
3443 break; 3461 break;
3444 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL: 3462 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
@@ -3454,9 +3472,9 @@ static void cx88_card_setup(struct cx88_core *core)
3454 /* GPIO0:0 is hooked to mt352 reset pin */ 3472 /* GPIO0:0 is hooked to mt352 reset pin */
3455 cx_set(MO_GP0_IO, 0x00000101); 3473 cx_set(MO_GP0_IO, 0x00000101);
3456 cx_clear(MO_GP0_IO, 0x00000001); 3474 cx_clear(MO_GP0_IO, 0x00000001);
3457 msleep(1); 3475 usleep_range(10000, 20000);
3458 cx_set(MO_GP0_IO, 0x00000101); 3476 cx_set(MO_GP0_IO, 0x00000101);
3459 if (0 == core->i2c_rc && 3477 if (!core->i2c_rc &&
3460 core->boardnr == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID) 3478 core->boardnr == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID)
3461 dvico_fusionhdtv_hybrid_init(core); 3479 dvico_fusionhdtv_hybrid_init(core);
3462 break; 3480 break;
@@ -3465,7 +3483,7 @@ static void cx88_card_setup(struct cx88_core *core)
3465 cx_set(MO_GP0_IO, 0x00000707); 3483 cx_set(MO_GP0_IO, 0x00000707);
3466 cx_set(MO_GP2_IO, 0x00000101); 3484 cx_set(MO_GP2_IO, 0x00000101);
3467 cx_clear(MO_GP2_IO, 0x00000001); 3485 cx_clear(MO_GP2_IO, 0x00000001);
3468 msleep(1); 3486 usleep_range(10000, 20000);
3469 cx_clear(MO_GP0_IO, 0x00000007); 3487 cx_clear(MO_GP0_IO, 0x00000007);
3470 cx_set(MO_GP2_IO, 0x00000101); 3488 cx_set(MO_GP2_IO, 0x00000101);
3471 break; 3489 break;
@@ -3473,7 +3491,7 @@ static void cx88_card_setup(struct cx88_core *core)
3473 cx_write(MO_GP0_IO, 0x00080808); 3491 cx_write(MO_GP0_IO, 0x00080808);
3474 break; 3492 break;
3475 case CX88_BOARD_ATI_HDTVWONDER: 3493 case CX88_BOARD_ATI_HDTVWONDER:
3476 if (core->i2c_rc == 0) { 3494 if (!core->i2c_rc) {
3477 /* enable tuner */ 3495 /* enable tuner */
3478 int i; 3496 int i;
3479 static const u8 buffer[][2] = { 3497 static const u8 buffer[][2] = {
@@ -3486,8 +3504,8 @@ static void cx88_card_setup(struct cx88_core *core)
3486 core->i2c_client.addr = 0x0a; 3504 core->i2c_client.addr = 0x0a;
3487 3505
3488 for (i = 0; i < ARRAY_SIZE(buffer); i++) 3506 for (i = 0; i < ARRAY_SIZE(buffer); i++)
3489 if (2 != i2c_master_send(&core->i2c_client, 3507 if (i2c_master_send(&core->i2c_client,
3490 buffer[i], 2)) 3508 buffer[i], 2) != 2)
3491 pr_warn("Unable to enable tuner(%i).\n", 3509 pr_warn("Unable to enable tuner(%i).\n",
3492 i); 3510 i);
3493 } 3511 }
@@ -3523,7 +3541,7 @@ static void cx88_card_setup(struct cx88_core *core)
3523 cx_write(MO_GP0_IO, 0x8000); 3541 cx_write(MO_GP0_IO, 0x8000);
3524 msleep(100); 3542 msleep(100);
3525 cx_write(MO_SRST_IO, 0); 3543 cx_write(MO_SRST_IO, 0);
3526 msleep(10); 3544 usleep_range(10000, 20000);
3527 cx_write(MO_GP0_IO, 0x8080); 3545 cx_write(MO_GP0_IO, 0x8080);
3528 msleep(100); 3546 msleep(100);
3529 cx_write(MO_SRST_IO, 1); 3547 cx_write(MO_SRST_IO, 1);
@@ -3531,9 +3549,8 @@ static void cx88_card_setup(struct cx88_core *core)
3531 break; 3549 break;
3532 } /*end switch() */ 3550 } /*end switch() */
3533 3551
3534
3535 /* Setup tuners */ 3552 /* Setup tuners */
3536 if ((core->board.radio_type != UNSET)) { 3553 if (core->board.radio_type != UNSET) {
3537 tun_setup.mode_mask = T_RADIO; 3554 tun_setup.mode_mask = T_RADIO;
3538 tun_setup.type = core->board.radio_type; 3555 tun_setup.type = core->board.radio_type;
3539 tun_setup.addr = core->board.radio_addr; 3556 tun_setup.addr = core->board.radio_addr;
@@ -3621,8 +3638,7 @@ static int cx88_pci_quirks(const char *name, struct pci_dev *pci)
3621 pci_write_config_byte(pci, CX88X_DEVCTRL, value); 3638 pci_write_config_byte(pci, CX88X_DEVCTRL, value);
3622 } 3639 }
3623 if (lat != UNSET) { 3640 if (lat != UNSET) {
3624 pr_info("setting pci latency timer to %d\n", 3641 pr_info("setting pci latency timer to %d\n", latency);
3625 latency);
3626 pci_write_config_byte(pci, PCI_LATENCY_TIMER, latency); 3642 pci_write_config_byte(pci, PCI_LATENCY_TIMER, latency);
3627 } 3643 }
3628 return 0; 3644 return 0;
@@ -3641,15 +3657,17 @@ int cx88_get_resources(const struct cx88_core *core, struct pci_dev *pci)
3641 return -EBUSY; 3657 return -EBUSY;
3642} 3658}
3643 3659
3644/* Allocate and initialize the cx88 core struct. One should hold the 3660/*
3645 * devlist mutex before calling this. */ 3661 * Allocate and initialize the cx88 core struct. One should hold the
3662 * devlist mutex before calling this.
3663 */
3646struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) 3664struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3647{ 3665{
3648 struct cx88_core *core; 3666 struct cx88_core *core;
3649 int i; 3667 int i;
3650 3668
3651 core = kzalloc(sizeof(*core), GFP_KERNEL); 3669 core = kzalloc(sizeof(*core), GFP_KERNEL);
3652 if (core == NULL) 3670 if (!core)
3653 return NULL; 3671 return NULL;
3654 3672
3655 atomic_inc(&core->refcount); 3673 atomic_inc(&core->refcount);
@@ -3701,9 +3719,9 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3701 pci_resource_len(pci, 0)); 3719 pci_resource_len(pci, 0));
3702 core->bmmio = (u8 __iomem *)core->lmmio; 3720 core->bmmio = (u8 __iomem *)core->lmmio;
3703 3721
3704 if (core->lmmio == NULL) { 3722 if (!core->lmmio) {
3705 release_mem_region(pci_resource_start(pci, 0), 3723 release_mem_region(pci_resource_start(pci, 0),
3706 pci_resource_len(pci, 0)); 3724 pci_resource_len(pci, 0));
3707 v4l2_ctrl_handler_free(&core->video_hdl); 3725 v4l2_ctrl_handler_free(&core->video_hdl);
3708 v4l2_ctrl_handler_free(&core->audio_hdl); 3726 v4l2_ctrl_handler_free(&core->audio_hdl);
3709 v4l2_device_unregister(&core->v4l2_dev); 3727 v4l2_device_unregister(&core->v4l2_dev);
@@ -3715,7 +3733,7 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3715 core->boardnr = UNSET; 3733 core->boardnr = UNSET;
3716 if (card[core->nr] < ARRAY_SIZE(cx88_boards)) 3734 if (card[core->nr] < ARRAY_SIZE(cx88_boards))
3717 core->boardnr = card[core->nr]; 3735 core->boardnr = card[core->nr];
3718 for (i = 0; UNSET == core->boardnr && i < ARRAY_SIZE(cx88_subids); i++) 3736 for (i = 0; core->boardnr == UNSET && i < ARRAY_SIZE(cx88_subids); i++)
3719 if (pci->subsystem_vendor == cx88_subids[i].subvendor && 3737 if (pci->subsystem_vendor == cx88_subids[i].subvendor &&
3720 pci->subsystem_device == cx88_subids[i].subdevice) 3738 pci->subsystem_device == cx88_subids[i].subdevice)
3721 core->boardnr = cx88_subids[i].card; 3739 core->boardnr = cx88_subids[i].card;
@@ -3750,9 +3768,11 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3750 3768
3751 /* load tuner module, if needed */ 3769 /* load tuner module, if needed */
3752 if (core->board.tuner_type != UNSET) { 3770 if (core->board.tuner_type != UNSET) {
3753 /* Ignore 0x6b and 0x6f on cx88 boards. 3771 /*
3772 * Ignore 0x6b and 0x6f on cx88 boards.
3754 * FusionHDTV5 RT Gold has an ir receiver at 0x6b 3773 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
3755 * and an RTC at 0x6f which can get corrupted if probed. */ 3774 * and an RTC at 0x6f which can get corrupted if probed.
3775 */
3756 static const unsigned short tv_addrs[] = { 3776 static const unsigned short tv_addrs[] = {
3757 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */ 3777 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
3758 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 3778 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
@@ -3761,24 +3781,27 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3761 }; 3781 };
3762 int has_demod = (core->board.tda9887_conf & TDA9887_PRESENT); 3782 int has_demod = (core->board.tda9887_conf & TDA9887_PRESENT);
3763 3783
3764 /* I don't trust the radio_type as is stored in the card 3784 /*
3765 definitions, so we just probe for it. 3785 * I don't trust the radio_type as is stored in the card
3766 The radio_type is sometimes missing, or set to UNSET but 3786 * definitions, so we just probe for it.
3767 later code configures a tea5767. 3787 * The radio_type is sometimes missing, or set to UNSET but
3788 * later code configures a tea5767.
3768 */ 3789 */
3769 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 3790 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
3770 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO)); 3791 "tuner", 0,
3792 v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3771 if (has_demod) 3793 if (has_demod)
3772 v4l2_i2c_new_subdev(&core->v4l2_dev, 3794 v4l2_i2c_new_subdev(&core->v4l2_dev,
3773 &core->i2c_adap, "tuner", 3795 &core->i2c_adap, "tuner",
3774 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 3796 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3775 if (core->board.tuner_addr == ADDR_UNSET) { 3797 if (core->board.tuner_addr == ADDR_UNSET) {
3776 v4l2_i2c_new_subdev(&core->v4l2_dev, 3798 v4l2_i2c_new_subdev(&core->v4l2_dev,
3777 &core->i2c_adap, "tuner", 3799 &core->i2c_adap, "tuner",
3778 0, has_demod ? tv_addrs + 4 : tv_addrs); 3800 0, has_demod ? tv_addrs + 4 : tv_addrs);
3779 } else { 3801 } else {
3780 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 3802 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
3781 "tuner", core->board.tuner_addr, NULL); 3803 "tuner", core->board.tuner_addr,
3804 NULL);
3782 } 3805 }
3783 } 3806 }
3784 3807
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index 33719f0b06a5..973a9cd4c635 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -72,12 +72,14 @@ static DEFINE_MUTEX(devlist);
72 72
73#define NO_SYNC_LINE (-1U) 73#define NO_SYNC_LINE (-1U)
74 74
75/* @lpi: lines per IRQ, or 0 to not generate irqs. Note: IRQ to be 75/*
76 generated _after_ lpi lines are transferred. */ 76 * @lpi: lines per IRQ, or 0 to not generate irqs. Note: IRQ to be
77 * generated _after_ lpi lines are transferred.
78 */
77static __le32 *cx88_risc_field(__le32 *rp, struct scatterlist *sglist, 79static __le32 *cx88_risc_field(__le32 *rp, struct scatterlist *sglist,
78 unsigned int offset, u32 sync_line, 80 unsigned int offset, u32 sync_line,
79 unsigned int bpl, unsigned int padding, 81 unsigned int bpl, unsigned int padding,
80 unsigned int lines, unsigned int lpi, bool jump) 82 unsigned int lines, unsigned int lpi, bool jump)
81{ 83{
82 struct scatterlist *sg; 84 struct scatterlist *sg;
83 unsigned int line, todo, sol; 85 unsigned int line, todo, sol;
@@ -102,28 +104,29 @@ static __le32 *cx88_risc_field(__le32 *rp, struct scatterlist *sglist,
102 sol = RISC_SOL | RISC_IRQ1 | RISC_CNT_INC; 104 sol = RISC_SOL | RISC_IRQ1 | RISC_CNT_INC;
103 else 105 else
104 sol = RISC_SOL; 106 sol = RISC_SOL;
105 if (bpl <= sg_dma_len(sg)-offset) { 107 if (bpl <= sg_dma_len(sg) - offset) {
106 /* fits into current chunk */ 108 /* fits into current chunk */
107 *(rp++) = cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl); 109 *(rp++) = cpu_to_le32(RISC_WRITE | sol |
108 *(rp++) = cpu_to_le32(sg_dma_address(sg)+offset); 110 RISC_EOL | bpl);
111 *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
109 offset += bpl; 112 offset += bpl;
110 } else { 113 } else {
111 /* scanline needs to be split */ 114 /* scanline needs to be split */
112 todo = bpl; 115 todo = bpl;
113 *(rp++) = cpu_to_le32(RISC_WRITE|sol| 116 *(rp++) = cpu_to_le32(RISC_WRITE | sol |
114 (sg_dma_len(sg)-offset)); 117 (sg_dma_len(sg) - offset));
115 *(rp++) = cpu_to_le32(sg_dma_address(sg)+offset); 118 *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
116 todo -= (sg_dma_len(sg)-offset); 119 todo -= (sg_dma_len(sg) - offset);
117 offset = 0; 120 offset = 0;
118 sg = sg_next(sg); 121 sg = sg_next(sg);
119 while (todo > sg_dma_len(sg)) { 122 while (todo > sg_dma_len(sg)) {
120 *(rp++) = cpu_to_le32(RISC_WRITE| 123 *(rp++) = cpu_to_le32(RISC_WRITE |
121 sg_dma_len(sg)); 124 sg_dma_len(sg));
122 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 125 *(rp++) = cpu_to_le32(sg_dma_address(sg));
123 todo -= sg_dma_len(sg); 126 todo -= sg_dma_len(sg);
124 sg = sg_next(sg); 127 sg = sg_next(sg);
125 } 128 }
126 *(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo); 129 *(rp++) = cpu_to_le32(RISC_WRITE | RISC_EOL | todo);
127 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 130 *(rp++) = cpu_to_le32(sg_dma_address(sg));
128 offset += todo; 131 offset += todo;
129 } 132 }
@@ -147,16 +150,19 @@ int cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
147 if (bottom_offset != UNSET) 150 if (bottom_offset != UNSET)
148 fields++; 151 fields++;
149 152
150 /* estimate risc mem: worst case is one write per page border + 153 /*
151 one write per scan line + syncs + jump (all 2 dwords). Padding 154 * estimate risc mem: worst case is one write per page border +
152 can cause next bpl to start close to a page border. First DMA 155 * one write per scan line + syncs + jump (all 2 dwords). Padding
153 region may be smaller than PAGE_SIZE */ 156 * can cause next bpl to start close to a page border. First DMA
154 instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines); 157 * region may be smaller than PAGE_SIZE
158 */
159 instructions = fields * (1 + ((bpl + padding) * lines) /
160 PAGE_SIZE + lines);
155 instructions += 4; 161 instructions += 4;
156 risc->size = instructions * 8; 162 risc->size = instructions * 8;
157 risc->dma = 0; 163 risc->dma = 0;
158 risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma); 164 risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma);
159 if (risc->cpu == NULL) 165 if (!risc->cpu)
160 return -ENOMEM; 166 return -ENOMEM;
161 167
162 /* write risc instructions */ 168 /* write risc instructions */
@@ -166,13 +172,15 @@ int cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
166 bpl, padding, lines, 0, true); 172 bpl, padding, lines, 0, true);
167 if (bottom_offset != UNSET) 173 if (bottom_offset != UNSET)
168 rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200, 174 rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200,
169 bpl, padding, lines, 0, top_offset == UNSET); 175 bpl, padding, lines, 0,
176 top_offset == UNSET);
170 177
171 /* save pointer to jmp instruction address */ 178 /* save pointer to jmp instruction address */
172 risc->jmp = rp; 179 risc->jmp = rp;
173 WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); 180 WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
174 return 0; 181 return 0;
175} 182}
183EXPORT_SYMBOL(cx88_risc_buffer);
176 184
177int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc, 185int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
178 struct scatterlist *sglist, unsigned int bpl, 186 struct scatterlist *sglist, unsigned int bpl,
@@ -181,32 +189,38 @@ int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
181 u32 instructions; 189 u32 instructions;
182 __le32 *rp; 190 __le32 *rp;
183 191
184 /* estimate risc mem: worst case is one write per page border + 192 /*
185 one write per scan line + syncs + jump (all 2 dwords). Here 193 * estimate risc mem: worst case is one write per page border +
186 there is no padding and no sync. First DMA region may be smaller 194 * one write per scan line + syncs + jump (all 2 dwords). Here
187 than PAGE_SIZE */ 195 * there is no padding and no sync. First DMA region may be smaller
196 * than PAGE_SIZE
197 */
188 instructions = 1 + (bpl * lines) / PAGE_SIZE + lines; 198 instructions = 1 + (bpl * lines) / PAGE_SIZE + lines;
189 instructions += 3; 199 instructions += 3;
190 risc->size = instructions * 8; 200 risc->size = instructions * 8;
191 risc->dma = 0; 201 risc->dma = 0;
192 risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma); 202 risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma);
193 if (risc->cpu == NULL) 203 if (!risc->cpu)
194 return -ENOMEM; 204 return -ENOMEM;
195 205
196 /* write risc instructions */ 206 /* write risc instructions */
197 rp = risc->cpu; 207 rp = risc->cpu;
198 rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi, !lpi); 208 rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0,
209 lines, lpi, !lpi);
199 210
200 /* save pointer to jmp instruction address */ 211 /* save pointer to jmp instruction address */
201 risc->jmp = rp; 212 risc->jmp = rp;
202 WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); 213 WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
203 return 0; 214 return 0;
204} 215}
216EXPORT_SYMBOL(cx88_risc_databuffer);
205 217
206/* ------------------------------------------------------------------ */ 218/*
207/* our SRAM memory layout */ 219 * our SRAM memory layout
220 */
208 221
209/* we are going to put all thr risc programs into host memory, so we 222/*
223 * we are going to put all thr risc programs into host memory, so we
210 * can use the whole SDRAM for the DMA fifos. To simplify things, we 224 * can use the whole SDRAM for the DMA fifos. To simplify things, we
211 * use a static memory layout. That surely will waste memory in case 225 * use a static memory layout. That surely will waste memory in case
212 * we don't use all DMA channels at the same time (which will be the 226 * we don't use all DMA channels at the same time (which will be the
@@ -330,6 +344,7 @@ const struct sram_channel cx88_sram_channels[] = {
330 .cnt2_reg = MO_DMA27_CNT2, 344 .cnt2_reg = MO_DMA27_CNT2,
331 }, 345 },
332}; 346};
347EXPORT_SYMBOL(cx88_sram_channels);
333 348
334int cx88_sram_channel_setup(struct cx88_core *core, 349int cx88_sram_channel_setup(struct cx88_core *core,
335 const struct sram_channel *ch, 350 const struct sram_channel *ch,
@@ -347,12 +362,12 @@ int cx88_sram_channel_setup(struct cx88_core *core,
347 362
348 /* write CDT */ 363 /* write CDT */
349 for (i = 0; i < lines; i++) 364 for (i = 0; i < lines; i++)
350 cx_write(cdt + 16*i, ch->fifo_start + bpl*i); 365 cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
351 366
352 /* write CMDS */ 367 /* write CMDS */
353 cx_write(ch->cmds_start + 0, risc); 368 cx_write(ch->cmds_start + 0, risc);
354 cx_write(ch->cmds_start + 4, cdt); 369 cx_write(ch->cmds_start + 4, cdt);
355 cx_write(ch->cmds_start + 8, (lines*16) >> 3); 370 cx_write(ch->cmds_start + 8, (lines * 16) >> 3);
356 cx_write(ch->cmds_start + 12, ch->ctrl_start); 371 cx_write(ch->cmds_start + 12, ch->ctrl_start);
357 cx_write(ch->cmds_start + 16, 64 >> 2); 372 cx_write(ch->cmds_start + 16, 64 >> 2);
358 for (i = 20; i < 64; i += 4) 373 for (i = 20; i < 64; i += 4)
@@ -362,11 +377,12 @@ int cx88_sram_channel_setup(struct cx88_core *core,
362 cx_write(ch->ptr1_reg, ch->fifo_start); 377 cx_write(ch->ptr1_reg, ch->fifo_start);
363 cx_write(ch->ptr2_reg, cdt); 378 cx_write(ch->ptr2_reg, cdt);
364 cx_write(ch->cnt1_reg, (bpl >> 3) - 1); 379 cx_write(ch->cnt1_reg, (bpl >> 3) - 1);
365 cx_write(ch->cnt2_reg, (lines*16) >> 3); 380 cx_write(ch->cnt2_reg, (lines * 16) >> 3);
366 381
367 dprintk(2, "sram setup %s: bpl=%d lines=%d\n", ch->name, bpl, lines); 382 dprintk(2, "sram setup %s: bpl=%d lines=%d\n", ch->name, bpl, lines);
368 return 0; 383 return 0;
369} 384}
385EXPORT_SYMBOL(cx88_sram_channel_setup);
370 386
371/* ------------------------------------------------------------------ */ 387/* ------------------------------------------------------------------ */
372/* debug helper code */ 388/* debug helper code */
@@ -401,15 +417,14 @@ static int cx88_risc_decode(u32 risc)
401 int i; 417 int i;
402 418
403 dprintk0("0x%08x [ %s", risc, 419 dprintk0("0x%08x [ %s", risc,
404 instr[risc >> 28] ? instr[risc >> 28] : "INVALID"); 420 instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
405 for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) 421 for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--)
406 if (risc & (1 << (i + 12))) 422 if (risc & (1 << (i + 12)))
407 pr_cont(" %s", bits[i]); 423 pr_cont(" %s", bits[i]);
408 pr_cont(" count=%d ]\n", risc & 0xfff); 424 pr_cont(" count=%d ]\n", risc & 0xfff);
409 return incr[risc >> 28] ? incr[risc >> 28] : 1; 425 return incr[risc >> 28] ? incr[risc >> 28] : 1;
410} 426}
411 427
412
413void cx88_sram_channel_dump(struct cx88_core *core, 428void cx88_sram_channel_dump(struct cx88_core *core,
414 const struct sram_channel *ch) 429 const struct sram_channel *ch)
415{ 430{
@@ -429,14 +444,12 @@ void cx88_sram_channel_dump(struct cx88_core *core,
429 u32 risc; 444 u32 risc;
430 unsigned int i, j, n; 445 unsigned int i, j, n;
431 446
432 dprintk0("%s - dma channel status dump\n", 447 dprintk0("%s - dma channel status dump\n", ch->name);
433 ch->name);
434 for (i = 0; i < ARRAY_SIZE(name); i++) 448 for (i = 0; i < ARRAY_SIZE(name); i++)
435 dprintk0(" cmds: %-12s: 0x%08x\n", 449 dprintk0(" cmds: %-12s: 0x%08x\n",
436 name[i], 450 name[i], cx_read(ch->cmds_start + 4 * i));
437 cx_read(ch->cmds_start + 4*i));
438 for (n = 1, i = 0; i < 4; i++) { 451 for (n = 1, i = 0; i < 4; i++) {
439 risc = cx_read(ch->cmds_start + 4 * (i+11)); 452 risc = cx_read(ch->cmds_start + 4 * (i + 11));
440 pr_cont(" risc%d: ", i); 453 pr_cont(" risc%d: ", i);
441 if (--n) 454 if (--n)
442 pr_cont("0x%08x [ arg #%d ]\n", risc, n); 455 pr_cont("0x%08x [ arg #%d ]\n", risc, n);
@@ -448,21 +461,22 @@ void cx88_sram_channel_dump(struct cx88_core *core,
448 dprintk0(" iq %x: ", i); 461 dprintk0(" iq %x: ", i);
449 n = cx88_risc_decode(risc); 462 n = cx88_risc_decode(risc);
450 for (j = 1; j < n; j++) { 463 for (j = 1; j < n; j++) {
451 risc = cx_read(ch->ctrl_start + 4 * (i+j)); 464 risc = cx_read(ch->ctrl_start + 4 * (i + j));
452 pr_cont(" iq %x: 0x%08x [ arg #%d ]\n", 465 pr_cont(" iq %x: 0x%08x [ arg #%d ]\n",
453 i + j, risc, j); 466 i + j, risc, j);
454 } 467 }
455 } 468 }
456 469
457 dprintk0("fifo: 0x%08x -> 0x%x\n", 470 dprintk0("fifo: 0x%08x -> 0x%x\n",
458 ch->fifo_start, ch->fifo_start+ch->fifo_size); 471 ch->fifo_start, ch->fifo_start + ch->fifo_size);
459 dprintk0("ctrl: 0x%08x -> 0x%x\n", 472 dprintk0("ctrl: 0x%08x -> 0x%x\n",
460 ch->ctrl_start, ch->ctrl_start + 6 * 16); 473 ch->ctrl_start, ch->ctrl_start + 6 * 16);
461 dprintk0(" ptr1_reg: 0x%08x\n", cx_read(ch->ptr1_reg)); 474 dprintk0(" ptr1_reg: 0x%08x\n", cx_read(ch->ptr1_reg));
462 dprintk0(" ptr2_reg: 0x%08x\n", cx_read(ch->ptr2_reg)); 475 dprintk0(" ptr2_reg: 0x%08x\n", cx_read(ch->ptr2_reg));
463 dprintk0(" cnt1_reg: 0x%08x\n", cx_read(ch->cnt1_reg)); 476 dprintk0(" cnt1_reg: 0x%08x\n", cx_read(ch->cnt1_reg));
464 dprintk0(" cnt2_reg: 0x%08x\n", cx_read(ch->cnt2_reg)); 477 dprintk0(" cnt2_reg: 0x%08x\n", cx_read(ch->cnt2_reg));
465} 478}
479EXPORT_SYMBOL(cx88_sram_channel_dump);
466 480
467static const char *cx88_pci_irqs[32] = { 481static const char *cx88_pci_irqs[32] = {
468 "vid", "aud", "ts", "vip", "hst", "5", "6", "tm1", 482 "vid", "aud", "ts", "vip", "hst", "5", "6", "tm1",
@@ -490,6 +504,7 @@ void cx88_print_irqbits(const char *tag, const char *strings[],
490 } 504 }
491 pr_cont("\n"); 505 pr_cont("\n");
492} 506}
507EXPORT_SYMBOL(cx88_print_irqbits);
493 508
494/* ------------------------------------------------------------------ */ 509/* ------------------------------------------------------------------ */
495 510
@@ -507,6 +522,7 @@ int cx88_core_irq(struct cx88_core *core, u32 status)
507 status, core->pci_irqmask); 522 status, core->pci_irqmask);
508 return handled; 523 return handled;
509} 524}
525EXPORT_SYMBOL(cx88_core_irq);
510 526
511void cx88_wakeup(struct cx88_core *core, 527void cx88_wakeup(struct cx88_core *core,
512 struct cx88_dmaqueue *q, u32 count) 528 struct cx88_dmaqueue *q, u32 count)
@@ -521,6 +537,7 @@ void cx88_wakeup(struct cx88_core *core,
521 list_del(&buf->list); 537 list_del(&buf->list);
522 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); 538 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
523} 539}
540EXPORT_SYMBOL(cx88_wakeup);
524 541
525void cx88_shutdown(struct cx88_core *core) 542void cx88_shutdown(struct cx88_core *core)
526{ 543{
@@ -545,6 +562,7 @@ void cx88_shutdown(struct cx88_core *core)
545 /* stop capturing */ 562 /* stop capturing */
546 cx_write(VID_CAPTURE_CONTROL, 0); 563 cx_write(VID_CAPTURE_CONTROL, 0);
547} 564}
565EXPORT_SYMBOL(cx88_shutdown);
548 566
549int cx88_reset(struct cx88_core *core) 567int cx88_reset(struct cx88_core *core)
550{ 568{
@@ -560,13 +578,15 @@ int cx88_reset(struct cx88_core *core)
560 msleep(100); 578 msleep(100);
561 579
562 /* init sram */ 580 /* init sram */
563 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], 720*4, 0); 581 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
582 720 * 4, 0);
564 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH22], 128, 0); 583 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH22], 128, 0);
565 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH23], 128, 0); 584 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH23], 128, 0);
566 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH24], 128, 0); 585 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH24], 128, 0);
567 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], 128, 0); 586 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], 128, 0);
568 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], 128, 0); 587 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], 128, 0);
569 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], 188*4, 0); 588 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
589 188 * 4, 0);
570 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH27], 128, 0); 590 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH27], 128, 0);
571 591
572 /* misc init ... */ 592 /* misc init ... */
@@ -594,11 +614,12 @@ int cx88_reset(struct cx88_core *core)
594 614
595 /* Reset on-board parts */ 615 /* Reset on-board parts */
596 cx_write(MO_SRST_IO, 0); 616 cx_write(MO_SRST_IO, 0);
597 msleep(10); 617 usleep_range(10000, 20000);
598 cx_write(MO_SRST_IO, 1); 618 cx_write(MO_SRST_IO, 1);
599 619
600 return 0; 620 return 0;
601} 621}
622EXPORT_SYMBOL(cx88_reset);
602 623
603/* ------------------------------------------------------------------ */ 624/* ------------------------------------------------------------------ */
604 625
@@ -628,10 +649,11 @@ static inline unsigned int norm_fsc8(v4l2_std_id norm)
628 if (norm & V4L2_STD_NTSC) // All NTSC/M and variants 649 if (norm & V4L2_STD_NTSC) // All NTSC/M and variants
629 return 28636360; // 3.57954545 MHz +/- 10 Hz 650 return 28636360; // 3.57954545 MHz +/- 10 Hz
630 651
631 /* SECAM have also different sub carrier for chroma, 652 /*
632 but step_db and step_dr, at cx88_set_tvnorm already handles that. 653 * SECAM have also different sub carrier for chroma,
633 654 * but step_db and step_dr, at cx88_set_tvnorm already handles that.
634 The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N 655 *
656 * The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N
635 */ 657 */
636 658
637 return 35468950; // 4.43361875 MHz +/- 5 Hz 659 return 35468950; // 4.43361875 MHz +/- 5 Hz
@@ -639,13 +661,12 @@ static inline unsigned int norm_fsc8(v4l2_std_id norm)
639 661
640static inline unsigned int norm_htotal(v4l2_std_id norm) 662static inline unsigned int norm_htotal(v4l2_std_id norm)
641{ 663{
642 664 unsigned int fsc4 = norm_fsc8(norm) / 2;
643 unsigned int fsc4 = norm_fsc8(norm)/2;
644 665
645 /* returns 4*FSC / vtotal / frames per seconds */ 666 /* returns 4*FSC / vtotal / frames per seconds */
646 return (norm & V4L2_STD_625_50) ? 667 return (norm & V4L2_STD_625_50) ?
647 ((fsc4+312)/625+12)/25 : 668 ((fsc4 + 312) / 625 + 12) / 25 :
648 ((fsc4+262)/525*1001+15000)/30000; 669 ((fsc4 + 262) / 525 * 1001 + 15000) / 30000;
649} 670}
650 671
651static inline unsigned int norm_vbipack(v4l2_std_id norm) 672static inline unsigned int norm_vbipack(v4l2_std_id norm)
@@ -653,8 +674,8 @@ static inline unsigned int norm_vbipack(v4l2_std_id norm)
653 return (norm & V4L2_STD_625_50) ? 511 : 400; 674 return (norm & V4L2_STD_625_50) ? 511 : 400;
654} 675}
655 676
656int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int height, 677int cx88_set_scale(struct cx88_core *core, unsigned int width,
657 enum v4l2_field field) 678 unsigned int height, enum v4l2_field field)
658{ 679{
659 unsigned int swidth = norm_swidth(core->tvnorm); 680 unsigned int swidth = norm_swidth(core->tvnorm);
660 unsigned int sheight = norm_maxh(core->tvnorm); 681 unsigned int sheight = norm_maxh(core->tvnorm);
@@ -721,6 +742,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
721 742
722 return 0; 743 return 0;
723} 744}
745EXPORT_SYMBOL(cx88_set_scale);
724 746
725static const u32 xtal = 28636363; 747static const u32 xtal = 28636363;
726 748
@@ -749,13 +771,13 @@ static int set_pll(struct cx88_core *core, int prescale, u32 ofreq)
749 cx_write(MO_PLL_REG, reg); 771 cx_write(MO_PLL_REG, reg);
750 for (i = 0; i < 100; i++) { 772 for (i = 0; i < 100; i++) {
751 reg = cx_read(MO_DEVICE_STATUS); 773 reg = cx_read(MO_DEVICE_STATUS);
752 if (reg & (1<<2)) { 774 if (reg & (1 << 2)) {
753 dprintk(1, "pll locked [pre=%d,ofreq=%d]\n", 775 dprintk(1, "pll locked [pre=%d,ofreq=%d]\n",
754 prescale, ofreq); 776 prescale, ofreq);
755 return 0; 777 return 0;
756 } 778 }
757 dprintk(1, "pll not locked yet, waiting ...\n"); 779 dprintk(1, "pll not locked yet, waiting ...\n");
758 msleep(10); 780 usleep_range(10000, 20000);
759 } 781 }
760 dprintk(1, "pll NOT locked [pre=%d,ofreq=%d]\n", prescale, ofreq); 782 dprintk(1, "pll NOT locked [pre=%d,ofreq=%d]\n", prescale, ofreq);
761 return -1; 783 return -1;
@@ -764,9 +786,9 @@ static int set_pll(struct cx88_core *core, int prescale, u32 ofreq)
764int cx88_start_audio_dma(struct cx88_core *core) 786int cx88_start_audio_dma(struct cx88_core *core)
765{ 787{
766 /* constant 128 made buzz in analog Nicam-stereo for bigger fifo_size */ 788 /* constant 128 made buzz in analog Nicam-stereo for bigger fifo_size */
767 int bpl = cx88_sram_channels[SRAM_CH25].fifo_size/4; 789 int bpl = cx88_sram_channels[SRAM_CH25].fifo_size / 4;
768 790
769 int rds_bpl = cx88_sram_channels[SRAM_CH27].fifo_size/AUD_RDS_LINES; 791 int rds_bpl = cx88_sram_channels[SRAM_CH27].fifo_size / AUD_RDS_LINES;
770 792
771 /* If downstream RISC is enabled, bail out; ALSA is managing DMA */ 793 /* If downstream RISC is enabled, bail out; ALSA is managing DMA */
772 if (cx_read(MO_AUD_DMACNTRL) & 0x10) 794 if (cx_read(MO_AUD_DMACNTRL) & 0x10)
@@ -803,8 +825,8 @@ static int set_tvaudio(struct cx88_core *core)
803{ 825{
804 v4l2_std_id norm = core->tvnorm; 826 v4l2_std_id norm = core->tvnorm;
805 827
806 if (CX88_VMUX_TELEVISION != INPUT(core->input).type && 828 if (INPUT(core->input).type != CX88_VMUX_TELEVISION &&
807 CX88_VMUX_CABLE != INPUT(core->input).type) 829 INPUT(core->input).type != CX88_VMUX_CABLE)
808 return 0; 830 return 0;
809 831
810 if (V4L2_STD_PAL_BG & norm) { 832 if (V4L2_STD_PAL_BG & norm) {
@@ -819,7 +841,8 @@ static int set_tvaudio(struct cx88_core *core)
819 } else if (V4L2_STD_SECAM_L & norm) { 841 } else if (V4L2_STD_SECAM_L & norm) {
820 core->tvaudio = WW_L; 842 core->tvaudio = WW_L;
821 843
822 } else if ((V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H) & norm) { 844 } else if ((V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H) &
845 norm) {
823 core->tvaudio = WW_BG; 846 core->tvaudio = WW_BG;
824 847
825 } else if (V4L2_STD_SECAM_DK & norm) { 848 } else if (V4L2_STD_SECAM_DK & norm) {
@@ -844,15 +867,13 @@ static int set_tvaudio(struct cx88_core *core)
844 /* cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); */ 867 /* cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); */
845 868
846/* 869/*
847 This should be needed only on cx88-alsa. It seems that some cx88 chips have 870 * This should be needed only on cx88-alsa. It seems that some cx88 chips have
848 bugs and does require DMA enabled for it to work. 871 * bugs and does require DMA enabled for it to work.
849 */ 872 */
850 cx88_start_audio_dma(core); 873 cx88_start_audio_dma(core);
851 return 0; 874 return 0;
852} 875}
853 876
854
855
856int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm) 877int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
857{ 878{
858 u32 fsc8; 879 u32 fsc8;
@@ -916,8 +937,10 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
916 937
917 dprintk(1, "set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n", 938 dprintk(1, "set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
918 cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); 939 cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
919 /* Chroma AGC must be disabled if SECAM is used, we enable it 940 /*
920 by default on PAL and NTSC */ 941 * Chroma AGC must be disabled if SECAM is used, we enable it
942 * by default on PAL and NTSC
943 */
921 cx_andor(MO_INPUT_FORMAT, 0x40f, 944 cx_andor(MO_INPUT_FORMAT, 0x40f,
922 norm & V4L2_STD_SECAM ? cxiformat : cxiformat | 0x400); 945 norm & V4L2_STD_SECAM ? cxiformat : cxiformat | 0x400);
923 946
@@ -952,7 +975,8 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
952 agcdelay = vdec_clock * 68 / 20000000 + 15; 975 agcdelay = vdec_clock * 68 / 20000000 + 15;
953 dprintk(1, 976 dprintk(1,
954 "set_tvnorm: MO_AGC_BURST 0x%08x [old=0x%08x,bdelay=%d,agcdelay=%d]\n", 977 "set_tvnorm: MO_AGC_BURST 0x%08x [old=0x%08x,bdelay=%d,agcdelay=%d]\n",
955 (bdelay << 8) | agcdelay, cx_read(MO_AGC_BURST), bdelay, agcdelay); 978 (bdelay << 8) | agcdelay, cx_read(MO_AGC_BURST),
979 bdelay, agcdelay);
956 cx_write(MO_AGC_BURST, (bdelay << 8) | agcdelay); 980 cx_write(MO_AGC_BURST, (bdelay << 8) | agcdelay);
957 981
958 // htotal 982 // htotal
@@ -966,7 +990,7 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
966 990
967 // vbi stuff, set vbi offset to 10 (for 20 Clk*2 pixels), this makes 991 // vbi stuff, set vbi offset to 10 (for 20 Clk*2 pixels), this makes
968 // the effective vbi offset ~244 samples, the same as the Bt8x8 992 // the effective vbi offset ~244 samples, the same as the Bt8x8
969 cx_write(MO_VBI_PACKET, (10<<11) | norm_vbipack(norm)); 993 cx_write(MO_VBI_PACKET, (10 << 11) | norm_vbipack(norm));
970 994
971 // this is needed as well to set all tvnorm parameter 995 // this is needed as well to set all tvnorm parameter
972 cx88_set_scale(core, 320, 240, V4L2_FIELD_INTERLACED); 996 cx88_set_scale(core, 320, 240, V4L2_FIELD_INTERLACED);
@@ -977,12 +1001,16 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
977 // tell i2c chips 1001 // tell i2c chips
978 call_all(core, video, s_std, norm); 1002 call_all(core, video, s_std, norm);
979 1003
980 /* The chroma_agc control should be inaccessible if the video format is SECAM */ 1004 /*
1005 * The chroma_agc control should be inaccessible
1006 * if the video format is SECAM
1007 */
981 v4l2_ctrl_grab(core->chroma_agc, cxiformat == VideoFormatSECAM); 1008 v4l2_ctrl_grab(core->chroma_agc, cxiformat == VideoFormatSECAM);
982 1009
983 // done 1010 // done
984 return 0; 1011 return 0;
985} 1012}
1013EXPORT_SYMBOL(cx88_set_tvnorm);
986 1014
987/* ------------------------------------------------------------------ */ 1015/* ------------------------------------------------------------------ */
988 1016
@@ -1007,6 +1035,7 @@ void cx88_vdev_init(struct cx88_core *core,
1007 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 1035 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
1008 core->name, type, core->board.name); 1036 core->name, type, core->board.name);
1009} 1037}
1038EXPORT_SYMBOL(cx88_vdev_init);
1010 1039
1011struct cx88_core *cx88_core_get(struct pci_dev *pci) 1040struct cx88_core *cx88_core_get(struct pci_dev *pci)
1012{ 1041{
@@ -1029,7 +1058,7 @@ struct cx88_core *cx88_core_get(struct pci_dev *pci)
1029 } 1058 }
1030 1059
1031 core = cx88_core_create(pci, cx88_devcount); 1060 core = cx88_core_create(pci, cx88_devcount);
1032 if (core != NULL) { 1061 if (core) {
1033 cx88_devcount++; 1062 cx88_devcount++;
1034 list_add_tail(&core->devlist, &cx88_devlist); 1063 list_add_tail(&core->devlist, &cx88_devlist);
1035 } 1064 }
@@ -1037,6 +1066,7 @@ struct cx88_core *cx88_core_get(struct pci_dev *pci)
1037 mutex_unlock(&devlist); 1066 mutex_unlock(&devlist);
1038 return core; 1067 return core;
1039} 1068}
1069EXPORT_SYMBOL(cx88_core_get);
1040 1070
1041void cx88_core_put(struct cx88_core *core, struct pci_dev *pci) 1071void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1042{ 1072{
@@ -1062,29 +1092,4 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1062 v4l2_device_unregister(&core->v4l2_dev); 1092 v4l2_device_unregister(&core->v4l2_dev);
1063 kfree(core); 1093 kfree(core);
1064} 1094}
1065
1066/* ------------------------------------------------------------------ */
1067
1068EXPORT_SYMBOL(cx88_print_irqbits);
1069
1070EXPORT_SYMBOL(cx88_core_irq);
1071EXPORT_SYMBOL(cx88_wakeup);
1072EXPORT_SYMBOL(cx88_reset);
1073EXPORT_SYMBOL(cx88_shutdown);
1074
1075EXPORT_SYMBOL(cx88_risc_buffer);
1076EXPORT_SYMBOL(cx88_risc_databuffer);
1077
1078EXPORT_SYMBOL(cx88_sram_channels);
1079EXPORT_SYMBOL(cx88_sram_channel_setup);
1080EXPORT_SYMBOL(cx88_sram_channel_dump);
1081
1082EXPORT_SYMBOL(cx88_set_tvnorm);
1083EXPORT_SYMBOL(cx88_set_scale);
1084
1085EXPORT_SYMBOL(cx88_vdev_init);
1086EXPORT_SYMBOL(cx88_core_get);
1087EXPORT_SYMBOL(cx88_core_put); 1095EXPORT_SYMBOL(cx88_core_put);
1088
1089EXPORT_SYMBOL(cx88_ir_start);
1090EXPORT_SYMBOL(cx88_ir_stop);
diff --git a/drivers/media/pci/cx88/cx88-dsp.c b/drivers/media/pci/cx88/cx88-dsp.c
index 235124e2a763..105029088120 100644
--- a/drivers/media/pci/cx88/cx88-dsp.c
+++ b/drivers/media/pci/cx88/cx88-dsp.c
@@ -31,18 +31,22 @@
31#define baseband_freq(carrier, srate, tone) ((s32)( \ 31#define baseband_freq(carrier, srate, tone) ((s32)( \
32 (compat_remainder(carrier + tone, srate)) / srate * 2 * INT_PI)) 32 (compat_remainder(carrier + tone, srate)) / srate * 2 * INT_PI))
33 33
34/* We calculate the baseband frequencies of the carrier and the pilot tones 34/*
35 * based on the the sampling rate of the audio rds fifo. */ 35 * We calculate the baseband frequencies of the carrier and the pilot tones
36 * based on the the sampling rate of the audio rds fifo.
37 */
36 38
37#define FREQ_A2_CARRIER baseband_freq(54687.5, 2689.36, 0.0) 39#define FREQ_A2_CARRIER baseband_freq(54687.5, 2689.36, 0.0)
38#define FREQ_A2_DUAL baseband_freq(54687.5, 2689.36, 274.1) 40#define FREQ_A2_DUAL baseband_freq(54687.5, 2689.36, 274.1)
39#define FREQ_A2_STEREO baseband_freq(54687.5, 2689.36, 117.5) 41#define FREQ_A2_STEREO baseband_freq(54687.5, 2689.36, 117.5)
40 42
41/* The frequencies below are from the reference driver. They probably need 43/*
44 * The frequencies below are from the reference driver. They probably need
42 * further adjustments, because they are not tested at all. You may even need 45 * further adjustments, because they are not tested at all. You may even need
43 * to play a bit with the registers of the chip to select the proper signal 46 * to play a bit with the registers of the chip to select the proper signal
44 * for the input of the audio rds fifo, and measure it's sampling rate to 47 * for the input of the audio rds fifo, and measure it's sampling rate to
45 * calculate the proper baseband frequencies... */ 48 * calculate the proper baseband frequencies...
49 */
46 50
47#define FREQ_A2M_CARRIER ((s32)(2.114516 * 32768.0)) 51#define FREQ_A2M_CARRIER ((s32)(2.114516 * 32768.0))
48#define FREQ_A2M_DUAL ((s32)(2.754916 * 32768.0)) 52#define FREQ_A2M_DUAL ((s32)(2.754916 * 32768.0))
@@ -83,8 +87,10 @@ static s32 int_cos(u32 x)
83 x = x % INT_PI; 87 x = x % INT_PI;
84 if (x > INT_PI / 2) 88 if (x > INT_PI / 2)
85 return -int_cos(INT_PI / 2 - (x % (INT_PI / 2))); 89 return -int_cos(INT_PI / 2 - (x % (INT_PI / 2)));
86 /* Now x is between 0 and INT_PI/2. 90 /*
87 * To calculate cos(x) we use it's Taylor polinom. */ 91 * Now x is between 0 and INT_PI/2.
92 * To calculate cos(x) we use it's Taylor polinom.
93 */
88 t2 = x * x / 32768 / 2; 94 t2 = x * x / 32768 / 2;
89 t4 = t2 * x / 32768 * x / 32768 / 3 / 4; 95 t4 = t2 * x / 32768 * x / 32768 / 3 / 4;
90 t6 = t4 * x / 32768 * x / 32768 / 5 / 6; 96 t6 = t4 * x / 32768 * x / 32768 / 5 / 6;
@@ -95,8 +101,10 @@ static s32 int_cos(u32 x)
95 101
96static u32 int_goertzel(s16 x[], u32 N, u32 freq) 102static u32 int_goertzel(s16 x[], u32 N, u32 freq)
97{ 103{
98 /* We use the Goertzel algorithm to determine the power of the 104 /*
99 * given frequency in the signal */ 105 * We use the Goertzel algorithm to determine the power of the
106 * given frequency in the signal
107 */
100 s32 s_prev = 0; 108 s32 s_prev = 0;
101 s32 s_prev2 = 0; 109 s32 s_prev2 = 0;
102 s32 coeff = 2 * int_cos(freq); 110 s32 coeff = 2 * int_cos(freq);
@@ -115,12 +123,14 @@ static u32 int_goertzel(s16 x[], u32 N, u32 freq)
115 tmp = (s64)s_prev2 * s_prev2 + (s64)s_prev * s_prev - 123 tmp = (s64)s_prev2 * s_prev2 + (s64)s_prev * s_prev -
116 (s64)coeff * s_prev2 * s_prev / 32768; 124 (s64)coeff * s_prev2 * s_prev / 32768;
117 125
118 /* XXX: N must be low enough so that N*N fits in s32. 126 /*
119 * Else we need two divisions. */ 127 * XXX: N must be low enough so that N*N fits in s32.
128 * Else we need two divisions.
129 */
120 divisor = N * N; 130 divisor = N * N;
121 do_div(tmp, divisor); 131 do_div(tmp, divisor);
122 132
123 return (u32) tmp; 133 return (u32)tmp;
124} 134}
125 135
126static u32 freq_magnitude(s16 x[], u32 N, u32 freq) 136static u32 freq_magnitude(s16 x[], u32 N, u32 freq)
@@ -187,7 +197,8 @@ static s32 detect_a2_a2m_eiaj(struct cx88_core *core, s16 x[], u32 N)
187 dual = freq_magnitude(x, N, dual_freq); 197 dual = freq_magnitude(x, N, dual_freq);
188 noise = noise_magnitude(x, N, FREQ_NOISE_START, FREQ_NOISE_END); 198 noise = noise_magnitude(x, N, FREQ_NOISE_START, FREQ_NOISE_END);
189 199
190 dprintk(1, "detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, noise=%d\n", 200 dprintk(1,
201 "detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, noise=%d\n",
191 carrier, stereo, dual, noise); 202 carrier, stereo, dual, noise);
192 203
193 if (stereo > dual) 204 if (stereo > dual)
@@ -201,8 +212,10 @@ static s32 detect_a2_a2m_eiaj(struct cx88_core *core, s16 x[], u32 N)
201 (carrier < max(stereo, dual) * 6) && 212 (carrier < max(stereo, dual) * 6) &&
202 (carrier > 20 && carrier < 200) && 213 (carrier > 20 && carrier < 200) &&
203 (max(stereo, dual) > min(stereo, dual))) { 214 (max(stereo, dual) > min(stereo, dual))) {
204 /* For EIAJ the carrier is always present, 215 /*
205 so we probably don't need noise detection */ 216 * For EIAJ the carrier is always present,
217 * so we probably don't need noise detection
218 */
206 return ret; 219 return ret;
207 } 220 }
208 } else { 221 } else {
@@ -243,7 +256,8 @@ static s16 *read_rds_samples(struct cx88_core *core, u32 *N)
243 u32 current_address = cx_read(srch->ptr1_reg); 256 u32 current_address = cx_read(srch->ptr1_reg);
244 u32 offset = (current_address - srch->fifo_start + bpl); 257 u32 offset = (current_address - srch->fifo_start + bpl);
245 258
246 dprintk(1, "read RDS samples: current_address=%08x (offset=%08x), sample_count=%d, aud_intstat=%08x\n", 259 dprintk(1,
260 "read RDS samples: current_address=%08x (offset=%08x), sample_count=%d, aud_intstat=%08x\n",
247 current_address, 261 current_address,
248 current_address - srch->fifo_start, sample_count, 262 current_address - srch->fifo_start, sample_count,
249 cx_read(MO_AUD_INTSTAT)); 263 cx_read(MO_AUD_INTSTAT));
@@ -308,9 +322,9 @@ s32 cx88_dsp_detect_stereo_sap(struct cx88_core *core)
308 322
309 if (ret != UNSET) 323 if (ret != UNSET)
310 dprintk(1, "stereo/sap detection result:%s%s%s\n", 324 dprintk(1, "stereo/sap detection result:%s%s%s\n",
311 (ret & V4L2_TUNER_SUB_MONO) ? " mono" : "", 325 (ret & V4L2_TUNER_SUB_MONO) ? " mono" : "",
312 (ret & V4L2_TUNER_SUB_STEREO) ? " stereo" : "", 326 (ret & V4L2_TUNER_SUB_STEREO) ? " stereo" : "",
313 (ret & V4L2_TUNER_SUB_LANG2) ? " dual" : ""); 327 (ret & V4L2_TUNER_SUB_LANG2) ? " dual" : "");
314 328
315 return ret; 329 return ret;
316} 330}
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 5188f8f2d6dd..ddf90678df34 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -82,8 +82,8 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
82/* ------------------------------------------------------------------ */ 82/* ------------------------------------------------------------------ */
83 83
84static int queue_setup(struct vb2_queue *q, 84static int queue_setup(struct vb2_queue *q,
85 unsigned int *num_buffers, unsigned int *num_planes, 85 unsigned int *num_buffers, unsigned int *num_planes,
86 unsigned int sizes[], struct device *alloc_devs[]) 86 unsigned int sizes[], struct device *alloc_devs[])
87{ 87{
88 struct cx8802_dev *dev = q->drv_priv; 88 struct cx8802_dev *dev = q->drv_priv;
89 89
@@ -445,7 +445,7 @@ static const struct nxt200x_config ati_hdtvwonder = {
445}; 445};
446 446
447static int cx24123_set_ts_param(struct dvb_frontend *fe, 447static int cx24123_set_ts_param(struct dvb_frontend *fe,
448 int is_punctured) 448 int is_punctured)
449{ 449{
450 struct cx8802_dev *dev = fe->dvb->priv; 450 struct cx8802_dev *dev = fe->dvb->priv;
451 451
@@ -684,7 +684,7 @@ static int attach_xc4000(struct cx8802_dev *dev, struct xc4000_config *cfg)
684} 684}
685 685
686static int cx24116_set_ts_param(struct dvb_frontend *fe, 686static int cx24116_set_ts_param(struct dvb_frontend *fe,
687 int is_punctured) 687 int is_punctured)
688{ 688{
689 struct cx8802_dev *dev = fe->dvb->priv; 689 struct cx8802_dev *dev = fe->dvb->priv;
690 690
@@ -694,7 +694,7 @@ static int cx24116_set_ts_param(struct dvb_frontend *fe,
694} 694}
695 695
696static int stv0900_set_ts_param(struct dvb_frontend *fe, 696static int stv0900_set_ts_param(struct dvb_frontend *fe,
697 int is_punctured) 697 int is_punctured)
698{ 698{
699 struct cx8802_dev *dev = fe->dvb->priv; 699 struct cx8802_dev *dev = fe->dvb->priv;
700 700
@@ -711,10 +711,10 @@ static int cx24116_reset_device(struct dvb_frontend *fe)
711 /* Reset the part */ 711 /* Reset the part */
712 /* Put the cx24116 into reset */ 712 /* Put the cx24116 into reset */
713 cx_write(MO_SRST_IO, 0); 713 cx_write(MO_SRST_IO, 0);
714 msleep(10); 714 usleep_range(10000, 20000);
715 /* Take the cx24116 out of reset */ 715 /* Take the cx24116 out of reset */
716 cx_write(MO_SRST_IO, 1); 716 cx_write(MO_SRST_IO, 1);
717 msleep(10); 717 usleep_range(10000, 20000);
718 718
719 return 0; 719 return 0;
720} 720}
@@ -732,7 +732,7 @@ static const struct cx24116_config tevii_s460_config = {
732}; 732};
733 733
734static int ds3000_set_ts_param(struct dvb_frontend *fe, 734static int ds3000_set_ts_param(struct dvb_frontend *fe,
735 int is_punctured) 735 int is_punctured)
736{ 736{
737 struct cx8802_dev *dev = fe->dvb->priv; 737 struct cx8802_dev *dev = fe->dvb->priv;
738 738
@@ -812,8 +812,6 @@ static int cx8802_alloc_frontends(struct cx8802_dev *dev)
812 return 0; 812 return 0;
813} 813}
814 814
815
816
817static const u8 samsung_smt_7020_inittab[] = { 815static const u8 samsung_smt_7020_inittab[] = {
818 0x01, 0x15, 816 0x01, 0x15,
819 0x02, 0x00, 817 0x02, 0x00,
@@ -865,7 +863,6 @@ static const u8 samsung_smt_7020_inittab[] = {
865 0xff, 0xff, 863 0xff, 0xff,
866}; 864};
867 865
868
869static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe) 866static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe)
870{ 867{
871 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 868 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
@@ -898,7 +895,7 @@ static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe)
898} 895}
899 896
900static int samsung_smt_7020_set_tone(struct dvb_frontend *fe, 897static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,
901 enum fe_sec_tone_mode tone) 898 enum fe_sec_tone_mode tone)
902{ 899{
903 struct cx8802_dev *dev = fe->dvb->priv; 900 struct cx8802_dev *dev = fe->dvb->priv;
904 struct cx88_core *core = dev->core; 901 struct cx88_core *core = dev->core;
@@ -953,7 +950,7 @@ static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe,
953} 950}
954 951
955static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe, 952static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe,
956 u32 srate, u32 ratio) 953 u32 srate, u32 ratio)
957{ 954{
958 u8 aclk = 0; 955 u8 aclk = 0;
959 u8 bclk = 0; 956 u8 bclk = 0;
@@ -987,7 +984,6 @@ static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe,
987 return 0; 984 return 0;
988} 985}
989 986
990
991static const struct stv0299_config samsung_stv0299_config = { 987static const struct stv0299_config samsung_stv0299_config = {
992 .demod_address = 0x68, 988 .demod_address = 0x68,
993 .inittab = samsung_smt_7020_inittab, 989 .inittab = samsung_smt_7020_inittab,
@@ -1029,7 +1025,7 @@ static int dvb_register(struct cx8802_dev *dev)
1029 fe0->dvb.frontend = dvb_attach(cx22702_attach, 1025 fe0->dvb.frontend = dvb_attach(cx22702_attach,
1030 &connexant_refboard_config, 1026 &connexant_refboard_config,
1031 &core->i2c_adap); 1027 &core->i2c_adap);
1032 if (fe0->dvb.frontend != NULL) { 1028 if (fe0->dvb.frontend) {
1033 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1029 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1034 0x61, &core->i2c_adap, 1030 0x61, &core->i2c_adap,
1035 DVB_PLL_THOMSON_DTT759X)) 1031 DVB_PLL_THOMSON_DTT759X))
@@ -1043,7 +1039,7 @@ static int dvb_register(struct cx8802_dev *dev)
1043 fe0->dvb.frontend = dvb_attach(cx22702_attach, 1039 fe0->dvb.frontend = dvb_attach(cx22702_attach,
1044 &connexant_refboard_config, 1040 &connexant_refboard_config,
1045 &core->i2c_adap); 1041 &core->i2c_adap);
1046 if (fe0->dvb.frontend != NULL) { 1042 if (fe0->dvb.frontend) {
1047 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1043 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1048 0x60, &core->i2c_adap, 1044 0x60, &core->i2c_adap,
1049 DVB_PLL_THOMSON_DTT7579)) 1045 DVB_PLL_THOMSON_DTT7579))
@@ -1057,10 +1053,10 @@ static int dvb_register(struct cx8802_dev *dev)
1057 fe0->dvb.frontend = dvb_attach(cx22702_attach, 1053 fe0->dvb.frontend = dvb_attach(cx22702_attach,
1058 &hauppauge_hvr_config, 1054 &hauppauge_hvr_config,
1059 &core->i2c_adap); 1055 &core->i2c_adap);
1060 if (fe0->dvb.frontend != NULL) { 1056 if (fe0->dvb.frontend) {
1061 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1057 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1062 &core->i2c_adap, 0x61, 1058 &core->i2c_adap, 0x61,
1063 TUNER_PHILIPS_FMD1216ME_MK3)) 1059 TUNER_PHILIPS_FMD1216ME_MK3))
1064 goto frontend_detach; 1060 goto frontend_detach;
1065 } 1061 }
1066 break; 1062 break;
@@ -1068,10 +1064,10 @@ static int dvb_register(struct cx8802_dev *dev)
1068 fe0->dvb.frontend = dvb_attach(cx22702_attach, 1064 fe0->dvb.frontend = dvb_attach(cx22702_attach,
1069 &hauppauge_hvr_config, 1065 &hauppauge_hvr_config,
1070 &core->i2c_adap); 1066 &core->i2c_adap);
1071 if (fe0->dvb.frontend != NULL) { 1067 if (fe0->dvb.frontend) {
1072 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1068 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1073 &core->i2c_adap, 0x61, 1069 &core->i2c_adap, 0x61,
1074 TUNER_PHILIPS_FMD1216MEX_MK3)) 1070 TUNER_PHILIPS_FMD1216MEX_MK3))
1075 goto frontend_detach; 1071 goto frontend_detach;
1076 } 1072 }
1077 break; 1073 break;
@@ -1081,8 +1077,8 @@ static int dvb_register(struct cx8802_dev *dev)
1081 dev->frontends.gate = 2; 1077 dev->frontends.gate = 2;
1082 /* DVB-S init */ 1078 /* DVB-S init */
1083 fe0->dvb.frontend = dvb_attach(cx24123_attach, 1079 fe0->dvb.frontend = dvb_attach(cx24123_attach,
1084 &hauppauge_novas_config, 1080 &hauppauge_novas_config,
1085 &dev->core->i2c_adap); 1081 &dev->core->i2c_adap);
1086 if (fe0->dvb.frontend) { 1082 if (fe0->dvb.frontend) {
1087 if (!dvb_attach(isl6421_attach, 1083 if (!dvb_attach(isl6421_attach,
1088 fe0->dvb.frontend, 1084 fe0->dvb.frontend,
@@ -1096,8 +1092,8 @@ static int dvb_register(struct cx8802_dev *dev)
1096 goto frontend_detach; 1092 goto frontend_detach;
1097 /* DVB-T init */ 1093 /* DVB-T init */
1098 fe1->dvb.frontend = dvb_attach(cx22702_attach, 1094 fe1->dvb.frontend = dvb_attach(cx22702_attach,
1099 &hauppauge_hvr_config, 1095 &hauppauge_hvr_config,
1100 &dev->core->i2c_adap); 1096 &dev->core->i2c_adap);
1101 if (fe1->dvb.frontend) { 1097 if (fe1->dvb.frontend) {
1102 fe1->dvb.frontend->id = 1; 1098 fe1->dvb.frontend->id = 1;
1103 if (!dvb_attach(simple_tuner_attach, 1099 if (!dvb_attach(simple_tuner_attach,
@@ -1111,7 +1107,7 @@ static int dvb_register(struct cx8802_dev *dev)
1111 fe0->dvb.frontend = dvb_attach(mt352_attach, 1107 fe0->dvb.frontend = dvb_attach(mt352_attach,
1112 &dvico_fusionhdtv, 1108 &dvico_fusionhdtv,
1113 &core->i2c_adap); 1109 &core->i2c_adap);
1114 if (fe0->dvb.frontend != NULL) { 1110 if (fe0->dvb.frontend) {
1115 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1111 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1116 0x60, NULL, DVB_PLL_THOMSON_DTT7579)) 1112 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
1117 goto frontend_detach; 1113 goto frontend_detach;
@@ -1121,19 +1117,21 @@ static int dvb_register(struct cx8802_dev *dev)
1121 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1117 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1122 &dvico_fusionhdtv_plus_v1_1, 1118 &dvico_fusionhdtv_plus_v1_1,
1123 &core->i2c_adap); 1119 &core->i2c_adap);
1124 if (fe0->dvb.frontend != NULL) { 1120 if (fe0->dvb.frontend) {
1125 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1121 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1126 0x60, NULL, DVB_PLL_THOMSON_DTT7579)) 1122 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
1127 goto frontend_detach; 1123 goto frontend_detach;
1128 } 1124 }
1129 break; 1125 break;
1130 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL: 1126 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
1131 /* The tin box says DEE1601, but it seems to be DTT7579 1127 /*
1132 * compatible, with a slightly different MT352 AGC gain. */ 1128 * The tin box says DEE1601, but it seems to be DTT7579
1129 * compatible, with a slightly different MT352 AGC gain.
1130 */
1133 fe0->dvb.frontend = dvb_attach(mt352_attach, 1131 fe0->dvb.frontend = dvb_attach(mt352_attach,
1134 &dvico_fusionhdtv_dual, 1132 &dvico_fusionhdtv_dual,
1135 &core->i2c_adap); 1133 &core->i2c_adap);
1136 if (fe0->dvb.frontend != NULL) { 1134 if (fe0->dvb.frontend) {
1137 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1135 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1138 0x61, NULL, DVB_PLL_THOMSON_DTT7579)) 1136 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
1139 goto frontend_detach; 1137 goto frontend_detach;
@@ -1143,7 +1141,7 @@ static int dvb_register(struct cx8802_dev *dev)
1143 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1141 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1144 &dvico_fusionhdtv_plus_v1_1, 1142 &dvico_fusionhdtv_plus_v1_1,
1145 &core->i2c_adap); 1143 &core->i2c_adap);
1146 if (fe0->dvb.frontend != NULL) { 1144 if (fe0->dvb.frontend) {
1147 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1145 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1148 0x61, NULL, DVB_PLL_THOMSON_DTT7579)) 1146 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
1149 goto frontend_detach; 1147 goto frontend_detach;
@@ -1153,7 +1151,7 @@ static int dvb_register(struct cx8802_dev *dev)
1153 fe0->dvb.frontend = dvb_attach(mt352_attach, 1151 fe0->dvb.frontend = dvb_attach(mt352_attach,
1154 &dvico_fusionhdtv, 1152 &dvico_fusionhdtv,
1155 &core->i2c_adap); 1153 &core->i2c_adap);
1156 if (fe0->dvb.frontend != NULL) { 1154 if (fe0->dvb.frontend) {
1157 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1155 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1158 0x61, NULL, DVB_PLL_LG_Z201)) 1156 0x61, NULL, DVB_PLL_LG_Z201))
1159 goto frontend_detach; 1157 goto frontend_detach;
@@ -1165,7 +1163,7 @@ static int dvb_register(struct cx8802_dev *dev)
1165 fe0->dvb.frontend = dvb_attach(mt352_attach, 1163 fe0->dvb.frontend = dvb_attach(mt352_attach,
1166 &dntv_live_dvbt_config, 1164 &dntv_live_dvbt_config,
1167 &core->i2c_adap); 1165 &core->i2c_adap);
1168 if (fe0->dvb.frontend != NULL) { 1166 if (fe0->dvb.frontend) {
1169 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 1167 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
1170 0x61, NULL, DVB_PLL_UNKNOWN_1)) 1168 0x61, NULL, DVB_PLL_UNKNOWN_1))
1171 goto frontend_detach; 1169 goto frontend_detach;
@@ -1174,9 +1172,10 @@ static int dvb_register(struct cx8802_dev *dev)
1174 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 1172 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
1175#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054) 1173#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
1176 /* MT352 is on a secondary I2C bus made from some GPIO lines */ 1174 /* MT352 is on a secondary I2C bus made from some GPIO lines */
1177 fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config, 1175 fe0->dvb.frontend = dvb_attach(mt352_attach,
1176 &dntv_live_dvbt_pro_config,
1178 &dev->vp3054->adap); 1177 &dev->vp3054->adap);
1179 if (fe0->dvb.frontend != NULL) { 1178 if (fe0->dvb.frontend) {
1180 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1179 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1181 &core->i2c_adap, 0x61, 1180 &core->i2c_adap, 0x61,
1182 TUNER_PHILIPS_FMD1216ME_MK3)) 1181 TUNER_PHILIPS_FMD1216ME_MK3))
@@ -1190,10 +1189,10 @@ static int dvb_register(struct cx8802_dev *dev)
1190 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1189 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1191 &dvico_fusionhdtv_hybrid, 1190 &dvico_fusionhdtv_hybrid,
1192 &core->i2c_adap); 1191 &core->i2c_adap);
1193 if (fe0->dvb.frontend != NULL) { 1192 if (fe0->dvb.frontend) {
1194 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1193 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1195 &core->i2c_adap, 0x61, 1194 &core->i2c_adap, 0x61,
1196 TUNER_THOMSON_FE6600)) 1195 TUNER_THOMSON_FE6600))
1197 goto frontend_detach; 1196 goto frontend_detach;
1198 } 1197 }
1199 break; 1198 break;
@@ -1201,7 +1200,7 @@ static int dvb_register(struct cx8802_dev *dev)
1201 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1200 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1202 &dvico_fusionhdtv_xc3028, 1201 &dvico_fusionhdtv_xc3028,
1203 &core->i2c_adap); 1202 &core->i2c_adap);
1204 if (fe0->dvb.frontend == NULL) 1203 if (!fe0->dvb.frontend)
1205 fe0->dvb.frontend = dvb_attach(mt352_attach, 1204 fe0->dvb.frontend = dvb_attach(mt352_attach,
1206 &dvico_fusionhdtv_mt352_xc3028, 1205 &dvico_fusionhdtv_mt352_xc3028,
1207 &core->i2c_adap); 1206 &core->i2c_adap);
@@ -1218,7 +1217,7 @@ static int dvb_register(struct cx8802_dev *dev)
1218 case CX88_BOARD_PCHDTV_HD3000: 1217 case CX88_BOARD_PCHDTV_HD3000:
1219 fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000, 1218 fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
1220 &core->i2c_adap); 1219 &core->i2c_adap);
1221 if (fe0->dvb.frontend != NULL) { 1220 if (fe0->dvb.frontend) {
1222 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1221 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1223 &core->i2c_adap, 0x61, 1222 &core->i2c_adap, 0x61,
1224 TUNER_THOMSON_DTT761X)) 1223 TUNER_THOMSON_DTT761X))
@@ -1239,7 +1238,7 @@ static int dvb_register(struct cx8802_dev *dev)
1239 fe0->dvb.frontend = dvb_attach(lgdt330x_attach, 1238 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1240 &fusionhdtv_3_gold, 1239 &fusionhdtv_3_gold,
1241 &core->i2c_adap); 1240 &core->i2c_adap);
1242 if (fe0->dvb.frontend != NULL) { 1241 if (fe0->dvb.frontend) {
1243 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1242 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1244 &core->i2c_adap, 0x61, 1243 &core->i2c_adap, 0x61,
1245 TUNER_MICROTUNE_4042FI5)) 1244 TUNER_MICROTUNE_4042FI5))
@@ -1257,7 +1256,7 @@ static int dvb_register(struct cx8802_dev *dev)
1257 fe0->dvb.frontend = dvb_attach(lgdt330x_attach, 1256 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1258 &fusionhdtv_3_gold, 1257 &fusionhdtv_3_gold,
1259 &core->i2c_adap); 1258 &core->i2c_adap);
1260 if (fe0->dvb.frontend != NULL) { 1259 if (fe0->dvb.frontend) {
1261 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1260 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1262 &core->i2c_adap, 0x61, 1261 &core->i2c_adap, 0x61,
1263 TUNER_THOMSON_DTT761X)) 1262 TUNER_THOMSON_DTT761X))
@@ -1275,13 +1274,13 @@ static int dvb_register(struct cx8802_dev *dev)
1275 fe0->dvb.frontend = dvb_attach(lgdt330x_attach, 1274 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1276 &fusionhdtv_5_gold, 1275 &fusionhdtv_5_gold,
1277 &core->i2c_adap); 1276 &core->i2c_adap);
1278 if (fe0->dvb.frontend != NULL) { 1277 if (fe0->dvb.frontend) {
1279 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1278 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1280 &core->i2c_adap, 0x61, 1279 &core->i2c_adap, 0x61,
1281 TUNER_LG_TDVS_H06XF)) 1280 TUNER_LG_TDVS_H06XF))
1282 goto frontend_detach; 1281 goto frontend_detach;
1283 if (!dvb_attach(tda9887_attach, fe0->dvb.frontend, 1282 if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
1284 &core->i2c_adap, 0x43)) 1283 &core->i2c_adap, 0x43))
1285 goto frontend_detach; 1284 goto frontend_detach;
1286 } 1285 }
1287 break; 1286 break;
@@ -1296,13 +1295,13 @@ static int dvb_register(struct cx8802_dev *dev)
1296 fe0->dvb.frontend = dvb_attach(lgdt330x_attach, 1295 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1297 &pchdtv_hd5500, 1296 &pchdtv_hd5500,
1298 &core->i2c_adap); 1297 &core->i2c_adap);
1299 if (fe0->dvb.frontend != NULL) { 1298 if (fe0->dvb.frontend) {
1300 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1299 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1301 &core->i2c_adap, 0x61, 1300 &core->i2c_adap, 0x61,
1302 TUNER_LG_TDVS_H06XF)) 1301 TUNER_LG_TDVS_H06XF))
1303 goto frontend_detach; 1302 goto frontend_detach;
1304 if (!dvb_attach(tda9887_attach, fe0->dvb.frontend, 1303 if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
1305 &core->i2c_adap, 0x43)) 1304 &core->i2c_adap, 0x43))
1306 goto frontend_detach; 1305 goto frontend_detach;
1307 } 1306 }
1308 break; 1307 break;
@@ -1310,7 +1309,7 @@ static int dvb_register(struct cx8802_dev *dev)
1310 fe0->dvb.frontend = dvb_attach(nxt200x_attach, 1309 fe0->dvb.frontend = dvb_attach(nxt200x_attach,
1311 &ati_hdtvwonder, 1310 &ati_hdtvwonder,
1312 &core->i2c_adap); 1311 &core->i2c_adap);
1313 if (fe0->dvb.frontend != NULL) { 1312 if (fe0->dvb.frontend) {
1314 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1313 if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1315 &core->i2c_adap, 0x61, 1314 &core->i2c_adap, 0x61,
1316 TUNER_PHILIPS_TUV1236D)) 1315 TUNER_PHILIPS_TUV1236D))
@@ -1331,8 +1330,8 @@ static int dvb_register(struct cx8802_dev *dev)
1331 override_tone = false; 1330 override_tone = false;
1332 1331
1333 if (!dvb_attach(isl6421_attach, fe0->dvb.frontend, 1332 if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,
1334 &core->i2c_adap, 0x08, ISL6421_DCL, 0x00, 1333 &core->i2c_adap, 0x08, ISL6421_DCL,
1335 override_tone)) 1334 0x00, override_tone))
1336 goto frontend_detach; 1335 goto frontend_detach;
1337 } 1336 }
1338 break; 1337 break;
@@ -1358,7 +1357,7 @@ static int dvb_register(struct cx8802_dev *dev)
1358 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1357 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1359 &pinnacle_pctv_hd_800i_config, 1358 &pinnacle_pctv_hd_800i_config,
1360 &core->i2c_adap); 1359 &core->i2c_adap);
1361 if (fe0->dvb.frontend != NULL) { 1360 if (fe0->dvb.frontend) {
1362 if (!dvb_attach(xc5000_attach, fe0->dvb.frontend, 1361 if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
1363 &core->i2c_adap, 1362 &core->i2c_adap,
1364 &pinnacle_pctv_hd_800i_tuner_config)) 1363 &pinnacle_pctv_hd_800i_tuner_config))
@@ -1367,9 +1366,9 @@ static int dvb_register(struct cx8802_dev *dev)
1367 break; 1366 break;
1368 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO: 1367 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1369 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1368 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1370 &dvico_hdtv5_pci_nano_config, 1369 &dvico_hdtv5_pci_nano_config,
1371 &core->i2c_adap); 1370 &core->i2c_adap);
1372 if (fe0->dvb.frontend != NULL) { 1371 if (fe0->dvb.frontend) {
1373 struct dvb_frontend *fe; 1372 struct dvb_frontend *fe;
1374 struct xc2028_config cfg = { 1373 struct xc2028_config cfg = {
1375 .i2c_adap = &core->i2c_adap, 1374 .i2c_adap = &core->i2c_adap,
@@ -1383,7 +1382,7 @@ static int dvb_register(struct cx8802_dev *dev)
1383 1382
1384 fe = dvb_attach(xc2028_attach, 1383 fe = dvb_attach(xc2028_attach,
1385 fe0->dvb.frontend, &cfg); 1384 fe0->dvb.frontend, &cfg);
1386 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 1385 if (fe && fe->ops.tuner_ops.set_config)
1387 fe->ops.tuner_ops.set_config(fe, &ctl); 1386 fe->ops.tuner_ops.set_config(fe, &ctl);
1388 } 1387 }
1389 break; 1388 break;
@@ -1436,7 +1435,7 @@ static int dvb_register(struct cx8802_dev *dev)
1436 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1435 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1437 &dvico_fusionhdtv7_config, 1436 &dvico_fusionhdtv7_config,
1438 &core->i2c_adap); 1437 &core->i2c_adap);
1439 if (fe0->dvb.frontend != NULL) { 1438 if (fe0->dvb.frontend) {
1440 if (!dvb_attach(xc5000_attach, fe0->dvb.frontend, 1439 if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
1441 &core->i2c_adap, 1440 &core->i2c_adap,
1442 &dvico_fusionhdtv7_tuner_config)) 1441 &dvico_fusionhdtv7_tuner_config))
@@ -1449,8 +1448,8 @@ static int dvb_register(struct cx8802_dev *dev)
1449 dev->frontends.gate = 2; 1448 dev->frontends.gate = 2;
1450 /* DVB-S/S2 Init */ 1449 /* DVB-S/S2 Init */
1451 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1450 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1452 &hauppauge_hvr4000_config, 1451 &hauppauge_hvr4000_config,
1453 &dev->core->i2c_adap); 1452 &dev->core->i2c_adap);
1454 if (fe0->dvb.frontend) { 1453 if (fe0->dvb.frontend) {
1455 if (!dvb_attach(isl6421_attach, 1454 if (!dvb_attach(isl6421_attach,
1456 fe0->dvb.frontend, 1455 fe0->dvb.frontend,
@@ -1464,8 +1463,8 @@ static int dvb_register(struct cx8802_dev *dev)
1464 goto frontend_detach; 1463 goto frontend_detach;
1465 /* DVB-T Init */ 1464 /* DVB-T Init */
1466 fe1->dvb.frontend = dvb_attach(cx22702_attach, 1465 fe1->dvb.frontend = dvb_attach(cx22702_attach,
1467 &hauppauge_hvr_config, 1466 &hauppauge_hvr_config,
1468 &dev->core->i2c_adap); 1467 &dev->core->i2c_adap);
1469 if (fe1->dvb.frontend) { 1468 if (fe1->dvb.frontend) {
1470 fe1->dvb.frontend->id = 1; 1469 fe1->dvb.frontend->id = 1;
1471 if (!dvb_attach(simple_tuner_attach, 1470 if (!dvb_attach(simple_tuner_attach,
@@ -1477,8 +1476,8 @@ static int dvb_register(struct cx8802_dev *dev)
1477 break; 1476 break;
1478 case CX88_BOARD_HAUPPAUGE_HVR4000LITE: 1477 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
1479 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1478 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1480 &hauppauge_hvr4000_config, 1479 &hauppauge_hvr4000_config,
1481 &dev->core->i2c_adap); 1480 &dev->core->i2c_adap);
1482 if (fe0->dvb.frontend) { 1481 if (fe0->dvb.frontend) {
1483 if (!dvb_attach(isl6421_attach, 1482 if (!dvb_attach(isl6421_attach,
1484 fe0->dvb.frontend, 1483 fe0->dvb.frontend,
@@ -1493,7 +1492,7 @@ static int dvb_register(struct cx8802_dev *dev)
1493 fe0->dvb.frontend = dvb_attach(stv0299_attach, 1492 fe0->dvb.frontend = dvb_attach(stv0299_attach,
1494 &tevii_tuner_sharp_config, 1493 &tevii_tuner_sharp_config,
1495 &core->i2c_adap); 1494 &core->i2c_adap);
1496 if (fe0->dvb.frontend != NULL) { 1495 if (fe0->dvb.frontend) {
1497 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60, 1496 if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1498 &core->i2c_adap, DVB_PLL_OPERA1)) 1497 &core->i2c_adap, DVB_PLL_OPERA1))
1499 goto frontend_detach; 1498 goto frontend_detach;
@@ -1504,8 +1503,9 @@ static int dvb_register(struct cx8802_dev *dev)
1504 fe0->dvb.frontend = dvb_attach(stv0288_attach, 1503 fe0->dvb.frontend = dvb_attach(stv0288_attach,
1505 &tevii_tuner_earda_config, 1504 &tevii_tuner_earda_config,
1506 &core->i2c_adap); 1505 &core->i2c_adap);
1507 if (fe0->dvb.frontend != NULL) { 1506 if (fe0->dvb.frontend) {
1508 if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61, 1507 if (!dvb_attach(stb6000_attach,
1508 fe0->dvb.frontend, 0x61,
1509 &core->i2c_adap)) 1509 &core->i2c_adap))
1510 goto frontend_detach; 1510 goto frontend_detach;
1511 core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage; 1511 core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
@@ -1517,16 +1517,16 @@ static int dvb_register(struct cx8802_dev *dev)
1517 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1517 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1518 &tevii_s460_config, 1518 &tevii_s460_config,
1519 &core->i2c_adap); 1519 &core->i2c_adap);
1520 if (fe0->dvb.frontend != NULL) 1520 if (fe0->dvb.frontend)
1521 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage; 1521 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1522 break; 1522 break;
1523 case CX88_BOARD_TEVII_S464: 1523 case CX88_BOARD_TEVII_S464:
1524 fe0->dvb.frontend = dvb_attach(ds3000_attach, 1524 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1525 &tevii_ds3000_config, 1525 &tevii_ds3000_config,
1526 &core->i2c_adap); 1526 &core->i2c_adap);
1527 if (fe0->dvb.frontend != NULL) { 1527 if (fe0->dvb.frontend) {
1528 dvb_attach(ts2020_attach, fe0->dvb.frontend, 1528 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1529 &tevii_ts2020_config, &core->i2c_adap); 1529 &tevii_ts2020_config, &core->i2c_adap);
1530 fe0->dvb.frontend->ops.set_voltage = 1530 fe0->dvb.frontend->ops.set_voltage =
1531 tevii_dvbs_set_voltage; 1531 tevii_dvbs_set_voltage;
1532 } 1532 }
@@ -1538,7 +1538,7 @@ static int dvb_register(struct cx8802_dev *dev)
1538 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1538 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1539 &hauppauge_hvr4000_config, 1539 &hauppauge_hvr4000_config,
1540 &core->i2c_adap); 1540 &core->i2c_adap);
1541 if (fe0->dvb.frontend != NULL) 1541 if (fe0->dvb.frontend)
1542 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage; 1542 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1543 break; 1543 break;
1544 case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII: 1544 case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
@@ -1555,9 +1555,9 @@ static int dvb_register(struct cx8802_dev *dev)
1555 struct dvb_tuner_ops *tuner_ops = NULL; 1555 struct dvb_tuner_ops *tuner_ops = NULL;
1556 1556
1557 fe0->dvb.frontend = dvb_attach(stv0900_attach, 1557 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1558 &prof_7301_stv0900_config, 1558 &prof_7301_stv0900_config,
1559 &core->i2c_adap, 0); 1559 &core->i2c_adap, 0);
1560 if (fe0->dvb.frontend != NULL) { 1560 if (fe0->dvb.frontend) {
1561 if (!dvb_attach(stb6100_attach, fe0->dvb.frontend, 1561 if (!dvb_attach(stb6100_attach, fe0->dvb.frontend,
1562 &prof_7301_stb6100_config, 1562 &prof_7301_stb6100_config,
1563 &core->i2c_adap)) 1563 &core->i2c_adap))
@@ -1587,8 +1587,8 @@ static int dvb_register(struct cx8802_dev *dev)
1587 mdelay(200); 1587 mdelay(200);
1588 1588
1589 fe0->dvb.frontend = dvb_attach(stv0299_attach, 1589 fe0->dvb.frontend = dvb_attach(stv0299_attach,
1590 &samsung_stv0299_config, 1590 &samsung_stv0299_config,
1591 &dev->core->i2c_adap); 1591 &dev->core->i2c_adap);
1592 if (fe0->dvb.frontend) { 1592 if (fe0->dvb.frontend) {
1593 fe0->dvb.frontend->ops.tuner_ops.set_params = 1593 fe0->dvb.frontend->ops.tuner_ops.set_params =
1594 samsung_smt_7020_tuner_set_params; 1594 samsung_smt_7020_tuner_set_params;
@@ -1604,8 +1604,8 @@ static int dvb_register(struct cx8802_dev *dev)
1604 case CX88_BOARD_TWINHAN_VP1027_DVBS: 1604 case CX88_BOARD_TWINHAN_VP1027_DVBS:
1605 dev->ts_gen_cntrl = 0x00; 1605 dev->ts_gen_cntrl = 0x00;
1606 fe0->dvb.frontend = dvb_attach(mb86a16_attach, 1606 fe0->dvb.frontend = dvb_attach(mb86a16_attach,
1607 &twinhan_vp1027, 1607 &twinhan_vp1027,
1608 &core->i2c_adap); 1608 &core->i2c_adap);
1609 if (fe0->dvb.frontend) { 1609 if (fe0->dvb.frontend) {
1610 core->prev_set_voltage = 1610 core->prev_set_voltage =
1611 fe0->dvb.frontend->ops.set_voltage; 1611 fe0->dvb.frontend->ops.set_voltage;
@@ -1772,7 +1772,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
1772 struct vb2_queue *q; 1772 struct vb2_queue *q;
1773 1773
1774 fe = vb2_dvb_get_frontend(&core->dvbdev->frontends, i); 1774 fe = vb2_dvb_get_frontend(&core->dvbdev->frontends, i);
1775 if (fe == NULL) { 1775 if (!fe) {
1776 pr_err("%s() failed to get frontend(%d)\n", 1776 pr_err("%s() failed to get frontend(%d)\n",
1777 __func__, i); 1777 __func__, i);
1778 err = -ENODEV; 1778 err = -ENODEV;
diff --git a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c
index 99596fe56cd2..f7692775fb5a 100644
--- a/drivers/media/pci/cx88/cx88-i2c.c
+++ b/drivers/media/pci/cx88/cx88-i2c.c
@@ -24,10 +24,9 @@
24 24
25#include "cx88.h" 25#include "cx88.h"
26 26
27#include <linux/module.h>
28#include <linux/init.h> 27#include <linux/init.h>
29 28#include <linux/io.h>
30#include <asm/io.h> 29#include <linux/module.h>
31 30
32#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
33 32
@@ -41,7 +40,8 @@ MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
41 40
42static unsigned int i2c_udelay = 5; 41static unsigned int i2c_udelay = 5;
43module_param(i2c_udelay, int, 0644); 42module_param(i2c_udelay, int, 0644);
44MODULE_PARM_DESC(i2c_udelay, "i2c delay at insmod time, in usecs (should be 5 or higher). Lower value means higher bus speed."); 43MODULE_PARM_DESC(i2c_udelay,
44 "i2c delay at insmod time, in usecs (should be 5 or higher). Lower value means higher bus speed.");
45 45
46#define dprintk(level, fmt, arg...) do { \ 46#define dprintk(level, fmt, arg...) do { \
47 if (i2c_debug >= level) \ 47 if (i2c_debug >= level) \
@@ -139,7 +139,6 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
139 139
140 core->i2c_algo = cx8800_i2c_algo_template; 140 core->i2c_algo = cx8800_i2c_algo_template;
141 141
142
143 core->i2c_adap.dev.parent = &pci->dev; 142 core->i2c_adap.dev.parent = &pci->dev;
144 strlcpy(core->i2c_adap.name, core->name, sizeof(core->i2c_adap.name)); 143 strlcpy(core->i2c_adap.name, core->name, sizeof(core->i2c_adap.name));
145 core->i2c_adap.owner = THIS_MODULE; 144 core->i2c_adap.owner = THIS_MODULE;
@@ -166,14 +165,14 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
166 165
167 dprintk(1, "i2c register ok\n"); 166 dprintk(1, "i2c register ok\n");
168 switch (core->boardnr) { 167 switch (core->boardnr) {
169 case CX88_BOARD_HAUPPAUGE_HVR1300: 168 case CX88_BOARD_HAUPPAUGE_HVR1300:
170 case CX88_BOARD_HAUPPAUGE_HVR3000: 169 case CX88_BOARD_HAUPPAUGE_HVR3000:
171 case CX88_BOARD_HAUPPAUGE_HVR4000: 170 case CX88_BOARD_HAUPPAUGE_HVR4000:
172 pr_info("i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n"); 171 pr_info("i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n");
173 i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1); 172 i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1);
174 break; 173 break;
175 default: 174 default:
176 break; 175 break;
177 } 176 }
178 if (i2c_scan) 177 if (i2c_scan)
179 do_i2c_scan(core->name, &core->i2c_client); 178 do_i2c_scan(core->name, &core->i2c_client);
diff --git a/drivers/media/pci/cx88/cx88-input.c b/drivers/media/pci/cx88/cx88-input.c
index c072b7ecc8d6..dcfea3502e42 100644
--- a/drivers/media/pci/cx88/cx88-input.c
+++ b/drivers/media/pci/cx88/cx88-input.c
@@ -62,11 +62,15 @@ static int ir_debug;
62module_param(ir_debug, int, 0644); /* debug level [IR] */ 62module_param(ir_debug, int, 0644); /* debug level [IR] */
63MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 63MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
64 64
65#define ir_dprintk(fmt, arg...) if (ir_debug) \ 65#define ir_dprintk(fmt, arg...) do { \
66 printk(KERN_DEBUG "%s IR: " fmt, ir->core->name, ##arg) 66 if (ir_debug) \
67 printk(KERN_DEBUG "%s IR: " fmt, ir->core->name, ##arg);\
68} while (0)
67 69
68#define dprintk(fmt, arg...) if (ir_debug) \ 70#define dprintk(fmt, arg...) do { \
69 printk(KERN_DEBUG "cx88 IR: " fmt, ##arg) 71 if (ir_debug) \
72 printk(KERN_DEBUG "cx88 IR: " fmt, ##arg); \
73} while (0)
70 74
71/* ---------------------------------------------------------------------- */ 75/* ---------------------------------------------------------------------- */
72 76
@@ -79,16 +83,17 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
79 gpio = cx_read(ir->gpio_addr); 83 gpio = cx_read(ir->gpio_addr);
80 switch (core->boardnr) { 84 switch (core->boardnr) {
81 case CX88_BOARD_NPGTECH_REALTV_TOP10FM: 85 case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
82 /* This board apparently uses a combination of 2 GPIO 86 /*
83 to represent the keys. Additionally, the second GPIO 87 * This board apparently uses a combination of 2 GPIO
84 can be used for parity. 88 * to represent the keys. Additionally, the second GPIO
85 89 * can be used for parity.
86 Example: 90 *
87 91 * Example:
88 for key "5" 92 *
89 gpio = 0x758, auxgpio = 0xe5 or 0xf5 93 * for key "5"
90 for key "Power" 94 * gpio = 0x758, auxgpio = 0xe5 or 0xf5
91 gpio = 0x758, auxgpio = 0xed or 0xfd 95 * for key "Power"
96 * gpio = 0x758, auxgpio = 0xed or 0xfd
92 */ 97 */
93 98
94 auxgpio = cx_read(MO_GP1_IO); 99 auxgpio = cx_read(MO_GP1_IO);
@@ -142,7 +147,7 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
142 147
143 if (0 == (gpio & ir->mask_keyup)) 148 if (0 == (gpio & ir->mask_keyup))
144 rc_keydown_notimeout(ir->dev, RC_TYPE_NECX, scancode, 149 rc_keydown_notimeout(ir->dev, RC_TYPE_NECX, scancode,
145 0); 150 0);
146 else 151 else
147 rc_keyup(ir->dev); 152 rc_keyup(ir->dev);
148 153
@@ -231,12 +236,14 @@ int cx88_ir_start(struct cx88_core *core)
231 236
232 return 0; 237 return 0;
233} 238}
239EXPORT_SYMBOL(cx88_ir_start);
234 240
235void cx88_ir_stop(struct cx88_core *core) 241void cx88_ir_stop(struct cx88_core *core)
236{ 242{
237 if (core->ir->users) 243 if (core->ir->users)
238 __cx88_ir_stop(core); 244 __cx88_ir_stop(core);
239} 245}
246EXPORT_SYMBOL(cx88_ir_stop);
240 247
241static int cx88_ir_open(struct rc_dev *rc) 248static int cx88_ir_open(struct rc_dev *rc)
242{ 249{
@@ -508,7 +515,7 @@ int cx88_ir_fini(struct cx88_core *core)
508 struct cx88_IR *ir = core->ir; 515 struct cx88_IR *ir = core->ir;
509 516
510 /* skip detach on non attached boards */ 517 /* skip detach on non attached boards */
511 if (ir == NULL) 518 if (!ir)
512 return 0; 519 return 0;
513 520
514 cx88_ir_stop(core); 521 cx88_ir_stop(core);
@@ -576,7 +583,7 @@ static int get_key_pvr2000(struct IR_i2c *ir, enum rc_type *protocol,
576 } 583 }
577 584
578 dprintk("IR Key/Flags: (0x%02x/0x%02x)\n", 585 dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
579 code & 0xff, flags & 0xff); 586 code & 0xff, flags & 0xff);
580 587
581 *protocol = RC_TYPE_UNKNOWN; 588 *protocol = RC_TYPE_UNKNOWN;
582 *scancode = code & 0xff; 589 *scancode = code & 0xff;
@@ -636,8 +643,8 @@ void cx88_i2c_init_ir(struct cx88_core *core)
636 info.platform_data = &core->init_data; 643 info.platform_data = &core->init_data;
637 } 644 }
638 if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0, 645 if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
639 I2C_SMBUS_READ, 0, 646 I2C_SMBUS_READ, 0,
640 I2C_SMBUS_QUICK, NULL) >= 0) { 647 I2C_SMBUS_QUICK, NULL) >= 0) {
641 info.addr = *addrp; 648 info.addr = *addrp;
642 i2c_new_device(&core->i2c_adap, &info); 649 i2c_new_device(&core->i2c_adap, &info);
643 break; 650 break;
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index 4533e2c6cb9f..52ff00ebd4bd 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -16,10 +16,6 @@
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */ 19 */
24 20
25#include "cx88.h" 21#include "cx88.h"
@@ -30,7 +26,7 @@
30#include <linux/device.h> 26#include <linux/device.h>
31#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
32#include <linux/interrupt.h> 28#include <linux/interrupt.h>
33#include <asm/delay.h> 29#include <linux/delay.h>
34 30
35/* ------------------------------------------------------------------ */ 31/* ------------------------------------------------------------------ */
36 32
@@ -54,7 +50,8 @@ MODULE_PARM_DESC(debug, "enable debug messages [mpeg]");
54#if defined(CONFIG_MODULES) && defined(MODULE) 50#if defined(CONFIG_MODULES) && defined(MODULE)
55static void request_module_async(struct work_struct *work) 51static void request_module_async(struct work_struct *work)
56{ 52{
57 struct cx8802_dev *dev = container_of(work, struct cx8802_dev, request_module_wk); 53 struct cx8802_dev *dev = container_of(work, struct cx8802_dev,
54 request_module_wk);
58 55
59 if (dev->core->board.mpeg & CX88_MPEG_DVB) 56 if (dev->core->board.mpeg & CX88_MPEG_DVB)
60 request_module("cx88-dvb"); 57 request_module("cx88-dvb");
@@ -77,14 +74,13 @@ static void flush_request_modules(struct cx8802_dev *dev)
77#define flush_request_modules(dev) 74#define flush_request_modules(dev)
78#endif /* CONFIG_MODULES */ 75#endif /* CONFIG_MODULES */
79 76
80
81static LIST_HEAD(cx8802_devlist); 77static LIST_HEAD(cx8802_devlist);
82static DEFINE_MUTEX(cx8802_mutex); 78static DEFINE_MUTEX(cx8802_mutex);
83/* ------------------------------------------------------------------ */ 79/* ------------------------------------------------------------------ */
84 80
85int cx8802_start_dma(struct cx8802_dev *dev, 81int cx8802_start_dma(struct cx8802_dev *dev,
86 struct cx88_dmaqueue *q, 82 struct cx88_dmaqueue *q,
87 struct cx88_buffer *buf) 83 struct cx88_buffer *buf)
88{ 84{
89 struct cx88_core *core = dev->core; 85 struct cx88_core *core = dev->core;
90 86
@@ -98,33 +94,35 @@ int cx8802_start_dma(struct cx8802_dev *dev,
98 /* write TS length to chip */ 94 /* write TS length to chip */
99 cx_write(MO_TS_LNGTH, dev->ts_packet_size); 95 cx_write(MO_TS_LNGTH, dev->ts_packet_size);
100 96
101 /* FIXME: this needs a review. 97 /*
102 * also: move to cx88-blackbird + cx88-dvb source files? */ 98 * FIXME: this needs a review.
99 * also: move to cx88-blackbird + cx88-dvb source files?
100 */
103 101
104 dprintk(1, "core->active_type_id = 0x%08x\n", core->active_type_id); 102 dprintk(1, "core->active_type_id = 0x%08x\n", core->active_type_id);
105 103
106 if ((core->active_type_id == CX88_MPEG_DVB) && 104 if ((core->active_type_id == CX88_MPEG_DVB) &&
107 (core->board.mpeg & CX88_MPEG_DVB)) { 105 (core->board.mpeg & CX88_MPEG_DVB)) {
108
109 dprintk(1, "cx8802_start_dma doing .dvb\n"); 106 dprintk(1, "cx8802_start_dma doing .dvb\n");
110 /* negedge driven & software reset */ 107 /* negedge driven & software reset */
111 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl); 108 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
112 udelay(100); 109 udelay(100);
113 cx_write(MO_PINMUX_IO, 0x00); 110 cx_write(MO_PINMUX_IO, 0x00);
114 cx_write(TS_HW_SOP_CNTRL, 0x47<<16|188<<4|0x01); 111 cx_write(TS_HW_SOP_CNTRL, 0x47 << 16 | 188 << 4 | 0x01);
115 switch (core->boardnr) { 112 switch (core->boardnr) {
116 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 113 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
117 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T: 114 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
118 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: 115 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
119 case CX88_BOARD_PCHDTV_HD5500: 116 case CX88_BOARD_PCHDTV_HD5500:
120 cx_write(TS_SOP_STAT, 1<<13); 117 cx_write(TS_SOP_STAT, 1 << 13);
121 break; 118 break;
122 case CX88_BOARD_SAMSUNG_SMT_7020: 119 case CX88_BOARD_SAMSUNG_SMT_7020:
123 cx_write(TS_SOP_STAT, 0x00); 120 cx_write(TS_SOP_STAT, 0x00);
124 break; 121 break;
125 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 122 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
126 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: 123 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
127 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */ 124 /* Enable MPEG parallel IO and video signal pins */
125 cx_write(MO_PINMUX_IO, 0x88);
128 udelay(100); 126 udelay(100);
129 break; 127 break;
130 case CX88_BOARD_HAUPPAUGE_HVR1300: 128 case CX88_BOARD_HAUPPAUGE_HVR1300:
@@ -153,13 +151,15 @@ int cx8802_start_dma(struct cx8802_dev *dev,
153 dprintk(1, "cx8802_start_dma doing .blackbird\n"); 151 dprintk(1, "cx8802_start_dma doing .blackbird\n");
154 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */ 152 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
155 153
156 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */ 154 /* punctured clock TS & posedge driven & software reset */
155 cx_write(TS_GEN_CNTRL, 0x46);
157 udelay(100); 156 udelay(100);
158 157
159 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */ 158 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */
160 cx_write(TS_VALERR_CNTRL, 0x2000); 159 cx_write(TS_VALERR_CNTRL, 0x2000);
161 160
162 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 161 /* punctured clock TS & posedge driven */
162 cx_write(TS_GEN_CNTRL, 0x06);
163 udelay(100); 163 udelay(100);
164 } else { 164 } else {
165 pr_err("%s() Failed. Unsupported value in .mpeg (0x%08x)\n", 165 pr_err("%s() Failed. Unsupported value in .mpeg (0x%08x)\n",
@@ -177,10 +177,11 @@ int cx8802_start_dma(struct cx8802_dev *dev,
177 cx_set(MO_TS_INTMSK, 0x1f0011); 177 cx_set(MO_TS_INTMSK, 0x1f0011);
178 178
179 /* start dma */ 179 /* start dma */
180 cx_set(MO_DEV_CNTRL2, (1<<5)); 180 cx_set(MO_DEV_CNTRL2, (1 << 5));
181 cx_set(MO_TS_DMACNTRL, 0x11); 181 cx_set(MO_TS_DMACNTRL, 0x11);
182 return 0; 182 return 0;
183} 183}
184EXPORT_SYMBOL(cx8802_start_dma);
184 185
185static int cx8802_stop_dma(struct cx8802_dev *dev) 186static int cx8802_stop_dma(struct cx8802_dev *dev)
186{ 187{
@@ -219,7 +220,7 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
219/* ------------------------------------------------------------------ */ 220/* ------------------------------------------------------------------ */
220 221
221int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, 222int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
222 struct cx88_buffer *buf) 223 struct cx88_buffer *buf)
223{ 224{
224 int size = dev->ts_packet_size * dev->ts_packet_count; 225 int size = dev->ts_packet_size * dev->ts_packet_count;
225 struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb.vb2_buf, 0); 226 struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb.vb2_buf, 0);
@@ -231,15 +232,17 @@ int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
231 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size); 232 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
232 233
233 rc = cx88_risc_databuffer(dev->pci, risc, sgt->sgl, 234 rc = cx88_risc_databuffer(dev->pci, risc, sgt->sgl,
234 dev->ts_packet_size, dev->ts_packet_count, 0); 235 dev->ts_packet_size, dev->ts_packet_count, 0);
235 if (rc) { 236 if (rc) {
236 if (risc->cpu) 237 if (risc->cpu)
237 pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); 238 pci_free_consistent(dev->pci, risc->size,
239 risc->cpu, risc->dma);
238 memset(risc, 0, sizeof(*risc)); 240 memset(risc, 0, sizeof(*risc));
239 return rc; 241 return rc;
240 } 242 }
241 return 0; 243 return 0;
242} 244}
245EXPORT_SYMBOL(cx8802_buf_prepare);
243 246
244void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf) 247void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
245{ 248{
@@ -268,6 +271,7 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
268 buf, buf->vb.vb2_buf.index, __func__); 271 buf, buf->vb.vb2_buf.index, __func__);
269 } 272 }
270} 273}
274EXPORT_SYMBOL(cx8802_buf_queue);
271 275
272/* ----------------------------------------------------------- */ 276/* ----------------------------------------------------------- */
273 277
@@ -292,6 +296,7 @@ void cx8802_cancel_buffers(struct cx8802_dev *dev)
292 cx8802_stop_dma(dev); 296 cx8802_stop_dma(dev);
293 do_cancel_buffers(dev); 297 do_cancel_buffers(dev);
294} 298}
299EXPORT_SYMBOL(cx8802_cancel_buffers);
295 300
296static const char *cx88_mpeg_irqs[32] = { 301static const char *cx88_mpeg_irqs[32] = {
297 "ts_risci1", NULL, NULL, NULL, 302 "ts_risci1", NULL, NULL, NULL,
@@ -324,7 +329,8 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
324 if (status & (1 << 16)) { 329 if (status & (1 << 16)) {
325 pr_warn("mpeg risc op code error\n"); 330 pr_warn("mpeg risc op code error\n");
326 cx_clear(MO_TS_DMACNTRL, 0x11); 331 cx_clear(MO_TS_DMACNTRL, 0x11);
327 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]); 332 cx88_sram_channel_dump(dev->core,
333 &cx88_sram_channels[SRAM_CH28]);
328 } 334 }
329 335
330 /* risc1 y */ 336 /* risc1 y */
@@ -452,7 +458,8 @@ static int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
452 cx88_shutdown(dev->core); 458 cx88_shutdown(dev->core);
453 459
454 pci_save_state(pci_dev); 460 pci_save_state(pci_dev);
455 if (pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)) != 0) { 461 if (pci_set_power_state(pci_dev,
462 pci_choose_state(pci_dev, state)) != 0) {
456 pci_disable_device(pci_dev); 463 pci_disable_device(pci_dev);
457 dev->state.disabled = 1; 464 dev->state.disabled = 1;
458 } 465 }
@@ -497,7 +504,8 @@ static int cx8802_resume_common(struct pci_dev *pci_dev)
497 return 0; 504 return 0;
498} 505}
499 506
500struct cx8802_driver *cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype) 507struct cx8802_driver *cx8802_get_driver(struct cx8802_dev *dev,
508 enum cx88_board_type btype)
501{ 509{
502 struct cx8802_driver *d; 510 struct cx8802_driver *d;
503 511
@@ -507,6 +515,7 @@ struct cx8802_driver *cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_
507 515
508 return NULL; 516 return NULL;
509} 517}
518EXPORT_SYMBOL(cx8802_get_driver);
510 519
511/* Driver asked for hardware access. */ 520/* Driver asked for hardware access. */
512static int cx8802_request_acquire(struct cx8802_driver *drv) 521static int cx8802_request_acquire(struct cx8802_driver *drv)
@@ -524,7 +533,8 @@ static int cx8802_request_acquire(struct cx8802_driver *drv)
524 core->last_analog_input = core->input; 533 core->last_analog_input = core->input;
525 core->input = 0; 534 core->input = 0;
526 for (i = 0; 535 for (i = 0;
527 i < (sizeof(core->board.input) / sizeof(struct cx88_input)); 536 i < (sizeof(core->board.input) /
537 sizeof(struct cx88_input));
528 i++) { 538 i++) {
529 if (core->board.input[i].type == CX88_VMUX_DVB) { 539 if (core->board.input[i].type == CX88_VMUX_DVB) {
530 core->input = i; 540 core->input = i;
@@ -533,8 +543,7 @@ static int cx8802_request_acquire(struct cx8802_driver *drv)
533 } 543 }
534 } 544 }
535 545
536 if (drv->advise_acquire) 546 if (drv->advise_acquire) {
537 {
538 core->active_ref++; 547 core->active_ref++;
539 if (core->active_type_id == CX88_BOARD_NONE) { 548 if (core->active_type_id == CX88_BOARD_NONE) {
540 core->active_type_id = drv->type_id; 549 core->active_type_id = drv->type_id;
@@ -552,11 +561,12 @@ static int cx8802_request_release(struct cx8802_driver *drv)
552{ 561{
553 struct cx88_core *core = drv->core; 562 struct cx88_core *core = drv->core;
554 563
555 if (drv->advise_release && --core->active_ref == 0) 564 if (drv->advise_release && --core->active_ref == 0) {
556 {
557 if (drv->type_id == CX88_MPEG_DVB) { 565 if (drv->type_id == CX88_MPEG_DVB) {
558 /* If the DVB driver is releasing, reset the input 566 /*
559 state to the last configured analog input */ 567 * If the DVB driver is releasing, reset the input
568 * state to the last configured analog input
569 */
560 core->input = core->last_analog_input; 570 core->input = core->last_analog_input;
561 } 571 }
562 572
@@ -570,21 +580,21 @@ static int cx8802_request_release(struct cx8802_driver *drv)
570 580
571static int cx8802_check_driver(struct cx8802_driver *drv) 581static int cx8802_check_driver(struct cx8802_driver *drv)
572{ 582{
573 if (drv == NULL) 583 if (!drv)
574 return -ENODEV; 584 return -ENODEV;
575 585
576 if ((drv->type_id != CX88_MPEG_DVB) && 586 if ((drv->type_id != CX88_MPEG_DVB) &&
577 (drv->type_id != CX88_MPEG_BLACKBIRD)) 587 (drv->type_id != CX88_MPEG_BLACKBIRD))
578 return -EINVAL; 588 return -EINVAL;
579 589
580 if ((drv->hw_access != CX8802_DRVCTL_SHARED) && 590 if ((drv->hw_access != CX8802_DRVCTL_SHARED) &&
581 (drv->hw_access != CX8802_DRVCTL_EXCLUSIVE)) 591 (drv->hw_access != CX8802_DRVCTL_EXCLUSIVE))
582 return -EINVAL; 592 return -EINVAL;
583 593
584 if ((drv->probe == NULL) || 594 if ((!drv->probe) ||
585 (drv->remove == NULL) || 595 (!drv->remove) ||
586 (drv->advise_acquire == NULL) || 596 (!drv->advise_acquire) ||
587 (drv->advise_release == NULL)) 597 (!drv->advise_release))
588 return -EINVAL; 598 return -EINVAL;
589 599
590 return 0; 600 return 0;
@@ -598,9 +608,11 @@ int cx8802_register_driver(struct cx8802_driver *drv)
598 608
599 pr_info("registering cx8802 driver, type: %s access: %s\n", 609 pr_info("registering cx8802 driver, type: %s access: %s\n",
600 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird", 610 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
601 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive"); 611 drv->hw_access == CX8802_DRVCTL_SHARED ?
612 "shared" : "exclusive");
602 613
603 if ((err = cx8802_check_driver(drv)) != 0) { 614 err = cx8802_check_driver(drv);
615 if (err) {
604 pr_err("cx8802_driver is invalid\n"); 616 pr_err("cx8802_driver is invalid\n");
605 return err; 617 return err;
606 } 618 }
@@ -615,7 +627,7 @@ int cx8802_register_driver(struct cx8802_driver *drv)
615 627
616 /* Bring up a new struct for each driver instance */ 628 /* Bring up a new struct for each driver instance */
617 driver = kzalloc(sizeof(*drv), GFP_KERNEL); 629 driver = kzalloc(sizeof(*drv), GFP_KERNEL);
618 if (driver == NULL) { 630 if (!driver) {
619 err = -ENOMEM; 631 err = -ENOMEM;
620 goto out; 632 goto out;
621 } 633 }
@@ -644,6 +656,7 @@ out:
644 mutex_unlock(&cx8802_mutex); 656 mutex_unlock(&cx8802_mutex);
645 return err; 657 return err;
646} 658}
659EXPORT_SYMBOL(cx8802_register_driver);
647 660
648int cx8802_unregister_driver(struct cx8802_driver *drv) 661int cx8802_unregister_driver(struct cx8802_driver *drv)
649{ 662{
@@ -653,7 +666,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
653 666
654 pr_info("unregistering cx8802 driver, type: %s access: %s\n", 667 pr_info("unregistering cx8802 driver, type: %s access: %s\n",
655 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird", 668 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
656 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive"); 669 drv->hw_access == CX8802_DRVCTL_SHARED ?
670 "shared" : "exclusive");
657 671
658 mutex_lock(&cx8802_mutex); 672 mutex_lock(&cx8802_mutex);
659 673
@@ -686,6 +700,7 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
686 700
687 return err; 701 return err;
688} 702}
703EXPORT_SYMBOL(cx8802_unregister_driver);
689 704
690/* ----------------------------------------------------------- */ 705/* ----------------------------------------------------------- */
691static int cx8802_probe(struct pci_dev *pci_dev, 706static int cx8802_probe(struct pci_dev *pci_dev,
@@ -697,7 +712,7 @@ static int cx8802_probe(struct pci_dev *pci_dev,
697 712
698 /* general setup */ 713 /* general setup */
699 core = cx88_core_get(pci_dev); 714 core = cx88_core_get(pci_dev);
700 if (core == NULL) 715 if (!core)
701 return -EINVAL; 716 return -EINVAL;
702 717
703 pr_info("cx2388x 8802 Driver Manager\n"); 718 pr_info("cx2388x 8802 Driver Manager\n");
@@ -708,7 +723,7 @@ static int cx8802_probe(struct pci_dev *pci_dev,
708 723
709 err = -ENOMEM; 724 err = -ENOMEM;
710 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 725 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
711 if (dev == NULL) 726 if (!dev)
712 goto fail_core; 727 goto fail_core;
713 dev->pci = pci_dev; 728 dev->pci = pci_dev;
714 dev->core = core; 729 dev->core = core;
@@ -797,12 +812,3 @@ static struct pci_driver cx8802_pci_driver = {
797}; 812};
798 813
799module_pci_driver(cx8802_pci_driver); 814module_pci_driver(cx8802_pci_driver);
800
801EXPORT_SYMBOL(cx8802_buf_prepare);
802EXPORT_SYMBOL(cx8802_buf_queue);
803EXPORT_SYMBOL(cx8802_cancel_buffers);
804EXPORT_SYMBOL(cx8802_start_dma);
805
806EXPORT_SYMBOL(cx8802_register_driver);
807EXPORT_SYMBOL(cx8802_unregister_driver);
808EXPORT_SYMBOL(cx8802_get_driver);
diff --git a/drivers/media/pci/cx88/cx88-reg.h b/drivers/media/pci/cx88/cx88-reg.h
index 88ed8a2e4ee1..f1e1dd634a72 100644
--- a/drivers/media/pci/cx88/cx88-reg.h
+++ b/drivers/media/pci/cx88/cx88-reg.h
@@ -1,32 +1,28 @@
1/* 1/*
2 2 * cx88x-hw.h - CX2388x register offsets
3 cx88x-hw.h - CX2388x register offsets 3 *
4 4 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
5 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de) 5 * 2001 Michael Eskin
6 2001 Michael Eskin 6 * 2002 Yurij Sysoev <yurij@naturesoft.net>
7 2002 Yurij Sysoev <yurij@naturesoft.net> 7 * 2003 Gerd Knorr <kraxel@bytesex.org>
8 2003 Gerd Knorr <kraxel@bytesex.org> 8 *
9 9 * This program is free software; you can redistribute it and/or modify
10 This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by
11 it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or
12 the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version.
13 (at your option) any later version. 13 *
14 14 * This program is distributed in the hope that it will be useful,
15 This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details.
18 GNU General Public License for more details. 18 */
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*/
24 19
25#ifndef _CX88_REG_H_ 20#ifndef _CX88_REG_H_
26#define _CX88_REG_H_ 21#define _CX88_REG_H_
27 22
28/* ---------------------------------------------------------------------- */ 23/*
29/* PCI IDs and config space */ 24 * PCI IDs and config space
25 */
30 26
31#ifndef PCI_VENDOR_ID_CONEXANT 27#ifndef PCI_VENDOR_ID_CONEXANT
32# define PCI_VENDOR_ID_CONEXANT 0x14F1 28# define PCI_VENDOR_ID_CONEXANT 0x14F1
@@ -39,8 +35,9 @@
39#define CX88X_EN_TBFX 0x02 35#define CX88X_EN_TBFX 0x02
40#define CX88X_EN_VSFX 0x04 36#define CX88X_EN_VSFX 0x04
41 37
42/* ---------------------------------------------------------------------- */ 38/*
43/* PCI controller registers */ 39 * PCI controller registers
40 */
44 41
45/* Command and Status Register */ 42/* Command and Status Register */
46#define F0_CMD_STAT_MM 0x2f0004 43#define F0_CMD_STAT_MM 0x2f0004
@@ -63,8 +60,9 @@
63#define F3_BAR0_MM 0x2f0310 60#define F3_BAR0_MM 0x2f0310
64#define F4_BAR0_MM 0x2f0410 61#define F4_BAR0_MM 0x2f0410
65 62
66/* ---------------------------------------------------------------------- */ 63/*
67/* DMA Controller registers */ 64 * DMA Controller registers
65 */
68 66
69#define MO_PDMA_STHRSH 0x200000 // Source threshold 67#define MO_PDMA_STHRSH 0x200000 // Source threshold
70#define MO_PDMA_STADRS 0x200004 // Source target address 68#define MO_PDMA_STADRS 0x200004 // Source target address
@@ -157,9 +155,9 @@
157#define MO_DMA31_CNT2 0x300168 // {11}RW* DMA Table Size : Ch#31 155#define MO_DMA31_CNT2 0x300168 // {11}RW* DMA Table Size : Ch#31
158#define MO_DMA32_CNT2 0x30016C // {11}RW* DMA Table Size : Ch#32 156#define MO_DMA32_CNT2 0x30016C // {11}RW* DMA Table Size : Ch#32
159 157
160 158/*
161/* ---------------------------------------------------------------------- */ 159 * Video registers
162/* Video registers */ 160 */
163 161
164#define MO_VIDY_DMA 0x310000 // {64}RWp Video Y 162#define MO_VIDY_DMA 0x310000 // {64}RWp Video Y
165#define MO_VIDU_DMA 0x310008 // {64}RWp Video U 163#define MO_VIDU_DMA 0x310008 // {64}RWp Video U
@@ -217,9 +215,9 @@
217#define MO_VID_DMACNTRL 0x31C040 // {8}RW Video DMA control 215#define MO_VID_DMACNTRL 0x31C040 // {8}RW Video DMA control
218#define MO_VID_XFR_STAT 0x31C044 // {1}RO Video transfer status 216#define MO_VID_XFR_STAT 0x31C044 // {1}RO Video transfer status
219 217
220 218/*
221/* ---------------------------------------------------------------------- */ 219 * audio registers
222/* audio registers */ 220 */
223 221
224#define MO_AUDD_DMA 0x320000 // {64}RWp Audio downstream 222#define MO_AUDD_DMA 0x320000 // {64}RWp Audio downstream
225#define MO_AUDU_DMA 0x320008 // {64}RWp Audio upstream 223#define MO_AUDU_DMA 0x320008 // {64}RWp Audio upstream
@@ -437,9 +435,9 @@
437#define AUD_PHACC_FREQ_8LSB 0x320d2b 435#define AUD_PHACC_FREQ_8LSB 0x320d2b
438#define AUD_QAM_MODE 0x320d04 436#define AUD_QAM_MODE 0x320d04
439 437
440 438/*
441/* ---------------------------------------------------------------------- */ 439 * transport stream registers
442/* transport stream registers */ 440 */
443 441
444#define MO_TS_DMA 0x330000 // {64}RWp Transport stream downstream 442#define MO_TS_DMA 0x330000 // {64}RWp Transport stream downstream
445#define MO_TS_GPCNT 0x33C020 // {16}RO TS general purpose counter 443#define MO_TS_GPCNT 0x33C020 // {16}RO TS general purpose counter
@@ -455,9 +453,9 @@
455#define TS_FIFO_OVFL_STAT 0x33C05C 453#define TS_FIFO_OVFL_STAT 0x33C05C
456#define TS_VALERR_CNTRL 0x33C060 454#define TS_VALERR_CNTRL 0x33C060
457 455
458 456/*
459/* ---------------------------------------------------------------------- */ 457 * VIP registers
460/* VIP registers */ 458 */
461 459
462#define MO_VIPD_DMA 0x340000 // {64}RWp VIP downstream 460#define MO_VIPD_DMA 0x340000 // {64}RWp VIP downstream
463#define MO_VIPU_DMA 0x340008 // {64}RWp VIP upstream 461#define MO_VIPU_DMA 0x340008 // {64}RWp VIP upstream
@@ -475,9 +473,9 @@
475#define MO_VIP_INTCNTRL 0x34C05C // VIP Interrupt Control 473#define MO_VIP_INTCNTRL 0x34C05C // VIP Interrupt Control
476#define MO_VIP_XFTERM 0x340060 // VIP transfer terminate 474#define MO_VIP_XFTERM 0x340060 // VIP transfer terminate
477 475
478 476/*
479/* ---------------------------------------------------------------------- */ 477 * misc registers
480/* misc registers */ 478 */
481 479
482#define MO_M2M_DMA 0x350000 // {64}RWp Mem2Mem DMA Bfr 480#define MO_M2M_DMA 0x350000 // {64}RWp Mem2Mem DMA Bfr
483#define MO_GP0_IO 0x350010 // {32}RW* GPIOoutput enablesdata I/O 481#define MO_GP0_IO 0x350010 // {32}RW* GPIOoutput enablesdata I/O
@@ -509,9 +507,9 @@
509#define MO_INT1_STAT 0x35C064 // DMA RISC interrupt status 507#define MO_INT1_STAT 0x35C064 // DMA RISC interrupt status
510#define MO_INT1_MSTAT 0x35C068 // DMA RISC interrupt masked status 508#define MO_INT1_MSTAT 0x35C068 // DMA RISC interrupt masked status
511 509
512 510/*
513/* ---------------------------------------------------------------------- */ 511 * i2c bus registers
514/* i2c bus registers */ 512 */
515 513
516#define MO_I2C 0x368000 // I2C data/control 514#define MO_I2C 0x368000 // I2C data/control
517#define MO_I2C_DIV (0xf<<4) 515#define MO_I2C_DIV (0xf<<4)
@@ -521,9 +519,11 @@
521#define MO_I2C_SDA (1<<0) 519#define MO_I2C_SDA (1<<0)
522 520
523 521
524/* ---------------------------------------------------------------------- */ 522/*
525/* general purpose host registers */ 523 * general purpose host registers
526/* FIXME: tyops? s/0x35/0x38/ ?? */ 524 *
525 * FIXME: tyops? s/0x35/0x38/ ??
526 */
527 527
528#define MO_GPHSTD_DMA 0x350000 // {64}RWp Host downstream 528#define MO_GPHSTD_DMA 0x350000 // {64}RWp Host downstream
529#define MO_GPHSTU_DMA 0x350008 // {64}RWp Host upstream 529#define MO_GPHSTU_DMA 0x350008 // {64}RWp Host upstream
@@ -545,9 +545,9 @@
545#define MO_GPHST_XFR_STAT 0x38C044 // Host transfer status 545#define MO_GPHST_XFR_STAT 0x38C044 // Host transfer status
546#define MO_GPHST_SOFT_RST 0x38C06C // Host software reset 546#define MO_GPHST_SOFT_RST 0x38C06C // Host software reset
547 547
548 548/*
549/* ---------------------------------------------------------------------- */ 549 * RISC instructions
550/* RISC instructions */ 550 */
551 551
552#define RISC_SYNC 0x80000000 552#define RISC_SYNC 0x80000000
553#define RISC_SYNC_ODD 0x80000000 553#define RISC_SYNC_ODD 0x80000000
@@ -578,9 +578,9 @@
578#define RISC_CNT_RESET 0x00030000 578#define RISC_CNT_RESET 0x00030000
579#define RISC_JMP_SRP 0x01 579#define RISC_JMP_SRP 0x01
580 580
581 581/*
582/* ---------------------------------------------------------------------- */ 582 * various constants
583/* various constants */ 583 */
584 584
585// DMA 585// DMA
586/* Interrupt mask/status */ 586/* Interrupt mask/status */
diff --git a/drivers/media/pci/cx88/cx88-tvaudio.c b/drivers/media/pci/cx88/cx88-tvaudio.c
index 20f6924abe35..545ad4c4d1c7 100644
--- a/drivers/media/pci/cx88/cx88-tvaudio.c
+++ b/drivers/media/pci/cx88/cx88-tvaudio.c
@@ -57,7 +57,8 @@ MODULE_PARM_DESC(always_analog, "force analog audio out");
57 57
58static unsigned int radio_deemphasis; 58static unsigned int radio_deemphasis;
59module_param(radio_deemphasis, int, 0644); 59module_param(radio_deemphasis, int, 0644);
60MODULE_PARM_DESC(radio_deemphasis, "Radio deemphasis time constant, 0=None, 1=50us (elsewhere), 2=75us (USA)"); 60MODULE_PARM_DESC(radio_deemphasis,
61 "Radio deemphasis time constant, 0=None, 1=50us (elsewhere), 2=75us (USA)");
61 62
62#define dprintk(fmt, arg...) do { \ 63#define dprintk(fmt, arg...) do { \
63 if (audio_debug) \ 64 if (audio_debug) \
@@ -141,7 +142,10 @@ static void set_audio_finish(struct cx88_core *core, u32 ctl)
141 if (core->board.mpeg & CX88_MPEG_BLACKBIRD) { 142 if (core->board.mpeg & CX88_MPEG_BLACKBIRD) {
142 cx_write(AUD_I2SINPUTCNTL, 4); 143 cx_write(AUD_I2SINPUTCNTL, 4);
143 cx_write(AUD_BAUDRATE, 1); 144 cx_write(AUD_BAUDRATE, 1);
144 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */ 145 /*
146 * 'pass-thru mode': this enables the i2s
147 * output to the mpeg encoder
148 */
145 cx_set(AUD_CTL, EN_I2SOUT_ENABLE); 149 cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
146 cx_write(AUD_I2SOUTPUTCNTL, 1); 150 cx_write(AUD_I2SOUTPUTCNTL, 1);
147 cx_write(AUD_I2SCNTL, 0); 151 cx_write(AUD_I2SCNTL, 0);
@@ -634,7 +638,6 @@ static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
634 case WW_M: 638 case WW_M:
635 dprintk("%s Warning: wrong value\n", __func__); 639 dprintk("%s Warning: wrong value\n", __func__);
636 return; 640 return;
637 break;
638 } 641 }
639 642
640 mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF; 643 mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF;
@@ -691,13 +694,15 @@ static void set_audio_standard_FM(struct cx88_core *core,
691 { /* end of list */ }, 694 { /* end of list */ },
692 }; 695 };
693 696
694 /* It is enough to leave default values? */ 697 /*
695 /* No, it's not! The deemphasis registers are reset to the 75us 698 * It is enough to leave default values?
699 *
700 * No, it's not! The deemphasis registers are reset to the 75us
696 * values by default. Analyzing the spectrum of the decoded audio 701 * values by default. Analyzing the spectrum of the decoded audio
697 * reveals that "no deemphasis" is the same as 75 us, while the 50 us 702 * reveals that "no deemphasis" is the same as 75 us, while the 50 us
698 * setting results in less deemphasis. */ 703 * setting results in less deemphasis.
704 */
699 static const struct rlist fm_no_deemph[] = { 705 static const struct rlist fm_no_deemph[] = {
700
701 {AUD_POLYPH80SCALEFAC, 0x0003}, 706 {AUD_POLYPH80SCALEFAC, 0x0003},
702 { /* end of list */ }, 707 { /* end of list */ },
703 }; 708 };
@@ -741,7 +746,7 @@ static int cx88_detect_nicam(struct cx88_core *core)
741 } 746 }
742 747
743 /* wait a little bit for next reading status */ 748 /* wait a little bit for next reading status */
744 msleep(10); 749 usleep_range(10000, 20000);
745 } 750 }
746 751
747 dprintk("nicam is not detected.\n"); 752 dprintk("nicam is not detected.\n");
@@ -762,8 +767,10 @@ void cx88_set_tvaudio(struct cx88_core *core)
762 /* prepare all dsp registers */ 767 /* prepare all dsp registers */
763 set_audio_standard_A2(core, EN_A2_FORCE_MONO1); 768 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
764 769
765 /* set nicam mode - otherwise 770 /*
766 AUD_NICAM_STATUS2 contains wrong values */ 771 * set nicam mode - otherwise
772 * AUD_NICAM_STATUS2 contains wrong values
773 */
767 set_audio_standard_NICAM(core, EN_NICAM_AUTO_STEREO); 774 set_audio_standard_NICAM(core, EN_NICAM_AUTO_STEREO);
768 if (cx88_detect_nicam(core) == 0) { 775 if (cx88_detect_nicam(core) == 0) {
769 /* fall back to fm / am mono */ 776 /* fall back to fm / am mono */
@@ -797,19 +804,22 @@ void cx88_set_tvaudio(struct cx88_core *core)
797 pr_info("unknown tv audio mode [%d]\n", core->tvaudio); 804 pr_info("unknown tv audio mode [%d]\n", core->tvaudio);
798 break; 805 break;
799 } 806 }
800 return;
801} 807}
808EXPORT_SYMBOL(cx88_set_tvaudio);
802 809
803void cx88_newstation(struct cx88_core *core) 810void cx88_newstation(struct cx88_core *core)
804{ 811{
805 core->audiomode_manual = UNSET; 812 core->audiomode_manual = UNSET;
806 core->last_change = jiffies; 813 core->last_change = jiffies;
807} 814}
815EXPORT_SYMBOL(cx88_newstation);
808 816
809void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t) 817void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
810{ 818{
811 static const char * const m[] = { "stereo", "dual mono", "mono", "sap" }; 819 static const char * const m[] = { "stereo", "dual mono",
812 static const char * const p[] = { "no pilot", "pilot c1", "pilot c2", "?" }; 820 "mono", "sap" };
821 static const char * const p[] = { "no pilot", "pilot c1",
822 "pilot c2", "?" };
813 u32 reg, mode, pilot; 823 u32 reg, mode, pilot;
814 824
815 reg = cx_read(AUD_STATUS); 825 reg = cx_read(AUD_STATUS);
@@ -866,13 +876,16 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
866 /* If software stereo detection is not supported... */ 876 /* If software stereo detection is not supported... */
867 if (t->rxsubchans == UNSET) { 877 if (t->rxsubchans == UNSET) {
868 t->rxsubchans = V4L2_TUNER_SUB_MONO; 878 t->rxsubchans = V4L2_TUNER_SUB_MONO;
869 /* If the hardware itself detected stereo, also return 879 /*
870 stereo as an available subchannel */ 880 * If the hardware itself detected stereo, also return
881 * stereo as an available subchannel
882 */
871 if (t->audmode == V4L2_TUNER_MODE_STEREO) 883 if (t->audmode == V4L2_TUNER_MODE_STEREO)
872 t->rxsubchans |= V4L2_TUNER_SUB_STEREO; 884 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
873 } 885 }
874 return;
875} 886}
887EXPORT_SYMBOL(cx88_get_stereo);
888
876 889
877void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual) 890void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
878{ 891{
@@ -928,7 +941,8 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
928 break; 941 break;
929 } 942 }
930 } else { 943 } else {
931 if ((core->tvaudio == WW_I) || (core->tvaudio == WW_L)) { 944 if ((core->tvaudio == WW_I) ||
945 (core->tvaudio == WW_L)) {
932 /* fall back to fm / am mono */ 946 /* fall back to fm / am mono */
933 set_audio_standard_A2(core, EN_A2_FORCE_MONO1); 947 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
934 } else { 948 } else {
@@ -976,8 +990,8 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
976 cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL)); 990 cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL));
977 cx_andor(AUD_CTL, mask, ctl); 991 cx_andor(AUD_CTL, mask, ctl);
978 } 992 }
979 return;
980} 993}
994EXPORT_SYMBOL(cx88_set_stereo);
981 995
982int cx88_audio_thread(void *data) 996int cx88_audio_thread(void *data)
983{ 997{
@@ -1027,8 +1041,10 @@ int cx88_audio_thread(void *data)
1027 case WW_FM: 1041 case WW_FM:
1028 case WW_I2SADC: 1042 case WW_I2SADC:
1029hw_autodetect: 1043hw_autodetect:
1030 /* stereo autodetection is supported by hardware so 1044 /*
1031 we don't need to do it manually. Do nothing. */ 1045 * stereo autodetection is supported by hardware so
1046 * we don't need to do it manually. Do nothing.
1047 */
1032 break; 1048 break;
1033 } 1049 }
1034 } 1050 }
@@ -1036,11 +1052,4 @@ hw_autodetect:
1036 dprintk("cx88: tvaudio thread exiting\n"); 1052 dprintk("cx88: tvaudio thread exiting\n");
1037 return 0; 1053 return 0;
1038} 1054}
1039
1040/* ----------------------------------------------------------- */
1041
1042EXPORT_SYMBOL(cx88_set_tvaudio);
1043EXPORT_SYMBOL(cx88_newstation);
1044EXPORT_SYMBOL(cx88_set_stereo);
1045EXPORT_SYMBOL(cx88_get_stereo);
1046EXPORT_SYMBOL(cx88_audio_thread); 1055EXPORT_SYMBOL(cx88_audio_thread);
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index 9028822f507e..2d0ef19e6d65 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -20,7 +20,7 @@ MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
20/* ------------------------------------------------------------------ */ 20/* ------------------------------------------------------------------ */
21 21
22int cx8800_vbi_fmt(struct file *file, void *priv, 22int cx8800_vbi_fmt(struct file *file, void *priv,
23 struct v4l2_format *f) 23 struct v4l2_format *f)
24{ 24{
25 struct cx8800_dev *dev = video_drvdata(file); 25 struct cx8800_dev *dev = video_drvdata(file);
26 26
@@ -48,8 +48,8 @@ int cx8800_vbi_fmt(struct file *file, void *priv,
48} 48}
49 49
50static int cx8800_start_vbi_dma(struct cx8800_dev *dev, 50static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
51 struct cx88_dmaqueue *q, 51 struct cx88_dmaqueue *q,
52 struct cx88_buffer *buf) 52 struct cx88_buffer *buf)
53{ 53{
54 struct cx88_core *core = dev->core; 54 struct cx88_core *core = dev->core;
55 55
@@ -57,9 +57,9 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
57 cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24], 57 cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24],
58 VBI_LINE_LENGTH, buf->risc.dma); 58 VBI_LINE_LENGTH, buf->risc.dma);
59 59
60 cx_write(MO_VBOS_CONTROL, ((1 << 18) | // comb filter delay fixup 60 cx_write(MO_VBOS_CONTROL, (1 << 18) | /* comb filter delay fixup */
61 (1 << 15) | // enable vbi capture 61 (1 << 15) | /* enable vbi capture */
62 (1 << 11))); 62 (1 << 11));
63 63
64 /* reset counter */ 64 /* reset counter */
65 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET); 65 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET);
@@ -73,7 +73,7 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
73 cx_set(VID_CAPTURE_CONTROL, 0x18); 73 cx_set(VID_CAPTURE_CONTROL, 0x18);
74 74
75 /* start dma */ 75 /* start dma */
76 cx_set(MO_DEV_CNTRL2, (1<<5)); 76 cx_set(MO_DEV_CNTRL2, (1 << 5));
77 cx_set(MO_VID_DMACNTRL, 0x88); 77 cx_set(MO_VID_DMACNTRL, 0x88);
78 78
79 return 0; 79 return 0;
@@ -112,8 +112,8 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
112/* ------------------------------------------------------------------ */ 112/* ------------------------------------------------------------------ */
113 113
114static int queue_setup(struct vb2_queue *q, 114static int queue_setup(struct vb2_queue *q,
115 unsigned int *num_buffers, unsigned int *num_planes, 115 unsigned int *num_buffers, unsigned int *num_planes,
116 unsigned int sizes[], struct device *alloc_devs[]) 116 unsigned int sizes[], struct device *alloc_devs[])
117{ 117{
118 struct cx8800_dev *dev = q->drv_priv; 118 struct cx8800_dev *dev = q->drv_priv;
119 119
@@ -125,7 +125,6 @@ static int queue_setup(struct vb2_queue *q,
125 return 0; 125 return 0;
126} 126}
127 127
128
129static int buffer_prepare(struct vb2_buffer *vb) 128static int buffer_prepare(struct vb2_buffer *vb)
130{ 129{
131 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 130 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index 797d5d0a4060..c7d4e87ccb64 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -73,7 +73,6 @@ MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
73 __func__, ##arg); \ 73 __func__, ##arg); \
74} while (0) 74} while (0)
75 75
76
77/* ------------------------------------------------------------------- */ 76/* ------------------------------------------------------------------- */
78/* static data */ 77/* static data */
79 78
@@ -123,7 +122,8 @@ static const struct cx8800_fmt formats[] = {
123 }, { 122 }, {
124 .name = "32 bpp RGB, be", 123 .name = "32 bpp RGB, be",
125 .fourcc = V4L2_PIX_FMT_RGB32, 124 .fourcc = V4L2_PIX_FMT_RGB32,
126 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP, 125 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP |
126 ColorFormatWSWAP,
127 .depth = 32, 127 .depth = 32,
128 .flags = FORMAT_FLAGS_PACKED, 128 .flags = FORMAT_FLAGS_PACKED,
129 }, { 129 }, {
@@ -147,7 +147,7 @@ static const struct cx8800_fmt *format_by_fourcc(unsigned int fourcc)
147 147
148 for (i = 0; i < ARRAY_SIZE(formats); i++) 148 for (i = 0; i < ARRAY_SIZE(formats); i++)
149 if (formats[i].fourcc == fourcc) 149 if (formats[i].fourcc == fourcc)
150 return formats+i; 150 return formats + i;
151 return NULL; 151 return NULL;
152} 152}
153 153
@@ -221,8 +221,10 @@ static const struct cx88_ctrl cx8800_vid_ctls[] = {
221 .step = 1, 221 .step = 1,
222 .default_value = 0x0, 222 .default_value = 0x0,
223 .off = 0, 223 .off = 0,
224 /* NOTE: the value is converted and written to both even 224 /*
225 and odd registers in the code */ 225 * NOTE: the value is converted and written to both even
226 * and odd registers in the code
227 */
226 .reg = MO_FILTER_ODD, 228 .reg = MO_FILTER_ODD,
227 .mask = 7 << 7, 229 .mask = 7 << 7,
228 .shift = 7, 230 .shift = 7,
@@ -326,19 +328,25 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
326 break; 328 break;
327 } 329 }
328 330
329 /* if there are audioroutes defined, we have an external 331 /*
330 ADC to deal with audio */ 332 * if there are audioroutes defined, we have an external
333 * ADC to deal with audio
334 */
331 if (INPUT(input).audioroute) { 335 if (INPUT(input).audioroute) {
332 /* The wm8775 module has the "2" route hardwired into 336 /*
333 the initialization. Some boards may use different 337 * The wm8775 module has the "2" route hardwired into
334 routes for different inputs. HVR-1300 surely does */ 338 * the initialization. Some boards may use different
339 * routes for different inputs. HVR-1300 surely does
340 */
335 if (core->sd_wm8775) { 341 if (core->sd_wm8775) {
336 call_all(core, audio, s_routing, 342 call_all(core, audio, s_routing,
337 INPUT(input).audioroute, 0, 0); 343 INPUT(input).audioroute, 0, 0);
338 } 344 }
339 /* cx2388's C-ADC is connected to the tuner only. 345 /*
340 When used with S-Video, that ADC is busy dealing with 346 * cx2388's C-ADC is connected to the tuner only.
341 chroma, so an external must be used for baseband audio */ 347 * When used with S-Video, that ADC is busy dealing with
348 * chroma, so an external must be used for baseband audio
349 */
342 if (INPUT(input).type != CX88_VMUX_TELEVISION && 350 if (INPUT(input).type != CX88_VMUX_TELEVISION &&
343 INPUT(input).type != CX88_VMUX_CABLE) { 351 INPUT(input).type != CX88_VMUX_CABLE) {
344 /* "I2S ADC mode" */ 352 /* "I2S ADC mode" */
@@ -376,12 +384,13 @@ static int start_video_dma(struct cx8800_dev *dev,
376 /* enable irqs */ 384 /* enable irqs */
377 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); 385 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
378 386
379 /* Enables corresponding bits at PCI_INT_STAT: 387 /*
380 bits 0 to 4: video, audio, transport stream, VIP, Host 388 * Enables corresponding bits at PCI_INT_STAT:
381 bit 7: timer 389 * bits 0 to 4: video, audio, transport stream, VIP, Host
382 bits 8 and 9: DMA complete for: SRC, DST 390 * bit 7: timer
383 bits 10 and 11: BERR signal asserted for RISC: RD, WR 391 * bits 8 and 9: DMA complete for: SRC, DST
384 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB 392 * bits 10 and 11: BERR signal asserted for RISC: RD, WR
393 * bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
385 */ 394 */
386 cx_set(MO_VID_INTMSK, 0x0f0011); 395 cx_set(MO_VID_INTMSK, 0x0f0011);
387 396
@@ -389,7 +398,7 @@ static int start_video_dma(struct cx8800_dev *dev,
389 cx_set(VID_CAPTURE_CONTROL, 0x06); 398 cx_set(VID_CAPTURE_CONTROL, 0x06);
390 399
391 /* start dma */ 400 /* start dma */
392 cx_set(MO_DEV_CNTRL2, (1<<5)); 401 cx_set(MO_DEV_CNTRL2, (1 << 5));
393 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */ 402 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
394 403
395 return 0; 404 return 0;
@@ -430,8 +439,8 @@ static int restart_video_queue(struct cx8800_dev *dev,
430/* ------------------------------------------------------------------ */ 439/* ------------------------------------------------------------------ */
431 440
432static int queue_setup(struct vb2_queue *q, 441static int queue_setup(struct vb2_queue *q,
433 unsigned int *num_buffers, unsigned int *num_planes, 442 unsigned int *num_buffers, unsigned int *num_planes,
434 unsigned int sizes[], struct device *alloc_devs[]) 443 unsigned int sizes[], struct device *alloc_devs[])
435{ 444{
436 struct cx8800_dev *dev = q->drv_priv; 445 struct cx8800_dev *dev = q->drv_priv;
437 struct cx88_core *core = dev->core; 446 struct cx88_core *core = dev->core;
@@ -488,7 +497,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
488 core->height >> 1); 497 core->height >> 1);
489 break; 498 break;
490 } 499 }
491 dprintk(2, "[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", 500 dprintk(2,
501 "[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
492 buf, buf->vb.vb2_buf.index, 502 buf, buf->vb.vb2_buf.index,
493 core->width, core->height, dev->fmt->depth, dev->fmt->name, 503 core->width, core->height, dev->fmt->depth, dev->fmt->name,
494 (unsigned long)buf->risc.dma); 504 (unsigned long)buf->risc.dma);
@@ -595,7 +605,7 @@ static int radio_open(struct file *file)
595 if (core->board.radio.audioroute) { 605 if (core->board.radio.audioroute) {
596 if (core->sd_wm8775) { 606 if (core->sd_wm8775) {
597 call_all(core, audio, s_routing, 607 call_all(core, audio, s_routing,
598 core->board.radio.audioroute, 0, 0); 608 core->board.radio.audioroute, 0, 0);
599 } 609 }
600 /* "I2S ADC mode" */ 610 /* "I2S ADC mode" */
601 core->tvaudio = WW_I2SADC; 611 core->tvaudio = WW_I2SADC;
@@ -649,9 +659,10 @@ static int cx8800_s_vid_ctrl(struct v4l2_ctrl *ctrl)
649 value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; 659 value = ((ctrl->val - cc->off) << cc->shift) & cc->mask;
650 break; 660 break;
651 } 661 }
652 dprintk(1, "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", 662 dprintk(1,
653 ctrl->id, ctrl->name, ctrl->val, cc->reg, value, 663 "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
654 mask, cc->sreg ? " [shadowed]" : ""); 664 ctrl->id, ctrl->name, ctrl->val, cc->reg, value,
665 mask, cc->sreg ? " [shadowed]" : "");
655 if (cc->sreg) 666 if (cc->sreg)
656 cx_sandor(cc->sreg, cc->reg, mask, value); 667 cx_sandor(cc->sreg, cc->reg, mask, value);
657 else 668 else
@@ -687,7 +698,8 @@ static int cx8800_s_aud_ctrl(struct v4l2_ctrl *ctrl)
687 mask = cc->mask; 698 mask = cc->mask;
688 switch (ctrl->id) { 699 switch (ctrl->id) {
689 case V4L2_CID_AUDIO_BALANCE: 700 case V4L2_CID_AUDIO_BALANCE:
690 value = (ctrl->val < 0x40) ? (0x7f - ctrl->val) : (ctrl->val - 0x40); 701 value = (ctrl->val < 0x40) ?
702 (0x7f - ctrl->val) : (ctrl->val - 0x40);
691 break; 703 break;
692 case V4L2_CID_AUDIO_VOLUME: 704 case V4L2_CID_AUDIO_VOLUME:
693 value = 0x3f - (ctrl->val & 0x3f); 705 value = 0x3f - (ctrl->val & 0x3f);
@@ -696,9 +708,10 @@ static int cx8800_s_aud_ctrl(struct v4l2_ctrl *ctrl)
696 value = ((ctrl->val - cc->off) << cc->shift) & cc->mask; 708 value = ((ctrl->val - cc->off) << cc->shift) & cc->mask;
697 break; 709 break;
698 } 710 }
699 dprintk(1, "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n", 711 dprintk(1,
700 ctrl->id, ctrl->name, ctrl->val, cc->reg, value, 712 "set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
701 mask, cc->sreg ? " [shadowed]" : ""); 713 ctrl->id, ctrl->name, ctrl->val, cc->reg, value,
714 mask, cc->sreg ? " [shadowed]" : "");
702 if (cc->sreg) 715 if (cc->sreg)
703 cx_sandor(cc->sreg, cc->reg, mask, value); 716 cx_sandor(cc->sreg, cc->reg, mask, value);
704 else 717 else
@@ -710,7 +723,7 @@ static int cx8800_s_aud_ctrl(struct v4l2_ctrl *ctrl)
710/* VIDEO IOCTLS */ 723/* VIDEO IOCTLS */
711 724
712static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 725static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
713 struct v4l2_format *f) 726 struct v4l2_format *f)
714{ 727{
715 struct cx8800_dev *dev = video_drvdata(file); 728 struct cx8800_dev *dev = video_drvdata(file);
716 struct cx88_core *core = dev->core; 729 struct cx88_core *core = dev->core;
@@ -728,7 +741,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
728} 741}
729 742
730static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 743static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
731 struct v4l2_format *f) 744 struct v4l2_format *f)
732{ 745{
733 struct cx8800_dev *dev = video_drvdata(file); 746 struct cx8800_dev *dev = video_drvdata(file);
734 struct cx88_core *core = dev->core; 747 struct cx88_core *core = dev->core;
@@ -737,7 +750,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
737 unsigned int maxw, maxh; 750 unsigned int maxw, maxh;
738 751
739 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 752 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
740 if (fmt == NULL) 753 if (!fmt)
741 return -EINVAL; 754 return -EINVAL;
742 755
743 maxw = norm_maxw(core->tvnorm); 756 maxw = norm_maxw(core->tvnorm);
@@ -774,7 +787,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
774} 787}
775 788
776static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 789static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
777 struct v4l2_format *f) 790 struct v4l2_format *f)
778{ 791{
779 struct cx8800_dev *dev = video_drvdata(file); 792 struct cx8800_dev *dev = video_drvdata(file);
780 struct cx88_core *core = dev->core; 793 struct cx88_core *core = dev->core;
@@ -794,7 +807,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
794} 807}
795 808
796void cx88_querycap(struct file *file, struct cx88_core *core, 809void cx88_querycap(struct file *file, struct cx88_core *core,
797 struct v4l2_capability *cap) 810 struct v4l2_capability *cap)
798{ 811{
799 struct video_device *vdev = video_devdata(file); 812 struct video_device *vdev = video_devdata(file);
800 813
@@ -821,7 +834,7 @@ void cx88_querycap(struct file *file, struct cx88_core *core,
821EXPORT_SYMBOL(cx88_querycap); 834EXPORT_SYMBOL(cx88_querycap);
822 835
823static int vidioc_querycap(struct file *file, void *priv, 836static int vidioc_querycap(struct file *file, void *priv,
824 struct v4l2_capability *cap) 837 struct v4l2_capability *cap)
825{ 838{
826 struct cx8800_dev *dev = video_drvdata(file); 839 struct cx8800_dev *dev = video_drvdata(file);
827 struct cx88_core *core = dev->core; 840 struct cx88_core *core = dev->core;
@@ -833,7 +846,7 @@ static int vidioc_querycap(struct file *file, void *priv,
833} 846}
834 847
835static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 848static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
836 struct v4l2_fmtdesc *f) 849 struct v4l2_fmtdesc *f)
837{ 850{
838 if (unlikely(f->index >= ARRAY_SIZE(formats))) 851 if (unlikely(f->index >= ARRAY_SIZE(formats)))
839 return -EINVAL; 852 return -EINVAL;
@@ -879,21 +892,21 @@ int cx88_enum_input(struct cx88_core *core, struct v4l2_input *i)
879 892
880 if (n >= 4) 893 if (n >= 4)
881 return -EINVAL; 894 return -EINVAL;
882 if (0 == INPUT(n).type) 895 if (!INPUT(n).type)
883 return -EINVAL; 896 return -EINVAL;
884 i->type = V4L2_INPUT_TYPE_CAMERA; 897 i->type = V4L2_INPUT_TYPE_CAMERA;
885 strcpy(i->name, iname[INPUT(n).type]); 898 strcpy(i->name, iname[INPUT(n).type]);
886 if ((CX88_VMUX_TELEVISION == INPUT(n).type) || 899 if ((INPUT(n).type == CX88_VMUX_TELEVISION) ||
887 (CX88_VMUX_CABLE == INPUT(n).type)) { 900 (INPUT(n).type == CX88_VMUX_CABLE))
888 i->type = V4L2_INPUT_TYPE_TUNER; 901 i->type = V4L2_INPUT_TYPE_TUNER;
889 } 902
890 i->std = CX88_NORMS; 903 i->std = CX88_NORMS;
891 return 0; 904 return 0;
892} 905}
893EXPORT_SYMBOL(cx88_enum_input); 906EXPORT_SYMBOL(cx88_enum_input);
894 907
895static int vidioc_enum_input(struct file *file, void *priv, 908static int vidioc_enum_input(struct file *file, void *priv,
896 struct v4l2_input *i) 909 struct v4l2_input *i)
897{ 910{
898 struct cx8800_dev *dev = video_drvdata(file); 911 struct cx8800_dev *dev = video_drvdata(file);
899 struct cx88_core *core = dev->core; 912 struct cx88_core *core = dev->core;
@@ -917,7 +930,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
917 930
918 if (i >= 4) 931 if (i >= 4)
919 return -EINVAL; 932 return -EINVAL;
920 if (0 == INPUT(i).type) 933 if (!INPUT(i).type)
921 return -EINVAL; 934 return -EINVAL;
922 935
923 cx88_newstation(core); 936 cx88_newstation(core);
@@ -926,7 +939,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
926} 939}
927 940
928static int vidioc_g_tuner(struct file *file, void *priv, 941static int vidioc_g_tuner(struct file *file, void *priv,
929 struct v4l2_tuner *t) 942 struct v4l2_tuner *t)
930{ 943{
931 struct cx8800_dev *dev = video_drvdata(file); 944 struct cx8800_dev *dev = video_drvdata(file);
932 struct cx88_core *core = dev->core; 945 struct cx88_core *core = dev->core;
@@ -944,12 +957,12 @@ static int vidioc_g_tuner(struct file *file, void *priv,
944 957
945 cx88_get_stereo(core, t); 958 cx88_get_stereo(core, t);
946 reg = cx_read(MO_DEVICE_STATUS); 959 reg = cx_read(MO_DEVICE_STATUS);
947 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000; 960 t->signal = (reg & (1 << 5)) ? 0xffff : 0x0000;
948 return 0; 961 return 0;
949} 962}
950 963
951static int vidioc_s_tuner(struct file *file, void *priv, 964static int vidioc_s_tuner(struct file *file, void *priv,
952 const struct v4l2_tuner *t) 965 const struct v4l2_tuner *t)
953{ 966{
954 struct cx8800_dev *dev = video_drvdata(file); 967 struct cx8800_dev *dev = video_drvdata(file);
955 struct cx88_core *core = dev->core; 968 struct cx88_core *core = dev->core;
@@ -964,7 +977,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
964} 977}
965 978
966static int vidioc_g_frequency(struct file *file, void *priv, 979static int vidioc_g_frequency(struct file *file, void *priv,
967 struct v4l2_frequency *f) 980 struct v4l2_frequency *f)
968{ 981{
969 struct cx8800_dev *dev = video_drvdata(file); 982 struct cx8800_dev *dev = video_drvdata(file);
970 struct cx88_core *core = dev->core; 983 struct cx88_core *core = dev->core;
@@ -982,7 +995,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
982} 995}
983 996
984int cx88_set_freq(struct cx88_core *core, 997int cx88_set_freq(struct cx88_core *core,
985 const struct v4l2_frequency *f) 998 const struct v4l2_frequency *f)
986{ 999{
987 struct v4l2_frequency new_freq = *f; 1000 struct v4l2_frequency new_freq = *f;
988 1001
@@ -1005,7 +1018,7 @@ int cx88_set_freq(struct cx88_core *core,
1005EXPORT_SYMBOL(cx88_set_freq); 1018EXPORT_SYMBOL(cx88_set_freq);
1006 1019
1007static int vidioc_s_frequency(struct file *file, void *priv, 1020static int vidioc_s_frequency(struct file *file, void *priv,
1008 const struct v4l2_frequency *f) 1021 const struct v4l2_frequency *f)
1009{ 1022{
1010 struct cx8800_dev *dev = video_drvdata(file); 1023 struct cx8800_dev *dev = video_drvdata(file);
1011 struct cx88_core *core = dev->core; 1024 struct cx88_core *core = dev->core;
@@ -1015,7 +1028,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1015 1028
1016#ifdef CONFIG_VIDEO_ADV_DEBUG 1029#ifdef CONFIG_VIDEO_ADV_DEBUG
1017static int vidioc_g_register(struct file *file, void *fh, 1030static int vidioc_g_register(struct file *file, void *fh,
1018 struct v4l2_dbg_register *reg) 1031 struct v4l2_dbg_register *reg)
1019{ 1032{
1020 struct cx8800_dev *dev = video_drvdata(file); 1033 struct cx8800_dev *dev = video_drvdata(file);
1021 struct cx88_core *core = dev->core; 1034 struct cx88_core *core = dev->core;
@@ -1027,7 +1040,7 @@ static int vidioc_g_register(struct file *file, void *fh,
1027} 1040}
1028 1041
1029static int vidioc_s_register(struct file *file, void *fh, 1042static int vidioc_s_register(struct file *file, void *fh,
1030 const struct v4l2_dbg_register *reg) 1043 const struct v4l2_dbg_register *reg)
1031{ 1044{
1032 struct cx8800_dev *dev = video_drvdata(file); 1045 struct cx8800_dev *dev = video_drvdata(file);
1033 struct cx88_core *core = dev->core; 1046 struct cx88_core *core = dev->core;
@@ -1042,7 +1055,7 @@ static int vidioc_s_register(struct file *file, void *fh,
1042/* ----------------------------------------------------------- */ 1055/* ----------------------------------------------------------- */
1043 1056
1044static int radio_g_tuner(struct file *file, void *priv, 1057static int radio_g_tuner(struct file *file, void *priv,
1045 struct v4l2_tuner *t) 1058 struct v4l2_tuner *t)
1046{ 1059{
1047 struct cx8800_dev *dev = video_drvdata(file); 1060 struct cx8800_dev *dev = video_drvdata(file);
1048 struct cx88_core *core = dev->core; 1061 struct cx88_core *core = dev->core;
@@ -1057,7 +1070,7 @@ static int radio_g_tuner(struct file *file, void *priv,
1057} 1070}
1058 1071
1059static int radio_s_tuner(struct file *file, void *priv, 1072static int radio_s_tuner(struct file *file, void *priv,
1060 const struct v4l2_tuner *t) 1073 const struct v4l2_tuner *t)
1061{ 1074{
1062 struct cx8800_dev *dev = video_drvdata(file); 1075 struct cx8800_dev *dev = video_drvdata(file);
1063 struct cx88_core *core = dev->core; 1076 struct cx88_core *core = dev->core;
@@ -1152,7 +1165,6 @@ static irqreturn_t cx8800_irq(int irq, void *dev_id)
1152/* exported stuff */ 1165/* exported stuff */
1153 1166
1154static const struct v4l2_file_operations video_fops = { 1167static const struct v4l2_file_operations video_fops = {
1155
1156 .owner = THIS_MODULE, 1168 .owner = THIS_MODULE,
1157 .open = v4l2_fh_open, 1169 .open = v4l2_fh_open,
1158 .release = vb2_fop_release, 1170 .release = vb2_fop_release,
@@ -1232,7 +1244,6 @@ static const struct video_device cx8800_vbi_template = {
1232}; 1244};
1233 1245
1234static const struct v4l2_file_operations radio_fops = { 1246static const struct v4l2_file_operations radio_fops = {
1235
1236 .owner = THIS_MODULE, 1247 .owner = THIS_MODULE,
1237 .open = radio_open, 1248 .open = radio_open,
1238 .poll = v4l2_ctrl_poll, 1249 .poll = v4l2_ctrl_poll,
@@ -1287,7 +1298,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1287 int i; 1298 int i;
1288 1299
1289 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1300 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1290 if (dev == NULL) 1301 if (!dev)
1291 return -ENOMEM; 1302 return -ENOMEM;
1292 1303
1293 /* pci init */ 1304 /* pci init */
@@ -1297,7 +1308,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1297 goto fail_free; 1308 goto fail_free;
1298 } 1309 }
1299 core = cx88_core_get(dev->pci); 1310 core = cx88_core_get(dev->pci);
1300 if (core == NULL) { 1311 if (!core) {
1301 err = -EINVAL; 1312 err = -EINVAL;
1302 goto fail_free; 1313 goto fail_free;
1303 } 1314 }
@@ -1341,8 +1352,9 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1341 struct v4l2_ctrl *vc; 1352 struct v4l2_ctrl *vc;
1342 1353
1343 vc = v4l2_ctrl_new_std(&core->audio_hdl, &cx8800_ctrl_aud_ops, 1354 vc = v4l2_ctrl_new_std(&core->audio_hdl, &cx8800_ctrl_aud_ops,
1344 cc->id, cc->minimum, cc->maximum, cc->step, cc->default_value); 1355 cc->id, cc->minimum, cc->maximum,
1345 if (vc == NULL) { 1356 cc->step, cc->default_value);
1357 if (!vc) {
1346 err = core->audio_hdl.error; 1358 err = core->audio_hdl.error;
1347 goto fail_core; 1359 goto fail_core;
1348 } 1360 }
@@ -1354,8 +1366,9 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1354 struct v4l2_ctrl *vc; 1366 struct v4l2_ctrl *vc;
1355 1367
1356 vc = v4l2_ctrl_new_std(&core->video_hdl, &cx8800_ctrl_vid_ops, 1368 vc = v4l2_ctrl_new_std(&core->video_hdl, &cx8800_ctrl_vid_ops,
1357 cc->id, cc->minimum, cc->maximum, cc->step, cc->default_value); 1369 cc->id, cc->minimum, cc->maximum,
1358 if (vc == NULL) { 1370 cc->step, cc->default_value);
1371 if (!vc) {
1359 err = core->video_hdl.error; 1372 err = core->video_hdl.error;
1360 goto fail_core; 1373 goto fail_core;
1361 } 1374 }
@@ -1381,18 +1394,20 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1381 core->wm8775_data.is_nova_s = false; 1394 core->wm8775_data.is_nova_s = false;
1382 1395
1383 sd = v4l2_i2c_new_subdev_board(&core->v4l2_dev, &core->i2c_adap, 1396 sd = v4l2_i2c_new_subdev_board(&core->v4l2_dev, &core->i2c_adap,
1384 &wm8775_info, NULL); 1397 &wm8775_info, NULL);
1385 if (sd != NULL) { 1398 if (sd) {
1386 core->sd_wm8775 = sd; 1399 core->sd_wm8775 = sd;
1387 sd->grp_id = WM8775_GID; 1400 sd->grp_id = WM8775_GID;
1388 } 1401 }
1389 } 1402 }
1390 1403
1391 if (core->board.audio_chip == CX88_AUDIO_TVAUDIO) { 1404 if (core->board.audio_chip == CX88_AUDIO_TVAUDIO) {
1392 /* This probes for a tda9874 as is used on some 1405 /*
1393 Pixelview Ultra boards. */ 1406 * This probes for a tda9874 as is used on some
1407 * Pixelview Ultra boards.
1408 */
1394 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 1409 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
1395 "tvaudio", 0, I2C_ADDRS(0xb0 >> 1)); 1410 "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
1396 } 1411 }
1397 1412
1398 switch (core->boardnr) { 1413 switch (core->boardnr) {
@@ -1504,7 +1519,8 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1504 1519
1505 /* start tvaudio thread */ 1520 /* start tvaudio thread */
1506 if (core->board.tuner_type != UNSET) { 1521 if (core->board.tuner_type != UNSET) {
1507 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); 1522 core->kthread = kthread_run(cx88_audio_thread,
1523 core, "cx88 tvaudio");
1508 if (IS_ERR(core->kthread)) { 1524 if (IS_ERR(core->kthread)) {
1509 err = PTR_ERR(core->kthread); 1525 err = PTR_ERR(core->kthread);
1510 pr_err("failed to create cx88 audio thread, err=%d\n", 1526 pr_err("failed to create cx88 audio thread, err=%d\n",
@@ -1581,7 +1597,8 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1581 cx88_shutdown(core); 1597 cx88_shutdown(core);
1582 1598
1583 pci_save_state(pci_dev); 1599 pci_save_state(pci_dev);
1584 if (pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)) != 0) { 1600 if (pci_set_power_state(pci_dev,
1601 pci_choose_state(pci_dev, state)) != 0) {
1585 pci_disable_device(pci_dev); 1602 pci_disable_device(pci_dev);
1586 dev->state.disabled = 1; 1603 dev->state.disabled = 1;
1587 } 1604 }
diff --git a/drivers/media/pci/cx88/cx88-vp3054-i2c.c b/drivers/media/pci/cx88/cx88-vp3054-i2c.c
index eea56ae9071e..92876de3841c 100644
--- a/drivers/media/pci/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/pci/cx88/cx88-vp3054-i2c.c
@@ -22,8 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/init.h> 24#include <linux/init.h>
25 25#include <linux/io.h>
26#include <asm/io.h>
27 26
28MODULE_DESCRIPTION("driver for cx2388x VP3054 design"); 27MODULE_DESCRIPTION("driver for cx2388x VP3054 design");
29MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); 28MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
@@ -108,7 +107,7 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
108 return 0; 107 return 0;
109 108
110 vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL); 109 vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
111 if (vp3054_i2c == NULL) 110 if (!vp3054_i2c)
112 return -ENOMEM; 111 return -ENOMEM;
113 dev->vp3054 = vp3054_i2c; 112 dev->vp3054 = vp3054_i2c;
114 113
@@ -135,18 +134,17 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
135 134
136 return rc; 135 return rc;
137} 136}
137EXPORT_SYMBOL(vp3054_i2c_probe);
138 138
139void vp3054_i2c_remove(struct cx8802_dev *dev) 139void vp3054_i2c_remove(struct cx8802_dev *dev)
140{ 140{
141 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; 141 struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
142 142
143 if (vp3054_i2c == NULL || 143 if (!vp3054_i2c ||
144 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) 144 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
145 return; 145 return;
146 146
147 i2c_del_adapter(&vp3054_i2c->adap); 147 i2c_del_adapter(&vp3054_i2c->adap);
148 kfree(vp3054_i2c); 148 kfree(vp3054_i2c);
149} 149}
150
151EXPORT_SYMBOL(vp3054_i2c_probe);
152EXPORT_SYMBOL(vp3054_i2c_remove); 150EXPORT_SYMBOL(vp3054_i2c_remove);
diff --git a/drivers/media/pci/cx88/cx88-vp3054-i2c.h b/drivers/media/pci/cx88/cx88-vp3054-i2c.h
index 95d0c60a35e1..ec19bea8f1e2 100644
--- a/drivers/media/pci/cx88/cx88-vp3054-i2c.h
+++ b/drivers/media/pci/cx88/cx88-vp3054-i2c.h
@@ -1,26 +1,20 @@
1/* 1/*
2 2 * cx88-vp3054-i2c.h -- support for the secondary I2C bus of the
3 cx88-vp3054-i2c.h -- support for the secondary I2C bus of the 3 * DNTV Live! DVB-T Pro (VP-3054), wired as:
4 DNTV Live! DVB-T Pro (VP-3054), wired as: 4 * GPIO[0] -> SCL, GPIO[1] -> SDA
5 GPIO[0] -> SCL, GPIO[1] -> SDA 5 *
6 6 * (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
7 (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> 7 *
8 8 * This program is free software; you can redistribute it and/or modify
9 This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by
10 it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or
11 the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version.
12 (at your option) any later version. 12 *
13 13 * This program is distributed in the hope that it will be useful,
14 This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details.
17 GNU General Public License for more details. 17 */
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23*/
24 18
25/* ----------------------------------------------------------------------- */ 19/* ----------------------------------------------------------------------- */
26struct vp3054_i2c_state { 20struct vp3054_i2c_state {
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index ac1fb9fb340e..115414cf520f 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -1,5 +1,4 @@
1/* 1/*
2 *
3 * v4l2 device driver for cx2388x based TV cards 2 * v4l2 device driver for cx2388x based TV cards
4 * 3 *
5 * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs] 4 * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
@@ -99,7 +98,6 @@ static inline unsigned int norm_maxw(v4l2_std_id norm)
99 return 720; 98 return 720;
100} 99}
101 100
102
103static inline unsigned int norm_maxh(v4l2_std_id norm) 101static inline unsigned int norm_maxh(v4l2_std_id norm)
104{ 102{
105 return (norm & V4L2_STD_525_60) ? 480 : 576; 103 return (norm & V4L2_STD_525_60) ? 480 : 576;
@@ -141,6 +139,7 @@ struct sram_channel {
141 u32 cnt1_reg; 139 u32 cnt1_reg;
142 u32 cnt2_reg; 140 u32 cnt2_reg;
143}; 141};
142
144extern const struct sram_channel cx88_sram_channels[]; 143extern const struct sram_channel cx88_sram_channels[];
145 144
146/* ----------------------------------------------------------- */ 145/* ----------------------------------------------------------- */
@@ -384,8 +383,8 @@ struct cx88_core {
384 /* state info */ 383 /* state info */
385 struct task_struct *kthread; 384 struct task_struct *kthread;
386 v4l2_std_id tvnorm; 385 v4l2_std_id tvnorm;
387 unsigned int width, height; 386 unsigned int width, height;
388 unsigned int field; 387 unsigned int field;
389 enum cx88_tvaudio tvaudio; 388 enum cx88_tvaudio tvaudio;
390 u32 audiomode_manual; 389 u32 audiomode_manual;
391 u32 audiomode_current; 390 u32 audiomode_current;
@@ -428,7 +427,8 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
428 if (!core->i2c_rc) { \ 427 if (!core->i2c_rc) { \
429 if (core->gate_ctrl) \ 428 if (core->gate_ctrl) \
430 core->gate_ctrl(core, 1); \ 429 core->gate_ctrl(core, 1); \
431 v4l2_device_call_all(&core->v4l2_dev, grpid, o, f, ##args); \ 430 v4l2_device_call_all(&core->v4l2_dev, \
431 grpid, o, f, ##args); \
432 if (core->gate_ctrl) \ 432 if (core->gate_ctrl) \
433 core->gate_ctrl(core, 0); \ 433 core->gate_ctrl(core, 0); \
434 } \ 434 } \
@@ -439,31 +439,31 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
439#define WM8775_GID (1 << 0) 439#define WM8775_GID (1 << 0)
440 440
441#define wm8775_s_ctrl(core, id, val) \ 441#define wm8775_s_ctrl(core, id, val) \
442 do { \ 442 do { \
443 struct v4l2_ctrl *ctrl_ = \ 443 struct v4l2_ctrl *ctrl_ = \
444 v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id); \ 444 v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);\
445 if (ctrl_ && !core->i2c_rc) { \ 445 if (ctrl_ && !core->i2c_rc) { \
446 if (core->gate_ctrl) \ 446 if (core->gate_ctrl) \
447 core->gate_ctrl(core, 1); \ 447 core->gate_ctrl(core, 1); \
448 v4l2_ctrl_s_ctrl(ctrl_, val); \ 448 v4l2_ctrl_s_ctrl(ctrl_, val); \
449 if (core->gate_ctrl) \ 449 if (core->gate_ctrl) \
450 core->gate_ctrl(core, 0); \ 450 core->gate_ctrl(core, 0); \
451 } \ 451 } \
452 } while (0) 452 } while (0)
453 453
454#define wm8775_g_ctrl(core, id) \ 454#define wm8775_g_ctrl(core, id) \
455 ({ \ 455 ({ \
456 struct v4l2_ctrl *ctrl_ = \ 456 struct v4l2_ctrl *ctrl_ = \
457 v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id); \ 457 v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);\
458 s32 val = 0; \ 458 s32 val = 0; \
459 if (ctrl_ && !core->i2c_rc) { \ 459 if (ctrl_ && !core->i2c_rc) { \
460 if (core->gate_ctrl) \ 460 if (core->gate_ctrl) \
461 core->gate_ctrl(core, 1); \ 461 core->gate_ctrl(core, 1); \
462 val = v4l2_ctrl_g_ctrl(ctrl_); \ 462 val = v4l2_ctrl_g_ctrl(ctrl_); \
463 if (core->gate_ctrl) \ 463 if (core->gate_ctrl) \
464 core->gate_ctrl(core, 0); \ 464 core->gate_ctrl(core, 0); \
465 } \ 465 } \
466 val; \ 466 val; \
467 }) 467 })
468 468
469/* ----------------------------------------------------------- */ 469/* ----------------------------------------------------------- */
@@ -505,7 +505,6 @@ struct cx8800_dev {
505/* function 1: audio/alsa stuff */ 505/* function 1: audio/alsa stuff */
506/* =============> moved to cx88-alsa.c <====================== */ 506/* =============> moved to cx88-alsa.c <====================== */
507 507
508
509/* ----------------------------------------------------------- */ 508/* ----------------------------------------------------------- */
510/* function 2: mpeg stuff */ 509/* function 2: mpeg stuff */
511 510
@@ -567,6 +566,7 @@ struct cx8802_dev {
567 566
568 /* mpeg params */ 567 /* mpeg params */
569 struct cx2341x_handler cxhdl; 568 struct cx2341x_handler cxhdl;
569
570#endif 570#endif
571 571
572#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB) 572#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
@@ -589,40 +589,42 @@ struct cx8802_dev {
589 589
590/* ----------------------------------------------------------- */ 590/* ----------------------------------------------------------- */
591 591
592#define cx_read(reg) readl(core->lmmio + ((reg)>>2)) 592#define cx_read(reg) readl(core->lmmio + ((reg) >> 2))
593#define cx_write(reg, value) writel((value), core->lmmio + ((reg)>>2)) 593#define cx_write(reg, value) writel((value), core->lmmio + ((reg) >> 2))
594#define cx_writeb(reg, value) writeb((value), core->bmmio + (reg)) 594#define cx_writeb(reg, value) writeb((value), core->bmmio + (reg))
595 595
596#define cx_andor(reg, mask, value) \ 596#define cx_andor(reg, mask, value) \
597 writel((readl(core->lmmio+((reg)>>2)) & ~(mask)) |\ 597 writel((readl(core->lmmio + ((reg) >> 2)) & ~(mask)) |\
598 ((value) & (mask)), core->lmmio+((reg)>>2)) 598 ((value) & (mask)), core->lmmio + ((reg) >> 2))
599#define cx_set(reg, bit) cx_andor((reg), (bit), (bit)) 599#define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
600#define cx_clear(reg, bit) cx_andor((reg), (bit), 0) 600#define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
601 601
602#define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); } 602#define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
603 603
604/* shadow registers */ 604/* shadow registers */
605#define cx_sread(sreg) (core->shadow[sreg]) 605#define cx_sread(sreg) (core->shadow[sreg])
606#define cx_swrite(sreg, reg, value) \ 606#define cx_swrite(sreg, reg, value) \
607 (core->shadow[sreg] = value, \ 607 (core->shadow[sreg] = value, \
608 writel(core->shadow[sreg], core->lmmio + ((reg)>>2))) 608 writel(core->shadow[sreg], core->lmmio + ((reg) >> 2)))
609#define cx_sandor(sreg, reg, mask, value) \ 609#define cx_sandor(sreg, reg, mask, value) \
610 (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | ((value) & (mask)), \ 610 (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | \
611 writel(core->shadow[sreg], core->lmmio + ((reg)>>2))) 611 ((value) & (mask)), \
612 writel(core->shadow[sreg], \
613 core->lmmio + ((reg) >> 2)))
612 614
613/* ----------------------------------------------------------- */ 615/* ----------------------------------------------------------- */
614/* cx88-core.c */ 616/* cx88-core.c */
615 617
616extern unsigned int cx88_core_debug; 618extern unsigned int cx88_core_debug;
617 619
618extern void cx88_print_irqbits(const char *tag, const char *strings[], 620void cx88_print_irqbits(const char *tag, const char *strings[],
619 int len, u32 bits, u32 mask); 621 int len, u32 bits, u32 mask);
620 622
621extern int cx88_core_irq(struct cx88_core *core, u32 status); 623int cx88_core_irq(struct cx88_core *core, u32 status);
622extern void cx88_wakeup(struct cx88_core *core, 624void cx88_wakeup(struct cx88_core *core,
623 struct cx88_dmaqueue *q, u32 count); 625 struct cx88_dmaqueue *q, u32 count);
624extern void cx88_shutdown(struct cx88_core *core); 626void cx88_shutdown(struct cx88_core *core);
625extern int cx88_reset(struct cx88_core *core); 627int cx88_reset(struct cx88_core *core);
626 628
627extern int 629extern int
628cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc, 630cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
@@ -634,43 +636,37 @@ cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
634 struct scatterlist *sglist, unsigned int bpl, 636 struct scatterlist *sglist, unsigned int bpl,
635 unsigned int lines, unsigned int lpi); 637 unsigned int lines, unsigned int lpi);
636 638
637extern void cx88_risc_disasm(struct cx88_core *core, 639void cx88_risc_disasm(struct cx88_core *core,
638 struct cx88_riscmem *risc); 640 struct cx88_riscmem *risc);
639extern int cx88_sram_channel_setup(struct cx88_core *core, 641int cx88_sram_channel_setup(struct cx88_core *core,
640 const struct sram_channel *ch, 642 const struct sram_channel *ch,
641 unsigned int bpl, u32 risc); 643 unsigned int bpl, u32 risc);
642extern void cx88_sram_channel_dump(struct cx88_core *core, 644void cx88_sram_channel_dump(struct cx88_core *core,
643 const struct sram_channel *ch); 645 const struct sram_channel *ch);
644 646
645extern int cx88_set_scale(struct cx88_core *core, unsigned int width, 647int cx88_set_scale(struct cx88_core *core, unsigned int width,
646 unsigned int height, enum v4l2_field field); 648 unsigned int height, enum v4l2_field field);
647extern int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm); 649int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm);
648 650
649extern void cx88_vdev_init(struct cx88_core *core, 651void cx88_vdev_init(struct cx88_core *core,
650 struct pci_dev *pci, 652 struct pci_dev *pci,
651 struct video_device *vfd, 653 struct video_device *vfd,
652 const struct video_device *template_, 654 const struct video_device *template_,
653 const char *type); 655 const char *type);
654extern struct cx88_core *cx88_core_get(struct pci_dev *pci); 656struct cx88_core *cx88_core_get(struct pci_dev *pci);
655extern void cx88_core_put(struct cx88_core *core, 657void cx88_core_put(struct cx88_core *core,
656 struct pci_dev *pci); 658 struct pci_dev *pci);
657 659
658extern int cx88_start_audio_dma(struct cx88_core *core); 660int cx88_start_audio_dma(struct cx88_core *core);
659extern int cx88_stop_audio_dma(struct cx88_core *core); 661int cx88_stop_audio_dma(struct cx88_core *core);
660
661 662
662/* ----------------------------------------------------------- */ 663/* ----------------------------------------------------------- */
663/* cx88-vbi.c */ 664/* cx88-vbi.c */
664 665
665/* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */ 666/* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
666int cx8800_vbi_fmt(struct file *file, void *priv, 667int cx8800_vbi_fmt(struct file *file, void *priv,
667 struct v4l2_format *f); 668 struct v4l2_format *f);
668 669
669/*
670int cx8800_start_vbi_dma(struct cx8800_dev *dev,
671 struct cx88_dmaqueue *q,
672 struct cx88_buffer *buf);
673*/
674void cx8800_stop_vbi_dma(struct cx8800_dev *dev); 670void cx8800_stop_vbi_dma(struct cx8800_dev *dev);
675int cx8800_restart_vbi_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q); 671int cx8800_restart_vbi_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q);
676 672
@@ -679,17 +675,16 @@ extern const struct vb2_ops cx8800_vbi_qops;
679/* ----------------------------------------------------------- */ 675/* ----------------------------------------------------------- */
680/* cx88-i2c.c */ 676/* cx88-i2c.c */
681 677
682extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci); 678int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
683
684 679
685/* ----------------------------------------------------------- */ 680/* ----------------------------------------------------------- */
686/* cx88-cards.c */ 681/* cx88-cards.c */
687 682
688extern int cx88_tuner_callback(void *dev, int component, int command, int arg); 683int cx88_tuner_callback(void *dev, int component, int command, int arg);
689extern int cx88_get_resources(const struct cx88_core *core, 684int cx88_get_resources(const struct cx88_core *core,
690 struct pci_dev *pci); 685 struct pci_dev *pci);
691extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr); 686struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
692extern void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl); 687void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl);
693 688
694/* ----------------------------------------------------------- */ 689/* ----------------------------------------------------------- */
695/* cx88-tvaudio.c */ 690/* cx88-tvaudio.c */
@@ -720,18 +715,18 @@ int cx88_ir_fini(struct cx88_core *core);
720void cx88_ir_irq(struct cx88_core *core); 715void cx88_ir_irq(struct cx88_core *core);
721int cx88_ir_start(struct cx88_core *core); 716int cx88_ir_start(struct cx88_core *core);
722void cx88_ir_stop(struct cx88_core *core); 717void cx88_ir_stop(struct cx88_core *core);
723extern void cx88_i2c_init_ir(struct cx88_core *core); 718void cx88_i2c_init_ir(struct cx88_core *core);
724 719
725/* ----------------------------------------------------------- */ 720/* ----------------------------------------------------------- */
726/* cx88-mpeg.c */ 721/* cx88-mpeg.c */
727 722
728int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, 723int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
729 struct cx88_buffer *buf); 724 struct cx88_buffer *buf);
730void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); 725void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
731void cx8802_cancel_buffers(struct cx8802_dev *dev); 726void cx8802_cancel_buffers(struct cx8802_dev *dev);
732int cx8802_start_dma(struct cx8802_dev *dev, 727int cx8802_start_dma(struct cx8802_dev *dev,
733 struct cx88_dmaqueue *q, 728 struct cx88_dmaqueue *q,
734 struct cx88_buffer *buf); 729 struct cx88_buffer *buf);
735 730
736/* ----------------------------------------------------------- */ 731/* ----------------------------------------------------------- */
737/* cx88-video.c*/ 732/* cx88-video.c*/
@@ -739,6 +734,6 @@ int cx88_enum_input(struct cx88_core *core, struct v4l2_input *i);
739int cx88_set_freq(struct cx88_core *core, const struct v4l2_frequency *f); 734int cx88_set_freq(struct cx88_core *core, const struct v4l2_frequency *f);
740int cx88_video_mux(struct cx88_core *core, unsigned int input); 735int cx88_video_mux(struct cx88_core *core, unsigned int input);
741void cx88_querycap(struct file *file, struct cx88_core *core, 736void cx88_querycap(struct file *file, struct cx88_core *core,
742 struct v4l2_capability *cap); 737 struct v4l2_capability *cap);
743 738
744#endif 739#endif