diff options
-rw-r--r-- | drivers/staging/tm6000/tm6000-i2c.c | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c index fa11173e0fad..a5323303c34a 100644 --- a/drivers/staging/tm6000/tm6000-i2c.c +++ b/drivers/staging/tm6000/tm6000-i2c.c | |||
@@ -44,6 +44,36 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | |||
44 | printk(KERN_DEBUG "%s at %s: " fmt, \ | 44 | printk(KERN_DEBUG "%s at %s: " fmt, \ |
45 | dev->name, __FUNCTION__ , ##args); } while (0) | 45 | dev->name, __FUNCTION__ , ##args); } while (0) |
46 | 46 | ||
47 | static int tm6000_i2c_send_regs(struct tm6000_core *dev, unsigned char addr, | ||
48 | __u8 reg, char *buf, int len) | ||
49 | { | ||
50 | return tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
51 | REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); | ||
52 | } | ||
53 | |||
54 | /* Generic read - doesn't work fine with 16bit registers */ | ||
55 | static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr, | ||
56 | __u8 reg, char *buf, int len) | ||
57 | { | ||
58 | int rc; | ||
59 | |||
60 | rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
61 | REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); | ||
62 | |||
63 | return rc; | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * read from a 16bit register | ||
68 | * for example xc2028, xc3028 or xc3028L | ||
69 | */ | ||
70 | static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr, | ||
71 | __u16 reg, char *buf, int len) | ||
72 | { | ||
73 | return tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
74 | REQ_14_SET_GET_I2C_WR2_RDN, addr, reg, buf, len); | ||
75 | } | ||
76 | |||
47 | static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, | 77 | static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, |
48 | struct i2c_msg msgs[], int num) | 78 | struct i2c_msg msgs[], int num) |
49 | { | 79 | { |
@@ -78,13 +108,16 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
78 | i2c_dprintk(2, "; joined to read %s len=%d:", | 108 | i2c_dprintk(2, "; joined to read %s len=%d:", |
79 | i == num - 2 ? "stop" : "nonstop", | 109 | i == num - 2 ? "stop" : "nonstop", |
80 | msgs[i + 1].len); | 110 | msgs[i + 1].len); |
81 | rc = tm6000_read_write_usb (dev, | 111 | |
82 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 112 | if (msgs[i].len == 2) { |
83 | msgs[i].len == 1 ? REQ_16_SET_GET_I2C_WR1_RDN | 113 | rc = tm6000_i2c_recv_regs16(dev, addr, |
84 | : REQ_14_SET_GET_I2C_WR2_RDN, | 114 | msgs[i].buf[0] << 8 | msgs[i].buf[1], |
85 | addr | msgs[i].buf[0] << 8, | 115 | msgs[i + 1].buf, msgs[i + 1].len); |
86 | msgs[i].len == 1 ? 0 : msgs[i].buf[1], | 116 | } else { |
87 | msgs[i + 1].buf, msgs[i + 1].len); | 117 | rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0], |
118 | msgs[i + 1].buf, msgs[i + 1].len); | ||
119 | } | ||
120 | |||
88 | i++; | 121 | i++; |
89 | 122 | ||
90 | if (addr == dev->tuner_addr << 1) { | 123 | if (addr == dev->tuner_addr << 1) { |
@@ -99,10 +132,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
99 | if (i2c_debug >= 2) | 132 | if (i2c_debug >= 2) |
100 | for (byte = 0; byte < msgs[i].len; byte++) | 133 | for (byte = 0; byte < msgs[i].len; byte++) |
101 | printk(" %02x", msgs[i].buf[byte]); | 134 | printk(" %02x", msgs[i].buf[byte]); |
102 | rc = tm6000_read_write_usb(dev, | 135 | rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0], |
103 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
104 | REQ_16_SET_GET_I2C_WR1_RDN, | ||
105 | addr | msgs[i].buf[0] << 8, 0, | ||
106 | msgs[i].buf + 1, msgs[i].len - 1); | 136 | msgs[i].buf + 1, msgs[i].len - 1); |
107 | 137 | ||
108 | if (addr == dev->tuner_addr << 1) { | 138 | if (addr == dev->tuner_addr << 1) { |
@@ -134,9 +164,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev, | |||
134 | bytes[16] = '\0'; | 164 | bytes[16] = '\0'; |
135 | for (i = 0; i < len; ) { | 165 | for (i = 0; i < len; ) { |
136 | *p = i; | 166 | *p = i; |
137 | rc = tm6000_read_write_usb (dev, | 167 | rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1); |
138 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
139 | REQ_16_SET_GET_I2C_WR1_RDN, 0xa0 | i<<8, 0, p, 1); | ||
140 | if (rc < 1) { | 168 | if (rc < 1) { |
141 | if (p == eedata) | 169 | if (p == eedata) |
142 | goto noeeprom; | 170 | goto noeeprom; |