V4L/DVB (12733): cx25821: some CodingStyle fixes

The original driver were generated with some dos editor, and used their
own coding style.

This patch does some automatic CodingStyle fixes, by running dos2unix
and Lindent tools.

More work still needs to be done for it to use upstream CodingStyle.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Mauro Carvalho Chehab 2009-09-13 11:30:11 -03:00
parent bb4c9a74b8
commit 1a9fc85564
35 changed files with 12292 additions and 12426 deletions

View File

@ -20,7 +20,6 @@
* *
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/device.h> #include <linux/device.h>
@ -37,7 +36,6 @@
#include <sound/initval.h> #include <sound/initval.h>
#include <sound/tlv.h> #include <sound/tlv.h>
#include "cx25821.h" #include "cx25821.h"
#include "cx25821-reg.h" #include "cx25821-reg.h"
@ -49,12 +47,10 @@
#define dprintk_core(level,fmt, arg...) if (debug >= level) \ #define dprintk_core(level,fmt, arg...) if (debug >= level) \
printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg) printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg)
/**************************************************************************** /****************************************************************************
Data type declarations - Can be moded to a header file later Data type declarations - Can be moded to a header file later
****************************************************************************/ ****************************************************************************/
static struct snd_card *snd_cx25821_cards[SNDRV_CARDS]; static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
static int devno; static int devno;
@ -87,7 +83,6 @@ struct cx25821_audio_dev {
typedef struct cx25821_audio_dev snd_cx25821_card_t; typedef struct cx25821_audio_dev snd_cx25821_card_t;
/**************************************************************************** /****************************************************************************
Module global static vars Module global static vars
****************************************************************************/ ****************************************************************************/
@ -102,7 +97,6 @@ MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
module_param_array(index, int, NULL, 0444); module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s)."); MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
/**************************************************************************** /****************************************************************************
Module macros Module macros
****************************************************************************/ ****************************************************************************/
@ -144,17 +138,20 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
{ {
struct cx25821_buffer *buf = chip->buf; struct cx25821_buffer *buf = chip->buf;
struct cx25821_dev *dev = chip->dev; struct cx25821_dev *dev = chip->dev;
struct sram_channel *audio_ch = &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]; struct sram_channel *audio_ch =
&cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
u32 tmp = 0; u32 tmp = 0;
// enable output on the GPIO 0 for the MCLK ADC (Audio) // enable output on the GPIO 0 for the MCLK ADC (Audio)
cx25821_set_gpiopin_direction(chip->dev, 0, 0); cx25821_set_gpiopin_direction(chip->dev, 0, 0);
/* Make sure RISC/FIFO are off before changing FIFO/RISC settings */ /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN ); cx_clear(AUD_INT_DMA_CTL,
FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
/* setup fifo + format - out channel */ /* setup fifo + format - out channel */
cx25821_sram_channel_setup_audio(chip->dev, audio_ch, buf->bpl, buf->risc.dma); cx25821_sram_channel_setup_audio(chip->dev, audio_ch, buf->bpl,
buf->risc.dma);
/* sets bpl size */ /* sets bpl size */
cx_write(AUD_A_LNGTH, buf->bpl); cx_write(AUD_A_LNGTH, buf->bpl);
@ -165,15 +162,18 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
//Set the input mode to 16-bit //Set the input mode to 16-bit
tmp = cx_read(AUD_A_CFG); tmp = cx_read(AUD_A_CFG);
cx_write(AUD_A_CFG, tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE | FLD_AUD_CLK_ENABLE); cx_write(AUD_A_CFG,
tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE |
FLD_AUD_CLK_ENABLE);
//printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d " //printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d "
// "byte buffer\n", buf->bpl, audio_ch->cmds_start, cx_read(audio_ch->cmds_start + 12)>>1, // "byte buffer\n", buf->bpl, audio_ch->cmds_start, cx_read(audio_ch->cmds_start + 12)>>1,
// chip->num_periods, buf->bpl * chip->num_periods); // chip->num_periods, buf->bpl * chip->num_periods);
/* Enables corresponding bits at AUD_INT_STAT */ /* Enables corresponding bits at AUD_INT_STAT */
cx_write(AUD_A_INT_MSK, FLD_AUD_DST_RISCI1 | FLD_AUD_DST_OF | FLD_AUD_DST_SYNC | FLD_AUD_DST_OPC_ERR ); cx_write(AUD_A_INT_MSK,
FLD_AUD_DST_RISCI1 | FLD_AUD_DST_OF | FLD_AUD_DST_SYNC |
FLD_AUD_DST_OPC_ERR);
/* Clean any pending interrupt bits already set */ /* Clean any pending interrupt bits already set */
cx_write(AUD_A_INT_STAT, ~0); cx_write(AUD_A_INT_STAT, ~0);
@ -183,7 +183,8 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
// Turn on audio downstream fifo and risc enable 0x101 // Turn on audio downstream fifo and risc enable 0x101
tmp = cx_read(AUD_INT_DMA_CTL); tmp = cx_read(AUD_INT_DMA_CTL);
cx_set(AUD_INT_DMA_CTL, tmp | (FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN) ); cx_set(AUD_INT_DMA_CTL,
tmp | (FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN));
mdelay(100); mdelay(100);
return 0; return 0;
@ -197,11 +198,14 @@ static int _cx25821_stop_audio_dma(snd_cx25821_card_t *chip)
struct cx25821_dev *dev = chip->dev; struct cx25821_dev *dev = chip->dev;
/* stop dma */ /* stop dma */
cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN ); cx_clear(AUD_INT_DMA_CTL,
FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
/* disable irqs */ /* disable irqs */
cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT); cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT);
cx_clear(AUD_A_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC | AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1); cx_clear(AUD_A_INT_MSK,
AUD_INT_OPC_ERR | AUD_INT_DN_SYNC | AUD_INT_DN_RISCI2 |
AUD_INT_DN_RISCI1);
return 0; return 0;
} }
@ -231,31 +235,35 @@ static void cx25821_aud_irq(snd_cx25821_card_t *chip, u32 status, u32 mask)
{ {
struct cx25821_dev *dev = chip->dev; struct cx25821_dev *dev = chip->dev;
if (0 == (status & mask)) if (0 == (status & mask)) {
{
return; return;
} }
cx_write(AUD_A_INT_STAT, status); cx_write(AUD_A_INT_STAT, status);
if (debug > 1 || (status & mask & ~0xff)) if (debug > 1 || (status & mask & ~0xff))
cx25821_print_irqbits(dev->name, "irq aud", cx25821_print_irqbits(dev->name, "irq aud",
cx25821_aud_irqs, ARRAY_SIZE(cx25821_aud_irqs), cx25821_aud_irqs,
status, mask); ARRAY_SIZE(cx25821_aud_irqs), status,
mask);
/* risc op code error */ /* risc op code error */
if (status & AUD_INT_OPC_ERR) { if (status & AUD_INT_OPC_ERR) {
printk(KERN_WARNING "WARNING %s/1: Audio risc op code error\n",dev->name); printk(KERN_WARNING "WARNING %s/1: Audio risc op code error\n",
dev->name);
cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN ); cx_clear(AUD_INT_DMA_CTL,
cx25821_sram_channel_dump_audio(dev, &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]); FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
cx25821_sram_channel_dump_audio(dev,
&cx25821_sram_channels
[AUDIO_SRAM_CHANNEL]);
} }
if (status & AUD_INT_DN_SYNC) { if (status & AUD_INT_DN_SYNC) {
printk(KERN_WARNING "WARNING %s: Downstream sync error!\n",dev->name); printk(KERN_WARNING "WARNING %s: Downstream sync error!\n",
dev->name);
cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET); cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
return; return;
} }
/* risc1 downstream */ /* risc1 downstream */
if (status & AUD_INT_DN_RISCI1) { if (status & AUD_INT_DN_RISCI1) {
atomic_set(&chip->count, cx_read(AUD_A_GPCNT)); atomic_set(&chip->count, cx_read(AUD_A_GPCNT));
@ -263,7 +271,6 @@ static void cx25821_aud_irq(snd_cx25821_card_t *chip, u32 status, u32 mask)
} }
} }
/* /*
* BOARD Specific: Handles IRQ calls * BOARD Specific: Handles IRQ calls
*/ */
@ -276,30 +283,26 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
int loop, handled = 0; int loop, handled = 0;
int audint_count = 0; int audint_count = 0;
audint_status = cx_read(AUD_A_INT_STAT); audint_status = cx_read(AUD_A_INT_STAT);
audint_mask = cx_read(AUD_A_INT_MSK); audint_mask = cx_read(AUD_A_INT_MSK);
audint_count = cx_read(AUD_A_GPCNT); audint_count = cx_read(AUD_A_GPCNT);
status = cx_read(PCI_INT_STAT); status = cx_read(PCI_INT_STAT);
for (loop = 0; loop < 1; loop++) for (loop = 0; loop < 1; loop++) {
{
status = cx_read(PCI_INT_STAT); status = cx_read(PCI_INT_STAT);
if (0 == status) if (0 == status) {
{
status = cx_read(PCI_INT_STAT); status = cx_read(PCI_INT_STAT);
audint_status = cx_read(AUD_A_INT_STAT); audint_status = cx_read(AUD_A_INT_STAT);
audint_mask = cx_read(AUD_A_INT_MSK); audint_mask = cx_read(AUD_A_INT_MSK);
if (status) if (status) {
{
handled = 1; handled = 1;
cx_write(PCI_INT_STAT, status); cx_write(PCI_INT_STAT, status);
cx25821_aud_irq(chip, audint_status, audint_mask); cx25821_aud_irq(chip, audint_status,
audint_mask);
break; break;
} } else
else
goto out; goto out;
} }
@ -318,7 +321,6 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
return IRQ_RETVAL(handled); return IRQ_RETVAL(handled);
} }
static int dsp_buffer_free(snd_cx25821_card_t * chip) static int dsp_buffer_free(snd_cx25821_card_t * chip)
{ {
BUG_ON(!chip->dma_size); BUG_ON(!chip->dma_size);
@ -346,8 +348,7 @@ static int dsp_buffer_free(snd_cx25821_card_t *chip)
static struct snd_pcm_hardware snd_cx25821_digital_hw = { static struct snd_pcm_hardware snd_cx25821_digital_hw = {
.info = SNDRV_PCM_INFO_MMAP | .info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID,
SNDRV_PCM_INFO_MMAP_VALID,
.formats = SNDRV_PCM_FMTBIT_S16_LE, .formats = SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_48000, .rates = SNDRV_PCM_RATE_48000,
@ -364,8 +365,6 @@ static struct snd_pcm_hardware snd_cx25821_digital_hw = {
.buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE), //128*128 = 16384 = 1024 * 16 .buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE), //128*128 = 16384 = 1024 * 16
}; };
/* /*
* audio pcm capture open callback * audio pcm capture open callback
*/ */
@ -382,7 +381,8 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
return -ENODEV; return -ENODEV;
} }
err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS); err =
snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS);
if (err < 0) if (err < 0)
goto _error; goto _error;
@ -390,13 +390,12 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
runtime->hw = snd_cx25821_digital_hw; runtime->hw = snd_cx25821_digital_hw;
if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size != DEFAULT_FIFO_SIZE) if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size !=
{ DEFAULT_FIFO_SIZE) {
bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3; //since there are 3 audio Clusters bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3; //since there are 3 audio Clusters
bpl &= ~7; /* must be multiple of 8 */ bpl &= ~7; /* must be multiple of 8 */
if( bpl > AUDIO_LINE_SIZE ) if (bpl > AUDIO_LINE_SIZE) {
{
bpl = AUDIO_LINE_SIZE; bpl = AUDIO_LINE_SIZE;
} }
runtime->hw.period_bytes_min = bpl; runtime->hw.period_bytes_min = bpl;
@ -434,7 +433,6 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
substream->runtime->dma_area = NULL; substream->runtime->dma_area = NULL;
} }
chip->period_size = params_period_bytes(hw_params); chip->period_size = params_period_bytes(hw_params);
chip->num_periods = params_periods(hw_params); chip->num_periods = params_periods(hw_params);
chip->dma_size = chip->period_size * params_periods(hw_params); chip->dma_size = chip->period_size * params_periods(hw_params);
@ -446,13 +444,10 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
if (NULL == buf) if (NULL == buf)
return -ENOMEM; return -ENOMEM;
if (chip->period_size > AUDIO_LINE_SIZE) {
if( chip->period_size > AUDIO_LINE_SIZE )
{
chip->period_size = AUDIO_LINE_SIZE; chip->period_size = AUDIO_LINE_SIZE;
} }
buf->vb.memory = V4L2_MEMORY_MMAP; buf->vb.memory = V4L2_MEMORY_MMAP;
buf->vb.field = V4L2_FIELD_NONE; buf->vb.field = V4L2_FIELD_NONE;
buf->vb.width = chip->period_size; buf->vb.width = chip->period_size;
@ -464,7 +459,8 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
videobuf_dma_init(dma); videobuf_dma_init(dma);
ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
(PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); (PAGE_ALIGN(buf->vb.size) >>
PAGE_SHIFT));
if (ret < 0) if (ret < 0)
goto error; goto error;
@ -472,15 +468,15 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
if (ret < 0) if (ret < 0)
goto error; goto error;
ret =
ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, buf->vb.width, buf->vb.height, 1); cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist,
if (ret < 0) buf->vb.width, buf->vb.height, 1);
{ if (ret < 0) {
printk(KERN_INFO "DEBUG: ERROR after cx25821_risc_databuffer_audio() \n"); printk(KERN_INFO
"DEBUG: ERROR after cx25821_risc_databuffer_audio() \n");
goto error; goto error;
} }
/* Loop back to start of program */ /* Loop back to start of program */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
@ -528,7 +524,8 @@ static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
/* /*
* trigger callback * trigger callback
*/ */
static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream, int cmd) static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream,
int cmd)
{ {
snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream); snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
int err = 0; int err = 0;
@ -536,8 +533,7 @@ static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream, int cmd
/* Local interrupts are already disabled by ALSA */ /* Local interrupts are already disabled by ALSA */
spin_lock(&chip->reg_lock); spin_lock(&chip->reg_lock);
switch (cmd) switch (cmd) {
{
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
err = _cx25821_start_audio_dma(chip); err = _cx25821_start_audio_dma(chip);
break; break;
@ -557,7 +553,8 @@ static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream, int cmd
/* /*
* pointer callback * pointer callback
*/ */
static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream
*substream)
{ {
snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream); snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
@ -594,7 +591,6 @@ static struct snd_pcm_ops snd_cx25821_pcm_ops = {
.page = snd_cx25821_page, .page = snd_cx25821_page,
}; };
/* /*
* ALSA create a PCM device: Called when initializing the board. Sets up the name and hooks up * ALSA create a PCM device: Called when initializing the board. Sets up the name and hooks up
* the callbacks * the callbacks
@ -605,9 +601,9 @@ static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
int err; int err;
err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm); err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
if (err < 0) if (err < 0) {
{ printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n",
printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n", __func__); __func__);
return err; return err;
} }
pcm->private_data = chip; pcm->private_data = chip;
@ -618,7 +614,6 @@ static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
return 0; return 0;
} }
/**************************************************************************** /****************************************************************************
Basic Flow for Sound Devices Basic Flow for Sound Devices
****************************************************************************/ ****************************************************************************/
@ -632,6 +627,7 @@ static struct pci_device_id cx25821_audio_pci_tbl[] __devinitdata = {
{0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{0,} {0,}
}; };
MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl); MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
/* /*
@ -662,7 +658,6 @@ static void snd_cx25821_dev_free(struct snd_card * card)
snd_card_free(chip->card); snd_card_free(chip->card);
} }
/* /*
* Alsa Constructor - Component probe * Alsa Constructor - Component probe
*/ */
@ -672,9 +667,9 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
snd_cx25821_card_t *chip; snd_cx25821_card_t *chip;
int err; int err;
if (devno >= SNDRV_CARDS) if (devno >= SNDRV_CARDS) {
{ printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n",
printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__); __func__);
return (-ENODEV); return (-ENODEV);
} }
@ -684,10 +679,13 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
return (-ENOENT); return (-ENOENT);
} }
card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx25821_card_t)); card =
if (!card) snd_card_new(index[devno], id[devno], THIS_MODULE,
{ sizeof(snd_cx25821_card_t));
printk(KERN_INFO "DEBUG ERROR: cannot create snd_card_new in %s\n", __func__); if (!card) {
printk(KERN_INFO
"DEBUG ERROR: cannot create snd_card_new in %s\n",
__func__);
return (-ENOMEM); return (-ENOMEM);
} }
@ -703,37 +701,38 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
chip->pci = dev->pci; chip->pci = dev->pci;
chip->iobase = pci_resource_start(dev->pci, 0); chip->iobase = pci_resource_start(dev->pci, 0);
chip->irq = dev->pci->irq; chip->irq = dev->pci->irq;
err = request_irq(dev->pci->irq, cx25821_irq, err = request_irq(dev->pci->irq, cx25821_irq,
IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip); IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip);
if (err < 0) { if (err < 0) {
printk(KERN_ERR "ERROR %s: can't get IRQ %d for ALSA\n", chip->dev->name, dev->pci->irq); printk(KERN_ERR "ERROR %s: can't get IRQ %d for ALSA\n",
chip->dev->name, dev->pci->irq);
goto error; goto error;
} }
if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0) {
if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0) printk(KERN_INFO
{ "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
printk(KERN_INFO "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n", __func__); __func__);
goto error; goto error;
} }
snd_card_set_dev(card, &chip->pci->dev); snd_card_set_dev(card, &chip->pci->dev);
strcpy(card->shortname, "cx25821"); strcpy(card->shortname, "cx25821");
sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name, chip->iobase, chip->irq); sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name,
chip->iobase, chip->irq);
strcpy(card->mixername, "CX25821"); strcpy(card->mixername, "CX25821");
printk(KERN_INFO "%s/%i: ALSA support for cx25821 boards\n", card->driver, devno); printk(KERN_INFO "%s/%i: ALSA support for cx25821 boards\n",
card->driver, devno);
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0) {
{ printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n",
printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n", __func__); __func__);
goto error; goto error;
} }
@ -747,7 +746,6 @@ error:
return err; return err;
} }
/**************************************************************************** /****************************************************************************
LINUX MODULE INIT LINUX MODULE INIT
****************************************************************************/ ****************************************************************************/
@ -774,7 +772,8 @@ static int cx25821_alsa_init(void)
} }
if (dev == NULL) if (dev == NULL)
printk(KERN_INFO "cx25821 ERROR ALSA: no cx25821 cards found\n"); printk(KERN_INFO
"cx25821 ERROR ALSA: no cx25821 cards found\n");
return 0; return 0;

View File

@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "cx25821-video.h" #include "cx25821-video.h"
#include "cx25821-audio-upstream.h" #include "cx25821-audio-upstream.h"
@ -35,14 +34,13 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int _intr_msk =
static int _intr_msk = FLD_AUD_SRC_RISCI1 | FLD_AUD_SRC_OF | FLD_AUD_SRC_SYNC | FLD_AUD_SRC_OPC_ERR; FLD_AUD_SRC_RISCI1 | FLD_AUD_SRC_OF | FLD_AUD_SRC_SYNC |
FLD_AUD_SRC_OPC_ERR;
int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev, int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
struct sram_channel *ch, struct sram_channel *ch,
@ -51,7 +49,6 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
unsigned int i, lines; unsigned int i, lines;
u32 cdt; u32 cdt;
if (ch->cmds_start == 0) { if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0); cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0); cx_write(ch->ptr2_reg, 0);
@ -64,14 +61,12 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
cdt = ch->cdt; cdt = ch->cdt;
lines = ch->fifo_size / bpl; lines = ch->fifo_size / bpl;
if (lines > 3) if (lines > 3) {
{
lines = 3; lines = 3;
} }
BUG_ON(lines < 2); BUG_ON(lines < 2);
/* write CDT */ /* write CDT */
for (i = 0; i < lines; i++) { for (i = 0; i < lines; i++) {
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i); cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
@ -103,27 +98,26 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
return 0; return 0;
} }
static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
static __le32 *cx25821_risc_field_upstream_audio( struct cx25821_dev *dev, __le32 *rp, __le32 * rp,
dma_addr_t databuf_phys_addr, dma_addr_t databuf_phys_addr,
unsigned int bpl, int fifo_enable) unsigned int bpl,
int fifo_enable)
{ {
unsigned int line; unsigned int line;
struct sram_channel *sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select]; struct sram_channel *sram_ch =
&dev->sram_channels[dev->_audio_upstream_channel_select];
int offset = 0; int offset = 0;
/* scan lines */ /* scan lines */
for (line = 0; line < LINES_PER_AUDIO_BUFFER; line++) for (line = 0; line < LINES_PER_AUDIO_BUFFER; line++) {
{
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset); *(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
// Check if we need to enable the FIFO after the first 3 lines // Check if we need to enable the FIFO after the first 3 lines
// For the upstream audio channel, the risc engine will enable the FIFO. // For the upstream audio channel, the risc engine will enable the FIFO.
if ( fifo_enable && line == 2 ) if (fifo_enable && line == 2) {
{
*(rp++) = RISC_WRITECR; *(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl; *(rp++) = sram_ch->dma_ctl;
*(rp++) = sram_ch->fld_aud_fifo_en; *(rp++) = sram_ch->fld_aud_fifo_en;
@ -148,108 +142,106 @@ int cx25821_risc_buffer_upstream_audio( struct cx25821_dev *dev,
int risc_flag = RISC_CNT_INC; int risc_flag = RISC_CNT_INC;
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
/* Virtual address of Risc buffer program */ /* Virtual address of Risc buffer program */
rp = dev->_risc_virt_addr; rp = dev->_risc_virt_addr;
/* sync instruction */ /* sync instruction */
*(rp++) = cpu_to_le32(RISC_RESYNC | AUDIO_SYNC_LINE); *(rp++) = cpu_to_le32(RISC_RESYNC | AUDIO_SYNC_LINE);
for (frame = 0; frame < NUM_AUDIO_FRAMES; frame++) {
for( frame = 0; frame < NUM_AUDIO_FRAMES; frame++ )
{
databuf_offset = frame_size * frame; databuf_offset = frame_size * frame;
if( frame == 0 ) if (frame == 0) {
{
fifo_enable = 1; fifo_enable = 1;
risc_flag = RISC_CNT_RESET; risc_flag = RISC_CNT_RESET;
} } else {
else
{
fifo_enable = 0; fifo_enable = 0;
risc_flag = RISC_CNT_INC; risc_flag = RISC_CNT_INC;
} }
//Calculate physical jump address //Calculate physical jump address
if( (frame+1) == NUM_AUDIO_FRAMES ) if ((frame + 1) == NUM_AUDIO_FRAMES) {
{ risc_phys_jump_addr =
risc_phys_jump_addr = dev->_risc_phys_start_addr + RISC_SYNC_INSTRUCTION_SIZE; dev->_risc_phys_start_addr +
} RISC_SYNC_INSTRUCTION_SIZE;
else } else {
{ risc_phys_jump_addr =
risc_phys_jump_addr = dev->_risc_phys_start_addr + RISC_SYNC_INSTRUCTION_SIZE + AUDIO_RISC_DMA_BUF_SIZE*(frame+1); dev->_risc_phys_start_addr +
RISC_SYNC_INSTRUCTION_SIZE +
AUDIO_RISC_DMA_BUF_SIZE * (frame + 1);
} }
rp = cx25821_risc_field_upstream_audio(dev, rp, dev->_audiodata_buf_phys_addr+databuf_offset, bpl, fifo_enable); rp = cx25821_risc_field_upstream_audio(dev, rp,
dev->
_audiodata_buf_phys_addr
+ databuf_offset, bpl,
fifo_enable);
if (USE_RISC_NOOP_AUDIO) {
if( USE_RISC_NOOP_AUDIO ) for (i = 0; i < NUM_NO_OPS; i++) {
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP); *(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
// Loop to (Nth)FrameRISC or to Start of Risc program & generate IRQ // Loop to (Nth)FrameRISC or to Start of Risc program & generate IRQ
*(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
*(rp++) = cpu_to_le32(risc_phys_jump_addr); *(rp++) = cpu_to_le32(risc_phys_jump_addr);
*(rp++) = cpu_to_le32(0); *(rp++) = cpu_to_le32(0);
//Recalculate virtual address based on frame index //Recalculate virtual address based on frame index
rp = dev->_risc_virt_addr + RISC_SYNC_INSTRUCTION_SIZE/4 + (AUDIO_RISC_DMA_BUF_SIZE*(frame+1)/4 ) ; rp = dev->_risc_virt_addr + RISC_SYNC_INSTRUCTION_SIZE / 4 +
(AUDIO_RISC_DMA_BUF_SIZE * (frame + 1) / 4);
} }
return 0; return 0;
} }
void cx25821_free_memory_audio(struct cx25821_dev *dev) void cx25821_free_memory_audio(struct cx25821_dev *dev)
{ {
if (dev->_risc_virt_addr) if (dev->_risc_virt_addr) {
{ pci_free_consistent(dev->pci, dev->_audiorisc_size,
pci_free_consistent(dev->pci, dev->_audiorisc_size, dev->_risc_virt_addr, dev->_risc_phys_addr); dev->_risc_virt_addr, dev->_risc_phys_addr);
dev->_risc_virt_addr = NULL; dev->_risc_virt_addr = NULL;
} }
if (dev->_audiodata_buf_virt_addr) if (dev->_audiodata_buf_virt_addr) {
{ pci_free_consistent(dev->pci, dev->_audiodata_buf_size,
pci_free_consistent(dev->pci, dev->_audiodata_buf_size, dev->_audiodata_buf_virt_addr, dev->_audiodata_buf_phys_addr); dev->_audiodata_buf_virt_addr,
dev->_audiodata_buf_phys_addr);
dev->_audiodata_buf_virt_addr = NULL; dev->_audiodata_buf_virt_addr = NULL;
} }
} }
void cx25821_stop_upstream_audio(struct cx25821_dev *dev) void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
{ {
struct sram_channel *sram_ch = &dev->sram_channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B]; struct sram_channel *sram_ch =
&dev->sram_channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B];
u32 tmp = 0; u32 tmp = 0;
if( !dev->_audio_is_running ) if (!dev->_audio_is_running) {
{ printk
printk("cx25821: No audio file is currently running so return!\n"); ("cx25821: No audio file is currently running so return!\n");
return; return;
} }
//Disable RISC interrupts //Disable RISC interrupts
cx_write(sram_ch->int_msk, 0); cx_write(sram_ch->int_msk, 0);
//Turn OFF risc and fifo enable in AUD_DMA_CNTRL //Turn OFF risc and fifo enable in AUD_DMA_CNTRL
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
cx_write( sram_ch->dma_ctl, tmp & ~(sram_ch->fld_aud_fifo_en | sram_ch->fld_aud_risc_en) ); cx_write(sram_ch->dma_ctl,
tmp & ~(sram_ch->fld_aud_fifo_en | sram_ch->fld_aud_risc_en));
//Clear data buffer memory //Clear data buffer memory
if (dev->_audiodata_buf_virt_addr) if (dev->_audiodata_buf_virt_addr)
memset( dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size ); memset(dev->_audiodata_buf_virt_addr, 0,
dev->_audiodata_buf_size);
dev->_audio_is_running = 0; dev->_audio_is_running = 0;
dev->_is_first_audio_frame = 0; dev->_is_first_audio_frame = 0;
dev->_audioframe_count = 0; dev->_audioframe_count = 0;
dev->_audiofile_status = END_OF_FILE; dev->_audiofile_status = END_OF_FILE;
if( dev->_irq_audio_queues ) if (dev->_irq_audio_queues) {
{
kfree(dev->_irq_audio_queues); kfree(dev->_irq_audio_queues);
dev->_irq_audio_queues = NULL; dev->_irq_audio_queues = NULL;
} }
@ -258,19 +250,17 @@ void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
kfree(dev->_audiofilename); kfree(dev->_audiofilename);
} }
void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev) void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev)
{ {
if( dev->_audio_is_running ) if (dev->_audio_is_running) {
{
cx25821_stop_upstream_audio(dev); cx25821_stop_upstream_audio(dev);
} }
cx25821_free_memory_audio(dev); cx25821_free_memory_audio(dev);
} }
int cx25821_get_audio_data(struct cx25821_dev *dev,
int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch ) struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int frame_index_temp = dev->_audioframe_index; int frame_index_temp = dev->_audioframe_index;
@ -284,32 +274,27 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
loff_t pos; loff_t pos;
mm_segment_t old_fs; mm_segment_t old_fs;
if (dev->_audiofile_status == END_OF_FILE) if (dev->_audiofile_status == END_OF_FILE)
return 0; return 0;
myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_audiofilename, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_audiofilename, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered!\n",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered!\n", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk("%s: File has no READ operations registered! \n",
{ __func__);
printk("%s: File has no READ operations registered! \n", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -318,25 +303,26 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (i = 0; i < dev->_audio_lines_count; i++) {
for( i = 0; i < dev->_audio_lines_count; i++ )
{
pos = file_offset; pos = file_offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if (vfs_read_retval > 0 && vfs_read_retval == line_size
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_audiodata_buf_virt_addr != NULL ) && dev->_audiodata_buf_virt_addr != NULL) {
{ memcpy((void *)(dev->_audiodata_buf_virt_addr +
memcpy( (void*)(dev->_audiodata_buf_virt_addr+frame_offset/4), mybuf, vfs_read_retval); frame_offset / 4), mybuf,
vfs_read_retval);
} }
file_offset += vfs_read_retval; file_offset += vfs_read_retval;
frame_offset += vfs_read_retval; frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Audio file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Audio file.\n",
__func__);
break; break;
} }
} }
@ -344,8 +330,8 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
if (i > 0) if (i > 0)
dev->_audioframe_count++; dev->_audioframe_count++;
dev->_audiofile_status = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; dev->_audiofile_status =
(vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
filp_close(myfile, NULL); filp_close(myfile, NULL);
@ -356,18 +342,22 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
static void cx25821_audioups_handler(struct work_struct *work) static void cx25821_audioups_handler(struct work_struct *work)
{ {
struct cx25821_dev *dev = container_of(work, struct cx25821_dev, _audio_work_entry); struct cx25821_dev *dev =
container_of(work, struct cx25821_dev, _audio_work_entry);
if( !dev ) if (!dev) {
{ printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ ); __func__);
return; return;
} }
cx25821_get_audio_data( dev, &dev->sram_channels[dev->_audio_upstream_channel_select] ); cx25821_get_audio_data(dev,
&dev->sram_channels[dev->
_audio_upstream_channel_select]);
} }
int cx25821_openfile_audio(struct cx25821_dev *dev, struct sram_channel *sram_ch) int cx25821_openfile_audio(struct cx25821_dev *dev,
struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int i = 0, j = 0; int i = 0, j = 0;
@ -378,29 +368,24 @@ int cx25821_openfile_audio(struct cx25821_dev *dev, struct sram_channel *sram_ch
loff_t offset = (unsigned long)0; loff_t offset = (unsigned long)0;
mm_segment_t old_fs; mm_segment_t old_fs;
myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_audiofilename, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_audiofilename, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered! \n",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered! \n", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk("%s: File has no READ operations registered! \n",
{ __func__);
printk("%s: File has no READ operations registered! \n", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -409,42 +394,43 @@ int cx25821_openfile_audio(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (j = 0; j < NUM_AUDIO_FRAMES; j++) {
for( j = 0; j < NUM_AUDIO_FRAMES; j++ ) for (i = 0; i < dev->_audio_lines_count; i++) {
{
for( i = 0; i < dev->_audio_lines_count; i++ )
{
pos = offset; pos = offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if (vfs_read_retval > 0
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_audiodata_buf_virt_addr != NULL ) && vfs_read_retval == line_size
{ && dev->_audiodata_buf_virt_addr != NULL) {
memcpy( (void*)(dev->_audiodata_buf_virt_addr+offset/4), mybuf, vfs_read_retval); memcpy((void *)(dev->
_audiodata_buf_virt_addr
+ offset / 4), mybuf,
vfs_read_retval);
} }
offset += vfs_read_retval; offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Audio file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Audio file.\n",
__func__);
break; break;
} }
} }
if( i > 0 ) if (i > 0) {
{
dev->_audioframe_count++; dev->_audioframe_count++;
} }
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{
break; break;
} }
} }
dev->_audiofile_status = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; dev->_audiofile_status =
(vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
myfile->f_pos = 0; myfile->f_pos = 0;
@ -462,51 +448,50 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
dma_addr_t dma_addr; dma_addr_t dma_addr;
dma_addr_t data_dma_addr; dma_addr_t data_dma_addr;
cx25821_free_memory_audio(dev); cx25821_free_memory_audio(dev);
dev->_risc_virt_addr = pci_alloc_consistent(dev->pci, dev->audio_upstream_riscbuf_size, &dma_addr); dev->_risc_virt_addr =
pci_alloc_consistent(dev->pci, dev->audio_upstream_riscbuf_size,
&dma_addr);
dev->_risc_virt_start_addr = dev->_risc_virt_addr; dev->_risc_virt_start_addr = dev->_risc_virt_addr;
dev->_risc_phys_start_addr = dma_addr; dev->_risc_phys_start_addr = dma_addr;
dev->_risc_phys_addr = dma_addr; dev->_risc_phys_addr = dma_addr;
dev->_audiorisc_size = dev->audio_upstream_riscbuf_size; dev->_audiorisc_size = dev->audio_upstream_riscbuf_size;
if (!dev->_risc_virt_addr) {
if (!dev->_risc_virt_addr) printk
{ ("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
printk("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
return -ENOMEM; return -ENOMEM;
} }
//Clear out memory at address //Clear out memory at address
memset(dev->_risc_virt_addr, 0, dev->_audiorisc_size); memset(dev->_risc_virt_addr, 0, dev->_audiorisc_size);
//For Audio Data buffer allocation //For Audio Data buffer allocation
dev->_audiodata_buf_virt_addr = pci_alloc_consistent(dev->pci, dev->audio_upstream_databuf_size, &data_dma_addr); dev->_audiodata_buf_virt_addr =
pci_alloc_consistent(dev->pci, dev->audio_upstream_databuf_size,
&data_dma_addr);
dev->_audiodata_buf_phys_addr = data_dma_addr; dev->_audiodata_buf_phys_addr = data_dma_addr;
dev->_audiodata_buf_size = dev->audio_upstream_databuf_size; dev->_audiodata_buf_size = dev->audio_upstream_databuf_size;
if (!dev->_audiodata_buf_virt_addr) if (!dev->_audiodata_buf_virt_addr) {
{ printk
printk("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning. \n"); ("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning. \n");
return -ENOMEM; return -ENOMEM;
} }
//Clear out memory at address //Clear out memory at address
memset(dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size); memset(dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size);
ret = cx25821_openfile_audio(dev, sram_ch); ret = cx25821_openfile_audio(dev, sram_ch);
if (ret < 0) if (ret < 0)
return ret; return ret;
//Creating RISC programs //Creating RISC programs
ret = cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl, dev->_audio_lines_count ); ret =
if (ret < 0) cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl,
{ dev->_audio_lines_count);
printk(KERN_DEBUG "cx25821 ERROR creating audio upstream RISC programs! \n"); if (ret < 0) {
printk(KERN_DEBUG
"cx25821 ERROR creating audio upstream RISC programs! \n");
goto error; goto error;
} }
@ -516,7 +501,8 @@ error:
return ret; return ret;
} }
int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status) int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
u32 status)
{ {
int i = 0; int i = 0;
u32 int_msk_tmp; u32 int_msk_tmp;
@ -524,9 +510,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
__le32 *rp; __le32 *rp;
if (status & FLD_AUD_SRC_RISCI1) {
if (status & FLD_AUD_SRC_RISCI1)
{
//Get interrupt_index of the program that interrupted //Get interrupt_index of the program that interrupted
u32 prog_cnt = cx_read(channel->gpcnt); u32 prog_cnt = cx_read(channel->gpcnt);
@ -536,74 +520,76 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
spin_lock(&dev->slock); spin_lock(&dev->slock);
while (prog_cnt != dev->_last_index_irq) {
while(prog_cnt != dev->_last_index_irq)
{
//Update _last_index_irq //Update _last_index_irq
if(dev->_last_index_irq < (NUMBER_OF_PROGRAMS-1)) if (dev->_last_index_irq < (NUMBER_OF_PROGRAMS - 1)) {
{
dev->_last_index_irq++; dev->_last_index_irq++;
} } else {
else
{
dev->_last_index_irq = 0; dev->_last_index_irq = 0;
} }
dev->_audioframe_index = dev->_last_index_irq; dev->_audioframe_index = dev->_last_index_irq;
queue_work(dev->_irq_audio_queues, &dev->_audio_work_entry); queue_work(dev->_irq_audio_queues,
&dev->_audio_work_entry);
} }
if (dev->_is_first_audio_frame) {
if ( dev->_is_first_audio_frame )
{
dev->_is_first_audio_frame = 0; dev->_is_first_audio_frame = 0;
if( dev->_risc_virt_start_addr != NULL ) if (dev->_risc_virt_start_addr != NULL) {
{ risc_phys_jump_addr =
risc_phys_jump_addr = dev->_risc_phys_start_addr + RISC_SYNC_INSTRUCTION_SIZE + AUDIO_RISC_DMA_BUF_SIZE; dev->_risc_phys_start_addr +
RISC_SYNC_INSTRUCTION_SIZE +
AUDIO_RISC_DMA_BUF_SIZE;
rp = cx25821_risc_field_upstream_audio(dev, dev->_risc_virt_start_addr+1, dev->_audiodata_buf_phys_addr, AUDIO_LINE_SIZE, FIFO_DISABLE); rp = cx25821_risc_field_upstream_audio(dev,
dev->
_risc_virt_start_addr
+ 1,
dev->
_audiodata_buf_phys_addr,
AUDIO_LINE_SIZE,
FIFO_DISABLE);
if( USE_RISC_NOOP_AUDIO ) if (USE_RISC_NOOP_AUDIO) {
{ for (i = 0; i < NUM_NO_OPS; i++) {
for( i = 0; i < NUM_NO_OPS; i++ ) *(rp++) =
{ cpu_to_le32(RISC_NOOP);
*(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
// Jump to 2nd Audio Frame // Jump to 2nd Audio Frame
*(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_RESET); *(rp++) =
cpu_to_le32(RISC_JUMP | RISC_IRQ1 |
RISC_CNT_RESET);
*(rp++) = cpu_to_le32(risc_phys_jump_addr); *(rp++) = cpu_to_le32(risc_phys_jump_addr);
*(rp++) = cpu_to_le32(0); *(rp++) = cpu_to_le32(0);
} }
} }
spin_unlock(&dev->slock); spin_unlock(&dev->slock);
} } else {
else
{
if (status & FLD_AUD_SRC_OF) if (status & FLD_AUD_SRC_OF)
printk("%s: Audio Received Overflow Error Interrupt!\n", __func__); printk("%s: Audio Received Overflow Error Interrupt!\n",
__func__);
if (status & FLD_AUD_SRC_SYNC) if (status & FLD_AUD_SRC_SYNC)
printk("%s: Audio Received Sync Error Interrupt!\n", __func__); printk("%s: Audio Received Sync Error Interrupt!\n",
__func__);
if (status & FLD_AUD_SRC_OPC_ERR) if (status & FLD_AUD_SRC_OPC_ERR)
printk("%s: Audio Received OpCode Error Interrupt!\n", __func__); printk("%s: Audio Received OpCode Error Interrupt!\n",
__func__);
// Read and write back the interrupt status register to clear our bits // Read and write back the interrupt status register to clear our bits
cx_write(channel->int_stat, cx_read(channel->int_stat)); cx_write(channel->int_stat, cx_read(channel->int_stat));
} }
if (dev->_audiofile_status == END_OF_FILE) {
if( dev->_audiofile_status == END_OF_FILE ) printk("cx25821: EOF Channel Audio Framecount = %d\n",
{ dev->_audioframe_count);
printk("cx25821: EOF Channel Audio Framecount = %d\n", dev->_audioframe_count );
return -1; return -1;
} }
//ElSE, set the interrupt mask register, re-enable irq. //ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read(channel->int_msk); int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
@ -618,43 +604,39 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
int handled = 0; int handled = 0;
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
if (!dev) if (!dev)
return -1; return -1;
sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select]; sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select];
msk_stat = cx_read(sram_ch->int_mstat); msk_stat = cx_read(sram_ch->int_mstat);
audio_status = cx_read(sram_ch->int_stat); audio_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt // Only deal with our interrupt
if(audio_status) if (audio_status) {
{ handled =
handled = cx25821_audio_upstream_irq(dev, dev->_audio_upstream_channel_select, audio_status); cx25821_audio_upstream_irq(dev,
dev->
_audio_upstream_channel_select,
audio_status);
} }
if (handled < 0) {
if( handled < 0 )
{
cx25821_stop_upstream_audio(dev); cx25821_stop_upstream_audio(dev);
} } else {
else
{
handled += handled; handled += handled;
} }
return IRQ_RETVAL(handled); return IRQ_RETVAL(handled);
} }
static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, struct sram_channel *sram_ch) struct sram_channel *sram_ch)
{ {
int count = 0; int count = 0;
u32 tmp; u32 tmp;
do do {
{
//Wait 10 microsecond before checking to see if the FIFO is turned ON. //Wait 10 microsecond before checking to see if the FIFO is turned ON.
udelay(10); udelay(10);
@ -662,7 +644,9 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, struct sram_channe
if (count++ > 1000) //10 millisecond timeout if (count++ > 1000) //10 millisecond timeout
{ {
printk("cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n", __func__); printk
("cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n",
__func__);
return; return;
} }
@ -670,19 +654,16 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, struct sram_channe
} }
int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev, int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
struct sram_channel *sram_ch) struct sram_channel *sram_ch)
{ {
u32 tmp = 0; u32 tmp = 0;
int err = 0; int err = 0;
// Set the physical start address of the RISC program in the initial program counter(IPC) member of the CMDS. // Set the physical start address of the RISC program in the initial program counter(IPC) member of the CMDS.
cx_write(sram_ch->cmds_start + 0, dev->_risc_phys_addr); cx_write(sram_ch->cmds_start + 0, dev->_risc_phys_addr);
cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */ cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
/* reset counter */ /* reset counter */
cx_write(sram_ch->gpcnt_ctl, 3); cx_write(sram_ch->gpcnt_ctl, 3);
@ -691,7 +672,9 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
//Set the input mode to 16-bit //Set the input mode to 16-bit
tmp = cx_read(sram_ch->aud_cfg); tmp = cx_read(sram_ch->aud_cfg);
tmp |= FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE | FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D | FLD_AUD_SONY_MODE; tmp |=
FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE |
FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D | FLD_AUD_SONY_MODE;
cx_write(sram_ch->aud_cfg, tmp); cx_write(sram_ch->aud_cfg, tmp);
// Read and write back the interrupt status register to clear it // Read and write back the interrupt status register to clear it
@ -701,21 +684,20 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
// Clear our bits from the interrupt status register. // Clear our bits from the interrupt status register.
cx_write(sram_ch->int_stat, _intr_msk); cx_write(sram_ch->int_stat, _intr_msk);
//Set the interrupt mask register, enable irq. //Set the interrupt mask register, enable irq.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read(sram_ch->int_msk); tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk); cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
err = request_irq(dev->pci->irq, cx25821_upstream_irq_audio, IRQF_SHARED | IRQF_DISABLED, dev->name, dev); request_irq(dev->pci->irq, cx25821_upstream_irq_audio,
if (err < 0) IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
{ if (err < 0) {
printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, dev->pci->irq); printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name,
dev->pci->irq);
goto fail_irq; goto fail_irq;
} }
// Start the DMA engine // Start the DMA engine
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en); cx_set(sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en);
@ -728,13 +710,11 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
return 0; return 0;
fail_irq: fail_irq:
cx25821_dev_unregister(dev); cx25821_dev_unregister(dev);
return err; return err;
} }
int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select) int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
{ {
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
@ -742,8 +722,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
int err = 0; int err = 0;
int str_length = 0; int str_length = 0;
if( dev->_audio_is_running ) if (dev->_audio_is_running) {
{
printk("Audio Channel is still running so return!\n"); printk("Audio Channel is still running so return!\n");
return 0; return 0;
} }
@ -753,15 +732,15 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
//Work queue //Work queue
INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler); INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler);
dev->_irq_audio_queues = create_singlethread_workqueue("cx25821_audioworkqueue"); dev->_irq_audio_queues =
create_singlethread_workqueue("cx25821_audioworkqueue");
if(!dev->_irq_audio_queues) if (!dev->_irq_audio_queues) {
{ printk
printk("cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n"); ("cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n");
return -ENOMEM; return -ENOMEM;
} }
dev->_last_index_irq = 0; dev->_last_index_irq = 0;
dev->_audio_is_running = 0; dev->_audio_is_running = 0;
dev->_audioframe_count = 0; dev->_audioframe_count = 0;
@ -769,27 +748,25 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER; dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER;
_line_size = AUDIO_LINE_SIZE; _line_size = AUDIO_LINE_SIZE;
if (dev->input_audiofilename) {
if( dev->input_audiofilename )
{
str_length = strlen(dev->input_audiofilename); str_length = strlen(dev->input_audiofilename);
dev->_audiofilename = (char *) kmalloc(str_length + 1, GFP_KERNEL); dev->_audiofilename =
(char *)kmalloc(str_length + 1, GFP_KERNEL);
if (!dev->_audiofilename) if (!dev->_audiofilename)
goto error; goto error;
memcpy(dev->_audiofilename, dev->input_audiofilename, str_length + 1); memcpy(dev->_audiofilename, dev->input_audiofilename,
str_length + 1);
//Default if filename is empty string //Default if filename is empty string
if( strcmp(dev->input_audiofilename,"") == 0) if (strcmp(dev->input_audiofilename, "") == 0) {
{
dev->_audiofilename = "/root/audioGOOD.wav"; dev->_audiofilename = "/root/audioGOOD.wav";
} }
} } else {
else
{
str_length = strlen(_defaultAudioName); str_length = strlen(_defaultAudioName);
dev->_audiofilename = (char *) kmalloc(str_length + 1, GFP_KERNEL); dev->_audiofilename =
(char *)kmalloc(str_length + 1, GFP_KERNEL);
if (!dev->_audiofilename) if (!dev->_audiofilename)
goto error; goto error;
@ -797,21 +774,24 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
memcpy(dev->_audiofilename, _defaultAudioName, str_length + 1); memcpy(dev->_audiofilename, _defaultAudioName, str_length + 1);
} }
retval =
cx25821_sram_channel_setup_upstream_audio(dev, sram_ch, _line_size,
0);
retval = cx25821_sram_channel_setup_upstream_audio(dev, sram_ch, _line_size, 0); dev->audio_upstream_riscbuf_size =
AUDIO_RISC_DMA_BUF_SIZE * NUM_AUDIO_PROGS +
dev->audio_upstream_riscbuf_size = AUDIO_RISC_DMA_BUF_SIZE * NUM_AUDIO_PROGS + RISC_SYNC_INSTRUCTION_SIZE; RISC_SYNC_INSTRUCTION_SIZE;
dev->audio_upstream_databuf_size = AUDIO_DATA_BUF_SZ * NUM_AUDIO_PROGS; dev->audio_upstream_databuf_size = AUDIO_DATA_BUF_SZ * NUM_AUDIO_PROGS;
//Allocating buffers and prepare RISC program //Allocating buffers and prepare RISC program
retval = cx25821_audio_upstream_buffer_prepare(dev, sram_ch, _line_size); retval =
if (retval < 0) cx25821_audio_upstream_buffer_prepare(dev, sram_ch, _line_size);
{ if (retval < 0) {
printk(KERN_ERR "%s: Failed to set up Audio upstream buffers!\n", dev->name); printk(KERN_ERR
"%s: Failed to set up Audio upstream buffers!\n",
dev->name);
goto error; goto error;
} }
//Start RISC engine //Start RISC engine
cx25821_start_audio_dma_upstream(dev, sram_ch); cx25821_start_audio_dma_upstream(dev, sram_ch);

View File

@ -23,7 +23,6 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#define NUM_AUDIO_PROGS 8 #define NUM_AUDIO_PROGS 8
#define NUM_AUDIO_FRAMES 8 #define NUM_AUDIO_FRAMES 8
#define END_OF_FILE 0 #define END_OF_FILE 0
@ -33,7 +32,6 @@
#define FIFO_ENABLE 1 #define FIFO_ENABLE 1
#define NUM_NO_OPS 4 #define NUM_NO_OPS 4
#define RISC_READ_INSTRUCTION_SIZE 12 #define RISC_READ_INSTRUCTION_SIZE 12
#define RISC_JUMP_INSTRUCTION_SIZE 12 #define RISC_JUMP_INSTRUCTION_SIZE 12
#define RISC_WRITECR_INSTRUCTION_SIZE 16 #define RISC_WRITECR_INSTRUCTION_SIZE 16
@ -41,7 +39,6 @@
#define DWORD_SIZE 4 #define DWORD_SIZE 4
#define AUDIO_SYNC_LINE 4 #define AUDIO_SYNC_LINE 4
#define LINES_PER_AUDIO_BUFFER 15 #define LINES_PER_AUDIO_BUFFER 15
#define AUDIO_LINE_SIZE 128 #define AUDIO_LINE_SIZE 128
#define AUDIO_DATA_BUF_SZ (AUDIO_LINE_SIZE * LINES_PER_AUDIO_BUFFER) #define AUDIO_DATA_BUF_SZ (AUDIO_LINE_SIZE * LINES_PER_AUDIO_BUFFER)
@ -52,11 +49,9 @@
#define AUDIO_RISC_DMA_BUF_SIZE ( LINES_PER_AUDIO_BUFFER*RISC_READ_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + NUM_NO_OPS*DWORD_SIZE + RISC_JUMP_INSTRUCTION_SIZE) #define AUDIO_RISC_DMA_BUF_SIZE ( LINES_PER_AUDIO_BUFFER*RISC_READ_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + NUM_NO_OPS*DWORD_SIZE + RISC_JUMP_INSTRUCTION_SIZE)
#endif #endif
#ifndef USE_RISC_NOOP_AUDIO #ifndef USE_RISC_NOOP_AUDIO
#define AUDIO_RISC_DMA_BUF_SIZE ( LINES_PER_AUDIO_BUFFER*RISC_READ_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + RISC_JUMP_INSTRUCTION_SIZE) #define AUDIO_RISC_DMA_BUF_SIZE ( LINES_PER_AUDIO_BUFFER*RISC_READ_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + RISC_JUMP_INSTRUCTION_SIZE)
#endif #endif
static int _line_size; static int _line_size;
char *_defaultAudioName = "/root/audioGOOD.wav"; char *_defaultAudioName = "/root/audioGOOD.wav";

View File

@ -23,7 +23,6 @@
#ifndef __CX25821_AUDIO_H__ #ifndef __CX25821_AUDIO_H__
#define __CX25821_AUDIO_H__ #define __CX25821_AUDIO_H__
#define USE_RISC_NOOP 1 #define USE_RISC_NOOP 1
#define LINES_PER_BUFFER 15 #define LINES_PER_BUFFER 15
#define AUDIO_LINE_SIZE 128 #define AUDIO_LINE_SIZE 128
@ -45,7 +44,6 @@
(2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4) (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4)
#endif #endif
//Sizes of various instructions in bytes. Used when adding instructions. //Sizes of various instructions in bytes. Used when adding instructions.
#define RISC_WRITE_INSTRUCTION_SIZE 12 #define RISC_WRITE_INSTRUCTION_SIZE 12
#define RISC_JUMP_INSTRUCTION_SIZE 12 #define RISC_JUMP_INSTRUCTION_SIZE 12
@ -57,4 +55,3 @@
#define MAX_AUDIO_DMA_BUFFER_SIZE (MAX_BUFFER_PROGRAM_SIZE * NUMBER_OF_PROGRAMS + RISC_SYNC_INSTRUCTION_SIZE) #define MAX_AUDIO_DMA_BUFFER_SIZE (MAX_BUFFER_PROGRAM_SIZE * NUMBER_OF_PROGRAMS + RISC_SYNC_INSTRUCTION_SIZE)
#endif #endif

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH11]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH11]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -97,12 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0; enum v4l2_buf_type type = 0;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH11] && h->video_dev[SRAM_CH11]->minor == minor) if (h->video_dev[SRAM_CH11]
{ && h->video_dev[SRAM_CH11]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -141,8 +144,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -150,17 +152,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO11)) if (res_locked(fh->dev, RESOURCE_VIDEO11))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -168,7 +171,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -192,7 +196,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO11)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO11)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -265,15 +264,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -288,35 +286,35 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
} }
static long video_ioctl_upstream11(struct file *file, unsigned int cmd, unsigned long arg) static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
unsigned long arg)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
int command = 0; int command = 0;
struct upstream_user_struct *data_from_user; struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg; data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user ) if (!data_from_user) {
{ printk
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__); ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0; return 0;
} }
command = data_from_user->command; command = data_from_user->command;
if( command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO ) if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) {
{
return 0; return 0;
} }
dev->input_filename = data_from_user->input_filename; dev->input_filename = data_from_user->input_filename;
dev->input_audiofilename = data_from_user->input_filename; dev->input_audiofilename = data_from_user->input_filename;
dev->vid_stdname = data_from_user->vid_stdname; dev->vid_stdname = data_from_user->vid_stdname;
@ -324,9 +322,7 @@ static long video_ioctl_upstream11(struct file *file, unsigned int cmd, unsigned
dev->channel_select = data_from_user->channel_select; dev->channel_select = data_from_user->channel_select;
dev->command = data_from_user->command; dev->command = data_from_user->command;
switch (command) {
switch(command)
{
case UPSTREAM_START_AUDIO: case UPSTREAM_START_AUDIO:
cx25821_start_upstream_audio(dev, data_from_user); cx25821_start_upstream_audio(dev, data_from_user);
break; break;
@ -366,14 +362,14 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
} }
return 0; return 0;
} }
// exported stuff // exported stuff
static const struct v4l2_file_operations video_fops = { static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -436,6 +432,3 @@ struct video_device cx25821_video_template11 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -58,15 +58,13 @@ struct cx25821_subid cx25821_subids[]={
}, },
}; };
void cx25821_card_setup(struct cx25821_dev *dev) void cx25821_card_setup(struct cx25821_dev *dev)
{ {
static u8 eeprom[256]; static u8 eeprom[256];
if (dev->i2c_bus[0].i2c_rc == 0) if (dev->i2c_bus[0].i2c_rc == 0) {
{
dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom)); tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
sizeof(eeprom));
} }
} }

View File

@ -40,13 +40,11 @@ static unsigned int card[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
module_param_array(card, int, NULL, 0444); module_param_array(card, int, NULL, 0444);
MODULE_PARM_DESC(card, "card type"); MODULE_PARM_DESC(card, "card type");
static unsigned int cx25821_devcount = 0; static unsigned int cx25821_devcount = 0;
static DEFINE_MUTEX(devlist); static DEFINE_MUTEX(devlist);
LIST_HEAD(cx25821_devlist); LIST_HEAD(cx25821_devlist);
struct sram_channel cx25821_sram_channels[] = { struct sram_channel cx25821_sram_channels[] = {
[SRAM_CH00] = { [SRAM_CH00] = {
.i = SRAM_CH00, .i = SRAM_CH00,
@ -289,7 +287,6 @@ struct sram_channel cx25821_sram_channels[] = {
.irq_bit = 9, .irq_bit = 9,
}, },
[SRAM_CH11] = { [SRAM_CH11] = {
.i = SRAM_CH11, .i = SRAM_CH11,
.name = "Audio Upstream Channel B", .name = "Audio Upstream Channel B",
@ -316,7 +313,6 @@ struct sram_channel cx25821_sram_channels[] = {
}, },
}; };
struct sram_channel *channel0 = &cx25821_sram_channels[SRAM_CH00]; struct sram_channel *channel0 = &cx25821_sram_channels[SRAM_CH00];
struct sram_channel *channel1 = &cx25821_sram_channels[SRAM_CH01]; struct sram_channel *channel1 = &cx25821_sram_channels[SRAM_CH01];
struct sram_channel *channel2 = &cx25821_sram_channels[SRAM_CH02]; struct sram_channel *channel2 = &cx25821_sram_channels[SRAM_CH02];
@ -362,9 +358,9 @@ static int cx25821_risc_decode(u32 risc)
}; };
int i; int i;
printk("0x%08x [ %s", risc, instr[risc >> 28] ? instr[risc >> 28] : "INVALID"); printk("0x%08x [ %s", risc,
for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--) instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
{ for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--) {
if (risc & (1 << (i + 12))) if (risc & (1 << (i + 12)))
printk(" %s", bits[i]); printk(" %s", bits[i]);
} }
@ -379,7 +375,6 @@ static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
return cx_read(bus->reg_stat) & 0x01; return cx_read(bus->reg_stat) & 0x01;
} }
void cx_i2c_read_print(struct cx25821_dev *dev, u32 reg, const char *reg_string) void cx_i2c_read_print(struct cx25821_dev *dev, u32 reg, const char *reg_string)
{ {
int tmp = 0; int tmp = 0;
@ -443,19 +438,16 @@ static void cx25821_registers_init(struct cx25821_dev *dev)
tmp = cx_read(PLL_D_INT_FRAC); tmp = cx_read(PLL_D_INT_FRAC);
cx_write(PLL_D_INT_FRAC, tmp & 0x7FFFFFFF); cx_write(PLL_D_INT_FRAC, tmp & 0x7FFFFFFF);
// This selects the PLL C clock source for the video upstream channel I and J // This selects the PLL C clock source for the video upstream channel I and J
tmp = cx_read(VID_CH_CLK_SEL); tmp = cx_read(VID_CH_CLK_SEL);
cx_write(VID_CH_CLK_SEL, (tmp & 0x00FFFFFF) | 0x24000000); cx_write(VID_CH_CLK_SEL, (tmp & 0x00FFFFFF) | 0x24000000);
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
//select 656/VIP DST for downstream Channel A - C //select 656/VIP DST for downstream Channel A - C
tmp = cx_read(VID_CH_MODE_SEL); tmp = cx_read(VID_CH_MODE_SEL);
//cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF); //cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
// enables 656 port I and J as output // enables 656 port I and J as output
tmp = cx_read(CLK_RST); tmp = cx_read(CLK_RST);
tmp |= FLD_USE_ALT_PLL_REF; // use external ALT_PLL_REF pin as its reference clock instead tmp |= FLD_USE_ALT_PLL_REF; // use external ALT_PLL_REF pin as its reference clock instead
@ -464,7 +456,6 @@ static void cx25821_registers_init(struct cx25821_dev *dev)
mdelay(100); mdelay(100);
} }
int cx25821_sram_channel_setup(struct cx25821_dev *dev, int cx25821_sram_channel_setup(struct cx25821_dev *dev,
struct sram_channel *ch, struct sram_channel *ch,
unsigned int bpl, u32 risc) unsigned int bpl, u32 risc)
@ -484,8 +475,7 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
cdt = ch->cdt; cdt = ch->cdt;
lines = ch->fifo_size / bpl; lines = ch->fifo_size / bpl;
if (lines > 4) if (lines > 4) {
{
lines = 4; lines = 4;
} }
@ -508,12 +498,9 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
cx_write(ch->fifo_start + 4 * i, i); cx_write(ch->fifo_start + 4 * i, i);
/* write CMDS */ /* write CMDS */
if (ch->jumponly) if (ch->jumponly) {
{
cx_write(ch->cmds_start + 0, 8); cx_write(ch->cmds_start + 0, 8);
} } else {
else
{
cx_write(ch->cmds_start + 0, risc); cx_write(ch->cmds_start + 0, risc);
} }
@ -546,7 +533,6 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
unsigned int i, lines; unsigned int i, lines;
u32 cdt; u32 cdt;
if (ch->cmds_start == 0) { if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0); cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0); cx_write(ch->ptr2_reg, 0);
@ -559,14 +545,12 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
cdt = ch->cdt; cdt = ch->cdt;
lines = ch->fifo_size / bpl; lines = ch->fifo_size / bpl;
if (lines > 3) if (lines > 3) {
{
lines = 3; //for AUDIO lines = 3; //for AUDIO
} }
BUG_ON(lines < 2); BUG_ON(lines < 2);
cx_write(8 + 0, RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); cx_write(8 + 0, RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
cx_write(8 + 4, 8); cx_write(8 + 4, 8);
cx_write(8 + 8, 0); cx_write(8 + 8, 0);
@ -580,12 +564,9 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
} }
/* write CMDS */ /* write CMDS */
if (ch->jumponly) if (ch->jumponly) {
{
cx_write(ch->cmds_start + 0, 8); cx_write(ch->cmds_start + 0, 8);
} } else {
else
{
cx_write(ch->cmds_start + 0, risc); cx_write(ch->cmds_start + 0, risc);
} }
@ -595,12 +576,9 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
cx_write(ch->cmds_start + 16, ch->ctrl_start); cx_write(ch->cmds_start + 16, ch->ctrl_start);
//IQ size //IQ size
if (ch->jumponly) if (ch->jumponly) {
{
cx_write(ch->cmds_start + 20, 0x80000000 | (64 >> 2)); cx_write(ch->cmds_start + 20, 0x80000000 | (64 >> 2));
} } else {
else
{
cx_write(ch->cmds_start + 20, 64 >> 2); cx_write(ch->cmds_start + 20, 64 >> 2);
} }
@ -617,7 +595,6 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
return 0; return 0;
} }
void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch) void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
{ {
static char *name[] = { static char *name[] = {
@ -639,10 +616,11 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
u32 risc; u32 risc;
unsigned int i, j, n; unsigned int i, j, n;
printk(KERN_WARNING "%s: %s - dma channel status dump\n", dev->name, ch->name); printk(KERN_WARNING "%s: %s - dma channel status dump\n", dev->name,
ch->name);
for (i = 0; i < ARRAY_SIZE(name); i++) for (i = 0; i < ARRAY_SIZE(name); i++)
printk(KERN_WARNING "cmds + 0x%2x: %-15s: 0x%08x\n", i*4, name[i], printk(KERN_WARNING "cmds + 0x%2x: %-15s: 0x%08x\n", i * 4,
cx_read(ch->cmds_start + 4*i)); name[i], cx_read(ch->cmds_start + 4 * i));
j = i * 4; j = i * 4;
for (i = 0; i < 4;) { for (i = 0; i < 4;) {
@ -655,23 +633,33 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
risc = cx_read(ch->ctrl_start + 4 * i); risc = cx_read(ch->ctrl_start + 4 * i);
/* No consideration for bits 63-32 */ /* No consideration for bits 63-32 */
printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i*4, ch->ctrl_start + 4 * i, i); printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i * 4,
ch->ctrl_start + 4 * i, i);
n = cx25821_risc_decode(risc); n = cx25821_risc_decode(risc);
for (j = 1; j < n; j++) { for (j = 1; j < n; j++) {
risc = cx_read(ch->ctrl_start + 4 * (i + j)); risc = cx_read(ch->ctrl_start + 4 * (i + j));
printk(KERN_WARNING "ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n", 4*(i+j), i+j, risc, j); printk(KERN_WARNING
"ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
4 * (i + j), i + j, risc, j);
} }
} }
printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n", ch->fifo_start, ch->fifo_start+ch->fifo_size); printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n",
printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n", ch->ctrl_start, ch->ctrl_start + 6*16); ch->fifo_start, ch->fifo_start + ch->fifo_size);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", cx_read(ch->ptr1_reg)); printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n",
printk(KERN_WARNING " : ptr2_reg: 0x%08x\n", cx_read(ch->ptr2_reg)); ch->ctrl_start, ch->ctrl_start + 6 * 16);
printk(KERN_WARNING " : cnt1_reg: 0x%08x\n", cx_read(ch->cnt1_reg)); printk(KERN_WARNING " : ptr1_reg: 0x%08x\n",
printk(KERN_WARNING " : cnt2_reg: 0x%08x\n", cx_read(ch->cnt2_reg)); cx_read(ch->ptr1_reg));
printk(KERN_WARNING " : ptr2_reg: 0x%08x\n",
cx_read(ch->ptr2_reg));
printk(KERN_WARNING " : cnt1_reg: 0x%08x\n",
cx_read(ch->cnt1_reg));
printk(KERN_WARNING " : cnt2_reg: 0x%08x\n",
cx_read(ch->cnt2_reg));
} }
void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channel *ch) void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
struct sram_channel *ch)
{ {
static char *name[] = { static char *name[] = {
"init risc lo", "init risc lo",
@ -693,12 +681,13 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channe
u32 risc, value, tmp; u32 risc, value, tmp;
unsigned int i, j, n; unsigned int i, j, n;
printk(KERN_INFO "\n%s: %s - dma Audio channel status dump\n",
printk(KERN_INFO "\n%s: %s - dma Audio channel status dump\n", dev->name, ch->name); dev->name, ch->name);
for (i = 0; i < ARRAY_SIZE(name); i++) for (i = 0; i < ARRAY_SIZE(name); i++)
printk(KERN_INFO "%s: cmds + 0x%2x: %-15s: 0x%08x\n", dev->name, i*4, name[i], cx_read(ch->cmds_start + 4*i)); printk(KERN_INFO "%s: cmds + 0x%2x: %-15s: 0x%08x\n",
dev->name, i * 4, name[i],
cx_read(ch->cmds_start + 4 * i));
j = i * 4; j = i * 4;
for (i = 0; i < 4;) { for (i = 0; i < 4;) {
@ -711,24 +700,32 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channe
risc = cx_read(ch->ctrl_start + 4 * i); risc = cx_read(ch->ctrl_start + 4 * i);
/* No consideration for bits 63-32 */ /* No consideration for bits 63-32 */
printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i*4, ch->ctrl_start + 4 * i, i); printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i * 4,
ch->ctrl_start + 4 * i, i);
n = cx25821_risc_decode(risc); n = cx25821_risc_decode(risc);
for (j = 1; j < n; j++) { for (j = 1; j < n; j++) {
risc = cx_read(ch->ctrl_start + 4 * (i + j)); risc = cx_read(ch->ctrl_start + 4 * (i + j));
printk(KERN_WARNING "ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n", 4*(i+j), i+j, risc, j); printk(KERN_WARNING
"ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
4 * (i + j), i + j, risc, j);
} }
} }
printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n", ch->fifo_start, ch->fifo_start+ch->fifo_size); printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n",
printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n", ch->ctrl_start, ch->ctrl_start + 6*16); ch->fifo_start, ch->fifo_start + ch->fifo_size);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", cx_read(ch->ptr1_reg)); printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n",
printk(KERN_WARNING " : ptr2_reg: 0x%08x\n", cx_read(ch->ptr2_reg)); ch->ctrl_start, ch->ctrl_start + 6 * 16);
printk(KERN_WARNING " : cnt1_reg: 0x%08x\n", cx_read(ch->cnt1_reg)); printk(KERN_WARNING " : ptr1_reg: 0x%08x\n",
printk(KERN_WARNING " : cnt2_reg: 0x%08x\n", cx_read(ch->cnt2_reg)); cx_read(ch->ptr1_reg));
printk(KERN_WARNING " : ptr2_reg: 0x%08x\n",
cx_read(ch->ptr2_reg));
printk(KERN_WARNING " : cnt1_reg: 0x%08x\n",
cx_read(ch->cnt1_reg));
printk(KERN_WARNING " : cnt2_reg: 0x%08x\n",
cx_read(ch->cnt2_reg));
for( i=0; i < 4; i++) for (i = 0; i < 4; i++) {
{
risc = cx_read(ch->cmds_start + 56 + (i * 4)); risc = cx_read(ch->cmds_start + 56 + (i * 4));
printk(KERN_WARNING "instruction %d = 0x%x\n", i, risc); printk(KERN_WARNING "instruction %d = 0x%x\n", i, risc);
} }
@ -736,14 +733,12 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channe
//read data from the first cdt buffer //read data from the first cdt buffer
risc = cx_read(AUD_A_CDT); risc = cx_read(AUD_A_CDT);
printk(KERN_WARNING "\nread cdt loc=0x%x\n", risc); printk(KERN_WARNING "\nread cdt loc=0x%x\n", risc);
for(i=0; i<8; i++) for (i = 0; i < 8; i++) {
{
n = cx_read(risc + i * 4); n = cx_read(risc + i * 4);
printk(KERN_WARNING "0x%x ", n); printk(KERN_WARNING "0x%x ", n);
} }
printk(KERN_WARNING "\n\n"); printk(KERN_WARNING "\n\n");
value = cx_read(CLK_RST); value = cx_read(CLK_RST);
CX25821_INFO(" CLK_RST = 0x%x \n\n", value); CX25821_INFO(" CLK_RST = 0x%x \n\n", value);
@ -779,14 +774,13 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
cx_write(DEV_CNTRL2, 0); cx_write(DEV_CNTRL2, 0);
/* Disable Video A/B activity */ /* Disable Video A/B activity */
for(i=0; i<VID_CHANNEL_NUM; i++) for (i = 0; i < VID_CHANNEL_NUM; i++) {
{
cx_write(dev->sram_channels[i].dma_ctl, 0); cx_write(dev->sram_channels[i].dma_ctl, 0);
cx_write(dev->sram_channels[i].int_msk, 0); cx_write(dev->sram_channels[i].int_msk, 0);
} }
for( i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; i++) for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
{ i++) {
cx_write(dev->sram_channels[i].dma_ctl, 0); cx_write(dev->sram_channels[i].dma_ctl, 0);
cx_write(dev->sram_channels[i].int_msk, 0); cx_write(dev->sram_channels[i].int_msk, 0);
} }
@ -802,19 +796,20 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
cx_write(AUD_A_INT_MSK, 0); cx_write(AUD_A_INT_MSK, 0);
} }
void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select, u32 format) void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select,
u32 format)
{ {
struct sram_channel *ch; struct sram_channel *ch;
if( channel_select <= 7 && channel_select >= 0 ) if (channel_select <= 7 && channel_select >= 0) {
{
ch = &cx25821_sram_channels[channel_select]; ch = &cx25821_sram_channels[channel_select];
cx_write(ch->pix_frmt, format); cx_write(ch->pix_frmt, format);
dev->pixel_formats[channel_select] = format; dev->pixel_formats[channel_select] = format;
} }
} }
static void cx25821_set_vip_mode(struct cx25821_dev *dev, struct sram_channel *ch) static void cx25821_set_vip_mode(struct cx25821_dev *dev,
struct sram_channel *ch)
{ {
cx_write(ch->pix_frmt, PIXEL_FRMT_422); cx_write(ch->pix_frmt, PIXEL_FRMT_422);
cx_write(ch->vip_ctl, PIXEL_ENGINE_VIP1); cx_write(ch->vip_ctl, PIXEL_ENGINE_VIP1);
@ -832,7 +827,6 @@ static void cx25821_initialize(struct cx25821_dev *dev)
for (i = 0; i < VID_CHANNEL_NUM; i++) for (i = 0; i < VID_CHANNEL_NUM; i++)
cx_write(dev->sram_channels[i].int_stat, 0xffffffff); cx_write(dev->sram_channels[i].int_stat, 0xffffffff);
cx_write(AUD_A_INT_STAT, 0xffffffff); cx_write(AUD_A_INT_STAT, 0xffffffff);
cx_write(AUD_B_INT_STAT, 0xffffffff); cx_write(AUD_B_INT_STAT, 0xffffffff);
cx_write(AUD_C_INT_STAT, 0xffffffff); cx_write(AUD_C_INT_STAT, 0xffffffff);
@ -844,29 +838,31 @@ static void cx25821_initialize(struct cx25821_dev *dev)
cx25821_registers_init(dev); //init Pecos registers cx25821_registers_init(dev); //init Pecos registers
mdelay(100); mdelay(100);
for (i = 0; i < VID_CHANNEL_NUM; i++) {
for(i=0; i<VID_CHANNEL_NUM; i++)
{
cx25821_set_vip_mode(dev, &dev->sram_channels[i]); cx25821_set_vip_mode(dev, &dev->sram_channels[i]);
cx25821_sram_channel_setup(dev, &dev->sram_channels[i], 1440, 0); cx25821_sram_channel_setup(dev, &dev->sram_channels[i], 1440,
0);
dev->pixel_formats[i] = PIXEL_FRMT_422; dev->pixel_formats[i] = PIXEL_FRMT_422;
dev->use_cif_resolution[i] = FALSE; dev->use_cif_resolution[i] = FALSE;
} }
//Probably only affect Downstream //Probably only affect Downstream
for( i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; i++) for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
{ i++) {
cx25821_set_vip_mode(dev, &dev->sram_channels[i]); cx25821_set_vip_mode(dev, &dev->sram_channels[i]);
} }
cx25821_sram_channel_setup_audio(dev, &dev->sram_channels[SRAM_CH08], 128, 0); cx25821_sram_channel_setup_audio(dev, &dev->sram_channels[SRAM_CH08],
128, 0);
cx25821_gpio_init(dev); cx25821_gpio_init(dev);
} }
static int get_resources(struct cx25821_dev *dev) static int get_resources(struct cx25821_dev *dev)
{ {
if (request_mem_region(pci_resource_start(dev->pci, 0), pci_resource_len(dev->pci, 0), dev->name)) if (request_mem_region
(pci_resource_start(dev->pci, 0), pci_resource_len(dev->pci, 0),
dev->name))
return 0; return 0;
printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n", printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n",
@ -875,12 +871,12 @@ static int get_resources(struct cx25821_dev *dev)
return -EBUSY; return -EBUSY;
} }
static void cx25821_dev_checkrevision(struct cx25821_dev *dev) static void cx25821_dev_checkrevision(struct cx25821_dev *dev)
{ {
dev->hwrevision = cx_read(RDR_CFG2) & 0xff; dev->hwrevision = cx_read(RDR_CFG2) & 0xff;
printk(KERN_INFO "%s() Hardware revision = 0x%02x\n", __func__, dev->hwrevision); printk(KERN_INFO "%s() Hardware revision = 0x%02x\n", __func__,
dev->hwrevision);
} }
static void cx25821_iounmap(struct cx25821_dev *dev) static void cx25821_iounmap(struct cx25821_dev *dev)
@ -889,15 +885,13 @@ static void cx25821_iounmap(struct cx25821_dev *dev)
return; return;
/* Releasing IO memory */ /* Releasing IO memory */
if (dev->lmmio != NULL) if (dev->lmmio != NULL) {
{
CX25821_INFO("Releasing lmmio.\n"); CX25821_INFO("Releasing lmmio.\n");
iounmap(dev->lmmio); iounmap(dev->lmmio);
dev->lmmio = NULL; dev->lmmio = NULL;
} }
} }
static int cx25821_dev_setup(struct cx25821_dev *dev) static int cx25821_dev_setup(struct cx25821_dev *dev)
{ {
int io_size = 0, i; int io_size = 0, i;
@ -935,24 +929,21 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
strcpy(cx25821_boards[UNKNOWN_BOARD].name, "unknown"); strcpy(cx25821_boards[UNKNOWN_BOARD].name, "unknown");
strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821"); strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821");
if (dev->pci->device != 0x8210) {
if( dev->pci->device != 0x8210 ) printk(KERN_INFO
{ "%s() Exiting. Incorrect Hardware device = 0x%02x\n",
printk(KERN_INFO "%s() Exiting. Incorrect Hardware device = 0x%02x\n",
__func__, dev->pci->device); __func__, dev->pci->device);
return -1; return -1;
} } else {
else printk(KERN_INFO "Athena Hardware device = 0x%02x\n",
{ dev->pci->device);
printk(KERN_INFO "Athena Hardware device = 0x%02x\n", dev->pci->device);
} }
/* Apply a sensible clock frequency for the PCIe bridge */ /* Apply a sensible clock frequency for the PCIe bridge */
dev->clk_freq = 28000000; dev->clk_freq = 28000000;
dev->sram_channels = cx25821_sram_channels; dev->sram_channels = cx25821_sram_channels;
if(dev->nr > 1) if (dev->nr > 1) {
{
CX25821_INFO("dev->nr > 1!"); CX25821_INFO("dev->nr > 1!");
} }
@ -960,7 +951,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
dev->board = 1; //card[dev->nr]; dev->board = 1; //card[dev->nr];
dev->_max_num_decoders = MAX_DECODERS; dev->_max_num_decoders = MAX_DECODERS;
dev->pci_bus = dev->pci->bus->number; dev->pci_bus = dev->pci->bus->number;
dev->pci_slot = PCI_SLOT(dev->pci->devfn); dev->pci_slot = PCI_SLOT(dev->pci->devfn);
dev->pci_irqmask = 0x001f00; dev->pci_irqmask = 0x001f00;
@ -976,9 +966,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */ dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */
if (get_resources(dev) < 0) {
if (get_resources(dev) < 0)
{
printk(KERN_ERR "%s No more PCIe resources for " printk(KERN_ERR "%s No more PCIe resources for "
"subsystem: %04x:%04x\n", "subsystem: %04x:%04x\n",
dev->name, dev->pci->subsystem_vendor, dev->name, dev->pci->subsystem_vendor,
@ -1000,12 +988,12 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
dev->lmmio = ioremap(dev->base_io_addr, pci_resource_len(dev->pci, 0)); dev->lmmio = ioremap(dev->base_io_addr, pci_resource_len(dev->pci, 0));
if (!dev->lmmio) { if (!dev->lmmio) {
CX25821_ERR("ioremap failed, maybe increasing __VMALLOC_RESERVE in page.h\n"); CX25821_ERR
("ioremap failed, maybe increasing __VMALLOC_RESERVE in page.h\n");
cx25821_iounmap(dev); cx25821_iounmap(dev);
return -ENOMEM; return -ENOMEM;
} }
dev->bmmio = (u8 __iomem *) dev->lmmio; dev->bmmio = (u8 __iomem *) dev->lmmio;
printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
@ -1021,34 +1009,41 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
// cx25821_i2c_register(&dev->i2c_bus[1]); // cx25821_i2c_register(&dev->i2c_bus[1]);
// cx25821_i2c_register(&dev->i2c_bus[2]); // cx25821_i2c_register(&dev->i2c_bus[2]);
CX25821_INFO("i2c register! bus->i2c_rc = %d\n", dev->i2c_bus[0].i2c_rc); CX25821_INFO("i2c register! bus->i2c_rc = %d\n",
dev->i2c_bus[0].i2c_rc);
cx25821_card_setup(dev); cx25821_card_setup(dev);
medusa_video_init(dev); medusa_video_init(dev);
for(i = 0; i < VID_CHANNEL_NUM; i++) for (i = 0; i < VID_CHANNEL_NUM; i++) {
{
if (cx25821_video_register(dev, i, video_template[i]) < 0) { if (cx25821_video_register(dev, i, video_template[i]) < 0) {
printk(KERN_ERR "%s() Failed to register analog video adapters on VID channel %d\n", __func__, i); printk(KERN_ERR
"%s() Failed to register analog video adapters on VID channel %d\n",
__func__, i);
} }
} }
for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
for(i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
{
//Since we don't have template8 for Audio Downstream //Since we don't have template8 for Audio Downstream
if (cx25821_video_register(dev, i, video_template[i - 1]) < 0) { if (cx25821_video_register(dev, i, video_template[i - 1]) < 0) {
printk(KERN_ERR "%s() Failed to register analog video adapters for Upstream channel %d.\n", __func__, i); printk(KERN_ERR
"%s() Failed to register analog video adapters for Upstream channel %d.\n",
__func__, i);
} }
} }
// register IOCTL device // register IOCTL device
dev->ioctl_dev = cx25821_vdev_init(dev, dev->pci, video_template[VIDEO_IOCTL_CH], "video"); dev->ioctl_dev =
cx25821_vdev_init(dev, dev->pci, video_template[VIDEO_IOCTL_CH],
"video");
if( video_register_device(dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0 ) if (video_register_device
{ (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
cx25821_videoioctl_unregister(dev); cx25821_videoioctl_unregister(dev);
printk(KERN_ERR "%s() Failed to register video adapter for IOCTL so releasing.\n", __func__); printk(KERN_ERR
"%s() Failed to register video adapter for IOCTL so releasing.\n",
__func__);
} }
cx25821_dev_checkrevision(dev); cx25821_dev_checkrevision(dev);
@ -1057,30 +1052,32 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
return 0; return 0;
} }
void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev, struct upstream_user_struct *up_data) struct upstream_user_struct *up_data)
{ {
dev->_isNTSC = !strcmp(dev->vid_stdname, "NTSC") ? 1 : 0; dev->_isNTSC = !strcmp(dev->vid_stdname, "NTSC") ? 1 : 0;
dev->tvnorm = !dev->_isNTSC ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M; dev->tvnorm = !dev->_isNTSC ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
medusa_set_videostandard(dev); medusa_set_videostandard(dev);
cx25821_vidupstream_init_ch1(dev, dev->channel_select, dev->pixel_format); cx25821_vidupstream_init_ch1(dev, dev->channel_select,
dev->pixel_format);
} }
void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev, struct upstream_user_struct *up_data) struct upstream_user_struct *up_data)
{ {
dev->_isNTSC_ch2 = !strcmp(dev->vid_stdname_ch2, "NTSC") ? 1 : 0; dev->_isNTSC_ch2 = !strcmp(dev->vid_stdname_ch2, "NTSC") ? 1 : 0;
dev->tvnorm = !dev->_isNTSC_ch2 ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M; dev->tvnorm = !dev->_isNTSC_ch2 ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
medusa_set_videostandard(dev); medusa_set_videostandard(dev);
cx25821_vidupstream_init_ch2(dev, dev->channel_select_ch2, dev->pixel_format_ch2); cx25821_vidupstream_init_ch2(dev, dev->channel_select_ch2,
dev->pixel_format_ch2);
} }
void cx25821_start_upstream_audio(struct cx25821_dev *dev,
void cx25821_start_upstream_audio(struct cx25821_dev *dev, struct upstream_user_struct *up_data) struct upstream_user_struct *up_data)
{ {
cx25821_audio_upstream_init(dev, AUDIO_UPSTREAM_SRAM_CHANNEL_B); cx25821_audio_upstream_init(dev, AUDIO_UPSTREAM_SRAM_CHANNEL_B);
} }
@ -1104,9 +1101,8 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
for (i = 0; i < VID_CHANNEL_NUM; i++) for (i = 0; i < VID_CHANNEL_NUM; i++)
cx25821_video_unregister(dev, i); cx25821_video_unregister(dev, i);
for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
for(i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
{
cx25821_video_unregister(dev, i); cx25821_video_unregister(dev, i);
} }
@ -1116,8 +1112,6 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
cx25821_iounmap(dev); cx25821_iounmap(dev);
} }
static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist, static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist,
unsigned int offset, u32 sync_line, unsigned int offset, u32 sync_line,
unsigned int bpl, unsigned int padding, unsigned int bpl, unsigned int padding,
@ -1127,8 +1121,7 @@ static __le32 *cx25821_risc_field(__le32 *rp, struct scatterlist *sglist,
unsigned int line, todo; unsigned int line, todo;
/* sync instruction */ /* sync instruction */
if (sync_line != NO_SYNC_LINE) if (sync_line != NO_SYNC_LINE) {
{
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
} }
@ -1141,21 +1134,25 @@ static __le32 *cx25821_risc_field(__le32 *rp, struct scatterlist *sglist,
} }
if (bpl <= sg_dma_len(sg) - offset) { if (bpl <= sg_dma_len(sg) - offset) {
/* fits into current chunk */ /* fits into current chunk */
*(rp++) = cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl); *(rp++) =
cpu_to_le32(RISC_WRITE | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset); *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += bpl; offset += bpl;
} else { } else {
/* scanline needs to be split */ /* scanline needs to be split */
todo = bpl; todo = bpl;
*(rp++) = cpu_to_le32(RISC_WRITE|RISC_SOL|(sg_dma_len(sg)-offset)); *(rp++) =
cpu_to_le32(RISC_WRITE | RISC_SOL |
(sg_dma_len(sg) - offset));
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset); *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= (sg_dma_len(sg) - offset); todo -= (sg_dma_len(sg) - offset);
offset = 0; offset = 0;
sg++; sg++;
while (todo > sg_dma_len(sg)) { while (todo > sg_dma_len(sg)) {
*(rp++) = cpu_to_le32(RISC_WRITE|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));
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= sg_dma_len(sg); todo -= sg_dma_len(sg);
@ -1194,7 +1191,8 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
can cause next bpl to start close to a page border. First DMA can cause next bpl to start close to a page border. First DMA
region may be smaller than PAGE_SIZE */ region may be smaller than PAGE_SIZE */
/* write and jump need and extra dword */ /* write and jump need and extra dword */
instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines); instructions =
fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines);
instructions += 2; instructions += 2;
rc = btcx_riscmem_alloc(pci, risc, instructions * 12); rc = btcx_riscmem_alloc(pci, risc, instructions * 12);
@ -1204,14 +1202,14 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
/* write risc instructions */ /* write risc instructions */
rp = risc->cpu; rp = risc->cpu;
if (UNSET != top_offset) if (UNSET != top_offset) {
{ rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding,
rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding, lines); lines);
} }
if (UNSET != bottom_offset) if (UNSET != bottom_offset) {
{ rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl,
rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl, padding, lines); padding, lines);
} }
/* save pointer to jmp instruction address */ /* save pointer to jmp instruction address */
@ -1221,7 +1219,6 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
return 0; return 0;
} }
static __le32 *cx25821_risc_field_audio(__le32 * rp, struct scatterlist *sglist, static __le32 *cx25821_risc_field_audio(__le32 * rp, struct scatterlist *sglist,
unsigned int offset, u32 sync_line, unsigned int offset, u32 sync_line,
unsigned int bpl, unsigned int padding, unsigned int bpl, unsigned int padding,
@ -1249,7 +1246,8 @@ static __le32* cx25821_risc_field_audio(__le32 *rp, struct scatterlist *sglist,
if (bpl <= sg_dma_len(sg) - offset) { if (bpl <= sg_dma_len(sg) - offset) {
/* fits into current chunk */ /* fits into current chunk */
*(rp++) = cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl); *(rp++) =
cpu_to_le32(RISC_WRITE | sol | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset); *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += bpl; offset += bpl;
@ -1286,8 +1284,7 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
struct btcx_riscmem *risc, struct btcx_riscmem *risc,
struct scatterlist *sglist, struct scatterlist *sglist,
unsigned int bpl, unsigned int bpl,
unsigned int lines, unsigned int lines, unsigned int lpi)
unsigned int lpi)
{ {
u32 instructions; u32 instructions;
__le32 *rp; __le32 *rp;
@ -1304,10 +1301,10 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
if ((rc = btcx_riscmem_alloc(pci, risc, instructions * 12)) < 0) if ((rc = btcx_riscmem_alloc(pci, risc, instructions * 12)) < 0)
return rc; return rc;
/* write risc instructions */ /* write risc instructions */
rp = risc->cpu; rp = risc->cpu;
rp = cx25821_risc_field_audio(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi); rp = cx25821_risc_field_audio(rp, sglist, 0, NO_SYNC_LINE, bpl, 0,
lines, lpi);
/* save pointer to jmp instruction address */ /* save pointer to jmp instruction address */
risc->jmp = rp; risc->jmp = rp;
@ -1315,8 +1312,8 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
return 0; return 0;
} }
int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,u32 reg, u32 mask, u32 value) u32 reg, u32 mask, u32 value)
{ {
__le32 *rp; __le32 *rp;
int rc; int rc;
@ -1351,7 +1348,6 @@ void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf)
buf->vb.state = VIDEOBUF_NEEDS_INIT; buf->vb.state = VIDEOBUF_NEEDS_INIT;
} }
static irqreturn_t cx25821_irq(int irq, void *dev_id) static irqreturn_t cx25821_irq(int irq, void *dev_id)
{ {
struct cx25821_dev *dev = dev_id; struct cx25821_dev *dev = dev_id;
@ -1363,18 +1359,16 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
pci_status = cx_read(PCI_INT_STAT); pci_status = cx_read(PCI_INT_STAT);
pci_mask = cx_read(PCI_INT_MSK); pci_mask = cx_read(PCI_INT_MSK);
if (pci_status == 0) if (pci_status == 0)
goto out; goto out;
for(i = 0; i < VID_CHANNEL_NUM; i++) for (i = 0; i < VID_CHANNEL_NUM; i++) {
{ if (pci_status & mask[i]) {
if(pci_status & mask[i])
{
vid_status = cx_read(dev->sram_channels[i].int_stat); vid_status = cx_read(dev->sram_channels[i].int_stat);
if (vid_status) if (vid_status)
handled += cx25821_video_irq(dev, i, vid_status); handled +=
cx25821_video_irq(dev, i, vid_status);
cx_write(PCI_INT_STAT, mask[i]); cx_write(PCI_INT_STAT, mask[i]);
} }
@ -1411,7 +1405,8 @@ struct cx25821_dev* cx25821_dev_get(struct pci_dev *pci)
return dev; return dev;
} }
static int __devinit cx25821_initdev(struct pci_dev *pci_dev, const struct pci_device_id *pci_id) static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
const struct pci_device_id *pci_id)
{ {
struct cx25821_dev *dev; struct cx25821_dev *dev;
int err = 0; int err = 0;
@ -1420,15 +1415,13 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev, const struct pci_d
if (NULL == dev) if (NULL == dev)
return -ENOMEM; return -ENOMEM;
err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev); err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev);
if (err < 0) if (err < 0)
goto fail_free; goto fail_free;
/* pci init */ /* pci init */
dev->pci = pci_dev; dev->pci = pci_dev;
if (pci_enable_device(pci_dev)) if (pci_enable_device(pci_dev)) {
{
err = -EIO; err = -EIO;
printk(KERN_INFO "pci enable failed! "); printk(KERN_INFO "pci enable failed! ");
@ -1438,8 +1431,7 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev, const struct pci_d
printk(KERN_INFO "cx25821 Athena pci enable ! \n"); printk(KERN_INFO "cx25821 Athena pci enable ! \n");
if (cx25821_dev_setup(dev) < 0) if (cx25821_dev_setup(dev) < 0) {
{
err = -EINVAL; err = -EINVAL;
goto fail_unregister_device; goto fail_unregister_device;
} }
@ -1450,23 +1442,22 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev, const struct pci_d
printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, " printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
"latency: %d, mmio: 0x%llx\n", dev->name, "latency: %d, mmio: 0x%llx\n", dev->name,
pci_name(pci_dev), dev->pci_rev, pci_dev->irq, pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
dev->pci_lat, dev->pci_lat, (unsigned long long)dev->base_io_addr);
(unsigned long long)dev->base_io_addr );
pci_set_master(pci_dev); pci_set_master(pci_dev);
if (!pci_dma_supported(pci_dev, 0xffffffff)) if (!pci_dma_supported(pci_dev, 0xffffffff)) {
{
printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name);
err = -EIO; err = -EIO;
goto fail_irq; goto fail_irq;
} }
err = request_irq(pci_dev->irq, cx25821_irq, IRQF_SHARED | IRQF_DISABLED, dev->name, dev); err =
request_irq(pci_dev->irq, cx25821_irq, IRQF_SHARED | IRQF_DISABLED,
dev->name, dev);
if (err < 0) if (err < 0) {
{ printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name, pci_dev->irq); pci_dev->irq);
goto fail_irq; goto fail_irq;
} }
@ -1496,7 +1487,6 @@ static void __devexit cx25821_finidev(struct pci_dev *pci_dev)
if (pci_dev->irq) if (pci_dev->irq)
free_irq(pci_dev->irq, dev); free_irq(pci_dev->irq, dev);
mutex_lock(&devlist); mutex_lock(&devlist);
list_del(&dev->devlist); list_del(&dev->devlist);
mutex_unlock(&devlist); mutex_unlock(&devlist);
@ -1521,8 +1511,7 @@ static struct pci_device_id cx25821_pci_tbl[] = {
MODULE_DEVICE_TABLE(pci, cx25821_pci_tbl); MODULE_DEVICE_TABLE(pci, cx25821_pci_tbl);
static struct pci_driver cx25821_pci_driver = static struct pci_driver cx25821_pci_driver = {
{
.name = "cx25821", .name = "cx25821",
.id_table = cx25821_pci_tbl, .id_table = cx25821_pci_tbl,
.probe = cx25821_initdev, .probe = cx25821_initdev,
@ -1537,8 +1526,7 @@ static int cx25821_init(void)
INIT_LIST_HEAD(&cx25821_devlist); INIT_LIST_HEAD(&cx25821_devlist);
printk(KERN_INFO "cx25821 driver version %d.%d.%d loaded\n", printk(KERN_INFO "cx25821 driver version %d.%d.%d loaded\n",
(CX25821_VERSION_CODE >> 16) & 0xff, (CX25821_VERSION_CODE >> 16) & 0xff,
(CX25821_VERSION_CODE >> 8) & 0xff, (CX25821_VERSION_CODE >> 8) & 0xff, CX25821_VERSION_CODE & 0xff);
CX25821_VERSION_CODE & 0xff);
return pci_register_driver(&cx25821_pci_driver); return pci_register_driver(&cx25821_pci_driver);
} }
@ -1547,7 +1535,6 @@ static void cx25821_fini(void)
pci_unregister_driver(&cx25821_pci_driver); pci_unregister_driver(&cx25821_pci_driver);
} }
EXPORT_SYMBOL(cx25821_devlist); EXPORT_SYMBOL(cx25821_devlist);
EXPORT_SYMBOL(cx25821_sram_channels); EXPORT_SYMBOL(cx25821_sram_channels);
EXPORT_SYMBOL(cx25821_print_irqbits); EXPORT_SYMBOL(cx25821_print_irqbits);
@ -1562,4 +1549,3 @@ EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
module_init(cx25821_init); module_init(cx25821_init);
module_exit(cx25821_fini); module_exit(cx25821_fini);

View File

@ -22,11 +22,9 @@
#include "cx25821.h" #include "cx25821.h"
/********************* GPIO stuffs *********************/ /********************* GPIO stuffs *********************/
void cx25821_set_gpiopin_direction(struct cx25821_dev *dev, void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
int pin_number, int pin_number, int pin_logic_value)
int pin_logic_value)
{ {
int bit = pin_number; int bit = pin_number;
u32 gpio_oe_reg = GPIO_LO_OE; u32 gpio_oe_reg = GPIO_LO_OE;
@ -37,22 +35,16 @@ void cx25821_set_gpiopin_direction( struct cx25821_dev *dev,
if (pin_number >= 47) if (pin_number >= 47)
return; return;
if (pin_number > 31) {
if ( pin_number > 31 )
{
bit = pin_number - 31; bit = pin_number - 31;
gpio_oe_reg = GPIO_HI_OE; gpio_oe_reg = GPIO_HI_OE;
} }
// Here we will make sure that the GPIOs 0 and 1 are output. keep the rest as is // Here we will make sure that the GPIOs 0 and 1 are output. keep the rest as is
gpio_register = cx_read(gpio_oe_reg); gpio_register = cx_read(gpio_oe_reg);
if (pin_logic_value == 1) if (pin_logic_value == 1) {
{
value = gpio_register | Set_GPIO_Bit(bit); value = gpio_register | Set_GPIO_Bit(bit);
} } else {
else
{
value = gpio_register & Clear_GPIO_Bit(bit); value = gpio_register & Clear_GPIO_Bit(bit);
} }
@ -60,36 +52,28 @@ void cx25821_set_gpiopin_direction( struct cx25821_dev *dev,
} }
static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev, static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
int pin_number, int pin_number, int pin_logic_value)
int pin_logic_value)
{ {
int bit = pin_number; int bit = pin_number;
u32 gpio_reg = GPIO_LO; u32 gpio_reg = GPIO_LO;
u32 value = 0; u32 value = 0;
// Check for valid pinNumber // Check for valid pinNumber
if (pin_number >= 47) if (pin_number >= 47)
return; return;
cx25821_set_gpiopin_direction(dev, pin_number, 0); // change to output direction cx25821_set_gpiopin_direction(dev, pin_number, 0); // change to output direction
if (pin_number > 31) {
if ( pin_number > 31 )
{
bit = pin_number - 31; bit = pin_number - 31;
gpio_reg = GPIO_HI; gpio_reg = GPIO_HI;
} }
value = cx_read(gpio_reg); value = cx_read(gpio_reg);
if (pin_logic_value == 0) {
if (pin_logic_value == 0)
{
value &= Clear_GPIO_Bit(bit); value &= Clear_GPIO_Bit(bit);
} } else {
else
{
value |= Set_GPIO_Bit(bit); value |= Set_GPIO_Bit(bit);
} }
@ -98,13 +82,11 @@ static void cx25821_set_gpiopin_logicvalue( struct cx25821_dev *dev,
void cx25821_gpio_init(struct cx25821_dev *dev) void cx25821_gpio_init(struct cx25821_dev *dev)
{ {
if( dev == NULL ) if (dev == NULL) {
{
return; return;
} }
switch (dev->board) switch (dev->board) {
{
case CX25821_BOARD_CONEXANT_ATHENA10: case CX25821_BOARD_CONEXANT_ATHENA10:
default: default:
//set GPIO 5 to select the path for Medusa/Athena //set GPIO 5 to select the path for Medusa/Athena

View File

@ -1,3 +1,2 @@
void cx25821_gpio_init(struct athena_dev *dev); void cx25821_gpio_init(struct athena_dev *dev);

View File

@ -24,7 +24,6 @@
#include "cx25821.h" #include "cx25821.h"
#include <linux/i2c.h> #include <linux/i2c.h>
static unsigned int i2c_debug; static unsigned int i2c_debug;
module_param(i2c_debug, int, 0644); module_param(i2c_debug, int, 0644);
MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
@ -44,7 +43,6 @@ MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
#define I2C_EXTEND (1 << 3) #define I2C_EXTEND (1 << 3)
#define I2C_NOSTOP (1 << 4) #define I2C_NOSTOP (1 << 4)
static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap) static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
{ {
struct cx25821_i2c *bus = i2c_adap->algo_data; struct cx25821_i2c *bus = i2c_adap->algo_data;
@ -75,7 +73,8 @@ static int i2c_wait_done(struct i2c_adapter *i2c_adap)
return 1; return 1;
} }
static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg, int joined_rlen) static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
const struct i2c_msg *msg, int joined_rlen)
{ {
struct cx25821_i2c *bus = i2c_adap->algo_data; struct cx25821_i2c *bus = i2c_adap->algo_data;
struct cx25821_dev *dev = bus->dev; struct cx25821_dev *dev = bus->dev;
@ -83,13 +82,13 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
int retval, cnt; int retval, cnt;
if (joined_rlen) if (joined_rlen)
dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__, msg->len, joined_rlen); dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__,
msg->len, joined_rlen);
else else
dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len); dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
/* Deal with i2c probe functions with zero payload */ /* Deal with i2c probe functions with zero payload */
if (msg->len == 0) if (msg->len == 0) {
{
cx_write(bus->reg_addr, msg->addr << 25); cx_write(bus->reg_addr, msg->addr << 25);
cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2)); cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2));
@ -125,8 +124,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
if (retval == 0) if (retval == 0)
goto eio; goto eio;
if (i2c_debug) if (i2c_debug) {
{
if (!(ctrl & I2C_NOSTOP)) if (!(ctrl & I2C_NOSTOP))
printk(" >\n"); printk(" >\n");
} }
@ -152,8 +150,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
if (retval == 0) if (retval == 0)
goto eio; goto eio;
if (i2c_debug) if (i2c_debug) {
{
dprintk(1, " %02x", msg->buf[cnt]); dprintk(1, " %02x", msg->buf[cnt]);
if (!(ctrl & I2C_NOSTOP)) if (!(ctrl & I2C_NOSTOP))
dprintk(1, " >\n"); dprintk(1, " >\n");
@ -170,14 +167,14 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
return retval; return retval;
} }
static int i2c_readbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg, int joined) static int i2c_readbytes(struct i2c_adapter *i2c_adap,
const struct i2c_msg *msg, int joined)
{ {
struct cx25821_i2c *bus = i2c_adap->algo_data; struct cx25821_i2c *bus = i2c_adap->algo_data;
struct cx25821_dev *dev = bus->dev; struct cx25821_dev *dev = bus->dev;
u32 ctrl, cnt; u32 ctrl, cnt;
int retval; int retval;
if (i2c_debug && !joined) if (i2c_debug && !joined)
dprintk(1, "6-%s(msg->len=%d)\n", __func__, msg->len); dprintk(1, "6-%s(msg->len=%d)\n", __func__, msg->len);
@ -190,7 +187,6 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
if (!i2c_slave_did_ack(i2c_adap)) if (!i2c_slave_did_ack(i2c_adap))
return -EIO; return -EIO;
dprintk(1, "%s() returns 0\n", __func__); dprintk(1, "%s() returns 0\n", __func__);
return 0; return 0;
} }
@ -209,7 +205,6 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
if (cnt < msg->len - 1) if (cnt < msg->len - 1)
ctrl |= I2C_NOSTOP | I2C_EXTEND; ctrl |= I2C_NOSTOP | I2C_EXTEND;
cx_write(bus->reg_addr, msg->addr << 25); cx_write(bus->reg_addr, msg->addr << 25);
cx_write(bus->reg_ctrl, ctrl); cx_write(bus->reg_ctrl, ctrl);
@ -244,29 +239,24 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
dprintk(1, "%s(num = %d)\n", __func__, num); dprintk(1, "%s(num = %d)\n", __func__, num);
for (i = 0 ; i < num; i++) for (i = 0; i < num; i++) {
{
dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n", dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
__func__, num, msgs[i].addr, msgs[i].len); __func__, num, msgs[i].addr, msgs[i].len);
if (msgs[i].flags & I2C_M_RD) if (msgs[i].flags & I2C_M_RD) {
{
/* read */ /* read */
retval = i2c_readbytes(i2c_adap, &msgs[i], 0); retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
} } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && msgs[i].addr == msgs[i + 1].addr) {
msgs[i].addr == msgs[i + 1].addr)
{
/* write then read from same address */ /* write then read from same address */
retval = i2c_sendbytes(i2c_adap, &msgs[i], msgs[i + 1].len); retval =
i2c_sendbytes(i2c_adap, &msgs[i], msgs[i + 1].len);
if (retval < 0) if (retval < 0)
goto err; goto err;
i++; i++;
retval = i2c_readbytes(i2c_adap, &msgs[i], 1); retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
} } else {
else
{
/* write */ /* write */
retval = i2c_sendbytes(i2c_adap, &msgs[i], 0); retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
} }
@ -286,8 +276,7 @@ static u32 cx25821_functionality(struct i2c_adapter *adap)
return I2C_FUNC_SMBUS_EMUL | return I2C_FUNC_SMBUS_EMUL |
I2C_FUNC_I2C | I2C_FUNC_I2C |
I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
} }
static struct i2c_algorithm cx25821_i2c_algo_template = { static struct i2c_algorithm cx25821_i2c_algo_template = {
@ -295,7 +284,6 @@ static struct i2c_algorithm cx25821_i2c_algo_template = {
.functionality = cx25821_functionality, .functionality = cx25821_functionality,
}; };
static struct i2c_adapter cx25821_i2c_adap_template = { static struct i2c_adapter cx25821_i2c_adap_template = {
.name = "cx25821", .name = "cx25821",
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -367,7 +355,6 @@ void cx25821_av_clk(struct cx25821_dev *dev, int enable)
i2c_xfer(&dev->i2c_bus[0].i2c_adap, &msg, 1); i2c_xfer(&dev->i2c_bus[0].i2c_adap, &msg, 1);
} }
int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value) int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value)
{ {
struct i2c_client *client = &bus->i2c_client; struct i2c_client *client = &bus->i2c_client;
@ -390,7 +377,6 @@ int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value)
} }
}; };
addr[0] = (reg_addr >> 8); addr[0] = (reg_addr >> 8);
addr[1] = (reg_addr & 0xff); addr[1] = (reg_addr & 0xff);
msgs[0].addr = 0x44; msgs[0].addr = 0x44;
@ -404,7 +390,6 @@ int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value)
return v; return v;
} }
int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value) int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value)
{ {
struct i2c_client *client = &bus->i2c_client; struct i2c_client *client = &bus->i2c_client;
@ -420,7 +405,6 @@ int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value)
} }
}; };
buf[0] = reg_addr >> 8; buf[0] = reg_addr >> 8;
buf[1] = reg_addr & 0xff; buf[1] = reg_addr & 0xff;
buf[5] = (value >> 24) & 0xff; buf[5] = (value >> 24) & 0xff;
@ -434,4 +418,3 @@ int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value)
return retval; return retval;
} }

View File

@ -452,5 +452,4 @@
#define VDEC_A_VSAT_CTRL 0x1019 #define VDEC_A_VSAT_CTRL 0x1019
#define VDEC_A_HUE_CTRL 0x101A #define VDEC_A_HUE_CTRL 0x101A
#endif #endif

View File

@ -24,13 +24,13 @@
#include "cx25821-medusa-video.h" #include "cx25821-medusa-video.h"
#include "cx25821-biffuncs.h" #include "cx25821-biffuncs.h"
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
//medusa_enable_bluefield_output() //medusa_enable_bluefield_output()
// //
// Enable the generation of blue filed output if no video // Enable the generation of blue filed output if no video
// //
static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel, int enable) static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel,
int enable)
{ {
int ret_val = 1; int ret_val = 1;
u32 value = 0; u32 value = 0;
@ -38,9 +38,7 @@ static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel,
int out_ctrl = OUT_CTRL1; int out_ctrl = OUT_CTRL1;
int out_ctrl_ns = OUT_CTRL_NS; int out_ctrl_ns = OUT_CTRL_NS;
switch (channel) {
switch (channel)
{
default: default:
case VDEC_A: case VDEC_A:
break; break;
@ -87,7 +85,6 @@ static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel,
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl_ns, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl_ns, value);
} }
static int medusa_initialize_ntsc(struct cx25821_dev *dev) static int medusa_initialize_ntsc(struct cx25821_dev *dev)
{ {
int ret_val = 0; int ret_val = 0;
@ -97,96 +94,145 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
for (i = 0; i < MAX_DECODERS; i++) {
for (i=0; i < MAX_DECODERS; i++)
{
// set video format NTSC-M // set video format NTSC-M
value = cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
&tmp);
value &= 0xFFFFFFF0; value &= 0xFFFFFFF0;
value |= 0x10001; // enable the fast locking mode bit[16] value |= 0x10001; // enable the fast locking mode bit[16]
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
value);
// resolution NTSC 720x480 // resolution NTSC 720x480
value = cx25821_i2c_read(&dev->i2c_bus[0], HORIZ_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
HORIZ_TIM_CTRL + (0x200 * i), &tmp);
value &= 0x00C00C00; value &= 0x00C00C00;
value |= 0x612D0074; value |= 0x612D0074;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HORIZ_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
HORIZ_TIM_CTRL + (0x200 * i), value);
value = cx25821_i2c_read(&dev->i2c_bus[0], VERT_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
VERT_TIM_CTRL + (0x200 * i), &tmp);
value &= 0x00C00C00; value &= 0x00C00C00;
value |= 0x1C1E001A; // vblank_cnt + 2 to get camera ID value |= 0x1C1E001A; // vblank_cnt + 2 to get camera ID
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VERT_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
VERT_TIM_CTRL + (0x200 * i), value);
// chroma subcarrier step size // chroma subcarrier step size
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], SC_STEP_SIZE+(0x200*i), 0x43E00000); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
SC_STEP_SIZE + (0x200 * i), 0x43E00000);
// enable VIP optional active // enable VIP optional active
value = cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL_NS+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
OUT_CTRL_NS + (0x200 * i), &tmp);
value &= 0xFFFBFFFF; value &= 0xFFFBFFFF;
value |= 0x00040000; value |= 0x00040000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL_NS+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
OUT_CTRL_NS + (0x200 * i), value);
// enable VIP optional active (VIP_OPT_AL) for direct output. // enable VIP optional active (VIP_OPT_AL) for direct output.
value = cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
&tmp);
value &= 0xFFFBFFFF; value &= 0xFFFBFFFF;
value |= 0x00040000; value |= 0x00040000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
value);
// clear VPRES_VERT_EN bit, fixes the chroma run away problem // clear VPRES_VERT_EN bit, fixes the chroma run away problem
// when the input switching rate < 16 fields // when the input switching rate < 16 fields
// //
value = cx25821_i2c_read(&dev->i2c_bus[0], MISC_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
MISC_TIM_CTRL + (0x200 * i), &tmp);
value = setBitAtPos(value, 14); // disable special play detection value = setBitAtPos(value, 14); // disable special play detection
value = clearBitAtPos(value, 15); value = clearBitAtPos(value, 15);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MISC_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
MISC_TIM_CTRL + (0x200 * i), value);
// set vbi_gate_en to 0 // set vbi_gate_en to 0
value = cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
&tmp);
value = clearBitAtPos(value, 29); value = clearBitAtPos(value, 29);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
value);
// Enable the generation of blue field output if no video // Enable the generation of blue field output if no video
medusa_enable_bluefield_output(dev, i, 1); medusa_enable_bluefield_output(dev, i, 1);
} }
for (i = 0; i < MAX_ENCODERS; i++) {
for (i=0; i < MAX_ENCODERS; i++)
{
// NTSC hclock // NTSC hclock
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_1+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_1 + (0x100 * i), &tmp);
value &= 0xF000FC00; value &= 0xF000FC00;
value |= 0x06B402D0; value |= 0x06B402D0;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_1+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_1 + (0x100 * i), value);
// burst begin and burst end // burst begin and burst end
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_2+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_2 + (0x100 * i), &tmp);
value &= 0xFF000000; value &= 0xFF000000;
value |= 0x007E9054; value |= 0x007E9054;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_2+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_2 + (0x100 * i), value);
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_3+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_3 + (0x100 * i), &tmp);
value &= 0xFC00FE00; value &= 0xFC00FE00;
value |= 0x00EC00F0; value |= 0x00EC00F0;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_3+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_3 + (0x100 * i), value);
// set NTSC vblank, no phase alternation, 7.5 IRE pedestal // set NTSC vblank, no phase alternation, 7.5 IRE pedestal
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_4 + (0x100 * i), &tmp);
value &= 0x00FCFFFF; value &= 0x00FCFFFF;
value |= 0x13020000; value |= 0x13020000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_4 + (0x100 * i), value);
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_5+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_5 + (0x100 * i), &tmp);
value &= 0xFFFF0000; value &= 0xFFFF0000;
value |= 0x0000E575; value |= 0x0000E575;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_5+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_5 + (0x100 * i), value);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_6+(0x100*i), 0x009A89C1); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_6 + (0x100 * i), 0x009A89C1);
// Subcarrier Increment // Subcarrier Increment
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_7+(0x100*i), 0x21F07C1F); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_7 + (0x100 * i), 0x21F07C1F);
} }
//set picture resolutions //set picture resolutions
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); //0 - 720 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); //0 - 720
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); //0 - 480 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); //0 - 480
@ -201,32 +247,44 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
return ret_val; return ret_val;
} }
static int medusa_PALCombInit(struct cx25821_dev *dev, int dec) static int medusa_PALCombInit(struct cx25821_dev *dev, int dec)
{ {
int ret_val = -1; int ret_val = -1;
u32 value = 0, tmp = 0; u32 value = 0, tmp = 0;
// Setup for 2D threshold // Setup for 2D threshold
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG+(0x200*dec), 0x20002861); ret_val =
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFD_CFG+(0x200*dec), 0x20002861); cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG + (0x200 * dec),
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_LF_CFG+(0x200*dec), 0x200A1023); 0x20002861);
ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFD_CFG + (0x200 * dec),
0x20002861);
ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_LF_CFG + (0x200 * dec),
0x200A1023);
// Setup flat chroma and luma thresholds // Setup flat chroma and luma thresholds
value = cx25821_i2c_read(&dev->i2c_bus[0], COMB_FLAT_THRESH_CTRL+(0x200*dec), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
COMB_FLAT_THRESH_CTRL + (0x200 * dec), &tmp);
value &= 0x06230000; value &= 0x06230000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_FLAT_THRESH_CTRL+(0x200*dec), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
COMB_FLAT_THRESH_CTRL + (0x200 * dec), value);
// set comb 2D blend // set comb 2D blend
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_BLEND+(0x200*dec), 0x210F0F0F); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_BLEND + (0x200 * dec),
0x210F0F0F);
// COMB MISC CONTROL // COMB MISC CONTROL
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_MISC_CTRL+(0x200*dec), 0x41120A7F); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], COMB_MISC_CTRL + (0x200 * dec),
0x41120A7F);
return ret_val; return ret_val;
} }
static int medusa_initialize_pal(struct cx25821_dev *dev) static int medusa_initialize_pal(struct cx25821_dev *dev)
{ {
int ret_val = 0; int ret_val = 0;
@ -236,53 +294,81 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
for (i=0; i < MAX_DECODERS; i++) for (i = 0; i < MAX_DECODERS; i++) {
{
// set video format PAL-BDGHI // set video format PAL-BDGHI
value = cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
&tmp);
value &= 0xFFFFFFF0; value &= 0xFFFFFFF0;
value |= 0x10004; // enable the fast locking mode bit[16] value |= 0x10004; // enable the fast locking mode bit[16]
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
value);
// resolution PAL 720x576 // resolution PAL 720x576
value = cx25821_i2c_read(&dev->i2c_bus[0], HORIZ_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
HORIZ_TIM_CTRL + (0x200 * i), &tmp);
value &= 0x00C00C00; value &= 0x00C00C00;
value |= 0x632D007D; value |= 0x632D007D;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HORIZ_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
HORIZ_TIM_CTRL + (0x200 * i), value);
// vblank656_cnt=x26, vactive_cnt=240h, vblank_cnt=x24 // vblank656_cnt=x26, vactive_cnt=240h, vblank_cnt=x24
value = cx25821_i2c_read(&dev->i2c_bus[0], VERT_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
VERT_TIM_CTRL + (0x200 * i), &tmp);
value &= 0x00C00C00; value &= 0x00C00C00;
value |= 0x28240026; // vblank_cnt + 2 to get camera ID value |= 0x28240026; // vblank_cnt + 2 to get camera ID
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VERT_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
VERT_TIM_CTRL + (0x200 * i), value);
// chroma subcarrier step size // chroma subcarrier step size
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], SC_STEP_SIZE+(0x200*i), 0x5411E2D0); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
SC_STEP_SIZE + (0x200 * i), 0x5411E2D0);
// enable VIP optional active // enable VIP optional active
value = cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL_NS+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
OUT_CTRL_NS + (0x200 * i), &tmp);
value &= 0xFFFBFFFF; value &= 0xFFFBFFFF;
value |= 0x00040000; value |= 0x00040000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL_NS+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
OUT_CTRL_NS + (0x200 * i), value);
// enable VIP optional active (VIP_OPT_AL) for direct output. // enable VIP optional active (VIP_OPT_AL) for direct output.
value = cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
&tmp);
value &= 0xFFFBFFFF; value &= 0xFFFBFFFF;
value |= 0x00040000; value |= 0x00040000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
value);
// clear VPRES_VERT_EN bit, fixes the chroma run away problem // clear VPRES_VERT_EN bit, fixes the chroma run away problem
// when the input switching rate < 16 fields // when the input switching rate < 16 fields
value = cx25821_i2c_read(&dev->i2c_bus[0], MISC_TIM_CTRL+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
MISC_TIM_CTRL + (0x200 * i), &tmp);
value = setBitAtPos(value, 14); // disable special play detection value = setBitAtPos(value, 14); // disable special play detection
value = clearBitAtPos(value, 15); value = clearBitAtPos(value, 15);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MISC_TIM_CTRL+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
MISC_TIM_CTRL + (0x200 * i), value);
// set vbi_gate_en to 0 // set vbi_gate_en to 0
value = cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1+(0x200*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
&tmp);
value = clearBitAtPos(value, 29); value = clearBitAtPos(value, 29);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1+(0x200*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
value);
medusa_PALCombInit(dev, i); medusa_PALCombInit(dev, i);
@ -290,46 +376,66 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
medusa_enable_bluefield_output(dev, i, 1); medusa_enable_bluefield_output(dev, i, 1);
} }
for (i = 0; i < MAX_ENCODERS; i++) {
for (i=0; i < MAX_ENCODERS; i++)
{
// PAL hclock // PAL hclock
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_1+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_1 + (0x100 * i), &tmp);
value &= 0xF000FC00; value &= 0xF000FC00;
value |= 0x06C002D0; value |= 0x06C002D0;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_1+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_1 + (0x100 * i), value);
// burst begin and burst end // burst begin and burst end
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_2+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_2 + (0x100 * i), &tmp);
value &= 0xFF000000; value &= 0xFF000000;
value |= 0x007E9754; value |= 0x007E9754;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_2+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_2 + (0x100 * i), value);
// hblank and vactive // hblank and vactive
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_3+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_3 + (0x100 * i), &tmp);
value &= 0xFC00FE00; value &= 0xFC00FE00;
value |= 0x00FC0120; value |= 0x00FC0120;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_3+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_3 + (0x100 * i), value);
// set PAL vblank, phase alternation, 0 IRE pedestal // set PAL vblank, phase alternation, 0 IRE pedestal
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4+(0x100*i), &tmp); value =
cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_4 + (0x100 * i), &tmp);
value &= 0x00FCFFFF; value &= 0x00FCFFFF;
value |= 0x14010000; value |= 0x14010000;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_4 + (0x100 * i), value);
value =
value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_5+(0x100*i), &tmp); cx25821_i2c_read(&dev->i2c_bus[0],
DENC_A_REG_5 + (0x100 * i), &tmp);
value &= 0xFFFF0000; value &= 0xFFFF0000;
value |= 0x0000F078; value |= 0x0000F078;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_5+(0x100*i), value); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_5 + (0x100 * i), value);
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_6+(0x100*i), 0x00A493CF); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_6 + (0x100 * i), 0x00A493CF);
// Subcarrier Increment // Subcarrier Increment
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_7+(0x100*i), 0x2A098ACB); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
DENC_A_REG_7 + (0x100 * i), 0x2A098ACB);
} }
//set picture resolutions //set picture resolutions
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); //0 - 720 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); //0 - 720
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); //0 - 576 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); //0 - 576
@ -344,19 +450,14 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
return ret_val; return ret_val;
} }
int medusa_set_videostandard(struct cx25821_dev *dev) int medusa_set_videostandard(struct cx25821_dev *dev)
{ {
int status = STATUS_SUCCESS; int status = STATUS_SUCCESS;
u32 value = 0, tmp = 0; u32 value = 0, tmp = 0;
if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) {
if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
{
status = medusa_initialize_pal(dev); status = medusa_initialize_pal(dev);
} } else {
else
{
status = medusa_initialize_ntsc(dev); status = medusa_initialize_ntsc(dev);
} }
@ -373,8 +474,8 @@ int medusa_set_videostandard(struct cx25821_dev *dev)
return status; return status;
} }
void medusa_set_resolution(struct cx25821_dev *dev, int width,
void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_select) int decoder_select)
{ {
int decoder = 0; int decoder = 0;
int decoder_count = 0; int decoder_count = 0;
@ -386,26 +487,22 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_selec
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
// validate the width - cannot be negative // validate the width - cannot be negative
if (width > MAX_WIDTH) if (width > MAX_WIDTH) {
{ printk
printk("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH \n", __func__, width, MAX_WIDTH); ("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH \n",
__func__, width, MAX_WIDTH);
width = MAX_WIDTH; width = MAX_WIDTH;
} }
if( decoder_select <= 7 && decoder_select >= 0 ) if (decoder_select <= 7 && decoder_select >= 0) {
{
decoder = decoder_select; decoder = decoder_select;
decoder_count = decoder_select + 1; decoder_count = decoder_select + 1;
} } else {
else
{
decoder = 0; decoder = 0;
decoder_count = _num_decoders; decoder_count = _num_decoders;
} }
switch (width) {
switch( width )
{
case 320: case 320:
hscale = 0x13E34B; hscale = 0x13E34B;
vscale = 0x0; vscale = 0x0;
@ -432,17 +529,21 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_selec
break; break;
} }
for( ; decoder < decoder_count; decoder++) for (; decoder < decoder_count; decoder++) {
{
// write scaling values for each decoder // write scaling values for each decoder
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL+(0x200*decoder), hscale); ret_val =
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL+(0x200*decoder), vscale); cx25821_i2c_write(&dev->i2c_bus[0],
HSCALE_CTRL + (0x200 * decoder), hscale);
ret_val =
cx25821_i2c_write(&dev->i2c_bus[0],
VSCALE_CTRL + (0x200 * decoder), vscale);
} }
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
} }
static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int duration) static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
int duration)
{ {
int ret_val = 0; int ret_val = 0;
u32 fld_cnt = 0; u32 fld_cnt = 0;
@ -452,14 +553,12 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
// no support // no support
if (decoder < VDEC_A && decoder > VDEC_H) if (decoder < VDEC_A && decoder > VDEC_H) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return; return;
} }
switch (decoder) switch (decoder) {
{
default: default:
break; break;
case VDEC_C: case VDEC_C:
@ -485,9 +584,7 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
{ {
fld_cnt &= 0xFFFF0000; fld_cnt &= 0xFFFF0000;
fld_cnt |= duration; fld_cnt |= duration;
} } else {
else
{
fld_cnt &= 0x0000FFFF; fld_cnt &= 0x0000FFFF;
fld_cnt |= ((u32) duration) << 16; fld_cnt |= ((u32) duration) << 16;
} }
@ -499,24 +596,16 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
// Map to Medusa register setting // Map to Medusa register setting
static int mapM( static int mapM(int srcMin,
int srcMin, int srcMax, int srcVal, int dstMin, int dstMax, int *dstVal)
int srcMax,
int srcVal,
int dstMin,
int dstMax,
int* dstVal
)
{ {
int numerator; int numerator;
int denominator; int denominator;
int quotient; int quotient;
if((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax)) if ((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax)) {
{
return -1; return -1;
} }
// This is the overall expression used: // This is the overall expression used:
// *dstVal = (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin; // *dstVal = (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin;
// but we need to account for rounding so below we use the modulus // but we need to account for rounding so below we use the modulus
@ -525,8 +614,7 @@ static int mapM(
denominator = srcMax - srcMin; denominator = srcMax - srcMin;
quotient = numerator / denominator; quotient = numerator / denominator;
if(2 * ( numerator % denominator ) >= denominator) if (2 * (numerator % denominator) >= denominator) {
{
quotient++; quotient++;
} }
@ -541,13 +629,13 @@ static unsigned long convert_to_twos(long numeric, unsigned long bits_len)
if (numeric >= 0) if (numeric >= 0)
return numeric; return numeric;
else else {
{
temp = ~(abs(numeric) & 0xFF); temp = ~(abs(numeric) & 0xFF);
temp += 1; temp += 1;
return temp; return temp;
} }
} }
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder) int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
{ {
@ -556,16 +644,23 @@ int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
u32 val = 0, tmp = 0; u32 val = 0, tmp = 0;
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
if((brightness > VIDEO_PROCAMP_MAX) || (brightness < VIDEO_PROCAMP_MIN)) if ((brightness > VIDEO_PROCAMP_MAX)
{ || (brightness < VIDEO_PROCAMP_MIN)) {
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -1; return -1;
} }
ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, brightness, SIGNED_BYTE_MIN, SIGNED_BYTE_MAX, &value); ret_val =
mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, brightness,
SIGNED_BYTE_MIN, SIGNED_BYTE_MAX, &value);
value = convert_to_twos(value, 8); value = convert_to_twos(value, 8);
val = cx25821_i2c_read(&dev->i2c_bus[0], VDEC_A_BRITE_CTRL+(0x200*decoder), &tmp); val =
cx25821_i2c_read(&dev->i2c_bus[0],
VDEC_A_BRITE_CTRL + (0x200 * decoder), &tmp);
val &= 0xFFFFFF00; val &= 0xFFFFFF00;
ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], VDEC_A_BRITE_CTRL+(0x200*decoder), val | value); ret_val |=
cx25821_i2c_write(&dev->i2c_bus[0],
VDEC_A_BRITE_CTRL + (0x200 * decoder),
val | value);
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return ret_val; return ret_val;
} }
@ -579,16 +674,22 @@ int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
if((contrast > VIDEO_PROCAMP_MAX) || (contrast < VIDEO_PROCAMP_MIN)) if ((contrast > VIDEO_PROCAMP_MAX) || (contrast < VIDEO_PROCAMP_MIN)) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -1; return -1;
} }
ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, contrast, UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value); ret_val =
val = cx25821_i2c_read(&dev->i2c_bus[0], VDEC_A_CNTRST_CTRL+(0x200*decoder), &tmp); mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, contrast,
UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value);
val =
cx25821_i2c_read(&dev->i2c_bus[0],
VDEC_A_CNTRST_CTRL + (0x200 * decoder), &tmp);
val &= 0xFFFFFF00; val &= 0xFFFFFF00;
ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], VDEC_A_CNTRST_CTRL+(0x200*decoder), val | value); ret_val |=
cx25821_i2c_write(&dev->i2c_bus[0],
VDEC_A_CNTRST_CTRL + (0x200 * decoder),
val | value);
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return ret_val; return ret_val;
@ -603,25 +704,29 @@ int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
if((hue > VIDEO_PROCAMP_MAX) || (hue < VIDEO_PROCAMP_MIN)) if ((hue > VIDEO_PROCAMP_MAX) || (hue < VIDEO_PROCAMP_MIN)) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -1; return -1;
} }
ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, hue, SIGNED_BYTE_MIN, SIGNED_BYTE_MAX, &value); ret_val =
mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, hue, SIGNED_BYTE_MIN,
SIGNED_BYTE_MAX, &value);
value = convert_to_twos(value, 8); value = convert_to_twos(value, 8);
val = cx25821_i2c_read(&dev->i2c_bus[0], VDEC_A_HUE_CTRL+(0x200*decoder), &tmp); val =
cx25821_i2c_read(&dev->i2c_bus[0],
VDEC_A_HUE_CTRL + (0x200 * decoder), &tmp);
val &= 0xFFFFFF00; val &= 0xFFFFFF00;
ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], VDEC_A_HUE_CTRL+(0x200*decoder), val | value); ret_val |=
cx25821_i2c_write(&dev->i2c_bus[0],
VDEC_A_HUE_CTRL + (0x200 * decoder), val | value);
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return ret_val; return ret_val;
} }
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder) int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
{ {
@ -631,27 +736,38 @@ int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
if((saturation > VIDEO_PROCAMP_MAX) || (saturation < VIDEO_PROCAMP_MIN)) if ((saturation > VIDEO_PROCAMP_MAX)
{ || (saturation < VIDEO_PROCAMP_MIN)) {
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -1; return -1;
} }
ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, saturation, UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value); ret_val =
mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, saturation,
UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value);
val = cx25821_i2c_read(&dev->i2c_bus[0], VDEC_A_USAT_CTRL+(0x200*decoder), &tmp); val =
cx25821_i2c_read(&dev->i2c_bus[0],
VDEC_A_USAT_CTRL + (0x200 * decoder), &tmp);
val &= 0xFFFFFF00; val &= 0xFFFFFF00;
ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], VDEC_A_USAT_CTRL+(0x200*decoder), val | value); ret_val |=
cx25821_i2c_write(&dev->i2c_bus[0],
VDEC_A_USAT_CTRL + (0x200 * decoder),
val | value);
val = cx25821_i2c_read(&dev->i2c_bus[0], VDEC_A_VSAT_CTRL+(0x200*decoder), &tmp); val =
cx25821_i2c_read(&dev->i2c_bus[0],
VDEC_A_VSAT_CTRL + (0x200 * decoder), &tmp);
val &= 0xFFFFFF00; val &= 0xFFFFFF00;
ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], VDEC_A_VSAT_CTRL+(0x200*decoder), val | value); ret_val |=
cx25821_i2c_write(&dev->i2c_bus[0],
VDEC_A_VSAT_CTRL + (0x200 * decoder),
val | value);
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return ret_val; return ret_val;
} }
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
// Program the display sequence and monitor output. // Program the display sequence and monitor output.
// //
@ -665,33 +781,28 @@ int medusa_video_init(struct cx25821_dev *dev)
_num_decoders = dev->_max_num_decoders; _num_decoders = dev->_max_num_decoders;
// disable Auto source selection on all video decoders // disable Auto source selection on all video decoders
value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
value &= 0xFFFFF0FF; value &= 0xFFFFF0FF;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
// Turn off Master source switch enable // Turn off Master source switch enable
value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
value &= 0xFFFFFFDF; value &= 0xFFFFFFDF;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
for (i=0; i < _num_decoders; i++) for (i = 0; i < _num_decoders; i++) {
{
medusa_set_decoderduration(dev, i, _display_field_cnt[i]); medusa_set_decoderduration(dev, i, _display_field_cnt[i]);
} }
@ -703,64 +814,53 @@ int medusa_video_init(struct cx25821_dev *dev)
value |= 0x00090008; // set en_active value |= 0x00090008; // set en_active
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
// enable input is VIP/656 // enable input is VIP/656
value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp); value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp);
value |= 0x00040100; // enable VIP value |= 0x00040100; // enable VIP
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
// select AFE clock to output mode // select AFE clock to output mode
value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp); value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
value &= 0x83FFFFFF; value &= 0x83FFFFFF;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, value | 0x10000000); ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL,
value | 0x10000000);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
// Turn on all of the data out and control output pins. // Turn on all of the data out and control output pins.
value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp); value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp);
value &= 0xFEF0FE00; value &= 0xFEF0FE00;
if (_num_decoders == MAX_DECODERS) if (_num_decoders == MAX_DECODERS) {
{
// Note: The octal board does not support control pins(bit16-19). // Note: The octal board does not support control pins(bit16-19).
// These bits are ignored in the octal board. // These bits are ignored in the octal board.
value |= 0x010001F8; // disable VDEC A-C port, default to Mobilygen Interface value |= 0x010001F8; // disable VDEC A-C port, default to Mobilygen Interface
} } else {
else
{
value |= 0x010F0108; // disable VDEC A-C port, default to Mobilygen Interface value |= 0x010F0108; // disable VDEC A-C port, default to Mobilygen Interface
} }
value |= 7; value |= 7;
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value); ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value);
if (ret_val < 0) if (ret_val < 0) {
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
ret_val = medusa_set_videostandard(dev); ret_val = medusa_set_videostandard(dev);
if (ret_val < 0) {
if (ret_val < 0)
{
mutex_unlock(&dev->lock); mutex_unlock(&dev->lock);
return -EINVAL; return -EINVAL;
} }

View File

@ -25,7 +25,6 @@
#include "cx25821-medusa-defines.h" #include "cx25821-medusa-defines.h"
// Color control constants // Color control constants
#define VIDEO_PROCAMP_MIN 0 #define VIDEO_PROCAMP_MIN 0
#define VIDEO_PROCAMP_MAX 10000 #define VIDEO_PROCAMP_MAX 10000
@ -41,7 +40,6 @@
#define CONTRAST_DEFAULT 5000 #define CONTRAST_DEFAULT 5000
#define HUE_DEFAULT 5000 #define HUE_DEFAULT 5000
unsigned short _num_decoders; unsigned short _num_decoders;
unsigned short _num_cameras; unsigned short _num_cameras;

View File

@ -166,7 +166,6 @@
#define FLD_VID_SRC_ERRORS FLD_VID_SRC_OPC_ERR | FLD_VID_SRC_SYNC | FLD_VID_SRC_UF #define FLD_VID_SRC_ERRORS FLD_VID_SRC_OPC_ERR | FLD_VID_SRC_SYNC | FLD_VID_SRC_UF
#define FLD_VID_DST_ERRORS FLD_VID_DST_OPC_ERR | FLD_VID_DST_SYNC | FLD_VID_DST_OF #define FLD_VID_DST_ERRORS FLD_VID_DST_OPC_ERR | FLD_VID_DST_SYNC | FLD_VID_DST_OF
//***************************************************************************** //*****************************************************************************
#define AUD_A_INT_MSK 0x0400C0 // Audio Int interrupt mask #define AUD_A_INT_MSK 0x0400C0 // Audio Int interrupt mask
#define AUD_A_INT_STAT 0x0400C4 // Audio Int interrupt status #define AUD_A_INT_STAT 0x0400C4 // Audio Int interrupt status
@ -237,7 +236,6 @@
#define FLD_AUD_EXT_RISCI2 0x00000010 #define FLD_AUD_EXT_RISCI2 0x00000010
#define FLD_AUD_EXT_RISCI1 0x00000001 #define FLD_AUD_EXT_RISCI1 0x00000001
//***************************************************************************** //*****************************************************************************
#define GPIO_LO 0x110010 // Lower of GPIO pins [31:0] #define GPIO_LO 0x110010 // Lower of GPIO pins [31:0]
#define GPIO_HI 0x110014 // Upper WORD of GPIO pins [47:31] #define GPIO_HI 0x110014 // Upper WORD of GPIO pins [47:31]
@ -279,7 +277,6 @@
//***************************************************************************** //*****************************************************************************
#define TC_REQ_SET 0x040094 // Rider PCI Express traFFic class request set #define TC_REQ_SET 0x040094 // Rider PCI Express traFFic class request set
//***************************************************************************** //*****************************************************************************
// Rider // Rider
//***************************************************************************** //*****************************************************************************
@ -669,7 +666,6 @@
//***************************************************************************** //*****************************************************************************
#define DMA26_PTR1 0x100064 // DMA Current Ptr : Ch#26 #define DMA26_PTR1 0x100064 // DMA Current Ptr : Ch#26
//***************************************************************************** //*****************************************************************************
#define DMA1_PTR2 0x100080 // DMA Tab Ptr : Ch#1 #define DMA1_PTR2 0x100080 // DMA Tab Ptr : Ch#1
@ -748,8 +744,6 @@
//***************************************************************************** //*****************************************************************************
#define DMA26_PTR2 0x1000E4 // DMA Tab Ptr : Ch#26 #define DMA26_PTR2 0x1000E4 // DMA Tab Ptr : Ch#26
//***************************************************************************** //*****************************************************************************
#define DMA1_CNT1 0x100100 // DMA BuFFer Size : Ch#1 #define DMA1_CNT1 0x100100 // DMA BuFFer Size : Ch#1
@ -828,7 +822,6 @@
//***************************************************************************** //*****************************************************************************
#define DMA26_CNT1 0x100164 // DMA BuFFer Size : Ch#26 #define DMA26_CNT1 0x100164 // DMA BuFFer Size : Ch#26
//***************************************************************************** //*****************************************************************************
#define DMA1_CNT2 0x100180 // DMA Table Size : Ch#1 #define DMA1_CNT2 0x100180 // DMA Table Size : Ch#1
@ -907,8 +900,6 @@
//***************************************************************************** //*****************************************************************************
#define DMA26_CNT2 0x1001E4 // DMA Table Size : Ch#26 #define DMA26_CNT2 0x1001E4 // DMA Table Size : Ch#26
//***************************************************************************** //*****************************************************************************
// ITG // ITG
//***************************************************************************** //*****************************************************************************
@ -1070,7 +1061,6 @@
#define CLK_DELAY 0x110048 // Clock delay #define CLK_DELAY 0x110048 // Clock delay
#define FLD_MOE_CLK_DIS 0x80000000 // Disable MoE clock #define FLD_MOE_CLK_DIS 0x80000000 // Disable MoE clock
//***************************************************************************** //*****************************************************************************
#define PAD_CTRL 0x110068 // Pad drive strength control #define PAD_CTRL 0x110068 // Pad drive strength control
@ -1100,7 +1090,6 @@
#define VID_CH_MODE_SEL 0x110078 #define VID_CH_MODE_SEL 0x110078
#define VID_CH_CLK_SEL 0x11007C #define VID_CH_CLK_SEL 0x11007C
//***************************************************************************** //*****************************************************************************
#define VBI_A_DMA 0x130008 // VBI A DMA data port #define VBI_A_DMA 0x130008 // VBI A DMA data port
@ -1148,7 +1137,6 @@
#define VID_C_LNGTH 0x130250 // Video C line length #define VID_C_LNGTH 0x130250 // Video C line length
#define FLD_VID_C_LN_LNGTH 0x00000FFF #define FLD_VID_C_LN_LNGTH 0x00000FFF
//***************************************************************************** //*****************************************************************************
// Video Destination Channels // Video Destination Channels
//***************************************************************************** //*****************************************************************************
@ -1173,7 +1161,6 @@
#define VID_DST_G_GPCNT_CTL 0x130630 // Video G general purpose control #define VID_DST_G_GPCNT_CTL 0x130630 // Video G general purpose control
#define VID_DST_H_GPCNT_CTL 0x130730 // Video H general purpose control #define VID_DST_H_GPCNT_CTL 0x130730 // Video H general purpose control
//***************************************************************************** //*****************************************************************************
#define VID_DST_A_DMA_CTL 0x130040 // Video A DMA control #define VID_DST_A_DMA_CTL 0x130040 // Video A DMA control
@ -1397,7 +1384,6 @@
#define FLD_AUD_DST_B_FIFO_EN 0x00000002 #define FLD_AUD_DST_B_FIFO_EN 0x00000002
#define FLD_AUD_DST_A_FIFO_EN 0x00000001 #define FLD_AUD_DST_A_FIFO_EN 0x00000001
//***************************************************************************** //*****************************************************************************
// //
// Mobilygen Interface Registers // Mobilygen Interface Registers
@ -1475,7 +1461,6 @@
#define FLD_MB_HCMD_H_ADDR 0x00FF0000 #define FLD_MB_HCMD_H_ADDR 0x00FF0000
#define FLD_MB_HCMD_H_DATA 0x0000FFFF #define FLD_MB_HCMD_H_DATA 0x0000FFFF
//***************************************************************************** //*****************************************************************************
// I2C #1 // I2C #1
//***************************************************************************** //*****************************************************************************
@ -1605,5 +1590,3 @@
#define PIXEL_ENGINE_VIP2 1 #define PIXEL_ENGINE_VIP2 1
#endif //Athena_REGISTERS #endif //Athena_REGISTERS

View File

@ -47,7 +47,6 @@
#define AUDIO_CLUSTER_SIZE 128 // AUDIO cluster data line #define AUDIO_CLUSTER_SIZE 128 // AUDIO cluster data line
#define MBIF_CLUSTER_SIZE 1440 // MBIF/HBI cluster data line #define MBIF_CLUSTER_SIZE 1440 // MBIF/HBI cluster data line
//#define TX_SRAM_POOL_FREE_SIZE = 704; // Start of available TX SRAM //#define TX_SRAM_POOL_FREE_SIZE = 704; // Start of available TX SRAM
//#define TX_SRAM_END_SIZE = 0; // End of TX SRAM //#define TX_SRAM_END_SIZE = 0; // End of TX SRAM
@ -181,7 +180,6 @@
// Free Receive SRAM 144 Bytes // Free Receive SRAM 144 Bytes
// Transmit SRAM // Transmit SRAM
#define TX_SRAM_POOL_START 0x00000 #define TX_SRAM_POOL_START 0x00000
@ -244,7 +242,6 @@
#define TX_SRAM_POOL_FREE 0x0BB00 #define TX_SRAM_POOL_FREE 0x0BB00
#define TX_SRAM_END 0x0C000 #define TX_SRAM_END 0x0C000
#define BYTES_TO_DWORDS(bcount) ((bcount) >> 2) #define BYTES_TO_DWORDS(bcount) ((bcount) >> 2)
#define BYTES_TO_QWORDS(bcount) ((bcount) >> 3) #define BYTES_TO_QWORDS(bcount) ((bcount) >> 3)
#define BYTES_TO_OWORDS(bcount) ((bcount) >> 4) #define BYTES_TO_OWORDS(bcount) ((bcount) >> 4)
@ -261,6 +258,4 @@
#define MBIF_CDT_SIZE_QW BYTES_TO_QWORDS(MBIF_CDT_SIZE) #define MBIF_CDT_SIZE_QW BYTES_TO_QWORDS(MBIF_CDT_SIZE)
#define MBIF_CLUSTER_SIZE_OW BYTES_TO_OWORDS(MBIF_CLUSTER_SIZE) #define MBIF_CLUSTER_SIZE_OW BYTES_TO_OWORDS(MBIF_CLUSTER_SIZE)
#endif #endif

View File

@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "cx25821-video.h" #include "cx25821-video.h"
#include "cx25821-video-upstream-ch2.h" #include "cx25821-video-upstream-ch2.h"
@ -34,43 +33,39 @@
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int _intr_msk =
static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR; FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR;
static __le32 *cx25821_update_riscprogram_ch2(struct cx25821_dev *dev, static __le32 *cx25821_update_riscprogram_ch2(struct cx25821_dev *dev,
__le32 *rp, unsigned int offset, unsigned int bpl, __le32 * rp, unsigned int offset,
u32 sync_line, unsigned int lines, int fifo_enable, int field_type) unsigned int bpl, u32 sync_line,
unsigned int lines,
int fifo_enable, int field_type)
{ {
unsigned int line, i; unsigned int line, i;
int dist_betwn_starts = bpl * 2; int dist_betwn_starts = bpl * 2;
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
if (USE_RISC_NOOP_VIDEO) {
if( USE_RISC_NOOP_VIDEO ) for (i = 0; i < NUM_NO_OPS; i++) {
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP); *(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
/* scan lines */ /* scan lines */
for (line = 0; line < lines; line++) for (line = 0; line < lines; line++) {
{
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(dev->_data_buf_phys_addr_ch2 + offset); *(rp++) = cpu_to_le32(dev->_data_buf_phys_addr_ch2 + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
if ( (lines <= NTSC_FIELD_HEIGHT) || (line < (NTSC_FIELD_HEIGHT-1)) || !(dev->_isNTSC_ch2) ) if ((lines <= NTSC_FIELD_HEIGHT)
{ || (line < (NTSC_FIELD_HEIGHT - 1))
|| !(dev->_isNTSC_ch2)) {
offset += dist_betwn_starts; offset += dist_betwn_starts;
} }
} }
@ -81,47 +76,42 @@ static __le32 *cx25821_update_riscprogram_ch2( struct cx25821_dev *dev,
static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev, static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
__le32 * rp, __le32 * rp,
dma_addr_t databuf_phys_addr, dma_addr_t databuf_phys_addr,
unsigned int offset, u32 sync_line, unsigned int bpl, unsigned int offset,
unsigned int lines, int fifo_enable, int field_type) u32 sync_line, unsigned int bpl,
unsigned int lines,
int fifo_enable, int field_type)
{ {
unsigned int line, i; unsigned int line, i;
struct sram_channel *sram_ch = &dev->sram_channels[dev->_channel2_upstream_select]; struct sram_channel *sram_ch =
&dev->sram_channels[dev->_channel2_upstream_select];
int dist_betwn_starts = bpl * 2; int dist_betwn_starts = bpl * 2;
/* sync instruction */ /* sync instruction */
if (sync_line != NO_SYNC_LINE) if (sync_line != NO_SYNC_LINE) {
{
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
} }
if (USE_RISC_NOOP_VIDEO) {
if( USE_RISC_NOOP_VIDEO ) for (i = 0; i < NUM_NO_OPS; i++) {
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP); *(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
/* scan lines */ /* scan lines */
for (line = 0; line < lines; line++) for (line = 0; line < lines; line++) {
{
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset); *(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
if ((lines <= NTSC_FIELD_HEIGHT)
if ( (lines <= NTSC_FIELD_HEIGHT) || (line < (NTSC_FIELD_HEIGHT-1)) || !(dev->_isNTSC_ch2) ) || (line < (NTSC_FIELD_HEIGHT - 1))
{ || !(dev->_isNTSC_ch2)) {
offset += dist_betwn_starts; offset += dist_betwn_starts;
} }
// check if we need to enable the FIFO after the first 4 lines // check if we need to enable the FIFO after the first 4 lines
// For the upstream video channel, the risc engine will enable the FIFO. // For the upstream video channel, the risc engine will enable the FIFO.
if ( fifo_enable && line == 3 ) if (fifo_enable && line == 3) {
{
*(rp++) = RISC_WRITECR; *(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl; *(rp++) = sram_ch->dma_ctl;
*(rp++) = FLD_VID_FIFO_EN; *(rp++) = FLD_VID_FIFO_EN;
@ -132,9 +122,10 @@ static __le32 *cx25821_risc_field_upstream_ch2( struct cx25821_dev *dev,
return rp; return rp;
} }
int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *pci, int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
unsigned int top_offset, struct pci_dev *pci,
unsigned int bpl, unsigned int lines) unsigned int top_offset, unsigned int bpl,
unsigned int lines)
{ {
__le32 *rp; __le32 *rp;
int fifo_enable = 0; int fifo_enable = 0;
@ -148,53 +139,58 @@ int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *p
unsigned int bottom_offset = bpl; unsigned int bottom_offset = bpl;
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
if (dev->_isNTSC_ch2) {
if( dev->_isNTSC_ch2 )
{
odd_num_lines = singlefield_lines + 1; odd_num_lines = singlefield_lines + 1;
risc_program_size = FRAME1_VID_PROG_SIZE; risc_program_size = FRAME1_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; frame_size =
} (bpl ==
else Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
{ FRAME_SIZE_NTSC_Y422;
} else {
risc_program_size = PAL_VID_PROG_SIZE; risc_program_size = PAL_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; frame_size =
(bpl ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
} }
/* Virtual address of Risc buffer program */ /* Virtual address of Risc buffer program */
rp = dev->_dma_virt_addr_ch2; rp = dev->_dma_virt_addr_ch2;
for( frame = 0; frame < NUM_FRAMES; frame++ ) for (frame = 0; frame < NUM_FRAMES; frame++) {
{
databuf_offset = frame_size * frame; databuf_offset = frame_size * frame;
if (UNSET != top_offset) {
if (UNSET != top_offset)
{
fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE; fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE;
rp = cx25821_risc_field_upstream_ch2(dev, rp, dev->_data_buf_phys_addr_ch2 + databuf_offset, top_offset, 0, bpl, odd_num_lines, fifo_enable, ODD_FIELD); rp = cx25821_risc_field_upstream_ch2(dev, rp,
dev->
_data_buf_phys_addr_ch2
+ databuf_offset,
top_offset, 0, bpl,
odd_num_lines,
fifo_enable,
ODD_FIELD);
} }
fifo_enable = FIFO_DISABLE; fifo_enable = FIFO_DISABLE;
//Even field //Even field
rp = cx25821_risc_field_upstream_ch2(dev, rp, dev->_data_buf_phys_addr_ch2 + databuf_offset, bottom_offset, 0x200, bpl, singlefield_lines, fifo_enable, EVEN_FIELD); rp = cx25821_risc_field_upstream_ch2(dev, rp,
dev->
_data_buf_phys_addr_ch2 +
databuf_offset,
bottom_offset, 0x200, bpl,
singlefield_lines,
fifo_enable, EVEN_FIELD);
if (frame == 0) {
if( frame == 0 )
{
risc_flag = RISC_CNT_RESET; risc_flag = RISC_CNT_RESET;
risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2 + risc_program_size; risc_phys_jump_addr =
} dev->_dma_phys_start_addr_ch2 + risc_program_size;
else } else {
{
risc_flag = RISC_CNT_INC; risc_flag = RISC_CNT_INC;
risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2; risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2;
} }
// Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ // Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ
*(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
*(rp++) = cpu_to_le32(risc_phys_jump_addr); *(rp++) = cpu_to_le32(risc_phys_jump_addr);
@ -204,18 +200,17 @@ int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *p
return 0; return 0;
} }
void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev) void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
{ {
struct sram_channel *sram_ch = &dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_J]; struct sram_channel *sram_ch =
&dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_J];
u32 tmp = 0; u32 tmp = 0;
if( !dev->_is_running_ch2 ) if (!dev->_is_running_ch2) {
{ printk
printk("cx25821: No video file is currently running so return!\n"); ("cx25821: No video file is currently running so return!\n");
return; return;
} }
//Disable RISC interrupts //Disable RISC interrupts
tmp = cx_read(sram_ch->int_msk); tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp & ~_intr_msk); cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
@ -226,15 +221,15 @@ void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
//Clear data buffer memory //Clear data buffer memory
if (dev->_data_buf_virt_addr_ch2) if (dev->_data_buf_virt_addr_ch2)
memset( dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2 ); memset(dev->_data_buf_virt_addr_ch2, 0,
dev->_data_buf_size_ch2);
dev->_is_running_ch2 = 0; dev->_is_running_ch2 = 0;
dev->_is_first_frame_ch2 = 0; dev->_is_first_frame_ch2 = 0;
dev->_frame_count_ch2 = 0; dev->_frame_count_ch2 = 0;
dev->_file_status_ch2 = END_OF_FILE; dev->_file_status_ch2 = END_OF_FILE;
if( dev->_irq_queues_ch2 ) if (dev->_irq_queues_ch2) {
{
kfree(dev->_irq_queues_ch2); kfree(dev->_irq_queues_ch2);
dev->_irq_queues_ch2 = NULL; dev->_irq_queues_ch2 = NULL;
} }
@ -248,31 +243,33 @@ void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev) void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev)
{ {
if( dev->_is_running_ch2 ) if (dev->_is_running_ch2) {
{
cx25821_stop_upstream_video_ch2(dev); cx25821_stop_upstream_video_ch2(dev);
} }
if (dev->_dma_virt_addr_ch2) if (dev->_dma_virt_addr_ch2) {
{ pci_free_consistent(dev->pci, dev->_risc_size_ch2,
pci_free_consistent(dev->pci, dev->_risc_size_ch2, dev->_dma_virt_addr_ch2, dev->_dma_phys_addr_ch2); dev->_dma_virt_addr_ch2,
dev->_dma_phys_addr_ch2);
dev->_dma_virt_addr_ch2 = NULL; dev->_dma_virt_addr_ch2 = NULL;
} }
if (dev->_data_buf_virt_addr_ch2) if (dev->_data_buf_virt_addr_ch2) {
{ pci_free_consistent(dev->pci, dev->_data_buf_size_ch2,
pci_free_consistent(dev->pci, dev->_data_buf_size_ch2, dev->_data_buf_virt_addr_ch2, dev->_data_buf_phys_addr_ch2); dev->_data_buf_virt_addr_ch2,
dev->_data_buf_phys_addr_ch2);
dev->_data_buf_virt_addr_ch2 = NULL; dev->_data_buf_virt_addr_ch2 = NULL;
} }
} }
int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch) int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int frame_index_temp = dev->_frame_index_ch2; int frame_index_temp = dev->_frame_index_ch2;
int i = 0; int i = 0;
int line_size = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; int line_size =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ;
int frame_size = 0; int frame_size = 0;
int frame_offset = 0; int frame_offset = 0;
ssize_t vfs_read_retval = 0; ssize_t vfs_read_retval = 0;
@ -281,45 +278,41 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch
loff_t pos; loff_t pos;
mm_segment_t old_fs; mm_segment_t old_fs;
if (dev->_file_status_ch2 == END_OF_FILE) if (dev->_file_status_ch2 == END_OF_FILE)
return 0; return 0;
if( dev->_isNTSC_ch2 ) if (dev->_isNTSC_ch2) {
{ frame_size =
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; (line_size ==
} Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
else FRAME_SIZE_NTSC_Y422;
{ } else {
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
} }
frame_offset = (frame_index_temp > 0) ? frame_size : 0; frame_offset = (frame_index_temp > 0) ? frame_size : 0;
file_offset = dev->_frame_count_ch2 * frame_size; file_offset = dev->_frame_count_ch2 * frame_size;
myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_filename_ch2, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_filename_ch2, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered!",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk("%s: File has no READ operations registered!",
{ __func__);
printk("%s: File has no READ operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -328,24 +321,26 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (i = 0; i < dev->_lines_count_ch2; i++) {
for( i = 0; i < dev->_lines_count_ch2; i++ )
{
pos = file_offset; pos = file_offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_data_buf_virt_addr_ch2 != NULL ) if (vfs_read_retval > 0 && vfs_read_retval == line_size
{ && dev->_data_buf_virt_addr_ch2 != NULL) {
memcpy( (void*)(dev->_data_buf_virt_addr_ch2+frame_offset/4), mybuf, vfs_read_retval); memcpy((void *)(dev->_data_buf_virt_addr_ch2 +
frame_offset / 4), mybuf,
vfs_read_retval);
} }
file_offset += vfs_read_retval; file_offset += vfs_read_retval;
frame_offset += vfs_read_retval; frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break; break;
} }
} }
@ -353,8 +348,8 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch
if (i > 0) if (i > 0)
dev->_frame_count_ch2++; dev->_frame_count_ch2++;
dev->_file_status_ch2 = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; dev->_file_status_ch2 =
(vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
filp_close(myfile, NULL); filp_close(myfile, NULL);
@ -365,52 +360,52 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch
static void cx25821_vidups_handler_ch2(struct work_struct *work) static void cx25821_vidups_handler_ch2(struct work_struct *work)
{ {
struct cx25821_dev *dev = container_of(work, struct cx25821_dev, _irq_work_entry_ch2); struct cx25821_dev *dev =
container_of(work, struct cx25821_dev, _irq_work_entry_ch2);
if( !dev ) if (!dev) {
{ printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ ); __func__);
return; return;
} }
cx25821_get_frame_ch2( dev, &dev->sram_channels[dev->_channel2_upstream_select] ); cx25821_get_frame_ch2(dev,
&dev->sram_channels[dev->
_channel2_upstream_select]);
} }
int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch) int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int i = 0, j = 0; int i = 0, j = 0;
int line_size = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; int line_size =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ;
ssize_t vfs_read_retval = 0; ssize_t vfs_read_retval = 0;
char mybuf[line_size]; char mybuf[line_size];
loff_t pos; loff_t pos;
loff_t offset = (unsigned long)0; loff_t offset = (unsigned long)0;
mm_segment_t old_fs; mm_segment_t old_fs;
myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_filename_ch2, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_filename_ch2, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered!",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk
{ ("%s: File has no READ operations registered! Returning.",
printk("%s: File has no READ operations registered! Returning.", __func__); __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -419,26 +414,28 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (j = 0; j < NUM_FRAMES; j++) {
for( j = 0; j < NUM_FRAMES; j++ ) for (i = 0; i < dev->_lines_count_ch2; i++) {
{
for( i = 0; i < dev->_lines_count_ch2; i++ )
{
pos = offset; pos = offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_data_buf_virt_addr_ch2 != NULL ) if (vfs_read_retval > 0
{ && vfs_read_retval == line_size
memcpy( (void*)(dev->_data_buf_virt_addr_ch2+offset/4), mybuf, vfs_read_retval); && dev->_data_buf_virt_addr_ch2 != NULL) {
memcpy((void *)(dev->
_data_buf_virt_addr_ch2
+ offset / 4), mybuf,
vfs_read_retval);
} }
offset += vfs_read_retval; offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break; break;
} }
} }
@ -446,13 +443,13 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
if (i > 0) if (i > 0)
dev->_frame_count_ch2++; dev->_frame_count_ch2++;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{
break; break;
} }
} }
dev->_file_status_ch2 = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; dev->_file_status_ch2 =
(vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
myfile->f_pos = 0; myfile->f_pos = 0;
@ -462,7 +459,6 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
return 0; return 0;
} }
static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev, static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
struct sram_channel *sram_ch, struct sram_channel *sram_ch,
int bpl) int bpl)
@ -471,61 +467,61 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
dma_addr_t dma_addr; dma_addr_t dma_addr;
dma_addr_t data_dma_addr; dma_addr_t data_dma_addr;
if (dev->_dma_virt_addr_ch2 != NULL) {
if( dev->_dma_virt_addr_ch2 != NULL ) pci_free_consistent(dev->pci, dev->upstream_riscbuf_size_ch2,
{ dev->_dma_virt_addr_ch2,
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size_ch2, dev->_dma_virt_addr_ch2, dev->_dma_phys_addr_ch2); dev->_dma_phys_addr_ch2);
} }
dev->_dma_virt_addr_ch2 = pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size_ch2, &dma_addr); dev->_dma_virt_addr_ch2 =
pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size_ch2,
&dma_addr);
dev->_dma_virt_start_addr_ch2 = dev->_dma_virt_addr_ch2; dev->_dma_virt_start_addr_ch2 = dev->_dma_virt_addr_ch2;
dev->_dma_phys_start_addr_ch2 = dma_addr; dev->_dma_phys_start_addr_ch2 = dma_addr;
dev->_dma_phys_addr_ch2 = dma_addr; dev->_dma_phys_addr_ch2 = dma_addr;
dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2; dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2;
if (!dev->_dma_virt_addr_ch2) {
if (!dev->_dma_virt_addr_ch2) printk
{ ("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
printk("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
return -ENOMEM; return -ENOMEM;
} }
//Iniitize at this address until n bytes to 0 //Iniitize at this address until n bytes to 0
memset(dev->_dma_virt_addr_ch2, 0, dev->_risc_size_ch2); memset(dev->_dma_virt_addr_ch2, 0, dev->_risc_size_ch2);
if (dev->_data_buf_virt_addr_ch2 != NULL) {
if( dev->_data_buf_virt_addr_ch2 != NULL ) pci_free_consistent(dev->pci, dev->upstream_databuf_size_ch2,
{ dev->_data_buf_virt_addr_ch2,
pci_free_consistent(dev->pci, dev->upstream_databuf_size_ch2, dev->_data_buf_virt_addr_ch2, dev->_data_buf_phys_addr_ch2); dev->_data_buf_phys_addr_ch2);
} }
//For Video Data buffer allocation //For Video Data buffer allocation
dev->_data_buf_virt_addr_ch2 = pci_alloc_consistent(dev->pci, dev->upstream_databuf_size_ch2, &data_dma_addr); dev->_data_buf_virt_addr_ch2 =
pci_alloc_consistent(dev->pci, dev->upstream_databuf_size_ch2,
&data_dma_addr);
dev->_data_buf_phys_addr_ch2 = data_dma_addr; dev->_data_buf_phys_addr_ch2 = data_dma_addr;
dev->_data_buf_size_ch2 = dev->upstream_databuf_size_ch2; dev->_data_buf_size_ch2 = dev->upstream_databuf_size_ch2;
if (!dev->_data_buf_virt_addr_ch2) if (!dev->_data_buf_virt_addr_ch2) {
{ printk
printk("cx25821: FAILED to allocate memory for data buffer! Returning.\n"); ("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
return -ENOMEM; return -ENOMEM;
} }
//Initialize at this address until n bytes to 0 //Initialize at this address until n bytes to 0
memset(dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2); memset(dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2);
ret = cx25821_openfile_ch2(dev, sram_ch); ret = cx25821_openfile_ch2(dev, sram_ch);
if (ret < 0) if (ret < 0)
return ret; return ret;
//Creating RISC programs //Creating RISC programs
ret = cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl, dev->_lines_count_ch2 ); ret =
if (ret < 0) cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl,
{ dev->_lines_count_ch2);
printk(KERN_INFO "cx25821: Failed creating Video Upstream Risc programs! \n"); if (ret < 0) {
printk(KERN_INFO
"cx25821: Failed creating Video Upstream Risc programs! \n");
goto error; goto error;
} }
@ -535,7 +531,8 @@ error:
return ret; return ret;
} }
int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 status) int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
u32 status)
{ {
u32 int_msk_tmp; u32 int_msk_tmp;
struct sram_channel *channel = &dev->sram_channels[chan_num]; struct sram_channel *channel = &dev->sram_channels[chan_num];
@ -545,10 +542,7 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 st
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
__le32 *rp; __le32 *rp;
if (status & FLD_VID_SRC_RISC1) {
if (status & FLD_VID_SRC_RISC1)
{
// We should only process one program per call // We should only process one program per call
u32 prog_cnt = cx_read(channel->gpcnt); u32 prog_cnt = cx_read(channel->gpcnt);
@ -563,29 +557,35 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 st
queue_work(dev->_irq_queues_ch2, &dev->_irq_work_entry_ch2); queue_work(dev->_irq_queues_ch2, &dev->_irq_work_entry_ch2);
if (dev->_is_first_frame_ch2) {
if ( dev->_is_first_frame_ch2 )
{
dev->_is_first_frame_ch2 = 0; dev->_is_first_frame_ch2 = 0;
if( dev->_isNTSC_ch2 ) if (dev->_isNTSC_ch2) {
{
singlefield_lines += 1; singlefield_lines += 1;
odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE; odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
} } else {
else
{
singlefield_lines = PAL_FIELD_HEIGHT; singlefield_lines = PAL_FIELD_HEIGHT;
odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE; odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE;
} }
if (dev->_dma_virt_start_addr_ch2 != NULL) {
line_size_in_bytes =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? Y411_LINE_SZ :
Y422_LINE_SZ;
risc_phys_jump_addr =
dev->_dma_phys_start_addr_ch2 +
odd_risc_prog_size;
if( dev->_dma_virt_start_addr_ch2 != NULL ) rp = cx25821_update_riscprogram_ch2(dev,
{ dev->
line_size_in_bytes = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; _dma_virt_start_addr_ch2,
risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2 + odd_risc_prog_size; TOP_OFFSET,
line_size_in_bytes,
rp = cx25821_update_riscprogram_ch2(dev, dev->_dma_virt_start_addr_ch2, TOP_OFFSET, line_size_in_bytes, 0x0, singlefield_lines, FIFO_DISABLE, ODD_FIELD); 0x0,
singlefield_lines,
FIFO_DISABLE,
ODD_FIELD);
// Jump to Even Risc program of 1st Frame // Jump to Even Risc program of 1st Frame
*(rp++) = cpu_to_le32(RISC_JUMP); *(rp++) = cpu_to_le32(RISC_JUMP);
@ -597,13 +597,11 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 st
spin_unlock(&dev->slock); spin_unlock(&dev->slock);
} }
if (dev->_file_status_ch2 == END_OF_FILE) {
if( dev->_file_status_ch2 == END_OF_FILE ) printk("cx25821: EOF Channel 2 Framecount = %d\n",
{ dev->_frame_count_ch2);
printk("cx25821: EOF Channel 2 Framecount = %d\n", dev->_frame_count_ch2 );
return -1; return -1;
} }
//ElSE, set the interrupt mask register, re-enable irq. //ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read(channel->int_msk); int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
@ -619,7 +617,6 @@ static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
int channel_num = 0; int channel_num = 0;
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
if (!dev) if (!dev)
return -1; return -1;
@ -631,26 +628,23 @@ static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
vid_status = cx_read(sram_ch->int_stat); vid_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt // Only deal with our interrupt
if(vid_status) if (vid_status) {
{ handled =
handled = cx25821_video_upstream_irq_ch2(dev, channel_num, vid_status); cx25821_video_upstream_irq_ch2(dev, channel_num,
vid_status);
} }
if (handled < 0) {
if( handled < 0 )
{
cx25821_stop_upstream_video_ch2(dev); cx25821_stop_upstream_video_ch2(dev);
} } else {
else
{
handled += handled; handled += handled;
} }
return IRQ_RETVAL(handled); return IRQ_RETVAL(handled);
} }
static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_channel *ch, int pix_format) struct sram_channel *ch, int pix_format)
{ {
int width = WIDTH_D1; int width = WIDTH_D1;
int height = dev->_lines_count_ch2; int height = dev->_lines_count_ch2;
@ -658,7 +652,6 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_cha
u32 value; u32 value;
int vip_mode = PIXEL_ENGINE_VIP1; int vip_mode = PIXEL_ENGINE_VIP1;
value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7); value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7);
value &= 0xFFFFFFEF; value &= 0xFFFFFFEF;
value |= dev->_isNTSC_ch2 ? 0 : 0x10; value |= dev->_isNTSC_ch2 ? 0 : 0x10;
@ -670,8 +663,7 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_cha
num_lines = (height / 2) & 0x3FF; num_lines = (height / 2) & 0x3FF;
odd_num_lines = num_lines; odd_num_lines = num_lines;
if(dev->_isNTSC_ch2) if (dev->_isNTSC_ch2) {
{
odd_num_lines += 1; odd_num_lines += 1;
} }
@ -683,19 +675,16 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_cha
cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3); cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
} }
int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev, int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
struct sram_channel *sram_ch) struct sram_channel *sram_ch)
{ {
u32 tmp = 0; u32 tmp = 0;
int err = 0; int err = 0;
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read(VID_CH_MODE_SEL); tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
// Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds. // Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds.
cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2); cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2);
cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */ cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
@ -706,20 +695,19 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
// Clear our bits from the interrupt status register. // Clear our bits from the interrupt status register.
cx_write(sram_ch->int_stat, _intr_msk); cx_write(sram_ch->int_stat, _intr_msk);
//Set the interrupt mask register, enable irq. //Set the interrupt mask register, enable irq.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read(sram_ch->int_msk); tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk); cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
err = request_irq(dev->pci->irq, cx25821_upstream_irq_ch2, IRQF_SHARED | IRQF_DISABLED, dev->name, dev); request_irq(dev->pci->irq, cx25821_upstream_irq_ch2,
if (err < 0) IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
{ if (err < 0) {
printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, dev->pci->irq); printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name,
dev->pci->irq);
goto fail_irq; goto fail_irq;
} }
// Start the DMA engine // Start the DMA engine
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN); cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
@ -729,14 +717,13 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
return 0; return 0;
fail_irq: fail_irq:
cx25821_dev_unregister(dev); cx25821_dev_unregister(dev);
return err; return err;
} }
int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, int pixel_format) int pixel_format)
{ {
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
u32 tmp; u32 tmp;
@ -746,8 +733,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, in
int risc_buffer_size = 0; int risc_buffer_size = 0;
int str_length = 0; int str_length = 0;
if( dev->_is_running_ch2 ) if (dev->_is_running_ch2) {
{
printk("Video Channel is still running so return!\n"); printk("Video Channel is still running so return!\n");
return 0; return 0;
} }
@ -755,69 +741,71 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, in
dev->_channel2_upstream_select = channel_select; dev->_channel2_upstream_select = channel_select;
sram_ch = &dev->sram_channels[channel_select]; sram_ch = &dev->sram_channels[channel_select];
INIT_WORK(&dev->_irq_work_entry_ch2, cx25821_vidups_handler_ch2); INIT_WORK(&dev->_irq_work_entry_ch2, cx25821_vidups_handler_ch2);
dev->_irq_queues_ch2 = create_singlethread_workqueue("cx25821_workqueue2"); dev->_irq_queues_ch2 =
create_singlethread_workqueue("cx25821_workqueue2");
if(!dev->_irq_queues_ch2) if (!dev->_irq_queues_ch2) {
{ printk
printk("cx25821: create_singlethread_workqueue() for Video FAILED!\n"); ("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
return -ENOMEM; return -ENOMEM;
} }
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read(VID_CH_MODE_SEL); tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
dev->_is_running_ch2 = 0; dev->_is_running_ch2 = 0;
dev->_frame_count_ch2 = 0; dev->_frame_count_ch2 = 0;
dev->_file_status_ch2 = RESET_STATUS; dev->_file_status_ch2 = RESET_STATUS;
dev->_lines_count_ch2 = dev->_isNTSC_ch2 ? 480 : 576; dev->_lines_count_ch2 = dev->_isNTSC_ch2 ? 480 : 576;
dev->_pixel_format_ch2 = pixel_format; dev->_pixel_format_ch2 = pixel_format;
dev->_line_size_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; dev->_line_size_ch2 =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
data_frame_size = dev->_isNTSC_ch2 ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ; data_frame_size = dev->_isNTSC_ch2 ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ;
risc_buffer_size = dev->_isNTSC_ch2 ? NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE; risc_buffer_size =
dev->_isNTSC_ch2 ? NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE;
if (dev->input_filename_ch2) {
if( dev->input_filename_ch2 )
{
str_length = strlen(dev->input_filename_ch2); str_length = strlen(dev->input_filename_ch2);
dev->_filename_ch2 = (char *) kmalloc(str_length + 1, GFP_KERNEL); dev->_filename_ch2 =
(char *)kmalloc(str_length + 1, GFP_KERNEL);
if (!dev->_filename_ch2) if (!dev->_filename_ch2)
goto error; goto error;
memcpy(dev->_filename_ch2, dev->input_filename_ch2, str_length + 1); memcpy(dev->_filename_ch2, dev->input_filename_ch2,
} str_length + 1);
else } else {
{
str_length = strlen(dev->_defaultname_ch2); str_length = strlen(dev->_defaultname_ch2);
dev->_filename_ch2 = (char *) kmalloc(str_length + 1, GFP_KERNEL); dev->_filename_ch2 =
(char *)kmalloc(str_length + 1, GFP_KERNEL);
if (!dev->_filename_ch2) if (!dev->_filename_ch2)
goto error; goto error;
memcpy(dev->_filename_ch2, dev->_defaultname_ch2, str_length + 1); memcpy(dev->_filename_ch2, dev->_defaultname_ch2,
str_length + 1);
} }
//Default if filename is empty string //Default if filename is empty string
if( strcmp(dev->input_filename_ch2,"") == 0) if (strcmp(dev->input_filename_ch2, "") == 0) {
{ if (dev->_isNTSC_ch2) {
if( dev->_isNTSC_ch2 ) dev->_filename_ch2 =
{ (dev->_pixel_format_ch2 ==
dev->_filename_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? "/root/vid411.yuv" : "/root/vidtest.yuv"; PIXEL_FRMT_411) ? "/root/vid411.yuv" :
} "/root/vidtest.yuv";
else } else {
{ dev->_filename_ch2 =
dev->_filename_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? "/root/pal411.yuv" : "/root/pal422.yuv"; (dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? "/root/pal411.yuv" :
"/root/pal422.yuv";
} }
} }
retval =
retval = cx25821_sram_channel_setup_upstream(dev, sram_ch, dev->_line_size_ch2, 0); cx25821_sram_channel_setup_upstream(dev, sram_ch,
dev->_line_size_ch2, 0);
/* setup fifo + format */ /* setup fifo + format */
cx25821_set_pixelengine_ch2(dev, sram_ch, dev->_pixel_format_ch2); cx25821_set_pixelengine_ch2(dev, sram_ch, dev->_pixel_format_ch2);
@ -825,16 +813,17 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, in
dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2; dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2;
dev->upstream_databuf_size_ch2 = data_frame_size * 2; dev->upstream_databuf_size_ch2 = data_frame_size * 2;
//Allocating buffers and prepare RISC program //Allocating buffers and prepare RISC program
retval = cx25821_upstream_buffer_prepare_ch2(dev, sram_ch, dev->_line_size_ch2); retval =
if (retval < 0) cx25821_upstream_buffer_prepare_ch2(dev, sram_ch,
{ dev->_line_size_ch2);
printk(KERN_ERR "%s: Failed to set up Video upstream buffers!\n", dev->name); if (retval < 0) {
printk(KERN_ERR
"%s: Failed to set up Video upstream buffers!\n",
dev->name);
goto error; goto error;
} }
cx25821_start_video_dma_upstream_ch2(dev, sram_ch); cx25821_start_video_dma_upstream_ch2(dev, sram_ch);
return 0; return 0;
@ -844,4 +833,3 @@ error:
return err; return err;
} }

View File

@ -23,7 +23,6 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#define OPEN_FILE_1 0 #define OPEN_FILE_1 0
#define NUM_PROGS 8 #define NUM_PROGS 8
#define NUM_FRAMES 2 #define NUM_FRAMES 2
@ -38,8 +37,6 @@
#define RESET_STATUS -1 #define RESET_STATUS -1
#define NUM_NO_OPS 5 #define NUM_NO_OPS 5
// PAL and NTSC line sizes and number of lines. // PAL and NTSC line sizes and number of lines.
#define WIDTH_D1 720 #define WIDTH_D1 720
#define NTSC_LINES_PER_FRAME 480 #define NTSC_LINES_PER_FRAME 480
@ -65,8 +62,6 @@
#define MAXSIZE_NO_OPS 36 #define MAXSIZE_NO_OPS 36
#define DWORD_SIZE 4 #define DWORD_SIZE 4
#define USE_RISC_NOOP_VIDEO 1 #define USE_RISC_NOOP_VIDEO 1
#ifdef USE_RISC_NOOP_VIDEO #ifdef USE_RISC_NOOP_VIDEO
@ -92,7 +87,6 @@
RISC_WRITECR_INSTRUCTION_SIZE + NUM_NO_OPS*DWORD_SIZE) RISC_WRITECR_INSTRUCTION_SIZE + NUM_NO_OPS*DWORD_SIZE)
#endif #endif
#ifndef USE_RISC_NOOP_VIDEO #ifndef USE_RISC_NOOP_VIDEO
#define PAL_US_VID_PROG_SIZE ((PAL_FIELD_HEIGHT + 1) * 3 * DWORD_SIZE + RISC_WRITECR_INSTRUCTION_SIZE ) #define PAL_US_VID_PROG_SIZE ((PAL_FIELD_HEIGHT + 1) * 3 * DWORD_SIZE + RISC_WRITECR_INSTRUCTION_SIZE )
#define PAL_RISC_BUF_SIZE ( 2 * (RISC_SYNC_INSTRUCTION_SIZE + PAL_US_VID_PROG_SIZE) ) #define PAL_RISC_BUF_SIZE ( 2 * (RISC_SYNC_INSTRUCTION_SIZE + PAL_US_VID_PROG_SIZE) )

View File

@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "cx25821-video.h" #include "cx25821-video.h"
#include "cx25821-video-upstream.h" #include "cx25821-video-upstream.h"
@ -34,13 +33,12 @@
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int _intr_msk =
static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR; FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR;
int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev, int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
struct sram_channel *ch, struct sram_channel *ch,
@ -49,7 +47,6 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
unsigned int i, lines; unsigned int i, lines;
u32 cdt; u32 cdt;
if (ch->cmds_start == 0) { if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0); cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0); cx_write(ch->ptr2_reg, 0);
@ -62,14 +59,12 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
cdt = ch->cdt; cdt = ch->cdt;
lines = ch->fifo_size / bpl; lines = ch->fifo_size / bpl;
if (lines > 4) if (lines > 4) {
{
lines = 4; lines = 4;
} }
BUG_ON(lines < 2); BUG_ON(lines < 2);
/* write CDT */ /* write CDT */
for (i = 0; i < lines; i++) { for (i = 0; i < lines; i++) {
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i); cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
@ -86,7 +81,6 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
cx_write(ch->cmds_start + 12, (lines * 16) >> 3); cx_write(ch->cmds_start + 12, (lines * 16) >> 3);
cx_write(ch->cmds_start + 16, ch->ctrl_start); cx_write(ch->cmds_start + 16, ch->ctrl_start);
cx_write(ch->cmds_start + 20, VID_IQ_SIZE_DW); cx_write(ch->cmds_start + 20, VID_IQ_SIZE_DW);
for (i = 24; i < 80; i += 4) for (i = 24; i < 80; i += 4)
@ -102,33 +96,30 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
} }
static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev, static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
__le32 *rp, unsigned int offset, unsigned int bpl, __le32 * rp, unsigned int offset,
u32 sync_line, unsigned int lines, int fifo_enable, int field_type) unsigned int bpl, u32 sync_line,
unsigned int lines, int fifo_enable,
int field_type)
{ {
unsigned int line, i; unsigned int line, i;
int dist_betwn_starts = bpl * 2; int dist_betwn_starts = bpl * 2;
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
if (USE_RISC_NOOP_VIDEO) {
if( USE_RISC_NOOP_VIDEO ) for (i = 0; i < NUM_NO_OPS; i++) {
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP); *(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
/* scan lines */ /* scan lines */
for (line = 0; line < lines; line++) for (line = 0; line < lines; line++) {
{
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(dev->_data_buf_phys_addr + offset); *(rp++) = cpu_to_le32(dev->_data_buf_phys_addr + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
if ( (lines <= NTSC_FIELD_HEIGHT) || (line < (NTSC_FIELD_HEIGHT-1)) || !(dev->_isNTSC) ) if ((lines <= NTSC_FIELD_HEIGHT)
{ || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC)) {
offset += dist_betwn_starts; offset += dist_betwn_starts;
} }
} }
@ -139,46 +130,39 @@ static __le32 *cx25821_update_riscprogram( struct cx25821_dev *dev,
static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp, static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
dma_addr_t databuf_phys_addr, dma_addr_t databuf_phys_addr,
unsigned int offset, u32 sync_line, unsigned int offset, u32 sync_line,
unsigned int bpl, unsigned int lines, int fifo_enable, int field_type) unsigned int bpl, unsigned int lines,
int fifo_enable, int field_type)
{ {
unsigned int line, i; unsigned int line, i;
struct sram_channel *sram_ch = &dev->sram_channels[dev->_channel_upstream_select]; struct sram_channel *sram_ch =
&dev->sram_channels[dev->_channel_upstream_select];
int dist_betwn_starts = bpl * 2; int dist_betwn_starts = bpl * 2;
/* sync instruction */ /* sync instruction */
if (sync_line != NO_SYNC_LINE) if (sync_line != NO_SYNC_LINE) {
{
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
} }
if (USE_RISC_NOOP_VIDEO) {
if( USE_RISC_NOOP_VIDEO ) for (i = 0; i < NUM_NO_OPS; i++) {
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP); *(rp++) = cpu_to_le32(RISC_NOOP);
} }
} }
/* scan lines */ /* scan lines */
for (line = 0; line < lines; line++) for (line = 0; line < lines; line++) {
{
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset); *(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */ *(rp++) = cpu_to_le32(0); /* bits 63-32 */
if ((lines <= NTSC_FIELD_HEIGHT)
if ( (lines <= NTSC_FIELD_HEIGHT) || (line < (NTSC_FIELD_HEIGHT-1)) || !(dev->_isNTSC) ) || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC)) {
{
offset += dist_betwn_starts; //to skip the other field line offset += dist_betwn_starts; //to skip the other field line
} }
// check if we need to enable the FIFO after the first 4 lines // check if we need to enable the FIFO after the first 4 lines
// For the upstream video channel, the risc engine will enable the FIFO. // For the upstream video channel, the risc engine will enable the FIFO.
if ( fifo_enable && line == 3 ) if (fifo_enable && line == 3) {
{
*(rp++) = RISC_WRITECR; *(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl; *(rp++) = sram_ch->dma_ctl;
*(rp++) = FLD_VID_FIFO_EN; *(rp++) = FLD_VID_FIFO_EN;
@ -206,52 +190,56 @@ int cx25821_risc_buffer_upstream( struct cx25821_dev *dev,
unsigned int bottom_offset = bpl; unsigned int bottom_offset = bpl;
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
if( dev->_isNTSC ) if (dev->_isNTSC) {
{
odd_num_lines = singlefield_lines + 1; odd_num_lines = singlefield_lines + 1;
risc_program_size = FRAME1_VID_PROG_SIZE; risc_program_size = FRAME1_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; frame_size =
} (bpl ==
else Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
{ FRAME_SIZE_NTSC_Y422;
} else {
risc_program_size = PAL_VID_PROG_SIZE; risc_program_size = PAL_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; frame_size =
(bpl ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
} }
/* Virtual address of Risc buffer program */ /* Virtual address of Risc buffer program */
rp = dev->_dma_virt_addr; rp = dev->_dma_virt_addr;
for( frame = 0; frame < NUM_FRAMES; frame++ ) for (frame = 0; frame < NUM_FRAMES; frame++) {
{
databuf_offset = frame_size * frame; databuf_offset = frame_size * frame;
if (UNSET != top_offset) if (UNSET != top_offset) {
{
fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE; fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE;
rp = cx25821_risc_field_upstream(dev, rp, dev->_data_buf_phys_addr+databuf_offset, top_offset, 0, bpl, odd_num_lines, fifo_enable, ODD_FIELD); rp = cx25821_risc_field_upstream(dev, rp,
dev->
_data_buf_phys_addr +
databuf_offset,
top_offset, 0, bpl,
odd_num_lines,
fifo_enable,
ODD_FIELD);
} }
fifo_enable = FIFO_DISABLE; fifo_enable = FIFO_DISABLE;
//Even Field //Even Field
rp = cx25821_risc_field_upstream(dev, rp, dev->_data_buf_phys_addr+databuf_offset, bottom_offset, 0x200, bpl, singlefield_lines, fifo_enable, EVEN_FIELD); rp = cx25821_risc_field_upstream(dev, rp,
dev->_data_buf_phys_addr +
databuf_offset, bottom_offset,
0x200, bpl, singlefield_lines,
fifo_enable, EVEN_FIELD);
if (frame == 0) {
if( frame == 0 )
{
risc_flag = RISC_CNT_RESET; risc_flag = RISC_CNT_RESET;
risc_phys_jump_addr = dev->_dma_phys_start_addr + risc_program_size; risc_phys_jump_addr =
} dev->_dma_phys_start_addr + risc_program_size;
else } else {
{
risc_phys_jump_addr = dev->_dma_phys_start_addr; risc_phys_jump_addr = dev->_dma_phys_start_addr;
risc_flag = RISC_CNT_INC; risc_flag = RISC_CNT_INC;
} }
// Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ // Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ
*(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
*(rp++) = cpu_to_le32(risc_phys_jump_addr); *(rp++) = cpu_to_le32(risc_phys_jump_addr);
@ -261,18 +249,17 @@ int cx25821_risc_buffer_upstream( struct cx25821_dev *dev,
return 0; return 0;
} }
void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev) void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
{ {
struct sram_channel *sram_ch = &dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_I]; struct sram_channel *sram_ch =
&dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_I];
u32 tmp = 0; u32 tmp = 0;
if( !dev->_is_running ) if (!dev->_is_running) {
{ printk
printk("cx25821: No video file is currently running so return!\n"); ("cx25821: No video file is currently running so return!\n");
return; return;
} }
//Disable RISC interrupts //Disable RISC interrupts
tmp = cx_read(sram_ch->int_msk); tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp & ~_intr_msk); cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
@ -290,8 +277,7 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
dev->_frame_count = 0; dev->_frame_count = 0;
dev->_file_status = END_OF_FILE; dev->_file_status = END_OF_FILE;
if( dev->_irq_queues ) if (dev->_irq_queues) {
{
kfree(dev->_irq_queues); kfree(dev->_irq_queues);
dev->_irq_queues = NULL; dev->_irq_queues = NULL;
} }
@ -305,31 +291,32 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev) void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev)
{ {
if( dev->_is_running ) if (dev->_is_running) {
{
cx25821_stop_upstream_video_ch1(dev); cx25821_stop_upstream_video_ch1(dev);
} }
if (dev->_dma_virt_addr) if (dev->_dma_virt_addr) {
{ pci_free_consistent(dev->pci, dev->_risc_size,
pci_free_consistent(dev->pci, dev->_risc_size, dev->_dma_virt_addr, dev->_dma_phys_addr); dev->_dma_virt_addr, dev->_dma_phys_addr);
dev->_dma_virt_addr = NULL; dev->_dma_virt_addr = NULL;
} }
if (dev->_data_buf_virt_addr) if (dev->_data_buf_virt_addr) {
{ pci_free_consistent(dev->pci, dev->_data_buf_size,
pci_free_consistent(dev->pci, dev->_data_buf_size, dev->_data_buf_virt_addr, dev->_data_buf_phys_addr); dev->_data_buf_virt_addr,
dev->_data_buf_phys_addr);
dev->_data_buf_virt_addr = NULL; dev->_data_buf_virt_addr = NULL;
} }
} }
int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch) int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int frame_index_temp = dev->_frame_index; int frame_index_temp = dev->_frame_index;
int i = 0; int i = 0;
int line_size = (dev->_pixel_format == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; int line_size =
(dev->_pixel_format ==
PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ;
int frame_size = 0; int frame_size = 0;
int frame_offset = 0; int frame_offset = 0;
ssize_t vfs_read_retval = 0; ssize_t vfs_read_retval = 0;
@ -338,45 +325,41 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch )
loff_t pos; loff_t pos;
mm_segment_t old_fs; mm_segment_t old_fs;
if (dev->_file_status == END_OF_FILE) if (dev->_file_status == END_OF_FILE)
return 0; return 0;
if( dev->_isNTSC ) if (dev->_isNTSC) {
{ frame_size =
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; (line_size ==
} Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
else FRAME_SIZE_NTSC_Y422;
{ } else {
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
} }
frame_offset = (frame_index_temp > 0) ? frame_size : 0; frame_offset = (frame_index_temp > 0) ? frame_size : 0;
file_offset = dev->_frame_count * frame_size; file_offset = dev->_frame_count * frame_size;
myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_filename, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_filename, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered!",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk("%s: File has no READ operations registered!",
{ __func__);
printk("%s: File has no READ operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -385,24 +368,26 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch )
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (i = 0; i < dev->_lines_count; i++) {
for( i = 0; i < dev->_lines_count; i++ )
{
pos = file_offset; pos = file_offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_data_buf_virt_addr != NULL ) if (vfs_read_retval > 0 && vfs_read_retval == line_size
{ && dev->_data_buf_virt_addr != NULL) {
memcpy( (void*)(dev->_data_buf_virt_addr+frame_offset/4), mybuf, vfs_read_retval); memcpy((void *)(dev->_data_buf_virt_addr +
frame_offset / 4), mybuf,
vfs_read_retval);
} }
file_offset += vfs_read_retval; file_offset += vfs_read_retval;
frame_offset += vfs_read_retval; frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break; break;
} }
} }
@ -410,8 +395,8 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch )
if (i > 0) if (i > 0)
dev->_frame_count++; dev->_frame_count++;
dev->_file_status = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; dev->_file_status =
(vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
filp_close(myfile, NULL); filp_close(myfile, NULL);
@ -422,52 +407,51 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch )
static void cx25821_vidups_handler(struct work_struct *work) static void cx25821_vidups_handler(struct work_struct *work)
{ {
struct cx25821_dev *dev = container_of(work, struct cx25821_dev, _irq_work_entry); struct cx25821_dev *dev =
container_of(work, struct cx25821_dev, _irq_work_entry);
if( !dev ) if (!dev) {
{ printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ ); __func__);
return; return;
} }
cx25821_get_frame( dev, &dev->sram_channels[dev->_channel_upstream_select] ); cx25821_get_frame(dev,
&dev->sram_channels[dev->_channel_upstream_select]);
} }
int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch) int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
{ {
struct file *myfile; struct file *myfile;
int i = 0, j = 0; int i = 0, j = 0;
int line_size = (dev->_pixel_format == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; int line_size =
(dev->_pixel_format ==
PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ;
ssize_t vfs_read_retval = 0; ssize_t vfs_read_retval = 0;
char mybuf[line_size]; char mybuf[line_size];
loff_t pos; loff_t pos;
loff_t offset = (unsigned long)0; loff_t offset = (unsigned long)0;
mm_segment_t old_fs; mm_segment_t old_fs;
myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0); myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0);
if (IS_ERR(myfile)) {
if (IS_ERR(myfile))
{
const int open_errno = -PTR_ERR(myfile); const int open_errno = -PTR_ERR(myfile);
printk("%s(): ERROR opening file(%s) with errno = %d! \n", __func__, dev->_filename, open_errno); printk("%s(): ERROR opening file(%s) with errno = %d! \n",
__func__, dev->_filename, open_errno);
return PTR_ERR(myfile); return PTR_ERR(myfile);
} } else {
else if (!(myfile->f_op)) {
{ printk("%s: File has no file operations registered!",
if( !(myfile->f_op) ) __func__);
{
printk("%s: File has no file operations registered!", __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
if (!myfile->f_op->read) {
if( !myfile->f_op->read ) printk
{ ("%s: File has no READ operations registered! Returning.",
printk("%s: File has no READ operations registered! Returning.", __func__); __func__);
filp_close(myfile, NULL); filp_close(myfile, NULL);
return -EIO; return -EIO;
} }
@ -476,26 +460,28 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
old_fs = get_fs(); old_fs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
for (j = 0; j < NUM_FRAMES; j++) {
for( j = 0; j < NUM_FRAMES; j++ ) for (i = 0; i < dev->_lines_count; i++) {
{
for( i = 0; i < dev->_lines_count; i++ )
{
pos = offset; pos = offset;
vfs_read_retval = vfs_read(myfile, mybuf, line_size, &pos); vfs_read_retval =
vfs_read(myfile, mybuf, line_size, &pos);
if( vfs_read_retval > 0 && vfs_read_retval == line_size && dev->_data_buf_virt_addr != NULL ) if (vfs_read_retval > 0
{ && vfs_read_retval == line_size
memcpy( (void*)(dev->_data_buf_virt_addr+offset/4), mybuf, vfs_read_retval); && dev->_data_buf_virt_addr != NULL) {
memcpy((void *)(dev->
_data_buf_virt_addr +
offset / 4), mybuf,
vfs_read_retval);
} }
offset += vfs_read_retval; offset += vfs_read_retval;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{ printk(KERN_INFO
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ ); "Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break; break;
} }
} }
@ -503,14 +489,13 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
if (i > 0) if (i > 0)
dev->_frame_count++; dev->_frame_count++;
if( vfs_read_retval < line_size ) if (vfs_read_retval < line_size) {
{
break; break;
} }
} }
dev->_file_status =
dev->_file_status = (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE; (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
set_fs(old_fs); set_fs(old_fs);
myfile->f_pos = 0; myfile->f_pos = 0;
@ -520,70 +505,67 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
return 0; return 0;
} }
int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev, int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
struct sram_channel *sram_ch, struct sram_channel *sram_ch, int bpl)
int bpl)
{ {
int ret = 0; int ret = 0;
dma_addr_t dma_addr; dma_addr_t dma_addr;
dma_addr_t data_dma_addr; dma_addr_t data_dma_addr;
if( dev->_dma_virt_addr != NULL ) if (dev->_dma_virt_addr != NULL) {
{ pci_free_consistent(dev->pci, dev->upstream_riscbuf_size,
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size, dev->_dma_virt_addr, dev->_dma_phys_addr); dev->_dma_virt_addr, dev->_dma_phys_addr);
} }
dev->_dma_virt_addr =
dev->_dma_virt_addr = pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size, &dma_addr); pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size,
&dma_addr);
dev->_dma_virt_start_addr = dev->_dma_virt_addr; dev->_dma_virt_start_addr = dev->_dma_virt_addr;
dev->_dma_phys_start_addr = dma_addr; dev->_dma_phys_start_addr = dma_addr;
dev->_dma_phys_addr = dma_addr; dev->_dma_phys_addr = dma_addr;
dev->_risc_size = dev->upstream_riscbuf_size; dev->_risc_size = dev->upstream_riscbuf_size;
if (!dev->_dma_virt_addr) {
if (!dev->_dma_virt_addr) printk
{ ("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
printk("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
return -ENOMEM; return -ENOMEM;
} }
//Clear memory at address //Clear memory at address
memset(dev->_dma_virt_addr, 0, dev->_risc_size); memset(dev->_dma_virt_addr, 0, dev->_risc_size);
if (dev->_data_buf_virt_addr != NULL) {
if( dev->_data_buf_virt_addr != NULL ) pci_free_consistent(dev->pci, dev->upstream_databuf_size,
{ dev->_data_buf_virt_addr,
pci_free_consistent(dev->pci, dev->upstream_databuf_size, dev->_data_buf_virt_addr, dev->_data_buf_phys_addr); dev->_data_buf_phys_addr);
} }
//For Video Data buffer allocation //For Video Data buffer allocation
dev->_data_buf_virt_addr = pci_alloc_consistent(dev->pci, dev->upstream_databuf_size, &data_dma_addr); dev->_data_buf_virt_addr =
pci_alloc_consistent(dev->pci, dev->upstream_databuf_size,
&data_dma_addr);
dev->_data_buf_phys_addr = data_dma_addr; dev->_data_buf_phys_addr = data_dma_addr;
dev->_data_buf_size = dev->upstream_databuf_size; dev->_data_buf_size = dev->upstream_databuf_size;
if (!dev->_data_buf_virt_addr) if (!dev->_data_buf_virt_addr) {
{ printk
printk("cx25821: FAILED to allocate memory for data buffer! Returning.\n"); ("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
return -ENOMEM; return -ENOMEM;
} }
//Clear memory at address //Clear memory at address
memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size); memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size);
ret = cx25821_openfile(dev, sram_ch); ret = cx25821_openfile(dev, sram_ch);
if (ret < 0) if (ret < 0)
return ret; return ret;
//Create RISC programs //Create RISC programs
ret = cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl, dev->_lines_count ); ret =
if (ret < 0) cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl,
{ dev->_lines_count);
printk(KERN_INFO "cx25821: Failed creating Video Upstream Risc programs! \n"); if (ret < 0) {
printk(KERN_INFO
"cx25821: Failed creating Video Upstream Risc programs! \n");
goto error; goto error;
} }
@ -593,7 +575,8 @@ error:
return ret; return ret;
} }
int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status) int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
u32 status)
{ {
u32 int_msk_tmp; u32 int_msk_tmp;
struct sram_channel *channel = &dev->sram_channels[chan_num]; struct sram_channel *channel = &dev->sram_channels[chan_num];
@ -603,10 +586,7 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
dma_addr_t risc_phys_jump_addr; dma_addr_t risc_phys_jump_addr;
__le32 *rp; __le32 *rp;
if (status & FLD_VID_SRC_RISC1) {
if (status & FLD_VID_SRC_RISC1)
{
// We should only process one program per call // We should only process one program per call
u32 prog_cnt = cx_read(channel->gpcnt); u32 prog_cnt = cx_read(channel->gpcnt);
@ -621,29 +601,35 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
queue_work(dev->_irq_queues, &dev->_irq_work_entry); queue_work(dev->_irq_queues, &dev->_irq_work_entry);
if (dev->_is_first_frame) {
if ( dev->_is_first_frame )
{
dev->_is_first_frame = 0; dev->_is_first_frame = 0;
if( dev->_isNTSC ) if (dev->_isNTSC) {
{
singlefield_lines += 1; singlefield_lines += 1;
odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE; odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
} } else {
else
{
singlefield_lines = PAL_FIELD_HEIGHT; singlefield_lines = PAL_FIELD_HEIGHT;
odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE; odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE;
} }
if (dev->_dma_virt_start_addr != NULL) {
line_size_in_bytes =
(dev->_pixel_format ==
PIXEL_FRMT_411) ? Y411_LINE_SZ :
Y422_LINE_SZ;
risc_phys_jump_addr =
dev->_dma_phys_start_addr +
odd_risc_prog_size;
if( dev->_dma_virt_start_addr != NULL ) rp = cx25821_update_riscprogram(dev,
{ dev->
line_size_in_bytes = (dev->_pixel_format == PIXEL_FRMT_411) ? Y411_LINE_SZ : Y422_LINE_SZ; _dma_virt_start_addr,
risc_phys_jump_addr = dev->_dma_phys_start_addr + odd_risc_prog_size; TOP_OFFSET,
line_size_in_bytes,
rp = cx25821_update_riscprogram(dev, dev->_dma_virt_start_addr, TOP_OFFSET, line_size_in_bytes, 0x0, singlefield_lines, FIFO_DISABLE, ODD_FIELD); 0x0,
singlefield_lines,
FIFO_DISABLE,
ODD_FIELD);
// Jump to Even Risc program of 1st Frame // Jump to Even Risc program of 1st Frame
*(rp++) = cpu_to_le32(RISC_JUMP); *(rp++) = cpu_to_le32(RISC_JUMP);
@ -653,26 +639,26 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
} }
spin_unlock(&dev->slock); spin_unlock(&dev->slock);
} } else {
else
{
if (status & FLD_VID_SRC_UF) if (status & FLD_VID_SRC_UF)
printk("%s: Video Received Underflow Error Interrupt!\n", __func__); printk
("%s: Video Received Underflow Error Interrupt!\n",
__func__);
if (status & FLD_VID_SRC_SYNC) if (status & FLD_VID_SRC_SYNC)
printk("%s: Video Received Sync Error Interrupt!\n", __func__); printk("%s: Video Received Sync Error Interrupt!\n",
__func__);
if (status & FLD_VID_SRC_OPC_ERR) if (status & FLD_VID_SRC_OPC_ERR)
printk("%s: Video Received OpCode Error Interrupt!\n", __func__); printk("%s: Video Received OpCode Error Interrupt!\n",
__func__);
} }
if (dev->_file_status == END_OF_FILE) {
if( dev->_file_status == END_OF_FILE ) printk("cx25821: EOF Channel 1 Framecount = %d\n",
{ dev->_frame_count);
printk("cx25821: EOF Channel 1 Framecount = %d\n", dev->_frame_count );
return -1; return -1;
} }
//ElSE, set the interrupt mask register, re-enable irq. //ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read(channel->int_msk); int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
@ -688,7 +674,6 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
int channel_num = 0; int channel_num = 0;
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
if (!dev) if (!dev)
return -1; return -1;
@ -700,25 +685,22 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
vid_status = cx_read(sram_ch->int_stat); vid_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt // Only deal with our interrupt
if(vid_status) if (vid_status) {
{ handled =
handled = cx25821_video_upstream_irq(dev, channel_num, vid_status); cx25821_video_upstream_irq(dev, channel_num, vid_status);
} }
if( handled < 0 ) if (handled < 0) {
{
cx25821_stop_upstream_video_ch1(dev); cx25821_stop_upstream_video_ch1(dev);
} } else {
else
{
handled += handled; handled += handled;
} }
return IRQ_RETVAL(handled); return IRQ_RETVAL(handled);
} }
void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch,
void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch, int pix_format) int pix_format)
{ {
int width = WIDTH_D1; int width = WIDTH_D1;
int height = dev->_lines_count; int height = dev->_lines_count;
@ -726,21 +708,18 @@ void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch, i
u32 value; u32 value;
int vip_mode = OUTPUT_FRMT_656; int vip_mode = OUTPUT_FRMT_656;
value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7); value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7);
value &= 0xFFFFFFEF; value &= 0xFFFFFFEF;
value |= dev->_isNTSC ? 0 : 0x10; value |= dev->_isNTSC ? 0 : 0x10;
cx_write(ch->vid_fmt_ctl, value); cx_write(ch->vid_fmt_ctl, value);
// set number of active pixels in each line. Default is 720 pixels in both NTSC and PAL format // set number of active pixels in each line. Default is 720 pixels in both NTSC and PAL format
cx_write(ch->vid_active_ctl1, width); cx_write(ch->vid_active_ctl1, width);
num_lines = (height / 2) & 0x3FF; num_lines = (height / 2) & 0x3FF;
odd_num_lines = num_lines; odd_num_lines = num_lines;
if(dev->_isNTSC) if (dev->_isNTSC) {
{
odd_num_lines += 1; odd_num_lines += 1;
} }
@ -752,19 +731,16 @@ void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch, i
cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3); cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
} }
int cx25821_start_video_dma_upstream(struct cx25821_dev *dev, int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
struct sram_channel *sram_ch) struct sram_channel *sram_ch)
{ {
u32 tmp = 0; u32 tmp = 0;
int err = 0; int err = 0;
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read(VID_CH_MODE_SEL); tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
// Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds. // Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds.
cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr); cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr);
cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */ cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
@ -775,21 +751,20 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
// Clear our bits from the interrupt status register. // Clear our bits from the interrupt status register.
cx_write(sram_ch->int_stat, _intr_msk); cx_write(sram_ch->int_stat, _intr_msk);
//Set the interrupt mask register, enable irq. //Set the interrupt mask register, enable irq.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read(sram_ch->int_msk); tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk); cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
err = request_irq(dev->pci->irq, cx25821_upstream_irq, IRQF_SHARED | IRQF_DISABLED, dev->name, dev); request_irq(dev->pci->irq, cx25821_upstream_irq,
if (err < 0) IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
{ if (err < 0) {
printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, dev->pci->irq); printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name,
dev->pci->irq);
goto fail_irq; goto fail_irq;
} }
// Start the DMA engine // Start the DMA engine
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN); cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
@ -804,8 +779,8 @@ fail_irq:
return err; return err;
} }
int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, int pixel_format) int pixel_format)
{ {
struct sram_channel *sram_ch; struct sram_channel *sram_ch;
u32 tmp; u32 tmp;
@ -815,44 +790,39 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
int risc_buffer_size = 0; int risc_buffer_size = 0;
int str_length = 0; int str_length = 0;
if (dev->_is_running) {
if( dev->_is_running )
{
printk("Video Channel is still running so return!\n"); printk("Video Channel is still running so return!\n");
return 0; return 0;
} }
dev->_channel_upstream_select = channel_select; dev->_channel_upstream_select = channel_select;
sram_ch = &dev->sram_channels[channel_select]; sram_ch = &dev->sram_channels[channel_select];
INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler); INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler);
dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue"); dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue");
if(!dev->_irq_queues) if (!dev->_irq_queues) {
{ printk
printk("cx25821: create_singlethread_workqueue() for Video FAILED!\n"); ("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
return -ENOMEM; return -ENOMEM;
} }
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read(VID_CH_MODE_SEL); tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
dev->_is_running = 0; dev->_is_running = 0;
dev->_frame_count = 0; dev->_frame_count = 0;
dev->_file_status = RESET_STATUS; dev->_file_status = RESET_STATUS;
dev->_lines_count = dev->_isNTSC ? 480 : 576; dev->_lines_count = dev->_isNTSC ? 480 : 576;
dev->_pixel_format = pixel_format; dev->_pixel_format = pixel_format;
dev->_line_size = (dev->_pixel_format == PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; dev->_line_size =
(dev->_pixel_format ==
PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
data_frame_size = dev->_isNTSC ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ; data_frame_size = dev->_isNTSC ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ;
risc_buffer_size = dev->_isNTSC ? NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE; risc_buffer_size =
dev->_isNTSC ? NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE;
if (dev->input_filename) {
if( dev->input_filename )
{
str_length = strlen(dev->input_filename); str_length = strlen(dev->input_filename);
dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL); dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL);
@ -860,9 +830,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
goto error; goto error;
memcpy(dev->_filename, dev->input_filename, str_length + 1); memcpy(dev->_filename, dev->input_filename, str_length + 1);
} } else {
else
{
str_length = strlen(dev->_defaultname); str_length = strlen(dev->_defaultname);
dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL); dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL);
@ -872,17 +840,18 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
memcpy(dev->_filename, dev->_defaultname, str_length + 1); memcpy(dev->_filename, dev->_defaultname, str_length + 1);
} }
//Default if filename is empty string //Default if filename is empty string
if( strcmp(dev->input_filename,"") == 0) if (strcmp(dev->input_filename, "") == 0) {
{ if (dev->_isNTSC) {
if( dev->_isNTSC ) dev->_filename =
{ (dev->_pixel_format ==
dev->_filename = (dev->_pixel_format == PIXEL_FRMT_411) ? "/root/vid411.yuv" : "/root/vidtest.yuv"; PIXEL_FRMT_411) ? "/root/vid411.yuv" :
} "/root/vidtest.yuv";
else } else {
{ dev->_filename =
dev->_filename = (dev->_pixel_format == PIXEL_FRMT_411) ? "/root/pal411.yuv" : "/root/pal422.yuv"; (dev->_pixel_format ==
PIXEL_FRMT_411) ? "/root/pal411.yuv" :
"/root/pal422.yuv";
} }
} }
@ -891,9 +860,13 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
dev->_file_status = RESET_STATUS; dev->_file_status = RESET_STATUS;
dev->_lines_count = dev->_isNTSC ? 480 : 576; dev->_lines_count = dev->_isNTSC ? 480 : 576;
dev->_pixel_format = pixel_format; dev->_pixel_format = pixel_format;
dev->_line_size = (dev->_pixel_format == PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; dev->_line_size =
(dev->_pixel_format ==
PIXEL_FRMT_422) ? (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
retval = cx25821_sram_channel_setup_upstream(dev, sram_ch, dev->_line_size, 0); retval =
cx25821_sram_channel_setup_upstream(dev, sram_ch, dev->_line_size,
0);
/* setup fifo + format */ /* setup fifo + format */
cx25821_set_pixelengine(dev, sram_ch, dev->_pixel_format); cx25821_set_pixelengine(dev, sram_ch, dev->_pixel_format);
@ -901,16 +874,15 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
dev->upstream_riscbuf_size = risc_buffer_size * 2; dev->upstream_riscbuf_size = risc_buffer_size * 2;
dev->upstream_databuf_size = data_frame_size * 2; dev->upstream_databuf_size = data_frame_size * 2;
//Allocating buffers and prepare RISC program //Allocating buffers and prepare RISC program
retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size); retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size);
if (retval < 0) if (retval < 0) {
{ printk(KERN_ERR
printk(KERN_ERR "%s: Failed to set up Video upstream buffers!\n", dev->name); "%s: Failed to set up Video upstream buffers!\n",
dev->name);
goto error; goto error;
} }
cx25821_start_video_dma_upstream(dev, sram_ch); cx25821_start_video_dma_upstream(dev, sram_ch);
return 0; return 0;
@ -920,4 +892,3 @@ error:
return err; return err;
} }

View File

@ -38,8 +38,6 @@
#define RESET_STATUS -1 #define RESET_STATUS -1
#define NUM_NO_OPS 5 #define NUM_NO_OPS 5
// PAL and NTSC line sizes and number of lines. // PAL and NTSC line sizes and number of lines.
#define WIDTH_D1 720 #define WIDTH_D1 720
#define NTSC_LINES_PER_FRAME 480 #define NTSC_LINES_PER_FRAME 480
@ -65,7 +63,6 @@
#define MAXSIZE_NO_OPS 36 #define MAXSIZE_NO_OPS 36
#define DWORD_SIZE 4 #define DWORD_SIZE 4
#define USE_RISC_NOOP_VIDEO 1 #define USE_RISC_NOOP_VIDEO 1
#ifdef USE_RISC_NOOP_VIDEO #ifdef USE_RISC_NOOP_VIDEO
@ -93,7 +90,6 @@
#endif #endif
#ifndef USE_RISC_NOOP_VIDEO #ifndef USE_RISC_NOOP_VIDEO
#define PAL_US_VID_PROG_SIZE ((PAL_FIELD_HEIGHT) * 3 * DWORD_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \ #define PAL_US_VID_PROG_SIZE ((PAL_FIELD_HEIGHT) * 3 * DWORD_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
RISC_SYNC_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE) RISC_SYNC_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE)

View File

@ -81,19 +81,16 @@ struct cx25821_fmt formats[] = {
}, },
}; };
int get_format_size(void) int get_format_size(void)
{ {
return ARRAY_SIZE(formats); return ARRAY_SIZE(formats);
} }
struct cx25821_fmt *format_by_fourcc(unsigned int fourcc) struct cx25821_fmt *format_by_fourcc(unsigned int fourcc)
{ {
unsigned int i; unsigned int i;
if( fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P ) if (fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P) {
{
return formats + 1; return formats + 1;
} }
@ -116,34 +113,32 @@ void dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q)
buf = list_entry(item, struct cx25821_buffer, vb.queue); buf = list_entry(item, struct cx25821_buffer, vb.queue);
} }
if (!list_empty(&q->queued)) if (!list_empty(&q->queued)) {
{
list_for_each(item, &q->queued) list_for_each(item, &q->queued)
buf = list_entry(item, struct cx25821_buffer, vb.queue); buf = list_entry(item, struct cx25821_buffer, vb.queue);
} }
} }
void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u32 count) u32 count)
{ {
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
int bc; int bc;
for (bc = 0;; bc++) { for (bc = 0;; bc++) {
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(1, "bc=%d (=0: active empty)\n", bc); dprintk(1, "bc=%d (=0: active empty)\n", bc);
break; break;
} }
buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); buf =
list_entry(q->active.next, struct cx25821_buffer, vb.queue);
/* count comes from the hw and it is 16bit wide -- /* count comes from the hw and it is 16bit wide --
* this trick handles wrap-arounds correctly for * this trick handles wrap-arounds correctly for
* up to 32767 buffers in flight... */ * up to 32767 buffers in flight... */
if ((s16) (count - buf->count) < 0) if ((s16) (count - buf->count) < 0) {
{
break; break;
} }
@ -158,15 +153,15 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u
else else
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
if (bc != 1) if (bc != 1)
printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", __func__, bc); printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
__func__, bc);
} }
#ifdef TUNER_FLAG #ifdef TUNER_FLAG
int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm) int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm)
{ {
dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__, dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__,
(unsigned int)norm, (unsigned int)norm, v4l2_norm_to_name(norm));
v4l2_norm_to_name(norm));
dev->tvnorm = norm; dev->tvnorm = norm;
@ -192,7 +187,8 @@ struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
vfd->minor = -1; vfd->minor = -1;
vfd->v4l2_dev = &dev->v4l2_dev; vfd->v4l2_dev = &dev->v4l2_dev;
vfd->release = video_device_release; vfd->release = video_device_release;
snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, type, cx25821_boards[dev->board].name); snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, type,
cx25821_boards[dev->board].name);
return vfd; return vfd;
} }
@ -265,10 +261,9 @@ int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input)
struct v4l2_routing route; struct v4l2_routing route;
memset(&route, 0, sizeof(route)); memset(&route, 0, sizeof(route));
dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", __func__, dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
input, INPUT(input)->vmux, __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0,
INPUT(input)->gpio0, INPUT(input)->gpio1, INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3);
INPUT(input)->gpio2, INPUT(input)->gpio3);
dev->input = input; dev->input = input;
route.input = INPUT(input)->vmux; route.input = INPUT(input)->vmux;
@ -307,14 +302,16 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
return 0; return 0;
} }
int cx25821_restart_video_queue(struct cx25821_dev *dev,
int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, struct sram_channel *channel) struct cx25821_dmaqueue *q,
struct sram_channel *channel)
{ {
struct cx25821_buffer *buf, *prev; struct cx25821_buffer *buf, *prev;
struct list_head *item; struct list_head *item;
if (!list_empty(&q->active)) { if (!list_empty(&q->active)) {
buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); buf =
list_entry(q->active.next, struct cx25821_buffer, vb.queue);
cx25821_start_video_dma(dev, q, buf, channel); cx25821_start_video_dma(dev, q, buf, channel);
@ -332,7 +329,8 @@ int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue
if (list_empty(&q->queued)) if (list_empty(&q->queued))
return 0; return 0;
buf = list_entry(q->queued.next, struct cx25821_buffer, vb.queue); buf =
list_entry(q->queued.next, struct cx25821_buffer, vb.queue);
if (NULL == prev) { if (NULL == prev) {
list_move_tail(&buf->vb.queue, &q->active); list_move_tail(&buf->vb.queue, &q->active);
@ -369,7 +367,8 @@ void cx25821_vid_timeout(unsigned long data)
spin_lock_irqsave(&dev->slock, flags); spin_lock_irqsave(&dev->slock, flags);
while (!list_empty(&q->active)) { while (!list_empty(&q->active)) {
buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); buf =
list_entry(q->active.next, struct cx25821_buffer, vb.queue);
list_del(&buf->vb.queue); list_del(&buf->vb.queue);
buf->vb.state = VIDEOBUF_ERROR; buf->vb.state = VIDEOBUF_ERROR;
@ -395,7 +394,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
/* risc op code error */ /* risc op code error */
if (status & (1 << 16)) { if (status & (1 << 16)) {
printk(KERN_WARNING "%s, %s: video risc op code error\n", dev->name, channel->name); printk(KERN_WARNING "%s, %s: video risc op code error\n",
dev->name, channel->name);
cx_clear(channel->dma_ctl, 0x11); cx_clear(channel->dma_ctl, 0x11);
cx25821_sram_channel_dump(dev, channel); cx25821_sram_channel_dump(dev, channel);
} }
@ -413,7 +413,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
if (status & 0x10) { if (status & 0x10) {
dprintk(2, "stopper video\n"); dprintk(2, "stopper video\n");
spin_lock(&dev->slock); spin_lock(&dev->slock);
cx25821_restart_video_queue(dev, &dev->vidq[channel->i], channel); cx25821_restart_video_queue(dev, &dev->vidq[channel->i],
channel);
spin_unlock(&dev->slock); spin_unlock(&dev->slock);
handled++; handled++;
} }
@ -422,8 +423,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
void cx25821_videoioctl_unregister(struct cx25821_dev *dev) void cx25821_videoioctl_unregister(struct cx25821_dev *dev)
{ {
if( dev->ioctl_dev ) if (dev->ioctl_dev) {
{
if (dev->ioctl_dev->minor != -1) if (dev->ioctl_dev->minor != -1)
video_unregister_device(dev->ioctl_dev); video_unregister_device(dev->ioctl_dev);
else else
@ -452,8 +452,8 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
} }
int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
int cx25821_video_register(struct cx25821_dev *dev, int chan_num, struct video_device *video_template) struct video_device *video_template)
{ {
int err; int err;
@ -471,23 +471,25 @@ int cx25821_video_register(struct cx25821_dev *dev, int chan_num, struct video_d
INIT_LIST_HEAD(&dev->vidq[chan_num].active); INIT_LIST_HEAD(&dev->vidq[chan_num].active);
INIT_LIST_HEAD(&dev->vidq[chan_num].queued); INIT_LIST_HEAD(&dev->vidq[chan_num].queued);
dev->vidq[chan_num].timeout.function = cx25821_vid_timeout; dev->vidq[chan_num].timeout.function = cx25821_vid_timeout;
dev->vidq[chan_num].timeout.data = (unsigned long)&dev->timeout_data[chan_num]; dev->vidq[chan_num].timeout.data =
(unsigned long)&dev->timeout_data[chan_num];
init_timer(&dev->vidq[chan_num].timeout); init_timer(&dev->vidq[chan_num].timeout);
cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper, dev->sram_channels[chan_num].dma_ctl, 0x11, 0); cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper,
dev->sram_channels[chan_num].dma_ctl, 0x11, 0);
/* register v4l devices */ /* register v4l devices */
dev->video_dev[chan_num] = cx25821_vdev_init(dev, dev->pci, video_template, "video"); dev->video_dev[chan_num] =
err = video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER, video_nr[dev->nr]); cx25821_vdev_init(dev, dev->pci, video_template, "video");
err =
video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER,
video_nr[dev->nr]);
if (err < 0) { if (err < 0) {
goto fail_unreg; goto fail_unreg;
} }
//set PCI interrupt //set PCI interrupt
cx_set(PCI_INT_MSK, 0xff); cx_set(PCI_INT_MSK, 0xff);
/* initial device configuration */ /* initial device configuration */
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
#ifdef TUNER_FLAG #ifdef TUNER_FLAG
@ -504,13 +506,13 @@ fail_unreg:
return err; return err;
} }
int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) int buffer_setup(struct videobuf_queue *q, unsigned int *count,
unsigned int *size)
{ {
struct cx25821_fh *fh = q->priv_data; struct cx25821_fh *fh = q->priv_data;
*size = fh->fmt->depth * fh->width * fh->height >> 3; *size = fh->fmt->depth * fh->width * fh->height >> 3;
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
@ -520,18 +522,19 @@ int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *si
return 0; return 0;
} }
int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4l2_field field) int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
enum v4l2_field field)
{ {
struct cx25821_fh *fh = q->priv_data; struct cx25821_fh *fh = q->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
int rc, init_buffer = 0; int rc, init_buffer = 0;
u32 line0_offset, line1_offset; u32 line0_offset, line1_offset;
struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
int bpl_local = LINE_SIZE_D1; int bpl_local = LINE_SIZE_D1;
int channel_opened = 0; int channel_opened = 0;
BUG_ON(NULL == fh->fmt); BUG_ON(NULL == fh->fmt);
if (fh->width < 48 || fh->width > 720 || if (fh->width < 48 || fh->width > 720 ||
fh->height < 32 || fh->height > 576) fh->height < 32 || fh->height > 576)
@ -542,11 +545,9 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
return -EINVAL; return -EINVAL;
if (buf->fmt != fh->fmt || if (buf->fmt != fh->fmt ||
buf->vb.width != fh->width || buf->vb.width != fh->width ||
buf->vb.height != fh->height || buf->vb.height != fh->height || buf->vb.field != field) {
buf->vb.field != field) {
buf->fmt = fh->fmt; buf->fmt = fh->fmt;
buf->vb.width = fh->width; buf->vb.width = fh->width;
buf->vb.height = fh->height; buf->vb.height = fh->height;
@ -557,8 +558,7 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
init_buffer = 1; init_buffer = 1;
rc = videobuf_iolock(q, &buf->vb, NULL); rc = videobuf_iolock(q, &buf->vb, NULL);
if (0 != rc) if (0 != rc) {
{
printk(KERN_DEBUG "videobuf_iolock failed!\n"); printk(KERN_DEBUG "videobuf_iolock failed!\n");
goto fail; goto fail;
} }
@ -569,35 +569,33 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
if (init_buffer) { if (init_buffer) {
channel_opened = dev->channel_opened; channel_opened = dev->channel_opened;
channel_opened = (channel_opened < 0 || channel_opened > 7) ? 7 : channel_opened; channel_opened = (channel_opened < 0
|| channel_opened > 7) ? 7 : channel_opened;
if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411) if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411)
buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
else else
buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411) {
if( dev->pixel_formats[channel_opened] == PIXEL_FRMT_411 )
{
bpl_local = buf->bpl; bpl_local = buf->bpl;
} } else {
else
{
bpl_local = buf->bpl; //Default bpl_local = buf->bpl; //Default
if( channel_opened >= 0 && channel_opened <= 7 ) if (channel_opened >= 0 && channel_opened <= 7) {
{ if (dev->use_cif_resolution[channel_opened]) {
if( dev->use_cif_resolution[channel_opened] ) if (dev->tvnorm & V4L2_STD_PAL_BG
{ || dev->tvnorm & V4L2_STD_PAL_DK)
if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK )
bpl_local = 352 << 1; bpl_local = 352 << 1;
else else
bpl_local = dev->cif_width[channel_opened] << 1; bpl_local =
dev->
cif_width[channel_opened] <<
1;
} }
} }
} }
switch (buf->vb.field) { switch (buf->vb.field) {
case V4L2_FIELD_TOP: case V4L2_FIELD_TOP:
cx25821_risc_buffer(dev->pci, &buf->risc, cx25821_risc_buffer(dev->pci, &buf->risc,
@ -624,15 +622,13 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
cx25821_risc_buffer(dev->pci, &buf->risc, cx25821_risc_buffer(dev->pci, &buf->risc,
dma->sglist, dma->sglist,
0, buf->bpl * (buf->vb.height >> 1), 0, buf->bpl * (buf->vb.height >> 1),
buf->bpl, 0, buf->bpl, 0, buf->vb.height >> 1);
buf->vb.height >> 1);
break; break;
case V4L2_FIELD_SEQ_BT: case V4L2_FIELD_SEQ_BT:
cx25821_risc_buffer(dev->pci, &buf->risc, cx25821_risc_buffer(dev->pci, &buf->risc,
dma->sglist, dma->sglist,
buf->bpl * (buf->vb.height >> 1), 0, buf->bpl * (buf->vb.height >> 1), 0,
buf->bpl, 0, buf->bpl, 0, buf->vb.height >> 1);
buf->vb.height >> 1);
break; break;
default: default:
BUG(); BUG();
@ -640,8 +636,8 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
} }
dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, fh->fmt->name, buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth,
(unsigned long)buf->risc.dma); fh->fmt->name, (unsigned long)buf->risc.dma);
buf->vb.state = VIDEOBUF_PREPARED; buf->vb.state = VIDEOBUF_PREPARED;
@ -652,15 +648,14 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
return rc; return rc;
} }
void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
cx25821_free_buffer(q, buf); cx25821_free_buffer(q, buf);
} }
struct videobuf_queue *get_queue(struct cx25821_fh *fh) struct videobuf_queue *get_queue(struct cx25821_fh *fh)
{ {
switch (fh->type) { switch (fh->type) {
@ -683,7 +678,6 @@ int get_resource(struct cx25821_fh *fh, int resource)
} }
} }
int video_mmap(struct file *file, struct vm_area_struct *vma) int video_mmap(struct file *file, struct vm_area_struct *vma)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -722,8 +716,7 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
if (V4L2_FIELD_ANY == field) { if (V4L2_FIELD_ANY == field) {
field = (f->fmt.pix.height > maxh / 2) field = (f->fmt.pix.height > maxh / 2)
? V4L2_FIELD_INTERLACED ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
: V4L2_FIELD_TOP;
} }
switch (field) { switch (field) {
@ -753,8 +746,6 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
return 0; return 0;
} }
int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
{ {
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@ -764,15 +755,14 @@ int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
cap->version = CX25821_VERSION_CODE; cap->version = CX25821_VERSION_CODE;
cap->capabilities = cap->capabilities =
V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING;
if (UNSET != dev->tuner_type) if (UNSET != dev->tuner_type)
cap->capabilities |= V4L2_CAP_TUNER; cap->capabilities |= V4L2_CAP_TUNER;
return 0; return 0;
} }
int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f) int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{ {
if (unlikely(f->index >= ARRAY_SIZE(formats))) if (unlikely(f->index >= ARRAY_SIZE(formats)))
return -EINVAL; return -EINVAL;
@ -838,8 +828,7 @@ int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
return 0; return 0;
} }
int vidioc_s_priority(struct file *file, void *f, int vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio)
enum v4l2_priority prio)
{ {
struct cx25821_fh *fh = f; struct cx25821_fh *fh = f;
struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
@ -847,7 +836,6 @@ int vidioc_s_priority(struct file *file, void *f,
return v4l2_prio_change(&dev->prio, &fh->prio, prio); return v4l2_prio_change(&dev->prio, &fh->prio, prio);
} }
#ifdef TUNER_FLAG #ifdef TUNER_FLAG
int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms) int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
{ {
@ -857,15 +845,13 @@ int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
dprintk(1, "%s()\n", __func__); dprintk(1, "%s()\n", __func__);
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
} }
if( dev->tvnorm == *tvnorms ) if (dev->tvnorm == *tvnorms) {
{
return 0; return 0;
} }
@ -921,7 +907,6 @@ int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
return 0; return 0;
} }
int vidioc_s_input(struct file *file, void *priv, unsigned int i) int vidioc_s_input(struct file *file, void *priv, unsigned int i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
@ -930,8 +915,7 @@ int vidioc_s_input(struct file *file, void *priv, unsigned int i)
dprintk(1, "%s(%d)\n", __func__, i); dprintk(1, "%s(%d)\n", __func__, i);
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -982,8 +966,7 @@ int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -1022,7 +1005,6 @@ int vidioc_s_register(struct file *file, void *fh,
#endif #endif
#ifdef TUNER_FLAG #ifdef TUNER_FLAG
int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
{ {
@ -1042,15 +1024,13 @@ int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
return 0; return 0;
} }
int vidioc_s_tuner(struct file *file, void *priv, int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
struct v4l2_tuner *t)
{ {
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -1114,8 +1094,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
{ {
int i; int i;
if (qctrl->id < V4L2_CID_BASE || if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1)
qctrl->id >= V4L2_CID_LASTP1)
return -EINVAL; return -EINVAL;
for (i = 0; i < CX25821_CTLS; i++) for (i = 0; i < CX25821_CTLS; i++)
if (cx25821_ctls[i].id == qctrl->id) if (cx25821_ctls[i].id == qctrl->id)
@ -1147,9 +1126,7 @@ static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
return NULL; return NULL;
} }
int vidioc_g_ctrl(struct file *file, int vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
void *priv,
struct v4l2_control *ctl)
{ {
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@ -1159,8 +1136,7 @@ int vidioc_g_ctrl(struct file *file,
if (NULL == ctrl) if (NULL == ctrl)
return -EINVAL; return -EINVAL;
switch (ctl->id) switch (ctl->id) {
{
case V4L2_CID_BRIGHTNESS: case V4L2_CID_BRIGHTNESS:
ctl->value = dev->ctl_bright; ctl->value = dev->ctl_bright;
break; break;
@ -1190,8 +1166,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
if (NULL == ctrl) if (NULL == ctrl)
return err; return err;
switch (ctrl->type) switch (ctrl->type) {
{
case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_BOOLEAN:
case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_MENU:
case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_INTEGER:
@ -1204,8 +1179,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
/* nothing */ ; /* nothing */ ;
}; };
switch (ctl->id) switch (ctl->id) {
{
case V4L2_CID_BRIGHTNESS: case V4L2_CID_BRIGHTNESS:
dev->ctl_bright = ctl->value; dev->ctl_bright = ctl->value;
medusa_set_brightness(dev, ctl->value, chan_num); medusa_set_brightness(dev, ctl->value, chan_num);
@ -1241,9 +1215,7 @@ static void init_controls(struct cx25821_dev *dev, int chan_num)
} }
} }
int vidioc_cropcap(struct file *file, int vidioc_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cropcap)
void *priv,
struct v4l2_cropcap *cropcap)
{ {
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@ -1252,22 +1224,21 @@ int vidioc_cropcap(struct file *file,
cropcap->bounds.top = cropcap->bounds.left = 0; cropcap->bounds.top = cropcap->bounds.left = 0;
cropcap->bounds.width = 720; cropcap->bounds.width = 720;
cropcap->bounds.height = dev->tvnorm == V4L2_STD_PAL_BG ? 576 : 480; cropcap->bounds.height = dev->tvnorm == V4L2_STD_PAL_BG ? 576 : 480;
cropcap->pixelaspect.numerator = dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10; cropcap->pixelaspect.numerator =
cropcap->pixelaspect.denominator = dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11; dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10;
cropcap->pixelaspect.denominator =
dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11;
cropcap->defrect = cropcap->bounds; cropcap->defrect = cropcap->bounds;
return 0; return 0;
} }
int vidioc_s_crop(struct file *file, int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
void *priv,
struct v4l2_crop *crop)
{ {
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -1276,17 +1247,13 @@ int vidioc_s_crop(struct file *file,
return -EINVAL; return -EINVAL;
} }
int vidioc_g_crop(struct file *file, int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
void *priv,
struct v4l2_crop *crop)
{ {
// vidioc_g_crop not supported // vidioc_g_crop not supported
return -EINVAL; return -EINVAL;
} }
int vidioc_querystd(struct file *file, int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
void *priv,
v4l2_std_id *norm)
{ {
// medusa does not support video standard sensing of current input // medusa does not support video standard sensing of current input
*norm = CX25821_NORMS; *norm = CX25821_NORMS;
@ -1296,16 +1263,14 @@ int vidioc_querystd(struct file *file,
int is_valid_width(u32 width, v4l2_std_id tvnorm) int is_valid_width(u32 width, v4l2_std_id tvnorm)
{ {
if(tvnorm == V4L2_STD_PAL_BG) if (tvnorm == V4L2_STD_PAL_BG) {
{
if (width == 352 || width == 720) if (width == 352 || width == 720)
return 1; return 1;
else else
return 0; return 0;
} }
if(tvnorm == V4L2_STD_NTSC_M) if (tvnorm == V4L2_STD_NTSC_M) {
{
if (width == 320 || width == 352 || width == 720) if (width == 320 || width == 352 || width == 720)
return 1; return 1;
else else
@ -1316,16 +1281,14 @@ int is_valid_width(u32 width, v4l2_std_id tvnorm)
int is_valid_height(u32 height, v4l2_std_id tvnorm) int is_valid_height(u32 height, v4l2_std_id tvnorm)
{ {
if(tvnorm == V4L2_STD_PAL_BG) if (tvnorm == V4L2_STD_PAL_BG) {
{
if (height == 576 || height == 288) if (height == 576 || height == 288)
return 1; return 1;
else else
return 0; return 0;
} }
if(tvnorm == V4L2_STD_NTSC_M) if (tvnorm == V4L2_STD_NTSC_M) {
{
if (height == 480 || height == 240) if (height == 480 || height == 240)
return 1; return 1;
else else
@ -1334,4 +1297,3 @@ int is_valid_height(u32 height, v4l2_std_id tvnorm)
return 0; return 0;
} }

View File

@ -24,7 +24,6 @@
#ifndef CX25821_VIDEO_H_ #ifndef CX25821_VIDEO_H_
#define CX25821_VIDEO_H_ #define CX25821_VIDEO_H_
#include <linux/init.h> #include <linux/init.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
@ -55,7 +54,6 @@
printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
} while (0) } while (0)
//For IOCTL to identify running upstream //For IOCTL to identify running upstream
#define UPSTREAM_START_VIDEO 700 #define UPSTREAM_START_VIDEO 700
#define UPSTREAM_STOP_VIDEO 701 #define UPSTREAM_STOP_VIDEO 701
@ -103,55 +101,75 @@ extern struct cx25821_fmt formats[];
extern struct cx25821_fmt *format_by_fourcc(unsigned int fourcc); extern struct cx25821_fmt *format_by_fourcc(unsigned int fourcc);
extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM]; extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM];
extern void dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q); extern void dump_video_queue(struct cx25821_dev *dev,
extern void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u32 count); struct cx25821_dmaqueue *q);
extern void cx25821_video_wakeup(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q, u32 count);
#ifdef TUNER_FLAG #ifdef TUNER_FLAG
extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm); extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm);
#endif #endif
extern int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
extern int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit); unsigned int bit);
extern int res_check(struct cx25821_fh *fh, unsigned int bit); extern int res_check(struct cx25821_fh *fh, unsigned int bit);
extern int res_locked(struct cx25821_dev *dev, unsigned int bit); extern int res_locked(struct cx25821_dev *dev, unsigned int bit);
extern void res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits); extern void res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
unsigned int bits);
extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input); extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input);
extern int cx25821_start_video_dma(struct cx25821_dev *dev, extern int cx25821_start_video_dma(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q, struct cx25821_dmaqueue *q,
struct cx25821_buffer *buf, struct cx25821_buffer *buf,
struct sram_channel *channel); struct sram_channel *channel);
extern int cx25821_set_scale(struct cx25821_dev *dev, unsigned int width, unsigned int height, enum v4l2_field field); extern int cx25821_set_scale(struct cx25821_dev *dev, unsigned int width,
unsigned int height, enum v4l2_field field);
extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status); extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status);
extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num); extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num);
extern int cx25821_video_register(struct cx25821_dev *dev, int chan_num, struct video_device *video_template); extern int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
struct video_device *video_template);
extern int get_format_size(void); extern int get_format_size(void);
extern int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size); extern int buffer_setup(struct videobuf_queue *q, unsigned int *count,
extern int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4l2_field field); unsigned int *size);
extern void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb); extern int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
enum v4l2_field field);
extern void buffer_release(struct videobuf_queue *q,
struct videobuf_buffer *vb);
extern struct videobuf_queue *get_queue(struct cx25821_fh *fh); extern struct videobuf_queue *get_queue(struct cx25821_fh *fh);
extern int get_resource(struct cx25821_fh *fh, int resource); extern int get_resource(struct cx25821_fh *fh, int resource);
extern int video_mmap(struct file *file, struct vm_area_struct *vma); extern int video_mmap(struct file *file, struct vm_area_struct *vma);
extern int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f); extern int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
extern int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap); struct v4l2_format *f);
extern int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f); extern int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *cap);
extern int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f);
extern int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf); extern int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf);
extern int vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p); extern int vidioc_reqbufs(struct file *file, void *priv,
extern int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p); struct v4l2_requestbuffers *p);
extern int vidioc_querybuf(struct file *file, void *priv,
struct v4l2_buffer *p);
extern int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p); extern int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
extern int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms); extern int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms);
extern int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i); extern int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i);
extern int vidioc_enum_input(struct file *file, void *priv, struct v4l2_input *i); extern int vidioc_enum_input(struct file *file, void *priv,
struct v4l2_input *i);
extern int vidioc_g_input(struct file *file, void *priv, unsigned int *i); extern int vidioc_g_input(struct file *file, void *priv, unsigned int *i);
extern int vidioc_s_input(struct file *file, void *priv, unsigned int i); extern int vidioc_s_input(struct file *file, void *priv, unsigned int i);
extern int vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl); extern int vidioc_g_ctrl(struct file *file, void *priv,
extern int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f); struct v4l2_control *ctl);
extern int vidioc_g_frequency(struct file *file, void *priv, struct v4l2_frequency *f); extern int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f);
extern int vidioc_g_frequency(struct file *file, void *priv,
struct v4l2_frequency *f);
extern int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f); extern int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f);
extern int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f); extern int vidioc_s_frequency(struct file *file, void *priv,
extern int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg); struct v4l2_frequency *f);
extern int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg); extern int vidioc_g_register(struct file *file, void *fh,
struct v4l2_dbg_register *reg);
extern int vidioc_s_register(struct file *file, void *fh,
struct v4l2_dbg_register *reg);
extern int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t); extern int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
extern int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t); extern int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
@ -159,12 +177,16 @@ extern int is_valid_width(u32 width, v4l2_std_id tvnorm);
extern int is_valid_height(u32 height, v4l2_std_id tvnorm); extern int is_valid_height(u32 height, v4l2_std_id tvnorm);
extern int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p); extern int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p);
extern int vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio); extern int vidioc_s_priority(struct file *file, void *f,
enum v4l2_priority prio);
extern int vidioc_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *qctrl); extern int vidioc_queryctrl(struct file *file, void *priv,
extern int cx25821_set_control(struct cx25821_dev *dev, struct v4l2_control *ctrl, int chan_num); struct v4l2_queryctrl *qctrl);
extern int cx25821_set_control(struct cx25821_dev *dev,
struct v4l2_control *ctrl, int chan_num);
extern int vidioc_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap); extern int vidioc_cropcap(struct file *file, void *fh,
struct v4l2_cropcap *cropcap);
extern int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop); extern int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop);
extern int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop); extern int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop);

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH00]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH00]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,12 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH00] && h->video_dev[SRAM_CH00]->minor == minor) if (h->video_dev[SRAM_CH00]
{ && h->video_dev[SRAM_CH00]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -134,7 +137,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH00; dev->channel_opened = SRAM_CH00;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -143,8 +148,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -152,17 +156,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO0)) if (res_locked(fh->dev, RESOURCE_VIDEO0))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -170,7 +175,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -189,16 +195,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH00] ) if (dev && dev->use_cif_resolution[SRAM_CH00]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -209,7 +214,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -238,24 +242,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO0)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO0)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -281,16 +281,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = PIXEL_FRMT_422; int pix_format = PIXEL_FRMT_422;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -306,13 +305,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -326,17 +323,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH00] = 1; dev->use_cif_resolution[SRAM_CH00] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH00] = 0; dev->use_cif_resolution[SRAM_CH00] = 0;
} }
dev->cif_width[SRAM_CH00] = fh->width; dev->cif_width[SRAM_CH00] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH00); medusa_set_resolution(dev, fh->width, SRAM_CH00);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -368,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
dev->name); dev->name);
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 0 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 0 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -452,6 +449,3 @@ struct video_device cx25821_video_template0 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,16 +23,15 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH01]; struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH01];
/* add jump to stopper */ /* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
@ -43,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH01]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH01]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -65,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH01] && h->video_dev[SRAM_CH01]->minor == minor) { if (h->video_dev[SRAM_CH01]
&& h->video_dev[SRAM_CH01]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -134,7 +137,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH01; dev->channel_opened = SRAM_CH01;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -143,8 +148,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -152,17 +156,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO1)) if (res_locked(fh->dev, RESOURCE_VIDEO1))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -170,7 +175,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -189,16 +195,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH01] ) if (dev && dev->use_cif_resolution[SRAM_CH01]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -237,24 +242,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO1)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO1)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -280,17 +281,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -306,13 +305,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -326,17 +323,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH01, pix_format); cx25821_set_pixel_format(dev, SRAM_CH01, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH01] = 1; dev->use_cif_resolution[SRAM_CH01] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH01] = 0; dev->use_cif_resolution[SRAM_CH01] = 0;
} }
dev->cif_width[SRAM_CH01] = fh->width; dev->cif_width[SRAM_CH01] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH01); medusa_set_resolution(dev, fh->width, SRAM_CH01);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -368,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
dev->name); dev->name);
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 1 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 1 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -389,6 +386,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return cx25821_set_control(dev, ctl, SRAM_CH01); return cx25821_set_control(dev, ctl, SRAM_CH01);
} }
//exported stuff //exported stuff
static const struct v4l2_file_operations video_fops = { static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -451,6 +449,3 @@ struct video_device cx25821_video_template1 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,16 +23,15 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH02]; struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH02];
/* add jump to stopper */ /* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
@ -43,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH02]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH02]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -65,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH02] && h->video_dev[SRAM_CH02]->minor == minor) { if (h->video_dev[SRAM_CH02]
&& h->video_dev[SRAM_CH02]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -133,7 +136,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH02; dev->channel_opened = SRAM_CH02;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -142,8 +147,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -151,17 +155,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO2)) if (res_locked(fh->dev, RESOURCE_VIDEO2))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -169,7 +174,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -188,16 +194,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH02] ) if (dev && dev->use_cif_resolution[SRAM_CH02]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -208,7 +213,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -237,24 +241,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO2)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO2)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -280,17 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -306,13 +304,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -326,18 +322,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH02, pix_format); cx25821_set_pixel_format(dev, SRAM_CH02, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH02] = 1; dev->use_cif_resolution[SRAM_CH02] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH02] = 0; dev->use_cif_resolution[SRAM_CH02] = 0;
} }
dev->cif_width[SRAM_CH02] = fh->width; dev->cif_width[SRAM_CH02] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH02); medusa_set_resolution(dev, fh->width, SRAM_CH02);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -371,7 +365,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 2 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 2 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -392,6 +387,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return cx25821_set_control(dev, ctl, SRAM_CH02); return cx25821_set_control(dev, ctl, SRAM_CH02);
} }
// exported stuff // exported stuff
static const struct v4l2_file_operations video_fops = { static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -454,6 +450,3 @@ struct video_device cx25821_video_template2 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,16 +23,15 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH03]; struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH03];
/* add jump to stopper */ /* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
@ -43,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH03]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH03]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -65,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH03] && h->video_dev[SRAM_CH03]->minor == minor) { if (h->video_dev[SRAM_CH03]
&& h->video_dev[SRAM_CH03]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -133,7 +136,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH03; dev->channel_opened = SRAM_CH03;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -142,8 +147,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -151,17 +155,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO3)) if (res_locked(fh->dev, RESOURCE_VIDEO3))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -169,7 +174,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -188,16 +194,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH03] ) if (dev && dev->use_cif_resolution[SRAM_CH03]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -208,7 +213,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -237,24 +241,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO3)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO3)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -280,17 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -306,13 +304,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -326,17 +322,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH03, pix_format); cx25821_set_pixel_format(dev, SRAM_CH03, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH03] = 1; dev->use_cif_resolution[SRAM_CH03] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH03] = 0; dev->use_cif_resolution[SRAM_CH03] = 0;
} }
dev->cif_width[SRAM_CH03] = fh->width; dev->cif_width[SRAM_CH03] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH03); medusa_set_resolution(dev, fh->width, SRAM_CH03);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -369,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 3 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 3 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -453,6 +449,3 @@ struct video_device cx25821_video_template3 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH04]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH04]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH04] && h->video_dev[SRAM_CH04]->minor == minor) { if (h->video_dev[SRAM_CH04]
&& h->video_dev[SRAM_CH04]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -132,7 +136,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH04; dev->channel_opened = SRAM_CH04;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -140,8 +146,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -149,17 +154,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO4)) if (res_locked(fh->dev, RESOURCE_VIDEO4))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -167,7 +173,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -186,16 +193,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH04] ) if (dev && dev->use_cif_resolution[SRAM_CH04]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -206,7 +212,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -235,24 +240,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO4)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO4)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -278,9 +279,8 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@ -288,8 +288,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
int pix_format = 0; int pix_format = 0;
// check priority // check priority
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -304,13 +303,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -324,17 +321,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH04, pix_format); cx25821_set_pixel_format(dev, SRAM_CH04, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH04] = 1; dev->use_cif_resolution[SRAM_CH04] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH04] = 0; dev->use_cif_resolution[SRAM_CH04] = 0;
} }
dev->cif_width[SRAM_CH04] = fh->width; dev->cif_width[SRAM_CH04] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH04); medusa_set_resolution(dev, fh->width, SRAM_CH04);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -367,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 4 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 4 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -451,6 +448,3 @@ struct video_device cx25821_video_template4 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH05]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH05]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH05] && h->video_dev[SRAM_CH05]->minor == minor) { if (h->video_dev[SRAM_CH05]
&& h->video_dev[SRAM_CH05]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -132,7 +136,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH05; dev->channel_opened = SRAM_CH05;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -141,8 +147,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -150,17 +155,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO5)) if (res_locked(fh->dev, RESOURCE_VIDEO5))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -168,7 +174,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -187,16 +194,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH05] ) if (dev && dev->use_cif_resolution[SRAM_CH05]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -207,7 +213,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -236,24 +241,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO5)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO5)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -279,16 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -304,13 +304,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -324,17 +322,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH05, pix_format); cx25821_set_pixel_format(dev, SRAM_CH05, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH05] = 1; dev->use_cif_resolution[SRAM_CH05] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH05] = 0; dev->use_cif_resolution[SRAM_CH05] = 0;
} }
dev->cif_width[SRAM_CH05] = fh->width; dev->cif_width[SRAM_CH05] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH05); medusa_set_resolution(dev, fh->width, SRAM_CH05);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -366,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 5 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 5 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -450,6 +448,3 @@ struct video_device cx25821_video_template5 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH06]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH06]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH06] && h->video_dev[SRAM_CH06]->minor == minor) { if (h->video_dev[SRAM_CH06]
&& h->video_dev[SRAM_CH06]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -132,7 +136,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH06; dev->channel_opened = SRAM_CH06;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -141,8 +147,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -150,17 +155,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO6)) if (res_locked(fh->dev, RESOURCE_VIDEO6))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -168,7 +174,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -187,16 +194,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH06] ) if (dev && dev->use_cif_resolution[SRAM_CH06]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -207,7 +213,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -235,24 +240,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO6)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO6)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -278,16 +279,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -303,13 +303,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -323,17 +321,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH06, pix_format); cx25821_set_pixel_format(dev, SRAM_CH06, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH06] = 1; dev->use_cif_resolution[SRAM_CH06] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH06] = 0; dev->use_cif_resolution[SRAM_CH06] = 0;
} }
dev->cif_width[SRAM_CH06] = fh->width; dev->cif_width[SRAM_CH06] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH06); medusa_set_resolution(dev, fh->width, SRAM_CH06);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -366,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 6 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 6 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -450,6 +448,3 @@ struct video_device cx25821_video_template6 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -41,21 +41,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH07]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH07]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -63,22 +67,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -86,7 +91,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -97,11 +101,11 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH07] && h->video_dev[SRAM_CH07]->minor == minor) { if (h->video_dev[SRAM_CH07]
&& h->video_dev[SRAM_CH07]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -131,7 +135,9 @@ static int video_open(struct file *file)
fh->height = 480; fh->height = 480;
dev->channel_opened = SRAM_CH07; dev->channel_opened = SRAM_CH07;
pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; pix_format =
(dev->pixel_formats[dev->channel_opened] ==
PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format); fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio, &fh->prio); v4l2_prio_open(&dev->prio, &fh->prio);
@ -140,8 +146,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -149,17 +154,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO7)) if (res_locked(fh->dev, RESOURCE_VIDEO7))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -167,7 +173,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -186,16 +193,15 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
} }
poll_wait(file, &buf->vb.done, wait); poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
{ if (buf->vb.state == VIDEOBUF_DONE) {
if( buf->vb.state == VIDEOBUF_DONE )
{
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH07] ) if (dev && dev->use_cif_resolution[SRAM_CH07]) {
{
u8 cam_id = *((char *)buf->vb.baddr + 3); u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id; *((char *)buf->vb.baddr + 3) = cam_id;
} }
} }
@ -206,7 +212,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -235,24 +240,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO7)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO7)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -278,16 +279,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
int pix_format = 0; int pix_format = 0;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -303,13 +303,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
// check if width and height is valid based on set standard // check if width and height is valid based on set standard
if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
{
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
} }
if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
{
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
} }
@ -323,17 +321,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
cx25821_set_pixel_format(dev, SRAM_CH07, pix_format); cx25821_set_pixel_format(dev, SRAM_CH07, pix_format);
// check if cif resolution // check if cif resolution
if (fh->width == 320 || fh->width == 352) if (fh->width == 320 || fh->width == 352) {
{
dev->use_cif_resolution[SRAM_CH07] = 1; dev->use_cif_resolution[SRAM_CH07] = 1;
}else } else {
{
dev->use_cif_resolution[SRAM_CH07] = 0; dev->use_cif_resolution[SRAM_CH07] = 0;
} }
dev->cif_width[SRAM_CH07] = fh->width; dev->cif_width[SRAM_CH07] = fh->width;
medusa_set_resolution(dev, fh->width, SRAM_CH07); medusa_set_resolution(dev, fh->width, SRAM_CH07);
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
@ -365,7 +362,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status); cx25821_call_all(dev, core, log_status);
tmp = cx_read(sram_ch->dma_ctl); tmp = cx_read(sram_ch->dma_ctl);
printk(KERN_INFO "Video input 7 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); printk(KERN_INFO "Video input 7 is %s\n",
(tmp & 0x11) ? "streaming" : "stopped");
printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
dev->name); dev->name);
return 0; return 0;
@ -449,6 +447,3 @@ struct video_device cx25821_video_template7 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[VIDEO_IOCTL_CH]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[VIDEO_IOCTL_CH]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,12 +102,10 @@ static int video_open(struct file *file)
u32 pix_format; u32 pix_format;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->ioctl_dev && h->ioctl_dev->minor == minor) if (h->ioctl_dev && h->ioctl_dev->minor == minor) {
{
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -143,8 +145,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -152,17 +153,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO_IOCTL)) if (res_locked(fh->dev, RESOURCE_VIDEO_IOCTL))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -170,7 +172,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -195,7 +198,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -222,24 +224,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO_IOCTL)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO_IOCTL)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -265,15 +263,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -288,7 +285,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
} }
@ -299,7 +297,8 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
} }
static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long arg) static long video_ioctl_set(struct file *file, unsigned int cmd,
unsigned long arg)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -310,28 +309,28 @@ static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long a
int cif_enable = 0, cif_width = 0; int cif_enable = 0, cif_width = 0;
u32 value = 0; u32 value = 0;
data_from_user = (struct downstream_user_struct *)arg; data_from_user = (struct downstream_user_struct *)arg;
if( !data_from_user ) if (!data_from_user) {
{ printk("cx25821 in %s(): User data is INVALID. Returning.\n",
printk("cx25821 in %s(): User data is INVALID. Returning.\n", __func__); __func__);
return 0; return 0;
} }
command = data_from_user->command; command = data_from_user->command;
if( command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT && command != ENABLE_CIF_RESOLUTION && if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
command != REG_READ && command != REG_WRITE && command != MEDUSA_READ && command != MEDUSA_WRITE) && command != ENABLE_CIF_RESOLUTION && command != REG_READ
{ && command != REG_WRITE && command != MEDUSA_READ
&& command != MEDUSA_WRITE) {
return 0; return 0;
} }
switch (command) {
switch(command)
{
case SET_VIDEO_STD: case SET_VIDEO_STD:
dev->tvnorm = !strcmp(data_from_user->vid_stdname,"PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M; dev->tvnorm =
!strcmp(data_from_user->vid_stdname,
"PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
medusa_set_videostandard(dev); medusa_set_videostandard(dev);
break; break;
@ -339,14 +338,14 @@ static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long a
selected_channel = data_from_user->decoder_select; selected_channel = data_from_user->decoder_select;
pix_format = data_from_user->pixel_format; pix_format = data_from_user->pixel_format;
if( !(selected_channel <= 7 && selected_channel >= 0) ) if (!(selected_channel <= 7 && selected_channel >= 0)) {
{
selected_channel -= 4; selected_channel -= 4;
selected_channel = selected_channel % 8; selected_channel = selected_channel % 8;
} }
if (selected_channel >= 0) if (selected_channel >= 0)
cx25821_set_pixel_format( dev, selected_channel, pix_format ); cx25821_set_pixel_format(dev, selected_channel,
pix_format);
break; break;
@ -355,30 +354,25 @@ static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long a
cif_enable = data_from_user->cif_resolution_enable; cif_enable = data_from_user->cif_resolution_enable;
cif_width = data_from_user->cif_width; cif_width = data_from_user->cif_width;
if( cif_enable ) if (cif_enable) {
{ if (dev->tvnorm & V4L2_STD_PAL_BG
if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK ) || dev->tvnorm & V4L2_STD_PAL_DK)
width = 352; width = 352;
else else
width = (cif_width == 320 || cif_width == 352) ? cif_width : 320; width = (cif_width == 320
|| cif_width == 352) ? cif_width : 320;
} }
if( !(selected_channel <= 7 && selected_channel >= 0) ) if (!(selected_channel <= 7 && selected_channel >= 0)) {
{
selected_channel -= 4; selected_channel -= 4;
selected_channel = selected_channel % 8; selected_channel = selected_channel % 8;
} }
if (selected_channel <= 7 && selected_channel >= 0) {
if( selected_channel <= 7 && selected_channel >= 0 )
{
dev->use_cif_resolution[selected_channel] = cif_enable; dev->use_cif_resolution[selected_channel] = cif_enable;
dev->cif_width[selected_channel] = width; dev->cif_width[selected_channel] = width;
} } else {
else for (i = 0; i < VID_CHANNEL_NUM; i++) {
{
for( i=0; i < VID_CHANNEL_NUM; i++ )
{
dev->use_cif_resolution[i] = cif_enable; dev->use_cif_resolution[i] = cif_enable;
dev->cif_width[i] = width; dev->cif_width[i] = width;
} }
@ -393,10 +387,15 @@ static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long a
cx_write(data_from_user->reg_address, data_from_user->reg_data); cx_write(data_from_user->reg_address, data_from_user->reg_data);
break; break;
case MEDUSA_READ: case MEDUSA_READ:
value = cx25821_i2c_read(&dev->i2c_bus[0], (u16)data_from_user->reg_address, &data_from_user->reg_data); value =
cx25821_i2c_read(&dev->i2c_bus[0],
(u16) data_from_user->reg_address,
&data_from_user->reg_data);
break; break;
case MEDUSA_WRITE: case MEDUSA_WRITE:
cx25821_i2c_write(&dev->i2c_bus[0], (u16)data_from_user->reg_address, data_from_user->reg_data); cx25821_i2c_write(&dev->i2c_bus[0],
(u16) data_from_user->reg_address,
data_from_user->reg_data);
break; break;
} }
@ -424,8 +423,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -433,6 +431,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return 0; return 0;
} }
// exported stuff // exported stuff
static const struct v4l2_file_operations video_fops = { static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -495,6 +494,3 @@ struct video_device cx25821_videoioctl_template = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,16 +23,15 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH10]; struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH10];
/* add jump to stopper */ /* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
@ -43,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH10]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH10]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -65,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -98,11 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0; enum v4l2_buf_type type = 0;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH10] && h->video_dev[SRAM_CH10]->minor == minor) { if (h->video_dev[SRAM_CH10]
&& h->video_dev[SRAM_CH10]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -132,7 +135,6 @@ static int video_open(struct file *file)
else else
fh->height = 480; fh->height = 480;
dev->channel_opened = 9; dev->channel_opened = 9;
fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV); fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
@ -142,8 +144,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -151,17 +152,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO10)) if (res_locked(fh->dev, RESOURCE_VIDEO10))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -169,7 +171,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO10)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO10)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -265,27 +264,26 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
static long video_ioctl_upstream10(struct file *file, unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
int command = 0; int command = 0;
struct upstream_user_struct *data_from_user; struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg; data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user ) if (!data_from_user) {
{ printk
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__); ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0; return 0;
} }
command = data_from_user->command; command = data_from_user->command;
if( command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO ) if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) {
{
return 0; return 0;
} }
@ -296,9 +294,7 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd, unsigned
dev->channel_select_ch2 = data_from_user->channel_select; dev->channel_select_ch2 = data_from_user->channel_select;
dev->command_ch2 = data_from_user->command; dev->command_ch2 = data_from_user->command;
switch (command) {
switch(command)
{
case UPSTREAM_START_VIDEO: case UPSTREAM_START_VIDEO:
cx25821_start_upstream_video_ch2(dev, data_from_user); cx25821_start_upstream_video_ch2(dev, data_from_user);
break; break;
@ -311,15 +307,14 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd, unsigned
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -334,7 +329,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
} }
@ -366,8 +362,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -438,6 +433,3 @@ struct video_device cx25821_video_template10 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -23,10 +23,10 @@
#include "cx25821-video.h" #include "cx25821-video.h"
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{ {
struct cx25821_buffer *buf = container_of(vb, struct cx25821_buffer, vb); struct cx25821_buffer *buf =
container_of(vb, struct cx25821_buffer, vb);
struct cx25821_buffer *prev; struct cx25821_buffer *prev;
struct cx25821_fh *fh = vq->priv_data; struct cx25821_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
@ -42,21 +42,25 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
if (!list_empty(&q->queued)) { if (!list_empty(&q->queued)) {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
buf->vb.i);
} else if (list_empty(&q->active)) { } else if (list_empty(&q->active)) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH09]); cx25821_start_video_dma(dev, q, buf,
&dev->sram_channels[SRAM_CH09]);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count); buf, buf->vb.i, buf->count, q->count);
} else { } else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); prev =
if (prev->vb.width == buf->vb.width && list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
prev->vb.height == buf->vb.height && if (prev->vb.width == buf->vb.width
prev->fmt == buf->fmt) { && prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active); list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE; buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++; buf->count = q->count++;
@ -64,22 +68,23 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
/* 64 bit bits 63-32 */ /* 64 bit bits 63-32 */
prev->risc.jmp[2] = cpu_to_le32(0); prev->risc.jmp[2] = cpu_to_le32(0);
dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); dprintk(2,
"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
buf, buf->vb.i, buf->count);
} else { } else {
list_add_tail(&buf->vb.queue, &q->queued); list_add_tail(&buf->vb.queue, &q->queued);
buf->vb.state = VIDEOBUF_QUEUED; buf->vb.state = VIDEOBUF_QUEUED;
dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
buf->vb.i);
} }
} }
if (list_empty(&q->active)) if (list_empty(&q->active)) {
{
dprintk(2, "active queue empty!\n"); dprintk(2, "active queue empty!\n");
} }
} }
static struct videobuf_queue_ops cx25821_video_qops = { static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup, .buf_setup = buffer_setup,
.buf_prepare = buffer_prepare, .buf_prepare = buffer_prepare,
@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release, .buf_release = buffer_release,
}; };
static int video_open(struct file *file) static int video_open(struct file *file)
{ {
int minor = video_devdata(file)->minor; int minor = video_devdata(file)->minor;
@ -97,12 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0; enum v4l2_buf_type type = 0;
lock_kernel(); lock_kernel();
list_for_each(list, &cx25821_devlist) list_for_each(list, &cx25821_devlist) {
{
h = list_entry(list, struct cx25821_dev, devlist); h = list_entry(list, struct cx25821_dev, devlist);
if (h->video_dev[SRAM_CH09] && h->video_dev[SRAM_CH09]->minor == minor) if (h->video_dev[SRAM_CH09]
{ && h->video_dev[SRAM_CH09]->minor == minor) {
dev = h; dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
} }
@ -141,8 +144,7 @@ static int video_open(struct file *file)
&dev->pci->dev, &dev->slock, &dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED, V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer), sizeof(struct cx25821_buffer), fh);
fh);
dprintk(1, "post videobuf_queue_init()\n"); dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel(); unlock_kernel();
@ -150,17 +152,18 @@ static int video_open(struct file *file)
return 0; return 0;
} }
static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) static ssize_t video_read(struct file *file, char __user * data, size_t count,
loff_t * ppos)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
switch (fh->type) switch (fh->type) {
{
case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO9)) if (res_locked(fh->dev, RESOURCE_VIDEO9))
return -EBUSY; return -EBUSY;
return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); return videobuf_read_one(&fh->vidq, data, count, ppos,
file->f_flags & O_NONBLOCK);
default: default:
BUG(); BUG();
@ -168,7 +171,8 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
} }
} }
static unsigned int video_poll(struct file *file, struct poll_table_struct *wait) static unsigned int video_poll(struct file *file,
struct poll_table_struct *wait)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_buffer *buf; struct cx25821_buffer *buf;
@ -192,7 +196,6 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
return 0; return 0;
} }
static int video_release(struct file *file) static int video_release(struct file *file)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0; return 0;
} }
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(i != fh->type)) if (unlikely(i != fh->type)) {
{
return -EINVAL; return -EINVAL;
} }
if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO9)))) if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO9)))) {
{
return -EBUSY; return -EBUSY;
} }
@ -265,31 +264,29 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0; return 0;
} }
static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
static long video_ioctl_upstream9(struct file *file, unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
struct cx25821_fh *fh = file->private_data; struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev; struct cx25821_dev *dev = fh->dev;
int command = 0; int command = 0;
struct upstream_user_struct *data_from_user; struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg; data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user ) if (!data_from_user) {
{ printk
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__); ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0; return 0;
} }
command = data_from_user->command; command = data_from_user->command;
if( command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO ) if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) {
{
return 0; return 0;
} }
dev->input_filename = data_from_user->input_filename; dev->input_filename = data_from_user->input_filename;
dev->input_audiofilename = data_from_user->input_filename; dev->input_audiofilename = data_from_user->input_filename;
dev->vid_stdname = data_from_user->vid_stdname; dev->vid_stdname = data_from_user->vid_stdname;
@ -297,9 +294,7 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd, unsigned
dev->channel_select = data_from_user->channel_select; dev->channel_select = data_from_user->channel_select;
dev->command = data_from_user->command; dev->command = data_from_user->command;
switch (command) {
switch(command)
{
case UPSTREAM_START_VIDEO: case UPSTREAM_START_VIDEO:
cx25821_start_upstream_video_ch1(dev, data_from_user); cx25821_start_upstream_video_ch1(dev, data_from_user);
break; break;
@ -312,15 +307,14 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd, unsigned
return 0; return 0;
} }
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -335,7 +329,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
fh->width = f->fmt.pix.width; fh->width = f->fmt.pix.width;
fh->height = f->fmt.pix.height; fh->height = f->fmt.pix.height;
fh->vidq.field = f->fmt.pix.field; fh->vidq.field = f->fmt.pix.field;
dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
fh->height, fh->vidq.field);
cx25821_call_all(dev, video, s_fmt, f); cx25821_call_all(dev, video, s_fmt, f);
return 0; return 0;
} }
@ -365,8 +360,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
struct cx25821_fh *fh = priv; struct cx25821_fh *fh = priv;
int err; int err;
if (fh) if (fh) {
{
err = v4l2_prio_check(&dev->prio, &fh->prio); err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err) if (0 != err)
return err; return err;
@ -374,6 +368,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return 0; return 0;
} }
// exported stuff // exported stuff
static const struct v4l2_file_operations video_fops = { static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -436,6 +431,3 @@ struct video_device cx25821_video_template9 = {
.tvnorms = CX25821_NORMS, .tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M, .current_norm = V4L2_STD_NTSC_M,
}; };

View File

@ -21,7 +21,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef CX25821_H_ #ifndef CX25821_H_
#define CX25821_H_ #define CX25821_H_
@ -85,7 +84,6 @@
#define RESOURCE_VIDEO11 2048 #define RESOURCE_VIDEO11 2048
#define RESOURCE_VIDEO_IOCTL 4096 #define RESOURCE_VIDEO_IOCTL 4096
#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */ #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
#define UNKNOWN_BOARD 0 #define UNKNOWN_BOARD 0
@ -346,7 +344,6 @@ struct cx25821_dev {
char *_filename; char *_filename;
char *_defaultname; char *_defaultname;
int _line_size_ch2; int _line_size_ch2;
int _prog_cnt_ch2; int _prog_cnt_ch2;
int _pixel_format_ch2; int _pixel_format_ch2;
@ -410,7 +407,6 @@ struct cx25821_dev {
int channel_opened; int channel_opened;
}; };
struct upstream_user_struct { struct upstream_user_struct {
char *input_filename; char *input_filename;
char *vid_stdname; char *vid_stdname;
@ -458,8 +454,6 @@ extern struct cx25821_subid cx25821_subids[];
#define SRAM_CH10 10 /* Video Upstream J */ #define SRAM_CH10 10 /* Video Upstream J */
#define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */ #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
#define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09 #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
#define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10 #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
#define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11 #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
@ -529,59 +523,77 @@ extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
extern int cx25821_i2c_unregister(struct cx25821_i2c *bus); extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
extern void cx25821_gpio_init(struct cx25821_dev *dev); extern void cx25821_gpio_init(struct cx25821_dev *dev);
extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev, extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
int pin_number, int pin_number, int pin_logic_value);
int pin_logic_value);
extern int medusa_video_init(struct cx25821_dev *dev); extern int medusa_video_init(struct cx25821_dev *dev);
extern int medusa_set_videostandard(struct cx25821_dev *dev); extern int medusa_set_videostandard(struct cx25821_dev *dev);
extern void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_select); extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder); int decoder_select);
extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder); extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
int decoder);
extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
int decoder);
extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder); extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder); extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
int decoder);
extern int cx25821_sram_channel_setup(struct cx25821_dev *dev, struct sram_channel *ch, unsigned int bpl, u32 risc); extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
struct sram_channel *ch, unsigned int bpl,
u32 risc);
extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
struct scatterlist *sglist, struct scatterlist *sglist,
unsigned int top_offset, unsigned int top_offset,
unsigned int bottom_offset, unsigned int bottom_offset,
unsigned int bpl, unsigned int bpl,
unsigned int padding, unsigned int padding, unsigned int lines);
unsigned int lines);
extern int cx25821_risc_databuffer_audio(struct pci_dev *pci, extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
struct btcx_riscmem *risc, struct btcx_riscmem *risc,
struct scatterlist *sglist, struct scatterlist *sglist,
unsigned int bpl, unsigned int bpl,
unsigned int lines, unsigned int lines, unsigned int lpi);
unsigned int lpi); extern void cx25821_free_buffer(struct videobuf_queue *q,
extern void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf); struct cx25821_buffer *buf);
extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,u32 reg, u32 mask, u32 value); extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
extern void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch); u32 reg, u32 mask, u32 value);
extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channel *ch); extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
struct sram_channel *ch);
extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
struct sram_channel *ch);
extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci); extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
extern void cx25821_print_irqbits(char *name, char *tag, char **strings, int len, u32 bits, u32 mask); extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
int len, u32 bits, u32 mask);
extern void cx25821_dev_unregister(struct cx25821_dev *dev); extern void cx25821_dev_unregister(struct cx25821_dev *dev);
extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev, extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
struct sram_channel *ch, struct sram_channel *ch,
unsigned int bpl, u32 risc); unsigned int bpl, u32 risc);
extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, int pixel_format); extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, int pixel_format); int channel_select, int pixel_format);
extern int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select); extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
int channel_select, int pixel_format);
extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
int channel_select);
extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev); extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev); extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev); extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev, struct upstream_user_struct *up_data); extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev, struct upstream_user_struct *up_data); struct upstream_user_struct
extern void cx25821_start_upstream_audio(struct cx25821_dev *dev, struct upstream_user_struct *up_data); *up_data);
extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
struct upstream_user_struct
*up_data);
extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
struct upstream_user_struct *up_data);
extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev); extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev); extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev); extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
extern int cx25821_sram_channel_setup_upstream( struct cx25821_dev *dev, struct sram_channel *ch, unsigned int bpl, u32 risc); extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel, u32 format); struct sram_channel *ch,
unsigned int bpl, u32 risc);
extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
u32 format);
extern void cx25821_videoioctl_unregister(struct cx25821_dev *dev); extern void cx25821_videoioctl_unregister(struct cx25821_dev *dev);
extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev, extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
struct pci_dev *pci, struct pci_dev *pci,