Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] cec: adv7511: add cec support

Add CEC support to the adv7511 driver.

Signed-off-by: Hans Verkuil <hansverk@cisco.com>
[k.debski@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski <kamil@wypas.org>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
257d4eae 25c84fb1

+402 -13
+8
drivers/media/i2c/Kconfig
··· 463 463 tristate "Analog Devices ADV7511 encoder" 464 464 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API 465 465 select HDMI 466 + select MEDIA_CEC_EDID 466 467 ---help--- 467 468 Support for the Analog Devices ADV7511 video encoder. 468 469 ··· 471 470 472 471 To compile this driver as a module, choose M here: the 473 472 module will be called adv7511. 473 + 474 + config VIDEO_ADV7511_CEC 475 + bool "Enable Analog Devices ADV7511 CEC support" 476 + depends on VIDEO_ADV7511 && MEDIA_CEC 477 + ---help--- 478 + When selected the adv7511 will support the optional 479 + HDMI CEC feature. 474 480 475 481 config VIDEO_AD9389B 476 482 tristate "Analog Devices AD9389B encoder"
+393 -8
drivers/media/i2c/adv7511.c
··· 33 33 #include <media/v4l2-ctrls.h> 34 34 #include <media/v4l2-dv-timings.h> 35 35 #include <media/i2c/adv7511.h> 36 + #include <media/cec.h> 36 37 37 38 static int debug; 38 39 module_param(debug, int, 0644); ··· 59 58 #define ADV7511_MAX_HEIGHT 1200 60 59 #define ADV7511_MIN_PIXELCLOCK 20000000 61 60 #define ADV7511_MAX_PIXELCLOCK 225000000 61 + 62 + #define ADV7511_MAX_ADDRS (3) 62 63 63 64 /* 64 65 ********************************************************************** ··· 93 90 struct v4l2_ctrl_handler hdl; 94 91 int chip_revision; 95 92 u8 i2c_edid_addr; 96 - u8 i2c_cec_addr; 97 93 u8 i2c_pktmem_addr; 94 + u8 i2c_cec_addr; 95 + 96 + struct i2c_client *i2c_cec; 97 + struct cec_adapter *cec_adap; 98 + u8 cec_addr[ADV7511_MAX_ADDRS]; 99 + u8 cec_valid_addrs; 100 + bool cec_enabled_adap; 101 + 98 102 /* Is the adv7511 powered on? */ 99 103 bool power_on; 100 104 /* Did we receive hotplug and rx-sense signals? */ 101 105 bool have_monitor; 106 + bool enabled_irq; 102 107 /* timings from s_dv_timings */ 103 108 struct v4l2_dv_timings dv_timings; 104 109 u32 fmt_code; ··· 238 227 return ret; 239 228 } 240 229 241 - static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf) 230 + static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) 242 231 { 243 232 struct adv7511_state *state = get_adv7511_state(sd); 244 233 int i; ··· 251 240 I2C_SMBUS_BLOCK_MAX, buf + i); 252 241 if (err) 253 242 v4l2_err(sd, "%s: i2c read error\n", __func__); 243 + } 244 + 245 + static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg) 246 + { 247 + struct adv7511_state *state = get_adv7511_state(sd); 248 + 249 + return i2c_smbus_read_byte_data(state->i2c_cec, reg); 250 + } 251 + 252 + static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) 253 + { 254 + struct adv7511_state *state = get_adv7511_state(sd); 255 + int ret; 256 + int i; 257 + 258 + for (i = 0; i < 3; i++) { 259 + ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val); 260 + if (ret == 0) 261 + return 0; 262 + } 263 + v4l2_err(sd, "%s: I2C Write Problem\n", __func__); 264 + return ret; 265 + } 266 + 267 + static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, 268 + u8 val) 269 + { 270 + return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val); 254 271 } 255 272 256 273 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg) ··· 464 425 #ifdef CONFIG_VIDEO_ADV_DEBUG 465 426 static void adv7511_inv_register(struct v4l2_subdev *sd) 466 427 { 428 + struct adv7511_state *state = get_adv7511_state(sd); 429 + 467 430 v4l2_info(sd, "0x000-0x0ff: Main Map\n"); 431 + if (state->i2c_cec) 432 + v4l2_info(sd, "0x100-0x1ff: CEC Map\n"); 468 433 } 469 434 470 435 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 471 436 { 437 + struct adv7511_state *state = get_adv7511_state(sd); 438 + 472 439 reg->size = 1; 473 440 switch (reg->reg >> 8) { 474 441 case 0: 475 442 reg->val = adv7511_rd(sd, reg->reg & 0xff); 476 443 break; 444 + case 1: 445 + if (state->i2c_cec) { 446 + reg->val = adv7511_cec_read(sd, reg->reg & 0xff); 447 + break; 448 + } 449 + /* fall through */ 477 450 default: 478 451 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); 479 452 adv7511_inv_register(sd); ··· 496 445 497 446 static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 498 447 { 448 + struct adv7511_state *state = get_adv7511_state(sd); 449 + 499 450 switch (reg->reg >> 8) { 500 451 case 0: 501 452 adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff); 502 453 break; 454 + case 1: 455 + if (state->i2c_cec) { 456 + adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff); 457 + break; 458 + } 459 + /* fall through */ 503 460 default: 504 461 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); 505 462 adv7511_inv_register(sd); ··· 595 536 { 596 537 struct adv7511_state *state = get_adv7511_state(sd); 597 538 struct adv7511_state_edid *edid = &state->edid; 539 + int i; 598 540 599 541 static const char * const states[] = { 600 542 "in reset", ··· 665 605 else 666 606 v4l2_info(sd, "no timings set\n"); 667 607 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); 608 + 609 + if (state->i2c_cec == NULL) 610 + return 0; 611 + 668 612 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); 613 + 614 + v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? 615 + "enabled" : "disabled"); 616 + if (state->cec_enabled_adap) { 617 + for (i = 0; i < ADV7511_MAX_ADDRS; i++) { 618 + bool is_valid = state->cec_valid_addrs & (1 << i); 619 + 620 + if (is_valid) 621 + v4l2_info(sd, "CEC Logical Address: 0x%x\n", 622 + state->cec_addr[i]); 623 + } 624 + } 669 625 v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr); 670 626 return 0; 671 627 } ··· 739 663 return true; 740 664 } 741 665 666 + #if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) 667 + static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) 668 + { 669 + struct adv7511_state *state = adap->priv; 670 + struct v4l2_subdev *sd = &state->sd; 671 + 672 + if (state->i2c_cec == NULL) 673 + return -EIO; 674 + 675 + if (!state->cec_enabled_adap && enable) { 676 + /* power up cec section */ 677 + adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01); 678 + /* legacy mode and clear all rx buffers */ 679 + adv7511_cec_write(sd, 0x4a, 0x07); 680 + adv7511_cec_write(sd, 0x4a, 0); 681 + adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */ 682 + /* enabled irqs: */ 683 + /* tx: ready */ 684 + /* tx: arbitration lost */ 685 + /* tx: retry timeout */ 686 + /* rx: ready 1 */ 687 + if (state->enabled_irq) 688 + adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39); 689 + } else if (state->cec_enabled_adap && !enable) { 690 + if (state->enabled_irq) 691 + adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00); 692 + /* disable address mask 1-3 */ 693 + adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00); 694 + /* power down cec section */ 695 + adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00); 696 + state->cec_valid_addrs = 0; 697 + } 698 + state->cec_enabled_adap = enable; 699 + return 0; 700 + } 701 + 702 + static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) 703 + { 704 + struct adv7511_state *state = adap->priv; 705 + struct v4l2_subdev *sd = &state->sd; 706 + unsigned int i, free_idx = ADV7511_MAX_ADDRS; 707 + 708 + if (!state->cec_enabled_adap) 709 + return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO; 710 + 711 + if (addr == CEC_LOG_ADDR_INVALID) { 712 + adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0); 713 + state->cec_valid_addrs = 0; 714 + return 0; 715 + } 716 + 717 + for (i = 0; i < ADV7511_MAX_ADDRS; i++) { 718 + bool is_valid = state->cec_valid_addrs & (1 << i); 719 + 720 + if (free_idx == ADV7511_MAX_ADDRS && !is_valid) 721 + free_idx = i; 722 + if (is_valid && state->cec_addr[i] == addr) 723 + return 0; 724 + } 725 + if (i == ADV7511_MAX_ADDRS) { 726 + i = free_idx; 727 + if (i == ADV7511_MAX_ADDRS) 728 + return -ENXIO; 729 + } 730 + state->cec_addr[i] = addr; 731 + state->cec_valid_addrs |= 1 << i; 732 + 733 + switch (i) { 734 + case 0: 735 + /* enable address mask 0 */ 736 + adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10); 737 + /* set address for mask 0 */ 738 + adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr); 739 + break; 740 + case 1: 741 + /* enable address mask 1 */ 742 + adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20); 743 + /* set address for mask 1 */ 744 + adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4); 745 + break; 746 + case 2: 747 + /* enable address mask 2 */ 748 + adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40); 749 + /* set address for mask 1 */ 750 + adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr); 751 + break; 752 + } 753 + return 0; 754 + } 755 + 756 + static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, 757 + u32 signal_free_time, struct cec_msg *msg) 758 + { 759 + struct adv7511_state *state = adap->priv; 760 + struct v4l2_subdev *sd = &state->sd; 761 + u8 len = msg->len; 762 + unsigned int i; 763 + 764 + v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len); 765 + 766 + if (len > 16) { 767 + v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); 768 + return -EINVAL; 769 + } 770 + 771 + /* 772 + * The number of retries is the number of attempts - 1, but retry 773 + * at least once. It's not clear if a value of 0 is allowed, so 774 + * let's do at least one retry. 775 + */ 776 + adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4); 777 + 778 + /* blocking, clear cec tx irq status */ 779 + adv7511_wr_and_or(sd, 0x97, 0xc7, 0x38); 780 + 781 + /* write data */ 782 + for (i = 0; i < len; i++) 783 + adv7511_cec_write(sd, i, msg->msg[i]); 784 + 785 + /* set length (data + header) */ 786 + adv7511_cec_write(sd, 0x10, len); 787 + /* start transmit, enable tx */ 788 + adv7511_cec_write(sd, 0x11, 0x01); 789 + return 0; 790 + } 791 + 792 + static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) 793 + { 794 + struct adv7511_state *state = get_adv7511_state(sd); 795 + 796 + if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) { 797 + v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); 798 + return; 799 + } 800 + 801 + if (tx_raw_status & 0x10) { 802 + v4l2_dbg(1, debug, sd, 803 + "%s: tx raw: arbitration lost\n", __func__); 804 + cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST, 805 + 1, 0, 0, 0); 806 + return; 807 + } 808 + if (tx_raw_status & 0x08) { 809 + u8 status; 810 + u8 nack_cnt; 811 + u8 low_drive_cnt; 812 + 813 + v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); 814 + /* 815 + * We set this status bit since this hardware performs 816 + * retransmissions. 817 + */ 818 + status = CEC_TX_STATUS_MAX_RETRIES; 819 + nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf; 820 + if (nack_cnt) 821 + status |= CEC_TX_STATUS_NACK; 822 + low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4; 823 + if (low_drive_cnt) 824 + status |= CEC_TX_STATUS_LOW_DRIVE; 825 + cec_transmit_done(state->cec_adap, status, 826 + 0, nack_cnt, low_drive_cnt, 0); 827 + return; 828 + } 829 + if (tx_raw_status & 0x20) { 830 + v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); 831 + cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0); 832 + return; 833 + } 834 + } 835 + 836 + static const struct cec_adap_ops adv7511_cec_adap_ops = { 837 + .adap_enable = adv7511_cec_adap_enable, 838 + .adap_log_addr = adv7511_cec_adap_log_addr, 839 + .adap_transmit = adv7511_cec_adap_transmit, 840 + }; 841 + #endif 842 + 742 843 /* Enable interrupts */ 743 844 static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) 744 845 { 846 + struct adv7511_state *state = get_adv7511_state(sd); 745 847 u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT; 746 848 u8 irqs_rd; 747 849 int retries = 100; 748 850 749 851 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); 852 + 853 + if (state->enabled_irq == enable) 854 + return; 855 + state->enabled_irq = enable; 750 856 751 857 /* The datasheet says that the EDID ready interrupt should be 752 858 disabled if there is no hotplug. */ ··· 936 678 irqs = 0; 937 679 else if (adv7511_have_hotplug(sd)) 938 680 irqs |= MASK_ADV7511_EDID_RDY_INT; 681 + 682 + adv7511_wr_and_or(sd, 0x95, 0xc0, 683 + (state->cec_enabled_adap && enable) ? 0x39 : 0x00); 939 684 940 685 /* 941 686 * This i2c write can fail (approx. 1 in 1000 writes). But it ··· 962 701 static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) 963 702 { 964 703 u8 irq_status; 704 + u8 cec_irq; 965 705 966 706 /* disable interrupts to prevent a race condition */ 967 707 adv7511_set_isr(sd, false); 968 708 irq_status = adv7511_rd(sd, 0x96); 709 + cec_irq = adv7511_rd(sd, 0x97); 969 710 /* clear detected interrupts */ 970 711 adv7511_wr(sd, 0x96, irq_status); 712 + adv7511_wr(sd, 0x97, cec_irq); 971 713 972 - v4l2_dbg(1, debug, sd, "%s: irq 0x%x\n", __func__, irq_status); 714 + v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__, 715 + irq_status, cec_irq); 973 716 974 717 if (irq_status & (MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT)) 975 718 adv7511_check_monitor_present_status(sd); 976 719 if (irq_status & MASK_ADV7511_EDID_RDY_INT) 977 720 adv7511_check_edid_status(sd); 721 + 722 + #if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) 723 + if (cec_irq & 0x38) 724 + adv_cec_tx_raw_status(sd, cec_irq); 725 + 726 + if (cec_irq & 1) { 727 + struct adv7511_state *state = get_adv7511_state(sd); 728 + struct cec_msg msg; 729 + 730 + msg.len = adv7511_cec_read(sd, 0x25) & 0x1f; 731 + 732 + v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__, 733 + msg.len); 734 + 735 + if (msg.len > 16) 736 + msg.len = 16; 737 + 738 + if (msg.len) { 739 + u8 i; 740 + 741 + for (i = 0; i < msg.len; i++) 742 + msg.msg[i] = adv7511_cec_read(sd, i + 0x15); 743 + 744 + adv7511_cec_write(sd, 0x4a, 1); /* toggle to re-enable rx 1 */ 745 + adv7511_cec_write(sd, 0x4a, 0); 746 + cec_received_msg(state->cec_adap, &msg); 747 + } 748 + } 749 + #endif 978 750 979 751 /* enable interrupts */ 980 752 adv7511_set_isr(sd, true); ··· 1477 1183 /* We failed to read the EDID, so send an event for this. */ 1478 1184 ed.present = false; 1479 1185 ed.segment = adv7511_rd(sd, 0xc4); 1186 + ed.phys_addr = CEC_PHYS_ADDR_INVALID; 1187 + cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); 1480 1188 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); 1481 1189 v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0); 1482 1190 } ··· 1702 1406 1703 1407 v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments); 1704 1408 state->edid.complete = true; 1705 - 1409 + ed.phys_addr = cec_get_edid_phys_addr(state->edid.data, 1410 + state->edid.segments * 256, 1411 + NULL); 1706 1412 /* report when we have all segments 1707 1413 but report only for segment 0 1708 1414 */ 1709 1415 ed.present = true; 1710 1416 ed.segment = 0; 1711 1417 state->edid_detect_counter++; 1418 + cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); 1712 1419 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); 1713 1420 return ed.present; 1714 1421 } ··· 1719 1420 return false; 1720 1421 } 1721 1422 1423 + static int adv7511_registered(struct v4l2_subdev *sd) 1424 + { 1425 + struct adv7511_state *state = get_adv7511_state(sd); 1426 + int err; 1427 + 1428 + err = cec_register_adapter(state->cec_adap); 1429 + if (err) 1430 + cec_delete_adapter(state->cec_adap); 1431 + return err; 1432 + } 1433 + 1434 + static void adv7511_unregistered(struct v4l2_subdev *sd) 1435 + { 1436 + struct adv7511_state *state = get_adv7511_state(sd); 1437 + 1438 + cec_unregister_adapter(state->cec_adap); 1439 + } 1440 + 1441 + static const struct v4l2_subdev_internal_ops adv7511_int_ops = { 1442 + .registered = adv7511_registered, 1443 + .unregistered = adv7511_unregistered, 1444 + }; 1445 + 1722 1446 /* ----------------------------------------------------------------------- */ 1723 1447 /* Setup ADV7511 */ 1724 1448 static void adv7511_init_setup(struct v4l2_subdev *sd) 1725 1449 { 1726 1450 struct adv7511_state *state = get_adv7511_state(sd); 1727 1451 struct adv7511_state_edid *edid = &state->edid; 1452 + u32 cec_clk = state->pdata.cec_clk; 1453 + u8 ratio; 1728 1454 1729 1455 v4l2_dbg(1, debug, sd, "%s\n", __func__); 1730 1456 1731 1457 /* clear all interrupts */ 1732 1458 adv7511_wr(sd, 0x96, 0xff); 1459 + adv7511_wr(sd, 0x97, 0xff); 1733 1460 /* 1734 1461 * Stop HPD from resetting a lot of registers. 1735 1462 * It might leave the chip in a partly un-initialized state, ··· 1767 1442 adv7511_set_isr(sd, false); 1768 1443 adv7511_s_stream(sd, false); 1769 1444 adv7511_s_audio_stream(sd, false); 1445 + 1446 + if (state->i2c_cec == NULL) 1447 + return; 1448 + 1449 + v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk); 1450 + 1451 + /* cec soft reset */ 1452 + adv7511_cec_write(sd, 0x50, 0x01); 1453 + adv7511_cec_write(sd, 0x50, 0x00); 1454 + 1455 + /* legacy mode */ 1456 + adv7511_cec_write(sd, 0x4a, 0x00); 1457 + 1458 + if (cec_clk % 750000 != 0) 1459 + v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n", 1460 + __func__, cec_clk); 1461 + 1462 + ratio = (cec_clk / 750000) - 1; 1463 + adv7511_cec_write(sd, 0x4e, ratio << 2); 1770 1464 } 1771 1465 1772 1466 static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *id) ··· 1820 1476 client->addr << 1); 1821 1477 1822 1478 v4l2_i2c_subdev_init(sd, client, &adv7511_ops); 1479 + sd->internal_ops = &adv7511_int_ops; 1823 1480 1824 1481 hdl = &state->hdl; 1825 1482 v4l2_ctrl_handler_init(hdl, 10); ··· 1861 1516 chip_id[0] = adv7511_rd(sd, 0xf5); 1862 1517 chip_id[1] = adv7511_rd(sd, 0xf6); 1863 1518 if (chip_id[0] != 0x75 || chip_id[1] != 0x11) { 1864 - v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], chip_id[1]); 1519 + v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], 1520 + chip_id[1]); 1865 1521 err = -EIO; 1866 1522 goto err_entity; 1867 1523 } 1868 1524 1869 - state->i2c_edid = i2c_new_dummy(client->adapter, state->i2c_edid_addr >> 1); 1525 + state->i2c_edid = i2c_new_dummy(client->adapter, 1526 + state->i2c_edid_addr >> 1); 1870 1527 if (state->i2c_edid == NULL) { 1871 1528 v4l2_err(sd, "failed to register edid i2c client\n"); 1872 1529 err = -ENOMEM; 1873 1530 goto err_entity; 1874 1531 } 1875 1532 1533 + adv7511_wr(sd, 0xe1, state->i2c_cec_addr); 1534 + if (state->pdata.cec_clk < 3000000 || 1535 + state->pdata.cec_clk > 100000000) { 1536 + v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n", 1537 + __func__, state->pdata.cec_clk); 1538 + state->pdata.cec_clk = 0; 1539 + } 1540 + 1541 + if (state->pdata.cec_clk) { 1542 + state->i2c_cec = i2c_new_dummy(client->adapter, 1543 + state->i2c_cec_addr >> 1); 1544 + if (state->i2c_cec == NULL) { 1545 + v4l2_err(sd, "failed to register cec i2c client\n"); 1546 + goto err_unreg_edid; 1547 + } 1548 + adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */ 1549 + } else { 1550 + adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ 1551 + } 1552 + 1876 1553 state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1); 1877 1554 if (state->i2c_pktmem == NULL) { 1878 1555 v4l2_err(sd, "failed to register pktmem i2c client\n"); 1879 1556 err = -ENOMEM; 1880 - goto err_unreg_edid; 1557 + goto err_unreg_cec; 1881 1558 } 1882 1559 1883 - adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ 1884 1560 state->work_queue = create_singlethread_workqueue(sd->name); 1885 1561 if (state->work_queue == NULL) { 1886 1562 v4l2_err(sd, "could not create workqueue\n"); ··· 1912 1546 INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler); 1913 1547 1914 1548 adv7511_init_setup(sd); 1549 + 1550 + #if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC) 1551 + state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, 1552 + state, dev_name(&client->dev), CEC_CAP_TRANSMIT | 1553 + CEC_CAP_LOG_ADDRS | CEC_CAP_PASSTHROUGH | CEC_CAP_RC, 1554 + ADV7511_MAX_ADDRS, &client->dev); 1555 + err = PTR_ERR_OR_ZERO(state->cec_adap); 1556 + if (err) { 1557 + destroy_workqueue(state->work_queue); 1558 + goto err_unreg_pktmem; 1559 + } 1560 + #endif 1561 + 1915 1562 adv7511_set_isr(sd, true); 1916 1563 adv7511_check_monitor_present_status(sd); 1917 1564 ··· 1934 1555 1935 1556 err_unreg_pktmem: 1936 1557 i2c_unregister_device(state->i2c_pktmem); 1558 + err_unreg_cec: 1559 + if (state->i2c_cec) 1560 + i2c_unregister_device(state->i2c_cec); 1937 1561 err_unreg_edid: 1938 1562 i2c_unregister_device(state->i2c_edid); 1939 1563 err_entity: ··· 1958 1576 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name, 1959 1577 client->addr << 1, client->adapter->name); 1960 1578 1579 + adv7511_set_isr(sd, false); 1961 1580 adv7511_init_setup(sd); 1962 1581 cancel_delayed_work(&state->edid_handler); 1963 1582 i2c_unregister_device(state->i2c_edid); 1583 + if (state->i2c_cec) 1584 + i2c_unregister_device(state->i2c_cec); 1964 1585 i2c_unregister_device(state->i2c_pktmem); 1965 1586 destroy_workqueue(state->work_queue); 1966 1587 v4l2_device_unregister_subdev(sd);
+1 -5
include/media/i2c/adv7511.h
··· 32 32 struct adv7511_edid_detect { 33 33 int present; 34 34 int segment; 35 - }; 36 - 37 - struct adv7511_cec_arg { 38 - void *arg; 39 - u32 f_flags; 35 + uint16_t phys_addr; 40 36 }; 41 37 42 38 struct adv7511_platform_data {