72 #define IVTV_REG_I2C_SETSCL_OFFSET 0x7000
73 #define IVTV_REG_I2C_SETSDA_OFFSET 0x7004
74 #define IVTV_REG_I2C_GETSCL_OFFSET 0x7008
75 #define IVTV_REG_I2C_GETSDA_OFFSET 0x700c
77 #define IVTV_CS53L32A_I2C_ADDR 0x11
78 #define IVTV_M52790_I2C_ADDR 0x48
79 #define IVTV_CX25840_I2C_ADDR 0x44
80 #define IVTV_SAA7115_I2C_ADDR 0x21
81 #define IVTV_SAA7127_I2C_ADDR 0x44
82 #define IVTV_SAA717x_I2C_ADDR 0x21
83 #define IVTV_MSP3400_I2C_ADDR 0x40
84 #define IVTV_HAUPPAUGE_I2C_ADDR 0x50
85 #define IVTV_WM8739_I2C_ADDR 0x1a
86 #define IVTV_WM8775_I2C_ADDR 0x1b
87 #define IVTV_TEA5767_I2C_ADDR 0x60
88 #define IVTV_UPD64031A_I2C_ADDR 0x12
89 #define IVTV_UPD64083_I2C_ADDR 0x5c
90 #define IVTV_VP27SMPX_I2C_ADDR 0x5b
91 #define IVTV_M52790_I2C_ADDR 0x48
92 #define IVTV_AVERMEDIA_IR_RX_I2C_ADDR 0x40
93 #define IVTV_HAUP_EXT_IR_RX_I2C_ADDR 0x1a
94 #define IVTV_HAUP_INT_IR_RX_I2C_ADDR 0x18
95 #define IVTV_Z8F0811_IR_TX_I2C_ADDR 0x70
96 #define IVTV_Z8F0811_IR_RX_I2C_ADDR 0x71
97 #define IVTV_ADAPTEC_IR_ADDR 0x6b
100 static const u8 hw_addrs[] = {
126 static const char *
const hw_devicenames[] = {
146 "ir_tx_z8f0811_haup",
147 "ir_rx_z8f0811_haup",
151 static int get_key_adaptec(
struct IR_i2c *
ir,
u32 *ir_key,
u32 *ir_raw)
153 unsigned char keybuf[4];
163 if (keybuf[2] == 0xff)
170 *ir_key = keybuf[3] | keybuf[2] << 8 | keybuf[1] << 16 |keybuf[0] << 24;
185 if (itv->
hw_flags & IVTV_HW_IR_TX_ANY)
204 init_data->
name =
"AVerMedia AVerTV card";
221 init_data->
get_key = get_key_adaptec;
230 info.platform_data = init_data;
252 const unsigned short addr_list[] = {
267 const char *type = hw_devicenames[
idx];
290 return ivtv_i2c_new_ir(itv, hw, type, hw_addrs[idx]);
299 adap, type, 0,
I2C_ADDRS(hw_addrs[idx]));
304 .addr = hw_addrs[
idx],
305 .platform_data = &
pdata,
310 &cx25840_info,
NULL);
313 adap, type, hw_addrs[idx],
NULL);
337 static void ivtv_setscl(
struct ivtv *itv,
int state)
345 static void ivtv_setsda(
struct ivtv *itv,
int state)
353 static int ivtv_getscl(
struct ivtv *itv)
359 static int ivtv_getsda(
struct ivtv *itv)
365 static void ivtv_scldelay(
struct ivtv *itv)
369 for (i = 0; i < 5; ++
i)
374 static int ivtv_waitscl(
struct ivtv *itv,
int val)
379 for (i = 0; i < 1000; ++
i) {
380 if (ivtv_getscl(itv) == val)
387 static int ivtv_waitsda(
struct ivtv *itv,
int val)
392 for (i = 0; i < 1000; ++
i) {
393 if (ivtv_getsda(itv) == val)
400 static int ivtv_ack(
struct ivtv *itv)
404 if (ivtv_getscl(itv) == 1) {
407 if (!ivtv_waitscl(itv, 0)) {
415 if (!ivtv_waitsda(itv, 0)) {
420 if (!ivtv_waitscl(itv, 0)) {
428 static int ivtv_sendbyte(
struct ivtv *itv,
unsigned char byte)
433 for (i = 0; i < 8; ++
i, byte<<=1) {
435 if (!ivtv_waitscl(itv, 0)) {
440 ivtv_setsda(itv, bit);
441 if (!ivtv_waitsda(itv, bit)) {
446 if (!ivtv_waitscl(itv, 1)) {
452 if (!ivtv_waitscl(itv, 0)) {
456 return ivtv_ack(itv);
461 static int ivtv_readbyte(
struct ivtv *itv,
unsigned char *byte,
int nack)
469 for (i = 0; i < 8; ++
i) {
473 if (!ivtv_waitscl(itv, 1)) {
477 *byte = ((*byte)<<1)|ivtv_getsda(itv);
481 ivtv_setsda(itv, nack);
493 static int ivtv_start(
struct ivtv *itv)
497 sda = ivtv_getsda(itv);
501 if (!ivtv_waitsda(itv, 1)) {
506 if (ivtv_getscl(itv) != 1) {
508 if (!ivtv_waitscl(itv, 1)) {
519 static int ivtv_stop(
struct ivtv *itv)
523 if (ivtv_getscl(itv) != 0) {
526 if (!ivtv_waitscl(itv, 0)) {
533 if (!ivtv_waitscl(itv, 1)) {
539 if (!ivtv_waitsda(itv, 1)) {
541 for (i = 0; i < 16; ++
i) {
548 ivtv_waitsda(itv, 1);
556 static int ivtv_write(
struct ivtv *itv,
unsigned char addr,
unsigned char *
data,
u32 len,
int do_stop)
561 for (retry = 0; ret != 0 && retry < 8; ++
retry) {
562 ret = ivtv_start(itv);
565 ret = ivtv_sendbyte(itv, addr<<1);
566 for (i = 0; ret == 0 && i < len; ++
i)
567 ret = ivtv_sendbyte(itv, data[i]);
569 if (ret != 0 || do_stop) {
579 static int ivtv_read(
struct ivtv *itv,
unsigned char addr,
unsigned char *data,
u32 len)
584 for (retry = 0; ret != 0 && retry < 8; ++
retry) {
585 ret = ivtv_start(itv);
587 ret = ivtv_sendbyte(itv, (addr << 1) | 1);
588 for (i = 0; ret == 0 && i < len; ++
i) {
589 ret = ivtv_readbyte(itv, &data[i], i == len - 1);
603 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
604 struct ivtv *itv = to_ivtv(v4l2_dev);
609 for (i = retval = 0; retval == 0 && i < num; i++) {
611 retval = ivtv_read(itv, msgs[i].addr, msgs[i].
buf, msgs[i].len);
616 retval = ivtv_write(itv, msgs[i].addr, msgs[i].
buf, msgs[i].len, stop);
620 return retval ? retval : num;
630 .master_xfer = ivtv_xfer,
631 .functionality = ivtv_functionality,
635 static struct i2c_adapter ivtv_i2c_adap_hw_template = {
636 .name =
"ivtv i2c driver",
642 static void ivtv_setscl_old(
void *data,
int state)
644 struct ivtv *itv = (
struct ivtv *)data;
656 static void ivtv_setsda_old(
void *data,
int state)
658 struct ivtv *itv = (
struct ivtv *)data;
670 static int ivtv_getscl_old(
void *data)
672 struct ivtv *itv = (
struct ivtv *)data;
677 static int ivtv_getsda_old(
void *data)
679 struct ivtv *itv = (
struct ivtv *)data;
685 static struct i2c_adapter ivtv_i2c_adap_template = {
686 .name =
"ivtv i2c driver",
692 #define IVTV_ALGO_BIT_TIMEOUT (2)
695 .setsda = ivtv_setsda_old,
696 .setscl = ivtv_setscl_old,
697 .getsda = ivtv_getsda_old,
698 .getscl = ivtv_getscl_old,
703 static struct i2c_client ivtv_i2c_client_template = {
704 .name =
"ivtv internal",
718 IVTV_ERR(
"Mismatched I2C hardware arrays\n");