提交 7615e434 编写于 作者: S Steven Toth 提交者: Mauro Carvalho Chehab

[media] saa7164: add various encoder message functions

Signed-off-by: NSteven Toth <stoth@kernellabs.com>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 add3f580
......@@ -265,3 +265,41 @@ int saa7164_buffer_cfg_port(struct saa7164_port *port)
return 0;
}
struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev, u32 len)
{
struct saa7164_user_buffer *buf;
buf = kzalloc(sizeof(struct saa7164_user_buffer), GFP_KERNEL);
if (buf == 0)
return 0;
buf->data = kzalloc(len, GFP_KERNEL);
if (buf->data == 0) {
kfree(buf);
return 0;
}
buf->actual_size = len;
buf->pos = 0;
dprintk(DBGLVL_BUF, "%s() allocated user buffer @ 0x%p\n",
__func__, buf);
return buf;
}
void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf)
{
if (!buf)
return;
if (buf->data) {
kfree(buf->data);
buf->data = 0;
}
if (buf)
kfree(buf);
}
......@@ -55,6 +55,8 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2200",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV3,
.unit = {{
.id = 0x1d,
......@@ -97,6 +99,8 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2200",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV2,
.unit = {{
.id = 0x06,
......@@ -139,6 +143,8 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2200",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV2,
.unit = {{
.id = 0x1d,
......@@ -195,6 +201,10 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2250",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV3,
.unit = {{
.id = 0x22,
......@@ -251,6 +261,8 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2250",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV3,
.unit = {{
.id = 0x28,
......@@ -307,6 +319,8 @@ struct saa7164_board saa7164_boards[] = {
.name = "Hauppauge WinTV-HVR2250",
.porta = SAA7164_MPEG_DVB,
.portb = SAA7164_MPEG_DVB,
.portc = SAA7164_MPEG_ENCODER,
.portd = SAA7164_MPEG_ENCODER,
.chiprev = SAA7164_CHIP_REV3,
.unit = {{
.id = 0x26,
......
......@@ -82,6 +82,69 @@ static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
}
static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
{
struct saa7164_dev *dev = port->dev;
struct saa7164_buffer *buf;
struct saa7164_user_buffer *ubuf;
struct list_head *c, *n;
int wp, i = 0, rp;
/* Find the current write point from the hardware */
wp = saa7164_readl(port->bufcounter);
if (wp > (port->hwcfg.buffercount - 1))
BUG();
/* Find the previous buffer to the current write point */
if (wp == 0)
rp = 7;
else
rp = wp - 1;
/* Lookup the WP in the buffer list */
/* TODO: turn this into a worker thread */
list_for_each_safe(c, n, &port->dmaqueue.list) {
buf = list_entry(c, struct saa7164_buffer, list);
if (i++ > port->hwcfg.buffercount)
BUG();
if (buf->idx == rp) {
/* Found the buffer, deal with it */
dprintk(DBGLVL_IRQ, "%s() wp: %d processing: %d\n",
__func__, wp, rp);
/* */
/* find a free user buffer and clone to it */
if (!list_empty(&port->list_buf_free.list)) {
/* Pull the first buffer from the used list */
ubuf = list_first_entry(&port->list_buf_free.list,
struct saa7164_user_buffer, list);
if (ubuf->actual_size == buf->actual_size)
memcpy(ubuf->data, buf->cpu, ubuf->actual_size);
/* Requeue the buffer on the free list */
ubuf->pos = 0;
// mutex_lock(&port->dmaqueue_lock);
list_move_tail(&ubuf->list, &port->list_buf_used.list);
// mutex_unlock(&port->dmaqueue_lock);
/* Flag any userland waiters */
wake_up_interruptible(&port->wait_read);
} else
printk(KERN_ERR "encirq no free buffers\n");
break;
}
}
return 0;
}
static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
{
struct saa7164_dev *dev = port->dev;
......@@ -123,6 +186,11 @@ static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
static irqreturn_t saa7164_irq(int irq, void *dev_id)
{
struct saa7164_dev *dev = dev_id;
struct saa7164_port *porta = &dev->ports[ SAA7164_PORT_TS1 ];
struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ];
struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ];
struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ];
u32 intid, intstat[INT_SIZE/4];
int i, handled = 0, bit;
......@@ -168,17 +236,25 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
if (intid == dev->intfdesc.bInterruptId) {
/* A response to an cmd/api call */
schedule_work(&dev->workcmd);
} else if (intid ==
dev->ts1.hwcfg.interruptid) {
} else if (intid == porta->hwcfg.interruptid) {
/* Transport path 1 */
saa7164_irq_ts(&dev->ts1);
saa7164_irq_ts(porta);
} else if (intid ==
dev->ts2.hwcfg.interruptid) {
} else if (intid == portb->hwcfg.interruptid) {
/* Transport path 2 */
saa7164_irq_ts(&dev->ts2);
saa7164_irq_ts(portb);
} else if (intid == portc->hwcfg.interruptid) {
/* Encoder path 1 */
saa7164_irq_encoder(portc);
} else if (intid == portd->hwcfg.interruptid) {
/* Encoder path 1 */
saa7164_irq_encoder(portd);
} else {
/* Find the function */
......@@ -402,6 +478,37 @@ static int get_resources(struct saa7164_dev *dev)
return -EBUSY;
}
static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
{
struct saa7164_port *port = 0;
if ((portnr < 0) || (portnr >= SAA7164_MAX_PORTS))
BUG();
port = &dev->ports[ portnr ];
port->dev = dev;
port->nr = portnr;
if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
port->type = SAA7164_MPEG_DVB;
else
if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2))
port->type = SAA7164_MPEG_ENCODER;
else
BUG();
/* Init all the critical resources */
mutex_init(&port->dvb.lock);
INIT_LIST_HEAD(&port->dmaqueue.list);
mutex_init(&port->dmaqueue_lock);
INIT_LIST_HEAD(&port->list_buf_used.list);
INIT_LIST_HEAD(&port->list_buf_free.list);
init_waitqueue_head(&port->wait_read);
return 0;
}
static int saa7164_dev_setup(struct saa7164_dev *dev)
{
int i;
......@@ -443,21 +550,11 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
dev->i2c_bus[2].dev = dev;
dev->i2c_bus[2].nr = 2;
/* Transport port A Defaults / setup */
dev->ts1.dev = dev;
dev->ts1.nr = 0;
dev->ts1.type = SAA7164_MPEG_UNDEFINED;
mutex_init(&dev->ts1.dvb.lock);
INIT_LIST_HEAD(&dev->ts1.dmaqueue.list);
mutex_init(&dev->ts1.dmaqueue_lock);
/* Transport port B Defaults / setup */
dev->ts2.dev = dev;
dev->ts2.nr = 1;
dev->ts2.type = SAA7164_MPEG_UNDEFINED;
mutex_init(&dev->ts2.dvb.lock);
INIT_LIST_HEAD(&dev->ts2.dmaqueue.list);
mutex_init(&dev->ts2.dmaqueue_lock);
/* Transport + Encoder ports 1, 2, 3, 4 - Defaults / setup */
saa7164_port_init(dev, SAA7164_PORT_TS1);
saa7164_port_init(dev, SAA7164_PORT_TS2);
saa7164_port_init(dev, SAA7164_PORT_ENC1);
saa7164_port_init(dev, SAA7164_PORT_ENC2);
if (get_resources(dev) < 0) {
printk(KERN_ERR "CORE %s No more PCIe resources for "
......@@ -631,7 +728,7 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
/* Begin to create the video sub-systems and register funcs */
if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB) {
if (saa7164_dvb_register(&dev->ts1) < 0) {
if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS1 ]) < 0) {
printk(KERN_ERR "%s() Failed to register "
"dvb adapters on porta\n",
__func__);
......@@ -639,13 +736,27 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
}
if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB) {
if (saa7164_dvb_register(&dev->ts2) < 0) {
if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS2 ]) < 0) {
printk(KERN_ERR"%s() Failed to register "
"dvb adapters on portb\n",
__func__);
}
}
if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER) {
if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC1 ]) < 0) {
printk(KERN_ERR"%s() Failed to register "
"mpeg encoder\n", __func__);
}
}
if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER) {
if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC2 ]) < 0) {
printk(KERN_ERR"%s() Failed to register "
"mpeg encoder\n", __func__);
}
}
} /* != BOARD_UNKNOWN */
else
printk(KERN_ERR "%s() Unsupported board detected, "
......@@ -676,10 +787,16 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
saa7164_shutdown(dev);
if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB)
saa7164_dvb_unregister(&dev->ts1);
saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS1 ]);
if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB)
saa7164_dvb_unregister(&dev->ts2);
saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS2 ]);
if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER)
saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC1 ]);
if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]);
saa7164_i2c_unregister(&dev->i2c_bus[0]);
saa7164_i2c_unregister(&dev->i2c_bus[1]);
......
......@@ -48,18 +48,26 @@
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
#include <linux/kdev_t.h>
#include <linux/version.h>
#include <linux/mutex.h>
#include <media/tuner.h>
#include <media/tveeprom.h>
#include <media/videobuf-dma-sg.h>
#include <media/videobuf-dvb.h>
#include <linux/smp_lock.h>
#include <dvb_demux.h>
#include <dvb_frontend.h>
#include <dvb_net.h>
#include <dvbdev.h>
#include <dmxdev.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-chip-ident.h>
#include "saa7164-reg.h"
#include "saa7164-types.h"
#include <linux/version.h>
#include <linux/mutex.h>
#define SAA7164_MAXBOARDS 8
#define UNSET (-1U)
......@@ -77,6 +85,14 @@
#define SAA7164_MAX_UNITS 8
#define SAA7164_TS_NUMBER_OF_LINES 312
#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
#define SAA7164_MAX_ENCODER_BUFFERS 16
/* Port related defines */
#define SAA7164_PORT_TS1 (0)
#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
#define SAA7164_MAX_PORTS (SAA7164_PORT_ENC2 + 1)
#define DBGLVL_FW 4
#define DBGLVL_DVB 8
......@@ -88,6 +104,8 @@
#define DBGLVL_BUF 512
#define DBGLVL_ENC 1024
#define SAA7164_NORMS ( V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 )
enum port_t {
SAA7164_MPEG_UNDEFINED = 0,
SAA7164_MPEG_DVB,
......@@ -136,7 +154,7 @@ struct saa7164_unit {
struct saa7164_board {
char *name;
enum port_t porta, portb;
enum port_t porta, portb, portc, portd;
enum {
SAA7164_CHIP_UNDEFINED = 0,
SAA7164_CHIP_REV2,
......@@ -151,6 +169,22 @@ struct saa7164_subid {
u32 card;
};
struct saa7164_fh {
struct saa7164_port *port;
u32 freq;
u32 tuner_type;
atomic_t v4l_reading;
};
struct saa7164_user_buffer {
struct list_head list;
/* Attributes */
u8 *data;
u32 pos;
u32 actual_size;
};
struct saa7164_fw_status {
/* RISC Core details */
......@@ -193,6 +227,30 @@ struct saa7164_i2c {
u32 i2c_rc;
};
struct saa7164_ctrl {
struct v4l2_queryctrl v;
};
struct saa7164_tvnorm {
char *name;
v4l2_std_id id;
// u32 cxiformat;
// u32 cxoformat;
};
struct saa7164_encoder_params {
struct saa7164_tvnorm encodernorm;
u32 height;
u32 width;
u32 is_50hz;
u32 bitrate; /* bps */
u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
u32 audio_sampling_freq;
u32 ctl_mute;
u32 ctl_aspect;
};
struct saa7164_port;
struct saa7164_buffer {
......@@ -254,7 +312,42 @@ struct saa7164_port {
struct saa7164_dvb dvb;
/* --- Encoder/V4L related attributes --- */
/* Encoder */
/* Defaults established in saa7164-encoder.c */
struct saa7164_tvnorm encodernorm;
u32 height;
u32 width;
u32 freq;
u32 ts_packet_size;
u32 ts_packet_count;
u8 mux_input;
u8 encoder_profile;
u8 video_format;
u8 audio_format;
u8 video_resolution;
u16 ctl_brightness;
u16 ctl_contrast;
u16 ctl_hue;
u16 ctl_saturation;
u16 ctl_sharpness;
s8 ctl_volume;
tmComResAFeatureDescrHeader_t audfeat;
tmComResEncoderDescrHeader_t encunit;
tmComResProcDescrHeader_t vidproc;
tmComResExtDevDescrHeader_t ifunit;
tmComResTunerDescrHeader_t tunerunit;
/* V4L */
struct saa7164_encoder_params encoder_params;
struct video_device *v4l_device;
atomic_t v4l_reader_count;
// spinlock_t slock;
// struct mutex fops_lock;
struct saa7164_buffer list_buf_used;
struct saa7164_buffer list_buf_free;
wait_queue_head_t wait_read;
};
struct saa7164_dev {
......@@ -297,7 +390,7 @@ struct saa7164_dev {
struct saa7164_i2c i2c_bus[3];
/* Transport related */
struct saa7164_port ts1, ts2;
struct saa7164_port ports[ SAA7164_MAX_PORTS ];
/* Deferred command/api interrupts handling */
struct work_struct workcmd;
......@@ -355,6 +448,19 @@ int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
int saa7164_api_initialize_dif(struct saa7164_port *port);
int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
int saa7164_api_set_encoder(struct saa7164_port *port);
int saa7164_api_get_encoder(struct saa7164_port *port);
int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
int saa7164_api_set_videomux(struct saa7164_port *port);
int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
int saa7164_api_set_audio_std(struct saa7164_port *port);
int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
int saa7164_api_get_videomux(struct saa7164_port *port);
/* ----------------------------------------------------------- */
/* saa7164-cards.c */
......@@ -385,6 +491,15 @@ extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
extern void saa7164_buffer_display(struct saa7164_buffer *buf);
extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
struct saa7164_dev *dev, u32 len);
extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
/* ----------------------------------------------------------- */
/* saa7164-encoder.c */
int saa7164_encoder_register(struct saa7164_port *port);
void saa7164_encoder_unregister(struct saa7164_port *port);
/* ----------------------------------------------------------- */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册