aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-11-24 18:55:33 -0500
committerDave Airlie <airlied@redhat.com>2016-11-24 18:55:33 -0500
commit7625e05286cf3f37c8a5e633379a4d014ddbe555 (patch)
tree40a4be339cec8dccebfea8cd8b4c557dee15d9c2 /drivers
parent4d5304d87034fe3f003cffa7ef2350d066ef7f3e (diff)
parent9b2502b6ebc632ff49743b3639ea12d4f08808a5 (diff)
Merge branch 'drm-tda998x-devel' of git://git.armlinux.org.uk/~rmk/linux-arm into drm-next
These updates: * improve the robustness of the driver wrt races * improve the compliance for sending infoframes and audio * re-organise the function order in the driver to group like functions together. (This unfortunately causes a conflict with the change in drm-misc, but it should be trivial to solve, although it looks more scarey than it really is - sfr has already sent two reports about this, one earlier today.) * simplify tda998x_audio_get_eld and DPMS handling * power down sections of the chip that we never use * add some initial preparation for supporting the CEC driver * 'drm-tda998x-devel' of git://git.armlinux.org.uk/~rmk/linux-arm: drm/i2c: tda998x: fix spelling mistake drm/i2c: tda998x: allow sharing of the CEC device accesses drm/i2c: tda998x: allow interrupt to be shared drm/i2c: tda998x: power down pre-filter and color conversion drm/i2c: tda998x: switch to boolean is_on drm/i2c: tda998x: remove complexity from tda998x_audio_get_eld() drm/i2c: tda998x: group audio functions together drm/i2c: tda998x: separate connector initialisation drm/i2c: tda998x: group connector functions and funcs together drm/i2c: tda998x: move and rename tda998x_encoder_set_config() drm/i2c: tda998x: correct function name in comments drm/i2c: tda998x: only enable audio if supported by sink drm/i2c: tda998x: only configure infoframes and audio if supported drm/i2c: tda998x: avoid race when programming audio drm/i2c: tda998x: avoid racy access to mode clock drm/i2c: tda998x: avoid race in tda998x_encoder_mode_set() drm/i2c: tda998x: move audio mutex initialisation
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/i2c/tda998x_drv.c856
1 files changed, 454 insertions, 402 deletions
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 027521f30b6e..86f47e190309 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -41,12 +41,15 @@ struct tda998x_priv {
41 struct i2c_client *hdmi; 41 struct i2c_client *hdmi;
42 struct mutex mutex; 42 struct mutex mutex;
43 u16 rev; 43 u16 rev;
44 u8 cec_addr;
44 u8 current_page; 45 u8 current_page;
45 int dpms; 46 bool is_on;
46 bool is_hdmi_sink; 47 bool supports_infoframes;
48 bool sink_has_audio;
47 u8 vip_cntrl_0; 49 u8 vip_cntrl_0;
48 u8 vip_cntrl_1; 50 u8 vip_cntrl_1;
49 u8 vip_cntrl_2; 51 u8 vip_cntrl_2;
52 unsigned long tmds_clock;
50 struct tda998x_audio_params audio_params; 53 struct tda998x_audio_params audio_params;
51 54
52 struct platform_device *audio_pdev; 55 struct platform_device *audio_pdev;
@@ -105,6 +108,8 @@ struct tda998x_priv {
105# define I2C_MASTER_DIS_FILT (1 << 1) 108# define I2C_MASTER_DIS_FILT (1 << 1)
106# define I2C_MASTER_APP_STRT_LAT (1 << 2) 109# define I2C_MASTER_APP_STRT_LAT (1 << 2)
107#define REG_FEAT_POWERDOWN REG(0x00, 0x0e) /* read/write */ 110#define REG_FEAT_POWERDOWN REG(0x00, 0x0e) /* read/write */
111# define FEAT_POWERDOWN_PREFILT BIT(0)
112# define FEAT_POWERDOWN_CSC BIT(1)
108# define FEAT_POWERDOWN_SPDIF (1 << 3) 113# define FEAT_POWERDOWN_SPDIF (1 << 3)
109#define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */ 114#define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */
110#define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */ 115#define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */
@@ -370,35 +375,46 @@ struct tda998x_priv {
370static void 375static void
371cec_write(struct tda998x_priv *priv, u16 addr, u8 val) 376cec_write(struct tda998x_priv *priv, u16 addr, u8 val)
372{ 377{
373 struct i2c_client *client = priv->cec;
374 u8 buf[] = {addr, val}; 378 u8 buf[] = {addr, val};
379 struct i2c_msg msg = {
380 .addr = priv->cec_addr,
381 .len = 2,
382 .buf = buf,
383 };
375 int ret; 384 int ret;
376 385
377 ret = i2c_master_send(client, buf, sizeof(buf)); 386 ret = i2c_transfer(priv->hdmi->adapter, &msg, 1);
378 if (ret < 0) 387 if (ret < 0)
379 dev_err(&client->dev, "Error %d writing to cec:0x%x\n", ret, addr); 388 dev_err(&priv->hdmi->dev, "Error %d writing to cec:0x%x\n",
389 ret, addr);
380} 390}
381 391
382static u8 392static u8
383cec_read(struct tda998x_priv *priv, u8 addr) 393cec_read(struct tda998x_priv *priv, u8 addr)
384{ 394{
385 struct i2c_client *client = priv->cec;
386 u8 val; 395 u8 val;
396 struct i2c_msg msg[2] = {
397 {
398 .addr = priv->cec_addr,
399 .len = 1,
400 .buf = &addr,
401 }, {
402 .addr = priv->cec_addr,
403 .flags = I2C_M_RD,
404 .len = 1,
405 .buf = &val,
406 },
407 };
387 int ret; 408 int ret;
388 409
389 ret = i2c_master_send(client, &addr, sizeof(addr)); 410 ret = i2c_transfer(priv->hdmi->adapter, msg, ARRAY_SIZE(msg));
390 if (ret < 0) 411 if (ret < 0) {
391 goto fail; 412 dev_err(&priv->hdmi->dev, "Error %d reading from cec:0x%x\n",
392 413 ret, addr);
393 ret = i2c_master_recv(client, &val, sizeof(val)); 414 val = 0;
394 if (ret < 0) 415 }
395 goto fail;
396 416
397 return val; 417 return val;
398
399fail:
400 dev_err(&client->dev, "Error %d reading from cec:0x%x\n", ret, addr);
401 return 0;
402} 418}
403 419
404static int 420static int
@@ -579,9 +595,9 @@ tda998x_reset(struct tda998x_priv *priv)
579 * HPD assertion: it needs a delay of 100ms to avoid timing out while 595 * HPD assertion: it needs a delay of 100ms to avoid timing out while
580 * trying to read EDID data. 596 * trying to read EDID data.
581 * 597 *
582 * However, tda998x_encoder_get_modes() may be called at any moment 598 * However, tda998x_connector_get_modes() may be called at any moment
583 * after tda998x_connector_detect() indicates that we are connected, so 599 * after tda998x_connector_detect() indicates that we are connected, so
584 * we need to delay probing modes in tda998x_encoder_get_modes() after 600 * we need to delay probing modes in tda998x_connector_get_modes() after
585 * we have seen a HPD inactive->active transition. This code implements 601 * we have seen a HPD inactive->active transition. This code implements
586 * that delay. 602 * that delay.
587 */ 603 */
@@ -630,28 +646,30 @@ static irqreturn_t tda998x_irq_thread(int irq, void *data)
630 bool handled = false; 646 bool handled = false;
631 647
632 sta = cec_read(priv, REG_CEC_INTSTATUS); 648 sta = cec_read(priv, REG_CEC_INTSTATUS);
633 cec = cec_read(priv, REG_CEC_RXSHPDINT); 649 if (sta & CEC_INTSTATUS_HDMI) {
634 lvl = cec_read(priv, REG_CEC_RXSHPDLEV); 650 cec = cec_read(priv, REG_CEC_RXSHPDINT);
635 flag0 = reg_read(priv, REG_INT_FLAGS_0); 651 lvl = cec_read(priv, REG_CEC_RXSHPDLEV);
636 flag1 = reg_read(priv, REG_INT_FLAGS_1); 652 flag0 = reg_read(priv, REG_INT_FLAGS_0);
637 flag2 = reg_read(priv, REG_INT_FLAGS_2); 653 flag1 = reg_read(priv, REG_INT_FLAGS_1);
638 DRM_DEBUG_DRIVER( 654 flag2 = reg_read(priv, REG_INT_FLAGS_2);
639 "tda irq sta %02x cec %02x lvl %02x f0 %02x f1 %02x f2 %02x\n", 655 DRM_DEBUG_DRIVER(
640 sta, cec, lvl, flag0, flag1, flag2); 656 "tda irq sta %02x cec %02x lvl %02x f0 %02x f1 %02x f2 %02x\n",
641 657 sta, cec, lvl, flag0, flag1, flag2);
642 if (cec & CEC_RXSHPDINT_HPD) { 658
643 if (lvl & CEC_RXSHPDLEV_HPD) 659 if (cec & CEC_RXSHPDINT_HPD) {
644 tda998x_edid_delay_start(priv); 660 if (lvl & CEC_RXSHPDLEV_HPD)
645 else 661 tda998x_edid_delay_start(priv);
646 schedule_work(&priv->detect_work); 662 else
647 663 schedule_work(&priv->detect_work);
648 handled = true; 664
649 } 665 handled = true;
666 }
650 667
651 if ((flag2 & INT_FLAGS_2_EDID_BLK_RD) && priv->wq_edid_wait) { 668 if ((flag2 & INT_FLAGS_2_EDID_BLK_RD) && priv->wq_edid_wait) {
652 priv->wq_edid_wait = 0; 669 priv->wq_edid_wait = 0;
653 wake_up(&priv->wq_edid); 670 wake_up(&priv->wq_edid);
654 handled = true; 671 handled = true;
672 }
655 } 673 }
656 674
657 return IRQ_RETVAL(handled); 675 return IRQ_RETVAL(handled);
@@ -700,6 +718,8 @@ tda998x_write_avi(struct tda998x_priv *priv, struct drm_display_mode *mode)
700 tda998x_write_if(priv, DIP_IF_FLAGS_IF2, REG_IF2_HB0, &frame); 718 tda998x_write_if(priv, DIP_IF_FLAGS_IF2, REG_IF2_HB0, &frame);
701} 719}
702 720
721/* Audio support */
722
703static void tda998x_audio_mute(struct tda998x_priv *priv, bool on) 723static void tda998x_audio_mute(struct tda998x_priv *priv, bool on)
704{ 724{
705 if (on) { 725 if (on) {
@@ -713,8 +733,7 @@ static void tda998x_audio_mute(struct tda998x_priv *priv, bool on)
713 733
714static int 734static int
715tda998x_configure_audio(struct tda998x_priv *priv, 735tda998x_configure_audio(struct tda998x_priv *priv,
716 struct tda998x_audio_params *params, 736 struct tda998x_audio_params *params)
717 unsigned mode_clock)
718{ 737{
719 u8 buf[6], clksel_aip, clksel_fs, cts_n, adiv; 738 u8 buf[6], clksel_aip, clksel_fs, cts_n, adiv;
720 u32 n; 739 u32 n;
@@ -771,7 +790,7 @@ tda998x_configure_audio(struct tda998x_priv *priv,
771 * assume 100MHz requires larger divider. 790 * assume 100MHz requires larger divider.
772 */ 791 */
773 adiv = AUDIO_DIV_SERCLK_8; 792 adiv = AUDIO_DIV_SERCLK_8;
774 if (mode_clock > 100000) 793 if (priv->tmds_clock > 100000)
775 adiv++; /* AUDIO_DIV_SERCLK_16 */ 794 adiv++; /* AUDIO_DIV_SERCLK_16 */
776 795
777 /* S/PDIF asks for a larger divider */ 796 /* S/PDIF asks for a larger divider */
@@ -819,58 +838,281 @@ tda998x_configure_audio(struct tda998x_priv *priv,
819 return tda998x_write_aif(priv, &params->cea); 838 return tda998x_write_aif(priv, &params->cea);
820} 839}
821 840
822/* DRM encoder functions */ 841static int tda998x_audio_hw_params(struct device *dev, void *data,
842 struct hdmi_codec_daifmt *daifmt,
843 struct hdmi_codec_params *params)
844{
845 struct tda998x_priv *priv = dev_get_drvdata(dev);
846 int i, ret;
847 struct tda998x_audio_params audio = {
848 .sample_width = params->sample_width,
849 .sample_rate = params->sample_rate,
850 .cea = params->cea,
851 };
852
853 memcpy(audio.status, params->iec.status,
854 min(sizeof(audio.status), sizeof(params->iec.status)));
823 855
824static void tda998x_encoder_set_config(struct tda998x_priv *priv, 856 switch (daifmt->fmt) {
825 const struct tda998x_encoder_params *p) 857 case HDMI_I2S:
858 if (daifmt->bit_clk_inv || daifmt->frame_clk_inv ||
859 daifmt->bit_clk_master || daifmt->frame_clk_master) {
860 dev_err(dev, "%s: Bad flags %d %d %d %d\n", __func__,
861 daifmt->bit_clk_inv, daifmt->frame_clk_inv,
862 daifmt->bit_clk_master,
863 daifmt->frame_clk_master);
864 return -EINVAL;
865 }
866 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++)
867 if (priv->audio_port[i].format == AFMT_I2S)
868 audio.config = priv->audio_port[i].config;
869 audio.format = AFMT_I2S;
870 break;
871 case HDMI_SPDIF:
872 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++)
873 if (priv->audio_port[i].format == AFMT_SPDIF)
874 audio.config = priv->audio_port[i].config;
875 audio.format = AFMT_SPDIF;
876 break;
877 default:
878 dev_err(dev, "%s: Invalid format %d\n", __func__, daifmt->fmt);
879 return -EINVAL;
880 }
881
882 if (audio.config == 0) {
883 dev_err(dev, "%s: No audio configuration found\n", __func__);
884 return -EINVAL;
885 }
886
887 mutex_lock(&priv->audio_mutex);
888 if (priv->supports_infoframes && priv->sink_has_audio)
889 ret = tda998x_configure_audio(priv, &audio);
890 else
891 ret = 0;
892
893 if (ret == 0)
894 priv->audio_params = audio;
895 mutex_unlock(&priv->audio_mutex);
896
897 return ret;
898}
899
900static void tda998x_audio_shutdown(struct device *dev, void *data)
826{ 901{
827 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) | 902 struct tda998x_priv *priv = dev_get_drvdata(dev);
828 (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) |
829 VIP_CNTRL_0_SWAP_B(p->swap_b) |
830 (p->mirr_b ? VIP_CNTRL_0_MIRR_B : 0);
831 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(p->swap_c) |
832 (p->mirr_c ? VIP_CNTRL_1_MIRR_C : 0) |
833 VIP_CNTRL_1_SWAP_D(p->swap_d) |
834 (p->mirr_d ? VIP_CNTRL_1_MIRR_D : 0);
835 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(p->swap_e) |
836 (p->mirr_e ? VIP_CNTRL_2_MIRR_E : 0) |
837 VIP_CNTRL_2_SWAP_F(p->swap_f) |
838 (p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0);
839 903
840 priv->audio_params = p->audio_params; 904 mutex_lock(&priv->audio_mutex);
905
906 reg_write(priv, REG_ENA_AP, 0);
907
908 priv->audio_params.format = AFMT_UNUSED;
909
910 mutex_unlock(&priv->audio_mutex);
841} 911}
842 912
843static void tda998x_encoder_dpms(struct drm_encoder *encoder, int mode) 913int tda998x_audio_digital_mute(struct device *dev, void *data, bool enable)
844{ 914{
845 struct tda998x_priv *priv = enc_to_tda998x_priv(encoder); 915 struct tda998x_priv *priv = dev_get_drvdata(dev);
846 916
847 /* we only care about on or off: */ 917 mutex_lock(&priv->audio_mutex);
848 if (mode != DRM_MODE_DPMS_ON)
849 mode = DRM_MODE_DPMS_OFF;
850 918
851 if (mode == priv->dpms) 919 tda998x_audio_mute(priv, enable);
852 return;
853 920
854 switch (mode) { 921 mutex_unlock(&priv->audio_mutex);
855 case DRM_MODE_DPMS_ON: 922 return 0;
856 /* enable video ports, audio will be enabled later */ 923}
857 reg_write(priv, REG_ENA_VP_0, 0xff); 924
858 reg_write(priv, REG_ENA_VP_1, 0xff); 925static int tda998x_audio_get_eld(struct device *dev, void *data,
859 reg_write(priv, REG_ENA_VP_2, 0xff); 926 uint8_t *buf, size_t len)
860 /* set muxing after enabling ports: */ 927{
861 reg_write(priv, REG_VIP_CNTRL_0, priv->vip_cntrl_0); 928 struct tda998x_priv *priv = dev_get_drvdata(dev);
862 reg_write(priv, REG_VIP_CNTRL_1, priv->vip_cntrl_1); 929
863 reg_write(priv, REG_VIP_CNTRL_2, priv->vip_cntrl_2); 930 mutex_lock(&priv->audio_mutex);
864 break; 931 memcpy(buf, priv->connector.eld,
865 case DRM_MODE_DPMS_OFF: 932 min(sizeof(priv->connector.eld), len));
866 /* disable video ports */ 933 mutex_unlock(&priv->audio_mutex);
867 reg_write(priv, REG_ENA_VP_0, 0x00); 934
868 reg_write(priv, REG_ENA_VP_1, 0x00); 935 return 0;
869 reg_write(priv, REG_ENA_VP_2, 0x00); 936}
870 break; 937
938static const struct hdmi_codec_ops audio_codec_ops = {
939 .hw_params = tda998x_audio_hw_params,
940 .audio_shutdown = tda998x_audio_shutdown,
941 .digital_mute = tda998x_audio_digital_mute,
942 .get_eld = tda998x_audio_get_eld,
943};
944
945static int tda998x_audio_codec_init(struct tda998x_priv *priv,
946 struct device *dev)
947{
948 struct hdmi_codec_pdata codec_data = {
949 .ops = &audio_codec_ops,
950 .max_i2s_channels = 2,
951 };
952 int i;
953
954 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++) {
955 if (priv->audio_port[i].format == AFMT_I2S &&
956 priv->audio_port[i].config != 0)
957 codec_data.i2s = 1;
958 if (priv->audio_port[i].format == AFMT_SPDIF &&
959 priv->audio_port[i].config != 0)
960 codec_data.spdif = 1;
871 } 961 }
872 962
873 priv->dpms = mode; 963 priv->audio_pdev = platform_device_register_data(
964 dev, HDMI_CODEC_DRV_NAME, PLATFORM_DEVID_AUTO,
965 &codec_data, sizeof(codec_data));
966
967 return PTR_ERR_OR_ZERO(priv->audio_pdev);
968}
969
970/* DRM connector functions */
971
972static int tda998x_connector_dpms(struct drm_connector *connector, int mode)
973{
974 if (drm_core_check_feature(connector->dev, DRIVER_ATOMIC))
975 return drm_atomic_helper_connector_dpms(connector, mode);
976 else
977 return drm_helper_connector_dpms(connector, mode);
978}
979
980static int tda998x_connector_fill_modes(struct drm_connector *connector,
981 uint32_t maxX, uint32_t maxY)
982{
983 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
984 int ret;
985
986 mutex_lock(&priv->audio_mutex);
987 ret = drm_helper_probe_single_connector_modes(connector, maxX, maxY);
988
989 if (connector->edid_blob_ptr) {
990 struct edid *edid = (void *)connector->edid_blob_ptr->data;
991
992 priv->sink_has_audio = drm_detect_monitor_audio(edid);
993 } else {
994 priv->sink_has_audio = false;
995 }
996 mutex_unlock(&priv->audio_mutex);
997
998 return ret;
999}
1000
1001static enum drm_connector_status
1002tda998x_connector_detect(struct drm_connector *connector, bool force)
1003{
1004 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1005 u8 val = cec_read(priv, REG_CEC_RXSHPDLEV);
1006
1007 return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected :
1008 connector_status_disconnected;
1009}
1010
1011static void tda998x_connector_destroy(struct drm_connector *connector)
1012{
1013 drm_connector_cleanup(connector);
1014}
1015
1016static const struct drm_connector_funcs tda998x_connector_funcs = {
1017 .dpms = tda998x_connector_dpms,
1018 .reset = drm_atomic_helper_connector_reset,
1019 .fill_modes = tda998x_connector_fill_modes,
1020 .detect = tda998x_connector_detect,
1021 .destroy = tda998x_connector_destroy,
1022 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1023 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1024};
1025
1026static int read_edid_block(void *data, u8 *buf, unsigned int blk, size_t length)
1027{
1028 struct tda998x_priv *priv = data;
1029 u8 offset, segptr;
1030 int ret, i;
1031
1032 offset = (blk & 1) ? 128 : 0;
1033 segptr = blk / 2;
1034
1035 reg_write(priv, REG_DDC_ADDR, 0xa0);
1036 reg_write(priv, REG_DDC_OFFS, offset);
1037 reg_write(priv, REG_DDC_SEGM_ADDR, 0x60);
1038 reg_write(priv, REG_DDC_SEGM, segptr);
1039
1040 /* enable reading EDID: */
1041 priv->wq_edid_wait = 1;
1042 reg_write(priv, REG_EDID_CTRL, 0x1);
1043
1044 /* flag must be cleared by sw: */
1045 reg_write(priv, REG_EDID_CTRL, 0x0);
1046
1047 /* wait for block read to complete: */
1048 if (priv->hdmi->irq) {
1049 i = wait_event_timeout(priv->wq_edid,
1050 !priv->wq_edid_wait,
1051 msecs_to_jiffies(100));
1052 if (i < 0) {
1053 dev_err(&priv->hdmi->dev, "read edid wait err %d\n", i);
1054 return i;
1055 }
1056 } else {
1057 for (i = 100; i > 0; i--) {
1058 msleep(1);
1059 ret = reg_read(priv, REG_INT_FLAGS_2);
1060 if (ret < 0)
1061 return ret;
1062 if (ret & INT_FLAGS_2_EDID_BLK_RD)
1063 break;
1064 }
1065 }
1066
1067 if (i == 0) {
1068 dev_err(&priv->hdmi->dev, "read edid timeout\n");
1069 return -ETIMEDOUT;
1070 }
1071
1072 ret = reg_read_range(priv, REG_EDID_DATA_0, buf, length);
1073 if (ret != length) {
1074 dev_err(&priv->hdmi->dev, "failed to read edid block %d: %d\n",
1075 blk, ret);
1076 return ret;
1077 }
1078
1079 return 0;
1080}
1081
1082static int tda998x_connector_get_modes(struct drm_connector *connector)
1083{
1084 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1085 struct edid *edid;
1086 int n;
1087
1088 /*
1089 * If we get killed while waiting for the HPD timeout, return
1090 * no modes found: we are not in a restartable path, so we
1091 * can't handle signals gracefully.
1092 */
1093 if (tda998x_edid_delay_wait(priv))
1094 return 0;
1095
1096 if (priv->rev == TDA19988)
1097 reg_clear(priv, REG_TX4, TX4_PD_RAM);
1098
1099 edid = drm_do_get_edid(connector, read_edid_block, priv);
1100
1101 if (priv->rev == TDA19988)
1102 reg_set(priv, REG_TX4, TX4_PD_RAM);
1103
1104 if (!edid) {
1105 dev_warn(&priv->hdmi->dev, "failed to read EDID\n");
1106 return 0;
1107 }
1108
1109 drm_mode_connector_update_edid_property(connector, edid);
1110 n = drm_add_edid_modes(connector, edid);
1111 drm_edid_to_eld(connector, edid);
1112
1113 kfree(edid);
1114
1115 return n;
874} 1116}
875 1117
876static int tda998x_connector_mode_valid(struct drm_connector *connector, 1118static int tda998x_connector_mode_valid(struct drm_connector *connector,
@@ -888,6 +1130,80 @@ static int tda998x_connector_mode_valid(struct drm_connector *connector,
888 return MODE_OK; 1130 return MODE_OK;
889} 1131}
890 1132
1133static struct drm_encoder *
1134tda998x_connector_best_encoder(struct drm_connector *connector)
1135{
1136 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1137
1138 return &priv->encoder;
1139}
1140
1141static
1142const struct drm_connector_helper_funcs tda998x_connector_helper_funcs = {
1143 .get_modes = tda998x_connector_get_modes,
1144 .mode_valid = tda998x_connector_mode_valid,
1145 .best_encoder = tda998x_connector_best_encoder,
1146};
1147
1148static int tda998x_connector_init(struct tda998x_priv *priv,
1149 struct drm_device *drm)
1150{
1151 struct drm_connector *connector = &priv->connector;
1152 int ret;
1153
1154 connector->interlace_allowed = 1;
1155
1156 if (priv->hdmi->irq)
1157 connector->polled = DRM_CONNECTOR_POLL_HPD;
1158 else
1159 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
1160 DRM_CONNECTOR_POLL_DISCONNECT;
1161
1162 drm_connector_helper_add(connector, &tda998x_connector_helper_funcs);
1163 ret = drm_connector_init(drm, connector, &tda998x_connector_funcs,
1164 DRM_MODE_CONNECTOR_HDMIA);
1165 if (ret)
1166 return ret;
1167
1168 drm_mode_connector_attach_encoder(&priv->connector, &priv->encoder);
1169
1170 return 0;
1171}
1172
1173/* DRM encoder functions */
1174
1175static void tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)
1176{
1177 struct tda998x_priv *priv = enc_to_tda998x_priv(encoder);
1178 bool on;
1179
1180 /* we only care about on or off: */
1181 on = mode == DRM_MODE_DPMS_ON;
1182
1183 if (on == priv->is_on)
1184 return;
1185
1186 if (on) {
1187 /* enable video ports, audio will be enabled later */
1188 reg_write(priv, REG_ENA_VP_0, 0xff);
1189 reg_write(priv, REG_ENA_VP_1, 0xff);
1190 reg_write(priv, REG_ENA_VP_2, 0xff);
1191 /* set muxing after enabling ports: */
1192 reg_write(priv, REG_VIP_CNTRL_0, priv->vip_cntrl_0);
1193 reg_write(priv, REG_VIP_CNTRL_1, priv->vip_cntrl_1);
1194 reg_write(priv, REG_VIP_CNTRL_2, priv->vip_cntrl_2);
1195
1196 priv->is_on = true;
1197 } else {
1198 /* disable video ports */
1199 reg_write(priv, REG_ENA_VP_0, 0x00);
1200 reg_write(priv, REG_ENA_VP_1, 0x00);
1201 reg_write(priv, REG_ENA_VP_2, 0x00);
1202
1203 priv->is_on = false;
1204 }
1205}
1206
891static void 1207static void
892tda998x_encoder_mode_set(struct drm_encoder *encoder, 1208tda998x_encoder_mode_set(struct drm_encoder *encoder,
893 struct drm_display_mode *mode, 1209 struct drm_display_mode *mode,
@@ -971,6 +1287,8 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
971 div = 3; 1287 div = 3;
972 } 1288 }
973 1289
1290 mutex_lock(&priv->audio_mutex);
1291
974 /* mute the audio FIFO: */ 1292 /* mute the audio FIFO: */
975 reg_set(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); 1293 reg_set(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO);
976 1294
@@ -982,6 +1300,7 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
982 /* no pre-filter or interpolator: */ 1300 /* no pre-filter or interpolator: */
983 reg_write(priv, REG_HVF_CNTRL_0, HVF_CNTRL_0_PREFIL(0) | 1301 reg_write(priv, REG_HVF_CNTRL_0, HVF_CNTRL_0_PREFIL(0) |
984 HVF_CNTRL_0_INTPOL(0)); 1302 HVF_CNTRL_0_INTPOL(0));
1303 reg_set(priv, REG_FEAT_POWERDOWN, FEAT_POWERDOWN_PREFILT);
985 reg_write(priv, REG_VIP_CNTRL_5, VIP_CNTRL_5_SP_CNT(0)); 1304 reg_write(priv, REG_VIP_CNTRL_5, VIP_CNTRL_5_SP_CNT(0));
986 reg_write(priv, REG_VIP_CNTRL_4, VIP_CNTRL_4_BLANKIT(0) | 1305 reg_write(priv, REG_VIP_CNTRL_4, VIP_CNTRL_4_BLANKIT(0) |
987 VIP_CNTRL_4_BLC(0)); 1306 VIP_CNTRL_4_BLC(0));
@@ -1004,6 +1323,7 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
1004 /* set color matrix bypass flag: */ 1323 /* set color matrix bypass flag: */
1005 reg_write(priv, REG_MAT_CONTRL, MAT_CONTRL_MAT_BP | 1324 reg_write(priv, REG_MAT_CONTRL, MAT_CONTRL_MAT_BP |
1006 MAT_CONTRL_MAT_SC(1)); 1325 MAT_CONTRL_MAT_SC(1));
1326 reg_set(priv, REG_FEAT_POWERDOWN, FEAT_POWERDOWN_CSC);
1007 1327
1008 /* set BIAS tmds value: */ 1328 /* set BIAS tmds value: */
1009 reg_write(priv, REG_ANA_GENERAL, 0x09); 1329 reg_write(priv, REG_ANA_GENERAL, 0x09);
@@ -1064,8 +1384,22 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
1064 /* must be last register set: */ 1384 /* must be last register set: */
1065 reg_write(priv, REG_TBG_CNTRL_0, 0); 1385 reg_write(priv, REG_TBG_CNTRL_0, 0);
1066 1386
1067 /* Only setup the info frames if the sink is HDMI */ 1387 priv->tmds_clock = adjusted_mode->clock;
1068 if (priv->is_hdmi_sink) { 1388
1389 /* CEA-861B section 6 says that:
1390 * CEA version 1 (CEA-861) has no support for infoframes.
1391 * CEA version 2 (CEA-861A) supports version 1 AVI infoframes,
1392 * and optional basic audio.
1393 * CEA version 3 (CEA-861B) supports version 1 and 2 AVI infoframes,
1394 * and optional digital audio, with audio infoframes.
1395 *
1396 * Since we only support generation of version 2 AVI infoframes,
1397 * ignore CEA version 2 and below (iow, behave as if we're a
1398 * CEA-861 source.)
1399 */
1400 priv->supports_infoframes = priv->connector.display_info.cea_rev >= 3;
1401
1402 if (priv->supports_infoframes) {
1069 /* We need to turn HDMI HDCP stuff on to get audio through */ 1403 /* We need to turn HDMI HDCP stuff on to get audio through */
1070 reg &= ~TBG_CNTRL_1_DWIN_DIS; 1404 reg &= ~TBG_CNTRL_1_DWIN_DIS;
1071 reg_write(priv, REG_TBG_CNTRL_1, reg); 1405 reg_write(priv, REG_TBG_CNTRL_1, reg);
@@ -1074,127 +1408,12 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
1074 1408
1075 tda998x_write_avi(priv, adjusted_mode); 1409 tda998x_write_avi(priv, adjusted_mode);
1076 1410
1077 if (priv->audio_params.format != AFMT_UNUSED) { 1411 if (priv->audio_params.format != AFMT_UNUSED &&
1078 mutex_lock(&priv->audio_mutex); 1412 priv->sink_has_audio)
1079 tda998x_configure_audio(priv, 1413 tda998x_configure_audio(priv, &priv->audio_params);
1080 &priv->audio_params,
1081 adjusted_mode->clock);
1082 mutex_unlock(&priv->audio_mutex);
1083 }
1084 } 1414 }
1085}
1086 1415
1087static enum drm_connector_status 1416 mutex_unlock(&priv->audio_mutex);
1088tda998x_connector_detect(struct drm_connector *connector, bool force)
1089{
1090 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1091 u8 val = cec_read(priv, REG_CEC_RXSHPDLEV);
1092
1093 return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected :
1094 connector_status_disconnected;
1095}
1096
1097static int read_edid_block(void *data, u8 *buf, unsigned int blk, size_t length)
1098{
1099 struct tda998x_priv *priv = data;
1100 u8 offset, segptr;
1101 int ret, i;
1102
1103 offset = (blk & 1) ? 128 : 0;
1104 segptr = blk / 2;
1105
1106 reg_write(priv, REG_DDC_ADDR, 0xa0);
1107 reg_write(priv, REG_DDC_OFFS, offset);
1108 reg_write(priv, REG_DDC_SEGM_ADDR, 0x60);
1109 reg_write(priv, REG_DDC_SEGM, segptr);
1110
1111 /* enable reading EDID: */
1112 priv->wq_edid_wait = 1;
1113 reg_write(priv, REG_EDID_CTRL, 0x1);
1114
1115 /* flag must be cleared by sw: */
1116 reg_write(priv, REG_EDID_CTRL, 0x0);
1117
1118 /* wait for block read to complete: */
1119 if (priv->hdmi->irq) {
1120 i = wait_event_timeout(priv->wq_edid,
1121 !priv->wq_edid_wait,
1122 msecs_to_jiffies(100));
1123 if (i < 0) {
1124 dev_err(&priv->hdmi->dev, "read edid wait err %d\n", i);
1125 return i;
1126 }
1127 } else {
1128 for (i = 100; i > 0; i--) {
1129 msleep(1);
1130 ret = reg_read(priv, REG_INT_FLAGS_2);
1131 if (ret < 0)
1132 return ret;
1133 if (ret & INT_FLAGS_2_EDID_BLK_RD)
1134 break;
1135 }
1136 }
1137
1138 if (i == 0) {
1139 dev_err(&priv->hdmi->dev, "read edid timeout\n");
1140 return -ETIMEDOUT;
1141 }
1142
1143 ret = reg_read_range(priv, REG_EDID_DATA_0, buf, length);
1144 if (ret != length) {
1145 dev_err(&priv->hdmi->dev, "failed to read edid block %d: %d\n",
1146 blk, ret);
1147 return ret;
1148 }
1149
1150 return 0;
1151}
1152
1153static int tda998x_connector_get_modes(struct drm_connector *connector)
1154{
1155 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1156 struct edid *edid;
1157 int n;
1158
1159 /*
1160 * If we get killed while waiting for the HPD timeout, return
1161 * no modes found: we are not in a restartable path, so we
1162 * can't handle signals gracefully.
1163 */
1164 if (tda998x_edid_delay_wait(priv))
1165 return 0;
1166
1167 if (priv->rev == TDA19988)
1168 reg_clear(priv, REG_TX4, TX4_PD_RAM);
1169
1170 edid = drm_do_get_edid(connector, read_edid_block, priv);
1171
1172 if (priv->rev == TDA19988)
1173 reg_set(priv, REG_TX4, TX4_PD_RAM);
1174
1175 if (!edid) {
1176 dev_warn(&priv->hdmi->dev, "failed to read EDID\n");
1177 return 0;
1178 }
1179
1180 drm_mode_connector_update_edid_property(connector, edid);
1181 n = drm_add_edid_modes(connector, edid);
1182 priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid);
1183 drm_edid_to_eld(connector, edid);
1184
1185 kfree(edid);
1186
1187 return n;
1188}
1189
1190static void tda998x_encoder_set_polling(struct tda998x_priv *priv,
1191 struct drm_connector *connector)
1192{
1193 if (priv->hdmi->irq)
1194 connector->polled = DRM_CONNECTOR_POLL_HPD;
1195 else
1196 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
1197 DRM_CONNECTOR_POLL_DISCONNECT;
1198} 1417}
1199 1418
1200static void tda998x_destroy(struct tda998x_priv *priv) 1419static void tda998x_destroy(struct tda998x_priv *priv)
@@ -1215,146 +1434,6 @@ static void tda998x_destroy(struct tda998x_priv *priv)
1215 i2c_unregister_device(priv->cec); 1434 i2c_unregister_device(priv->cec);
1216} 1435}
1217 1436
1218static int tda998x_audio_hw_params(struct device *dev, void *data,
1219 struct hdmi_codec_daifmt *daifmt,
1220 struct hdmi_codec_params *params)
1221{
1222 struct tda998x_priv *priv = dev_get_drvdata(dev);
1223 int i, ret;
1224 struct tda998x_audio_params audio = {
1225 .sample_width = params->sample_width,
1226 .sample_rate = params->sample_rate,
1227 .cea = params->cea,
1228 };
1229
1230 if (!priv->encoder.crtc)
1231 return -ENODEV;
1232
1233 memcpy(audio.status, params->iec.status,
1234 min(sizeof(audio.status), sizeof(params->iec.status)));
1235
1236 switch (daifmt->fmt) {
1237 case HDMI_I2S:
1238 if (daifmt->bit_clk_inv || daifmt->frame_clk_inv ||
1239 daifmt->bit_clk_master || daifmt->frame_clk_master) {
1240 dev_err(dev, "%s: Bad flags %d %d %d %d\n", __func__,
1241 daifmt->bit_clk_inv, daifmt->frame_clk_inv,
1242 daifmt->bit_clk_master,
1243 daifmt->frame_clk_master);
1244 return -EINVAL;
1245 }
1246 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++)
1247 if (priv->audio_port[i].format == AFMT_I2S)
1248 audio.config = priv->audio_port[i].config;
1249 audio.format = AFMT_I2S;
1250 break;
1251 case HDMI_SPDIF:
1252 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++)
1253 if (priv->audio_port[i].format == AFMT_SPDIF)
1254 audio.config = priv->audio_port[i].config;
1255 audio.format = AFMT_SPDIF;
1256 break;
1257 default:
1258 dev_err(dev, "%s: Invalid format %d\n", __func__, daifmt->fmt);
1259 return -EINVAL;
1260 }
1261
1262 if (audio.config == 0) {
1263 dev_err(dev, "%s: No audio configutation found\n", __func__);
1264 return -EINVAL;
1265 }
1266
1267 mutex_lock(&priv->audio_mutex);
1268 ret = tda998x_configure_audio(priv,
1269 &audio,
1270 priv->encoder.crtc->hwmode.clock);
1271
1272 if (ret == 0)
1273 priv->audio_params = audio;
1274 mutex_unlock(&priv->audio_mutex);
1275
1276 return ret;
1277}
1278
1279static void tda998x_audio_shutdown(struct device *dev, void *data)
1280{
1281 struct tda998x_priv *priv = dev_get_drvdata(dev);
1282
1283 mutex_lock(&priv->audio_mutex);
1284
1285 reg_write(priv, REG_ENA_AP, 0);
1286
1287 priv->audio_params.format = AFMT_UNUSED;
1288
1289 mutex_unlock(&priv->audio_mutex);
1290}
1291
1292static int
1293tda998x_audio_digital_mute(struct device *dev, void *data, bool enable)
1294{
1295 struct tda998x_priv *priv = dev_get_drvdata(dev);
1296
1297 mutex_lock(&priv->audio_mutex);
1298
1299 tda998x_audio_mute(priv, enable);
1300
1301 mutex_unlock(&priv->audio_mutex);
1302 return 0;
1303}
1304
1305static int tda998x_audio_get_eld(struct device *dev, void *data,
1306 uint8_t *buf, size_t len)
1307{
1308 struct tda998x_priv *priv = dev_get_drvdata(dev);
1309 struct drm_mode_config *config = &priv->encoder.dev->mode_config;
1310 struct drm_connector *connector;
1311 int ret = -ENODEV;
1312
1313 mutex_lock(&config->mutex);
1314 list_for_each_entry(connector, &config->connector_list, head) {
1315 if (&priv->encoder == connector->encoder) {
1316 memcpy(buf, connector->eld,
1317 min(sizeof(connector->eld), len));
1318 ret = 0;
1319 }
1320 }
1321 mutex_unlock(&config->mutex);
1322
1323 return ret;
1324}
1325
1326static const struct hdmi_codec_ops audio_codec_ops = {
1327 .hw_params = tda998x_audio_hw_params,
1328 .audio_shutdown = tda998x_audio_shutdown,
1329 .digital_mute = tda998x_audio_digital_mute,
1330 .get_eld = tda998x_audio_get_eld,
1331};
1332
1333static int tda998x_audio_codec_init(struct tda998x_priv *priv,
1334 struct device *dev)
1335{
1336 struct hdmi_codec_pdata codec_data = {
1337 .ops = &audio_codec_ops,
1338 .max_i2s_channels = 2,
1339 };
1340 int i;
1341
1342 for (i = 0; i < ARRAY_SIZE(priv->audio_port); i++) {
1343 if (priv->audio_port[i].format == AFMT_I2S &&
1344 priv->audio_port[i].config != 0)
1345 codec_data.i2s = 1;
1346 if (priv->audio_port[i].format == AFMT_SPDIF &&
1347 priv->audio_port[i].config != 0)
1348 codec_data.spdif = 1;
1349 }
1350
1351 priv->audio_pdev = platform_device_register_data(
1352 dev, HDMI_CODEC_DRV_NAME, PLATFORM_DEVID_AUTO,
1353 &codec_data, sizeof(codec_data));
1354
1355 return PTR_ERR_OR_ZERO(priv->audio_pdev);
1356}
1357
1358/* I2C driver functions */ 1437/* I2C driver functions */
1359 1438
1360static int tda998x_get_audio_ports(struct tda998x_priv *priv, 1439static int tda998x_get_audio_ports(struct tda998x_priv *priv,
@@ -1404,22 +1483,21 @@ static int tda998x_create(struct i2c_client *client, struct tda998x_priv *priv)
1404 struct device_node *np = client->dev.of_node; 1483 struct device_node *np = client->dev.of_node;
1405 u32 video; 1484 u32 video;
1406 int rev_lo, rev_hi, ret; 1485 int rev_lo, rev_hi, ret;
1407 unsigned short cec_addr; 1486
1487 mutex_init(&priv->audio_mutex); /* Protect access from audio thread */
1408 1488
1409 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3); 1489 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3);
1410 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1); 1490 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1);
1411 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5); 1491 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5);
1412 1492
1493 /* CEC I2C address bound to TDA998x I2C addr by configuration pins */
1494 priv->cec_addr = 0x34 + (client->addr & 0x03);
1413 priv->current_page = 0xff; 1495 priv->current_page = 0xff;
1414 priv->hdmi = client; 1496 priv->hdmi = client;
1415 /* CEC I2C address bound to TDA998x I2C addr by configuration pins */ 1497 priv->cec = i2c_new_dummy(client->adapter, priv->cec_addr);
1416 cec_addr = 0x34 + (client->addr & 0x03);
1417 priv->cec = i2c_new_dummy(client->adapter, cec_addr);
1418 if (!priv->cec) 1498 if (!priv->cec)
1419 return -ENODEV; 1499 return -ENODEV;
1420 1500
1421 priv->dpms = DRM_MODE_DPMS_OFF;
1422
1423 mutex_init(&priv->mutex); /* protect the page access */ 1501 mutex_init(&priv->mutex); /* protect the page access */
1424 init_waitqueue_head(&priv->edid_delay_waitq); 1502 init_waitqueue_head(&priv->edid_delay_waitq);
1425 setup_timer(&priv->edid_delay_timer, tda998x_edid_delay_done, 1503 setup_timer(&priv->edid_delay_timer, tda998x_edid_delay_done,
@@ -1479,7 +1557,7 @@ static int tda998x_create(struct i2c_client *client, struct tda998x_priv *priv)
1479 1557
1480 /* initialize the optional IRQ */ 1558 /* initialize the optional IRQ */
1481 if (client->irq) { 1559 if (client->irq) {
1482 int irqf_trigger; 1560 unsigned long irq_flags;
1483 1561
1484 /* init read EDID waitqueue and HDP work */ 1562 /* init read EDID waitqueue and HDP work */
1485 init_waitqueue_head(&priv->wq_edid); 1563 init_waitqueue_head(&priv->wq_edid);
@@ -1489,11 +1567,11 @@ static int tda998x_create(struct i2c_client *client, struct tda998x_priv *priv)
1489 reg_read(priv, REG_INT_FLAGS_1); 1567 reg_read(priv, REG_INT_FLAGS_1);
1490 reg_read(priv, REG_INT_FLAGS_2); 1568 reg_read(priv, REG_INT_FLAGS_2);
1491 1569
1492 irqf_trigger = 1570 irq_flags =
1493 irqd_get_trigger_type(irq_get_irq_data(client->irq)); 1571 irqd_get_trigger_type(irq_get_irq_data(client->irq));
1572 irq_flags |= IRQF_SHARED | IRQF_ONESHOT;
1494 ret = request_threaded_irq(client->irq, NULL, 1573 ret = request_threaded_irq(client->irq, NULL,
1495 tda998x_irq_thread, 1574 tda998x_irq_thread, irq_flags,
1496 irqf_trigger | IRQF_ONESHOT,
1497 "tda998x", priv); 1575 "tda998x", priv);
1498 if (ret) { 1576 if (ret) {
1499 dev_err(&client->dev, 1577 dev_err(&client->dev,
@@ -1520,8 +1598,6 @@ static int tda998x_create(struct i2c_client *client, struct tda998x_priv *priv)
1520 priv->vip_cntrl_2 = video; 1598 priv->vip_cntrl_2 = video;
1521 } 1599 }
1522 1600
1523 mutex_init(&priv->audio_mutex); /* Protect access from audio thread */
1524
1525 ret = tda998x_get_audio_ports(priv, np); 1601 ret = tda998x_get_audio_ports(priv, np);
1526 if (ret) 1602 if (ret)
1527 goto fail; 1603 goto fail;
@@ -1568,44 +1644,25 @@ static const struct drm_encoder_funcs tda998x_encoder_funcs = {
1568 .destroy = tda998x_encoder_destroy, 1644 .destroy = tda998x_encoder_destroy,
1569}; 1645};
1570 1646
1571static struct drm_encoder * 1647static void tda998x_set_config(struct tda998x_priv *priv,
1572tda998x_connector_best_encoder(struct drm_connector *connector) 1648 const struct tda998x_encoder_params *p)
1573{
1574 struct tda998x_priv *priv = conn_to_tda998x_priv(connector);
1575
1576 return &priv->encoder;
1577}
1578
1579static
1580const struct drm_connector_helper_funcs tda998x_connector_helper_funcs = {
1581 .get_modes = tda998x_connector_get_modes,
1582 .mode_valid = tda998x_connector_mode_valid,
1583 .best_encoder = tda998x_connector_best_encoder,
1584};
1585
1586static void tda998x_connector_destroy(struct drm_connector *connector)
1587{ 1649{
1588 drm_connector_cleanup(connector); 1650 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) |
1589} 1651 (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) |
1652 VIP_CNTRL_0_SWAP_B(p->swap_b) |
1653 (p->mirr_b ? VIP_CNTRL_0_MIRR_B : 0);
1654 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(p->swap_c) |
1655 (p->mirr_c ? VIP_CNTRL_1_MIRR_C : 0) |
1656 VIP_CNTRL_1_SWAP_D(p->swap_d) |
1657 (p->mirr_d ? VIP_CNTRL_1_MIRR_D : 0);
1658 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(p->swap_e) |
1659 (p->mirr_e ? VIP_CNTRL_2_MIRR_E : 0) |
1660 VIP_CNTRL_2_SWAP_F(p->swap_f) |
1661 (p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0);
1590 1662
1591static int tda998x_connector_dpms(struct drm_connector *connector, int mode) 1663 priv->audio_params = p->audio_params;
1592{
1593 if (drm_core_check_feature(connector->dev, DRIVER_ATOMIC))
1594 return drm_atomic_helper_connector_dpms(connector, mode);
1595 else
1596 return drm_helper_connector_dpms(connector, mode);
1597} 1664}
1598 1665
1599static const struct drm_connector_funcs tda998x_connector_funcs = {
1600 .dpms = tda998x_connector_dpms,
1601 .reset = drm_atomic_helper_connector_reset,
1602 .fill_modes = drm_helper_probe_single_connector_modes,
1603 .detect = tda998x_connector_detect,
1604 .destroy = tda998x_connector_destroy,
1605 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1606 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1607};
1608
1609static int tda998x_bind(struct device *dev, struct device *master, void *data) 1666static int tda998x_bind(struct device *dev, struct device *master, void *data)
1610{ 1667{
1611 struct tda998x_encoder_params *params = dev->platform_data; 1668 struct tda998x_encoder_params *params = dev->platform_data;
@@ -1630,7 +1687,6 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)
1630 crtcs = 1 << 0; 1687 crtcs = 1 << 0;
1631 } 1688 }
1632 1689
1633 priv->connector.interlace_allowed = 1;
1634 priv->encoder.possible_crtcs = crtcs; 1690 priv->encoder.possible_crtcs = crtcs;
1635 1691
1636 ret = tda998x_create(client, priv); 1692 ret = tda998x_create(client, priv);
@@ -1638,9 +1694,7 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)
1638 return ret; 1694 return ret;
1639 1695
1640 if (!dev->of_node && params) 1696 if (!dev->of_node && params)
1641 tda998x_encoder_set_config(priv, params); 1697 tda998x_set_config(priv, params);
1642
1643 tda998x_encoder_set_polling(priv, &priv->connector);
1644 1698
1645 drm_encoder_helper_add(&priv->encoder, &tda998x_encoder_helper_funcs); 1699 drm_encoder_helper_add(&priv->encoder, &tda998x_encoder_helper_funcs);
1646 ret = drm_encoder_init(drm, &priv->encoder, &tda998x_encoder_funcs, 1700 ret = drm_encoder_init(drm, &priv->encoder, &tda998x_encoder_funcs,
@@ -1648,16 +1702,10 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)
1648 if (ret) 1702 if (ret)
1649 goto err_encoder; 1703 goto err_encoder;
1650 1704
1651 drm_connector_helper_add(&priv->connector, 1705 ret = tda998x_connector_init(priv, drm);
1652 &tda998x_connector_helper_funcs);
1653 ret = drm_connector_init(drm, &priv->connector,
1654 &tda998x_connector_funcs,
1655 DRM_MODE_CONNECTOR_HDMIA);
1656 if (ret) 1706 if (ret)
1657 goto err_connector; 1707 goto err_connector;
1658 1708
1659 drm_mode_connector_attach_encoder(&priv->connector, &priv->encoder);
1660
1661 return 0; 1709 return 0;
1662 1710
1663err_connector: 1711err_connector:
@@ -1685,6 +1733,10 @@ static const struct component_ops tda998x_ops = {
1685static int 1733static int
1686tda998x_probe(struct i2c_client *client, const struct i2c_device_id *id) 1734tda998x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1687{ 1735{
1736 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1737 dev_warn(&client->dev, "adapter does not support I2C\n");
1738 return -EIO;
1739 }
1688 return component_add(&client->dev, &tda998x_ops); 1740 return component_add(&client->dev, &tda998x_ops);
1689} 1741}
1690 1742