📄 tvp5150.c
字号:
#include <linux/init.h>#include <linux/module.h>#include <linux/i2c.h>#include <linux/delay.h>#include <asm/io.h>#include <asm/arch/gio.h>#include <asm/arch/hardware.h>#if 0#define dbg(fmt, arg...) \ printk(KERN_INFO "\r%s:%d> " fmt, __func__, __LINE__ , ## arg)#else#define dbg(fmt...)#endif/** \addtogroup tvp5150 Video Decoder * \section tvp5150 TVP5150 NTSC Video Decoder * The TVP5150 is a NTSC Video Decoder that may be configured * to send a clock signal to the CCD controller, and various * forms of raw video data. *//* @{ *//* Begin structure/define definitions */#define MOD_DESC "Envision Technologes TI TVP5150 NTSC/PAL Video Decoder"/* End structure/define definitions *//* Begin Prototypes */static int tvp5150_attach_adapter(struct i2c_adapter * adapter);static int tvp5150_detach_client(struct i2c_client * client);/* End Prototypes *//* Begin variables declarations */static unsigned short normal_i2c[] = { 0x5C, 0x5D, I2C_CLIENT_END};static unsigned short normal_i2c_range[] = { I2C_CLIENT_END};I2C_CLIENT_INSMOD;static struct i2c_driver tvp5150_driver = { .owner = THIS_MODULE, .name = "TVP5150 v.$Revision: 1.10 $", .id = I2C_DRIVERID_TVP5150, .flags = I2C_DF_NOTIFY, .attach_adapter = &tvp5150_attach_adapter, .detach_client = &tvp5150_detach_client,};/* End variables declarations *//* Begin Private Functions */static int tvp5150_read(struct i2c_client * client, u8 reg){ return i2c_smbus_read_byte_data(client, reg);}//tvp5150_readstatic int tvp5150_write(struct i2c_client * client, u8 reg, u8 value){ return i2c_smbus_write_byte_data(client, reg, value);}//tvp5150_write/** Initialize the TVP5150 Video Decoder for NTSC 720x240 * * @param client The I2C client data containing the * I2C address. * @return 0 for successfull, otherwise less than 0. */static int tvp5150_init_registers(struct i2c_client * client){ return tvp5150_write(client, 0x03, 0x09); return 0;}//tvp5150_init_registersstatic int tvp5150_detect_client(struct i2c_adapter * adapter, int address, int kind){ int ret = 0; struct i2c_client * client = NULL; static int id = 1; printk("tvp5150 detach client\n");#if 1 // power up tvp5152 /* request GIO23, GIO_VIDIO_SUSPEND */ if(request_gio(GIO_VIDIO_SUSPEND)){ printk(KERN_ERR "Request of GIO:%d for GIO_SUSPEND failed.\n",GIO_VIDIO_SUSPEND); } gio_set_dir(GIO_VIDIO_SUSPEND, bit_low); //output gio_set_bitset(GIO_VIDIO_SUSPEND); /* 0=power down mode, 1=normal operation */#endif if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) goto out; if (!(client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { ret = -ENOMEM; goto out; }//if memset(client, 0, sizeof(struct i2c_client));// client -> id = id++; client -> addr = address; client -> adapter = adapter; client -> driver = &tvp5150_driver; client -> flags = I2C_M_IGNORE_NAK; strcpy(client -> name, "tvp5150 write only"); if ((ret = i2c_attach_client(client)) != 0) { dbg("Unable to attach client\n"); kfree(client); goto out; }//if dbg("Reading ID\n"); dbg("Register:Value 0x%02X:0x%02X\n", 0x80, tvp5150_read(client, 0x80)); tvp5150_init_registers(client); gio_set_bitclr(GIO_VIDIO_SUSPEND);//by li#if 0 gio_set_dir(GIO_VIDIO_SUSPEND , bit_low); //output gio_set_bitclr(GIO_VIDIO_SUSPEND);#endif out: return ret;}//tvp5150_detect_clientstatic int tvp5150_attach_adapter(struct i2c_adapter * adapter){ return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);}//tvp5150_attach_adapterstatic int tvp5150_detach_client(struct i2c_client * client){ int ret = 0; if ((ret = i2c_detach_client(client)) != 0) { dbg("Unable to detach client\n"); goto out; }//if unrequest_gio( GIO_VIDIO_SUSPEND ); kfree(client); out: return ret;}//tvp5150_detach_client/* End Private Functions */static int __init tvp5150_init(void){ printk(KERN_INFO "\t" MOD_DESC "\n"); return i2c_add_driver(&tvp5150_driver);}//tvp5150_initstatic void __exit tvp5150_exit(void){ i2c_del_driver(&tvp5150_driver);}//tvp5150_exit/* @} */MODULE_AUTHOR("Envision Technologies");MODULE_DESCRIPTION(MOD_DESC);MODULE_LICENSE("Envision Technologies");module_init(tvp5150_init);module_exit(tvp5150_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -