1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 static int saa7146_i2c_msg_prepare(
const struct i2c_msg *
m,
int num,
__le32 *
op)
31 int mem = 0, op_count = 0;
34 for(i = 0; i < num; i++) {
40 mem = 1 + ((mem-1) / 3);
54 for(i = 0; i < num; i++) {
60 h1 = op_count/3; h2 = op_count%3;
66 for(j = 0; j < m[
i].
len; j++) {
68 h1 = op_count/3; h2 = op_count%3;
78 h1 = (op_count-1)/3; h2 = (op_count-1)%3;
92 static int saa7146_i2c_msg_cleanup(
const struct i2c_msg *m,
int num,
__le32 *op)
98 for(i = 0; i < num; i++) {
103 for(j = 0; j < m[
i].
len; j++) {
127 DEB_I2C(
"busy_state detected\n");
141 status = saa7146_i2c_status(dev);
145 DEB_I2C(
"error_state detected. status:0x%08x\n", status);
166 status = saa7146_i2c_status(dev);
168 DEB_I2C(
"fatal error. status:0x%08x\n", status);
180 u32 status = 0, mc2 = 0;
185 DEB_I2C(
"before: 0x%08x (status: 0x%08x), %d\n",
198 timeout =
HZ/100 + 1;
207 pr_warn(
"%s %s [irq]: timed out waiting for end of xfer\n",
208 dev->
name, __func__);
225 pr_warn(
"%s %s: timed out waiting for MC2\n",
226 dev->
name, __func__);
233 saa7146_i2c_status(dev);
235 status = saa7146_i2c_status(dev);
236 if ((status & 0x3) != 1)
242 pr_warn(
"%s %s [poll]: timed out waiting for end of xfer\n",
243 dev->
name, __func__);
246 if (++trial < 50 && short_delay)
257 SAA7146_I2C_BUSY)) ) {
260 0 == (status & SAA7146_I2C_BUSY) ) {
262 DEB_I2C(
"unexpected i2c status %04x\n", status);
265 DEB_I2C(
"error due to invalid start/stop condition\n");
268 DEB_I2C(
"error in data transmission\n");
271 DEB_I2C(
"error when receiving data\n");
274 DEB_I2C(
"error because arbitration lost\n");
279 DEB_I2C(
"error in address phase\n");
289 DEB_I2C(
"after: 0x%08x\n", *dword);
295 int i = 0,
count = 0;
304 DEB_I2C(
"msg:%d/%d\n", i+1, num);
308 count = saa7146_i2c_msg_prepare(msgs, num, buffer);
319 err = saa7146_i2c_reset(dev);
321 DEB_I2C(
"could not reset i2c-device\n");
326 for(i = 0; i <
count; i++) {
327 err = saa7146_i2c_writeout(dev, &buffer[i], short_delay);
341 DEB_I2C(
"error while sending message(s). starting again\n");
353 }
while (err != num && retries--);
360 if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) {
361 DEB_I2C(
"could not cleanup i2c-message\n");
367 DEB_I2C(
"transmission successful. (msg:%d)\n", err);
373 saa7146_i2c_reset(dev);
374 if( 0 != saa7146_i2c_writeout(dev, &zero, short_delay)) {
375 pr_info(
"revision 0 error. this should never happen\n");
386 struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
387 struct saa7146_dev *dev = to_saa7146_dev(v4l2_dev);
390 return saa7146_i2c_transfer(dev, msg, num, adapter->
retries);
399 .master_xfer = saa7146_i2c_xfer,
400 .functionality = saa7146_i2c_func,
405 DEB_EE(
"bitrate: 0x%08x\n", bitrate);
411 saa7146_i2c_reset(dev);
414 i2c_set_adapdata(i2c_adapter, &dev->
v4l2_dev);
415 i2c_adapter->
dev.parent = &dev->
pci->dev;
416 i2c_adapter->
algo = &saa7146_algo;