diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2013-08-14 15:43:30 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2013-08-18 19:10:32 -0400 |
commit | c4c11dd160a8cc98f402c4e12f94b1572e822ffd (patch) | |
tree | 2dfd698b8d5ba7e5fe352a68ee32b720d86639b8 | |
parent | 5e74c22cd1e0f9e49573fe580de47e198ee04975 (diff) |
drm/i2c: tda998x: add video and audio input configuration
This patch adds tda998x specific parameters to allow it to be configured
for different boards using it. Also, this implements rudimentary audio
support for S/PDIF attached controllers.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Tested-by: Darren Etheridge <detheridge@ti.com>
Tested-by: Russell King <rmk_kernel@arm.linux.org.uk>
Tested-by: Russell King <rmk_kernel@arm.linux.org.uk>
Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r-- | drivers/gpu/drm/i2c/tda998x_drv.c | 268 | ||||
-rw-r--r-- | include/drm/i2c/tda998x.h | 30 |
2 files changed, 290 insertions, 8 deletions
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index 527d11b5ff14..2b64dfa60205 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <drm/drm_crtc_helper.h> | 23 | #include <drm/drm_crtc_helper.h> |
24 | #include <drm/drm_encoder_slave.h> | 24 | #include <drm/drm_encoder_slave.h> |
25 | #include <drm/drm_edid.h> | 25 | #include <drm/drm_edid.h> |
26 | 26 | #include <drm/i2c/tda998x.h> | |
27 | 27 | ||
28 | #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) | 28 | #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) |
29 | 29 | ||
@@ -32,9 +32,11 @@ struct tda998x_priv { | |||
32 | uint16_t rev; | 32 | uint16_t rev; |
33 | uint8_t current_page; | 33 | uint8_t current_page; |
34 | int dpms; | 34 | int dpms; |
35 | bool is_hdmi_sink; | ||
35 | u8 vip_cntrl_0; | 36 | u8 vip_cntrl_0; |
36 | u8 vip_cntrl_1; | 37 | u8 vip_cntrl_1; |
37 | u8 vip_cntrl_2; | 38 | u8 vip_cntrl_2; |
39 | struct tda998x_encoder_params params; | ||
38 | }; | 40 | }; |
39 | 41 | ||
40 | #define to_tda998x_priv(x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv) | 42 | #define to_tda998x_priv(x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv) |
@@ -71,10 +73,13 @@ struct tda998x_priv { | |||
71 | # define I2C_MASTER_DIS_MM (1 << 0) | 73 | # define I2C_MASTER_DIS_MM (1 << 0) |
72 | # define I2C_MASTER_DIS_FILT (1 << 1) | 74 | # define I2C_MASTER_DIS_FILT (1 << 1) |
73 | # define I2C_MASTER_APP_STRT_LAT (1 << 2) | 75 | # define I2C_MASTER_APP_STRT_LAT (1 << 2) |
76 | #define REG_FEAT_POWERDOWN REG(0x00, 0x0e) /* read/write */ | ||
77 | # define FEAT_POWERDOWN_SPDIF (1 << 3) | ||
74 | #define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */ | 78 | #define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */ |
75 | #define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */ | 79 | #define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */ |
76 | #define REG_INT_FLAGS_2 REG(0x00, 0x11) /* read/write */ | 80 | #define REG_INT_FLAGS_2 REG(0x00, 0x11) /* read/write */ |
77 | # define INT_FLAGS_2_EDID_BLK_RD (1 << 1) | 81 | # define INT_FLAGS_2_EDID_BLK_RD (1 << 1) |
82 | #define REG_ENA_ACLK REG(0x00, 0x16) /* read/write */ | ||
78 | #define REG_ENA_VP_0 REG(0x00, 0x18) /* read/write */ | 83 | #define REG_ENA_VP_0 REG(0x00, 0x18) /* read/write */ |
79 | #define REG_ENA_VP_1 REG(0x00, 0x19) /* read/write */ | 84 | #define REG_ENA_VP_1 REG(0x00, 0x19) /* read/write */ |
80 | #define REG_ENA_VP_2 REG(0x00, 0x1a) /* read/write */ | 85 | #define REG_ENA_VP_2 REG(0x00, 0x1a) /* read/write */ |
@@ -113,6 +118,7 @@ struct tda998x_priv { | |||
113 | #define REG_VIP_CNTRL_5 REG(0x00, 0x25) /* write */ | 118 | #define REG_VIP_CNTRL_5 REG(0x00, 0x25) /* write */ |
114 | # define VIP_CNTRL_5_CKCASE (1 << 0) | 119 | # define VIP_CNTRL_5_CKCASE (1 << 0) |
115 | # define VIP_CNTRL_5_SP_CNT(x) (((x) & 3) << 1) | 120 | # define VIP_CNTRL_5_SP_CNT(x) (((x) & 3) << 1) |
121 | #define REG_MUX_AP REG(0x00, 0x26) /* read/write */ | ||
116 | #define REG_MUX_VP_VIP_OUT REG(0x00, 0x27) /* read/write */ | 122 | #define REG_MUX_VP_VIP_OUT REG(0x00, 0x27) /* read/write */ |
117 | #define REG_MAT_CONTRL REG(0x00, 0x80) /* write */ | 123 | #define REG_MAT_CONTRL REG(0x00, 0x80) /* write */ |
118 | # define MAT_CONTRL_MAT_SC(x) (((x) & 3) << 0) | 124 | # define MAT_CONTRL_MAT_SC(x) (((x) & 3) << 0) |
@@ -175,6 +181,12 @@ struct tda998x_priv { | |||
175 | # define HVF_CNTRL_1_PAD(x) (((x) & 3) << 4) | 181 | # define HVF_CNTRL_1_PAD(x) (((x) & 3) << 4) |
176 | # define HVF_CNTRL_1_SEMI_PLANAR (1 << 6) | 182 | # define HVF_CNTRL_1_SEMI_PLANAR (1 << 6) |
177 | #define REG_RPT_CNTRL REG(0x00, 0xf0) /* write */ | 183 | #define REG_RPT_CNTRL REG(0x00, 0xf0) /* write */ |
184 | #define REG_I2S_FORMAT REG(0x00, 0xfc) /* read/write */ | ||
185 | # define I2S_FORMAT(x) (((x) & 3) << 0) | ||
186 | #define REG_AIP_CLKSEL REG(0x00, 0xfd) /* write */ | ||
187 | # define AIP_CLKSEL_FS(x) (((x) & 3) << 0) | ||
188 | # define AIP_CLKSEL_CLK_POL(x) (((x) & 1) << 2) | ||
189 | # define AIP_CLKSEL_AIP(x) (((x) & 7) << 3) | ||
178 | 190 | ||
179 | 191 | ||
180 | /* Page 02h: PLL settings */ | 192 | /* Page 02h: PLL settings */ |
@@ -198,6 +210,12 @@ struct tda998x_priv { | |||
198 | #define REG_PLL_SCGR1 REG(0x02, 0x09) /* read/write */ | 210 | #define REG_PLL_SCGR1 REG(0x02, 0x09) /* read/write */ |
199 | #define REG_PLL_SCGR2 REG(0x02, 0x0a) /* read/write */ | 211 | #define REG_PLL_SCGR2 REG(0x02, 0x0a) /* read/write */ |
200 | #define REG_AUDIO_DIV REG(0x02, 0x0e) /* read/write */ | 212 | #define REG_AUDIO_DIV REG(0x02, 0x0e) /* read/write */ |
213 | # define AUDIO_DIV_SERCLK_1 0 | ||
214 | # define AUDIO_DIV_SERCLK_2 1 | ||
215 | # define AUDIO_DIV_SERCLK_4 2 | ||
216 | # define AUDIO_DIV_SERCLK_8 3 | ||
217 | # define AUDIO_DIV_SERCLK_16 4 | ||
218 | # define AUDIO_DIV_SERCLK_32 5 | ||
201 | #define REG_SEL_CLK REG(0x02, 0x11) /* read/write */ | 219 | #define REG_SEL_CLK REG(0x02, 0x11) /* read/write */ |
202 | # define SEL_CLK_SEL_CLK1 (1 << 0) | 220 | # define SEL_CLK_SEL_CLK1 (1 << 0) |
203 | # define SEL_CLK_SEL_VRF_CLK(x) (((x) & 3) << 1) | 221 | # define SEL_CLK_SEL_VRF_CLK(x) (((x) & 3) << 1) |
@@ -216,6 +234,11 @@ struct tda998x_priv { | |||
216 | 234 | ||
217 | 235 | ||
218 | /* Page 10h: information frames and packets */ | 236 | /* Page 10h: information frames and packets */ |
237 | #define REG_IF1_HB0 REG(0x10, 0x20) /* read/write */ | ||
238 | #define REG_IF2_HB0 REG(0x10, 0x40) /* read/write */ | ||
239 | #define REG_IF3_HB0 REG(0x10, 0x60) /* read/write */ | ||
240 | #define REG_IF4_HB0 REG(0x10, 0x80) /* read/write */ | ||
241 | #define REG_IF5_HB0 REG(0x10, 0xa0) /* read/write */ | ||
219 | 242 | ||
220 | 243 | ||
221 | /* Page 11h: audio settings and content info packets */ | 244 | /* Page 11h: audio settings and content info packets */ |
@@ -225,10 +248,33 @@ struct tda998x_priv { | |||
225 | # define AIP_CNTRL_0_LAYOUT (1 << 2) | 248 | # define AIP_CNTRL_0_LAYOUT (1 << 2) |
226 | # define AIP_CNTRL_0_ACR_MAN (1 << 5) | 249 | # define AIP_CNTRL_0_ACR_MAN (1 << 5) |
227 | # define AIP_CNTRL_0_RST_CTS (1 << 6) | 250 | # define AIP_CNTRL_0_RST_CTS (1 << 6) |
251 | #define REG_CA_I2S REG(0x11, 0x01) /* read/write */ | ||
252 | # define CA_I2S_CA_I2S(x) (((x) & 31) << 0) | ||
253 | # define CA_I2S_HBR_CHSTAT (1 << 6) | ||
254 | #define REG_LATENCY_RD REG(0x11, 0x04) /* read/write */ | ||
255 | #define REG_ACR_CTS_0 REG(0x11, 0x05) /* read/write */ | ||
256 | #define REG_ACR_CTS_1 REG(0x11, 0x06) /* read/write */ | ||
257 | #define REG_ACR_CTS_2 REG(0x11, 0x07) /* read/write */ | ||
258 | #define REG_ACR_N_0 REG(0x11, 0x08) /* read/write */ | ||
259 | #define REG_ACR_N_1 REG(0x11, 0x09) /* read/write */ | ||
260 | #define REG_ACR_N_2 REG(0x11, 0x0a) /* read/write */ | ||
261 | #define REG_CTS_N REG(0x11, 0x0c) /* read/write */ | ||
262 | # define CTS_N_K(x) (((x) & 7) << 0) | ||
263 | # define CTS_N_M(x) (((x) & 3) << 4) | ||
228 | #define REG_ENC_CNTRL REG(0x11, 0x0d) /* read/write */ | 264 | #define REG_ENC_CNTRL REG(0x11, 0x0d) /* read/write */ |
229 | # define ENC_CNTRL_RST_ENC (1 << 0) | 265 | # define ENC_CNTRL_RST_ENC (1 << 0) |
230 | # define ENC_CNTRL_RST_SEL (1 << 1) | 266 | # define ENC_CNTRL_RST_SEL (1 << 1) |
231 | # define ENC_CNTRL_CTL_CODE(x) (((x) & 3) << 2) | 267 | # define ENC_CNTRL_CTL_CODE(x) (((x) & 3) << 2) |
268 | #define REG_DIP_FLAGS REG(0x11, 0x0e) /* read/write */ | ||
269 | # define DIP_FLAGS_ACR (1 << 0) | ||
270 | # define DIP_FLAGS_GC (1 << 1) | ||
271 | #define REG_DIP_IF_FLAGS REG(0x11, 0x0f) /* read/write */ | ||
272 | # define DIP_IF_FLAGS_IF1 (1 << 1) | ||
273 | # define DIP_IF_FLAGS_IF2 (1 << 2) | ||
274 | # define DIP_IF_FLAGS_IF3 (1 << 3) | ||
275 | # define DIP_IF_FLAGS_IF4 (1 << 4) | ||
276 | # define DIP_IF_FLAGS_IF5 (1 << 5) | ||
277 | #define REG_CH_STAT_B(x) REG(0x11, 0x14 + (x)) /* read/write */ | ||
232 | 278 | ||
233 | 279 | ||
234 | /* Page 12h: HDCP and OTP */ | 280 | /* Page 12h: HDCP and OTP */ |
@@ -344,6 +390,23 @@ fail: | |||
344 | return ret; | 390 | return ret; |
345 | } | 391 | } |
346 | 392 | ||
393 | static void | ||
394 | reg_write_range(struct drm_encoder *encoder, uint16_t reg, uint8_t *p, int cnt) | ||
395 | { | ||
396 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); | ||
397 | uint8_t buf[cnt+1]; | ||
398 | int ret; | ||
399 | |||
400 | buf[0] = REG2ADDR(reg); | ||
401 | memcpy(&buf[1], p, cnt); | ||
402 | |||
403 | set_page(encoder, reg); | ||
404 | |||
405 | ret = i2c_master_send(client, buf, cnt + 1); | ||
406 | if (ret < 0) | ||
407 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); | ||
408 | } | ||
409 | |||
347 | static uint8_t | 410 | static uint8_t |
348 | reg_read(struct drm_encoder *encoder, uint16_t reg) | 411 | reg_read(struct drm_encoder *encoder, uint16_t reg) |
349 | { | 412 | { |
@@ -412,7 +475,7 @@ tda998x_reset(struct drm_encoder *encoder) | |||
412 | reg_write(encoder, REG_SERIALIZER, 0x00); | 475 | reg_write(encoder, REG_SERIALIZER, 0x00); |
413 | reg_write(encoder, REG_BUFFER_OUT, 0x00); | 476 | reg_write(encoder, REG_BUFFER_OUT, 0x00); |
414 | reg_write(encoder, REG_PLL_SCG1, 0x00); | 477 | reg_write(encoder, REG_PLL_SCG1, 0x00); |
415 | reg_write(encoder, REG_AUDIO_DIV, 0x03); | 478 | reg_write(encoder, REG_AUDIO_DIV, AUDIO_DIV_SERCLK_8); |
416 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); | 479 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); |
417 | reg_write(encoder, REG_PLL_SCGN1, 0xfa); | 480 | reg_write(encoder, REG_PLL_SCGN1, 0xfa); |
418 | reg_write(encoder, REG_PLL_SCGN2, 0x00); | 481 | reg_write(encoder, REG_PLL_SCGN2, 0x00); |
@@ -424,11 +487,184 @@ tda998x_reset(struct drm_encoder *encoder) | |||
424 | reg_write(encoder, REG_MUX_VP_VIP_OUT, 0x24); | 487 | reg_write(encoder, REG_MUX_VP_VIP_OUT, 0x24); |
425 | } | 488 | } |
426 | 489 | ||
490 | static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes) | ||
491 | { | ||
492 | uint8_t sum = 0; | ||
493 | |||
494 | while (bytes--) | ||
495 | sum += *buf++; | ||
496 | return (255 - sum) + 1; | ||
497 | } | ||
498 | |||
499 | #define HB(x) (x) | ||
500 | #define PB(x) (HB(2) + 1 + (x)) | ||
501 | |||
502 | static void | ||
503 | tda998x_write_if(struct drm_encoder *encoder, uint8_t bit, uint16_t addr, | ||
504 | uint8_t *buf, size_t size) | ||
505 | { | ||
506 | buf[PB(0)] = tda998x_cksum(buf, size); | ||
507 | |||
508 | reg_clear(encoder, REG_DIP_IF_FLAGS, bit); | ||
509 | reg_write_range(encoder, addr, buf, size); | ||
510 | reg_set(encoder, REG_DIP_IF_FLAGS, bit); | ||
511 | } | ||
512 | |||
513 | static void | ||
514 | tda998x_write_aif(struct drm_encoder *encoder, struct tda998x_encoder_params *p) | ||
515 | { | ||
516 | uint8_t buf[PB(5) + 1]; | ||
517 | |||
518 | buf[HB(0)] = 0x84; | ||
519 | buf[HB(1)] = 0x01; | ||
520 | buf[HB(2)] = 10; | ||
521 | buf[PB(0)] = 0; | ||
522 | buf[PB(1)] = p->audio_frame[1] & 0x07; /* CC */ | ||
523 | buf[PB(2)] = p->audio_frame[2] & 0x1c; /* SF */ | ||
524 | buf[PB(4)] = p->audio_frame[4]; | ||
525 | buf[PB(5)] = p->audio_frame[5] & 0xf8; /* DM_INH + LSV */ | ||
526 | |||
527 | tda998x_write_if(encoder, DIP_IF_FLAGS_IF4, REG_IF4_HB0, buf, | ||
528 | sizeof(buf)); | ||
529 | } | ||
530 | |||
531 | static void | ||
532 | tda998x_write_avi(struct drm_encoder *encoder, struct drm_display_mode *mode) | ||
533 | { | ||
534 | uint8_t buf[PB(13) + 1]; | ||
535 | |||
536 | memset(buf, 0, sizeof(buf)); | ||
537 | buf[HB(0)] = 0x82; | ||
538 | buf[HB(1)] = 0x02; | ||
539 | buf[HB(2)] = 13; | ||
540 | buf[PB(4)] = drm_match_cea_mode(mode); | ||
541 | |||
542 | tda998x_write_if(encoder, DIP_IF_FLAGS_IF2, REG_IF2_HB0, buf, | ||
543 | sizeof(buf)); | ||
544 | } | ||
545 | |||
546 | static void tda998x_audio_mute(struct drm_encoder *encoder, bool on) | ||
547 | { | ||
548 | if (on) { | ||
549 | reg_set(encoder, REG_SOFTRESET, SOFTRESET_AUDIO); | ||
550 | reg_clear(encoder, REG_SOFTRESET, SOFTRESET_AUDIO); | ||
551 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); | ||
552 | } else { | ||
553 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); | ||
554 | } | ||
555 | } | ||
556 | |||
557 | static void | ||
558 | tda998x_configure_audio(struct drm_encoder *encoder, | ||
559 | struct drm_display_mode *mode, struct tda998x_encoder_params *p) | ||
560 | { | ||
561 | uint8_t buf[6], clksel_aip, clksel_fs, ca_i2s, cts_n, adiv; | ||
562 | uint32_t n; | ||
563 | |||
564 | /* Enable audio ports */ | ||
565 | reg_write(encoder, REG_ENA_AP, p->audio_cfg); | ||
566 | reg_write(encoder, REG_ENA_ACLK, p->audio_clk_cfg); | ||
567 | |||
568 | /* Set audio input source */ | ||
569 | switch (p->audio_format) { | ||
570 | case AFMT_SPDIF: | ||
571 | reg_write(encoder, REG_MUX_AP, 0x40); | ||
572 | clksel_aip = AIP_CLKSEL_AIP(0); | ||
573 | /* FS64SPDIF */ | ||
574 | clksel_fs = AIP_CLKSEL_FS(2); | ||
575 | cts_n = CTS_N_M(3) | CTS_N_K(3); | ||
576 | ca_i2s = 0; | ||
577 | break; | ||
578 | |||
579 | case AFMT_I2S: | ||
580 | reg_write(encoder, REG_MUX_AP, 0x64); | ||
581 | clksel_aip = AIP_CLKSEL_AIP(1); | ||
582 | /* ACLK */ | ||
583 | clksel_fs = AIP_CLKSEL_FS(0); | ||
584 | cts_n = CTS_N_M(3) | CTS_N_K(3); | ||
585 | ca_i2s = CA_I2S_CA_I2S(0); | ||
586 | break; | ||
587 | } | ||
588 | |||
589 | reg_write(encoder, REG_AIP_CLKSEL, clksel_aip); | ||
590 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_LAYOUT); | ||
591 | |||
592 | /* Enable automatic CTS generation */ | ||
593 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_ACR_MAN); | ||
594 | reg_write(encoder, REG_CTS_N, cts_n); | ||
595 | |||
596 | /* | ||
597 | * Audio input somehow depends on HDMI line rate which is | ||
598 | * related to pixclk. Testing showed that modes with pixclk | ||
599 | * >100MHz need a larger divider while <40MHz need the default. | ||
600 | * There is no detailed info in the datasheet, so we just | ||
601 | * assume 100MHz requires larger divider. | ||
602 | */ | ||
603 | if (mode->clock > 100000) | ||
604 | adiv = AUDIO_DIV_SERCLK_16; | ||
605 | else | ||
606 | adiv = AUDIO_DIV_SERCLK_8; | ||
607 | reg_write(encoder, REG_AUDIO_DIV, adiv); | ||
608 | |||
609 | /* | ||
610 | * This is the approximate value of N, which happens to be | ||
611 | * the recommended values for non-coherent clocks. | ||
612 | */ | ||
613 | n = 128 * p->audio_sample_rate / 1000; | ||
614 | |||
615 | /* Write the CTS and N values */ | ||
616 | buf[0] = 0x44; | ||
617 | buf[1] = 0x42; | ||
618 | buf[2] = 0x01; | ||
619 | buf[3] = n; | ||
620 | buf[4] = n >> 8; | ||
621 | buf[5] = n >> 16; | ||
622 | reg_write_range(encoder, REG_ACR_CTS_0, buf, 6); | ||
623 | |||
624 | /* Set CTS clock reference */ | ||
625 | reg_write(encoder, REG_AIP_CLKSEL, clksel_aip | clksel_fs); | ||
626 | |||
627 | /* Reset CTS generator */ | ||
628 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS); | ||
629 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS); | ||
630 | |||
631 | /* Write the channel status */ | ||
632 | buf[0] = 0x04; | ||
633 | buf[1] = 0x00; | ||
634 | buf[2] = 0x00; | ||
635 | buf[3] = 0xf1; | ||
636 | reg_write_range(encoder, REG_CH_STAT_B(0), buf, 4); | ||
637 | |||
638 | tda998x_audio_mute(encoder, true); | ||
639 | mdelay(20); | ||
640 | tda998x_audio_mute(encoder, false); | ||
641 | |||
642 | /* Write the audio information packet */ | ||
643 | tda998x_write_aif(encoder, p); | ||
644 | } | ||
645 | |||
427 | /* DRM encoder functions */ | 646 | /* DRM encoder functions */ |
428 | 647 | ||
429 | static void | 648 | static void |
430 | tda998x_encoder_set_config(struct drm_encoder *encoder, void *params) | 649 | tda998x_encoder_set_config(struct drm_encoder *encoder, void *params) |
431 | { | 650 | { |
651 | struct tda998x_priv *priv = to_tda998x_priv(encoder); | ||
652 | struct tda998x_encoder_params *p = params; | ||
653 | |||
654 | priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) | | ||
655 | (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) | | ||
656 | VIP_CNTRL_0_SWAP_B(p->swap_b) | | ||
657 | (p->mirr_b ? VIP_CNTRL_0_MIRR_B : 0); | ||
658 | priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(p->swap_c) | | ||
659 | (p->mirr_c ? VIP_CNTRL_1_MIRR_C : 0) | | ||
660 | VIP_CNTRL_1_SWAP_D(p->swap_d) | | ||
661 | (p->mirr_d ? VIP_CNTRL_1_MIRR_D : 0); | ||
662 | priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(p->swap_e) | | ||
663 | (p->mirr_e ? VIP_CNTRL_2_MIRR_E : 0) | | ||
664 | VIP_CNTRL_2_SWAP_F(p->swap_f) | | ||
665 | (p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0); | ||
666 | |||
667 | priv->params = *p; | ||
432 | } | 668 | } |
433 | 669 | ||
434 | static void | 670 | static void |
@@ -445,8 +681,7 @@ tda998x_encoder_dpms(struct drm_encoder *encoder, int mode) | |||
445 | 681 | ||
446 | switch (mode) { | 682 | switch (mode) { |
447 | case DRM_MODE_DPMS_ON: | 683 | case DRM_MODE_DPMS_ON: |
448 | /* enable audio and video ports */ | 684 | /* enable video ports, audio will be enabled later */ |
449 | reg_write(encoder, REG_ENA_AP, 0xff); | ||
450 | reg_write(encoder, REG_ENA_VP_0, 0xff); | 685 | reg_write(encoder, REG_ENA_VP_0, 0xff); |
451 | reg_write(encoder, REG_ENA_VP_1, 0xff); | 686 | reg_write(encoder, REG_ENA_VP_1, 0xff); |
452 | reg_write(encoder, REG_ENA_VP_2, 0xff); | 687 | reg_write(encoder, REG_ENA_VP_2, 0xff); |
@@ -608,17 +843,32 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder, | |||
608 | reg_write16(encoder, REG_REFPIX_MSB, ref_pix); | 843 | reg_write16(encoder, REG_REFPIX_MSB, ref_pix); |
609 | reg_write16(encoder, REG_REFLINE_MSB, ref_line); | 844 | reg_write16(encoder, REG_REFLINE_MSB, ref_line); |
610 | 845 | ||
611 | reg = TBG_CNTRL_1_VHX_EXT_DE | | 846 | reg = TBG_CNTRL_1_DWIN_DIS | /* HDCP off */ |
612 | TBG_CNTRL_1_VHX_EXT_HS | | ||
613 | TBG_CNTRL_1_VHX_EXT_VS | | ||
614 | TBG_CNTRL_1_DWIN_DIS | /* HDCP off */ | ||
615 | TBG_CNTRL_1_VH_TGL_2; | 847 | TBG_CNTRL_1_VH_TGL_2; |
848 | /* | ||
849 | * It is questionable whether this is correct - the nxp driver | ||
850 | * does not set VH_TGL_2 and the below for all display modes. | ||
851 | */ | ||
616 | if (mode->flags & (DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC)) | 852 | if (mode->flags & (DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC)) |
617 | reg |= TBG_CNTRL_1_VH_TGL_0; | 853 | reg |= TBG_CNTRL_1_VH_TGL_0; |
618 | reg_set(encoder, REG_TBG_CNTRL_1, reg); | 854 | reg_set(encoder, REG_TBG_CNTRL_1, reg); |
619 | 855 | ||
620 | /* must be last register set: */ | 856 | /* must be last register set: */ |
621 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_ONCE); | 857 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_ONCE); |
858 | |||
859 | /* Only setup the info frames if the sink is HDMI */ | ||
860 | if (priv->is_hdmi_sink) { | ||
861 | /* We need to turn HDMI HDCP stuff on to get audio through */ | ||
862 | reg_clear(encoder, REG_TBG_CNTRL_1, TBG_CNTRL_1_DWIN_DIS); | ||
863 | reg_write(encoder, REG_ENC_CNTRL, ENC_CNTRL_CTL_CODE(1)); | ||
864 | reg_set(encoder, REG_TX33, TX33_HDMI); | ||
865 | |||
866 | tda998x_write_avi(encoder, adjusted_mode); | ||
867 | |||
868 | if (priv->params.audio_cfg) | ||
869 | tda998x_configure_audio(encoder, adjusted_mode, | ||
870 | &priv->params); | ||
871 | } | ||
622 | } | 872 | } |
623 | 873 | ||
624 | static enum drm_connector_status | 874 | static enum drm_connector_status |
@@ -744,12 +994,14 @@ static int | |||
744 | tda998x_encoder_get_modes(struct drm_encoder *encoder, | 994 | tda998x_encoder_get_modes(struct drm_encoder *encoder, |
745 | struct drm_connector *connector) | 995 | struct drm_connector *connector) |
746 | { | 996 | { |
997 | struct tda998x_priv *priv = to_tda998x_priv(encoder); | ||
747 | struct edid *edid = (struct edid *)do_get_edid(encoder); | 998 | struct edid *edid = (struct edid *)do_get_edid(encoder); |
748 | int n = 0; | 999 | int n = 0; |
749 | 1000 | ||
750 | if (edid) { | 1001 | if (edid) { |
751 | drm_mode_connector_update_edid_property(connector, edid); | 1002 | drm_mode_connector_update_edid_property(connector, edid); |
752 | n = drm_add_edid_modes(connector, edid); | 1003 | n = drm_add_edid_modes(connector, edid); |
1004 | priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid); | ||
753 | kfree(edid); | 1005 | kfree(edid); |
754 | } | 1006 | } |
755 | 1007 | ||
diff --git a/include/drm/i2c/tda998x.h b/include/drm/i2c/tda998x.h new file mode 100644 index 000000000000..3e419d92cf5a --- /dev/null +++ b/include/drm/i2c/tda998x.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef __DRM_I2C_TDA998X_H__ | ||
2 | #define __DRM_I2C_TDA998X_H__ | ||
3 | |||
4 | struct tda998x_encoder_params { | ||
5 | u8 swap_b:3; | ||
6 | u8 mirr_b:1; | ||
7 | u8 swap_a:3; | ||
8 | u8 mirr_a:1; | ||
9 | u8 swap_d:3; | ||
10 | u8 mirr_d:1; | ||
11 | u8 swap_c:3; | ||
12 | u8 mirr_c:1; | ||
13 | u8 swap_f:3; | ||
14 | u8 mirr_f:1; | ||
15 | u8 swap_e:3; | ||
16 | u8 mirr_e:1; | ||
17 | |||
18 | u8 audio_cfg; | ||
19 | u8 audio_clk_cfg; | ||
20 | u8 audio_frame[6]; | ||
21 | |||
22 | enum { | ||
23 | AFMT_SPDIF, | ||
24 | AFMT_I2S | ||
25 | } audio_format; | ||
26 | |||
27 | unsigned audio_sample_rate; | ||
28 | }; | ||
29 | |||
30 | #endif | ||