亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? bttv-i2c.c

?? 電視卡驅(qū)動源碼!適用于FI1256/FI1216ME等PHILIPS高頻頭
?? C
字號:
/*
    bttv-i2c.c  --  all the i2c code is here

    bttv - Bt848 frame grabber driver

    Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
                           & Marcus Metzler (mocm@thp.uni-koeln.de)
    (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>

    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; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
*/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>

#include "bttvp.h"

static struct i2c_algo_bit_data bttv_i2c_algo_bit_template;
static struct i2c_adapter bttv_i2c_adap_sw_template;
static struct i2c_adapter bttv_i2c_adap_hw_template;
static struct i2c_client bttv_i2c_client_template;

#ifndef I2C_PEC
static void bttv_inc_use(struct i2c_adapter *adap);
static void bttv_dec_use(struct i2c_adapter *adap);
#endif
static int attach_inform(struct i2c_client *client);

static int i2c_debug = 0;
static int i2c_hw = 0;
MODULE_PARM(i2c_debug,"i");
MODULE_PARM(i2c_hw,"i");

/* ----------------------------------------------------------------------- */
/* I2C functions - bitbanging adapter (software i2c)                       */

void bttv_bit_setscl(void *data, int state)
{
	struct bttv *btv = (struct bttv*)data;

	if (state)
		btv->i2c_state |= 0x02;
	else
		btv->i2c_state &= ~0x02;
	btwrite(btv->i2c_state, BT848_I2C);
	btread(BT848_I2C);
}

void bttv_bit_setsda(void *data, int state)
{
	struct bttv *btv = (struct bttv*)data;

	if (state)
		btv->i2c_state |= 0x01;
	else
		btv->i2c_state &= ~0x01;
	btwrite(btv->i2c_state, BT848_I2C);
	btread(BT848_I2C);
}

static int bttv_bit_getscl(void *data)
{
	struct bttv *btv = (struct bttv*)data;
	int state;
	
	state = btread(BT848_I2C) & 0x02 ? 1 : 0;
	return state;
}

static int bttv_bit_getsda(void *data)
{
	struct bttv *btv = (struct bttv*)data;
	int state;

	state = btread(BT848_I2C) & 0x01;
	return state;
}

static struct i2c_algo_bit_data bttv_i2c_algo_bit_template = {
	.setsda  = bttv_bit_setsda,
	.setscl  = bttv_bit_setscl,
	.getsda  = bttv_bit_getsda,
	.getscl  = bttv_bit_getscl,
	.udelay  = 16,
	.mdelay  = 10,
	.timeout = 200,
};

static struct i2c_adapter bttv_i2c_adap_sw_template = {
#ifdef I2C_PEC
	.owner             = THIS_MODULE,
#else
	.inc_use           = bttv_inc_use,
	.dec_use           = bttv_dec_use,
#endif
#ifdef I2C_ADAP_CLASS_TV_ANALOG
	.class             = I2C_ADAP_CLASS_TV_ANALOG,
#endif
	I2C_DEVNAME("bt848"),
	.id                = I2C_HW_B_BT848,
	.client_register   = attach_inform,
};

/* ----------------------------------------------------------------------- */
/* I2C functions - hardware i2c                                            */

static int algo_control(struct i2c_adapter *adapter, 
			unsigned int cmd, unsigned long arg)
{
	return 0;
}

static u32 functionality(struct i2c_adapter *adap)
{
	return I2C_FUNC_SMBUS_EMUL;
}

static int
bttv_i2c_wait_done(struct bttv *btv)
{
	DECLARE_WAITQUEUE(wait, current);
	int rc = 0;
	
	add_wait_queue(&btv->i2c_queue, &wait);
	set_current_state(TASK_INTERRUPTIBLE);
	if (0 == btv->i2c_done)
		schedule_timeout(HZ/50+1);
	set_current_state(TASK_RUNNING);
	remove_wait_queue(&btv->i2c_queue, &wait);

	if (0 == btv->i2c_done)
		/* timeout */
		rc = -EIO;
	if (btv->i2c_done & BT848_INT_RACK)
		rc = 1;
	btv->i2c_done = 0;
	return rc;
}

#define I2C_HW (BT878_I2C_MODE  | BT848_I2C_SYNC |\
		BT848_I2C_SCL | BT848_I2C_SDA)

static int
bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
{
	u32 xmit;
	int retval,cnt;

	/* start, address + first byte */
	xmit = (msg->addr << 25) | (msg->buf[0] << 16) | I2C_HW;
	if (msg->len > 1 || !last)
		xmit |= BT878_I2C_NOSTOP;
	btwrite(xmit, BT848_I2C);
	retval = bttv_i2c_wait_done(btv);
	if (retval < 0)
		goto err;
	if (retval == 0)
		goto eio;
	if (i2c_debug) {
		printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
		if (!(xmit & BT878_I2C_NOSTOP))
			printk(" >\n");
	}

	for (cnt = 1; cnt < msg->len; cnt++ ) {
		/* following bytes */
		xmit = (msg->buf[cnt] << 24) | I2C_HW | BT878_I2C_NOSTART;
		if (cnt < msg->len-1 || !last)
			xmit |= BT878_I2C_NOSTOP;
		btwrite(xmit, BT848_I2C);
		retval = bttv_i2c_wait_done(btv);
		if (retval < 0)
			goto err;
		if (retval == 0)
			goto eio;
		if (i2c_debug) {
			printk(" %02x", msg->buf[cnt]);
			if (!(xmit & BT878_I2C_NOSTOP))
				printk(" >\n");
		}
	}
	return msg->len;

 eio:
	retval = -EIO;
 err:
	if (i2c_debug)
		printk(" ERR: %d\n",retval);
	return retval;
}

static int
bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
{
	u32 xmit;
	u32 cnt;
	int retval;

	for(cnt = 0; cnt < msg->len; cnt++) {
		xmit = (msg->addr << 25) | (1 << 24) | I2C_HW;
		if (cnt < msg->len-1)
			xmit |= BT848_I2C_W3B;
		if (cnt < msg->len-1 || !last)
			xmit |= BT878_I2C_NOSTOP;
		if (cnt)
			xmit |= BT878_I2C_NOSTART;
		btwrite(xmit, BT848_I2C);
		retval = bttv_i2c_wait_done(btv);
		if (retval < 0)
			goto err;
		if (retval == 0)
			goto eio;
		msg->buf[cnt] = ((u32)btread(BT848_I2C) >> 8) & 0xff;
		if (i2c_debug) {
			if (!(xmit & BT878_I2C_NOSTART))
				printk(" <R %02x", (msg->addr << 1) +1);
			printk(" =%02x", msg->buf[cnt]);
			if (!(xmit & BT878_I2C_NOSTOP))
				printk(" >\n");
		}
	}
	return msg->len;

 eio:
	retval = -EIO;
 err:
	if (i2c_debug)
		printk(" ERR: %d\n",retval);
       	return retval;
}

int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
{
	struct bttv *btv = i2c_get_adapdata(i2c_adap);
	int retval = 0;
	int i;

	if (i2c_debug)
		printk("bt-i2c:");
	btwrite(BT848_INT_I2CDONE|BT848_INT_RACK, BT848_INT_STAT);
	for (i = 0 ; i < num; i++) {
		if (msgs[i].flags & I2C_M_RD) {
			/* read */
			retval = bttv_i2c_readbytes(btv, &msgs[i], i+1 == num);
			if (retval < 0)
				goto err;
		} else {
			/* write */
			retval = bttv_i2c_sendbytes(btv, &msgs[i], i+1 == num);
			if (retval < 0)
				goto err;
		}
	}
	return num;

 err:
	return retval;
}

static struct i2c_algorithm bttv_algo = {
	.name          = "bt878",
	.id            = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */,
	.master_xfer   = bttv_i2c_xfer,
	.algo_control  = algo_control,
	.functionality = functionality,
};

static struct i2c_adapter bttv_i2c_adap_hw_template = {
#ifdef I2C_PEC
	.owner         = THIS_MODULE,
#else
	.inc_use       = bttv_inc_use,
	.dec_use       = bttv_dec_use,
#endif
#ifdef I2C_ADAP_CLASS_TV_ANALOG
	.class         = I2C_ADAP_CLASS_TV_ANALOG,
#endif
	I2C_DEVNAME("bt878"),
	.id            = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */,
	.algo          = &bttv_algo,
	.client_register = attach_inform,
};

/* ----------------------------------------------------------------------- */
/* I2C functions - common stuff                                            */

#ifndef I2C_PEC
static void bttv_inc_use(struct i2c_adapter *adap)
{
	MOD_INC_USE_COUNT;
}

static void bttv_dec_use(struct i2c_adapter *adap)
{
	MOD_DEC_USE_COUNT;
}
#endif

static int attach_inform(struct i2c_client *client)
{
        struct bttv *btv = i2c_get_adapdata(client->adapter);

	if (btv->tuner_type != UNSET)
		bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type);
	if (btv->pinnacle_id != UNSET)
		bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE,
				      &btv->pinnacle_id);

        if (bttv_debug)
		printk("bttv%d: i2c attach [client=%s]\n",
		       btv->c.nr, i2c_clientname(client));
        return 0;
}

void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
{
	if (0 != btv->i2c_rc)
		return;
	i2c_clients_command(&btv->c.i2c_adap, cmd, arg);
}

void bttv_i2c_call(unsigned int card, unsigned int cmd, void *arg)
{
	if (card >= bttv_num)
		return;
	bttv_call_i2c_clients(&bttvs[card], cmd, arg);
}

static struct i2c_client bttv_i2c_client_template = {
	I2C_DEVNAME("bttv internal"),
        .id       = -1,
};


/* read I2C */
int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for) 
{
        unsigned char buffer = 0;

	if (0 != btv->i2c_rc)
		return -1;
	if (bttv_verbose && NULL != probe_for)
		printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
		       btv->c.nr,probe_for,addr);
        btv->i2c_client.addr = addr >> 1;
        if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
		if (NULL != probe_for) {
			if (bttv_verbose)
				printk("not found\n");
		} else
			printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
			       btv->c.nr,addr);
                return -1;
	}
	if (bttv_verbose && NULL != probe_for)
		printk("found\n");
        return buffer;
}

/* write I2C */
int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
                    unsigned char b2, int both)
{
        unsigned char buffer[2];
        int bytes = both ? 2 : 1;

	if (0 != btv->i2c_rc)
		return -1;
        btv->i2c_client.addr = addr >> 1;
        buffer[0] = b1;
        buffer[1] = b2;
        if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
		return -1;
        return 0;
}

/* read EEPROM content */
void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
{
	int i;
        
	if (bttv_I2CWrite(btv, addr, 0, -1, 0)<0) {
		printk(KERN_WARNING "bttv: readee error\n");
		return;
	}
	btv->i2c_client.addr = addr >> 1;
	for (i=0; i<256; i+=16) {
		if (16 != i2c_master_recv(&btv->i2c_client,eedata+i,16)) {
			printk(KERN_WARNING "bttv: readee error\n");
			break;
		}
	}
}

/* init + register i2c algo-bit adapter */
int __devinit init_bttv_i2c(struct bttv *btv)
{
	int use_hw = (btv->id == 878) && i2c_hw;

	memcpy(&btv->i2c_client, &bttv_i2c_client_template,
	       sizeof(bttv_i2c_client_template));

	if (use_hw) {
		/* bt878 */
		memcpy(&btv->c.i2c_adap, &bttv_i2c_adap_hw_template,
		       sizeof(bttv_i2c_adap_hw_template));
	} else {
		/* bt848 */
		memcpy(&btv->c.i2c_adap, &bttv_i2c_adap_sw_template,
		       sizeof(bttv_i2c_adap_sw_template));
		memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
		       sizeof(bttv_i2c_algo_bit_template));
		btv->i2c_algo.data = btv;
		btv->c.i2c_adap.algo_data = &btv->i2c_algo;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,66)
	btv->c.i2c_adap.dev.parent = &btv->c.pci->dev;
#endif
	snprintf(btv->c.i2c_adap.name, sizeof(btv->c.i2c_adap.name),
		 "bt%d #%d [%s]", btv->id, btv->c.nr, use_hw ? "hw" : "sw");

        i2c_set_adapdata(&btv->c.i2c_adap, btv);
        btv->i2c_client.adapter = &btv->c.i2c_adap;

	if (use_hw) {
		btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap);
	} else {
		bttv_bit_setscl(btv,1);
		bttv_bit_setsda(btv,1);
		btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap);
	}
	return btv->i2c_rc;
}

int __devexit fini_bttv_i2c(struct bttv *btv)
{
	int use_hw = (btv->id == 878) && i2c_hw;

	if (0 != btv->i2c_rc)
		return 0;

	if (use_hw) {
		return i2c_del_adapter(&btv->c.i2c_adap);
	} else {
		return i2c_bit_del_bus(&btv->c.i2c_adap);
	}
}

/*
 * Local variables:
 * c-basic-offset: 8
 * End:
 */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品欧美综合在线观看最新| 国产亲近乱来精品视频| 成人免费一区二区三区在线观看| 韩国三级中文字幕hd久久精品| 日韩一区二区三区视频在线| 美国欧美日韩国产在线播放| 日韩三级电影网址| 国产一区日韩二区欧美三区| 国产清纯白嫩初高生在线观看91| 不卡av在线免费观看| 亚洲日本电影在线| 欧美日韩一二三| 日本最新不卡在线| 26uuu国产一区二区三区 | 激情文学综合丁香| 国产精品丝袜在线| 91丨porny丨首页| 视频在线观看国产精品| 久久综合成人精品亚洲另类欧美| 国产毛片精品国产一区二区三区| 亚洲欧洲日产国产综合网| 在线中文字幕一区| 免费久久精品视频| 国产精品污网站| 在线观看一区二区精品视频| 免费日韩伦理电影| 国产精品电影一区二区| 在线播放国产精品二区一二区四区| 另类小说图片综合网| 国产精品色哟哟网站| 欧美自拍丝袜亚洲| 国内久久婷婷综合| 亚洲愉拍自拍另类高清精品| 欧美精品一区二区三区很污很色的| 成人免费视频视频| 日本午夜一本久久久综合| 国产精品久久久久久久久免费桃花 | 青娱乐精品在线视频| 久久综合五月天婷婷伊人| 91在线观看免费视频| 看国产成人h片视频| 亚洲欧美一区二区三区国产精品| 日韩女优毛片在线| 99精品欧美一区二区三区小说| 毛片一区二区三区| 亚洲一区在线观看免费 | 最新热久久免费视频| 欧美一区二区啪啪| 色呦呦国产精品| 国产成人日日夜夜| 看国产成人h片视频| 亚洲一区二区三区四区在线| 久久久亚洲欧洲日产国码αv| 欧美日韩国产另类一区| gogogo免费视频观看亚洲一| 久久av资源网| 首页国产丝袜综合| 午夜欧美在线一二页| 日韩美女视频一区二区 | 精品国产免费久久| 欧美日韩你懂得| 91在线播放网址| 成人黄色小视频在线观看| 久久精品国产精品亚洲精品| 亚洲国产aⅴ成人精品无吗| 中文字幕一区在线观看视频| 国产亚洲一区二区三区| 日韩午夜激情免费电影| 欧美精品一卡两卡| 欧美日本高清视频在线观看| 91极品视觉盛宴| 色老综合老女人久久久| 色综合中文字幕国产 | 欧美三级欧美一级| 欧美在线看片a免费观看| 99久精品国产| 99久久er热在这里只有精品15| 成人国产亚洲欧美成人综合网| 国产综合色视频| 国产精品99久| 成人免费视频视频在线观看免费| 成人午夜激情片| 成人福利视频网站| 91蜜桃网址入口| 在线日韩国产精品| 欧美三级电影网| 日韩午夜激情视频| 久久日一线二线三线suv| 久久久久久久综合| 国产精品毛片无遮挡高清| 国产精品久久久一本精品| 亚洲欧洲av在线| 亚洲裸体xxx| 亚洲超碰97人人做人人爱| 午夜一区二区三区视频| 日韩av一区二区三区| 麻豆免费精品视频| 国产麻豆一精品一av一免费| 国产v综合v亚洲欧| 在线免费观看日本一区| 欧美日韩高清一区| 日韩久久久久久| 国产精品视频观看| 亚洲国产欧美日韩另类综合| 视频在线在亚洲| 国产成人在线免费观看| 91日韩一区二区三区| 欧美午夜宅男影院| 日韩精品专区在线影院重磅| 欧美激情在线免费观看| 亚洲美女电影在线| 麻豆成人在线观看| 成人国产精品免费网站| 欧美色男人天堂| 久久久一区二区三区捆绑**| 亚洲欧美国产高清| 日本最新不卡在线| 99在线视频精品| 91精品国产福利| 国产欧美综合色| 亚洲大型综合色站| 国产成人免费视频一区| 欧美日韩日日骚| 国产精品看片你懂得| 亚洲成人av福利| 成人激情视频网站| 日韩欧美亚洲一区二区| 中文字幕亚洲区| 激情综合一区二区三区| 色偷偷成人一区二区三区91 | 国产欧美日韩精品一区| 亚洲一区二区欧美日韩| 国产成人精品亚洲日本在线桃色 | 欧美三级电影精品| 欧美高清在线视频| 日韩精品一二三区| 色偷偷久久一区二区三区| 久久久久久免费网| 免费在线欧美视频| 麻豆久久久久久| 欧美日韩1234| 亚洲自拍偷拍综合| 国产99久久精品| 日韩美女视频在线| 日韩和的一区二区| 在线免费观看成人短视频| 国产免费久久精品| 韩国毛片一区二区三区| 欧美人妇做爰xxxⅹ性高电影| 日韩一区在线免费观看| 国产一区二区三区久久悠悠色av| 亚洲精品视频一区二区| 亚洲日本va午夜在线电影| 国产精一区二区三区| 欧美电影精品一区二区| 日韩激情av在线| 欧美日韩中字一区| 亚洲免费观看高清完整版在线| 成人深夜在线观看| 国产精品免费看片| 国产在线精品一区在线观看麻豆| 欧美精品在线一区二区三区| 亚洲国产欧美在线| 欧美视频完全免费看| 亚洲一区在线视频| 欧美性生活久久| 亚洲在线视频一区| 在线观看亚洲a| 亚洲一区二区视频| 欧美视频在线观看一区二区| 一区二区三区成人| 91论坛在线播放| 亚洲人妖av一区二区| 91香蕉视频污在线| 亚洲乱码国产乱码精品精小说| 不卡视频一二三| 亚洲人妖av一区二区| 在线观看亚洲成人| 天堂av在线一区| 日韩精品一区二区三区老鸭窝| 免费三级欧美电影| 国产亚洲美州欧州综合国| 国产成人精品1024| 国产精品国产三级国产aⅴ中文| 99久久婷婷国产精品综合| 一区二区久久久| 欧美精品久久99久久在免费线 | k8久久久一区二区三区| 亚洲啪啪综合av一区二区三区| 欧美午夜不卡视频| 玖玖九九国产精品| 国产日韩欧美高清| 色综合一区二区| 美腿丝袜亚洲综合| 国产精品人成在线观看免费| 91啦中文在线观看| 日本午夜精品一区二区三区电影| 国产日韩欧美高清| 欧美午夜精品免费| 国产一区二区三区免费观看|