]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/cx88/cx88-core.c
Merge branch 'master'
[linux-2.6-omap-h63xx.git] / drivers / media / video / cx88 / cx88-core.c
index c046a23537d35ed22923e833c8ebcd7306c62213..bb6eb54e19ceddcb4726ee9dfc5117baa8c73ef1 100644 (file)
@@ -1,5 +1,4 @@
 /*
- * $Id: cx88-core.c,v 1.28 2005/06/12 04:19:19 mchehab Exp $
  *
  * device driver for Conexant 2388x based TV cards
  * driver core
@@ -32,7 +31,7 @@
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/delay.h>
-#include <linux/videodev.h>
+#include <linux/videodev2.h>
 
 #include "cx88.h"
 
@@ -154,26 +153,26 @@ static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist,
                }
                if (bpl <= sg_dma_len(sg)-offset) {
                        /* fits into current chunk */
-                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);
-                        *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
-                        offset+=bpl;
+                       *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);
+                       *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
+                       offset+=bpl;
                } else {
                        /* scanline needs to be splitted */
-                        todo = bpl;
-                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|
+                       todo = bpl;
+                       *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|
                                            (sg_dma_len(sg)-offset));
-                        *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
-                        todo -= (sg_dma_len(sg)-offset);
-                        offset = 0;
-                        sg++;
-                        while (todo > sg_dma_len(sg)) {
-                                *(rp++)=cpu_to_le32(RISC_WRITE|
+                       *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
+                       todo -= (sg_dma_len(sg)-offset);
+                       offset = 0;
+                       sg++;
+                       while (todo > sg_dma_len(sg)) {
+                               *(rp++)=cpu_to_le32(RISC_WRITE|
                                                    sg_dma_len(sg));
-                                *(rp++)=cpu_to_le32(sg_dma_address(sg));
+                               *(rp++)=cpu_to_le32(sg_dma_address(sg));
                                todo -= sg_dma_len(sg);
                                sg++;
                        }
-                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
+                       *(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
                        *(rp++)=cpu_to_le32(sg_dma_address(sg));
                        offset += todo;
                }
@@ -310,7 +309,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "video y / packed",
                .cmds_start = 0x180040,
                .ctrl_start = 0x180400,
-               .cdt        = 0x180400 + 64,
+               .cdt        = 0x180400 + 64,
                .fifo_start = 0x180c00,
                .fifo_size  = 0x002800,
                .ptr1_reg   = MO_DMA21_PTR1,
@@ -322,7 +321,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "video u",
                .cmds_start = 0x180080,
                .ctrl_start = 0x1804a0,
-               .cdt        = 0x1804a0 + 64,
+               .cdt        = 0x1804a0 + 64,
                .fifo_start = 0x183400,
                .fifo_size  = 0x000800,
                .ptr1_reg   = MO_DMA22_PTR1,
@@ -334,7 +333,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "video v",
                .cmds_start = 0x1800c0,
                .ctrl_start = 0x180540,
-               .cdt        = 0x180540 + 64,
+               .cdt        = 0x180540 + 64,
                .fifo_start = 0x183c00,
                .fifo_size  = 0x000800,
                .ptr1_reg   = MO_DMA23_PTR1,
@@ -346,7 +345,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "vbi",
                .cmds_start = 0x180100,
                .ctrl_start = 0x1805e0,
-               .cdt        = 0x1805e0 + 64,
+               .cdt        = 0x1805e0 + 64,
                .fifo_start = 0x184400,
                .fifo_size  = 0x001000,
                .ptr1_reg   = MO_DMA24_PTR1,
@@ -358,7 +357,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "audio from",
                .cmds_start = 0x180140,
                .ctrl_start = 0x180680,
-               .cdt        = 0x180680 + 64,
+               .cdt        = 0x180680 + 64,
                .fifo_start = 0x185400,
                .fifo_size  = 0x000200,
                .ptr1_reg   = MO_DMA25_PTR1,
@@ -370,7 +369,7 @@ struct sram_channel cx88_sram_channels[] = {
                .name       = "audio to",
                .cmds_start = 0x180180,
                .ctrl_start = 0x180720,
-               .cdt        = 0x180680 + 64,  /* same as audio IN */
+               .cdt        = 0x180680 + 64,  /* same as audio IN */
                .fifo_start = 0x185400,       /* same as audio IN */
                .fifo_size  = 0x000200,       /* same as audio IN */
                .ptr1_reg   = MO_DMA26_PTR1,
@@ -432,7 +431,7 @@ int cx88_sram_channel_setup(struct cx88_core *core,
 /* ------------------------------------------------------------------ */
 /* debug helper code                                                  */
 
-int cx88_risc_decode(u32 risc)
+static int cx88_risc_decode(u32 risc)
 {
        static char *instr[16] = {
                [ RISC_SYNC    >> 28 ] = "sync",
@@ -470,25 +469,6 @@ int cx88_risc_decode(u32 risc)
        return incr[risc >> 28] ? incr[risc >> 28] : 1;
 }
 
-#if 0 /* currently unused, but useful for debugging */
-void cx88_risc_disasm(struct cx88_core *core,
-                     struct btcx_riscmem *risc)
-{
-       unsigned int i,j,n;
-
-       printk("%s: risc disasm: %p [dma=0x%08lx]\n",
-              core->name, risc->cpu, (unsigned long)risc->dma);
-       for (i = 0; i < (risc->size >> 2); i += n) {
-               printk("%s:   %04d: ", core->name, i);
-               n = cx88_risc_decode(risc->cpu[i]);
-               for (j = 1; j < n; j++)
-                       printk("%s:   %04d: 0x%08x [ arg #%d ]\n",
-                              core->name, i+j, risc->cpu[i+j], j);
-               if (risc->cpu[i] == RISC_JUMP)
-                       break;
-       }
-}
-#endif
 
 void cx88_sram_channel_dump(struct cx88_core *core,
                            struct sram_channel *ch)
@@ -551,21 +531,6 @@ static char *cx88_pci_irqs[32] = {
        "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err",
        "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1"
 };
-char *cx88_vid_irqs[32] = {
-       "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
-       "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
-       "y_oflow",  "u_oflow",  "v_oflow",  "vbi_oflow",
-       "y_sync",   "u_sync",   "v_sync",   "vbi_sync",
-       "opc_err",  "par_err",  "rip_err",  "pci_abort",
-};
-char *cx88_mpeg_irqs[32] = {
-       "ts_risci1", NULL, NULL, NULL,
-       "ts_risci2", NULL, NULL, NULL,
-       "ts_oflow",  NULL, NULL, NULL,
-       "ts_sync",   NULL, NULL, NULL,
-       "opc_err", "par_err", "rip_err", "pci_abort",
-       "ts_err?",
-};
 
 void cx88_print_irqbits(char *name, char *tag, char **strings,
                        u32 bits, u32 mask)
@@ -615,16 +580,11 @@ void cx88_wakeup(struct cx88_core *core,
                        break;
                buf = list_entry(q->active.next,
                                 struct cx88_buffer, vb.queue);
-#if 0
-               if (buf->count > count)
-                       break;
-#else
                /* count comes from the hw and is is 16bit wide --
                 * this trick handles wrap-arounds correctly for
                 * up to 32767 buffers in flight... */
                if ((s16) (count - buf->count) < 0)
                        break;
-#endif
                do_gettimeofday(&buf->vb.ts);
                dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i,
                        count, buf->count);
@@ -877,6 +837,29 @@ static int set_pll(struct cx88_core *core, int prescale, u32 ofreq)
        return -1;
 }
 
+int cx88_start_audio_dma(struct cx88_core *core)
+{
+       /* setup fifo + format */
+       cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], 128, 0);
+       cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], 128, 0);
+
+       cx_write(MO_AUDD_LNGTH,    128); /* fifo bpl size */
+       cx_write(MO_AUDR_LNGTH,    128); /* fifo bpl size */
+
+       /* start dma */
+       cx_write(MO_AUD_DMACNTRL, 0x0003); /* Up and Down fifo enable */
+
+       return 0;
+}
+
+int cx88_stop_audio_dma(struct cx88_core *core)
+{
+       /* stop dma */
+       cx_write(MO_AUD_DMACNTRL, 0x0000);
+
+       return 0;
+}
+
 static int set_tvaudio(struct cx88_core *core)
 {
        struct cx88_tvnorm *norm = core->tvnorm;
@@ -885,19 +868,19 @@ static int set_tvaudio(struct cx88_core *core)
                return 0;
 
        if (V4L2_STD_PAL_BG & norm->id) {
-               core->tvaudio = nicam ? WW_NICAM_BGDKL : WW_A2_BG;
+               core->tvaudio = WW_BG;
 
        } else if (V4L2_STD_PAL_DK & norm->id) {
-               core->tvaudio = nicam ? WW_NICAM_BGDKL : WW_A2_DK;
+               core->tvaudio = WW_DK;
 
        } else if (V4L2_STD_PAL_I & norm->id) {
-               core->tvaudio = WW_NICAM_I;
+               core->tvaudio = WW_I;
 
        } else if (V4L2_STD_SECAM_L & norm->id) {
-               core->tvaudio = WW_SYSTEM_L_AM;
+               core->tvaudio = WW_L;
 
        } else if (V4L2_STD_SECAM_DK & norm->id) {
-               core->tvaudio = WW_A2_DK;
+               core->tvaudio = WW_DK;
 
        } else if ((V4L2_STD_NTSC_M & norm->id) ||
                   (V4L2_STD_PAL_M  & norm->id)) {
@@ -915,14 +898,18 @@ static int set_tvaudio(struct cx88_core *core)
 
        cx_andor(MO_AFECFG_IO, 0x1f, 0x0);
        cx88_set_tvaudio(core);
-       // cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO);
+       /* cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); */
 
-       cx_write(MO_AUDD_LNGTH,    128); /* fifo size */
-       cx_write(MO_AUDR_LNGTH,    128); /* fifo size */
-       cx_write(MO_AUD_DMACNTRL, 0x03); /* need audio fifo */
+/*
+   This should be needed only on cx88-alsa. It seems that some cx88 chips have
+   bugs and does require DMA enabled for it to work.
+ */
+       cx88_start_audio_dma(core);
        return 0;
 }
 
+
+
 int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
 {
        u32 fsc8;
@@ -952,12 +939,10 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
                norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
        cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat);
 
-#if 1
        // FIXME: as-is from DScaler
        dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
                norm->cxoformat, cx_read(MO_OUTPUT_FORMAT));
        cx_write(MO_OUTPUT_FORMAT, norm->cxoformat);
-#endif
 
        // MO_SCONV_REG = adc clock / video dec clock * 2^17
        tmp64  = adc_clock * (u64)(1 << 17);
@@ -1006,21 +991,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
        set_tvaudio(core);
 
        // tell i2c chips
-#ifdef V4L2_I2C_CLIENTS
        cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm->id);
-#else
-       {
-               struct video_channel c;
-               memset(&c,0,sizeof(c));
-               c.channel = core->input;
-               c.norm = VIDEO_MODE_PAL;
-               if ((norm->id & (V4L2_STD_NTSC_M|V4L2_STD_NTSC_M_JP)))
-                       c.norm = VIDEO_MODE_NTSC;
-               if (norm->id & V4L2_STD_SECAM)
-                       c.norm = VIDEO_MODE_SECAM;
-               cx88_call_i2c_clients(core,VIDIOCSCHAN,&c);
-       }
-#endif
 
        // done
        return 0;
@@ -1142,10 +1113,17 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
        core->pci_bus  = pci->bus->number;
        core->pci_slot = PCI_SLOT(pci->devfn);
        core->pci_irqmask = 0x00fc00;
+       init_MUTEX(&core->lock);
 
        core->nr = cx88_devcount++;
        sprintf(core->name,"cx88[%d]",core->nr);
        if (0 != get_ressources(core,pci)) {
+               printk(KERN_ERR "CORE %s No more PCI ressources for "
+                       "subsystem: %04x:%04x, board: %s\n",
+                       core->name,pci->subsystem_vendor,
+                       pci->subsystem_device,
+                       cx88_boards[core->board].name);
+
                cx88_devcount--;
                goto fail_free;
        }
@@ -1169,11 +1147,11 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
                core->board = CX88_BOARD_UNKNOWN;
                cx88_card_list(core,pci);
        }
-        printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
-              core->name,pci->subsystem_vendor,
-              pci->subsystem_device,cx88_boards[core->board].name,
-              core->board, card[core->nr] == core->board ?
-              "insmod option" : "autodetected");
+       printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
+               core->name,pci->subsystem_vendor,
+               pci->subsystem_device,cx88_boards[core->board].name,
+               core->board, card[core->nr] == core->board ?
+               "insmod option" : "autodetected");
 
        core->tuner_type = tuner[core->nr];
        core->radio_type = radio[core->nr];
@@ -1186,7 +1164,7 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
        if (!core->radio_addr)
                core->radio_addr = cx88_boards[core->board].radio_addr;
 
-        printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
+       printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
                core->tuner_type, core->tuner_addr<<1,
                core->radio_type, core->radio_addr<<1);
 
@@ -1195,6 +1173,7 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
        /* init hardware */
        cx88_reset(core);
        cx88_i2c_init(core,pci);
+       cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL);
        cx88_card_setup(core);
        cx88_ir_init(core,pci);
 
@@ -1230,8 +1209,6 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
 /* ------------------------------------------------------------------ */
 
 EXPORT_SYMBOL(cx88_print_ioctl);
-EXPORT_SYMBOL(cx88_vid_irqs);
-EXPORT_SYMBOL(cx88_mpeg_irqs);
 EXPORT_SYMBOL(cx88_print_irqbits);
 
 EXPORT_SYMBOL(cx88_core_irq);
@@ -1254,9 +1231,12 @@ EXPORT_SYMBOL(cx88_set_scale);
 EXPORT_SYMBOL(cx88_vdev_init);
 EXPORT_SYMBOL(cx88_core_get);
 EXPORT_SYMBOL(cx88_core_put);
+EXPORT_SYMBOL(cx88_start_audio_dma);
+EXPORT_SYMBOL(cx88_stop_audio_dma);
 
 /*
  * Local variables:
  * c-basic-offset: 8
  * End:
+ * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  */