3 #include <linux/module.h>
11 #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiBX000: "); printk(args); printk("\n"); } } while (0)
18 dprintk(
"could not acquire lock");
29 mst->
msg[0].flags = 0;
44 dprintk(
"could not acquire lock");
53 mst->
msg[0].flags = 0;
62 dprintk(
"i2c read error on %d", reg);
75 while (((status = dibx000_read_word(mst, mst->
base_reg + 2)) & 0x0100) == 0 && --i > 0)
83 if ((status & 0x0080) == 0)
98 dibx000_read_word(mst, mst->
base_reg + 2);
101 for (i = 0; i <
len; i += 2) {
105 dibx000_write_word(mst, mst->
base_reg, data);
107 da = (((
u8) (msg->
addr)) << 9) |
116 if (txlen == msg->
len)
119 if (txlen-len == 0 && stop)
122 dibx000_write_word(mst, mst->
base_reg+1, da);
124 if (dibx000_is_i2c_done(mst) != 0)
139 len = rxlen > 8 ? 8 :
rxlen;
140 da = (((
u8) (msg->
addr)) << 9) |
149 if (rxlen == msg->
len)
154 dibx000_write_word(mst, mst->
base_reg+1, da);
156 if (dibx000_is_i2c_done(mst) != 0)
162 da = dibx000_read_word(mst, mst->
base_reg);
163 *b++ = (da >> 8) & 0xff;
181 return dibx000_write_word(mst, mst->
base_reg + 3, (
u16)(60000 / speed));
195 dprintk(
"selecting interface: %d", intf);
197 return dibx000_write_word(mst, mst->
base_reg + 4, intf);
209 for (msg_index = 0; msg_index < num; msg_index++) {
211 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
215 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
224 static int dibx000_i2c_master_xfer_gpio34(
struct i2c_adapter *i2c_adap,
struct i2c_msg msg[],
int num)
231 for (msg_index = 0; msg_index < num; msg_index++) {
232 if (msg[msg_index].
flags & I2C_M_RD) {
233 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
237 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
246 static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
247 .master_xfer = dibx000_i2c_master_xfer_gpio12,
248 .functionality = dibx000_i2c_func,
251 static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
252 .master_xfer = dibx000_i2c_master_xfer_gpio34,
253 .functionality = dibx000_i2c_func,
270 tx[0] = (((mst->
base_reg + 1) >> 8) & 0xff);
271 tx[1] = ((mst->
base_reg + 1) & 0xff);
278 static int dibx000_i2c_gated_gpio67_xfer(
struct i2c_adapter *i2c_adap,
285 dprintk(
"%s: too much I2C message to be transmitted (%i).\
286 Maximum is 32", __func__, num);
293 dprintk(
"could not acquire lock");
311 mst->
msg[num + 1].len = 4;
320 static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
321 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
322 .functionality = dibx000_i2c_func,
325 static int dibx000_i2c_gated_tuner_xfer(
struct i2c_adapter *i2c_adap,
332 dprintk(
"%s: too much I2C message to be transmitted (%i).\
333 Maximum is 32", __func__, num);
340 dprintk(
"could not acquire lock");
357 mst->
msg[num + 1].len = 4;
366 .master_xfer = dibx000_i2c_gated_tuner_xfer,
367 .functionality = dibx000_i2c_func,
409 dibx000_i2c_gate_ctrl(mst, tx, 0, 0);
417 static int i2c_adapter_init(
struct i2c_adapter *i2c_adap,
422 i2c_adap->
algo = algo;
424 i2c_set_adapdata(i2c_adap, mst);
437 dprintk(
"could not acquire lock");
441 mst->
msg[0].addr = i2c_addr >> 1;
442 mst->
msg[0].flags = 0;
458 "DiBX000 tuner I2C bus", mst) != 0)
460 "DiBX000: could not initialize the tuner i2c_adapter\n");
465 "DiBX000 master GPIO12 I2C bus", mst) != 0)
467 "DiBX000: could not initialize the master i2c_adapter\n");
472 "DiBX000 master GPIO34 I2C bus", mst) != 0)
474 "DiBX000: could not initialize the master i2c_adapter\n");
479 "DiBX000 master GPIO67 I2C bus", mst) != 0)
481 "DiBX000: could not initialize the master i2c_adapter\n");
509 return (t.tv_sec * 10000) + (t.tv_nsec / 100000);