Commit 1a9fc855 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

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: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent bb4c9a74
......@@ -20,7 +20,6 @@
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
......@@ -37,7 +36,6 @@
#include <sound/initval.h>
#include <sound/tlv.h>
#include "cx25821.h"
#include "cx25821-reg.h"
......@@ -49,12 +47,10 @@
#define dprintk_core(level,fmt, arg...) if (debug >= level) \
printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg)
/****************************************************************************
Data type declarations - Can be moded to a header file later
****************************************************************************/
static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
static int devno;
......@@ -87,14 +83,13 @@ struct cx25821_audio_dev {
typedef struct cx25821_audio_dev snd_cx25821_card_t;
/****************************************************************************
Module global static vars
****************************************************************************/
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
static int enable[SNDRV_CARDS] = { 1,[1...(SNDRV_CARDS - 1)] = 1 };
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
......@@ -102,7 +97,6 @@ MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
/****************************************************************************
Module macros
****************************************************************************/
......@@ -110,11 +104,11 @@ MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
MODULE_DESCRIPTION("ALSA driver module for cx25821 based capture cards");
MODULE_AUTHOR("Hiep Huynh");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{Conexant,25821}");//"{{Conexant,23881},"
MODULE_SUPPORTED_DEVICE("{{Conexant,25821}"); //"{{Conexant,23881},"
static unsigned int debug;
module_param(debug,int,0644);
MODULE_PARM_DESC(debug,"enable debug messages");
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "enable debug messages");
/****************************************************************************
Module specific funtions
......@@ -140,21 +134,24 @@ MODULE_PARM_DESC(debug,"enable debug messages");
* BOARD Specific: Sets audio DMA
*/
static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
{
struct cx25821_buffer *buf = chip->buf;
struct cx25821_dev * dev = chip->dev;
struct sram_channel *audio_ch = &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
struct cx25821_dev *dev = chip->dev;
struct sram_channel *audio_ch =
&cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
u32 tmp = 0;
// 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 */
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 */
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 */
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
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 "
// "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);
/* 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 */
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
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);
return 0;
......@@ -192,16 +193,19 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
/*
* BOARD Specific: Resets audio DMA
*/
static int _cx25821_stop_audio_dma(snd_cx25821_card_t *chip)
static int _cx25821_stop_audio_dma(snd_cx25821_card_t * chip)
{
struct cx25821_dev *dev = chip->dev;
/* 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 */
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;
}
......@@ -227,35 +231,39 @@ static char *cx25821_aud_irqs[32] = {
/*
* BOARD Specific: Threats IRQ audio specific calls
*/
static void cx25821_aud_irq(snd_cx25821_card_t *chip, u32 status, u32 mask)
static void cx25821_aud_irq(snd_cx25821_card_t * chip, u32 status, u32 mask)
{
struct cx25821_dev *dev = chip->dev;
if (0 == (status & mask))
{
if (0 == (status & mask)) {
return;
}
cx_write(AUD_A_INT_STAT, status);
if (debug > 1 || (status & mask & ~0xff))
cx25821_print_irqbits(dev->name, "irq aud",
cx25821_aud_irqs, ARRAY_SIZE(cx25821_aud_irqs),
status, mask);
cx25821_aud_irqs,
ARRAY_SIZE(cx25821_aud_irqs), status,
mask);
/* risc op code error */
if (status & AUD_INT_OPC_ERR) {
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 );
cx25821_sram_channel_dump_audio(dev, &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]);
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);
cx25821_sram_channel_dump_audio(dev,
&cx25821_sram_channels
[AUDIO_SRAM_CHANNEL]);
}
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);
return;
}
/* risc1 downstream */
if (status & AUD_INT_DN_RISCI1) {
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
*/
......@@ -276,30 +283,26 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
int loop, handled = 0;
int audint_count = 0;
audint_status = cx_read(AUD_A_INT_STAT);
audint_mask = cx_read(AUD_A_INT_MSK);
audint_count = cx_read(AUD_A_GPCNT);
status = cx_read(PCI_INT_STAT);
for (loop = 0; loop < 1; loop++)
{
for (loop = 0; loop < 1; loop++) {
status = cx_read(PCI_INT_STAT);
if (0 == status)
{
if (0 == status) {
status = cx_read(PCI_INT_STAT);
audint_status = cx_read(AUD_A_INT_STAT);
audint_mask = cx_read(AUD_A_INT_MSK);
if (status)
{
if (status) {
handled = 1;
cx_write(PCI_INT_STAT, status);
cx25821_aud_irq(chip, audint_status, audint_mask);
cx25821_aud_irq(chip, audint_status,
audint_mask);
break;
}
else
} else
goto out;
}
......@@ -318,15 +321,14 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
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);
dprintk(2,"Freeing buffer\n");
dprintk(2, "Freeing buffer\n");
videobuf_sg_dma_unmap(&chip->pci->dev, chip->dma_risc);
videobuf_dma_free(chip->dma_risc);
btcx_riscmem_free(chip->pci,&chip->buf->risc);
btcx_riscmem_free(chip->pci, &chip->buf->risc);
kfree(chip->buf);
chip->dma_risc = NULL;
......@@ -346,8 +348,7 @@ static int dsp_buffer_free(snd_cx25821_card_t *chip)
static struct snd_pcm_hardware snd_cx25821_digital_hw = {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID,
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_48000,
......@@ -357,15 +358,13 @@ static struct snd_pcm_hardware snd_cx25821_digital_hw = {
.channels_max = 2,
/* Analog audio output will be full of clicks and pops if there
are not exactly four lines in the SRAM FIFO buffer. */
.period_bytes_min = DEFAULT_FIFO_SIZE/3,
.period_bytes_max = DEFAULT_FIFO_SIZE/3,
.period_bytes_min = DEFAULT_FIFO_SIZE / 3,
.period_bytes_max = DEFAULT_FIFO_SIZE / 3,
.periods_min = 1,
.periods_max = AUDIO_LINE_SIZE,
.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
*/
......@@ -382,7 +381,8 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
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)
goto _error;
......@@ -390,13 +390,12 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
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 &= ~7; /* must be multiple of 8 */
if( bpl > AUDIO_LINE_SIZE )
{
if (bpl > AUDIO_LINE_SIZE) {
bpl = AUDIO_LINE_SIZE;
}
runtime->hw.period_bytes_min = bpl;
......@@ -404,8 +403,8 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
}
return 0;
_error:
dprintk(1,"Error opening PCM!\n");
_error:
dprintk(1, "Error opening PCM!\n");
return err;
}
......@@ -420,8 +419,8 @@ static int snd_cx25821_close(struct snd_pcm_substream *substream)
/*
* hw_params callback
*/
static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
struct snd_pcm_hw_params * hw_params)
static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
struct videobuf_dmabuf *dma;
......@@ -434,25 +433,21 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
substream->runtime->dma_area = NULL;
}
chip->period_size = params_period_bytes(hw_params);
chip->num_periods = params_periods(hw_params);
chip->dma_size = chip->period_size * params_periods(hw_params);
BUG_ON(!chip->dma_size);
BUG_ON(chip->num_periods & (chip->num_periods-1));
BUG_ON(chip->num_periods & (chip->num_periods - 1));
buf = videobuf_sg_alloc(sizeof(*buf));
if (NULL == buf)
return -ENOMEM;
if( chip->period_size > AUDIO_LINE_SIZE )
{
if (chip->period_size > AUDIO_LINE_SIZE) {
chip->period_size = AUDIO_LINE_SIZE;
}
buf->vb.memory = V4L2_MEMORY_MMAP;
buf->vb.field = V4L2_FIELD_NONE;
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);
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)
goto error;
......@@ -472,17 +468,17 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
if (ret < 0)
goto error;
ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, buf->vb.width, buf->vb.height, 1);
if (ret < 0)
{
printk(KERN_INFO "DEBUG: ERROR after cx25821_risc_databuffer_audio() \n");
ret =
cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist,
buf->vb.width, buf->vb.height, 1);
if (ret < 0) {
printk(KERN_INFO
"DEBUG: ERROR after cx25821_risc_databuffer_audio() \n");
goto error;
}
/* 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[2] = cpu_to_le32(0); /* bits 63-32 */
......@@ -497,7 +493,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
return 0;
error:
error:
kfree(buf);
return ret;
}
......@@ -505,7 +501,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
/*
* hw free callback
*/
static int snd_cx25821_hw_free(struct snd_pcm_substream * substream)
static int snd_cx25821_hw_free(struct snd_pcm_substream *substream)
{
snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
......@@ -528,7 +524,8 @@ static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
/*
* 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);
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 */
spin_lock(&chip->reg_lock);
switch (cmd)
{
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
err = _cx25821_start_audio_dma(chip);
break;
......@@ -557,7 +553,8 @@ static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream, int cmd
/*
* 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);
struct snd_pcm_runtime *runtime = substream->runtime;
......@@ -565,7 +562,7 @@ static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream *substream
count = atomic_read(&chip->count);
return runtime->period_size * (count & (runtime->periods-1));
return runtime->period_size * (count & (runtime->periods - 1));
}
/*
......@@ -594,20 +591,19 @@ static struct snd_pcm_ops snd_cx25821_pcm_ops = {
.page = snd_cx25821_page,
};
/*
* ALSA create a PCM device: Called when initializing the board. Sets up the name and hooks up
* the callbacks
*/
static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
static int snd_cx25821_pcm(snd_cx25821_card_t * chip, int device, char *name)
{
struct snd_pcm *pcm;
int err;
err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
if (err < 0)
{
printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n", __func__);
if (err < 0) {
printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n",
__func__);
return err;
}
pcm->private_data = chip;
......@@ -618,7 +614,6 @@ static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
return 0;
}
/****************************************************************************
Basic Flow for Sound Devices
****************************************************************************/
......@@ -629,9 +624,10 @@ static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
*/
static struct pci_device_id cx25821_audio_pci_tbl[] __devinitdata = {
{0x14f1,0x0920,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
{0, }
{0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{0,}
};
MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
/*
......@@ -654,7 +650,7 @@ static int snd_cx25821_free(snd_cx25821_card_t *chip)
/*
* Component Destructor
*/
static void snd_cx25821_dev_free(struct snd_card * card)
static void snd_cx25821_dev_free(struct snd_card *card)
{
snd_cx25821_card_t *chip = card->private_data;
......@@ -662,7 +658,6 @@ static void snd_cx25821_dev_free(struct snd_card * card)
snd_card_free(chip->card);
}
/*
* Alsa Constructor - Component probe
*/
......@@ -672,9 +667,9 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
snd_cx25821_card_t *chip;
int err;
if (devno >= SNDRV_CARDS)
{
printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__);
if (devno >= SNDRV_CARDS) {
printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n",
__func__);
return (-ENODEV);
}
......@@ -684,10 +679,13 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
return (-ENOENT);
}
card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx25821_card_t));
if (!card)
{
printk(KERN_INFO "DEBUG ERROR: cannot create snd_card_new in %s\n", __func__);
card =
snd_card_new(index[devno], id[devno], THIS_MODULE,
sizeof(snd_cx25821_card_t));
if (!card) {
printk(KERN_INFO
"DEBUG ERROR: cannot create snd_card_new in %s\n",
__func__);
return (-ENOMEM);
}
......@@ -703,37 +701,38 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
chip->pci = dev->pci;
chip->iobase = pci_resource_start(dev->pci, 0);
chip->irq = dev->pci->irq;
err = request_irq(dev->pci->irq, cx25821_irq,
IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip);
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;
}
if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0)
{
printk(KERN_INFO "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n", __func__);
if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0) {
printk(KERN_INFO
"DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
__func__);
goto error;
}
snd_card_set_dev(card, &chip->pci->dev);
strcpy(card->shortname, "cx25821");
sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name, chip->iobase, chip->irq);
strcpy (card->mixername, "CX25821");
sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name,
chip->iobase, chip->irq);
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);
if (err < 0)
{
printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n", __func__);
if (err < 0) {
printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n",
__func__);
goto error;
}
......@@ -742,12 +741,11 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
devno++;
return 0;
error:
error:
snd_card_free(card);
return err;
}
/****************************************************************************
LINUX MODULE INIT
****************************************************************************/
......@@ -768,13 +766,14 @@ static int cx25821_alsa_init(void)
struct cx25821_dev *dev = NULL;
struct list_head *list;
list_for_each(list,&cx25821_devlist) {
list_for_each(list, &cx25821_devlist) {
dev = list_entry(list, struct cx25821_dev, devlist);
cx25821_audio_initdev(dev);
}
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;
......
......@@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cx25821-video.h"
#include "cx25821-audio-upstream.h"
......@@ -35,14 +34,13 @@
#include <linux/delay.h>
#include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL");
static int _intr_msk = FLD_AUD_SRC_RISCI1 | FLD_AUD_SRC_OF | FLD_AUD_SRC_SYNC | FLD_AUD_SRC_OPC_ERR;
static int _intr_msk =
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,
struct sram_channel *ch,
......@@ -51,7 +49,6 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
unsigned int i, lines;
u32 cdt;
if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0);
......@@ -64,20 +61,18 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
cdt = ch->cdt;
lines = ch->fifo_size / bpl;
if (lines > 3)
{
if (lines > 3) {
lines = 3;
}
BUG_ON(lines < 2);
/* write CDT */
for (i = 0; i < lines; i++) {
cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
cx_write(cdt + 16*i + 4, 0);
cx_write(cdt + 16*i + 8, 0);
cx_write(cdt + 16*i + 12, 0);
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
cx_write(cdt + 16 * i + 4, 0);
cx_write(cdt + 16 * i + 8, 0);
cx_write(cdt + 16 * i + 12, 0);
}
/* write CMDS */
......@@ -103,27 +98,26 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
return 0;
}
static __le32 *cx25821_risc_field_upstream_audio( struct cx25821_dev *dev, __le32 *rp,
static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
__le32 * rp,
dma_addr_t databuf_phys_addr,
unsigned int bpl, int fifo_enable)
unsigned int bpl,
int fifo_enable)
{
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;
/* scan lines */
for (line = 0; line < LINES_PER_AUDIO_BUFFER; line++)
{
*(rp++) = cpu_to_le32(RISC_READ|RISC_SOL|RISC_EOL|bpl);
for (line = 0; line < LINES_PER_AUDIO_BUFFER; line++) {
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
// 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.
if ( fifo_enable && line == 2 )
{
if (fifo_enable && line == 2) {
*(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl;
*(rp++) = sram_ch->fld_aud_fifo_en;
......@@ -136,7 +130,7 @@ static __le32 *cx25821_risc_field_upstream_audio( struct cx25821_dev *dev, __le3
return rp;
}
int cx25821_risc_buffer_upstream_audio( struct cx25821_dev *dev,
int cx25821_risc_buffer_upstream_audio(struct cx25821_dev *dev,
struct pci_dev *pci,
unsigned int bpl, unsigned int lines)
{
......@@ -148,131 +142,127 @@ int cx25821_risc_buffer_upstream_audio( struct cx25821_dev *dev,
int risc_flag = RISC_CNT_INC;
dma_addr_t risc_phys_jump_addr;
/* Virtual address of Risc buffer program */
rp = dev->_risc_virt_addr;
/* sync instruction */
*(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;
if( frame == 0 )
{
if (frame == 0) {
fifo_enable = 1;
risc_flag = RISC_CNT_RESET;
}
else
{
} else {
fifo_enable = 0;
risc_flag = RISC_CNT_INC;
}
//Calculate physical jump address
if( (frame+1) == NUM_AUDIO_FRAMES )
{
risc_phys_jump_addr = dev->_risc_phys_start_addr + RISC_SYNC_INSTRUCTION_SIZE;
}
else
{
risc_phys_jump_addr = 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);
if( USE_RISC_NOOP_AUDIO )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
if ((frame + 1) == NUM_AUDIO_FRAMES) {
risc_phys_jump_addr =
dev->_risc_phys_start_addr +
RISC_SYNC_INSTRUCTION_SIZE;
} else {
risc_phys_jump_addr =
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);
if (USE_RISC_NOOP_AUDIO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) = cpu_to_le32(RISC_NOOP);
}
}
// 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(0);
//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;
}
void cx25821_free_memory_audio(struct cx25821_dev *dev)
{
if (dev->_risc_virt_addr)
{
pci_free_consistent(dev->pci, dev->_audiorisc_size, dev->_risc_virt_addr, dev->_risc_phys_addr);
if (dev->_risc_virt_addr) {
pci_free_consistent(dev->pci, dev->_audiorisc_size,
dev->_risc_virt_addr, dev->_risc_phys_addr);
dev->_risc_virt_addr = NULL;
}
if (dev->_audiodata_buf_virt_addr)
{
pci_free_consistent(dev->pci, dev->_audiodata_buf_size, dev->_audiodata_buf_virt_addr, dev->_audiodata_buf_phys_addr);
if (dev->_audiodata_buf_virt_addr) {
pci_free_consistent(dev->pci, dev->_audiodata_buf_size,
dev->_audiodata_buf_virt_addr,
dev->_audiodata_buf_phys_addr);
dev->_audiodata_buf_virt_addr = NULL;
}
}
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;
if( !dev->_audio_is_running )
{
printk("cx25821: No audio file is currently running so return!\n");
if (!dev->_audio_is_running) {
printk
("cx25821: No audio file is currently running so return!\n");
return;
}
//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
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) );
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));
//Clear data buffer memory
if( dev->_audiodata_buf_virt_addr )
memset( dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size );
if (dev->_audiodata_buf_virt_addr)
memset(dev->_audiodata_buf_virt_addr, 0,
dev->_audiodata_buf_size);
dev->_audio_is_running = 0;
dev->_is_first_audio_frame = 0;
dev->_audioframe_count = 0;
dev->_audiofile_status = END_OF_FILE;
if( dev->_irq_audio_queues )
{
if (dev->_irq_audio_queues) {
kfree(dev->_irq_audio_queues);
dev->_irq_audio_queues = NULL;
}
if( dev->_audiofilename != NULL )
if (dev->_audiofilename != NULL)
kfree(dev->_audiofilename);
}
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_free_memory_audio(dev);
}
int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch )
int cx25821_get_audio_data(struct cx25821_dev *dev,
struct sram_channel *sram_ch)
{
struct file * myfile;
struct file *myfile;
int frame_index_temp = dev->_audioframe_index;
int i = 0;
int line_size = AUDIO_LINE_SIZE;
......@@ -284,32 +274,27 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
loff_t pos;
mm_segment_t old_fs;
if( dev->_audiofile_status == END_OF_FILE )
if (dev->_audiofile_status == END_OF_FILE)
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered!\n", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered!\n",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered! \n", __func__);
if (!myfile->f_op->read) {
printk("%s: File has no READ operations registered! \n",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -318,34 +303,35 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs();
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;
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->_audiodata_buf_virt_addr != NULL )
{
memcpy( (void*)(dev->_audiodata_buf_virt_addr+frame_offset/4), mybuf, vfs_read_retval);
if (vfs_read_retval > 0 && vfs_read_retval == line_size
&& dev->_audiodata_buf_virt_addr != NULL) {
memcpy((void *)(dev->_audiodata_buf_virt_addr +
frame_offset / 4), mybuf,
vfs_read_retval);
}
file_offset += vfs_read_retval;
frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Audio file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Audio file.\n",
__func__);
break;
}
}
if( i > 0 )
if (i > 0)
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);
filp_close(myfile, NULL);
......@@ -356,20 +342,24 @@ int cx25821_get_audio_data(struct cx25821_dev *dev, struct sram_channel *sram_ch
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 )
{
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ );
if (!dev) {
printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
__func__);
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 line_size = AUDIO_LINE_SIZE;
ssize_t vfs_read_retval = 0;
......@@ -378,29 +368,24 @@ int cx25821_openfile_audio(struct cx25821_dev *dev, struct sram_channel *sram_ch
loff_t offset = (unsigned long)0;
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered! \n", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered! \n",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered! \n", __func__);
if (!myfile->f_op->read) {
printk("%s: File has no READ operations registered! \n",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -409,42 +394,43 @@ int cx25821_openfile_audio(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs();
set_fs(KERNEL_DS);
for( j = 0; j < NUM_AUDIO_FRAMES; j++ )
{
for( i = 0; i < dev->_audio_lines_count; i++ )
{
for (j = 0; j < NUM_AUDIO_FRAMES; j++) {
for (i = 0; i < dev->_audio_lines_count; i++) {
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->_audiodata_buf_virt_addr != NULL )
{
memcpy( (void*)(dev->_audiodata_buf_virt_addr+offset/4), mybuf, vfs_read_retval);
if (vfs_read_retval > 0
&& vfs_read_retval == line_size
&& dev->_audiodata_buf_virt_addr != NULL) {
memcpy((void *)(dev->
_audiodata_buf_virt_addr
+ offset / 4), mybuf,
vfs_read_retval);
}
offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Audio file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Audio file.\n",
__func__);
break;
}
}
if( i > 0 )
{
if (i > 0) {
dev->_audioframe_count++;
}
if( vfs_read_retval < line_size )
{
if (vfs_read_retval < line_size) {
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);
myfile->f_pos = 0;
......@@ -462,151 +448,151 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
dma_addr_t dma_addr;
dma_addr_t data_dma_addr;
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_phys_start_addr = dma_addr;
dev->_risc_phys_addr = dma_addr;
dev->_audiorisc_size = dev->audio_upstream_riscbuf_size;
if (!dev->_risc_virt_addr)
{
printk("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
if (!dev->_risc_virt_addr) {
printk
("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
return -ENOMEM;
}
//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
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_size = dev->audio_upstream_databuf_size;
if (!dev->_audiodata_buf_virt_addr)
{
printk("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning. \n");
if (!dev->_audiodata_buf_virt_addr) {
printk
("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning. \n");
return -ENOMEM;
}
//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);
if( ret < 0 )
if (ret < 0)
return ret;
//Creating RISC programs
ret = cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl, dev->_audio_lines_count );
if (ret < 0)
{
printk(KERN_DEBUG "cx25821 ERROR creating audio upstream RISC programs! \n");
ret =
cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl,
dev->_audio_lines_count);
if (ret < 0) {
printk(KERN_DEBUG
"cx25821 ERROR creating audio upstream RISC programs! \n");
goto error;
}
return 0;
error:
error:
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;
u32 int_msk_tmp;
struct sram_channel *channel = &dev->sram_channels[chan_num];
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
u32 prog_cnt = cx_read( channel->gpcnt );
u32 prog_cnt = cx_read(channel->gpcnt);
//Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers
cx_write(channel->int_msk, 0);
cx_write(channel->int_stat, cx_read(channel->int_stat) );
cx_write(channel->int_stat, cx_read(channel->int_stat));
spin_lock(&dev->slock);
while(prog_cnt != dev->_last_index_irq)
{
while (prog_cnt != dev->_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++;
}
else
{
} else {
dev->_last_index_irq = 0;
}
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;
if( dev->_risc_virt_start_addr != NULL )
{
risc_phys_jump_addr = dev->_risc_phys_start_addr + RISC_SYNC_INSTRUCTION_SIZE + AUDIO_RISC_DMA_BUF_SIZE;
if (dev->_risc_virt_start_addr != NULL) {
risc_phys_jump_addr =
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 )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
*(rp++) = cpu_to_le32(RISC_NOOP);
if (USE_RISC_NOOP_AUDIO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) =
cpu_to_le32(RISC_NOOP);
}
}
// 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(0);
}
}
spin_unlock(&dev->slock);
}
else
{
if(status & FLD_AUD_SRC_OF)
printk("%s: Audio Received Overflow Error Interrupt!\n", __func__);
} else {
if (status & FLD_AUD_SRC_OF)
printk("%s: Audio Received Overflow Error Interrupt!\n",
__func__);
if(status & FLD_AUD_SRC_SYNC)
printk("%s: Audio Received Sync Error Interrupt!\n", __func__);
if (status & FLD_AUD_SRC_SYNC)
printk("%s: Audio Received Sync Error Interrupt!\n",
__func__);
if(status & FLD_AUD_SRC_OPC_ERR)
printk("%s: Audio Received OpCode Error Interrupt!\n", __func__);
if (status & FLD_AUD_SRC_OPC_ERR)
printk("%s: Audio Received OpCode Error Interrupt!\n",
__func__);
// 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 )
{
printk("cx25821: EOF Channel Audio Framecount = %d\n", dev->_audioframe_count );
if (dev->_audiofile_status == END_OF_FILE) {
printk("cx25821: EOF Channel Audio Framecount = %d\n",
dev->_audioframe_count);
return -1;
}
//ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read( channel->int_msk );
cx_write( channel->int_msk, int_msk_tmp |= _intr_msk );
int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
return 0;
}
......@@ -618,71 +604,66 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
int handled = 0;
struct sram_channel *sram_ch;
if( !dev )
if (!dev)
return -1;
sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select];
msk_stat = cx_read(sram_ch->int_mstat);
audio_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt
if(audio_status)
{
handled = cx25821_audio_upstream_irq(dev, dev->_audio_upstream_channel_select, audio_status);
if (audio_status) {
handled =
cx25821_audio_upstream_irq(dev,
dev->
_audio_upstream_channel_select,
audio_status);
}
if( handled < 0 )
{
if (handled < 0) {
cx25821_stop_upstream_audio(dev);
}
else
{
} else {
handled += handled;
}
return IRQ_RETVAL(handled);
}
static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, struct sram_channel *sram_ch)
static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
struct sram_channel *sram_ch)
{
int count = 0;
u32 tmp;
do
{
do {
//Wait 10 microsecond before checking to see if the FIFO is turned ON.
udelay(10);
tmp = cx_read( sram_ch->dma_ctl );
tmp = cx_read(sram_ch->dma_ctl);
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;
}
} while( !(tmp & sram_ch->fld_aud_fifo_en) );
} while (!(tmp & sram_ch->fld_aud_fifo_en));
}
int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
struct sram_channel *sram_ch)
{
u32 tmp = 0;
int err = 0;
// 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 + 4, 0); /* Risc IPC High 64 bits 63-32 */
/* reset counter */
cx_write(sram_ch->gpcnt_ctl, 3);
......@@ -690,35 +671,36 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
cx_write(sram_ch->aud_length, AUDIO_LINE_SIZE & FLD_AUD_DST_LN_LNGTH);
//Set the input mode to 16-bit
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;
cx_write( sram_ch->aud_cfg, tmp );
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;
cx_write(sram_ch->aud_cfg, tmp);
// Read and write back the interrupt status register to clear it
tmp = cx_read( sram_ch->int_stat);
cx_write( sram_ch->int_stat, tmp);
tmp = cx_read(sram_ch->int_stat);
cx_write(sram_ch->int_stat, tmp);
// 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.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read( sram_ch->int_msk );
cx_write( sram_ch->int_msk, tmp |= _intr_msk );
err = request_irq(dev->pci->irq, cx25821_upstream_irq_audio, 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);
tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
request_irq(dev->pci->irq, cx25821_upstream_irq_audio,
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);
goto fail_irq;
}
// Start the DMA engine
tmp = cx_read( sram_ch->dma_ctl );
cx_set( sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en );
tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en);
dev->_audio_is_running = 1;
dev->_is_first_audio_frame = 1;
......@@ -728,13 +710,11 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
return 0;
fail_irq:
fail_irq:
cx25821_dev_unregister(dev);
return err;
}
int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
{
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 str_length = 0;
if( dev->_audio_is_running )
{
if (dev->_audio_is_running) {
printk("Audio Channel is still running so return!\n");
return 0;
}
......@@ -753,15 +732,15 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
//Work queue
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)
{
printk("cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n");
if (!dev->_irq_audio_queues) {
printk
("cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n");
return -ENOMEM;
}
dev->_last_index_irq = 0;
dev->_audio_is_running = 0;
dev->_audioframe_count = 0;
......@@ -769,55 +748,56 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER;
_line_size = AUDIO_LINE_SIZE;
if( dev->input_audiofilename )
{
if (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;
memcpy(dev->_audiofilename, dev->input_audiofilename, str_length + 1);
memcpy(dev->_audiofilename, dev->input_audiofilename,
str_length + 1);
//Default if filename is empty string
if( strcmp(dev->input_audiofilename,"") == 0)
{
if (strcmp(dev->input_audiofilename, "") == 0) {
dev->_audiofilename = "/root/audioGOOD.wav";
}
}
else
{
} else {
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;
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 + RISC_SYNC_INSTRUCTION_SIZE;
dev->audio_upstream_riscbuf_size =
AUDIO_RISC_DMA_BUF_SIZE * NUM_AUDIO_PROGS +
RISC_SYNC_INSTRUCTION_SIZE;
dev->audio_upstream_databuf_size = AUDIO_DATA_BUF_SZ * NUM_AUDIO_PROGS;
//Allocating buffers and prepare RISC program
retval = 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);
retval =
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);
goto error;
}
//Start RISC engine
cx25821_start_audio_dma_upstream(dev, sram_ch);
return 0;
error:
error:
cx25821_dev_unregister(dev);
return err;
......
......@@ -23,7 +23,6 @@
#include <linux/mutex.h>
#include <linux/workqueue.h>
#define NUM_AUDIO_PROGS 8
#define NUM_AUDIO_FRAMES 8
#define END_OF_FILE 0
......@@ -33,7 +32,6 @@
#define FIFO_ENABLE 1
#define NUM_NO_OPS 4
#define RISC_READ_INSTRUCTION_SIZE 12
#define RISC_JUMP_INSTRUCTION_SIZE 12
#define RISC_WRITECR_INSTRUCTION_SIZE 16
......@@ -41,7 +39,6 @@
#define DWORD_SIZE 4
#define AUDIO_SYNC_LINE 4
#define LINES_PER_AUDIO_BUFFER 15
#define AUDIO_LINE_SIZE 128
#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)
#endif
#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)
#endif
static int _line_size;
char * _defaultAudioName = "/root/audioGOOD.wav";
char *_defaultAudioName = "/root/audioGOOD.wav";
......@@ -23,7 +23,6 @@
#ifndef __CX25821_AUDIO_H__
#define __CX25821_AUDIO_H__
#define USE_RISC_NOOP 1
#define LINES_PER_BUFFER 15
#define AUDIO_LINE_SIZE 128
......@@ -45,7 +44,6 @@
(2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4)
#endif
//Sizes of various instructions in bytes. Used when adding instructions.
#define RISC_WRITE_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)
#endif
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -97,12 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -127,7 +130,7 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
......@@ -135,14 +138,13 @@ static int video_open(struct file *file)
dev->channel_opened = 10;
fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -150,17 +152,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO11))
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:
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_buffer *buf;
......@@ -188,11 +192,10 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -214,7 +217,7 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
......@@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -265,15 +264,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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->height = f->fmt.pix.height;
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);
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_dev *dev = fh->dev;
int command = 0;
struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user )
{
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__);
if (!data_from_user) {
printk
("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0;
}
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;
}
dev->input_filename = data_from_user->input_filename;
dev->input_audiofilename = data_from_user->input_filename;
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->command = data_from_user->command;
switch(command)
{
switch (command) {
case UPSTREAM_START_AUDIO:
cx25821_start_upstream_audio(dev, data_from_user);
break;
......@@ -345,7 +341,7 @@ 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);
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -366,14 +362,14 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = fh->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
}
return 0;
}
// exported stuff
static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE,
......@@ -436,6 +432,3 @@ struct video_device cx25821_video_template11 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -50,7 +50,7 @@ struct cx25821_board cx25821_boards[] = {
const unsigned int cx25821_bcount = ARRAY_SIZE(cx25821_boards);
struct cx25821_subid cx25821_subids[]={
struct cx25821_subid cx25821_subids[] = {
{
.subvendor = 0x14f1,
.subdevice = 0x0920,
......@@ -58,15 +58,13 @@ struct cx25821_subid cx25821_subids[]={
},
};
void cx25821_card_setup(struct cx25821_dev *dev)
{
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;
tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
sizeof(eeprom));
}
}
......@@ -36,17 +36,15 @@ static unsigned int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "enable debug messages");
static unsigned int card[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
static unsigned int card[] = {[0...(CX25821_MAXBOARDS - 1)] = UNSET };
module_param_array(card, int, NULL, 0444);
MODULE_PARM_DESC(card, "card type");
static unsigned int cx25821_devcount = 0;
static DEFINE_MUTEX(devlist);
LIST_HEAD(cx25821_devlist);
struct sram_channel cx25821_sram_channels[] = {
[SRAM_CH00] = {
.i = SRAM_CH00,
......@@ -55,7 +53,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_A_IQ,
.cdt = VID_A_CDT,
.fifo_start = VID_A_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA1_PTR1,
.ptr2_reg = DMA1_PTR2,
.cnt1_reg = DMA1_CNT1,
......@@ -77,7 +75,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_B_IQ,
.cdt = VID_B_CDT,
.fifo_start = VID_B_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA2_PTR1,
.ptr2_reg = DMA2_PTR2,
.cnt1_reg = DMA2_CNT1,
......@@ -99,7 +97,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_C_IQ,
.cdt = VID_C_CDT,
.fifo_start = VID_C_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA3_PTR1,
.ptr2_reg = DMA3_PTR2,
.cnt1_reg = DMA3_CNT1,
......@@ -121,7 +119,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_D_IQ,
.cdt = VID_D_CDT,
.fifo_start = VID_D_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA4_PTR1,
.ptr2_reg = DMA4_PTR2,
.cnt1_reg = DMA4_CNT1,
......@@ -143,7 +141,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_E_IQ,
.cdt = VID_E_CDT,
.fifo_start = VID_E_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA5_PTR1,
.ptr2_reg = DMA5_PTR2,
.cnt1_reg = DMA5_CNT1,
......@@ -165,7 +163,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_F_IQ,
.cdt = VID_F_CDT,
.fifo_start = VID_F_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA6_PTR1,
.ptr2_reg = DMA6_PTR2,
.cnt1_reg = DMA6_CNT1,
......@@ -187,7 +185,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_G_IQ,
.cdt = VID_G_CDT,
.fifo_start = VID_G_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA7_PTR1,
.ptr2_reg = DMA7_PTR2,
.cnt1_reg = DMA7_CNT1,
......@@ -209,7 +207,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_H_IQ,
.cdt = VID_H_CDT,
.fifo_start = VID_H_DOWN_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA8_PTR1,
.ptr2_reg = DMA8_PTR2,
.cnt1_reg = DMA8_CNT1,
......@@ -244,7 +242,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_I_IQ,
.cdt = VID_I_CDT,
.fifo_start = VID_I_UP_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA15_PTR1,
.ptr2_reg = DMA15_PTR2,
.cnt1_reg = DMA15_CNT1,
......@@ -257,8 +255,8 @@ struct sram_channel cx25821_sram_channels[] = {
.gpcnt = VID_SRC_I_GPCNT,
.vid_fmt_ctl = VID_SRC_I_FMT_CTL,
.vid_active_ctl1= VID_SRC_I_ACTIVE_CTL1,
.vid_active_ctl2= VID_SRC_I_ACTIVE_CTL2,
.vid_active_ctl1 = VID_SRC_I_ACTIVE_CTL1,
.vid_active_ctl2 = VID_SRC_I_ACTIVE_CTL2,
.vid_cdt_size = VID_SRC_I_CDT_SZ,
.irq_bit = 8,
},
......@@ -270,7 +268,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = VID_J_IQ,
.cdt = VID_J_CDT,
.fifo_start = VID_J_UP_CLUSTER_1,
.fifo_size = (VID_CLUSTER_SIZE<<2),
.fifo_size = (VID_CLUSTER_SIZE << 2),
.ptr1_reg = DMA16_PTR1,
.ptr2_reg = DMA16_PTR2,
.cnt1_reg = DMA16_CNT1,
......@@ -283,13 +281,12 @@ struct sram_channel cx25821_sram_channels[] = {
.gpcnt = VID_SRC_J_GPCNT,
.vid_fmt_ctl = VID_SRC_J_FMT_CTL,
.vid_active_ctl1= VID_SRC_J_ACTIVE_CTL1,
.vid_active_ctl2= VID_SRC_J_ACTIVE_CTL2,
.vid_active_ctl1 = VID_SRC_J_ACTIVE_CTL1,
.vid_active_ctl2 = VID_SRC_J_ACTIVE_CTL2,
.vid_cdt_size = VID_SRC_J_CDT_SZ,
.irq_bit = 9,
},
[SRAM_CH11] = {
.i = SRAM_CH11,
.name = "Audio Upstream Channel B",
......@@ -297,7 +294,7 @@ struct sram_channel cx25821_sram_channels[] = {
.ctrl_start = AUD_B_IQ,
.cdt = AUD_B_CDT,
.fifo_start = AUD_B_UP_CLUSTER_1,
.fifo_size = (AUDIO_CLUSTER_SIZE*3),
.fifo_size = (AUDIO_CLUSTER_SIZE * 3),
.ptr1_reg = DMA22_PTR1,
.ptr2_reg = DMA22_PTR2,
.cnt1_reg = DMA22_CNT1,
......@@ -316,7 +313,6 @@ struct sram_channel cx25821_sram_channels[] = {
},
};
struct sram_channel *channel0 = &cx25821_sram_channels[SRAM_CH00];
struct sram_channel *channel1 = &cx25821_sram_channels[SRAM_CH01];
struct sram_channel *channel2 = &cx25821_sram_channels[SRAM_CH02];
......@@ -362,9 +358,9 @@ static int cx25821_risc_decode(u32 risc)
};
int i;
printk("0x%08x [ %s", risc, instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--)
{
printk("0x%08x [ %s", risc,
instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--) {
if (risc & (1 << (i + 12)))
printk(" %s", bits[i]);
}
......@@ -379,8 +375,7 @@ static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
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;
u32 value = 0;
......@@ -393,78 +388,74 @@ static void cx25821_registers_init(struct cx25821_dev *dev)
u32 tmp;
// enable RUN_RISC in Pecos
cx_write( DEV_CNTRL2, 0x20 );
cx_write(DEV_CNTRL2, 0x20);
// Set the master PCI interrupt masks to enable video, audio, MBIF, and GPIO interrupts
// I2C interrupt masking is handled by the I2C objects themselves.
cx_write( PCI_INT_MSK, 0x2001FFFF );
cx_write(PCI_INT_MSK, 0x2001FFFF);
tmp = cx_read( RDR_TLCTL0 );
tmp = cx_read(RDR_TLCTL0);
tmp &= ~FLD_CFG_RCB_CK_EN; // Clear the RCB_CK_EN bit
cx_write( RDR_TLCTL0, tmp);
cx_write(RDR_TLCTL0, tmp);
// PLL-A setting for the Audio Master Clock
cx_write( PLL_A_INT_FRAC, 0x9807A58B );
cx_write(PLL_A_INT_FRAC, 0x9807A58B);
// PLL_A_POST = 0x1C, PLL_A_OUT_TO_PIN = 0x1
cx_write( PLL_A_POST_STAT_BIST, 0x8000019C);
cx_write(PLL_A_POST_STAT_BIST, 0x8000019C);
// clear reset bit [31]
tmp = cx_read( PLL_A_INT_FRAC );
cx_write( PLL_A_INT_FRAC, tmp & 0x7FFFFFFF);
tmp = cx_read(PLL_A_INT_FRAC);
cx_write(PLL_A_INT_FRAC, tmp & 0x7FFFFFFF);
// PLL-B setting for Mobilygen Host Bus Interface
cx_write( PLL_B_INT_FRAC, 0x9883A86F);
cx_write(PLL_B_INT_FRAC, 0x9883A86F);
// PLL_B_POST = 0xD, PLL_B_OUT_TO_PIN = 0x0
cx_write( PLL_B_POST_STAT_BIST, 0x8000018D);
cx_write(PLL_B_POST_STAT_BIST, 0x8000018D);
// clear reset bit [31]
tmp = cx_read( PLL_B_INT_FRAC );
cx_write( PLL_B_INT_FRAC, tmp & 0x7FFFFFFF);
tmp = cx_read(PLL_B_INT_FRAC);
cx_write(PLL_B_INT_FRAC, tmp & 0x7FFFFFFF);
// PLL-C setting for video upstream channel
cx_write( PLL_C_INT_FRAC, 0x96A0EA3F);
cx_write(PLL_C_INT_FRAC, 0x96A0EA3F);
// PLL_C_POST = 0x3, PLL_C_OUT_TO_PIN = 0x0
cx_write( PLL_C_POST_STAT_BIST, 0x80000103);
cx_write(PLL_C_POST_STAT_BIST, 0x80000103);
// clear reset bit [31]
tmp = cx_read( PLL_C_INT_FRAC );
cx_write( PLL_C_INT_FRAC, tmp & 0x7FFFFFFF);
tmp = cx_read(PLL_C_INT_FRAC);
cx_write(PLL_C_INT_FRAC, tmp & 0x7FFFFFFF);
// PLL-D setting for audio upstream channel
cx_write( PLL_D_INT_FRAC, 0x98757F5B);
cx_write(PLL_D_INT_FRAC, 0x98757F5B);
// PLL_D_POST = 0x13, PLL_D_OUT_TO_PIN = 0x0
cx_write( PLL_D_POST_STAT_BIST, 0x80000113);
cx_write(PLL_D_POST_STAT_BIST, 0x80000113);
// clear reset bit [31]
tmp = cx_read( PLL_D_INT_FRAC );
cx_write( PLL_D_INT_FRAC, tmp & 0x7FFFFFFF);
tmp = cx_read(PLL_D_INT_FRAC);
cx_write(PLL_D_INT_FRAC, tmp & 0x7FFFFFFF);
// This selects the PLL C clock source for the video upstream channel I and J
tmp = cx_read( VID_CH_CLK_SEL );
cx_write( VID_CH_CLK_SEL, (tmp & 0x00FFFFFF) | 0x24000000);
tmp = cx_read(VID_CH_CLK_SEL);
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
//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 & 0xFFFFFE00);
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
// 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
cx_write( CLK_RST, tmp & ~(FLD_VID_I_CLK_NOE | FLD_VID_J_CLK_NOE) );
cx_write(CLK_RST, tmp & ~(FLD_VID_I_CLK_NOE | FLD_VID_J_CLK_NOE));
mdelay(100);
}
int cx25821_sram_channel_setup(struct cx25821_dev *dev,
struct sram_channel *ch,
unsigned int bpl, u32 risc)
......@@ -484,8 +475,7 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
cdt = ch->cdt;
lines = ch->fifo_size / bpl;
if (lines > 4)
{
if (lines > 4) {
lines = 4;
}
......@@ -497,29 +487,26 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
/* write CDT */
for (i = 0; i < lines; i++) {
cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
cx_write(cdt + 16*i + 4, 0);
cx_write(cdt + 16*i + 8, 0);
cx_write(cdt + 16*i + 12, 0);
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
cx_write(cdt + 16 * i + 4, 0);
cx_write(cdt + 16 * i + 8, 0);
cx_write(cdt + 16 * i + 12, 0);
}
//init the first cdt buffer
for(i=0; i<128; i++)
cx_write(ch->fifo_start+4*i, i);
for (i = 0; i < 128; i++)
cx_write(ch->fifo_start + 4 * i, i);
/* write CMDS */
if (ch->jumponly)
{
if (ch->jumponly) {
cx_write(ch->cmds_start + 0, 8);
}
else
{
} else {
cx_write(ch->cmds_start + 0, risc);
}
cx_write(ch->cmds_start + 4, 0); /* 64 bits 63-32 */
cx_write(ch->cmds_start + 8, cdt);
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);
if (ch->jumponly)
......@@ -533,7 +520,7 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
/* fill registers */
cx_write(ch->ptr1_reg, ch->fifo_start);
cx_write(ch->ptr2_reg, cdt);
cx_write(ch->cnt2_reg, (lines*16) >> 3);
cx_write(ch->cnt2_reg, (lines * 16) >> 3);
cx_write(ch->cnt1_reg, (bpl >> 3) - 1);
return 0;
......@@ -546,7 +533,6 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
unsigned int i, lines;
u32 cdt;
if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0);
......@@ -559,48 +545,40 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
cdt = ch->cdt;
lines = ch->fifo_size / bpl;
if (lines > 3)
{
if (lines > 3) {
lines = 3; //for AUDIO
}
BUG_ON(lines < 2);
cx_write(8 + 0, RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
cx_write(8 + 4, 8);
cx_write(8 + 8, 0);
/* write CDT */
for (i = 0; i < lines; i++) {
cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
cx_write(cdt + 16*i + 4, 0);
cx_write(cdt + 16*i + 8, 0);
cx_write(cdt + 16*i + 12, 0);
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
cx_write(cdt + 16 * i + 4, 0);
cx_write(cdt + 16 * i + 8, 0);
cx_write(cdt + 16 * i + 12, 0);
}
/* write CMDS */
if (ch->jumponly)
{
if (ch->jumponly) {
cx_write(ch->cmds_start + 0, 8);
}
else
{
} else {
cx_write(ch->cmds_start + 0, risc);
}
cx_write(ch->cmds_start + 4, 0); /* 64 bits 63-32 */
cx_write(ch->cmds_start + 8, cdt);
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);
//IQ size
if (ch->jumponly)
{
if (ch->jumponly) {
cx_write(ch->cmds_start + 20, 0x80000000 | (64 >> 2));
}
else
{
} else {
cx_write(ch->cmds_start + 20, 64 >> 2);
}
......@@ -611,13 +589,12 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
/* fill registers */
cx_write(ch->ptr1_reg, ch->fifo_start);
cx_write(ch->ptr2_reg, cdt);
cx_write(ch->cnt2_reg, (lines*16) >> 3);
cx_write(ch->cnt2_reg, (lines * 16) >> 3);
cx_write(ch->cnt1_reg, (bpl >> 3) - 1);
return 0;
}
void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
{
static char *name[] = {
......@@ -639,39 +616,50 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
u32 risc;
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++)
printk(KERN_WARNING "cmds + 0x%2x: %-15s: 0x%08x\n", i*4, name[i],
cx_read(ch->cmds_start + 4*i));
printk(KERN_WARNING "cmds + 0x%2x: %-15s: 0x%08x\n", i * 4,
name[i], cx_read(ch->cmds_start + 4 * i));
j=i*4;
for (i = 0; i < 4; ) {
j = i * 4;
for (i = 0; i < 4;) {
risc = cx_read(ch->cmds_start + 4 * (i + 14));
printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j+i*4, i);
i +=cx25821_risc_decode(risc);
printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j + i * 4, i);
i += cx25821_risc_decode(risc);
}
for (i = 0; i < (64 >> 2); i += n) {
risc = cx_read(ch->ctrl_start + 4 * i);
/* 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);
for (j = 1; j < n; 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 " : ctrl: 0x%08x -> 0x%x\n", ch->ctrl_start, ch->ctrl_start + 6*16);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", 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));
printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n",
ch->fifo_start, ch->fifo_start + ch->fifo_size);
printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n",
ch->ctrl_start, ch->ctrl_start + 6 * 16);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n",
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[] = {
"init risc lo",
......@@ -693,17 +681,18 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channe
u32 risc, value, tmp;
unsigned int i, j, n;
printk(KERN_INFO "\n%s: %s - dma Audio channel status dump\n", dev->name, ch->name);
printk(KERN_INFO "\n%s: %s - dma Audio channel status dump\n",
dev->name, ch->name);
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;
for (i = 0; i < 4; ) {
j = i * 4;
for (i = 0; i < 4;) {
risc = cx_read(ch->cmds_start + 4 * (i + 14));
printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j+i*4, i);
printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j + i * 4, i);
i += cx25821_risc_decode(risc);
}
......@@ -711,39 +700,45 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, struct sram_channe
risc = cx_read(ch->ctrl_start + 4 * i);
/* 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);
for (j = 1; j < n; 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 " : ctrl: 0x%08x -> 0x%x\n", ch->ctrl_start, ch->ctrl_start + 6*16);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", 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++)
{
risc = cx_read(ch->cmds_start + 56 + (i*4));
printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n",
ch->fifo_start, ch->fifo_start + ch->fifo_size);
printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n",
ch->ctrl_start, ch->ctrl_start + 6 * 16);
printk(KERN_WARNING " : ptr1_reg: 0x%08x\n",
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++) {
risc = cx_read(ch->cmds_start + 56 + (i * 4));
printk(KERN_WARNING "instruction %d = 0x%x\n", i, risc);
}
//read data from the first cdt buffer
risc = cx_read(AUD_A_CDT);
printk(KERN_WARNING "\nread cdt loc=0x%x\n", risc);
for(i=0; i<8; i++)
{
n = cx_read(risc+i*4);
for (i = 0; i < 8; i++) {
n = cx_read(risc + i * 4);
printk(KERN_WARNING "0x%x ", n);
}
printk(KERN_WARNING "\n\n");
value = cx_read(CLK_RST);
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);
/* 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].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].int_msk, 0);
}
......@@ -802,19 +796,20 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
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;
if( channel_select <= 7 && channel_select >= 0 )
{
if (channel_select <= 7 && channel_select >= 0) {
ch = &cx25821_sram_channels[channel_select];
cx_write(ch->pix_frmt, 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->vip_ctl, PIXEL_ENGINE_VIP1);
......@@ -829,10 +824,9 @@ static void cx25821_initialize(struct cx25821_dev *dev)
cx25821_shutdown(dev);
cx_write(PCI_INT_STAT, 0xffffffff);
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(AUD_A_INT_STAT, 0xffffffff);
cx_write(AUD_B_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
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_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->use_cif_resolution[i] = FALSE;
}
//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_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);
}
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;
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;
}
static void cx25821_dev_checkrevision(struct cx25821_dev *dev)
{
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)
......@@ -889,15 +885,13 @@ static void cx25821_iounmap(struct cx25821_dev *dev)
return;
/* Releasing IO memory */
if (dev->lmmio != NULL)
{
if (dev->lmmio != NULL) {
CX25821_INFO("Releasing lmmio.\n");
iounmap(dev->lmmio);
dev->lmmio = NULL;
}
}
static int cx25821_dev_setup(struct cx25821_dev *dev)
{
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[CX25821_BOARD].name, "cx25821");
if( dev->pci->device != 0x8210 )
{
printk(KERN_INFO "%s() Exiting. Incorrect Hardware device = 0x%02x\n",
if (dev->pci->device != 0x8210) {
printk(KERN_INFO
"%s() Exiting. Incorrect Hardware device = 0x%02x\n",
__func__, dev->pci->device);
return -1;
}
else
{
printk(KERN_INFO "Athena Hardware device = 0x%02x\n", dev->pci->device);
} else {
printk(KERN_INFO "Athena Hardware device = 0x%02x\n",
dev->pci->device);
}
/* Apply a sensible clock frequency for the PCIe bridge */
dev->clk_freq = 28000000;
dev->sram_channels = cx25821_sram_channels;
if(dev->nr > 1)
{
if (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->_max_num_decoders = MAX_DECODERS;
dev->pci_bus = dev->pci->bus->number;
dev->pci_slot = PCI_SLOT(dev->pci->devfn);
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 */
if (get_resources(dev) < 0)
{
if (get_resources(dev) < 0) {
printk(KERN_ERR "%s No more PCIe resources for "
"subsystem: %04x:%04x\n",
dev->name, dev->pci->subsystem_vendor,
......@@ -1000,13 +988,13 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
dev->lmmio = ioremap(dev->base_io_addr, pci_resource_len(dev->pci, 0));
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);
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",
dev->name, dev->pci->subsystem_vendor,
......@@ -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[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);
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) {
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; i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++)
{
for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
//Since we don't have template8 for Audio Downstream
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);
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);
}
}
// 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);
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);
......@@ -1057,30 +1052,32 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
return 0;
}
void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev, struct upstream_user_struct *up_data)
void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
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;
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, struct upstream_user_struct *up_data)
void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
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;
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, struct upstream_user_struct *up_data)
void cx25821_start_upstream_audio(struct cx25821_dev *dev,
struct upstream_user_struct *up_data)
{
cx25821_audio_upstream_init(dev, AUDIO_UPSTREAM_SRAM_CHANNEL_B);
}
......@@ -1101,24 +1098,21 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
if (!atomic_dec_and_test(&dev->refcount))
return;
for(i=0; i < VID_CHANNEL_NUM; i++)
for (i = 0; i < VID_CHANNEL_NUM; i++)
cx25821_video_unregister(dev, i);
for(i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++)
{
for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
cx25821_video_unregister(dev, i);
}
cx25821_videoioctl_unregister(dev);
cx25821_i2c_unregister( &dev->i2c_bus[0] );
cx25821_i2c_unregister(&dev->i2c_bus[0]);
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 bpl, unsigned int padding,
unsigned int lines)
......@@ -1127,8 +1121,7 @@ static __le32 *cx25821_risc_field(__le32 *rp, struct scatterlist *sglist,
unsigned int line, todo;
/* sync instruction */
if (sync_line != NO_SYNC_LINE)
{
if (sync_line != NO_SYNC_LINE) {
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
}
......@@ -1139,29 +1132,33 @@ static __le32 *cx25821_risc_field(__le32 *rp, struct scatterlist *sglist,
offset -= sg_dma_len(sg);
sg++;
}
if (bpl <= sg_dma_len(sg)-offset) {
if (bpl <= sg_dma_len(sg) - offset) {
/* fits into current chunk */
*(rp++) = cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);
*(rp++) = cpu_to_le32(sg_dma_address(sg)+offset);
*(rp++) =
cpu_to_le32(RISC_WRITE | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += bpl;
} else {
/* scanline needs to be split */
todo = bpl;
*(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(RISC_WRITE | RISC_SOL |
(sg_dma_len(sg) - offset));
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= (sg_dma_len(sg)-offset);
todo -= (sg_dma_len(sg) - offset);
offset = 0;
sg++;
while (todo > sg_dma_len(sg)) {
*(rp++) = cpu_to_le32(RISC_WRITE|sg_dma_len(sg));
*(rp++) =
cpu_to_le32(RISC_WRITE | sg_dma_len(sg));
*(rp++) = cpu_to_le32(sg_dma_address(sg));
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= sg_dma_len(sg);
sg++;
}
*(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
*(rp++) = cpu_to_le32(RISC_WRITE | RISC_EOL | todo);
*(rp++) = cpu_to_le32(sg_dma_address(sg));
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += todo;
......@@ -1194,9 +1191,10 @@ 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
region may be smaller than PAGE_SIZE */
/* 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;
rc = btcx_riscmem_alloc(pci, risc, instructions*12);
rc = btcx_riscmem_alloc(pci, risc, instructions * 12);
if (rc < 0)
return rc;
......@@ -1204,14 +1202,14 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
/* write risc instructions */
rp = risc->cpu;
if (UNSET != top_offset)
{
rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding, lines);
if (UNSET != top_offset) {
rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding,
lines);
}
if (UNSET != bottom_offset)
{
rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl, padding, lines);
if (UNSET != bottom_offset) {
rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl,
padding, lines);
}
/* save pointer to jmp instruction address */
......@@ -1221,8 +1219,7 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
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 bpl, unsigned int padding,
unsigned int lines, unsigned int lpi)
......@@ -1247,33 +1244,34 @@ static __le32* cx25821_risc_field_audio(__le32 *rp, struct scatterlist *sglist,
else
sol = RISC_SOL;
if (bpl <= sg_dma_len(sg)-offset) {
if (bpl <= sg_dma_len(sg) - offset) {
/* fits into current chunk */
*(rp++) = cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl);
*(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
*(rp++)=cpu_to_le32(0); /* bits 63-32 */
offset+=bpl;
*(rp++) =
cpu_to_le32(RISC_WRITE | sol | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += bpl;
} else {
/* scanline needs to be split */
todo = bpl;
*(rp++) = cpu_to_le32(RISC_WRITE|sol|
(sg_dma_len(sg)-offset));
*(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
*(rp++)=cpu_to_le32(0); /* bits 63-32 */
todo -= (sg_dma_len(sg)-offset);
*(rp++) = cpu_to_le32(RISC_WRITE | sol |
(sg_dma_len(sg) - offset));
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= (sg_dma_len(sg) - offset);
offset = 0;
sg++;
while (todo > sg_dma_len(sg)) {
*(rp++)=cpu_to_le32(RISC_WRITE|
*(rp++) = cpu_to_le32(RISC_WRITE |
sg_dma_len(sg));
*(rp++)=cpu_to_le32(sg_dma_address(sg));
*(rp++)=cpu_to_le32(0); /* bits 63-32 */
*(rp++) = cpu_to_le32(sg_dma_address(sg));
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
todo -= sg_dma_len(sg);
sg++;
}
*(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
*(rp++)=cpu_to_le32(sg_dma_address(sg));
*(rp++)=cpu_to_le32(0); /* bits 63-32 */
*(rp++) = cpu_to_le32(RISC_WRITE | RISC_EOL | todo);
*(rp++) = cpu_to_le32(sg_dma_address(sg));
*(rp++) = cpu_to_le32(0); /* bits 63-32 */
offset += todo;
}
offset += padding;
......@@ -1286,8 +1284,7 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
struct btcx_riscmem *risc,
struct scatterlist *sglist,
unsigned int bpl,
unsigned int lines,
unsigned int lpi)
unsigned int lines, unsigned int lpi)
{
u32 instructions;
__le32 *rp;
......@@ -1301,27 +1298,27 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
instructions = 1 + (bpl * lines) / PAGE_SIZE + lines;
instructions += 1;
if ((rc = btcx_riscmem_alloc(pci,risc,instructions*12)) < 0)
if ((rc = btcx_riscmem_alloc(pci, risc, instructions * 12)) < 0)
return rc;
/* write risc instructions */
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 */
risc->jmp = rp;
BUG_ON((risc->jmp - risc->cpu + 2) * sizeof (*risc->cpu) > risc->size);
BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
return 0;
}
int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,u32 reg, u32 mask, u32 value)
int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
u32 reg, u32 mask, u32 value)
{
__le32 *rp;
int rc;
rc = btcx_riscmem_alloc(pci, risc, 4*16);
rc = btcx_riscmem_alloc(pci, risc, 4 * 16);
if (rc < 0)
return rc;
......@@ -1351,36 +1348,33 @@ void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf)
buf->vb.state = VIDEOBUF_NEEDS_INIT;
}
static irqreturn_t cx25821_irq(int irq, void *dev_id)
{
struct cx25821_dev *dev = dev_id;
u32 pci_status, pci_mask;
u32 vid_status;
int i, handled = 0;
u32 mask[8] = {1, 2, 4, 8, 16, 32, 64, 128};
u32 mask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
pci_status = cx_read(PCI_INT_STAT);
pci_mask = cx_read(PCI_INT_MSK);
if (pci_status == 0)
goto out;
for(i = 0; i < VID_CHANNEL_NUM; i++)
{
if(pci_status & mask[i])
{
for (i = 0; i < VID_CHANNEL_NUM; i++) {
if (pci_status & mask[i]) {
vid_status = cx_read(dev->sram_channels[i].int_stat);
if(vid_status)
handled += cx25821_video_irq(dev, i, vid_status);
if (vid_status)
handled +=
cx25821_video_irq(dev, i, vid_status);
cx_write(PCI_INT_STAT, mask[i]);
}
}
out:
out:
return IRQ_RETVAL(handled);
}
......@@ -1405,13 +1399,14 @@ void cx25821_print_irqbits(char *name, char *tag, char **strings,
printk("\n");
}
struct cx25821_dev* cx25821_dev_get(struct pci_dev *pci)
struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci)
{
struct cx25821_dev *dev = pci_get_drvdata(pci);
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;
int err = 0;
......@@ -1420,15 +1415,13 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev, const struct pci_d
if (NULL == dev)
return -ENOMEM;
err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev);
if (err < 0)
goto fail_free;
/* pci init */
dev->pci = pci_dev;
if (pci_enable_device(pci_dev))
{
if (pci_enable_device(pci_dev)) {
err = -EIO;
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");
if (cx25821_dev_setup(dev) < 0)
{
if (cx25821_dev_setup(dev) < 0) {
err = -EINVAL;
goto fail_unregister_device;
}
......@@ -1450,36 +1442,35 @@ 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, "
"latency: %d, mmio: 0x%llx\n", dev->name,
pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
dev->pci_lat,
(unsigned long long)dev->base_io_addr );
dev->pci_lat, (unsigned long long)dev->base_io_addr);
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);
err = -EIO;
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)
{
printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name, pci_dev->irq);
if (err < 0) {
printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
pci_dev->irq);
goto fail_irq;
}
return 0;
fail_irq:
fail_irq:
printk(KERN_INFO "cx25821 cx25821_initdev() can't get IRQ ! \n");
cx25821_dev_unregister(dev);
fail_unregister_device:
fail_unregister_device:
v4l2_device_unregister(&dev->v4l2_dev);
fail_free:
fail_free:
kfree(dev);
return err;
}
......@@ -1493,10 +1484,9 @@ static void __devexit cx25821_finidev(struct pci_dev *pci_dev)
pci_disable_device(pci_dev);
/* unregister stuff */
if( pci_dev->irq )
if (pci_dev->irq)
free_irq(pci_dev->irq, dev);
mutex_lock(&devlist);
list_del(&dev->devlist);
mutex_unlock(&devlist);
......@@ -1508,7 +1498,7 @@ static void __devexit cx25821_finidev(struct pci_dev *pci_dev)
static struct pci_device_id cx25821_pci_tbl[] = {
{
/* CX25821 Athena*/
/* CX25821 Athena */
.vendor = 0x14f1,
.device = 0x8210,
.subvendor = 0x14f1,
......@@ -1521,8 +1511,7 @@ static struct pci_device_id 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",
.id_table = cx25821_pci_tbl,
.probe = cx25821_initdev,
......@@ -1537,8 +1526,7 @@ static int cx25821_init(void)
INIT_LIST_HEAD(&cx25821_devlist);
printk(KERN_INFO "cx25821 driver version %d.%d.%d loaded\n",
(CX25821_VERSION_CODE >> 16) & 0xff,
(CX25821_VERSION_CODE >> 8) & 0xff,
CX25821_VERSION_CODE & 0xff);
(CX25821_VERSION_CODE >> 8) & 0xff, CX25821_VERSION_CODE & 0xff);
return pci_register_driver(&cx25821_pci_driver);
}
......@@ -1547,7 +1535,6 @@ static void cx25821_fini(void)
pci_unregister_driver(&cx25821_pci_driver);
}
EXPORT_SYMBOL(cx25821_devlist);
EXPORT_SYMBOL(cx25821_sram_channels);
EXPORT_SYMBOL(cx25821_print_irqbits);
......@@ -1562,4 +1549,3 @@ EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
module_init(cx25821_init);
module_exit(cx25821_fini);
......@@ -22,11 +22,9 @@
#include "cx25821.h"
/********************* GPIO stuffs *********************/
void cx25821_set_gpiopin_direction( struct cx25821_dev *dev,
int pin_number,
int pin_logic_value)
void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
int pin_number, int pin_logic_value)
{
int bit = pin_number;
u32 gpio_oe_reg = GPIO_LO_OE;
......@@ -34,77 +32,61 @@ void cx25821_set_gpiopin_direction( struct cx25821_dev *dev,
u32 value = 0;
// Check for valid pinNumber
if ( pin_number >= 47 )
if (pin_number >= 47)
return;
if ( pin_number > 31 )
{
if (pin_number > 31) {
bit = pin_number - 31;
gpio_oe_reg = GPIO_HI_OE;
}
// 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)
{
value = gpio_register | Set_GPIO_Bit(bit) ;
}
else
{
value = gpio_register & Clear_GPIO_Bit(bit) ;
if (pin_logic_value == 1) {
value = gpio_register | Set_GPIO_Bit(bit);
} else {
value = gpio_register & Clear_GPIO_Bit(bit);
}
cx_write( gpio_oe_reg, value );
cx_write(gpio_oe_reg, value);
}
static void cx25821_set_gpiopin_logicvalue( struct cx25821_dev *dev,
int pin_number,
int pin_logic_value)
static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
int pin_number, int pin_logic_value)
{
int bit = pin_number;
u32 gpio_reg = GPIO_LO;
u32 value = 0;
// Check for valid pinNumber
if (pin_number >= 47)
return;
cx25821_set_gpiopin_direction(dev, pin_number, 0); // change to output direction
if ( pin_number > 31 )
{
if (pin_number > 31) {
bit = pin_number - 31;
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);
}
else
{
} else {
value |= Set_GPIO_Bit(bit);
}
cx_write( gpio_reg, value);
cx_write(gpio_reg, value);
}
void cx25821_gpio_init(struct cx25821_dev *dev)
{
if( dev == NULL )
{
if (dev == NULL) {
return;
}
switch (dev->board)
{
switch (dev->board) {
case CX25821_BOARD_CONEXANT_ATHENA10:
default:
//set GPIO 5 to select the path for Medusa/Athena
......
void cx25821_gpio_init(struct athena_dev *dev);
......@@ -24,12 +24,11 @@
#include "cx25821.h"
#include <linux/i2c.h>
static unsigned int i2c_debug;
module_param(i2c_debug, int, 0644);
MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
static unsigned int i2c_scan=0;
static unsigned int i2c_scan = 0;
module_param(i2c_scan, int, 0444);
MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
......@@ -44,7 +43,6 @@ MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
#define I2C_EXTEND (1 << 3)
#define I2C_NOSTOP (1 << 4)
static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
{
struct cx25821_i2c *bus = i2c_adap->algo_data;
......@@ -75,7 +73,8 @@ static int i2c_wait_done(struct i2c_adapter *i2c_adap)
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_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;
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
dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
/* 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_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)
goto eio;
if (i2c_debug)
{
if (i2c_debug) {
if (!(ctrl & I2C_NOSTOP))
printk(" >\n");
}
......@@ -152,8 +150,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
if (retval == 0)
goto eio;
if (i2c_debug)
{
if (i2c_debug) {
dprintk(1, " %02x", msg->buf[cnt]);
if (!(ctrl & I2C_NOSTOP))
dprintk(1, " >\n");
......@@ -170,14 +167,14 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, const struct i2c_msg *msg
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_dev *dev = bus->dev;
u32 ctrl, cnt;
int retval;
if (i2c_debug && !joined)
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))
return -EIO;
dprintk(1, "%s() returns 0\n", __func__);
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)
ctrl |= I2C_NOSTOP | I2C_EXTEND;
cx_write(bus->reg_addr, msg->addr << 25);
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);
for (i = 0 ; i < num; i++)
{
for (i = 0; i < num; i++) {
dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
__func__, num, msgs[i].addr, msgs[i].len);
if (msgs[i].flags & I2C_M_RD)
{
if (msgs[i].flags & I2C_M_RD) {
/* read */
retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
}
else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
msgs[i].addr == msgs[i + 1].addr)
{
} else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
msgs[i].addr == msgs[i + 1].addr) {
/* 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)
goto err;
i++;
retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
}
else
{
} else {
/* write */
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 |
I2C_FUNC_I2C |
I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_READ_WORD_DATA |
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
}
static struct i2c_algorithm cx25821_i2c_algo_template = {
......@@ -295,7 +284,6 @@ static struct i2c_algorithm cx25821_i2c_algo_template = {
.functionality = cx25821_functionality,
};
static struct i2c_adapter cx25821_i2c_adap_template = {
.name = "cx25821",
.owner = THIS_MODULE,
......@@ -333,7 +321,7 @@ int cx25821_i2c_register(struct cx25821_i2c *bus)
bus->i2c_client.adapter = &bus->i2c_adap;
//set up the I2c
bus->i2c_client.addr = (0x88>>1);
bus->i2c_client.addr = (0x88 >> 1);
return bus->i2c_rc;
}
......@@ -367,16 +355,15 @@ void cx25821_av_clk(struct cx25821_dev *dev, int enable)
i2c_xfer(&dev->i2c_bus[0].i2c_adap, &msg, 1);
}
int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value)
{
struct i2c_client *client = &bus->i2c_client;
int retval = 0;
int v = 0;
u8 addr[2] = {0, 0};
u8 buf[4] = {0,0,0,0};
u8 addr[2] = { 0, 0 };
u8 buf[4] = { 0, 0, 0, 0 };
struct i2c_msg msgs[2]={
struct i2c_msg msgs[2] = {
{
.addr = client->addr,
.flags = 0,
......@@ -390,28 +377,26 @@ 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);
msgs[0].addr = 0x44;
msgs[1].addr = 0x44;
retval = i2c_xfer(client->adapter, msgs, 2);
v = (buf[3]<<24) | (buf[2]<<16) | (buf[1]<<8) | buf[0];
v = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
*value = v;
return v;
}
int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value)
{
struct i2c_client *client = &bus->i2c_client;
int retval = 0;
u8 buf[6] = {0, 0, 0, 0, 0, 0};
u8 buf[6] = { 0, 0, 0, 0, 0, 0 };
struct i2c_msg msgs[1]={
struct i2c_msg msgs[1] = {
{
.addr = client->addr,
.flags = 0,
......@@ -420,12 +405,11 @@ 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[5] = (value>>24) & 0xff;
buf[4] = (value>>16) & 0xff;
buf[3] = (value>>8) & 0xff;
buf[5] = (value >> 24) & 0xff;
buf[4] = (value >> 16) & 0xff;
buf[3] = (value >> 8) & 0xff;
buf[2] = value & 0xff;
client->flags = 0;
msgs[0].addr = 0x44;
......@@ -434,4 +418,3 @@ int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value)
return retval;
}
......@@ -452,5 +452,4 @@
#define VDEC_A_VSAT_CTRL 0x1019
#define VDEC_A_HUE_CTRL 0x101A
#endif
......@@ -24,13 +24,13 @@
#include "cx25821-medusa-video.h"
#include "cx25821-biffuncs.h"
/////////////////////////////////////////////////////////////////////////////////////////
//medusa_enable_bluefield_output()
//
// 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;
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_ns = OUT_CTRL_NS;
switch (channel)
{
switch (channel) {
default:
case VDEC_A:
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);
}
static int medusa_initialize_ntsc(struct cx25821_dev *dev)
{
int ret_val = 0;
......@@ -97,96 +94,145 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
mutex_lock(&dev->lock);
for (i=0; i < MAX_DECODERS; i++)
{
for (i = 0; i < MAX_DECODERS; i++) {
// 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 |= 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
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 |= 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 |= 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
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
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 |= 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.
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 |= 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
// 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 = 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
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);
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
medusa_enable_bluefield_output(dev, i, 1);
}
for (i=0; i < MAX_ENCODERS; i++)
{
for (i = 0; i < MAX_ENCODERS; i++) {
// 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 |= 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
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 |= 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 |= 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
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 |= 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 |= 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
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
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
......@@ -201,32 +247,44 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
return ret_val;
}
static int medusa_PALCombInit(struct cx25821_dev *dev, int dec)
{
int ret_val = -1;
u32 value = 0, tmp = 0;
// Setup for 2D threshold
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG+(0x200*dec), 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);
ret_val =
cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG + (0x200 * dec),
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
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;
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
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
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;
}
static int medusa_initialize_pal(struct cx25821_dev *dev)
{
int ret_val = 0;
......@@ -236,53 +294,81 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
mutex_lock(&dev->lock);
for (i=0; i < MAX_DECODERS; i++)
{
for (i = 0; i < MAX_DECODERS; i++) {
// 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 |= 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
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 |= 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
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 |= 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
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
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 |= 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.
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 |= 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
// 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 = 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
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);
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);
......@@ -290,46 +376,66 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
medusa_enable_bluefield_output(dev, i, 1);
}
for (i=0; i < MAX_ENCODERS; i++)
{
for (i = 0; i < MAX_ENCODERS; i++) {
// 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 |= 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
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 |= 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
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 |= 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
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 |= 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 = 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 |= 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
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
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
......@@ -344,19 +450,14 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
return ret_val;
}
int medusa_set_videostandard(struct cx25821_dev *dev)
{
int status = STATUS_SUCCESS;
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);
}
else
{
} else {
status = medusa_initialize_ntsc(dev);
}
......@@ -373,8 +474,8 @@ int medusa_set_videostandard(struct cx25821_dev *dev)
return status;
}
void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_select)
void medusa_set_resolution(struct cx25821_dev *dev, int width,
int decoder_select)
{
int decoder = 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);
// validate the width - cannot be negative
if (width > MAX_WIDTH)
{
printk("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH \n", __func__, width, MAX_WIDTH);
if (width > MAX_WIDTH) {
printk
("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH \n",
__func__, width, MAX_WIDTH);
width = MAX_WIDTH;
}
if( decoder_select <= 7 && decoder_select >= 0 )
{
if (decoder_select <= 7 && decoder_select >= 0) {
decoder = decoder_select;
decoder_count = decoder_select + 1;
}
else
{
} else {
decoder = 0;
decoder_count = _num_decoders;
}
switch( width )
{
switch (width) {
case 320:
hscale = 0x13E34B;
vscale = 0x0;
......@@ -432,17 +529,21 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width, int decoder_selec
break;
}
for( ; decoder < decoder_count; decoder++)
{
for (; decoder < decoder_count; decoder++) {
// write scaling values for each decoder
ret_val = 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);
ret_val =
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);
}
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;
u32 fld_cnt = 0;
......@@ -452,14 +553,12 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
mutex_lock(&dev->lock);
// no support
if (decoder < VDEC_A && decoder > VDEC_H)
{
if (decoder < VDEC_A && decoder > VDEC_H) {
mutex_unlock(&dev->lock);
return;
}
switch (decoder)
{
switch (decoder) {
default:
break;
case VDEC_C:
......@@ -485,11 +584,9 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
{
fld_cnt &= 0xFFFF0000;
fld_cnt |= duration;
}
else
{
} else {
fld_cnt &= 0x0000FFFF;
fld_cnt |= ((u32)duration) << 16;
fld_cnt |= ((u32) duration) << 16;
}
ret_val = cx25821_i2c_write(&dev->i2c_bus[0], disp_cnt_reg, fld_cnt);
......@@ -499,34 +596,25 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, int
/////////////////////////////////////////////////////////////////////////////////////////
// Map to Medusa register setting
static int mapM(
int srcMin,
int srcMax,
int srcVal,
int dstMin,
int dstMax,
int* dstVal
)
static int mapM(int srcMin,
int srcMax, int srcVal, int dstMin, int dstMax, int *dstVal)
{
int numerator;
int denominator;
int quotient;
if((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax))
{
if ((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax)) {
return -1;
}
// This is the overall expression used:
// *dstVal = (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin;
// but we need to account for rounding so below we use the modulus
// operator to find the remainder and increment if necessary.
numerator = (srcVal - srcMin)*(dstMax - dstMin);
numerator = (srcVal - srcMin) * (dstMax - dstMin);
denominator = srcMax - srcMin;
quotient = numerator/denominator;
quotient = numerator / denominator;
if(2 * ( numerator % denominator ) >= denominator)
{
if (2 * (numerator % denominator) >= denominator) {
quotient++;
}
......@@ -541,13 +629,13 @@ static unsigned long convert_to_twos(long numeric, unsigned long bits_len)
if (numeric >= 0)
return numeric;
else
{
else {
temp = ~(abs(numeric) & 0xFF);
temp += 1;
return temp;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
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;
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);
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);
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;
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);
return ret_val;
}
......@@ -579,16 +674,22 @@ int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
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);
return -1;
}
ret_val = 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);
ret_val =
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;
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);
return ret_val;
......@@ -603,25 +704,29 @@ int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
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);
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);
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;
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);
return ret_val;
}
/////////////////////////////////////////////////////////////////////////////////////////
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);
if((saturation > VIDEO_PROCAMP_MAX) || (saturation < VIDEO_PROCAMP_MIN))
{
if ((saturation > VIDEO_PROCAMP_MAX)
|| (saturation < VIDEO_PROCAMP_MIN)) {
mutex_unlock(&dev->lock);
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;
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);
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 &= 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);
return ret_val;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Program the display sequence and monitor output.
//
......@@ -659,39 +775,34 @@ int medusa_video_init(struct cx25821_dev *dev)
{
u32 value = 0, tmp = 0;
int ret_val = 0;
int i=0;
int i = 0;
mutex_lock(&dev->lock);
_num_decoders = dev->_max_num_decoders;
// disable Auto source selection on all video decoders
value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
value &= 0xFFFFF0FF;
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);
return -EINVAL;
}
// Turn off Master source switch enable
value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
value &= 0xFFFFFFDF;
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);
return -EINVAL;
}
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]);
}
......@@ -703,64 +814,53 @@ int medusa_video_init(struct cx25821_dev *dev)
value |= 0x00090008; // set en_active
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);
return -EINVAL;
}
// enable input is VIP/656
value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp);
value |= 0x00040100; // enable VIP
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);
return -EINVAL;
}
// select AFE clock to output mode
value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
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);
return -EINVAL;
}
// Turn on all of the data out and control output pins.
value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp);
value &= 0xFEF0FE00;
if (_num_decoders == MAX_DECODERS)
{
if (_num_decoders == MAX_DECODERS) {
// Note: The octal board does not support control pins(bit16-19).
// These bits are ignored in the octal board.
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 |= 7;
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);
return -EINVAL;
}
mutex_unlock(&dev->lock);
ret_val = medusa_set_videostandard(dev);
if (ret_val < 0)
{
if (ret_val < 0) {
mutex_unlock(&dev->lock);
return -EINVAL;
}
......
......@@ -25,7 +25,6 @@
#include "cx25821-medusa-defines.h"
// Color control constants
#define VIDEO_PROCAMP_MIN 0
#define VIDEO_PROCAMP_MAX 10000
......@@ -41,7 +40,6 @@
#define CONTRAST_DEFAULT 5000
#define HUE_DEFAULT 5000
unsigned short _num_decoders;
unsigned short _num_cameras;
......
......@@ -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_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_STAT 0x0400C4 // Audio Int interrupt status
......@@ -237,7 +236,6 @@
#define FLD_AUD_EXT_RISCI2 0x00000010
#define FLD_AUD_EXT_RISCI1 0x00000001
//*****************************************************************************
#define GPIO_LO 0x110010 // Lower of GPIO pins [31:0]
#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
//*****************************************************************************
// Rider
//*****************************************************************************
......@@ -669,7 +666,6 @@
//*****************************************************************************
#define DMA26_PTR1 0x100064 // DMA Current Ptr : Ch#26
//*****************************************************************************
#define DMA1_PTR2 0x100080 // DMA Tab Ptr : Ch#1
......@@ -748,8 +744,6 @@
//*****************************************************************************
#define DMA26_PTR2 0x1000E4 // DMA Tab Ptr : Ch#26
//*****************************************************************************
#define DMA1_CNT1 0x100100 // DMA BuFFer Size : Ch#1
......@@ -828,7 +822,6 @@
//*****************************************************************************
#define DMA26_CNT1 0x100164 // DMA BuFFer Size : Ch#26
//*****************************************************************************
#define DMA1_CNT2 0x100180 // DMA Table Size : Ch#1
......@@ -907,8 +900,6 @@
//*****************************************************************************
#define DMA26_CNT2 0x1001E4 // DMA Table Size : Ch#26
//*****************************************************************************
// ITG
//*****************************************************************************
......@@ -1070,7 +1061,6 @@
#define CLK_DELAY 0x110048 // Clock delay
#define FLD_MOE_CLK_DIS 0x80000000 // Disable MoE clock
//*****************************************************************************
#define PAD_CTRL 0x110068 // Pad drive strength control
......@@ -1100,7 +1090,6 @@
#define VID_CH_MODE_SEL 0x110078
#define VID_CH_CLK_SEL 0x11007C
//*****************************************************************************
#define VBI_A_DMA 0x130008 // VBI A DMA data port
......@@ -1148,7 +1137,6 @@
#define VID_C_LNGTH 0x130250 // Video C line length
#define FLD_VID_C_LN_LNGTH 0x00000FFF
//*****************************************************************************
// Video Destination Channels
//*****************************************************************************
......@@ -1173,7 +1161,6 @@
#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_A_DMA_CTL 0x130040 // Video A DMA control
......@@ -1397,7 +1384,6 @@
#define FLD_AUD_DST_B_FIFO_EN 0x00000002
#define FLD_AUD_DST_A_FIFO_EN 0x00000001
//*****************************************************************************
//
// Mobilygen Interface Registers
......@@ -1475,7 +1461,6 @@
#define FLD_MB_HCMD_H_ADDR 0x00FF0000
#define FLD_MB_HCMD_H_DATA 0x0000FFFF
//*****************************************************************************
// I2C #1
//*****************************************************************************
......@@ -1605,5 +1590,3 @@
#define PIXEL_ENGINE_VIP2 1
#endif //Athena_REGISTERS
......@@ -47,7 +47,6 @@
#define AUDIO_CLUSTER_SIZE 128 // AUDIO 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_END_SIZE = 0; // End of TX SRAM
......@@ -181,7 +180,6 @@
// Free Receive SRAM 144 Bytes
// Transmit SRAM
#define TX_SRAM_POOL_START 0x00000
......@@ -244,7 +242,6 @@
#define TX_SRAM_POOL_FREE 0x0BB00
#define TX_SRAM_END 0x0C000
#define BYTES_TO_DWORDS(bcount) ((bcount) >> 2)
#define BYTES_TO_QWORDS(bcount) ((bcount) >> 3)
#define BYTES_TO_OWORDS(bcount) ((bcount) >> 4)
......@@ -261,6 +258,4 @@
#define MBIF_CDT_SIZE_QW BYTES_TO_QWORDS(MBIF_CDT_SIZE)
#define MBIF_CLUSTER_SIZE_OW BYTES_TO_OWORDS(MBIF_CLUSTER_SIZE)
#endif
......@@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cx25821-video.h"
#include "cx25821-video-upstream-ch2.h"
......@@ -34,43 +33,39 @@
#include <linux/fcntl.h>
#include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL");
static int _intr_msk =
FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR;
static int _intr_msk = 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,
__le32 *rp, unsigned int offset, unsigned int bpl,
u32 sync_line, unsigned int lines, int fifo_enable, int field_type)
static __le32 *cx25821_update_riscprogram_ch2(struct cx25821_dev *dev,
__le32 * rp, unsigned int offset,
unsigned int bpl, u32 sync_line,
unsigned int lines,
int fifo_enable, int field_type)
{
unsigned int line, i;
int dist_betwn_starts = bpl * 2;
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
if( USE_RISC_NOOP_VIDEO )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
if (USE_RISC_NOOP_VIDEO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) = cpu_to_le32(RISC_NOOP);
}
}
/* scan lines */
for (line = 0; line < lines; line++)
{
*(rp++) = cpu_to_le32(RISC_READ|RISC_SOL|RISC_EOL|bpl);
*(rp++) = cpu_to_le32(dev->_data_buf_phys_addr_ch2+offset);
for (line = 0; line < lines; line++) {
*(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(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;
}
}
......@@ -78,50 +73,45 @@ static __le32 *cx25821_update_riscprogram_ch2( struct cx25821_dev *dev,
return rp;
}
static __le32 *cx25821_risc_field_upstream_ch2( struct cx25821_dev *dev,
__le32 *rp,
static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
__le32 * rp,
dma_addr_t databuf_phys_addr,
unsigned int offset, u32 sync_line, unsigned int bpl,
unsigned int lines, int fifo_enable, int field_type)
unsigned int offset,
u32 sync_line, unsigned int bpl,
unsigned int lines,
int fifo_enable, int field_type)
{
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;
/* sync instruction */
if (sync_line != NO_SYNC_LINE)
{
if (sync_line != NO_SYNC_LINE) {
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
}
if( USE_RISC_NOOP_VIDEO )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
if (USE_RISC_NOOP_VIDEO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) = cpu_to_le32(RISC_NOOP);
}
}
/* scan lines */
for (line = 0; line < lines; line++)
{
*(rp++) = cpu_to_le32(RISC_READ|RISC_SOL|RISC_EOL|bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr+offset);
for (line = 0; line < lines; line++) {
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(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;
}
// 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.
if ( fifo_enable && line == 3 )
{
if (fifo_enable && line == 3) {
*(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl;
*(rp++) = FLD_VID_FIFO_EN;
......@@ -132,9 +122,10 @@ static __le32 *cx25821_risc_field_upstream_ch2( struct cx25821_dev *dev,
return rp;
}
int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *pci,
unsigned int top_offset,
unsigned int bpl, unsigned int lines)
int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
struct pci_dev *pci,
unsigned int top_offset, unsigned int bpl,
unsigned int lines)
{
__le32 *rp;
int fifo_enable = 0;
......@@ -148,55 +139,60 @@ int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *p
unsigned int bottom_offset = bpl;
dma_addr_t risc_phys_jump_addr;
if( dev->_isNTSC_ch2 )
{
if (dev->_isNTSC_ch2) {
odd_num_lines = singlefield_lines + 1;
risc_program_size = FRAME1_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
}
else
{
frame_size =
(bpl ==
Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
FRAME_SIZE_NTSC_Y422;
} else {
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 */
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;
if (UNSET != top_offset)
{
if (UNSET != top_offset) {
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;
//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 )
{
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) {
risc_flag = RISC_CNT_RESET;
risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2 + risc_program_size;
}
else
{
risc_phys_jump_addr =
dev->_dma_phys_start_addr_ch2 + risc_program_size;
} else {
risc_flag = RISC_CNT_INC;
risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2;
}
// 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(0);
}
......@@ -204,75 +200,76 @@ int cx25821_risc_buffer_upstream_ch2( struct cx25821_dev *dev, struct pci_dev *p
return 0;
}
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;
if( !dev->_is_running_ch2 )
{
printk("cx25821: No video file is currently running so return!\n");
if (!dev->_is_running_ch2) {
printk
("cx25821: No video file is currently running so return!\n");
return;
}
//Disable RISC interrupts
tmp = cx_read( sram_ch->int_msk );
cx_write( sram_ch->int_msk, tmp & ~_intr_msk);
tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
//Turn OFF risc and fifo
tmp = cx_read( sram_ch->dma_ctl );
cx_write( sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN) );
tmp = cx_read(sram_ch->dma_ctl);
cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
//Clear data buffer memory
if( dev->_data_buf_virt_addr_ch2 )
memset( dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2 );
if (dev->_data_buf_virt_addr_ch2)
memset(dev->_data_buf_virt_addr_ch2, 0,
dev->_data_buf_size_ch2);
dev->_is_running_ch2 = 0;
dev->_is_first_frame_ch2 = 0;
dev->_frame_count_ch2 = 0;
dev->_file_status_ch2 = END_OF_FILE;
if( dev->_irq_queues_ch2 )
{
if (dev->_irq_queues_ch2) {
kfree(dev->_irq_queues_ch2);
dev->_irq_queues_ch2 = NULL;
}
if( dev->_filename_ch2 != NULL )
if (dev->_filename_ch2 != NULL)
kfree(dev->_filename_ch2);
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
}
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);
}
if (dev->_dma_virt_addr_ch2)
{
pci_free_consistent(dev->pci, dev->_risc_size_ch2, dev->_dma_virt_addr_ch2, dev->_dma_phys_addr_ch2);
if (dev->_dma_virt_addr_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 = NULL;
}
if (dev->_data_buf_virt_addr_ch2)
{
pci_free_consistent(dev->pci, dev->_data_buf_size_ch2, dev->_data_buf_virt_addr_ch2, dev->_data_buf_phys_addr_ch2);
if (dev->_data_buf_virt_addr_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 = 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 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_offset = 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;
mm_segment_t old_fs;
if( dev->_file_status_ch2 == END_OF_FILE )
if (dev->_file_status_ch2 == END_OF_FILE)
return 0;
if( dev->_isNTSC_ch2 )
{
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
}
else
{
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
if (dev->_isNTSC_ch2) {
frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
FRAME_SIZE_NTSC_Y422;
} else {
frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
}
frame_offset = (frame_index_temp > 0) ? frame_size : 0;
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered!", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered!", __func__);
if (!myfile->f_op->read) {
printk("%s: File has no READ operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -328,33 +321,35 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch
old_fs = get_fs();
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;
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 )
{
memcpy( (void*)(dev->_data_buf_virt_addr_ch2+frame_offset/4), mybuf, vfs_read_retval);
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);
}
file_offset += vfs_read_retval;
frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break;
}
}
if( i > 0 )
if (i > 0)
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);
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)
{
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 )
{
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ );
if (!dev) {
printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
__func__);
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)
{
struct file * myfile;
struct file *myfile;
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;
char mybuf[line_size];
loff_t pos;
loff_t offset = (unsigned long)0;
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered!", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered! Returning.", __func__);
if (!myfile->f_op->read) {
printk
("%s: File has no READ operations registered! Returning.",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -419,40 +414,42 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
old_fs = get_fs();
set_fs(KERNEL_DS);
for( j = 0; j < NUM_FRAMES; j++ )
{
for( i = 0; i < dev->_lines_count_ch2; i++ )
{
for (j = 0; j < NUM_FRAMES; j++) {
for (i = 0; i < dev->_lines_count_ch2; i++) {
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 )
{
memcpy( (void*)(dev->_data_buf_virt_addr_ch2+offset/4), mybuf, vfs_read_retval);
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
+ offset / 4), mybuf,
vfs_read_retval);
}
offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break;
}
}
if( i > 0 )
if (i > 0)
dev->_frame_count_ch2++;
if( vfs_read_retval < line_size )
{
if (vfs_read_retval < line_size) {
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);
myfile->f_pos = 0;
......@@ -462,7 +459,6 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
return 0;
}
static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
struct sram_channel *sram_ch,
int bpl)
......@@ -471,71 +467,72 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
dma_addr_t dma_addr;
dma_addr_t data_dma_addr;
if( dev->_dma_virt_addr_ch2 != NULL )
{
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size_ch2, dev->_dma_virt_addr_ch2, dev->_dma_phys_addr_ch2);
if (dev->_dma_virt_addr_ch2 != NULL) {
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size_ch2,
dev->_dma_virt_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_phys_start_addr_ch2 = dma_addr;
dev->_dma_phys_addr_ch2 = dma_addr;
dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2;
if (!dev->_dma_virt_addr_ch2)
{
printk("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
if (!dev->_dma_virt_addr_ch2) {
printk
("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
return -ENOMEM;
}
//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 )
{
pci_free_consistent(dev->pci, dev->upstream_databuf_size_ch2, dev->_data_buf_virt_addr_ch2, dev->_data_buf_phys_addr_ch2);
if (dev->_data_buf_virt_addr_ch2 != NULL) {
pci_free_consistent(dev->pci, dev->upstream_databuf_size_ch2,
dev->_data_buf_virt_addr_ch2,
dev->_data_buf_phys_addr_ch2);
}
//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_size_ch2 = dev->upstream_databuf_size_ch2;
if (!dev->_data_buf_virt_addr_ch2)
{
printk("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
if (!dev->_data_buf_virt_addr_ch2) {
printk
("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
return -ENOMEM;
}
//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);
if( ret < 0 )
if (ret < 0)
return ret;
//Creating RISC programs
ret = cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl, dev->_lines_count_ch2 );
if (ret < 0)
{
printk(KERN_INFO "cx25821: Failed creating Video Upstream Risc programs! \n");
ret =
cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl,
dev->_lines_count_ch2);
if (ret < 0) {
printk(KERN_INFO
"cx25821: Failed creating Video Upstream Risc programs! \n");
goto error;
}
return 0;
error:
error:
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;
struct sram_channel *channel = &dev->sram_channels[chan_num];
......@@ -543,19 +540,16 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 st
int line_size_in_bytes = Y422_LINE_SZ;
int odd_risc_prog_size = 0;
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
u32 prog_cnt = cx_read( channel->gpcnt );
u32 prog_cnt = cx_read(channel->gpcnt);
//Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers
int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
cx_write( channel->int_stat, _intr_msk );
cx_write(channel->int_stat, _intr_msk);
spin_lock(&dev->slock);
......@@ -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);
if ( dev->_is_first_frame_ch2 )
{
if (dev->_is_first_frame_ch2) {
dev->_is_first_frame_ch2 = 0;
if( dev->_isNTSC_ch2 )
{
if (dev->_isNTSC_ch2) {
singlefield_lines += 1;
odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
}
else
{
} else {
singlefield_lines = PAL_FIELD_HEIGHT;
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;
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);
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;
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);
// Jump to Even Risc program of 1st Frame
*(rp++) = cpu_to_le32(RISC_JUMP);
......@@ -597,16 +597,14 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num, u32 st
spin_unlock(&dev->slock);
}
if( dev->_file_status_ch2 == END_OF_FILE )
{
printk("cx25821: EOF Channel 2 Framecount = %d\n", dev->_frame_count_ch2 );
if (dev->_file_status_ch2 == END_OF_FILE) {
printk("cx25821: EOF Channel 2 Framecount = %d\n",
dev->_frame_count_ch2);
return -1;
}
//ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read( channel->int_msk );
cx_write( channel->int_msk, int_msk_tmp |= _intr_msk );
int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
return 0;
}
......@@ -619,8 +617,7 @@ static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
int channel_num = 0;
struct sram_channel *sram_ch;
if( !dev )
if (!dev)
return -1;
channel_num = VID_UPSTREAM_SRAM_CHANNEL_J;
......@@ -631,26 +628,23 @@ static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
vid_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt
if(vid_status)
{
handled = cx25821_video_upstream_irq_ch2(dev, channel_num, vid_status);
if (vid_status) {
handled =
cx25821_video_upstream_irq_ch2(dev, channel_num,
vid_status);
}
if( handled < 0 )
{
if (handled < 0) {
cx25821_stop_upstream_video_ch2(dev);
}
else
{
} else {
handled += handled;
}
return IRQ_RETVAL(handled);
}
static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_channel *ch, int pix_format)
static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
struct sram_channel *ch, int pix_format)
{
int width = WIDTH_D1;
int height = dev->_lines_count_ch2;
......@@ -658,43 +652,38 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev, struct sram_cha
u32 value;
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 |= dev->_isNTSC_ch2 ? 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
cx_write( ch->vid_active_ctl1, width );
cx_write(ch->vid_active_ctl1, width);
num_lines = (height / 2) & 0x3FF;
odd_num_lines = num_lines;
if(dev->_isNTSC_ch2)
{
if (dev->_isNTSC_ch2) {
odd_num_lines += 1;
}
value = (num_lines << 16) | odd_num_lines;
// set number of active lines in field 0 (top) and field 1 (bottom)
cx_write( ch->vid_active_ctl2, value );
cx_write(ch->vid_active_ctl2, value);
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,
struct sram_channel *sram_ch)
{
u32 tmp = 0;
int err = 0;
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
tmp = cx_read(VID_CH_MODE_SEL);
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.
cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2);
......@@ -704,39 +693,37 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
cx_write(sram_ch->gpcnt_ctl, 3);
// 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.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read( sram_ch->int_msk );
cx_write( sram_ch->int_msk, tmp |= _intr_msk );
err = request_irq(dev->pci->irq, cx25821_upstream_irq_ch2, 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);
tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
request_irq(dev->pci->irq, cx25821_upstream_irq_ch2,
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);
goto fail_irq;
}
// Start the DMA engine
tmp = cx_read( sram_ch->dma_ctl );
cx_set( sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN );
tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
dev->_is_running_ch2 = 1;
dev->_is_first_frame_ch2 = 1;
return 0;
fail_irq:
fail_irq:
cx25821_dev_unregister(dev);
return err;
}
int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, int pixel_format)
int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
int pixel_format)
{
struct sram_channel *sram_ch;
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 str_length = 0;
if( dev->_is_running_ch2 )
{
if (dev->_is_running_ch2) {
printk("Video Channel is still running so return!\n");
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;
sram_ch = &dev->sram_channels[channel_select];
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)
{
printk("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
if (!dev->_irq_queues_ch2) {
printk
("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
return -ENOMEM;
}
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
dev->_is_running_ch2 = 0;
dev->_frame_count_ch2 = 0;
dev->_file_status_ch2 = RESET_STATUS;
dev->_lines_count_ch2 = dev->_isNTSC_ch2 ? 480 : 576;
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;
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);
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;
memcpy(dev->_filename_ch2, dev->input_filename_ch2, str_length + 1);
}
else
{
memcpy(dev->_filename_ch2, dev->input_filename_ch2,
str_length + 1);
} else {
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;
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
if( strcmp(dev->input_filename_ch2,"") == 0)
{
if( dev->_isNTSC_ch2 )
{
dev->_filename_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? "/root/vid411.yuv" : "/root/vidtest.yuv";
}
else
{
dev->_filename_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ? "/root/pal411.yuv" : "/root/pal422.yuv";
if (strcmp(dev->input_filename_ch2, "") == 0) {
if (dev->_isNTSC_ch2) {
dev->_filename_ch2 =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? "/root/vid411.yuv" :
"/root/vidtest.yuv";
} else {
dev->_filename_ch2 =
(dev->_pixel_format_ch2 ==
PIXEL_FRMT_411) ? "/root/pal411.yuv" :
"/root/pal422.yuv";
}
}
retval = cx25821_sram_channel_setup_upstream(dev, sram_ch, dev->_line_size_ch2, 0);
retval =
cx25821_sram_channel_setup_upstream(dev, sram_ch,
dev->_line_size_ch2, 0);
/* setup fifo + format */
cx25821_set_pixelengine_ch2(dev, sram_ch, dev->_pixel_format_ch2);
......@@ -825,23 +813,23 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select, in
dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2;
dev->upstream_databuf_size_ch2 = data_frame_size * 2;
//Allocating buffers and prepare RISC program
retval = cx25821_upstream_buffer_prepare_ch2(dev, sram_ch, dev->_line_size_ch2);
if (retval < 0)
{
printk(KERN_ERR "%s: Failed to set up Video upstream buffers!\n", dev->name);
retval =
cx25821_upstream_buffer_prepare_ch2(dev, sram_ch,
dev->_line_size_ch2);
if (retval < 0) {
printk(KERN_ERR
"%s: Failed to set up Video upstream buffers!\n",
dev->name);
goto error;
}
cx25821_start_video_dma_upstream_ch2(dev, sram_ch);
return 0;
error:
error:
cx25821_dev_unregister(dev);
return err;
}
......@@ -23,7 +23,6 @@
#include <linux/mutex.h>
#include <linux/workqueue.h>
#define OPEN_FILE_1 0
#define NUM_PROGS 8
#define NUM_FRAMES 2
......@@ -38,8 +37,6 @@
#define RESET_STATUS -1
#define NUM_NO_OPS 5
// PAL and NTSC line sizes and number of lines.
#define WIDTH_D1 720
#define NTSC_LINES_PER_FRAME 480
......@@ -65,8 +62,6 @@
#define MAXSIZE_NO_OPS 36
#define DWORD_SIZE 4
#define USE_RISC_NOOP_VIDEO 1
#ifdef USE_RISC_NOOP_VIDEO
......@@ -92,7 +87,6 @@
RISC_WRITECR_INSTRUCTION_SIZE + NUM_NO_OPS*DWORD_SIZE)
#endif
#ifndef USE_RISC_NOOP_VIDEO
#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) )
......
......@@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cx25821-video.h"
#include "cx25821-video-upstream.h"
......@@ -34,13 +33,12 @@
#include <linux/fcntl.h>
#include <asm/uaccess.h>
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
MODULE_LICENSE("GPL");
static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | FLD_VID_SRC_OPC_ERR;
static int _intr_msk =
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,
struct sram_channel *ch,
......@@ -49,7 +47,6 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
unsigned int i, lines;
u32 cdt;
if (ch->cmds_start == 0) {
cx_write(ch->ptr1_reg, 0);
cx_write(ch->ptr2_reg, 0);
......@@ -62,20 +59,18 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
cdt = ch->cdt;
lines = ch->fifo_size / bpl;
if (lines > 4)
{
if (lines > 4) {
lines = 4;
}
BUG_ON(lines < 2);
/* write CDT */
for (i = 0; i < lines; i++) {
cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
cx_write(cdt + 16*i + 4, 0);
cx_write(cdt + 16*i + 8, 0);
cx_write(cdt + 16*i + 12, 0);
cx_write(cdt + 16 * i, ch->fifo_start + bpl * i);
cx_write(cdt + 16 * i + 4, 0);
cx_write(cdt + 16 * i + 8, 0);
cx_write(cdt + 16 * i + 12, 0);
}
/* write CMDS */
......@@ -83,10 +78,9 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
cx_write(ch->cmds_start + 4, 0);
cx_write(ch->cmds_start + 8, cdt);
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 + 20, VID_IQ_SIZE_DW);
for (i = 24; i < 80; i += 4)
......@@ -95,40 +89,37 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
/* fill registers */
cx_write(ch->ptr1_reg, ch->fifo_start);
cx_write(ch->ptr2_reg, cdt);
cx_write(ch->cnt2_reg, (lines*16) >> 3);
cx_write(ch->cnt2_reg, (lines * 16) >> 3);
cx_write(ch->cnt1_reg, (bpl >> 3) - 1);
return 0;
}
static __le32 *cx25821_update_riscprogram( struct cx25821_dev *dev,
__le32 *rp, unsigned int offset, unsigned int bpl,
u32 sync_line, unsigned int lines, int fifo_enable, int field_type)
static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
__le32 * rp, unsigned int offset,
unsigned int bpl, u32 sync_line,
unsigned int lines, int fifo_enable,
int field_type)
{
unsigned int line, i;
int dist_betwn_starts = bpl * 2;
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
if( USE_RISC_NOOP_VIDEO )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
if (USE_RISC_NOOP_VIDEO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) = cpu_to_le32(RISC_NOOP);
}
}
/* scan lines */
for (line = 0; line < lines; line++)
{
*(rp++) = cpu_to_le32(RISC_READ|RISC_SOL|RISC_EOL|bpl);
*(rp++) = cpu_to_le32(dev->_data_buf_phys_addr+offset);
for (line = 0; line < lines; line++) {
*(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(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;
}
}
......@@ -136,49 +127,42 @@ static __le32 *cx25821_update_riscprogram( struct cx25821_dev *dev,
return rp;
}
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,
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;
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;
/* sync instruction */
if (sync_line != NO_SYNC_LINE)
{
if (sync_line != NO_SYNC_LINE) {
*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
}
if( USE_RISC_NOOP_VIDEO )
{
for( i = 0; i < NUM_NO_OPS; i++ )
{
if (USE_RISC_NOOP_VIDEO) {
for (i = 0; i < NUM_NO_OPS; i++) {
*(rp++) = cpu_to_le32(RISC_NOOP);
}
}
/* scan lines */
for (line = 0; line < lines; line++)
{
*(rp++) = cpu_to_le32(RISC_READ|RISC_SOL|RISC_EOL|bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr+offset);
for (line = 0; line < lines; line++) {
*(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
*(rp++) = cpu_to_le32(databuf_phys_addr + offset);
*(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; //to skip the other field line
}
// 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.
if ( fifo_enable && line == 3 )
{
if (fifo_enable && line == 3) {
*(rp++) = RISC_WRITECR;
*(rp++) = sram_ch->dma_ctl;
*(rp++) = FLD_VID_FIFO_EN;
......@@ -189,7 +173,7 @@ static __le32 *cx25821_risc_field_upstream( struct cx25821_dev *dev, __le32 *rp,
return rp;
}
int cx25821_risc_buffer_upstream( struct cx25821_dev *dev,
int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
struct pci_dev *pci,
unsigned int top_offset,
unsigned int bpl, unsigned int lines)
......@@ -206,54 +190,58 @@ int cx25821_risc_buffer_upstream( struct cx25821_dev *dev,
unsigned int bottom_offset = bpl;
dma_addr_t risc_phys_jump_addr;
if( dev->_isNTSC )
{
if (dev->_isNTSC) {
odd_num_lines = singlefield_lines + 1;
risc_program_size = FRAME1_VID_PROG_SIZE;
frame_size = (bpl == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
}
else
{
frame_size =
(bpl ==
Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
FRAME_SIZE_NTSC_Y422;
} else {
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 */
rp = dev->_dma_virt_addr;
for( frame = 0; frame < NUM_FRAMES; frame++ )
{
for (frame = 0; frame < NUM_FRAMES; frame++) {
databuf_offset = frame_size * frame;
if (UNSET != top_offset)
{
if (UNSET != top_offset) {
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;
//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_phys_jump_addr = dev->_dma_phys_start_addr + risc_program_size;
}
else
{
risc_phys_jump_addr =
dev->_dma_phys_start_addr + risc_program_size;
} else {
risc_phys_jump_addr = dev->_dma_phys_start_addr;
risc_flag = RISC_CNT_INC;
}
// 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(0);
}
......@@ -261,75 +249,74 @@ int cx25821_risc_buffer_upstream( struct cx25821_dev *dev,
return 0;
}
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;
if( !dev->_is_running )
{
printk("cx25821: No video file is currently running so return!\n");
if (!dev->_is_running) {
printk
("cx25821: No video file is currently running so return!\n");
return;
}
//Disable RISC interrupts
tmp = cx_read( sram_ch->int_msk );
cx_write( sram_ch->int_msk, tmp & ~_intr_msk);
tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
//Turn OFF risc and fifo enable
tmp = cx_read( sram_ch->dma_ctl );
cx_write( sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN) );
tmp = cx_read(sram_ch->dma_ctl);
cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
//Clear data buffer memory
if( dev->_data_buf_virt_addr )
memset( dev->_data_buf_virt_addr, 0, dev->_data_buf_size );
if (dev->_data_buf_virt_addr)
memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size);
dev->_is_running = 0;
dev->_is_first_frame = 0;
dev->_frame_count = 0;
dev->_file_status = END_OF_FILE;
if( dev->_irq_queues )
{
if (dev->_irq_queues) {
kfree(dev->_irq_queues);
dev->_irq_queues = NULL;
}
if( dev->_filename != NULL )
if (dev->_filename != NULL)
kfree(dev->_filename);
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
}
void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev)
{
if( dev->_is_running )
{
if (dev->_is_running) {
cx25821_stop_upstream_video_ch1(dev);
}
if (dev->_dma_virt_addr)
{
pci_free_consistent(dev->pci, dev->_risc_size, dev->_dma_virt_addr, dev->_dma_phys_addr);
if (dev->_dma_virt_addr) {
pci_free_consistent(dev->pci, dev->_risc_size,
dev->_dma_virt_addr, dev->_dma_phys_addr);
dev->_dma_virt_addr = NULL;
}
if (dev->_data_buf_virt_addr)
{
pci_free_consistent(dev->pci, dev->_data_buf_size, dev->_data_buf_virt_addr, dev->_data_buf_phys_addr);
if (dev->_data_buf_virt_addr) {
pci_free_consistent(dev->pci, dev->_data_buf_size,
dev->_data_buf_virt_addr,
dev->_data_buf_phys_addr);
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 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_offset = 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;
mm_segment_t old_fs;
if( dev->_file_status == END_OF_FILE )
if (dev->_file_status == END_OF_FILE)
return 0;
if( dev->_isNTSC )
{
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
}
else
{
frame_size = (line_size == Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
if (dev->_isNTSC) {
frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_NTSC_Y411 :
FRAME_SIZE_NTSC_Y422;
} else {
frame_size =
(line_size ==
Y411_LINE_SZ) ? FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
}
frame_offset = (frame_index_temp > 0) ? frame_size : 0;
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered!", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered!", __func__);
if (!myfile->f_op->read) {
printk("%s: File has no READ operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -385,33 +368,35 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch )
old_fs = get_fs();
set_fs(KERNEL_DS);
for( i = 0; i < dev->_lines_count; i++ )
{
for (i = 0; i < dev->_lines_count; i++) {
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 )
{
memcpy( (void*)(dev->_data_buf_virt_addr+frame_offset/4), mybuf, vfs_read_retval);
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);
}
file_offset += vfs_read_retval;
frame_offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break;
}
}
if( i > 0 )
if (i > 0)
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);
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)
{
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 )
{
printk("ERROR %s(): since container_of(work_struct) FAILED! \n", __func__ );
if (!dev) {
printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
__func__);
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)
{
struct file * myfile;
struct file *myfile;
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;
char mybuf[line_size];
loff_t pos;
loff_t offset = (unsigned long)0;
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);
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);
}
else
{
if( !(myfile->f_op) )
{
printk("%s: File has no file operations registered!", __func__);
} else {
if (!(myfile->f_op)) {
printk("%s: File has no file operations registered!",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
if( !myfile->f_op->read )
{
printk("%s: File has no READ operations registered! Returning.", __func__);
if (!myfile->f_op->read) {
printk
("%s: File has no READ operations registered! Returning.",
__func__);
filp_close(myfile, NULL);
return -EIO;
}
......@@ -476,41 +460,42 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
old_fs = get_fs();
set_fs(KERNEL_DS);
for( j = 0; j < NUM_FRAMES; j++ )
{
for( i = 0; i < dev->_lines_count; i++ )
{
for (j = 0; j < NUM_FRAMES; j++) {
for (i = 0; i < dev->_lines_count; i++) {
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 )
{
memcpy( (void*)(dev->_data_buf_virt_addr+offset/4), mybuf, vfs_read_retval);
if (vfs_read_retval > 0
&& vfs_read_retval == line_size
&& dev->_data_buf_virt_addr != NULL) {
memcpy((void *)(dev->
_data_buf_virt_addr +
offset / 4), mybuf,
vfs_read_retval);
}
offset += vfs_read_retval;
if( vfs_read_retval < line_size )
{
printk(KERN_INFO "Done: exit %s() since no more bytes to read from Video file.\n", __func__ );
if (vfs_read_retval < line_size) {
printk(KERN_INFO
"Done: exit %s() since no more bytes to read from Video file.\n",
__func__);
break;
}
}
if( i > 0 )
if (i > 0)
dev->_frame_count++;
if( vfs_read_retval < line_size )
{
if (vfs_read_retval < line_size) {
break;
}
}
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);
myfile->f_pos = 0;
......@@ -520,80 +505,78 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
return 0;
}
int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
struct sram_channel *sram_ch,
int bpl)
struct sram_channel *sram_ch, int bpl)
{
int ret = 0;
dma_addr_t dma_addr;
dma_addr_t data_dma_addr;
if( dev->_dma_virt_addr != NULL )
{
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size, dev->_dma_virt_addr, dev->_dma_phys_addr);
if (dev->_dma_virt_addr != NULL) {
pci_free_consistent(dev->pci, dev->upstream_riscbuf_size,
dev->_dma_virt_addr, dev->_dma_phys_addr);
}
dev->_dma_virt_addr = pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size, &dma_addr);
dev->_dma_virt_addr =
pci_alloc_consistent(dev->pci, dev->upstream_riscbuf_size,
&dma_addr);
dev->_dma_virt_start_addr = dev->_dma_virt_addr;
dev->_dma_phys_start_addr = dma_addr;
dev->_dma_phys_addr = dma_addr;
dev->_risc_size = dev->upstream_riscbuf_size;
if (!dev->_dma_virt_addr)
{
printk("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
if (!dev->_dma_virt_addr) {
printk
("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
return -ENOMEM;
}
//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 )
{
pci_free_consistent(dev->pci, dev->upstream_databuf_size, dev->_data_buf_virt_addr, dev->_data_buf_phys_addr);
if (dev->_data_buf_virt_addr != NULL) {
pci_free_consistent(dev->pci, dev->upstream_databuf_size,
dev->_data_buf_virt_addr,
dev->_data_buf_phys_addr);
}
//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_size = dev->upstream_databuf_size;
if (!dev->_data_buf_virt_addr)
{
printk("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
if (!dev->_data_buf_virt_addr) {
printk
("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
return -ENOMEM;
}
//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);
if( ret < 0 )
if (ret < 0)
return ret;
//Create RISC programs
ret = cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl, dev->_lines_count );
if (ret < 0)
{
printk(KERN_INFO "cx25821: Failed creating Video Upstream Risc programs! \n");
ret =
cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl,
dev->_lines_count);
if (ret < 0) {
printk(KERN_INFO
"cx25821: Failed creating Video Upstream Risc programs! \n");
goto error;
}
return 0;
error:
error:
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;
struct sram_channel *channel = &dev->sram_channels[chan_num];
......@@ -601,19 +584,16 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
int line_size_in_bytes = Y422_LINE_SZ;
int odd_risc_prog_size = 0;
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
u32 prog_cnt = cx_read( channel->gpcnt );
u32 prog_cnt = cx_read(channel->gpcnt);
//Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers
int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
cx_write( channel->int_stat, _intr_msk );
cx_write(channel->int_stat, _intr_msk);
spin_lock(&dev->slock);
......@@ -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);
if ( dev->_is_first_frame )
{
if (dev->_is_first_frame) {
dev->_is_first_frame = 0;
if( dev->_isNTSC )
{
if (dev->_isNTSC) {
singlefield_lines += 1;
odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
}
else
{
} else {
singlefield_lines = PAL_FIELD_HEIGHT;
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;
rp = cx25821_update_riscprogram(dev, dev->_dma_virt_start_addr, TOP_OFFSET, line_size_in_bytes, 0x0, singlefield_lines, FIFO_DISABLE, ODD_FIELD);
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;
rp = cx25821_update_riscprogram(dev,
dev->
_dma_virt_start_addr,
TOP_OFFSET,
line_size_in_bytes,
0x0,
singlefield_lines,
FIFO_DISABLE,
ODD_FIELD);
// Jump to Even Risc program of 1st Frame
*(rp++) = cpu_to_le32(RISC_JUMP);
......@@ -653,29 +639,29 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, u32 status
}
spin_unlock(&dev->slock);
}
else
{
if(status & FLD_VID_SRC_UF)
printk("%s: Video Received Underflow Error Interrupt!\n", __func__);
} else {
if (status & FLD_VID_SRC_UF)
printk
("%s: Video Received Underflow Error Interrupt!\n",
__func__);
if(status & FLD_VID_SRC_SYNC)
printk("%s: Video Received Sync Error Interrupt!\n", __func__);
if (status & FLD_VID_SRC_SYNC)
printk("%s: Video Received Sync Error Interrupt!\n",
__func__);
if(status & FLD_VID_SRC_OPC_ERR)
printk("%s: Video Received OpCode Error Interrupt!\n", __func__);
if (status & FLD_VID_SRC_OPC_ERR)
printk("%s: Video Received OpCode Error Interrupt!\n",
__func__);
}
if( dev->_file_status == END_OF_FILE )
{
printk("cx25821: EOF Channel 1 Framecount = %d\n", dev->_frame_count );
if (dev->_file_status == END_OF_FILE) {
printk("cx25821: EOF Channel 1 Framecount = %d\n",
dev->_frame_count);
return -1;
}
//ElSE, set the interrupt mask register, re-enable irq.
int_msk_tmp = cx_read( channel->int_msk );
cx_write( channel->int_msk, int_msk_tmp |= _intr_msk );
int_msk_tmp = cx_read(channel->int_msk);
cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
return 0;
}
......@@ -688,8 +674,7 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
int channel_num = 0;
struct sram_channel *sram_ch;
if( !dev )
if (!dev)
return -1;
channel_num = VID_UPSTREAM_SRAM_CHANNEL_I;
......@@ -700,25 +685,22 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
vid_status = cx_read(sram_ch->int_stat);
// Only deal with our interrupt
if(vid_status)
{
handled = cx25821_video_upstream_irq(dev, channel_num, vid_status);
if (vid_status) {
handled =
cx25821_video_upstream_irq(dev, channel_num, vid_status);
}
if( handled < 0 )
{
if (handled < 0) {
cx25821_stop_upstream_video_ch1(dev);
}
else
{
} else {
handled += handled;
}
return IRQ_RETVAL(handled);
}
void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch, int pix_format)
void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch,
int pix_format)
{
int width = WIDTH_D1;
int height = dev->_lines_count;
......@@ -726,44 +708,38 @@ void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch, i
u32 value;
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 |= 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
cx_write( ch->vid_active_ctl1, width );
cx_write(ch->vid_active_ctl1, width);
num_lines = (height / 2) & 0x3FF;
odd_num_lines = num_lines;
if(dev->_isNTSC)
{
if (dev->_isNTSC) {
odd_num_lines += 1;
}
value = (num_lines << 16) | odd_num_lines;
// set number of active lines in field 0 (top) and field 1 (bottom)
cx_write( ch->vid_active_ctl2, value );
cx_write(ch->vid_active_ctl2, value);
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,
struct sram_channel *sram_ch)
{
u32 tmp = 0;
int err = 0;
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
tmp = cx_read(VID_CH_MODE_SEL);
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.
cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr);
......@@ -773,39 +749,38 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
cx_write(sram_ch->gpcnt_ctl, 3);
// 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.
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
tmp = cx_read( sram_ch->int_msk );
cx_write( sram_ch->int_msk, tmp |= _intr_msk );
err = request_irq(dev->pci->irq, cx25821_upstream_irq, 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);
tmp = cx_read(sram_ch->int_msk);
cx_write(sram_ch->int_msk, tmp |= _intr_msk);
err =
request_irq(dev->pci->irq, cx25821_upstream_irq,
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);
goto fail_irq;
}
// Start the DMA engine
tmp = cx_read( sram_ch->dma_ctl );
cx_set( sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN );
tmp = cx_read(sram_ch->dma_ctl);
cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
dev->_is_running = 1;
dev->_is_first_frame = 1;
return 0;
fail_irq:
fail_irq:
cx25821_dev_unregister(dev);
return err;
}
int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, int pixel_format)
int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
int pixel_format)
{
struct sram_channel *sram_ch;
u32 tmp;
......@@ -815,74 +790,68 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
int risc_buffer_size = 0;
int str_length = 0;
if( dev->_is_running )
{
if (dev->_is_running) {
printk("Video Channel is still running so return!\n");
return 0;
}
dev->_channel_upstream_select = channel_select;
sram_ch = &dev->sram_channels[channel_select];
INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler);
dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue");
if(!dev->_irq_queues)
{
printk("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
if (!dev->_irq_queues) {
printk
("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
return -ENOMEM;
}
// 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
dev->_is_running = 0;
dev->_frame_count = 0;
dev->_file_status = RESET_STATUS;
dev->_lines_count = dev->_isNTSC ? 480 : 576;
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;
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);
dev->_filename = (char *) kmalloc(str_length + 1, GFP_KERNEL);
dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL);
if( !dev->_filename )
if (!dev->_filename)
goto error;
memcpy(dev->_filename, dev->input_filename, str_length + 1);
}
else
{
} else {
str_length = strlen(dev->_defaultname);
dev->_filename = (char *) kmalloc(str_length + 1, GFP_KERNEL);
dev->_filename = (char *)kmalloc(str_length + 1, GFP_KERNEL);
if( !dev->_filename )
if (!dev->_filename)
goto error;
memcpy(dev->_filename, dev->_defaultname, str_length + 1);
}
//Default if filename is empty string
if( strcmp(dev->input_filename,"") == 0)
{
if( dev->_isNTSC )
{
dev->_filename = (dev->_pixel_format == PIXEL_FRMT_411) ? "/root/vid411.yuv" : "/root/vidtest.yuv";
}
else
{
dev->_filename = (dev->_pixel_format == PIXEL_FRMT_411) ? "/root/pal411.yuv" : "/root/pal422.yuv";
if (strcmp(dev->input_filename, "") == 0) {
if (dev->_isNTSC) {
dev->_filename =
(dev->_pixel_format ==
PIXEL_FRMT_411) ? "/root/vid411.yuv" :
"/root/vidtest.yuv";
} else {
dev->_filename =
(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->_lines_count = dev->_isNTSC ? 480 : 576;
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 */
cx25821_set_pixelengine(dev, sram_ch, dev->_pixel_format);
......@@ -901,23 +874,21 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, in
dev->upstream_riscbuf_size = risc_buffer_size * 2;
dev->upstream_databuf_size = data_frame_size * 2;
//Allocating buffers and prepare RISC program
retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size);
if (retval < 0)
{
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;
}
cx25821_start_video_dma_upstream(dev, sram_ch);
return 0;
error:
error:
cx25821_dev_unregister(dev);
return err;
}
......@@ -38,8 +38,6 @@
#define RESET_STATUS -1
#define NUM_NO_OPS 5
// PAL and NTSC line sizes and number of lines.
#define WIDTH_D1 720
#define NTSC_LINES_PER_FRAME 480
......@@ -65,7 +63,6 @@
#define MAXSIZE_NO_OPS 36
#define DWORD_SIZE 4
#define USE_RISC_NOOP_VIDEO 1
#ifdef USE_RISC_NOOP_VIDEO
......@@ -93,7 +90,6 @@
#endif
#ifndef USE_RISC_NOOP_VIDEO
#define PAL_US_VID_PROG_SIZE ((PAL_FIELD_HEIGHT) * 3 * DWORD_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
RISC_SYNC_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE)
......
......@@ -27,8 +27,8 @@ MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
MODULE_LICENSE("GPL");
static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
static unsigned int radio_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
static unsigned int video_nr[] = {[0...(CX25821_MAXBOARDS - 1)] = UNSET };
static unsigned int radio_nr[] = {[0...(CX25821_MAXBOARDS - 1)] = UNSET };
module_param_array(video_nr, int, NULL, 0444);
module_param_array(radio_nr, int, NULL, 0444);
......@@ -36,7 +36,7 @@ module_param_array(radio_nr, int, NULL, 0444);
MODULE_PARM_DESC(video_nr, "video device numbers");
MODULE_PARM_DESC(radio_nr, "radio device numbers");
static unsigned int video_debug=VIDEO_DEBUG;
static unsigned int video_debug = VIDEO_DEBUG;
module_param(video_debug, int, 0644);
MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
......@@ -73,7 +73,7 @@ struct cx25821_fmt formats[] = {
.fourcc = V4L2_PIX_FMT_UYVY,
.depth = 16,
.flags = FORMAT_FLAGS_PACKED,
},{
}, {
.name = "4:2:0, YUV",
.fourcc = V4L2_PIX_FMT_YUV420,
.depth = 12,
......@@ -81,25 +81,22 @@ struct cx25821_fmt formats[] = {
},
};
int get_format_size(void)
{
return ARRAY_SIZE(formats);
}
struct cx25821_fmt *format_by_fourcc(unsigned int fourcc)
{
unsigned int i;
if( fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P )
{
return formats+1;
if (fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P) {
return formats + 1;
}
for (i = 0; i < ARRAY_SIZE(formats); i++)
if (formats[i].fourcc == fourcc)
return formats+i;
return formats + i;
printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
return NULL;
......@@ -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);
}
if (!list_empty(&q->queued))
{
if (!list_empty(&q->queued)) {
list_for_each(item, &q->queued)
buf = list_entry(item, struct cx25821_buffer, vb.queue);
}
}
void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u32 count)
void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
u32 count)
{
struct cx25821_buffer *buf;
int bc;
for (bc = 0;; bc++) {
if (list_empty(&q->active))
{
if (list_empty(&q->active)) {
dprintk(1, "bc=%d (=0: active empty)\n", bc);
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 --
* this trick handles wrap-arounds correctly for
* up to 32767 buffers in flight... */
if ((s16) (count - buf->count) < 0)
{
if ((s16) (count - buf->count) < 0) {
break;
}
......@@ -156,17 +151,17 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u
if (list_empty(&q->active))
del_timer(&q->timeout);
else
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
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
int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm)
{
dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__,
(unsigned int)norm,
v4l2_norm_to_name(norm));
(unsigned int)norm, v4l2_norm_to_name(norm));
dev->tvnorm = norm;
......@@ -192,7 +187,8 @@ struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
vfd->minor = -1;
vfd->v4l2_dev = &dev->v4l2_dev;
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;
}
......@@ -265,10 +261,9 @@ int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input)
struct v4l2_routing 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__,
input, INPUT(input)->vmux,
INPUT(input)->gpio0, INPUT(input)->gpio1,
INPUT(input)->gpio2, INPUT(input)->gpio3);
dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
__func__, input, INPUT(input)->vmux, INPUT(input)->gpio0,
INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3);
dev->input = input;
route.input = INPUT(input)->vmux;
......@@ -294,27 +289,29 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
q->count = 1;
/* enable irq */
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1<<channel->i));
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i));
cx_set(channel->int_msk, 0x11);
/* start dma */
cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */
/* make sure upstream setting if any is reversed */
tmp = cx_read( VID_CH_MODE_SEL );
cx_write( VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
tmp = cx_read(VID_CH_MODE_SEL);
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
return 0;
}
int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, struct sram_channel *channel)
int cx25821_restart_video_queue(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q,
struct sram_channel *channel)
{
struct cx25821_buffer *buf, *prev;
struct list_head *item;
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);
......@@ -323,7 +320,7 @@ int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue
buf->count = q->count++;
}
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
return 0;
}
......@@ -332,14 +329,15 @@ int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue
if (list_empty(&q->queued))
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) {
list_move_tail(&buf->vb.queue, &q->active);
cx25821_start_video_dma(dev, q, buf, channel);
buf->vb.state = VIDEOBUF_ACTIVE;
buf->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
} else if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
......@@ -369,7 +367,8 @@ void cx25821_vid_timeout(unsigned long data)
spin_lock_irqsave(&dev->slock, flags);
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);
buf->vb.state = VIDEOBUF_ERROR;
......@@ -382,7 +381,7 @@ void cx25821_vid_timeout(unsigned long data)
int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
{
u32 count=0;
u32 count = 0;
int handled = 0;
u32 mask;
struct sram_channel *channel = &dev->sram_channels[chan_num];
......@@ -395,7 +394,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
/* risc op code error */
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);
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) {
dprintk(2, "stopper video\n");
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);
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)
{
if( dev->ioctl_dev )
{
if (dev->ioctl_dev) {
if (dev->ioctl_dev->minor != -1)
video_unregister_device(dev->ioctl_dev);
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, struct video_device *video_template)
int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
struct video_device *video_template)
{
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].queued);
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);
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 */
dev->video_dev[chan_num] = 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]);
dev->video_dev[chan_num] =
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) {
goto fail_unreg;
}
//set PCI interrupt
cx_set(PCI_INT_MSK, 0xff);
/* initial device configuration */
mutex_lock(&dev->lock);
#ifdef TUNER_FLAG
......@@ -499,17 +501,17 @@ int cx25821_video_register(struct cx25821_dev *dev, int chan_num, struct video_d
return 0;
fail_unreg:
fail_unreg:
cx25821_video_unregister(dev, chan_num);
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;
*size = fh->fmt->depth*fh->width*fh->height >> 3;
*size = fh->fmt->depth * fh->width * fh->height >> 3;
if (0 == *count)
*count = 32;
......@@ -520,18 +522,19 @@ int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *si
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_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;
u32 line0_offset, line1_offset;
struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
int bpl_local = LINE_SIZE_D1;
int channel_opened = 0;
BUG_ON(NULL == fh->fmt);
if (fh->width < 48 || fh->width > 720 ||
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)
return -EINVAL;
if (buf->fmt != fh->fmt ||
buf->vb.width != fh->width ||
buf->vb.height != fh->height ||
buf->vb.field != field) {
buf->vb.height != fh->height || buf->vb.field != field) {
buf->fmt = fh->fmt;
buf->vb.width = fh->width;
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) {
init_buffer = 1;
rc = videobuf_iolock(q, &buf->vb, NULL);
if (0 != rc)
{
if (0 != rc) {
printk(KERN_DEBUG "videobuf_iolock failed!\n");
goto fail;
}
......@@ -569,35 +569,33 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
if (init_buffer) {
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;
else
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;
}
else
{
} else {
bpl_local = buf->bpl; //Default
if( channel_opened >= 0 && channel_opened <= 7 )
{
if( dev->use_cif_resolution[channel_opened] )
{
if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK )
if (channel_opened >= 0 && channel_opened <= 7) {
if (dev->use_cif_resolution[channel_opened]) {
if (dev->tvnorm & V4L2_STD_PAL_BG
|| dev->tvnorm & V4L2_STD_PAL_DK)
bpl_local = 352 << 1;
else
bpl_local = dev->cif_width[channel_opened] << 1;
bpl_local =
dev->
cif_width[channel_opened] <<
1;
}
}
}
switch (buf->vb.field) {
case V4L2_FIELD_TOP:
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,
dma->sglist,
0, buf->bpl * (buf->vb.height >> 1),
buf->bpl, 0,
buf->vb.height >> 1);
buf->bpl, 0, buf->vb.height >> 1);
break;
case V4L2_FIELD_SEQ_BT:
cx25821_risc_buffer(dev->pci, &buf->risc,
dma->sglist,
buf->bpl * (buf->vb.height >> 1), 0,
buf->bpl, 0,
buf->vb.height >> 1);
buf->bpl, 0, buf->vb.height >> 1);
break;
default:
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",
buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
(unsigned long)buf->risc.dma);
buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth,
fh->fmt->name, (unsigned long)buf->risc.dma);
buf->vb.state = VIDEOBUF_PREPARED;
......@@ -652,15 +648,14 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
return rc;
}
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);
}
struct videobuf_queue *get_queue(struct cx25821_fh *fh)
{
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)
{
struct cx25821_fh *fh = file->private_data;
......@@ -721,9 +715,8 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
maxh = 576;
if (V4L2_FIELD_ANY == field) {
field = (f->fmt.pix.height > maxh/2)
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_TOP;
field = (f->fmt.pix.height > maxh / 2)
? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
}
switch (field) {
......@@ -753,8 +746,6 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
return 0;
}
int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
{
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));
cap->version = CX25821_VERSION_CODE;
cap->capabilities =
V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING;
V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
if (UNSET != dev->tuner_type)
cap->capabilities |= V4L2_CAP_TUNER;
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)))
return -EINVAL;
......@@ -838,8 +828,7 @@ int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
return 0;
}
int vidioc_s_priority(struct file *file, void *f,
enum v4l2_priority prio)
int vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio)
{
struct cx25821_fh *fh = f;
struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
......@@ -847,9 +836,8 @@ int vidioc_s_priority(struct file *file, void *f,
return v4l2_prio_change(&dev->prio, &fh->prio, prio);
}
#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)
{
struct cx25821_fh *fh = priv;
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
......@@ -857,15 +845,13 @@ int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
dprintk(1, "%s()\n", __func__);
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
}
if( dev->tvnorm == *tvnorms )
{
if (dev->tvnorm == *tvnorms) {
return 0;
}
......@@ -921,7 +907,6 @@ int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
return 0;
}
int vidioc_s_input(struct file *file, void *priv, unsigned int i)
{
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);
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -1022,7 +1005,6 @@ int vidioc_s_register(struct file *file, void *fh,
#endif
#ifdef TUNER_FLAG
int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
{
......@@ -1038,19 +1020,17 @@ int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
t->capability = V4L2_TUNER_CAP_NORM;
t->rangehigh = 0xffffffffUL;
t->signal = 0xffff ; /* LOCKED */
t->signal = 0xffff; /* LOCKED */
return 0;
}
int vidioc_s_tuner(struct file *file, void *priv,
struct v4l2_tuner *t)
int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
struct cx25821_fh *fh = priv;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -1082,7 +1062,7 @@ static struct v4l2_queryctrl cx25821_ctls[] = {
.step = 1,
.default_value = 6200,
.type = V4L2_CTRL_TYPE_INTEGER,
},{
}, {
.id = V4L2_CID_CONTRAST,
.name = "Contrast",
.minimum = 0,
......@@ -1090,7 +1070,7 @@ static struct v4l2_queryctrl cx25821_ctls[] = {
.step = 1,
.default_value = 5000,
.type = V4L2_CTRL_TYPE_INTEGER,
},{
}, {
.id = V4L2_CID_SATURATION,
.name = "Saturation",
.minimum = 0,
......@@ -1098,7 +1078,7 @@ static struct v4l2_queryctrl cx25821_ctls[] = {
.step = 1,
.default_value = 5000,
.type = V4L2_CTRL_TYPE_INTEGER,
},{
}, {
.id = V4L2_CID_HUE,
.name = "Hue",
.minimum = 0,
......@@ -1114,8 +1094,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
{
int i;
if (qctrl->id < V4L2_CID_BASE ||
qctrl->id >= V4L2_CID_LASTP1)
if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1)
return -EINVAL;
for (i = 0; i < CX25821_CTLS; i++)
if (cx25821_ctls[i].id == qctrl->id)
......@@ -1137,30 +1116,27 @@ int vidioc_queryctrl(struct file *file, void *priv,
/* ------------------------------------------------------------------ */
/* VIDEO CTRL IOCTLS */
static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
{
unsigned int i;
for (i = 0; i < CX25821_CTLS; i++)
if (cx25821_ctls[i].id == id)
return cx25821_ctls+i;
return cx25821_ctls + i;
return NULL;
}
int vidioc_g_ctrl(struct file *file,
void *priv,
struct v4l2_control *ctl)
int vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
const struct v4l2_queryctrl* ctrl;
const struct v4l2_queryctrl *ctrl;
ctrl = ctrl_by_id(ctl->id);
if (NULL == ctrl)
return -EINVAL;
switch (ctl->id)
{
switch (ctl->id) {
case V4L2_CID_BRIGHTNESS:
ctl->value = dev->ctl_bright;
break;
......@@ -1181,7 +1157,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
struct v4l2_control *ctl, int chan_num)
{
int err;
const struct v4l2_queryctrl* ctrl;
const struct v4l2_queryctrl *ctrl;
err = -EINVAL;
......@@ -1190,8 +1166,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
if (NULL == ctrl)
return err;
switch (ctrl->type)
{
switch (ctrl->type) {
case V4L2_CTRL_TYPE_BOOLEAN:
case V4L2_CTRL_TYPE_MENU:
case V4L2_CTRL_TYPE_INTEGER:
......@@ -1201,11 +1176,10 @@ int cx25821_set_control(struct cx25821_dev *dev,
ctl->value = ctrl->maximum;
break;
default:
/* nothing */;
/* nothing */ ;
};
switch (ctl->id)
{
switch (ctl->id) {
case V4L2_CID_BRIGHTNESS:
dev->ctl_bright = ctl->value;
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,
void *priv,
struct v4l2_cropcap *cropcap)
int vidioc_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cropcap)
{
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.width = 720;
cropcap->bounds.height = dev->tvnorm == V4L2_STD_PAL_BG ? 576 : 480;
cropcap->pixelaspect.numerator = dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10;
cropcap->pixelaspect.denominator = dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11;
cropcap->pixelaspect.numerator =
dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10;
cropcap->pixelaspect.denominator =
dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11;
cropcap->defrect = cropcap->bounds;
return 0;
}
int vidioc_s_crop(struct file *file,
void *priv,
struct v4l2_crop *crop)
int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
struct cx25821_fh *fh = priv;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -1276,17 +1247,13 @@ int vidioc_s_crop(struct file *file,
return -EINVAL;
}
int vidioc_g_crop(struct file *file,
void *priv,
struct v4l2_crop *crop)
int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
{
// vidioc_g_crop not supported
return -EINVAL;
}
int vidioc_querystd(struct file *file,
void *priv,
v4l2_std_id *norm)
int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
{
// medusa does not support video standard sensing of current input
*norm = CX25821_NORMS;
......@@ -1296,16 +1263,14 @@ int vidioc_querystd(struct file *file,
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)
return 1;
else
return 0;
}
if(tvnorm == V4L2_STD_NTSC_M)
{
if (tvnorm == V4L2_STD_NTSC_M) {
if (width == 320 || width == 352 || width == 720)
return 1;
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)
{
if(tvnorm == V4L2_STD_PAL_BG)
{
if (tvnorm == V4L2_STD_PAL_BG) {
if (height == 576 || height == 288)
return 1;
else
return 0;
}
if(tvnorm == V4L2_STD_NTSC_M)
{
if (tvnorm == V4L2_STD_NTSC_M) {
if (height == 480 || height == 240)
return 1;
else
......@@ -1334,4 +1297,3 @@ int is_valid_height(u32 height, v4l2_std_id tvnorm)
return 0;
}
......@@ -24,7 +24,6 @@
#ifndef CX25821_VIDEO_H_
#define CX25821_VIDEO_H_
#include <linux/init.h>
#include <linux/list.h>
#include <linux/module.h>
......@@ -55,7 +54,6 @@
printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
} while (0)
//For IOCTL to identify running upstream
#define UPSTREAM_START_VIDEO 700
#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_data timeout_data[MAX_VID_CHANNEL_NUM];
extern void dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q);
extern void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u32 count);
extern void dump_video_queue(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q);
extern void cx25821_video_wakeup(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q, u32 count);
#ifdef TUNER_FLAG
extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm);
#endif
extern int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit);
extern int res_get(struct cx25821_dev *dev, 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 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_start_video_dma(struct cx25821_dev *dev,
struct cx25821_dmaqueue *q,
struct cx25821_buffer *buf,
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 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 buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size);
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 int buffer_setup(struct videobuf_queue *q, unsigned int *count,
unsigned int *size);
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 int get_resource(struct cx25821_fh *fh, int resource);
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_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 vidioc_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *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 vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p);
extern int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
extern int vidioc_reqbufs(struct file *file, void *priv,
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_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 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_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_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 vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctl);
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 vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f);
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_s_frequency(struct file *file, void *priv,
struct v4l2_frequency *f);
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_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
......@@ -159,14 +177,18 @@ extern int is_valid_width(u32 width, 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_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 cx25821_set_control(struct cx25821_dev *dev, struct v4l2_control *ctrl, int chan_num);
extern int vidioc_queryctrl(struct file *file, void *priv,
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_g_crop(struct file *file, void *priv, struct v4l2_crop *crop);
extern int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm);
extern int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm);
#endif
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,12 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -128,23 +131,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -152,17 +156,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO0))
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:
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_buffer *buf;
......@@ -189,27 +195,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH00] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH00]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -231,31 +235,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -281,16 +281,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = PIXEL_FRMT_422;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -323,20 +320,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH00, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH00] = 0;
}
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);
return 0;
......@@ -355,7 +351,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -368,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
dev->name);
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -452,6 +449,3 @@ struct video_device cx25821_video_template0 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,16 +23,15 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH01];
/* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -128,23 +131,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -152,17 +156,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO1))
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:
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_buffer *buf;
......@@ -189,21 +195,20 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH01] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH01]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
......@@ -230,31 +235,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -280,17 +281,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -323,20 +320,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH01, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH01, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH01] = 0;
}
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);
return 0;
......@@ -355,7 +351,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -368,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
dev->name);
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -389,6 +386,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return cx25821_set_control(dev, ctl, SRAM_CH01);
}
//exported stuff
static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE,
......@@ -451,6 +449,3 @@ struct video_device cx25821_video_template1 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,16 +23,15 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH02];
/* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -127,23 +130,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -151,17 +155,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO2))
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:
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_buffer *buf;
......@@ -188,27 +194,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH02] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH02]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -230,31 +234,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -280,17 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -323,21 +319,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH02, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH02, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH02] = 0;
}
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, 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);
return 0;
......@@ -356,7 +350,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -371,7 +365,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -392,6 +387,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return cx25821_set_control(dev, ctl, SRAM_CH02);
}
// exported stuff
static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE,
......@@ -454,6 +450,3 @@ struct video_device cx25821_video_template2 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,16 +23,15 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH03];
/* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -99,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -127,23 +130,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -151,17 +155,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO3))
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:
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_buffer *buf;
......@@ -188,27 +194,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH03] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH03]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -230,31 +234,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -280,17 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -323,20 +319,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH03, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH03, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH03] = 0;
}
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);
return 0;
......@@ -355,7 +350,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -369,7 +364,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -453,6 +449,3 @@ struct video_device cx25821_video_template3 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -126,22 +130,23 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -149,17 +154,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO4))
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:
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_buffer *buf;
......@@ -186,27 +193,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH04] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH04]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -228,31 +233,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -278,9 +279,8 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_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;
// check priority
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -321,20 +318,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH04, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH04, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH04] = 0;
}
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);
return 0;
......@@ -353,7 +349,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -367,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -451,6 +448,3 @@ struct video_device cx25821_video_template4 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -126,23 +130,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -150,17 +155,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO5))
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:
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_buffer *buf;
......@@ -187,27 +194,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH05] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH05]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -229,31 +234,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -279,16 +280,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -321,20 +319,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH05, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH05, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH05] = 0;
}
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);
return 0;
......@@ -352,7 +349,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -366,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -450,6 +448,3 @@ struct video_device cx25821_video_template5 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,11 +102,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -126,23 +130,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -150,17 +155,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO6))
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:
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_buffer *buf;
......@@ -187,27 +194,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH06] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH06]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -228,31 +233,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -278,16 +279,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -320,20 +318,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH06, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH06, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH06] = 0;
}
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);
return 0;
......@@ -352,7 +349,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -366,7 +363,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -450,6 +448,3 @@ struct video_device cx25821_video_template6 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -86,7 +91,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -97,11 +101,11 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -125,23 +129,24 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
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);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -149,17 +154,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO7))
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:
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_buffer *buf;
......@@ -186,27 +193,25 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *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 )
{
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
if (buf->vb.state == VIDEOBUF_DONE) {
struct cx25821_dev *dev = fh->dev;
if( dev && dev->use_cif_resolution[SRAM_CH07] )
{
u8 cam_id = *((char*)buf->vb.baddr+3);
memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
*((char*)buf->vb.baddr+3) = cam_id;
if (dev && dev->use_cif_resolution[SRAM_CH07]) {
u8 cam_id = *((char *)buf->vb.baddr + 3);
memcpy((char *)buf->vb.baddr,
(char *)buf->vb.baddr + (fh->width * 2),
(fh->width * 2));
*((char *)buf->vb.baddr + 3) = cam_id;
}
}
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
}
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -228,31 +233,27 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -278,16 +279,15 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
int pix_format = 0;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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;
// 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;
}
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;
}
......@@ -320,20 +318,19 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
else
return -EINVAL;
cx25821_set_pixel_format( dev, SRAM_CH07, pix_format );
cx25821_set_pixel_format(dev, SRAM_CH07, pix_format);
// 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;
}else
{
} else {
dev->use_cif_resolution[SRAM_CH07] = 0;
}
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);
return 0;
......@@ -351,7 +348,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
return ret_val;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -365,7 +362,8 @@ static int vidioc_log_status (struct file *file, void *priv)
cx25821_call_all(dev, core, log_status);
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",
dev->name);
return 0;
......@@ -449,6 +447,3 @@ struct video_device cx25821_video_template7 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,12 +102,10 @@ static int video_open(struct file *file)
u32 pix_format;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -128,7 +130,7 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
......@@ -137,14 +139,13 @@ static int video_open(struct file *file)
pix_format = V4L2_PIX_FMT_YUYV;
fh->fmt = format_by_fourcc(pix_format);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -152,17 +153,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO_IOCTL))
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:
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_buffer *buf;
......@@ -190,12 +193,11 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -214,7 +216,7 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
......@@ -222,24 +224,20 @@ static int video_release(struct file *file)
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -265,15 +263,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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->height = f->fmt.pix.height;
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);
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);
}
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_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;
u32 value = 0;
data_from_user = (struct downstream_user_struct *)arg;
if( !data_from_user )
{
printk("cx25821 in %s(): User data is INVALID. Returning.\n", __func__);
if (!data_from_user) {
printk("cx25821 in %s(): User data is INVALID. Returning.\n",
__func__);
return 0;
}
command = data_from_user->command;
if( command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT && command != ENABLE_CIF_RESOLUTION &&
command != REG_READ && command != REG_WRITE && command != MEDUSA_READ && command != MEDUSA_WRITE)
{
if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
&& command != ENABLE_CIF_RESOLUTION && command != REG_READ
&& command != REG_WRITE && command != MEDUSA_READ
&& command != MEDUSA_WRITE) {
return 0;
}
switch(command)
{
switch (command) {
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);
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;
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 = selected_channel % 8;
}
if( selected_channel >= 0 )
cx25821_set_pixel_format( dev, selected_channel, pix_format );
if (selected_channel >= 0)
cx25821_set_pixel_format(dev, selected_channel,
pix_format);
break;
......@@ -355,36 +354,31 @@ static long video_ioctl_set(struct file *file, unsigned int cmd, unsigned long a
cif_enable = data_from_user->cif_resolution_enable;
cif_width = data_from_user->cif_width;
if( cif_enable )
{
if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK )
if (cif_enable) {
if (dev->tvnorm & V4L2_STD_PAL_BG
|| dev->tvnorm & V4L2_STD_PAL_DK)
width = 352;
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 = 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->cif_width[selected_channel] = width;
}
else
{
for( i=0; i < VID_CHANNEL_NUM; i++ )
{
} else {
for (i = 0; i < VID_CHANNEL_NUM; i++) {
dev->use_cif_resolution[i] = cif_enable;
dev->cif_width[i] = width;
}
}
medusa_set_resolution( dev, width, selected_channel );
medusa_set_resolution(dev, width, selected_channel);
break;
case REG_READ:
data_from_user->reg_data = cx_read(data_from_user->reg_address);
......@@ -393,17 +387,22 @@ 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);
break;
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;
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;
}
return 0;
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -424,8 +423,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -433,6 +431,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return 0;
}
// exported stuff
static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE,
......@@ -495,6 +494,3 @@ struct video_device cx25821_videoioctl_template = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,16 +23,15 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
struct cx25821_dev *dev = fh->dev;
struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH10];
/* add jump to stopper */
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -88,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -98,11 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -127,23 +130,21 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
dev->channel_opened = 9;
fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -151,17 +152,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO10))
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:
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_buffer *buf;
......@@ -189,7 +192,7 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
return 0;
}
......@@ -214,7 +217,7 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
......@@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -265,27 +264,26 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0;
}
static long video_ioctl_upstream10(struct file *file, unsigned int cmd, unsigned long arg)
static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev;
int command = 0;
struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user )
{
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__);
if (!data_from_user) {
printk
("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0;
}
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;
}
......@@ -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->command_ch2 = data_from_user->command;
switch(command)
{
switch (command) {
case UPSTREAM_START_VIDEO:
cx25821_start_upstream_video_ch2(dev, data_from_user);
break;
......@@ -311,15 +307,14 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd, unsigned
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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->height = f->fmt.pix.height;
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);
return 0;
}
......@@ -345,7 +341,7 @@ 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);
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -366,8 +362,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -438,6 +433,3 @@ struct video_device cx25821_video_template10 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -23,10 +23,10 @@
#include "cx25821-video.h"
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_fh *fh = vq->priv_data;
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)) {
list_add_tail(&buf->vb.queue, &q->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)) {
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->count = q->count++;
mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb. i, buf->count, q->count);
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
dprintk(2,
"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
buf, buf->vb.i, buf->count, q->count);
} else {
prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width &&
prev->vb.height == buf->vb.height &&
prev->fmt == buf->fmt) {
prev =
list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
if (prev->vb.width == buf->vb.width
&& prev->vb.height == buf->vb.height
&& prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
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 */
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 {
list_add_tail(&buf->vb.queue, &q->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");
}
}
static struct videobuf_queue_ops cx25821_video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -87,7 +92,6 @@ static struct videobuf_queue_ops cx25821_video_qops = {
.buf_release = buffer_release,
};
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
......@@ -97,12 +101,11 @@ static int video_open(struct file *file)
enum v4l2_buf_type type = 0;
lock_kernel();
list_for_each(list, &cx25821_devlist)
{
list_for_each(list, &cx25821_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;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
......@@ -127,7 +130,7 @@ static int video_open(struct file *file)
fh->type = type;
fh->width = 720;
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)
fh->height = 576;
else
fh->height = 480;
......@@ -135,14 +138,13 @@ static int video_open(struct file *file)
dev->channel_opened = 8;
fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
v4l2_prio_open(&dev->prio,&fh->prio);
v4l2_prio_open(&dev->prio, &fh->prio);
videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
&dev->pci->dev, &dev->slock,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_FIELD_INTERLACED,
sizeof(struct cx25821_buffer),
fh);
sizeof(struct cx25821_buffer), fh);
dprintk(1, "post videobuf_queue_init()\n");
unlock_kernel();
......@@ -150,17 +152,18 @@ static int video_open(struct file *file)
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;
switch (fh->type)
{
switch (fh->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (res_locked(fh->dev, RESOURCE_VIDEO9))
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:
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_buffer *buf;
......@@ -188,11 +192,10 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
poll_wait(file, &buf->vb.done, wait);
if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
return POLLIN|POLLRDNORM;
return POLLIN | POLLRDNORM;
return 0;
}
static int video_release(struct file *file)
{
struct cx25821_fh *fh = file->private_data;
......@@ -214,7 +217,7 @@ static int video_release(struct file *file)
videobuf_mmap_free(&fh->vidq);
v4l2_prio_close(&dev->prio,&fh->prio);
v4l2_prio_close(&dev->prio, &fh->prio);
file->private_data = NULL;
kfree(fh);
......@@ -222,24 +225,20 @@ static int video_release(struct file *file)
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx25821_fh *fh = priv;
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;
}
if (unlikely(i != fh->type))
{
if (unlikely(i != fh->type)) {
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;
}
......@@ -265,31 +264,29 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
return 0;
}
static long video_ioctl_upstream9(struct file *file, unsigned int cmd, unsigned long arg)
static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct cx25821_fh *fh = file->private_data;
struct cx25821_dev *dev = fh->dev;
int command = 0;
struct upstream_user_struct *data_from_user;
data_from_user = (struct upstream_user_struct *)arg;
if( !data_from_user )
{
printk("cx25821 in %s(): Upstream data is INVALID. Returning.\n", __func__);
if (!data_from_user) {
printk
("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
__func__);
return 0;
}
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;
}
dev->input_filename = data_from_user->input_filename;
dev->input_audiofilename = data_from_user->input_filename;
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->command = data_from_user->command;
switch(command)
{
switch (command) {
case UPSTREAM_START_VIDEO:
cx25821_start_upstream_video_ch1(dev, data_from_user);
break;
......@@ -312,15 +307,14 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd, unsigned
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_dev *dev = ((struct cx25821_fh *)priv)->dev;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != 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->height = f->fmt.pix.height;
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);
return 0;
}
......@@ -345,7 +340,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
struct cx25821_fh *fh = priv;
return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
}
static int vidioc_log_status (struct file *file, void *priv)
static int vidioc_log_status(struct file *file, void *priv)
{
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
char name[32 + 2];
......@@ -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_fh *fh = priv;
int err;
if (fh)
{
if (fh) {
err = v4l2_prio_check(&dev->prio, &fh->prio);
if (0 != err)
return err;
......@@ -374,6 +368,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return 0;
}
// exported stuff
static const struct v4l2_file_operations video_fops = {
.owner = THIS_MODULE,
......@@ -436,6 +431,3 @@ struct video_device cx25821_video_template9 = {
.tvnorms = CX25821_NORMS,
.current_norm = V4L2_STD_NTSC_M,
};
......@@ -21,7 +21,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CX25821_H_
#define CX25821_H_
......@@ -85,7 +84,6 @@
#define RESOURCE_VIDEO11 2048
#define RESOURCE_VIDEO_IOCTL 4096
#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
#define UNKNOWN_BOARD 0
......@@ -301,15 +299,15 @@ struct cx25821_dev {
int _audio_upstream_channel_select;
int _last_index_irq; //The last interrupt index processed.
__le32 * _risc_audio_jmp_addr;
__le32 * _risc_virt_start_addr;
__le32 * _risc_virt_addr;
__le32 *_risc_audio_jmp_addr;
__le32 *_risc_virt_start_addr;
__le32 *_risc_virt_addr;
dma_addr_t _risc_phys_addr;
dma_addr_t _risc_phys_start_addr;
unsigned int _audiorisc_size;
unsigned int _audiodata_buf_size;
__le32 * _audiodata_buf_virt_addr;
__le32 *_audiodata_buf_virt_addr;
dma_addr_t _audiodata_buf_phys_addr;
char *_audiofilename;
......@@ -335,17 +333,16 @@ struct cx25821_dev {
int _channel_upstream_select;
unsigned int _risc_size;
__le32 * _dma_virt_start_addr;
__le32 * _dma_virt_addr;
__le32 *_dma_virt_start_addr;
__le32 *_dma_virt_addr;
dma_addr_t _dma_phys_addr;
dma_addr_t _dma_phys_start_addr;
unsigned int _data_buf_size;
__le32 * _data_buf_virt_addr;
__le32 *_data_buf_virt_addr;
dma_addr_t _data_buf_phys_addr;
char * _filename;
char * _defaultname;
char *_filename;
char *_defaultname;
int _line_size_ch2;
int _prog_cnt_ch2;
......@@ -358,16 +355,16 @@ struct cx25821_dev {
int _channel2_upstream_select;
unsigned int _risc_size_ch2;
__le32 * _dma_virt_start_addr_ch2;
__le32 * _dma_virt_addr_ch2;
__le32 *_dma_virt_start_addr_ch2;
__le32 *_dma_virt_addr_ch2;
dma_addr_t _dma_phys_addr_ch2;
dma_addr_t _dma_phys_start_addr_ch2;
unsigned int _data_buf_size_ch2;
__le32 * _data_buf_virt_addr_ch2;
__le32 *_data_buf_virt_addr_ch2;
dma_addr_t _data_buf_phys_addr_ch2;
char * _filename_ch2;
char * _defaultname_ch2;
char *_filename_ch2;
char *_defaultname_ch2;
/* MPEG Encoder ONLY settings */
u32 cx23417_mailbox;
......@@ -385,11 +382,11 @@ struct cx25821_dev {
int _isNTSC;
int _frame_index;
int _audioframe_index;
struct workqueue_struct * _irq_queues;
struct workqueue_struct *_irq_queues;
struct work_struct _irq_work_entry;
struct workqueue_struct * _irq_queues_ch2;
struct workqueue_struct *_irq_queues_ch2;
struct work_struct _irq_work_entry_ch2;
struct workqueue_struct * _irq_audio_queues;
struct workqueue_struct *_irq_audio_queues;
struct work_struct _audio_work_entry;
char *input_filename;
char *input_filename_ch2;
......@@ -410,7 +407,6 @@ struct cx25821_dev {
int channel_opened;
};
struct upstream_user_struct {
char *input_filename;
char *vid_stdname;
......@@ -458,8 +454,6 @@ extern struct cx25821_subid cx25821_subids[];
#define SRAM_CH10 10 /* Video Upstream J */
#define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
#define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
#define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
#define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
......@@ -528,60 +522,78 @@ extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
extern void cx25821_gpio_init(struct cx25821_dev *dev);
extern void cx25821_set_gpiopin_direction( struct cx25821_dev *dev,
int pin_number,
int pin_logic_value);
extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
int pin_number, int pin_logic_value);
extern int medusa_video_init(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 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 void medusa_set_resolution(struct cx25821_dev *dev, int width,
int decoder_select);
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_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,
struct scatterlist *sglist,
unsigned int top_offset,
unsigned int bottom_offset,
unsigned int bpl,
unsigned int padding,
unsigned int lines);
unsigned int padding, unsigned int lines);
extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
struct btcx_riscmem *risc,
struct scatterlist *sglist,
unsigned int bpl,
unsigned int lines,
unsigned int lpi);
extern void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf);
extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,u32 reg, u32 mask, u32 value);
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 void cx25821_print_irqbits(char *name, char *tag, char **strings, int len, u32 bits, u32 mask);
unsigned int lines, unsigned int lpi);
extern void cx25821_free_buffer(struct videobuf_queue *q,
struct cx25821_buffer *buf);
extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
u32 reg, u32 mask, u32 value);
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 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 int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
struct sram_channel *ch,
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_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 int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
int channel_select, int pixel_format);
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_ch2(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_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_start_upstream_video_ch1(struct cx25821_dev *dev,
struct upstream_user_struct
*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_ch2(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 void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel, u32 format);
extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
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 struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
struct pci_dev *pci,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment