📄 tw2880.c
字号:
/* extdrv/peripheral/vad/tw2815a.c * * Copyright (c) 2006 Hisilicon Co., Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; * * History: * 10-April-2006 create this file * 2006-04-29 add record path half d1 mod * 2006-05-13 set the playpath default output mod to full * 2006-05-24 add record mod 2cif * 2006-06-15 support mod changing between every record mod * 2006-08-12 change the filters when record mod change */#include <linux/config.h>#include <linux/kernel.h>#include <linux/version.h>#include <linux/module.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/fcntl.h>#include <linux/mm.h>#include <linux/miscdevice.h>#include <linux/proc_fs.h>#include <linux/fs.h>#include <linux/slab.h>#include <linux/smp_lock.h>#include <linux/devfs_fs_kernel.h>#include <linux/init.h>#include <asm/uaccess.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/system.h>#include <linux/interrupt.h>#include <linux/ioport.h>#include <linux/string.h>#include <linux/list.h>#include <asm/semaphore.h>#include <asm/delay.h>#include <linux/timer.h>#include <linux/delay.h>#include <linux/proc_fs.h>#include <linux/poll.h>#include <asm/hardware.h>#include <asm/bitops.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <linux/moduleparam.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/kcom.h>#include <kcom/gpio_i2c.h>#include "tw2815_def.h"#include "tw2815.h"#define DEBUG_2815 1static unsigned int tw2815a_dev_open_cnt =0;static unsigned int tw2815b_dev_open_cnt =0;static unsigned int cascad_judge = 0;unsigned char channel_array[8] = {0x20,0x64,0xa8,0xec,0x31,0x75,0xb9,0xfd};unsigned char channel_array_default[8] = {0x10,0x32,0x54,0x76,0x98,0xba,0xdc,0xfe};unsigned char channel_array_our[8] = {0x10,0x32,0x98,0xba,0x54,0x76,0xdc,0xfe};unsigned char channel_array_4chn[8] = {0x10,0x54,0x98,0xdc,0x32,0x76,0xba,0xfe};static unsigned char tw2815_byte_write(unsigned char chip_addr,unsigned char addr,unsigned char data) { gpio_i2c_write(chip_addr,addr,data); return 0;}static unsigned char tw2815_byte_read(unsigned char chip_addr,unsigned char addr){ return gpio_i2c_read_tw2815(chip_addr,addr); }static void tw2815_write_table(unsigned char chip_addr,unsigned char addr,unsigned char *tbl_ptr,unsigned char tbl_cnt){ unsigned char i = 0; for(i = 0;i<tbl_cnt;i++) { gpio_i2c_write(chip_addr,(addr+i),*(tbl_ptr+i)); }}static void tw2815_read_table(unsigned char chip_addr,unsigned char addr,unsigned char reg_num){ unsigned char i = 0,temp = 0; for(i =0; i < reg_num;i++ ) { temp = tw2815_byte_read(chip_addr,addr+i); printk("reg 0x%x=0x%x,",addr+i,temp); if(((i+1)%4)==0) printk("\n"); }}static void set_2_d1(unsigned char chip_addr,unsigned char ch1,unsigned char ch2){ unsigned char temp=0; if(ch1 >3 || ch2 > 3) { printk("tw2815 video chunnel error\n"); return; } temp = tw2815_byte_read(chip_addr,0x4d); CLEAR_BIT(temp,0x33); SET_BIT(temp,0x88); tw2815_byte_write(chip_addr,0x4d,temp); temp = tw2815_byte_read(chip_addr,0x43); SET_BIT(temp,0x3); tw2815_byte_write(chip_addr,0x43,temp); temp = tw2815_byte_read(chip_addr,0x75); CLEAR_BIT(temp,0x1<<ch1); tw2815_byte_write(chip_addr,0x75,temp); //printk("file:%s,line:%d\r\n",__FILE__,__LINE__); temp = tw2815_byte_read(chip_addr,0x0d+ch1*0x10); SET_BIT(temp,0x04); tw2815_byte_write(chip_addr,(0x0d+ch1*0x10),temp); temp = tw2815_byte_read(chip_addr,0x0d+ch1*0x10); CLEAR_BIT(temp,0x03); SET_BIT(temp,ch2); tw2815_byte_write(chip_addr,(0x0d+ch1*0x10),temp); /* temp = tw2815_byte_read(chip_addr,0x0d+ch2*0x10); SET_BIT(temp,0x04); tw2815_byte_write(chip_addr,(0x0d+ch2*0x10),temp); temp = tw2815_byte_read(chip_addr,0x0d+ch2*0x10); CLEAR_BIT(temp,0x03); SET_BIT(temp,ch1); tw2815_byte_write(chip_addr,(0x0d+ch2*0x10),temp); */ return; }static void tw2815_video_mode_init(unsigned chip_addr,unsigned char video_mode,unsigned char ch){ unsigned char video_mode_ctrl = 0,temp = 0,mode_temp = 0; mode_temp = video_mode; //soft reset temp = tw2815_byte_read(chip_addr, ch*0x10+0x0d); SET_BIT(temp,0x08); tw2815_byte_write(chip_addr,ch*0x10+0x0d,temp); udelay(50); if(video_mode == AUTOMATICALLY) { video_mode_ctrl = tw2815_byte_read(chip_addr,ch*0x10+0x1); CLEAR_BIT(video_mode_ctrl,0x80); tw2815_byte_write(chip_addr,ch*0x10+0x01,video_mode_ctrl); // usleep(50);//delay for automatically mode_temp = (tw2815_byte_read(chip_addr,ch*0x10+0x0))>>5; if(mode_temp <= 3) { mode_temp = PAL; } else { mode_temp = NTSC; } } if(mode_temp == NTSC) { tw2815_write_table(chip_addr,0x00+0x10*ch,tbl_ntsc_tw2815_common,15); tw2815_write_table(chip_addr,0x40,tbl_ntsc_tw2815_sfr1,16); tw2815_write_table(chip_addr,0x50,tbl_ntsc_tw2815_sfr2,10); } else { tw2815_write_table(chip_addr,0x00+0x10*ch,tbl_pal_tw2815_common,15); tw2815_write_table(chip_addr,0x40,tbl_pal_tw2815_sfr1,16); tw2815_write_table(chip_addr,0x50,tbl_pal_tw2815_sfr2,10); } temp = tw2815_byte_read(chip_addr,0x43); SET_BIT(chip_addr,0x80); tw2815_byte_write(chip_addr,0x43,temp); printk("tw2815 channel=%d set videomode %d\n",ch,video_mode); }static int tw2815_device_video_init(unsigned char chip_addr,unsigned char video_mode){ unsigned char tw2815_id =0; unsigned int i; tw2815_id = tw2815_byte_read(chip_addr,TW2815_ID); if(tw2815_id != 0x20) { if(DEBUG_2815) printk(" tw2815_id =%x\n",tw2815_id); return -1; } tw2815_video_mode_init(chip_addr,video_mode,0); tw2815_video_mode_init(chip_addr,video_mode,1); tw2815_video_mode_init(chip_addr,video_mode,2); tw2815_video_mode_init(chip_addr,video_mode,3); for(i=0;i<4;i++) { tw2815_byte_write(chip_addr,i*0x10+0x0b,0x9a); } return 0;}static void tw2815_reg_dump(unsigned char chip_addr){ tw2815_read_table(chip_addr,0x0,0x76); printk("tw2815_reg_dump ok\n");}/*restart alloc channeldefault: 0right and left alloc: 1our:2*/static void channel_alloc(unsigned char chip_addr,unsigned char ch){ unsigned char i = 0; if(ch == 0) { for(i =0 ;i < 8;i++) { tw2815_byte_write(chip_addr,0x64+i,0); tw2815_byte_write(chip_addr,0x64+i,channel_array_default[i]); } } else if(ch == 1) { for(i =0 ;i < 8;i++) { tw2815_byte_write(chip_addr,0x64+i,0); tw2815_byte_write(chip_addr,0x64+i,channel_array[i]); } } else if(ch == 2) { for(i =0 ;i < 8;i++) { tw2815_byte_write(chip_addr,0x64+i,0); tw2815_byte_write(chip_addr,0x64+i,channel_array_our[i]); } } else if(ch == 3) { for(i = 0; i < 8; i++) { tw2815_byte_write(chip_addr,0x64+i,0); tw2815_byte_write(chip_addr,0x64+i,channel_array_4chn[i]); } }}/*init when tw2815a:chip_addr = 0x50 when tw2815b:chip_addr = 0x52*/static int tw2815_device_audio_init(unsigned char chip_addr){ unsigned char temp; tw2815_write_table(chip_addr,0x5a,tbl_tw2815_audio,28); channel_alloc(chip_addr,1);/*enable output*/ temp = tw2815_byte_read(chip_addr,0x43); SET_BIT(temp,0x80); tw2815_byte_write(chip_addr,0x43,temp); printk("tw2815 audio init ok\n"); return 0;}#if 0static void tw2815_vin_cropping(unsigned chip_addr,unsigned int path,unsigned int hdelay,unsigned int hactive,unsigned int vdelay,unsigned int vactive){ tw2815_byte_write(chip_addr,(0x02+path*0x10),(hdelay&0xff)); tw2815_byte_write(chip_addr,(0x06+path*0x10),((hdelay&0x300)>>8)); tw2815_byte_write(chip_addr,(0x03+path*0x10),(hdelay&0xff)); tw2815_byte_write(chip_addr,(0x06+path*0x10),((hdelay&0xc00)>>8)); tw2815_byte_write(chip_addr,(0x04+path*0x10),(hdelay&0xff)); tw2815_byte_write(chip_addr,(0x06+path*0x10),((hdelay&0x3000)>>8)); tw2815_byte_write(chip_addr,(0x05+path*0x10),(hdelay&0xff)); tw2815_byte_write(chip_addr,(0x06+path*0x10),((hdelay&0xc000)>>8)); printk("tw2815_vin_cropping ok\n");}#endifstatic void setd1(unsigned char chip_addr){ unsigned char t1 = 0,temp = 0;#if 0 temp = tw2815_byte_read(chip_addr,0x4d); CLEAR_BIT(temp,0x33); SET_BIT(temp,0x22); tw2815_byte_write(chip_addr,0x4d,temp);#endif temp = tw2815_byte_read(chip_addr,0x75); CLEAR_BIT(temp,0xff); tw2815_byte_write(chip_addr,0x75,temp); for(t1 = 0;t1 < 4;t1++) { temp = tw2815_byte_read(chip_addr,0x0d+t1*0x10); CLEAR_BIT(temp,0x04); tw2815_byte_write(chip_addr,(0x0d+t1*0x10),temp); } temp = tw2815_byte_read(chip_addr,0x43); CLEAR_BIT(temp,0x3); tw2815_byte_write(chip_addr,0x43,temp); printk("setd1 ok\n"); return;}static void set_4half_d1(unsigned char chip_addr,unsigned char ch){ unsigned char temp = 0; temp = tw2815_byte_read(chip_addr,0x4d); CLEAR_BIT(temp,0x33); SET_BIT(temp,0x88); tw2815_byte_write(chip_addr,0x4d,temp); temp = tw2815_byte_read(chip_addr,0x0d+ch*0x10); CLEAR_BIT(temp,0x7); tw2815_byte_write(chip_addr,0x0d+ch*0x10,temp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -