aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/saa7146_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/common/saa7146_i2c.c')
-rw-r--r--drivers/media/common/saa7146_i2c.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 35b01ec40a51..c11da4d09cd0 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -24,7 +24,7 @@ static inline u32 saa7146_i2c_status(struct saa7146_dev *dev)
24 sent through the saa7146. have a look at the specifications p. 122 ff 24 sent through the saa7146. have a look at the specifications p. 122 ff
25 to understand this. it returns the number of u32s to send, or -1 25 to understand this. it returns the number of u32s to send, or -1
26 in case of an error. */ 26 in case of an error. */
27static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op) 27static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, __le32 *op)
28{ 28{
29 int h1, h2; 29 int h1, h2;
30 int i, j, addr; 30 int i, j, addr;
@@ -47,7 +47,7 @@ static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op)
47 } 47 }
48 48
49 /* be careful: clear out the i2c-mem first */ 49 /* be careful: clear out the i2c-mem first */
50 memset(op,0,sizeof(u32)*mem); 50 memset(op,0,sizeof(__le32)*mem);
51 51
52 /* loop through all messages */ 52 /* loop through all messages */
53 for(i = 0; i < num; i++) { 53 for(i = 0; i < num; i++) {
@@ -57,16 +57,16 @@ static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op)
57 so we have to perform a translation */ 57 so we have to perform a translation */
58 addr = (m[i].addr*2) + ( (0 != (m[i].flags & I2C_M_RD)) ? 1 : 0); 58 addr = (m[i].addr*2) + ( (0 != (m[i].flags & I2C_M_RD)) ? 1 : 0);
59 h1 = op_count/3; h2 = op_count%3; 59 h1 = op_count/3; h2 = op_count%3;
60 op[h1] |= ( (u8)addr << ((3-h2)*8)); 60 op[h1] |= cpu_to_le32( (u8)addr << ((3-h2)*8));
61 op[h1] |= (SAA7146_I2C_START << ((3-h2)*2)); 61 op[h1] |= cpu_to_le32(SAA7146_I2C_START << ((3-h2)*2));
62 op_count++; 62 op_count++;
63 63
64 /* loop through all bytes of message i */ 64 /* loop through all bytes of message i */
65 for(j = 0; j < m[i].len; j++) { 65 for(j = 0; j < m[i].len; j++) {
66 /* insert the data bytes */ 66 /* insert the data bytes */
67 h1 = op_count/3; h2 = op_count%3; 67 h1 = op_count/3; h2 = op_count%3;
68 op[h1] |= ( (u32)((u8)m[i].buf[j]) << ((3-h2)*8)); 68 op[h1] |= cpu_to_le32( (u32)((u8)m[i].buf[j]) << ((3-h2)*8));
69 op[h1] |= ( SAA7146_I2C_CONT << ((3-h2)*2)); 69 op[h1] |= cpu_to_le32( SAA7146_I2C_CONT << ((3-h2)*2));
70 op_count++; 70 op_count++;
71 } 71 }
72 72
@@ -75,9 +75,9 @@ static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op)
75 /* have a look at the last byte inserted: 75 /* have a look at the last byte inserted:
76 if it was: ...CONT change it to ...STOP */ 76 if it was: ...CONT change it to ...STOP */
77 h1 = (op_count-1)/3; h2 = (op_count-1)%3; 77 h1 = (op_count-1)/3; h2 = (op_count-1)%3;
78 if ( SAA7146_I2C_CONT == (0x3 & (op[h1] >> ((3-h2)*2))) ) { 78 if ( SAA7146_I2C_CONT == (0x3 & (le32_to_cpu(op[h1]) >> ((3-h2)*2))) ) {
79 op[h1] &= ~(0x2 << ((3-h2)*2)); 79 op[h1] &= ~cpu_to_le32(0x2 << ((3-h2)*2));
80 op[h1] |= (SAA7146_I2C_STOP << ((3-h2)*2)); 80 op[h1] |= cpu_to_le32(SAA7146_I2C_STOP << ((3-h2)*2));
81 } 81 }
82 82
83 /* return the number of u32s to send */ 83 /* return the number of u32s to send */
@@ -88,7 +88,7 @@ static int saa7146_i2c_msg_prepare(const struct i2c_msg *m, int num, u32 *op)
88 which bytes were read through the adapter and write them back to the corresponding 88 which bytes were read through the adapter and write them back to the corresponding
89 i2c-message. but instead, we simply write back all bytes. 89 i2c-message. but instead, we simply write back all bytes.
90 fixme: this could be improved. */ 90 fixme: this could be improved. */
91static int saa7146_i2c_msg_cleanup(const struct i2c_msg *m, int num, u32 *op) 91static int saa7146_i2c_msg_cleanup(const struct i2c_msg *m, int num, __le32 *op)
92{ 92{
93 int i, j; 93 int i, j;
94 int op_count = 0; 94 int op_count = 0;
@@ -101,7 +101,7 @@ static int saa7146_i2c_msg_cleanup(const struct i2c_msg *m, int num, u32 *op)
101 /* loop throgh all bytes of message i */ 101 /* loop throgh all bytes of message i */
102 for(j = 0; j < m[i].len; j++) { 102 for(j = 0; j < m[i].len; j++) {
103 /* write back all bytes that could have been read */ 103 /* write back all bytes that could have been read */
104 m[i].buf[j] = (op[op_count/3] >> ((3-(op_count%3))*8)); 104 m[i].buf[j] = (le32_to_cpu(op[op_count/3]) >> ((3-(op_count%3))*8));
105 op_count++; 105 op_count++;
106 } 106 }
107 } 107 }
@@ -174,7 +174,7 @@ static int saa7146_i2c_reset(struct saa7146_dev *dev)
174/* this functions writes out the data-byte 'dword' to the i2c-device. 174/* this functions writes out the data-byte 'dword' to the i2c-device.
175 it returns 0 if ok, -1 if the transfer failed, -2 if the transfer 175 it returns 0 if ok, -1 if the transfer failed, -2 if the transfer
176 failed badly (e.g. address error) */ 176 failed badly (e.g. address error) */
177static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_delay) 177static int saa7146_i2c_writeout(struct saa7146_dev *dev, __le32 *dword, int short_delay)
178{ 178{
179 u32 status = 0, mc2 = 0; 179 u32 status = 0, mc2 = 0;
180 int trial = 0; 180 int trial = 0;
@@ -186,7 +186,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
186 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) { 186 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) {
187 187
188 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 188 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
189 saa7146_write(dev, I2C_TRANSFER, *dword); 189 saa7146_write(dev, I2C_TRANSFER, le32_to_cpu(*dword));
190 190
191 dev->i2c_op = 1; 191 dev->i2c_op = 1;
192 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17); 192 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17);
@@ -209,7 +209,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
209 status = saa7146_read(dev, I2C_STATUS); 209 status = saa7146_read(dev, I2C_STATUS);
210 } else { 210 } else {
211 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate); 211 saa7146_write(dev, I2C_STATUS, dev->i2c_bitrate);
212 saa7146_write(dev, I2C_TRANSFER, *dword); 212 saa7146_write(dev, I2C_TRANSFER, le32_to_cpu(*dword));
213 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 213 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
214 214
215 /* do not poll for i2c-status before upload is complete */ 215 /* do not poll for i2c-status before upload is complete */
@@ -282,7 +282,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
282 } 282 }
283 283
284 /* read back data, just in case we were reading ... */ 284 /* read back data, just in case we were reading ... */
285 *dword = saa7146_read(dev, I2C_TRANSFER); 285 *dword = cpu_to_le32(saa7146_read(dev, I2C_TRANSFER));
286 286
287 DEB_I2C(("after: 0x%08x\n",*dword)); 287 DEB_I2C(("after: 0x%08x\n",*dword));
288 return 0; 288 return 0;
@@ -291,7 +291,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
291static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries) 291static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries)
292{ 292{
293 int i = 0, count = 0; 293 int i = 0, count = 0;
294 u32* buffer = dev->d_i2c.cpu_addr; 294 __le32 *buffer = dev->d_i2c.cpu_addr;
295 int err = 0; 295 int err = 0;
296 int address_err = 0; 296 int address_err = 0;
297 int short_delay = 0; 297 int short_delay = 0;
@@ -376,7 +376,7 @@ out:
376 /* another bug in revision 0: the i2c-registers get uploaded randomly by other 376 /* another bug in revision 0: the i2c-registers get uploaded randomly by other
377 uploads, so we better clear them out before continueing */ 377 uploads, so we better clear them out before continueing */
378 if( 0 == dev->revision ) { 378 if( 0 == dev->revision ) {
379 u32 zero = 0; 379 __le32 zero = 0;
380 saa7146_i2c_reset(dev); 380 saa7146_i2c_reset(dev);
381 if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) { 381 if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) {
382 INFO(("revision 0 error. this should never happen.\n")); 382 INFO(("revision 0 error. this should never happen.\n"));