⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saa7104.c

📁 saa7106的芯片的驱动代码
💻 C
字号:
          /* extdrv/peripheral/vad/saa7104.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/hi_i2c.h>#include "saa7104.h"#define SC_PERCTRL1 IO_ADDRESS(0x101e0020)#define GPIO_1_BASE 0x101E5000#define GPIO_1_DIR IO_ADDRESS(GPIO_1_BASE + 0x400)#define GPIO_RST_REG IO_ADDRESS(GPIO_1_BASE + 0x08)#define HW_REG(reg) *((volatile unsigned int *)(reg))static void time_delay_us(unsigned int usec){	int i,j;		for(i=0;i<usec * 5;i++)	{		for(j=0;j<47;j++)		{;}	}}void saa7104_reset(void){	unsigned long value;	unsigned long tmpreg;	tmpreg = HW_REG(SC_PERCTRL1);	tmpreg &= 0xfffeffff;	printk(">>>>>>>tmpreg = %x \n", tmpreg);	HW_REG(SC_PERCTRL1) = tmpreg;         	value = HW_REG(GPIO_1_DIR);	value |= 0x02;	HW_REG(GPIO_1_DIR) = value;	HW_REG(GPIO_RST_REG) = 2;	time_delay_us(100000);	HW_REG(GPIO_RST_REG) = 0;	time_delay_us(100000);	HW_REG(GPIO_RST_REG) = 2;}static unsigned char saa7104_byte_write(unsigned char chip_addr, unsigned char addr, unsigned char data){	int iRet;    iRet = hi_i2c_write(chip_addr, addr,data);       if(iRet)	{		printk(">>>>>>>>>>>>>iic write error = %d\n", iRet);	}	return iRet;}static unsigned char saa7104_byte_read(unsigned char chip_addr,unsigned char addr){		int value;		value = hi_i2c_read(chip_addr, addr);	if(value < 0)	{		printk(">>>>>>>>>>>>>iic read error = %d\n", value);	}	    return value;  }static void saa7104_write_table(unsigned char chip_addr, subaddInfo_t *tbl_ptr, int cnt){    unsigned char i = 0;    for(i = 0; i<cnt; i++)    {        saa7104_byte_write(chip_addr, tbl_ptr[i].subAddr, tbl_ptr[i].value);    }}static void saa7104_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 = saa7104_byte_read(chip_addr, addr+i);		printk("reg 0x%x=0x%2x,",addr+i,temp);		if(((i+1)%4)==0)		printk("\n");			}}static int saa7104_device_video_init(unsigned char chip_addr,unsigned char video_mode){    unsigned char saa7104_id =0;    	saa7104_reset();	saa7104_id = saa7104_byte_read(chip_addr, SAA7104_ID);    	if(saa7104_id != 0x05)    {		printk(" saa7104_id =%x\n",saa7104_id);        return -1;    }	if(video_mode == PAL)	{		saa7104_write_table(chip_addr, (subaddInfo_t *)&saa7104_720x576x50p_TO_PAL, 141);	}	else	{		saa7104_write_table(chip_addr, (subaddInfo_t *)&saa7104_720x480x60p_TO_NTSC, 141);	}    return 0;}static void saa7104_reg_dump(unsigned char chip_addr){	saa7104_read_table(chip_addr, 0x0, 0xff);	printk("saa7104_reg_dump ok\n");}/* * saa7104 read routine. * do nothing. */ssize_t saa7104_read(struct file * file, char __user * buf, size_t count, loff_t * offset){    return 0;}/* * saa7104 write routine. * do nothing. */ssize_t saa7104_write(struct file * file, const char __user * buf, size_t count, loff_t * offset){    return 0;}/* * tw2834 open routine. * do nothing. */ int saa7104_open(struct inode * inode, struct file * file){    return 0;} /* * saa7104 close routine. * do nothing. */int saa7104_close(struct inode * inode, struct file * file){    return 0;}SAA7104Ret saa7104_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){	    unsigned int __user *argp = (unsigned int __user *)arg;		saa7104_reg saa7104reg;	int tmp;	switch(cmd)	{	case SAA7104_READ_REG:		if (copy_from_user(&saa7104reg, argp, sizeof(saa7104reg)))		{			return SAA7104_READ_REG_FAIL;		}				saa7104reg.value = saa7104_byte_read(SAA7104_I2C_ADDR, (u8)saa7104reg.addr);		copy_to_user(argp, &saa7104reg, sizeof(saa7104reg));		break;	case SAA7104_WRITE_REG:		if (copy_from_user(&saa7104reg, argp, sizeof(saa7104reg)))		{			return SAA7104_WRITE_REG_FAIL;		}		saa7104_byte_write(SAA7104_I2C_ADDR, (u8)saa7104reg.addr,(u8)saa7104reg.value);		break;	case SAA7104_REG_MODE:		if (copy_from_user(&tmp, argp, sizeof(tmp)))		{			return SAA7104_WRITE_REG_FAIL;		}		saa7104_device_video_init(SAA7104_I2C_ADDR, tmp);		break;	case SAA7104_REG_DUMP:		saa7104_reg_dump(SAA7104_I2C_ADDR);		break;	default:		break;	}	return 0;}/* *      The various file operations we support. */static struct file_operations saa7104_fops = {    .owner      = THIS_MODULE,    .read       = saa7104_read,    .write      = saa7104_write,    .ioctl      = saa7104_ioctl,    .open       = saa7104_open,    .release    = saa7104_close};static struct miscdevice saa7104_dev = {   .minor		= MISC_DYNAMIC_MINOR,   .name		= "saa7104dev",   .fops  = &saa7104_fops,};DECLARE_KCOM_HI_I2C();static int __init saa7104_init(void){    int ret = 0;    	ret = KCOM_HI_I2C_INIT();    /*register saa7104a_dev*/    ret = misc_register(&saa7104_dev);    printk("saa7104 driver init start ... \n");    if (ret)    {		KCOM_HI_I2C_EXIT();		printk("\tsaa7104_ERROR: could not register saa7104 devices. \n");        return -1;    }		if (saa7104_device_video_init(SAA7104_I2C_ADDR,PAL) < 0)    {        misc_deregister(&saa7104_dev);		KCOM_HI_I2C_EXIT();		printk("\tsaa7104_ERROR: saa7104 driver init fail for device init error!\n");        return -1;    }	    printk("saa7104 driver init successful!\n");	    return ret;}static void __exit saa7104_exit(void){    misc_deregister(&saa7104_dev);    KCOM_HI_I2C_EXIT();}module_init(saa7104_init);module_exit(saa7104_exit);#ifdef MODULE#include <linux/compile.h>#endifMODULE_INFO(build, UTS_VERSION);MODULE_LICENSE("GPL");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -