📄 i2c_encoder.c
字号:
/* * Copyright (C) 2006 U-Camp Co,LTD. * Youngil.Kim <zeronine@ucamp.co.kr> * * Copyright (C) 2004 Samsung Electronics * SW.LEE <hitchcar@samsung.com> * * Copyright (C) 2000 Russell King : pcf8583.c * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Driver for SAA7121 video encoder * ChangeLog * 07.01.03 by lovejin * - 饭瘤胶磐 悸泼阑 困秦辑 #include <asm/arch/map.h> 眠啊窃 * - 2.6俊 绝绢柳 郡府刚飘甸捞 乐绢辑 struct i2c_client_address 俊辑 割啊瘤 * 郡府刚飘甸阑 林籍 贸府窃 * - 2.6 俊辑 struct i2c_client 狼 老何 郡府刚飘啊 绝绢廉辑 割 啊瘤 郡府刚飘甸阑 * 林籍 贸府窃. * * */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/i2c.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/init.h>#include <linux/delay.h>//#include <asm/arch/s3c2410.h>//#include <asm/arch/s3c2440.h> /* Helios 2.4 目澄侩 */#include <asm/arch/map.h> /* Helios 2.6 目澄侩 by lovejin*/#include "saa7121.h"//#define SW_DEBUG#include "bits.h"static struct i2c_driver saa7121_driver;#define I2C_ID 0x88//#define I2C_ID 0x8Cstatic unsigned short ignore[] = { I2C_CLIENT_END };static unsigned short normal_addr[] = { (I2C_ID>>1), I2C_CLIENT_END };static struct i2c_client_address_data addr_data = { normal_i2c: normal_addr,// normal_i2c_range: ignore, /* 2.6 目澄俊辑绰 绝绢咙 */ probe: ignore, // probe_range: ignore, /* 2.6 目澄俊辑绰 绝绢咙 */ ignore: ignore,// ignore_range: ignore, /* 2.6 目澄俊辑绰 绝绢咙 */ force: ignore,};unsigned char saa7121_i2c_read( struct i2c_adapter *adap, unsigned char subaddr){ int ret; unsigned char buf[1]; struct i2c_msg msg ={ I2C_ID >> 1, 0, 1, buf}; buf[0] = subaddr; msg.flags = I2C_M_RD; ret = i2c_transfer(adap, &msg, 1); printk("encoder reg read : val = 0x%x\n", buf[0]); return buf[0];}static intsaa7121_i2c_write(struct i2c_adapter *adap, unsigned char subaddr, unsigned short val){ unsigned char buf[2]; struct i2c_msg msg = { I2C_ID >> 1, 0, 2, buf}; printk("encoder reg write : reg = 0x%x, val = 0x%x\n", subaddr, val); buf[0]= subaddr; buf[1]= val & 0xff; return i2c_transfer(adap, &msg, 1);}static intsaa7121_attach(struct i2c_adapter *adap, int addr, unsigned short flags,int kind){ int ret = 0; struct i2c_client *c; printk("i2c attach: start\n"); c = kmalloc(sizeof(*c), GFP_KERNEL); if (!c) return -ENOMEM; printk("c->id = 0x%x\n", saa7121_driver.id); printk("c->addr = 0x%x\n", addr); strcpy(c->name, "SAA7121");// c->id = saa7121_driver.id; /* 2.6 俊辑绰 绝绢咙 by lovejin */ c->flags = I2C_CLIENT_ALLOW_USE; c->addr = addr; c->adapter = adap; c->driver = &saa7121_driver; //c->data = &data; /* 2.6俊辑绰 绝绢咙 by lovejin */ ret = i2c_attach_client(c); printk("saa7121_attach: end\n"); return ret;}static int saa7121_probe(struct i2c_adapter *adap){ int ret; int i; printk("encoder_probe(): start\n"); printk("-- start Video Encoder Register Setting!! --\n");#if 1 // real encoder setting printk("INIT7121LEN = %d\n", INIT7121LEN); for( i = 0; i < INIT7121LEN*2; i+=2 ) { ret = saa7121_i2c_write( adap, init7121ntsc[i], init7121ntsc[i+1] ); } //ret = saa7121_i2c_write( adap, 0x3a, 0x11 ); ret = saa7121_i2c_read( adap, 0x00 );#else // ID Check ret = saa7121_i2c_read( adap, 0x3a ); printk("check id 0x%08x\n", ret);#endif printk("--- End of Video Encoder Register Setting!! --\n"); // in 2.6 kernel // we have some errors when probing i2c driver. // so abort it. //printk("encoder_probe: start adap->name %s\n", adap->name); //ret = i2c_probe(adap, &addr_data, saa7121_attach); //printk("encoder_probe: end\n"); return ret;}static int saa7121_detach(struct i2c_client *client){ printk("saa7121_detach: start\n"); i2c_detach_client(client); return 0;}static intsaa7121_command(struct i2c_client *client, unsigned int cmd, void *arg){ printk("saa7121_command start\n"); switch (cmd) { default: panic("Unexpect SAA7121 Command \n"); break; } return 0;}static struct i2c_driver saa7121_driver = { name: "SAA7121", id: I2C_ALGO_S3C, flags: I2C_DF_NOTIFY, attach_adapter: saa7121_probe, detach_client: saa7121_detach, command: saa7121_command};static void iic_gpio_port(void) { rGPECON &= ~(0xf <<28); rGPECON |= 0xa <<28;}static __init int saa7121_init(void){ int ret; printk("saa7121_init start\n"); iic_gpio_port(); ret = i2c_add_driver(&saa7121_driver); printk("saa7121_init end\n"); return ret;}static __exit void saa7121_exit(void){ printk("saa7121_exit start\n"); i2c_del_driver(&saa7121_driver); printk("saa7121_exit end\n");}module_init(saa7121_init)module_exit(saa7121_exit)MODULE_AUTHOR("Youngil.Kim <zeronine@ucamp.co.kr>");MODULE_DESCRIPTION("I2C Client Driver For SAA7121 Driver");MODULE_LICENSE("GPL");/* * Local variables: * c-basic-offset: 8 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -