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

📄 tvp5150.c

📁 嵌入式linux系统下hi3510平台的osd开发源码
💻 C
字号:
/* extdrv/peripheral/vad/tvp5150.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
 */

#include <linux/config.h>
#include <linux/kernel.h>

#include <linux/version.h>
#include <linux/module.h>
#include <linux/config.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 "hi_i2c.h"
#include "video_def.h"
#include "tvp5150.h"

/* tvp5150 i2c slaver address micro-definition. */
#define I2C_TVP5150     0xB8

/* tvp5150 ccir6xx working mode flag. */
static int ccirmode_flag = 0;


/*
 * tvp5150 initialise routine. 
 
 * @param devccir: tvp5150's working mode:0--VIDEO_MODE_CCIR656; 1--VIDEO_MODE_CCIR601
 * @return value:0--success; 1--error.  
 */
static int init_tvp5150(int devccir)
{	
	if(devccir > VIDEO_MODE_CCIR601)
        	goto err_out;

        if(devccir == VIDEO_MODE_CCIR656)
	{
		/* Set tvp5150 in ccir656 mode */
		if(hi_i2c_write(I2C_TVP5150, 0x0d, 0x47) != 0)
			return -1;
		/* Set tvp5150's data port active, but hsync and vsync not active, for ccir656 is not needed. */
		if(hi_i2c_write(I2C_TVP5150, 0x03, 0x69) != 0)
			return -1;
			
		return 0;
	}	
	else if(devccir == VIDEO_MODE_CCIR601)
	{		
		/* Set tvp5150 in ccir601 mode */
		if(hi_i2c_write(I2C_TVP5150, 0x0d, 0x40) != 0)
			return -1;
		
		/* Set tvp5150's data port active, but hsync and vsync not active, for ccir601 is needed. */
		if(hi_i2c_write(I2C_TVP5150, 0x03, 0x6f) != 0)
			return -1;
			
		return 0;			
	}
	else
		return -1;          
err_out:
	return -1;       
}


/*
 * tvp5150 open routine. 
 * do nothing.
 */
static int tvp5150_open(struct inode * inode, struct file * file)
{
	return 0;
}

/*
 * tvp5150 close routine. 
 * do nothing.
 */
static int tvp5150_close(struct inode * inode, struct file * file)
{	
	return 0;
}

/*
 * tvp5150 ioctl routine. 
 * @param inode: pointer of the node;
 * @param file: pointer of the file;
 *
 * @param cmd: command from the app:
 * TVP5150_SET_CCIRMODE(0):set tvp5150's work mode; 
 * TVP5150_GET_CCIRMODE(1):get tvp5150's work mode;
 * TVP5150_GET_NORM(2):get tvp5150's current norm, such as PAL or NTSC;
 *
 * @param arg:arg from app layer.
 */
static int tvp5150_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = -ENOIOCTLCMD;
	int norm_flag;
	
	switch(cmd)
	{
		/*set tvp5150's  mode: 0-ccir656;1-ccir601.*/
		case TVP5150_SET_CCIRMODE:
		{
			ret = get_user(ccirmode_flag, (int *)arg);
			
			if((ccirmode_flag == VIDEO_MODE_CCIR656)||(ccirmode_flag == VIDEO_MODE_CCIR601))
			{
				if(init_tvp5150(ccirmode_flag) != 0)
					ret = -EFAULT;			
			}
			else
				ret = -EINVAL;
		}
		break;
		
		/*get tvp5150's mode */
		case TVP5150_GET_CCIRMODE:
		{
			ret = copy_to_user((int *)arg, &ccirmode_flag,
				   sizeof(ccirmode_flag)) ? -EFAULT : 0;
		}
		break;

		case TVP5150_GET_NORM:
		{
			/* When here we get 0x83, means PAL cvbs signal is connected. */
			if((hi_i2c_read(I2C_TVP5150,0x8c)&0x03) == 0x03)
				norm_flag = VIDEO_NORM_PAL;
			/* When we get 0x81, means NTSC. */
			else if((hi_i2c_read(I2C_TVP5150,0x8c)&0x01) == 0x01)
				norm_flag = VIDEO_NORM_NTSC;
			else
			{
				printk("Unsupported video norm.\n");
				norm_flag = -EFAULT;
			}
			ret = copy_to_user((int *)arg, &norm_flag,
				   sizeof(norm_flag)) ? -EFAULT : 0;			
		}
		break;

		default:
			printk("Unrecongnised command.\n");
			ret =  -EINVAL;
		break;
	}
	
	return ret;
}


/*
 *      The various file operations we support.
 */
static struct file_operations tvp5150_fops = {
	.owner	= THIS_MODULE,
	.ioctl		= tvp5150_ioctl,
	.open	= tvp5150_open,
	.release	= tvp5150_close
};

static struct miscdevice tvp5150_dev = {
	MISC_DYNAMIC_MINOR,
	"tvp5150",
	&tvp5150_fops,
};

static int tvp5150_device_init(void)
{
	if(init_tvp5150(VIDEO_MODE_CCIR656) == 0)
		return 0;
	else
		return -1;
}
static int __init tvp5150_init(void)
{
	int ret = 0;

	ret = misc_register(&tvp5150_dev);
	if(ret)
	{
		printk("could not register tvp5150 devices. \n");
		return ret;
	}
	if(tvp5150_device_init()<0){
		misc_deregister(&tvp5150_dev);
		printk("tvp5150 driver init fail for device init error!\n");
		return -1;
	}

	printk("tvp5150 driver init successful!\n");
	return ret;
}

static void __exit tvp5150_exit(void)
{
	
	misc_deregister(&tvp5150_dev);

}
module_init(tvp5150_init);
module_exit(tvp5150_exit);

#ifdef MODULE
#include <linux/compile.h>
#endif

MODULE_INFO(build, UTS_VERSION);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("hisilicon");

⌨️ 快捷键说明

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