aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/dibx000_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/frontends/dibx000_common.c')
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index 9bd95a978a1..f6938f97feb 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -26,8 +26,8 @@ static u16 dibx000_read_word(struct dibx000_i2c_master *mst, u16 reg)
26 u8 wb[2] = { reg >> 8, reg & 0xff }; 26 u8 wb[2] = { reg >> 8, reg & 0xff };
27 u8 rb[2]; 27 u8 rb[2];
28 struct i2c_msg msg[2] = { 28 struct i2c_msg msg[2] = {
29 {.addr = mst->i2c_addr,.flags = 0,.buf = wb,.len = 2}, 29 {.addr = mst->i2c_addr, .flags = 0, .buf = wb, .len = 2},
30 {.addr = mst->i2c_addr,.flags = I2C_M_RD,.buf = rb,.len = 2}, 30 {.addr = mst->i2c_addr, .flags = I2C_M_RD, .buf = rb, .len = 2},
31 }; 31 };
32 32
33 if (i2c_transfer(mst->i2c_adap, msg, 2) != 2) 33 if (i2c_transfer(mst->i2c_adap, msg, 2) != 2)
@@ -38,10 +38,11 @@ static u16 dibx000_read_word(struct dibx000_i2c_master *mst, u16 reg)
38 38
39static int dibx000_is_i2c_done(struct dibx000_i2c_master *mst) 39static int dibx000_is_i2c_done(struct dibx000_i2c_master *mst)
40{ 40{
41 int i = 100; // max_i2c_polls; 41 int i = 100;
42 u16 status; 42 u16 status;
43 43
44 while (((status = dibx000_read_word(mst, mst->base_reg + 2)) & 0x0100) == 0 && --i > 0); 44 while (((status = dibx000_read_word(mst, mst->base_reg + 2)) & 0x0100) == 0 && --i > 0)
45 ;
45 46
46 /* i2c timed out */ 47 /* i2c timed out */
47 if (i == 0) 48 if (i == 0)
@@ -63,7 +64,7 @@ static int dibx000_master_i2c_write(struct dibx000_i2c_master *mst, struct i2c_m
63 const u8 *b = msg->buf; 64 const u8 *b = msg->buf;
64 65
65 while (txlen) { 66 while (txlen) {
66 dibx000_read_word(mst, mst->base_reg + 2); // reset fifo ptr 67 dibx000_read_word(mst, mst->base_reg + 2);
67 68
68 len = txlen > 8 ? 8 : txlen; 69 len = txlen > 8 ? 8 : txlen;
69 for (i = 0; i < len; i += 2) { 70 for (i = 0; i < len; i += 2) {
@@ -72,14 +73,14 @@ static int dibx000_master_i2c_write(struct dibx000_i2c_master *mst, struct i2c_m
72 data |= *b++; 73 data |= *b++;
73 dibx000_write_word(mst, mst->base_reg, data); 74 dibx000_write_word(mst, mst->base_reg, data);
74 } 75 }
75 da = (((u8) (msg->addr)) << 9) | // addr 76 da = (((u8) (msg->addr)) << 9) |
76 (1 << 8) | // master 77 (1 << 8) |
77 (1 << 7) | // rq 78 (1 << 7) |
78 (0 << 6) | // stop 79 (0 << 6) |
79 (0 << 5) | // start 80 (0 << 5) |
80 ((len & 0x7) << 2) | // nb 8 bytes == 0 here 81 ((len & 0x7) << 2) |
81 (0 << 1) | // rw 82 (0 << 1) |
82 (0 << 0); // irqen 83 (0 << 0);
83 84
84 if (txlen == msg->len) 85 if (txlen == msg->len)
85 da |= 1 << 5; /* start */ 86 da |= 1 << 5; /* start */
@@ -105,14 +106,14 @@ static int dibx000_master_i2c_read(struct dibx000_i2c_master *mst, struct i2c_ms
105 106
106 while (rxlen) { 107 while (rxlen) {
107 len = rxlen > 8 ? 8 : rxlen; 108 len = rxlen > 8 ? 8 : rxlen;
108 da = (((u8) (msg->addr)) << 9) | // addr 109 da = (((u8) (msg->addr)) << 9) |
109 (1 << 8) | // master 110 (1 << 8) |
110 (1 << 7) | // rq 111 (1 << 7) |
111 (0 << 6) | // stop 112 (0 << 6) |
112 (0 << 5) | // start 113 (0 << 5) |
113 ((len & 0x7) << 2) | // nb 114 ((len & 0x7) << 2) |
114 (1 << 1) | // rw 115 (1 << 1) |
115 (0 << 0); // irqen 116 (0 << 0);
116 117
117 if (rxlen == msg->len) 118 if (rxlen == msg->len)
118 da |= 1 << 5; /* start */ 119 da |= 1 << 5; /* start */
@@ -174,15 +175,12 @@ static int dibx000_i2c_master_xfer_gpio12(struct i2c_adapter *i2c_adap, struct i
174 int ret = 0; 175 int ret = 0;
175 176
176 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_1_2); 177 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_1_2);
177 for (msg_index = 0; msg_index<num; msg_index++) { 178 for (msg_index = 0; msg_index < num; msg_index++) {
178 if (msg[msg_index].flags & I2C_M_RD) 179 if (msg[msg_index].flags & I2C_M_RD) {
179 {
180 ret = dibx000_master_i2c_read(mst, &msg[msg_index]); 180 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
181 if (ret != 0) 181 if (ret != 0)
182 return 0; 182 return 0;
183 } 183 } else {
184 else
185 {
186 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1); 184 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
187 if (ret != 0) 185 if (ret != 0)
188 return 0; 186 return 0;
@@ -199,15 +197,12 @@ static int dibx000_i2c_master_xfer_gpio34(struct i2c_adapter *i2c_adap, struct i
199 int ret = 0; 197 int ret = 0;
200 198
201 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_3_4); 199 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_3_4);
202 for (msg_index = 0; msg_index<num; msg_index++) { 200 for (msg_index = 0; msg_index < num; msg_index++) {
203 if (msg[msg_index].flags & I2C_M_RD) 201 if (msg[msg_index].flags & I2C_M_RD) {
204 {
205 ret = dibx000_master_i2c_read(mst, &msg[msg_index]); 202 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
206 if (ret != 0) 203 if (ret != 0)
207 return 0; 204 return 0;
208 } 205 } else {
209 else
210 {
211 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1); 206 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
212 if (ret != 0) 207 if (ret != 0)
213 return 0; 208 return 0;