📄 at2042_inf-old.c
字号:
AT2042_DELAY(100000);
#ifdef VIDEO_ONLY
id_conf = RxID(GID_ENCODER, 0x00, 0x02, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = VIDEO_ONLY;
#endif
}
static void read_tx_reg (void)
{
volatile unsigned short id_conf;
//id_conf = RxID(GID_ENC_AUDIO, 0, 0x01, R_FLAG);
id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x01, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][read_tx_reg] 0x%x\n", id_conf);
#if 0 /*JMP 2005-01-10*/
/*RATE_CNT_ID*/
id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x04, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][RATE_CNT_ID] 0x%x\n", id_conf);AT2042_DELAY(100000);
/*QUALITY_ID*/
id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x05, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][QUALITY_ID] 0x%x\n", id_conf);AT2042_DELAY(100000);
/*CBR_RATE_ID*/
id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x06, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][CBR_RATE_ID] 0x%x\n", id_conf);AT2042_DELAY(100000);
/*ENC_OPT_ID*/
id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x11, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][ENC_OPT_ID] 0x%x\n", id_conf);AT2042_DELAY(100000);
/*RESOL_ID*/
id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x22, R_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
printk ("[kernel][RESOL_ID] 0x%x\n", id_conf);AT2042_DELAY(100000);
for (id_conf=0;id_conf<20;id_conf++) {AT2042_DELAY(100000);}
#endif
return ;
}
static int at2041_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
_SET_REG_STR_ set_reg_str={0,0,{0,0,0,0,0,0}};
volatile unsigned short ioctl_dat=0;
//printk("[at2041_inf]at2041_ioctl : 0x%x\n", cmd);
switch(cmd) {
//case READ_Tx_FIFO :
case AT2041_TX_FIFO_ADDR :
put_user(*tx_buf[txfifo_rd_cnt], (unsigned short *) arg);
/* txfifo ring buffer control */
if (!txfifo_ring_cnt && txfifo_rd_cnt <= txfifo_wr_cnt) {
txfifo_rd_cnt ++;
if (txfifo_rd_cnt == MAX_BUF_NUM) {
txfifo_ring_cnt --;
txfifo_rd_cnt = 0;
}
} else if (txfifo_ring_cnt) {
txfifo_rd_cnt ++;
}
break;
case SET_REG:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
//do_mw32(set_reg_str.addr, set_reg_str.value[0]);
do_mw32 ( (_SET_REG_STR_ ) set_reg_str);
break;
#if 0
//case WRITE_Rx_FIFO :
case AT2041_RX_FIFO_ADDR :
//get_user(ioctl_dat, (unsigned short *)arg);
//do_mw32(AT2041_RX_FIFO_ADDR, ioctl_dat);
printk ("AT2041_RX_FIFO_ADDR\n");
break;
//case WRITE_COMMAND_REG :
case AT2041_COMMAND_REG_ADDR :
//get_user(ioctl_dat, (unsigned short *)arg);
//do_mw32(AT2041_COMMAND_REG_ADDR, ioctl_dat);
printk ("AT2041_COMMAND_REG_ADDR\n");
break;
//case WRITE_CONTROL_REG :
case AT2041_CONTROL_REG_ADDR :
//get_user(ioctl_dat, (unsigned short *)arg);
//do_mw32(AT2041_CONTROL_REG_ADDR, ioctl_dat);
printk ("AT2041_CONTROL_REG_ADDR\n");
break;
//case READ_STATUS_REG :
#endif
case AT2041_STATUS_REG_ADDR :
ioctl_dat = *((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG));
printk ("AT2041_STATUS_REG_ADDR : 0x%x\n", ioctl_dat);
put_user(ioctl_dat, (unsigned short *) arg);
break;
case AT2041_TX_FIFO_ADDR_READ :
read_tx_reg();
#if 0 /*JMP 2005-01-10*/
copy_to_user( (unsigned short *)arg, (AT2042_CUR *)&at2042_cur, sizeof(AT2042_CUR));
#endif
break;
case AT2041_INIT :
//at2041_ioctl_init();
//pre_enc_config();
break;
case SET_CBR:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
set_cbr(set_reg_str.value[1]);
break;
case SET_QUALITY:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
set_quality(set_reg_str.value[1]);
break;
case SET_ENC_MODE:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
set_enc_mode(set_reg_str.value[1]);
break;
case SET_ENC_OPT:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
set_enc_opt(set_reg_str.value[1]);
break;
case SET_RES:
copy_from_user( (_SET_REG_STR_ *)&set_reg_str, (unsigned short *)arg , sizeof(_SET_REG_STR_));
set_res(set_reg_str.value[1], set_reg_str.value[2]);
break;
case AT2041_RX_FIFO_ADDR :
get_user(ioctl_dat, (unsigned short *)arg);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = ioctl_dat;
break;
default :
break;
}
return 0;
}
static ssize_t muxfifo_read(struct file *file, char *buffer,size_t length,loff_t * offset)
{
/* copy mux_buf to user space */
/* real transfer size is size_buf[mux_rd_cnt] * 256bit.
* third parameter of copy_to_user() is the 'byte' number to transfer
* so, it's calculated size_buf[mux_rd_cnt] * 32
*/
volatile unsigned int size;
down(&muxfifo_read_sem);
size = (*size_buf[mux_rd_cnt] << 5) + (enc_txmsg_size << 1);
//size =(((*size_buf[mux_wr_cnt] & 0xffff) << 4) + enc_txmsg_size)*2;
copy_to_user(buffer, mux_buf[mux_rd_cnt], size);
/* multiplex ring buffer control */
if (!mux_ring_cnt && mux_rd_cnt <= mux_wr_cnt) {
mux_rd_cnt ++;
if (mux_rd_cnt == MAX_BUF_NUM) {
mux_ring_cnt --;
mux_rd_cnt = 0;
}
}
else if (mux_ring_cnt) {
mux_rd_cnt ++;
if (mux_rd_cnt == MAX_BUF_NUM) {
mux_ring_cnt --;
mux_rd_cnt = 0;
}
}
if (mux_full) {
/* acknowledge for data ready message */
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO_ADDR)) = 0x8803;
mux_full = 0;
}
return 0;
}
static ssize_t demuxfifo_write(struct file *file,const char *buffer, size_t length, loff_t * offset)
{
down(&demuxfifo_write_sem);
//printk ("#");
copy_from_user(demux_buf[demux_wr_cnt], buffer, length);
demux_size_buf[demux_wr_cnt] = length;
/* de-multiplex ring buffer control */
if (!demux_ring_cnt) {
demux_wr_cnt ++;
if (demux_wr_cnt == MAX_BUF_NUM) {
demux_ring_cnt ++;
demux_wr_cnt = 0;
}
}
else if (demux_ring_cnt && (demux_wr_cnt < demux_rd_cnt)) {
demux_wr_cnt ++;
}
//printk ("down:%d %d %d\n", demux_ring_cnt, demux_wr_cnt, demux_rd_cnt);
return 0;
}
static int at2041_open(struct inode* inode, struct file* filp)
{
printk("the AT2041 Open!!!\n");
MOD_INC_USE_COUNT;
return 0;
}
static int at2041_release(struct inode* inode, struct file* filp)
{
printk("the AT2041 Release!!!\n");
MOD_DEC_USE_COUNT;
return 0;
}
/* the AT2041 file operations */
static struct file_operations at2041_fops = {
read: muxfifo_read,
write: demuxfifo_write,
ioctl: at2041_ioctl,
open: at2041_open,
release: at2041_release,
};
static void at2041_interrupt_handle(int irq, void *dev_id, struct pt_regs * regs)
{
volatile unsigned int tx_data=0;
volatile unsigned int data_size = 0;
volatile unsigned short temp;
#if 0
int tmp=0;
unsigned short temp;
unsigned char picture_type[]={'I', 'P', 'B'};
#endif
volatile unsigned short mux_data;
volatile unsigned short demux_data;
volatile unsigned short mux_swap;
volatile unsigned short demux_swap;
volatile unsigned short id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x01, R_FLAG);
#if 0 /*JMP 2005-01-10*/
/*RATE_CNT_ID*/
volatile unsigned short id_conf0 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x04, R_FLAG);
/*QUALITY_ID*/
volatile unsigned short id_conf1 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x05, R_FLAG);
/*CBR_RATE_ID*/
volatile unsigned short id_conf2 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x06, R_FLAG);
/*ENC_OPT_ID*/
volatile unsigned short id_conf3 = RxID(GID_ENC_VIDEO, 0x00, 0x11, R_FLAG);
/*RESOL_ID*/
volatile unsigned short id_conf4 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x22, R_FLAG);
#endif
/* data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
#if 0 /*JMP 2005-01-10*/
if (tx_data ==id_conf0) { /*RATE_CNT_ID*/
//0:VBR 1~2:CBR
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.RATE_CNT=tx_data;
printk ("## RATE_CNT_ID 0x%04x:%d ##\n" , id_conf0, tx_data);
}
else if (tx_data ==id_conf1) { /*QUALITY_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.QUALITY=tx_data;
printk ("## QUALITY_ID 0x%04x:%d ##\n" , id_conf1, tx_data);
}
else if (tx_data ==id_conf2) { /*CBR_RATE_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.BIT_RATE=tx_data;
printk ("## CBR_RATE_ID 0x%04x:%d ##\n" , id_conf2, tx_data);
}
else if (tx_data ==id_conf3) { /*ENC_OPT_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.ENC_OPT=tx_data;
printk ("## ENC_OPT_ID 0x%04x:%d ##\n" , id_conf3, tx_data);
}
else if (tx_data ==id_conf4) { /*RESOL_ID*/
tx_data =*((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
if (tx_data==2) at2042_cur.RESOL=0; /*CIF*/
else at2042_cur.RESOL=1; /*D1*/
printk ("## RESOL_ID 0x%04x:%d ##\n" , id_conf4, tx_data);
tx_data =*((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
#endif
if (tx_data ==id_conf) /*RESOLUTION*/
{
/* ID data read from Tx_FIFO of the AT2041 */
//tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* 1ST data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* 2ND data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
if (tx_data==576) {
PAL_NTSC=PAL;
printk ("## PAL INPUT VIDEO DETECTEDT : %d ##\n" , tx_data);
}
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -