diff options
author | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-12-28 06:23:30 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-01-12 08:56:40 -0500 |
commit | 50f0a9df275b81096fbc0878c6deb5d99311549e (patch) | |
tree | 74e85d89fd5add01aa95eb2fbe9f05962d296ace | |
parent | e63b009d6e772e3fe6df39345ca2f8949d4497e6 (diff) |
[media] em28xx-i2c: cleanup I2C debug messages
The I2C output messages is too polluted. Clean it a little
bit, by:
- use the proper core support for memory dumps;
- hide most stuff under the i2c_debug umbrella;
- add the missing KERN_CONT where needed;
- use 2 levels or verbosity. Only the second one
will show the I2C transfer data.
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-i2c.c | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c index 76f956635bd9..e8eb83160d36 100644 --- a/drivers/media/usb/em28xx/em28xx-i2c.c +++ b/drivers/media/usb/em28xx/em28xx-i2c.c | |||
@@ -41,7 +41,7 @@ MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); | |||
41 | 41 | ||
42 | static unsigned int i2c_debug; | 42 | static unsigned int i2c_debug; |
43 | module_param(i2c_debug, int, 0644); | 43 | module_param(i2c_debug, int, 0644); |
44 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | 44 | MODULE_PARM_DESC(i2c_debug, "i2c debug message level (1: normal debug, 2: show I2C transfers)"); |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * em2800_i2c_send_bytes() | 47 | * em2800_i2c_send_bytes() |
@@ -89,7 +89,8 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | |||
89 | } | 89 | } |
90 | msleep(5); | 90 | msleep(5); |
91 | } | 91 | } |
92 | em28xx_warn("write to i2c device at 0x%x timed out\n", addr); | 92 | if (i2c_debug) |
93 | em28xx_warn("write to i2c device at 0x%x timed out\n", addr); | ||
93 | return -ETIMEDOUT; | 94 | return -ETIMEDOUT; |
94 | } | 95 | } |
95 | 96 | ||
@@ -132,8 +133,11 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | |||
132 | } | 133 | } |
133 | msleep(5); | 134 | msleep(5); |
134 | } | 135 | } |
135 | if (ret != 0x84 + len - 1) | 136 | if (ret != 0x84 + len - 1) { |
136 | em28xx_warn("read from i2c device at 0x%x timed out\n", addr); | 137 | if (i2c_debug) |
138 | em28xx_warn("read from i2c device at 0x%x timed out\n", | ||
139 | addr); | ||
140 | } | ||
137 | 141 | ||
138 | /* get the received message */ | 142 | /* get the received message */ |
139 | ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len); | 143 | ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len); |
@@ -213,7 +217,9 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf, | |||
213 | * (even with high payload) ... | 217 | * (even with high payload) ... |
214 | */ | 218 | */ |
215 | } | 219 | } |
216 | em28xx_warn("write to i2c device at 0x%x timed out (status=%i)\n", addr, ret); | 220 | if (i2c_debug) |
221 | em28xx_warn("write to i2c device at 0x%x timed out (status=%i)\n", | ||
222 | addr, ret); | ||
217 | return -ETIMEDOUT; | 223 | return -ETIMEDOUT; |
218 | } | 224 | } |
219 | 225 | ||
@@ -409,10 +415,6 @@ static inline int i2c_check_for_device(struct em28xx_i2c_bus *i2c_bus, u16 addr) | |||
409 | rc = em2800_i2c_check_for_device(dev, addr); | 415 | rc = em2800_i2c_check_for_device(dev, addr); |
410 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) | 416 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) |
411 | rc = em25xx_bus_B_check_for_device(dev, addr); | 417 | rc = em25xx_bus_B_check_for_device(dev, addr); |
412 | if (rc == -ENXIO) { | ||
413 | if (i2c_debug) | ||
414 | printk(" no device\n"); | ||
415 | } | ||
416 | return rc; | 418 | return rc; |
417 | } | 419 | } |
418 | 420 | ||
@@ -421,7 +423,7 @@ static inline int i2c_recv_bytes(struct em28xx_i2c_bus *i2c_bus, | |||
421 | { | 423 | { |
422 | struct em28xx *dev = i2c_bus->dev; | 424 | struct em28xx *dev = i2c_bus->dev; |
423 | u16 addr = msg.addr << 1; | 425 | u16 addr = msg.addr << 1; |
424 | int byte, rc = -EOPNOTSUPP; | 426 | int rc = -EOPNOTSUPP; |
425 | 427 | ||
426 | if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) | 428 | if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) |
427 | rc = em28xx_i2c_recv_bytes(dev, addr, msg.buf, msg.len); | 429 | rc = em28xx_i2c_recv_bytes(dev, addr, msg.buf, msg.len); |
@@ -429,10 +431,6 @@ static inline int i2c_recv_bytes(struct em28xx_i2c_bus *i2c_bus, | |||
429 | rc = em2800_i2c_recv_bytes(dev, addr, msg.buf, msg.len); | 431 | rc = em2800_i2c_recv_bytes(dev, addr, msg.buf, msg.len); |
430 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) | 432 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B) |
431 | rc = em25xx_bus_B_recv_bytes(dev, addr, msg.buf, msg.len); | 433 | rc = em25xx_bus_B_recv_bytes(dev, addr, msg.buf, msg.len); |
432 | if (i2c_debug) { | ||
433 | for (byte = 0; byte < msg.len; byte++) | ||
434 | printk(" %02x", msg.buf[byte]); | ||
435 | } | ||
436 | return rc; | 434 | return rc; |
437 | } | 435 | } |
438 | 436 | ||
@@ -441,12 +439,8 @@ static inline int i2c_send_bytes(struct em28xx_i2c_bus *i2c_bus, | |||
441 | { | 439 | { |
442 | struct em28xx *dev = i2c_bus->dev; | 440 | struct em28xx *dev = i2c_bus->dev; |
443 | u16 addr = msg.addr << 1; | 441 | u16 addr = msg.addr << 1; |
444 | int byte, rc = -EOPNOTSUPP; | 442 | int rc = -EOPNOTSUPP; |
445 | 443 | ||
446 | if (i2c_debug) { | ||
447 | for (byte = 0; byte < msg.len; byte++) | ||
448 | printk(" %02x", msg.buf[byte]); | ||
449 | } | ||
450 | if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) | 444 | if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) |
451 | rc = em28xx_i2c_send_bytes(dev, addr, msg.buf, msg.len, stop); | 445 | rc = em28xx_i2c_send_bytes(dev, addr, msg.buf, msg.len, stop); |
452 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) | 446 | else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) |
@@ -491,7 +485,7 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
491 | } | 485 | } |
492 | for (i = 0; i < num; i++) { | 486 | for (i = 0; i < num; i++) { |
493 | addr = msgs[i].addr << 1; | 487 | addr = msgs[i].addr << 1; |
494 | if (i2c_debug) | 488 | if (i2c_debug > 1) |
495 | printk(KERN_DEBUG "%s at %s: %s %s addr=%02x len=%d:", | 489 | printk(KERN_DEBUG "%s at %s: %s %s addr=%02x len=%d:", |
496 | dev->name, __func__ , | 490 | dev->name, __func__ , |
497 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", | 491 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", |
@@ -503,25 +497,41 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
503 | * This code is only called during device probe. | 497 | * This code is only called during device probe. |
504 | */ | 498 | */ |
505 | rc = i2c_check_for_device(i2c_bus, addr); | 499 | rc = i2c_check_for_device(i2c_bus, addr); |
506 | if (rc == -ENXIO) { | 500 | if (rc < 0) { |
501 | if (rc == -ENXIO) { | ||
502 | if (i2c_debug > 1) | ||
503 | printk(KERN_CONT " no device\n"); | ||
504 | rc = -ENODEV; | ||
505 | } else { | ||
506 | if (i2c_debug > 1) | ||
507 | printk(KERN_CONT " ERROR: %i\n", rc); | ||
508 | } | ||
507 | rt_mutex_unlock(&dev->i2c_bus_lock); | 509 | rt_mutex_unlock(&dev->i2c_bus_lock); |
508 | return -ENODEV; | 510 | return rc; |
509 | } | 511 | } |
510 | } else if (msgs[i].flags & I2C_M_RD) { | 512 | } else if (msgs[i].flags & I2C_M_RD) { |
511 | /* read bytes */ | 513 | /* read bytes */ |
512 | rc = i2c_recv_bytes(i2c_bus, msgs[i]); | 514 | rc = i2c_recv_bytes(i2c_bus, msgs[i]); |
515 | |||
516 | if (i2c_debug > 1 && rc >= 0) | ||
517 | printk(KERN_CONT " %*ph", | ||
518 | msgs[i].len, msgs[i].buf); | ||
513 | } else { | 519 | } else { |
520 | if (i2c_debug > 1) | ||
521 | printk(KERN_CONT " %*ph", | ||
522 | msgs[i].len, msgs[i].buf); | ||
523 | |||
514 | /* write bytes */ | 524 | /* write bytes */ |
515 | rc = i2c_send_bytes(i2c_bus, msgs[i], i == num - 1); | 525 | rc = i2c_send_bytes(i2c_bus, msgs[i], i == num - 1); |
516 | } | 526 | } |
517 | if (rc < 0) { | 527 | if (rc < 0) { |
518 | if (i2c_debug) | 528 | if (i2c_debug > 1) |
519 | printk(" ERROR: %i\n", rc); | 529 | printk(KERN_CONT " ERROR: %i\n", rc); |
520 | rt_mutex_unlock(&dev->i2c_bus_lock); | 530 | rt_mutex_unlock(&dev->i2c_bus_lock); |
521 | return rc; | 531 | return rc; |
522 | } | 532 | } |
523 | if (i2c_debug) | 533 | if (i2c_debug > 1) |
524 | printk("\n"); | 534 | printk(KERN_CONT "\n"); |
525 | } | 535 | } |
526 | 536 | ||
527 | rt_mutex_unlock(&dev->i2c_bus_lock); | 537 | rt_mutex_unlock(&dev->i2c_bus_lock); |
@@ -604,7 +614,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned bus, | |||
604 | * calculation and returned device dataset. Simplifies the code a lot, | 614 | * calculation and returned device dataset. Simplifies the code a lot, |
605 | * but we might have to deal with multiple sizes in the future ! | 615 | * but we might have to deal with multiple sizes in the future ! |
606 | */ | 616 | */ |
607 | int i, err; | 617 | int err; |
608 | struct em28xx_eeprom *dev_config; | 618 | struct em28xx_eeprom *dev_config; |
609 | u8 buf, *data; | 619 | u8 buf, *data; |
610 | 620 | ||
@@ -635,20 +645,14 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned bus, | |||
635 | goto error; | 645 | goto error; |
636 | } | 646 | } |
637 | 647 | ||
638 | /* Display eeprom content */ | 648 | if (i2c_debug) { |
639 | for (i = 0; i < len; i++) { | 649 | /* Display eeprom content */ |
640 | if (0 == (i % 16)) { | 650 | print_hex_dump(KERN_INFO, "eeprom ", DUMP_PREFIX_OFFSET, |
641 | if (dev->eeprom_addrwidth_16bit) | 651 | 16, 1, data, len, true); |
642 | em28xx_info("i2c eeprom %04x:", i); | 652 | |
643 | else | 653 | if (dev->eeprom_addrwidth_16bit) |
644 | em28xx_info("i2c eeprom %02x:", i); | 654 | em28xx_info("eeprom %06x: ... (skipped)\n", 256); |
645 | } | ||
646 | printk(" %02x", data[i]); | ||
647 | if (15 == (i % 16)) | ||
648 | printk("\n"); | ||
649 | } | 655 | } |
650 | if (dev->eeprom_addrwidth_16bit) | ||
651 | em28xx_info("i2c eeprom %04x: ... (skipped)\n", i); | ||
652 | 656 | ||
653 | if (dev->eeprom_addrwidth_16bit && | 657 | if (dev->eeprom_addrwidth_16bit && |
654 | data[0] == 0x26 && data[3] == 0x00) { | 658 | data[0] == 0x26 && data[3] == 0x00) { |