23 #include <linux/module.h>
24 #include <linux/kernel.h>
26 #include <linux/i2c.h>
41 #define i2c_dprintk(lvl, fmt, args...) if (i2c_debug >= lvl) do { \
42 printk(KERN_DEBUG "%s at %s: " fmt, \
43 dev->name, __func__, ##args); } while (0)
49 unsigned int i2c_packet_limit = 16;
52 i2c_packet_limit = 80;
57 if (len < 1 || len > i2c_packet_limit) {
58 printk(
KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
59 len, i2c_packet_limit);
66 addr | reg << 8, 0, buf, len);
83 unsigned int i2c_packet_limit = 16;
86 i2c_packet_limit = 64;
91 if (len < 1 || len > i2c_packet_limit) {
92 printk(
KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
93 len, i2c_packet_limit);
98 if ((dev->
caps.has_zl10353) && (dev->
demod_addr << 1 == addr) && (reg % 2 == 0)) {
122 static int tm6000_i2c_recv_regs16(
struct tm6000_core *dev,
unsigned char addr,
123 __u16 reg,
char *buf,
int len)
128 if (!buf || len != 2)
136 addr | (reg & 0xFF00), 0, &ureg, 1);
149 addr, reg, buf, len);
156 static int tm6000_i2c_xfer(
struct i2c_adapter *i2c_adap,
157 struct i2c_msg msgs[],
int num)
164 for (i = 0; i < num; i++) {
165 addr = (msgs[
i].
addr << 1) & 0xff;
168 i == num - 1 ?
"stop" :
"nonstop", addr, msgs[i].len);
180 }
else if (i + 1 < num && msgs[i].len <= 2 &&
181 (msgs[i + 1].
flags & I2C_M_RD) &&
182 msgs[i].addr == msgs[i + 1].addr) {
185 for (byte = 0; byte < msgs[
i].
len; byte++)
188 i == num - 2 ?
"stop" :
"nonstop",
191 if (msgs[i].len == 2) {
192 rc = tm6000_i2c_recv_regs16(dev, addr,
193 msgs[i].buf[0] << 8 | msgs[i].buf[1],
194 msgs[i + 1].buf, msgs[i + 1].len);
196 rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0],
197 msgs[i + 1].buf, msgs[i + 1].len);
207 for (byte = 0; byte < msgs[
i].
len; byte++)
212 for (byte = 0; byte < msgs[
i].
len; byte++)
214 rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0],
215 msgs[i].buf + 1, msgs[i].len - 1);
229 static int tm6000_i2c_eeprom(
struct tm6000_core *dev)
232 unsigned char *
p = dev->
eedata;
233 unsigned char bytes[17];
239 for (i = 0; i <
sizeof(dev->
eedata); ) {
241 rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1);
247 "%s: i2c eeprom read error (err=%d)\n",
271 for (i %= 16; i < 16; i++)
295 .master_xfer = tm6000_i2c_xfer,
321 tm6000_i2c_eeprom(dev);