2 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * SH-Mobile High-Definition Multimedia Interface (HDMI) driver
10 * for SLISHDMI13T and SLIPHDMIT IP cores
12 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
15 #include <linux/component.h>
16 #include <linux/irq.h>
17 #include <linux/delay.h>
18 #include <linux/err.h>
19 #include <linux/clk.h>
20 #include <linux/hdmi.h>
21 #include <linux/regmap.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
24 #include <linux/of_device.h>
27 #include <drm/drm_crtc_helper.h>
28 #include <drm/drm_edid.h>
29 #include <drm/drm_encoder_slave.h>
31 #include "ipu-v3/imx-ipu-v3.h"
35 #define HDMI_EDID_LEN 512
39 #define YCBCR422_16BITS 2
40 #define YCBCR422_8BITS 3
57 enum imx_hdmi_devtype
{
62 static const u16 csc_coeff_default
[3][4] = {
63 { 0x2000, 0x0000, 0x0000, 0x0000 },
64 { 0x0000, 0x2000, 0x0000, 0x0000 },
65 { 0x0000, 0x0000, 0x2000, 0x0000 }
68 static const u16 csc_coeff_rgb_out_eitu601
[3][4] = {
69 { 0x2000, 0x6926, 0x74fd, 0x010e },
70 { 0x2000, 0x2cdd, 0x0000, 0x7e9a },
71 { 0x2000, 0x0000, 0x38b4, 0x7e3b }
74 static const u16 csc_coeff_rgb_out_eitu709
[3][4] = {
75 { 0x2000, 0x7106, 0x7a02, 0x00a7 },
76 { 0x2000, 0x3264, 0x0000, 0x7e6d },
77 { 0x2000, 0x0000, 0x3b61, 0x7e25 }
80 static const u16 csc_coeff_rgb_in_eitu601
[3][4] = {
81 { 0x2591, 0x1322, 0x074b, 0x0000 },
82 { 0x6535, 0x2000, 0x7acc, 0x0200 },
83 { 0x6acd, 0x7534, 0x2000, 0x0200 }
86 static const u16 csc_coeff_rgb_in_eitu709
[3][4] = {
87 { 0x2dc5, 0x0d9b, 0x049e, 0x0000 },
88 { 0x62f0, 0x2000, 0x7d11, 0x0200 },
89 { 0x6756, 0x78ab, 0x2000, 0x0200 }
97 bool mdataenablepolarity
;
99 unsigned int mpixelclock
;
100 unsigned int mpixelrepetitioninput
;
101 unsigned int mpixelrepetitionoutput
;
104 struct hdmi_data_info
{
105 unsigned int enc_in_format
;
106 unsigned int enc_out_format
;
107 unsigned int enc_color_depth
;
108 unsigned int colorimetry
;
109 unsigned int pix_repet_factor
;
110 unsigned int hdcp_enable
;
111 struct hdmi_vmode video_mode
;
115 struct drm_connector connector
;
116 struct drm_encoder encoder
;
118 enum imx_hdmi_devtype dev_type
;
120 struct clk
*isfr_clk
;
121 struct clk
*iahb_clk
;
123 enum drm_connector_status connector_status
;
125 struct hdmi_data_info hdmi_data
;
128 u8 edid
[HDMI_EDID_LEN
];
132 struct drm_display_mode previous_mode
;
134 struct regmap
*regmap
;
135 struct i2c_adapter
*ddc
;
138 unsigned int sample_rate
;
142 static void imx_hdmi_set_ipu_di_mux(struct imx_hdmi
*hdmi
, int ipu_di
)
144 regmap_update_bits(hdmi
->regmap
, IOMUXC_GPR3
,
145 IMX6Q_GPR3_HDMI_MUX_CTL_MASK
,
146 ipu_di
<< IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT
);
149 static inline void hdmi_writeb(struct imx_hdmi
*hdmi
, u8 val
, int offset
)
151 writeb(val
, hdmi
->regs
+ offset
);
154 static inline u8
hdmi_readb(struct imx_hdmi
*hdmi
, int offset
)
156 return readb(hdmi
->regs
+ offset
);
159 static void hdmi_modb(struct imx_hdmi
*hdmi
, u8 data
, u8 mask
, unsigned reg
)
161 u8 val
= hdmi_readb(hdmi
, reg
) & ~mask
;
163 hdmi_writeb(hdmi
, val
, reg
);
166 static void hdmi_mask_writeb(struct imx_hdmi
*hdmi
, u8 data
, unsigned int reg
,
169 hdmi_modb(hdmi
, data
<< shift
, mask
, reg
);
172 static void hdmi_set_clock_regenerator_n(struct imx_hdmi
*hdmi
,
175 hdmi_writeb(hdmi
, value
& 0xff, HDMI_AUD_N1
);
176 hdmi_writeb(hdmi
, (value
>> 8) & 0xff, HDMI_AUD_N2
);
177 hdmi_writeb(hdmi
, (value
>> 16) & 0x0f, HDMI_AUD_N3
);
179 /* nshift factor = 0 */
180 hdmi_modb(hdmi
, 0, HDMI_AUD_CTS3_N_SHIFT_MASK
, HDMI_AUD_CTS3
);
183 static void hdmi_regenerate_cts(struct imx_hdmi
*hdmi
, unsigned int cts
)
185 /* Must be set/cleared first */
186 hdmi_modb(hdmi
, 0, HDMI_AUD_CTS3_CTS_MANUAL
, HDMI_AUD_CTS3
);
188 hdmi_writeb(hdmi
, cts
& 0xff, HDMI_AUD_CTS1
);
189 hdmi_writeb(hdmi
, (cts
>> 8) & 0xff, HDMI_AUD_CTS2
);
190 hdmi_writeb(hdmi
, ((cts
>> 16) & HDMI_AUD_CTS3_AUDCTS19_16_MASK
) |
191 HDMI_AUD_CTS3_CTS_MANUAL
, HDMI_AUD_CTS3
);
194 static unsigned int hdmi_compute_n(unsigned int freq
, unsigned long pixel_clk
,
197 unsigned int n
= (128 * freq
) / 1000;
201 if (pixel_clk
== 25170000)
202 n
= (ratio
== 150) ? 9152 : 4576;
203 else if (pixel_clk
== 27020000)
204 n
= (ratio
== 150) ? 8192 : 4096;
205 else if (pixel_clk
== 74170000 || pixel_clk
== 148350000)
212 if (pixel_clk
== 25170000)
214 else if (pixel_clk
== 74170000)
216 else if (pixel_clk
== 148350000)
217 n
= (ratio
== 150) ? 17836 : 8918;
223 if (pixel_clk
== 25170000)
224 n
= (ratio
== 150) ? 9152 : 6864;
225 else if (pixel_clk
== 27020000)
226 n
= (ratio
== 150) ? 8192 : 6144;
227 else if (pixel_clk
== 74170000)
229 else if (pixel_clk
== 148350000)
230 n
= (ratio
== 150) ? 11648 : 5824;
236 n
= hdmi_compute_n(44100, pixel_clk
, ratio
) * 2;
240 n
= hdmi_compute_n(48000, pixel_clk
, ratio
) * 2;
244 n
= hdmi_compute_n(44100, pixel_clk
, ratio
) * 4;
248 n
= hdmi_compute_n(48000, pixel_clk
, ratio
) * 4;
258 static unsigned int hdmi_compute_cts(unsigned int freq
, unsigned long pixel_clk
,
261 unsigned int cts
= 0;
263 pr_debug("%s: freq: %d pixel_clk: %ld ratio: %d\n", __func__
, freq
,
268 if (pixel_clk
== 297000000) {
281 cts
= pixel_clk
/ 1000;
287 * All other TMDS clocks are not supported by
288 * DWC_hdmi_tx. The TMDS clocks divided or
289 * multiplied by 1,001 coefficients are not
328 return (cts
* ratio
) / 100;
331 static void hdmi_set_clk_regenerator(struct imx_hdmi
*hdmi
,
332 unsigned long pixel_clk
)
334 unsigned int clk_n
, clk_cts
;
336 clk_n
= hdmi_compute_n(hdmi
->sample_rate
, pixel_clk
,
338 clk_cts
= hdmi_compute_cts(hdmi
->sample_rate
, pixel_clk
,
342 dev_dbg(hdmi
->dev
, "%s: pixel clock not supported: %lu\n",
343 __func__
, pixel_clk
);
347 dev_dbg(hdmi
->dev
, "%s: samplerate=%d ratio=%d pixelclk=%lu N=%d cts=%d\n",
348 __func__
, hdmi
->sample_rate
, hdmi
->ratio
,
349 pixel_clk
, clk_n
, clk_cts
);
351 hdmi_set_clock_regenerator_n(hdmi
, clk_n
);
352 hdmi_regenerate_cts(hdmi
, clk_cts
);
355 static void hdmi_init_clk_regenerator(struct imx_hdmi
*hdmi
)
357 hdmi_set_clk_regenerator(hdmi
, 74250000);
360 static void hdmi_clk_regenerator_update_pixel_clock(struct imx_hdmi
*hdmi
)
362 hdmi_set_clk_regenerator(hdmi
, hdmi
->hdmi_data
.video_mode
.mpixelclock
);
366 * this submodule is responsible for the video data synchronization.
367 * for example, for RGB 4:4:4 input, the data map is defined as
368 * pin{47~40} <==> R[7:0]
369 * pin{31~24} <==> G[7:0]
370 * pin{15~8} <==> B[7:0]
372 static void hdmi_video_sample(struct imx_hdmi
*hdmi
)
374 int color_format
= 0;
377 if (hdmi
->hdmi_data
.enc_in_format
== RGB
) {
378 if (hdmi
->hdmi_data
.enc_color_depth
== 8)
380 else if (hdmi
->hdmi_data
.enc_color_depth
== 10)
382 else if (hdmi
->hdmi_data
.enc_color_depth
== 12)
384 else if (hdmi
->hdmi_data
.enc_color_depth
== 16)
388 } else if (hdmi
->hdmi_data
.enc_in_format
== YCBCR444
) {
389 if (hdmi
->hdmi_data
.enc_color_depth
== 8)
391 else if (hdmi
->hdmi_data
.enc_color_depth
== 10)
393 else if (hdmi
->hdmi_data
.enc_color_depth
== 12)
395 else if (hdmi
->hdmi_data
.enc_color_depth
== 16)
399 } else if (hdmi
->hdmi_data
.enc_in_format
== YCBCR422_8BITS
) {
400 if (hdmi
->hdmi_data
.enc_color_depth
== 8)
402 else if (hdmi
->hdmi_data
.enc_color_depth
== 10)
404 else if (hdmi
->hdmi_data
.enc_color_depth
== 12)
410 val
= HDMI_TX_INVID0_INTERNAL_DE_GENERATOR_DISABLE
|
411 ((color_format
<< HDMI_TX_INVID0_VIDEO_MAPPING_OFFSET
) &
412 HDMI_TX_INVID0_VIDEO_MAPPING_MASK
);
413 hdmi_writeb(hdmi
, val
, HDMI_TX_INVID0
);
415 /* Enable TX stuffing: When DE is inactive, fix the output data to 0 */
416 val
= HDMI_TX_INSTUFFING_BDBDATA_STUFFING_ENABLE
|
417 HDMI_TX_INSTUFFING_RCRDATA_STUFFING_ENABLE
|
418 HDMI_TX_INSTUFFING_GYDATA_STUFFING_ENABLE
;
419 hdmi_writeb(hdmi
, val
, HDMI_TX_INSTUFFING
);
420 hdmi_writeb(hdmi
, 0x0, HDMI_TX_GYDATA0
);
421 hdmi_writeb(hdmi
, 0x0, HDMI_TX_GYDATA1
);
422 hdmi_writeb(hdmi
, 0x0, HDMI_TX_RCRDATA0
);
423 hdmi_writeb(hdmi
, 0x0, HDMI_TX_RCRDATA1
);
424 hdmi_writeb(hdmi
, 0x0, HDMI_TX_BCBDATA0
);
425 hdmi_writeb(hdmi
, 0x0, HDMI_TX_BCBDATA1
);
428 static int is_color_space_conversion(struct imx_hdmi
*hdmi
)
430 return hdmi
->hdmi_data
.enc_in_format
!= hdmi
->hdmi_data
.enc_out_format
;
433 static int is_color_space_decimation(struct imx_hdmi
*hdmi
)
435 if (hdmi
->hdmi_data
.enc_out_format
!= YCBCR422_8BITS
)
437 if (hdmi
->hdmi_data
.enc_in_format
== RGB
||
438 hdmi
->hdmi_data
.enc_in_format
== YCBCR444
)
443 static int is_color_space_interpolation(struct imx_hdmi
*hdmi
)
445 if (hdmi
->hdmi_data
.enc_in_format
!= YCBCR422_8BITS
)
447 if (hdmi
->hdmi_data
.enc_out_format
== RGB
||
448 hdmi
->hdmi_data
.enc_out_format
== YCBCR444
)
453 static void imx_hdmi_update_csc_coeffs(struct imx_hdmi
*hdmi
)
455 const u16 (*csc_coeff
)[3][4] = &csc_coeff_default
;
459 if (is_color_space_conversion(hdmi
)) {
460 if (hdmi
->hdmi_data
.enc_out_format
== RGB
) {
461 if (hdmi
->hdmi_data
.colorimetry
==
462 HDMI_COLORIMETRY_ITU_601
)
463 csc_coeff
= &csc_coeff_rgb_out_eitu601
;
465 csc_coeff
= &csc_coeff_rgb_out_eitu709
;
466 } else if (hdmi
->hdmi_data
.enc_in_format
== RGB
) {
467 if (hdmi
->hdmi_data
.colorimetry
==
468 HDMI_COLORIMETRY_ITU_601
)
469 csc_coeff
= &csc_coeff_rgb_in_eitu601
;
471 csc_coeff
= &csc_coeff_rgb_in_eitu709
;
476 /* The CSC registers are sequential, alternating MSB then LSB */
477 for (i
= 0; i
< ARRAY_SIZE(csc_coeff_default
[0]); i
++) {
478 u16 coeff_a
= (*csc_coeff
)[0][i
];
479 u16 coeff_b
= (*csc_coeff
)[1][i
];
480 u16 coeff_c
= (*csc_coeff
)[2][i
];
482 hdmi_writeb(hdmi
, coeff_a
& 0xff,
483 HDMI_CSC_COEF_A1_LSB
+ i
* 2);
484 hdmi_writeb(hdmi
, coeff_a
>> 8, HDMI_CSC_COEF_A1_MSB
+ i
* 2);
485 hdmi_writeb(hdmi
, coeff_b
& 0xff, HDMI_CSC_COEF_B1_LSB
+ i
* 2);
486 hdmi_writeb(hdmi
, coeff_b
>> 8, HDMI_CSC_COEF_B1_MSB
+ i
* 2);
487 hdmi_writeb(hdmi
, coeff_c
& 0xff,
488 HDMI_CSC_COEF_C1_LSB
+ i
* 2);
489 hdmi_writeb(hdmi
, coeff_c
>> 8, HDMI_CSC_COEF_C1_MSB
+ i
* 2);
492 hdmi_modb(hdmi
, csc_scale
, HDMI_CSC_SCALE_CSCSCALE_MASK
,
496 static void hdmi_video_csc(struct imx_hdmi
*hdmi
)
499 int interpolation
= HDMI_CSC_CFG_INTMODE_DISABLE
;
502 /* YCC422 interpolation to 444 mode */
503 if (is_color_space_interpolation(hdmi
))
504 interpolation
= HDMI_CSC_CFG_INTMODE_CHROMA_INT_FORMULA1
;
505 else if (is_color_space_decimation(hdmi
))
506 decimation
= HDMI_CSC_CFG_DECMODE_CHROMA_INT_FORMULA3
;
508 if (hdmi
->hdmi_data
.enc_color_depth
== 8)
509 color_depth
= HDMI_CSC_SCALE_CSC_COLORDE_PTH_24BPP
;
510 else if (hdmi
->hdmi_data
.enc_color_depth
== 10)
511 color_depth
= HDMI_CSC_SCALE_CSC_COLORDE_PTH_30BPP
;
512 else if (hdmi
->hdmi_data
.enc_color_depth
== 12)
513 color_depth
= HDMI_CSC_SCALE_CSC_COLORDE_PTH_36BPP
;
514 else if (hdmi
->hdmi_data
.enc_color_depth
== 16)
515 color_depth
= HDMI_CSC_SCALE_CSC_COLORDE_PTH_48BPP
;
519 /* Configure the CSC registers */
520 hdmi_writeb(hdmi
, interpolation
| decimation
, HDMI_CSC_CFG
);
521 hdmi_modb(hdmi
, color_depth
, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK
,
524 imx_hdmi_update_csc_coeffs(hdmi
);
528 * HDMI video packetizer is used to packetize the data.
529 * for example, if input is YCC422 mode or repeater is used,
530 * data should be repacked this module can be bypassed.
532 static void hdmi_video_packetize(struct imx_hdmi
*hdmi
)
534 unsigned int color_depth
= 0;
535 unsigned int remap_size
= HDMI_VP_REMAP_YCC422_16bit
;
536 unsigned int output_select
= HDMI_VP_CONF_OUTPUT_SELECTOR_PP
;
537 struct hdmi_data_info
*hdmi_data
= &hdmi
->hdmi_data
;
540 if (hdmi_data
->enc_out_format
== RGB
541 || hdmi_data
->enc_out_format
== YCBCR444
) {
542 if (!hdmi_data
->enc_color_depth
)
543 output_select
= HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS
;
544 else if (hdmi_data
->enc_color_depth
== 8) {
546 output_select
= HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS
;
547 } else if (hdmi_data
->enc_color_depth
== 10)
549 else if (hdmi_data
->enc_color_depth
== 12)
551 else if (hdmi_data
->enc_color_depth
== 16)
555 } else if (hdmi_data
->enc_out_format
== YCBCR422_8BITS
) {
556 if (!hdmi_data
->enc_color_depth
||
557 hdmi_data
->enc_color_depth
== 8)
558 remap_size
= HDMI_VP_REMAP_YCC422_16bit
;
559 else if (hdmi_data
->enc_color_depth
== 10)
560 remap_size
= HDMI_VP_REMAP_YCC422_20bit
;
561 else if (hdmi_data
->enc_color_depth
== 12)
562 remap_size
= HDMI_VP_REMAP_YCC422_24bit
;
565 output_select
= HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422
;
569 /* set the packetizer registers */
570 val
= ((color_depth
<< HDMI_VP_PR_CD_COLOR_DEPTH_OFFSET
) &
571 HDMI_VP_PR_CD_COLOR_DEPTH_MASK
) |
572 ((hdmi_data
->pix_repet_factor
<<
573 HDMI_VP_PR_CD_DESIRED_PR_FACTOR_OFFSET
) &
574 HDMI_VP_PR_CD_DESIRED_PR_FACTOR_MASK
);
575 hdmi_writeb(hdmi
, val
, HDMI_VP_PR_CD
);
577 hdmi_modb(hdmi
, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE
,
578 HDMI_VP_STUFF_PR_STUFFING_MASK
, HDMI_VP_STUFF
);
580 /* Data from pixel repeater block */
581 if (hdmi_data
->pix_repet_factor
> 1) {
582 vp_conf
= HDMI_VP_CONF_PR_EN_ENABLE
|
583 HDMI_VP_CONF_BYPASS_SELECT_PIX_REPEATER
;
584 } else { /* data from packetizer block */
585 vp_conf
= HDMI_VP_CONF_PR_EN_DISABLE
|
586 HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER
;
589 hdmi_modb(hdmi
, vp_conf
,
590 HDMI_VP_CONF_PR_EN_MASK
|
591 HDMI_VP_CONF_BYPASS_SELECT_MASK
, HDMI_VP_CONF
);
593 hdmi_modb(hdmi
, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET
,
594 HDMI_VP_STUFF_IDEFAULT_PHASE_MASK
, HDMI_VP_STUFF
);
596 hdmi_writeb(hdmi
, remap_size
, HDMI_VP_REMAP
);
598 if (output_select
== HDMI_VP_CONF_OUTPUT_SELECTOR_PP
) {
599 vp_conf
= HDMI_VP_CONF_BYPASS_EN_DISABLE
|
600 HDMI_VP_CONF_PP_EN_ENABLE
|
601 HDMI_VP_CONF_YCC422_EN_DISABLE
;
602 } else if (output_select
== HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422
) {
603 vp_conf
= HDMI_VP_CONF_BYPASS_EN_DISABLE
|
604 HDMI_VP_CONF_PP_EN_DISABLE
|
605 HDMI_VP_CONF_YCC422_EN_ENABLE
;
606 } else if (output_select
== HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS
) {
607 vp_conf
= HDMI_VP_CONF_BYPASS_EN_ENABLE
|
608 HDMI_VP_CONF_PP_EN_DISABLE
|
609 HDMI_VP_CONF_YCC422_EN_DISABLE
;
614 hdmi_modb(hdmi
, vp_conf
,
615 HDMI_VP_CONF_BYPASS_EN_MASK
| HDMI_VP_CONF_PP_EN_ENMASK
|
616 HDMI_VP_CONF_YCC422_EN_MASK
, HDMI_VP_CONF
);
618 hdmi_modb(hdmi
, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE
|
619 HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE
,
620 HDMI_VP_STUFF_PP_STUFFING_MASK
|
621 HDMI_VP_STUFF_YCC422_STUFFING_MASK
, HDMI_VP_STUFF
);
623 hdmi_modb(hdmi
, output_select
, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK
,
627 static inline void hdmi_phy_test_clear(struct imx_hdmi
*hdmi
,
630 hdmi_modb(hdmi
, bit
<< HDMI_PHY_TST0_TSTCLR_OFFSET
,
631 HDMI_PHY_TST0_TSTCLR_MASK
, HDMI_PHY_TST0
);
634 static inline void hdmi_phy_test_enable(struct imx_hdmi
*hdmi
,
637 hdmi_modb(hdmi
, bit
<< HDMI_PHY_TST0_TSTEN_OFFSET
,
638 HDMI_PHY_TST0_TSTEN_MASK
, HDMI_PHY_TST0
);
641 static inline void hdmi_phy_test_clock(struct imx_hdmi
*hdmi
,
644 hdmi_modb(hdmi
, bit
<< HDMI_PHY_TST0_TSTCLK_OFFSET
,
645 HDMI_PHY_TST0_TSTCLK_MASK
, HDMI_PHY_TST0
);
648 static inline void hdmi_phy_test_din(struct imx_hdmi
*hdmi
,
651 hdmi_writeb(hdmi
, bit
, HDMI_PHY_TST1
);
654 static inline void hdmi_phy_test_dout(struct imx_hdmi
*hdmi
,
657 hdmi_writeb(hdmi
, bit
, HDMI_PHY_TST2
);
660 static bool hdmi_phy_wait_i2c_done(struct imx_hdmi
*hdmi
, int msec
)
662 unsigned char val
= 0;
663 val
= hdmi_readb(hdmi
, HDMI_IH_I2CMPHY_STAT0
) & 0x3;
668 val
= hdmi_readb(hdmi
, HDMI_IH_I2CMPHY_STAT0
) & 0x3;
673 static void __hdmi_phy_i2c_write(struct imx_hdmi
*hdmi
, unsigned short data
,
676 hdmi_writeb(hdmi
, 0xFF, HDMI_IH_I2CMPHY_STAT0
);
677 hdmi_writeb(hdmi
, addr
, HDMI_PHY_I2CM_ADDRESS_ADDR
);
678 hdmi_writeb(hdmi
, (unsigned char)(data
>> 8),
679 HDMI_PHY_I2CM_DATAO_1_ADDR
);
680 hdmi_writeb(hdmi
, (unsigned char)(data
>> 0),
681 HDMI_PHY_I2CM_DATAO_0_ADDR
);
682 hdmi_writeb(hdmi
, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE
,
683 HDMI_PHY_I2CM_OPERATION_ADDR
);
684 hdmi_phy_wait_i2c_done(hdmi
, 1000);
687 static int hdmi_phy_i2c_write(struct imx_hdmi
*hdmi
, unsigned short data
,
690 __hdmi_phy_i2c_write(hdmi
, data
, addr
);
694 static void imx_hdmi_phy_enable_power(struct imx_hdmi
*hdmi
, u8 enable
)
696 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
697 HDMI_PHY_CONF0_PDZ_OFFSET
,
698 HDMI_PHY_CONF0_PDZ_MASK
);
701 static void imx_hdmi_phy_enable_tmds(struct imx_hdmi
*hdmi
, u8 enable
)
703 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
704 HDMI_PHY_CONF0_ENTMDS_OFFSET
,
705 HDMI_PHY_CONF0_ENTMDS_MASK
);
708 static void imx_hdmi_phy_gen2_pddq(struct imx_hdmi
*hdmi
, u8 enable
)
710 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
711 HDMI_PHY_CONF0_GEN2_PDDQ_OFFSET
,
712 HDMI_PHY_CONF0_GEN2_PDDQ_MASK
);
715 static void imx_hdmi_phy_gen2_txpwron(struct imx_hdmi
*hdmi
, u8 enable
)
717 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
718 HDMI_PHY_CONF0_GEN2_TXPWRON_OFFSET
,
719 HDMI_PHY_CONF0_GEN2_TXPWRON_MASK
);
722 static void imx_hdmi_phy_sel_data_en_pol(struct imx_hdmi
*hdmi
, u8 enable
)
724 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
725 HDMI_PHY_CONF0_SELDATAENPOL_OFFSET
,
726 HDMI_PHY_CONF0_SELDATAENPOL_MASK
);
729 static void imx_hdmi_phy_sel_interface_control(struct imx_hdmi
*hdmi
, u8 enable
)
731 hdmi_mask_writeb(hdmi
, enable
, HDMI_PHY_CONF0
,
732 HDMI_PHY_CONF0_SELDIPIF_OFFSET
,
733 HDMI_PHY_CONF0_SELDIPIF_MASK
);
744 unsigned long mpixelclock
;
751 static const struct mpll_config mpll_config
[] = {
780 unsigned long mpixelclock
;
784 static const struct curr_ctrl curr_ctrl
[] = {
785 /* pixelclk bpp8 bpp10 bpp12 */
787 54000000, { 0x091c, 0x091c, 0x06dc },
789 58400000, { 0x091c, 0x06dc, 0x06dc },
791 72000000, { 0x06dc, 0x06dc, 0x091c },
793 74250000, { 0x06dc, 0x0b5c, 0x091c },
795 118800000, { 0x091c, 0x091c, 0x06dc },
797 216000000, { 0x06dc, 0x0b5c, 0x091c },
801 static int hdmi_phy_configure(struct imx_hdmi
*hdmi
, unsigned char prep
,
802 unsigned char res
, int cscon
)
811 case 0: /* color resolution 0 is 8 bit colour depth */
825 /* Enable csc path */
827 val
= HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH
;
829 val
= HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS
;
831 hdmi_writeb(hdmi
, val
, HDMI_MC_FLOWCTRL
);
833 /* gen2 tx power off */
834 imx_hdmi_phy_gen2_txpwron(hdmi
, 0);
837 imx_hdmi_phy_gen2_pddq(hdmi
, 1);
840 hdmi_writeb(hdmi
, HDMI_MC_PHYRSTZ_DEASSERT
, HDMI_MC_PHYRSTZ
);
841 hdmi_writeb(hdmi
, HDMI_MC_PHYRSTZ_ASSERT
, HDMI_MC_PHYRSTZ
);
843 hdmi_writeb(hdmi
, HDMI_MC_HEACPHY_RST_ASSERT
, HDMI_MC_HEACPHY_RST
);
845 hdmi_phy_test_clear(hdmi
, 1);
846 hdmi_writeb(hdmi
, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2
,
847 HDMI_PHY_I2CM_SLAVE_ADDR
);
848 hdmi_phy_test_clear(hdmi
, 0);
850 /* PLL/MPLL Cfg - always match on final entry */
851 for (i
= 0; i
< ARRAY_SIZE(mpll_config
) - 1; i
++)
852 if (hdmi
->hdmi_data
.video_mode
.mpixelclock
<=
853 mpll_config
[i
].mpixelclock
)
856 hdmi_phy_i2c_write(hdmi
, mpll_config
[i
].res
[res_idx
].cpce
, 0x06);
857 hdmi_phy_i2c_write(hdmi
, mpll_config
[i
].res
[res_idx
].gmp
, 0x15);
859 for (i
= 0; i
< ARRAY_SIZE(curr_ctrl
); i
++)
860 if (hdmi
->hdmi_data
.video_mode
.mpixelclock
<=
861 curr_ctrl
[i
].mpixelclock
)
864 if (i
>= ARRAY_SIZE(curr_ctrl
)) {
866 "Pixel clock %d - unsupported by HDMI\n",
867 hdmi
->hdmi_data
.video_mode
.mpixelclock
);
872 hdmi_phy_i2c_write(hdmi
, curr_ctrl
[i
].curr
[res_idx
], 0x10);
874 hdmi_phy_i2c_write(hdmi
, 0x0000, 0x13); /* PLLPHBYCTRL */
875 hdmi_phy_i2c_write(hdmi
, 0x0006, 0x17);
876 /* RESISTANCE TERM 133Ohm Cfg */
877 hdmi_phy_i2c_write(hdmi
, 0x0005, 0x19); /* TXTERM */
878 /* PREEMP Cgf 0.00 */
879 hdmi_phy_i2c_write(hdmi
, 0x800d, 0x09); /* CKSYMTXCTRL */
881 hdmi_phy_i2c_write(hdmi
, 0x01ad, 0x0E); /* VLEVCTRL */
882 /* REMOVE CLK TERM */
883 hdmi_phy_i2c_write(hdmi
, 0x8000, 0x05); /* CKCALCTRL */
885 imx_hdmi_phy_enable_power(hdmi
, 1);
887 /* toggle TMDS enable */
888 imx_hdmi_phy_enable_tmds(hdmi
, 0);
889 imx_hdmi_phy_enable_tmds(hdmi
, 1);
891 /* gen2 tx power on */
892 imx_hdmi_phy_gen2_txpwron(hdmi
, 1);
893 imx_hdmi_phy_gen2_pddq(hdmi
, 0);
895 /*Wait for PHY PLL lock */
898 val
= hdmi_readb(hdmi
, HDMI_PHY_STAT0
) & HDMI_PHY_TX_PHY_LOCK
;
903 dev_err(hdmi
->dev
, "PHY PLL not locked\n");
914 static int imx_hdmi_phy_init(struct imx_hdmi
*hdmi
)
919 /*check csc whether needed activated in HDMI mode */
920 cscon
= (is_color_space_conversion(hdmi
) &&
921 !hdmi
->hdmi_data
.video_mode
.mdvi
);
923 /* HDMI Phy spec says to do the phy initialization sequence twice */
924 for (i
= 0; i
< 2; i
++) {
925 imx_hdmi_phy_sel_data_en_pol(hdmi
, 1);
926 imx_hdmi_phy_sel_interface_control(hdmi
, 0);
927 imx_hdmi_phy_enable_tmds(hdmi
, 0);
928 imx_hdmi_phy_enable_power(hdmi
, 0);
931 ret
= hdmi_phy_configure(hdmi
, 0, 8, cscon
);
936 hdmi
->phy_enabled
= true;
940 static void hdmi_tx_hdcp_config(struct imx_hdmi
*hdmi
)
944 if (hdmi
->hdmi_data
.video_mode
.mdataenablepolarity
)
945 de
= HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_HIGH
;
947 de
= HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_LOW
;
949 /* disable rx detect */
950 hdmi_modb(hdmi
, HDMI_A_HDCPCFG0_RXDETECT_DISABLE
,
951 HDMI_A_HDCPCFG0_RXDETECT_MASK
, HDMI_A_HDCPCFG0
);
953 hdmi_modb(hdmi
, de
, HDMI_A_VIDPOLCFG_DATAENPOL_MASK
, HDMI_A_VIDPOLCFG
);
955 hdmi_modb(hdmi
, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE
,
956 HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_MASK
, HDMI_A_HDCPCFG1
);
959 static void hdmi_config_AVI(struct imx_hdmi
*hdmi
)
961 u8 val
, pix_fmt
, under_scan
;
962 u8 act_ratio
, coded_ratio
, colorimetry
, ext_colorimetry
;
965 aspect_16_9
= false; /* FIXME */
967 /* AVI Data Byte 1 */
968 if (hdmi
->hdmi_data
.enc_out_format
== YCBCR444
)
969 pix_fmt
= HDMI_FC_AVICONF0_PIX_FMT_YCBCR444
;
970 else if (hdmi
->hdmi_data
.enc_out_format
== YCBCR422_8BITS
)
971 pix_fmt
= HDMI_FC_AVICONF0_PIX_FMT_YCBCR422
;
973 pix_fmt
= HDMI_FC_AVICONF0_PIX_FMT_RGB
;
975 under_scan
= HDMI_FC_AVICONF0_SCAN_INFO_NODATA
;
978 * Active format identification data is present in the AVI InfoFrame.
979 * Under scan info, no bar data
981 val
= pix_fmt
| under_scan
|
982 HDMI_FC_AVICONF0_ACTIVE_FMT_INFO_PRESENT
|
983 HDMI_FC_AVICONF0_BAR_DATA_NO_DATA
;
985 hdmi_writeb(hdmi
, val
, HDMI_FC_AVICONF0
);
987 /* AVI Data Byte 2 -Set the Aspect Ratio */
989 act_ratio
= HDMI_FC_AVICONF1_ACTIVE_ASPECT_RATIO_16_9
;
990 coded_ratio
= HDMI_FC_AVICONF1_CODED_ASPECT_RATIO_16_9
;
992 act_ratio
= HDMI_FC_AVICONF1_ACTIVE_ASPECT_RATIO_4_3
;
993 coded_ratio
= HDMI_FC_AVICONF1_CODED_ASPECT_RATIO_4_3
;
996 /* Set up colorimetry */
997 if (hdmi
->hdmi_data
.enc_out_format
== XVYCC444
) {
998 colorimetry
= HDMI_FC_AVICONF1_COLORIMETRY_EXTENDED_INFO
;
999 if (hdmi
->hdmi_data
.colorimetry
== HDMI_COLORIMETRY_ITU_601
)
1001 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601
;
1002 else /*hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_709*/
1004 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC709
;
1005 } else if (hdmi
->hdmi_data
.enc_out_format
!= RGB
) {
1006 if (hdmi
->hdmi_data
.colorimetry
== HDMI_COLORIMETRY_ITU_601
)
1007 colorimetry
= HDMI_FC_AVICONF1_COLORIMETRY_SMPTE
;
1008 else /*hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_709*/
1009 colorimetry
= HDMI_FC_AVICONF1_COLORIMETRY_ITUR
;
1010 ext_colorimetry
= HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601
;
1011 } else { /* Carries no data */
1012 colorimetry
= HDMI_FC_AVICONF1_COLORIMETRY_NO_DATA
;
1013 ext_colorimetry
= HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601
;
1016 val
= colorimetry
| coded_ratio
| act_ratio
;
1017 hdmi_writeb(hdmi
, val
, HDMI_FC_AVICONF1
);
1019 /* AVI Data Byte 3 */
1020 val
= HDMI_FC_AVICONF2_IT_CONTENT_NO_DATA
| ext_colorimetry
|
1021 HDMI_FC_AVICONF2_RGB_QUANT_DEFAULT
|
1022 HDMI_FC_AVICONF2_SCALING_NONE
;
1023 hdmi_writeb(hdmi
, val
, HDMI_FC_AVICONF2
);
1025 /* AVI Data Byte 4 */
1026 hdmi_writeb(hdmi
, hdmi
->vic
, HDMI_FC_AVIVID
);
1028 /* AVI Data Byte 5- set up input and output pixel repetition */
1029 val
= (((hdmi
->hdmi_data
.video_mode
.mpixelrepetitioninput
+ 1) <<
1030 HDMI_FC_PRCONF_INCOMING_PR_FACTOR_OFFSET
) &
1031 HDMI_FC_PRCONF_INCOMING_PR_FACTOR_MASK
) |
1032 ((hdmi
->hdmi_data
.video_mode
.mpixelrepetitionoutput
<<
1033 HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_OFFSET
) &
1034 HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_MASK
);
1035 hdmi_writeb(hdmi
, val
, HDMI_FC_PRCONF
);
1037 /* IT Content and quantization range = don't care */
1038 val
= HDMI_FC_AVICONF3_IT_CONTENT_TYPE_GRAPHICS
|
1039 HDMI_FC_AVICONF3_QUANT_RANGE_LIMITED
;
1040 hdmi_writeb(hdmi
, val
, HDMI_FC_AVICONF3
);
1042 /* AVI Data Bytes 6-13 */
1043 hdmi_writeb(hdmi
, 0, HDMI_FC_AVIETB0
);
1044 hdmi_writeb(hdmi
, 0, HDMI_FC_AVIETB1
);
1045 hdmi_writeb(hdmi
, 0, HDMI_FC_AVISBB0
);
1046 hdmi_writeb(hdmi
, 0, HDMI_FC_AVISBB1
);
1047 hdmi_writeb(hdmi
, 0, HDMI_FC_AVIELB0
);
1048 hdmi_writeb(hdmi
, 0, HDMI_FC_AVIELB1
);
1049 hdmi_writeb(hdmi
, 0, HDMI_FC_AVISRB0
);
1050 hdmi_writeb(hdmi
, 0, HDMI_FC_AVISRB1
);
1053 static void hdmi_av_composer(struct imx_hdmi
*hdmi
,
1054 const struct drm_display_mode
*mode
)
1057 struct hdmi_vmode
*vmode
= &hdmi
->hdmi_data
.video_mode
;
1058 int hblank
, vblank
, h_de_hs
, v_de_vs
, hsync_len
, vsync_len
;
1060 vmode
->mhsyncpolarity
= !!(mode
->flags
& DRM_MODE_FLAG_PHSYNC
);
1061 vmode
->mvsyncpolarity
= !!(mode
->flags
& DRM_MODE_FLAG_PVSYNC
);
1062 vmode
->minterlaced
= !!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
);
1063 vmode
->mpixelclock
= mode
->clock
* 1000;
1065 dev_dbg(hdmi
->dev
, "final pixclk = %d\n", vmode
->mpixelclock
);
1067 /* Set up HDMI_FC_INVIDCONF */
1068 inv_val
= (hdmi
->hdmi_data
.hdcp_enable
?
1069 HDMI_FC_INVIDCONF_HDCP_KEEPOUT_ACTIVE
:
1070 HDMI_FC_INVIDCONF_HDCP_KEEPOUT_INACTIVE
);
1072 inv_val
|= (vmode
->mvsyncpolarity
?
1073 HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_HIGH
:
1074 HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_LOW
);
1076 inv_val
|= (vmode
->mhsyncpolarity
?
1077 HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_HIGH
:
1078 HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_LOW
);
1080 inv_val
|= (vmode
->mdataenablepolarity
?
1081 HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH
:
1082 HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW
);
1084 if (hdmi
->vic
== 39)
1085 inv_val
|= HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH
;
1087 inv_val
|= (vmode
->minterlaced
?
1088 HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH
:
1089 HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW
);
1091 inv_val
|= (vmode
->minterlaced
?
1092 HDMI_FC_INVIDCONF_IN_I_P_INTERLACED
:
1093 HDMI_FC_INVIDCONF_IN_I_P_PROGRESSIVE
);
1095 inv_val
|= (vmode
->mdvi
?
1096 HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE
:
1097 HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE
);
1099 hdmi_writeb(hdmi
, inv_val
, HDMI_FC_INVIDCONF
);
1101 /* Set up horizontal active pixel width */
1102 hdmi_writeb(hdmi
, mode
->hdisplay
>> 8, HDMI_FC_INHACTV1
);
1103 hdmi_writeb(hdmi
, mode
->hdisplay
, HDMI_FC_INHACTV0
);
1105 /* Set up vertical active lines */
1106 hdmi_writeb(hdmi
, mode
->vdisplay
>> 8, HDMI_FC_INVACTV1
);
1107 hdmi_writeb(hdmi
, mode
->vdisplay
, HDMI_FC_INVACTV0
);
1109 /* Set up horizontal blanking pixel region width */
1110 hblank
= mode
->htotal
- mode
->hdisplay
;
1111 hdmi_writeb(hdmi
, hblank
>> 8, HDMI_FC_INHBLANK1
);
1112 hdmi_writeb(hdmi
, hblank
, HDMI_FC_INHBLANK0
);
1114 /* Set up vertical blanking pixel region width */
1115 vblank
= mode
->vtotal
- mode
->vdisplay
;
1116 hdmi_writeb(hdmi
, vblank
, HDMI_FC_INVBLANK
);
1118 /* Set up HSYNC active edge delay width (in pixel clks) */
1119 h_de_hs
= mode
->hsync_start
- mode
->hdisplay
;
1120 hdmi_writeb(hdmi
, h_de_hs
>> 8, HDMI_FC_HSYNCINDELAY1
);
1121 hdmi_writeb(hdmi
, h_de_hs
, HDMI_FC_HSYNCINDELAY0
);
1123 /* Set up VSYNC active edge delay (in lines) */
1124 v_de_vs
= mode
->vsync_start
- mode
->vdisplay
;
1125 hdmi_writeb(hdmi
, v_de_vs
, HDMI_FC_VSYNCINDELAY
);
1127 /* Set up HSYNC active pulse width (in pixel clks) */
1128 hsync_len
= mode
->hsync_end
- mode
->hsync_start
;
1129 hdmi_writeb(hdmi
, hsync_len
>> 8, HDMI_FC_HSYNCINWIDTH1
);
1130 hdmi_writeb(hdmi
, hsync_len
, HDMI_FC_HSYNCINWIDTH0
);
1132 /* Set up VSYNC active edge delay (in lines) */
1133 vsync_len
= mode
->vsync_end
- mode
->vsync_start
;
1134 hdmi_writeb(hdmi
, vsync_len
, HDMI_FC_VSYNCINWIDTH
);
1137 static void imx_hdmi_phy_disable(struct imx_hdmi
*hdmi
)
1139 if (!hdmi
->phy_enabled
)
1142 imx_hdmi_phy_enable_tmds(hdmi
, 0);
1143 imx_hdmi_phy_enable_power(hdmi
, 0);
1145 hdmi
->phy_enabled
= false;
1148 /* HDMI Initialization Step B.4 */
1149 static void imx_hdmi_enable_video_path(struct imx_hdmi
*hdmi
)
1153 /* control period minimum duration */
1154 hdmi_writeb(hdmi
, 12, HDMI_FC_CTRLDUR
);
1155 hdmi_writeb(hdmi
, 32, HDMI_FC_EXCTRLDUR
);
1156 hdmi_writeb(hdmi
, 1, HDMI_FC_EXCTRLSPAC
);
1158 /* Set to fill TMDS data channels */
1159 hdmi_writeb(hdmi
, 0x0B, HDMI_FC_CH0PREAM
);
1160 hdmi_writeb(hdmi
, 0x16, HDMI_FC_CH1PREAM
);
1161 hdmi_writeb(hdmi
, 0x21, HDMI_FC_CH2PREAM
);
1163 /* Enable pixel clock and tmds data path */
1165 clkdis
&= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE
;
1166 hdmi_writeb(hdmi
, clkdis
, HDMI_MC_CLKDIS
);
1168 clkdis
&= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE
;
1169 hdmi_writeb(hdmi
, clkdis
, HDMI_MC_CLKDIS
);
1171 /* Enable csc path */
1172 if (is_color_space_conversion(hdmi
)) {
1173 clkdis
&= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE
;
1174 hdmi_writeb(hdmi
, clkdis
, HDMI_MC_CLKDIS
);
1178 static void hdmi_enable_audio_clk(struct imx_hdmi
*hdmi
)
1180 hdmi_modb(hdmi
, 0, HDMI_MC_CLKDIS_AUDCLK_DISABLE
, HDMI_MC_CLKDIS
);
1183 /* Workaround to clear the overflow condition */
1184 static void imx_hdmi_clear_overflow(struct imx_hdmi
*hdmi
)
1189 /* TMDS software reset */
1190 hdmi_writeb(hdmi
, (u8
)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ
, HDMI_MC_SWRSTZ
);
1192 val
= hdmi_readb(hdmi
, HDMI_FC_INVIDCONF
);
1193 if (hdmi
->dev_type
== IMX6DL_HDMI
) {
1194 hdmi_writeb(hdmi
, val
, HDMI_FC_INVIDCONF
);
1198 for (count
= 0; count
< 4; count
++)
1199 hdmi_writeb(hdmi
, val
, HDMI_FC_INVIDCONF
);
1202 static void hdmi_enable_overflow_interrupts(struct imx_hdmi
*hdmi
)
1204 hdmi_writeb(hdmi
, 0, HDMI_FC_MASK2
);
1205 hdmi_writeb(hdmi
, 0, HDMI_IH_MUTE_FC_STAT2
);
1208 static void hdmi_disable_overflow_interrupts(struct imx_hdmi
*hdmi
)
1210 hdmi_writeb(hdmi
, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK
,
1211 HDMI_IH_MUTE_FC_STAT2
);
1214 static int imx_hdmi_setup(struct imx_hdmi
*hdmi
, struct drm_display_mode
*mode
)
1218 hdmi_disable_overflow_interrupts(hdmi
);
1220 hdmi
->vic
= drm_match_cea_mode(mode
);
1223 dev_dbg(hdmi
->dev
, "Non-CEA mode used in HDMI\n");
1224 hdmi
->hdmi_data
.video_mode
.mdvi
= true;
1226 dev_dbg(hdmi
->dev
, "CEA mode used vic=%d\n", hdmi
->vic
);
1227 hdmi
->hdmi_data
.video_mode
.mdvi
= false;
1230 if ((hdmi
->vic
== 6) || (hdmi
->vic
== 7) ||
1231 (hdmi
->vic
== 21) || (hdmi
->vic
== 22) ||
1232 (hdmi
->vic
== 2) || (hdmi
->vic
== 3) ||
1233 (hdmi
->vic
== 17) || (hdmi
->vic
== 18))
1234 hdmi
->hdmi_data
.colorimetry
= HDMI_COLORIMETRY_ITU_601
;
1236 hdmi
->hdmi_data
.colorimetry
= HDMI_COLORIMETRY_ITU_709
;
1238 if ((hdmi
->vic
== 10) || (hdmi
->vic
== 11) ||
1239 (hdmi
->vic
== 12) || (hdmi
->vic
== 13) ||
1240 (hdmi
->vic
== 14) || (hdmi
->vic
== 15) ||
1241 (hdmi
->vic
== 25) || (hdmi
->vic
== 26) ||
1242 (hdmi
->vic
== 27) || (hdmi
->vic
== 28) ||
1243 (hdmi
->vic
== 29) || (hdmi
->vic
== 30) ||
1244 (hdmi
->vic
== 35) || (hdmi
->vic
== 36) ||
1245 (hdmi
->vic
== 37) || (hdmi
->vic
== 38))
1246 hdmi
->hdmi_data
.video_mode
.mpixelrepetitionoutput
= 1;
1248 hdmi
->hdmi_data
.video_mode
.mpixelrepetitionoutput
= 0;
1250 hdmi
->hdmi_data
.video_mode
.mpixelrepetitioninput
= 0;
1252 /* TODO: Get input format from IPU (via FB driver interface) */
1253 hdmi
->hdmi_data
.enc_in_format
= RGB
;
1255 hdmi
->hdmi_data
.enc_out_format
= RGB
;
1257 hdmi
->hdmi_data
.enc_color_depth
= 8;
1258 hdmi
->hdmi_data
.pix_repet_factor
= 0;
1259 hdmi
->hdmi_data
.hdcp_enable
= 0;
1260 hdmi
->hdmi_data
.video_mode
.mdataenablepolarity
= true;
1262 /* HDMI Initialization Step B.1 */
1263 hdmi_av_composer(hdmi
, mode
);
1265 /* HDMI Initializateion Step B.2 */
1266 ret
= imx_hdmi_phy_init(hdmi
);
1270 /* HDMI Initialization Step B.3 */
1271 imx_hdmi_enable_video_path(hdmi
);
1273 /* not for DVI mode */
1274 if (hdmi
->hdmi_data
.video_mode
.mdvi
)
1275 dev_dbg(hdmi
->dev
, "%s DVI mode\n", __func__
);
1277 dev_dbg(hdmi
->dev
, "%s CEA mode\n", __func__
);
1279 /* HDMI Initialization Step E - Configure audio */
1280 hdmi_clk_regenerator_update_pixel_clock(hdmi
);
1281 hdmi_enable_audio_clk(hdmi
);
1283 /* HDMI Initialization Step F - Configure AVI InfoFrame */
1284 hdmi_config_AVI(hdmi
);
1287 hdmi_video_packetize(hdmi
);
1288 hdmi_video_csc(hdmi
);
1289 hdmi_video_sample(hdmi
);
1290 hdmi_tx_hdcp_config(hdmi
);
1292 imx_hdmi_clear_overflow(hdmi
);
1293 if (hdmi
->cable_plugin
&& !hdmi
->hdmi_data
.video_mode
.mdvi
)
1294 hdmi_enable_overflow_interrupts(hdmi
);
1299 /* Wait until we are registered to enable interrupts */
1300 static int imx_hdmi_fb_registered(struct imx_hdmi
*hdmi
)
1302 hdmi_writeb(hdmi
, HDMI_PHY_I2CM_INT_ADDR_DONE_POL
,
1303 HDMI_PHY_I2CM_INT_ADDR
);
1305 hdmi_writeb(hdmi
, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL
|
1306 HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL
,
1307 HDMI_PHY_I2CM_CTLINT_ADDR
);
1309 /* enable cable hot plug irq */
1310 hdmi_writeb(hdmi
, (u8
)~HDMI_PHY_HPD
, HDMI_PHY_MASK0
);
1312 /* Clear Hotplug interrupts */
1313 hdmi_writeb(hdmi
, HDMI_IH_PHY_STAT0_HPD
, HDMI_IH_PHY_STAT0
);
1318 static void initialize_hdmi_ih_mutes(struct imx_hdmi
*hdmi
)
1323 * Boot up defaults are:
1324 * HDMI_IH_MUTE = 0x03 (disabled)
1325 * HDMI_IH_MUTE_* = 0x00 (enabled)
1327 * Disable top level interrupt bits in HDMI block
1329 ih_mute
= hdmi_readb(hdmi
, HDMI_IH_MUTE
) |
1330 HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT
|
1331 HDMI_IH_MUTE_MUTE_ALL_INTERRUPT
;
1333 hdmi_writeb(hdmi
, ih_mute
, HDMI_IH_MUTE
);
1335 /* by default mask all interrupts */
1336 hdmi_writeb(hdmi
, 0xff, HDMI_VP_MASK
);
1337 hdmi_writeb(hdmi
, 0xff, HDMI_FC_MASK0
);
1338 hdmi_writeb(hdmi
, 0xff, HDMI_FC_MASK1
);
1339 hdmi_writeb(hdmi
, 0xff, HDMI_FC_MASK2
);
1340 hdmi_writeb(hdmi
, 0xff, HDMI_PHY_MASK0
);
1341 hdmi_writeb(hdmi
, 0xff, HDMI_PHY_I2CM_INT_ADDR
);
1342 hdmi_writeb(hdmi
, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR
);
1343 hdmi_writeb(hdmi
, 0xff, HDMI_AUD_INT
);
1344 hdmi_writeb(hdmi
, 0xff, HDMI_AUD_SPDIFINT
);
1345 hdmi_writeb(hdmi
, 0xff, HDMI_AUD_HBR_MASK
);
1346 hdmi_writeb(hdmi
, 0xff, HDMI_GP_MASK
);
1347 hdmi_writeb(hdmi
, 0xff, HDMI_A_APIINTMSK
);
1348 hdmi_writeb(hdmi
, 0xff, HDMI_CEC_MASK
);
1349 hdmi_writeb(hdmi
, 0xff, HDMI_I2CM_INT
);
1350 hdmi_writeb(hdmi
, 0xff, HDMI_I2CM_CTLINT
);
1352 /* Disable interrupts in the IH_MUTE_* registers */
1353 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_FC_STAT0
);
1354 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_FC_STAT1
);
1355 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_FC_STAT2
);
1356 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_AS_STAT0
);
1357 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_PHY_STAT0
);
1358 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_I2CM_STAT0
);
1359 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_CEC_STAT0
);
1360 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_VP_STAT0
);
1361 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0
);
1362 hdmi_writeb(hdmi
, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0
);
1364 /* Enable top level interrupt bits in HDMI block */
1365 ih_mute
&= ~(HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT
|
1366 HDMI_IH_MUTE_MUTE_ALL_INTERRUPT
);
1367 hdmi_writeb(hdmi
, ih_mute
, HDMI_IH_MUTE
);
1370 static void imx_hdmi_poweron(struct imx_hdmi
*hdmi
)
1372 imx_hdmi_setup(hdmi
, &hdmi
->previous_mode
);
1375 static void imx_hdmi_poweroff(struct imx_hdmi
*hdmi
)
1377 imx_hdmi_phy_disable(hdmi
);
1380 static enum drm_connector_status
imx_hdmi_connector_detect(struct drm_connector
1381 *connector
, bool force
)
1383 struct imx_hdmi
*hdmi
= container_of(connector
, struct imx_hdmi
,
1385 return hdmi
->connector_status
;
1388 static int imx_hdmi_connector_get_modes(struct drm_connector
*connector
)
1390 struct imx_hdmi
*hdmi
= container_of(connector
, struct imx_hdmi
,
1398 edid
= drm_get_edid(connector
, hdmi
->ddc
);
1400 dev_dbg(hdmi
->dev
, "got edid: width[%d] x height[%d]\n",
1401 edid
->width_cm
, edid
->height_cm
);
1403 drm_mode_connector_update_edid_property(connector
, edid
);
1404 ret
= drm_add_edid_modes(connector
, edid
);
1407 dev_dbg(hdmi
->dev
, "failed to get edid\n");
1413 static struct drm_encoder
*imx_hdmi_connector_best_encoder(struct drm_connector
1416 struct imx_hdmi
*hdmi
= container_of(connector
, struct imx_hdmi
,
1419 return &hdmi
->encoder
;
1422 static void imx_hdmi_encoder_mode_set(struct drm_encoder
*encoder
,
1423 struct drm_display_mode
*mode
,
1424 struct drm_display_mode
*adjusted_mode
)
1426 struct imx_hdmi
*hdmi
= container_of(encoder
, struct imx_hdmi
, encoder
);
1428 imx_hdmi_setup(hdmi
, mode
);
1430 /* Store the display mode for plugin/DKMS poweron events */
1431 memcpy(&hdmi
->previous_mode
, mode
, sizeof(hdmi
->previous_mode
));
1434 static bool imx_hdmi_encoder_mode_fixup(struct drm_encoder
*encoder
,
1435 const struct drm_display_mode
*mode
,
1436 struct drm_display_mode
*adjusted_mode
)
1441 static void imx_hdmi_encoder_disable(struct drm_encoder
*encoder
)
1445 static void imx_hdmi_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
1447 struct imx_hdmi
*hdmi
= container_of(encoder
, struct imx_hdmi
, encoder
);
1450 imx_hdmi_poweroff(hdmi
);
1452 imx_hdmi_poweron(hdmi
);
1455 static void imx_hdmi_encoder_prepare(struct drm_encoder
*encoder
)
1457 struct imx_hdmi
*hdmi
= container_of(encoder
, struct imx_hdmi
, encoder
);
1459 imx_hdmi_poweroff(hdmi
);
1460 imx_drm_panel_format(encoder
, V4L2_PIX_FMT_RGB24
);
1463 static void imx_hdmi_encoder_commit(struct drm_encoder
*encoder
)
1465 struct imx_hdmi
*hdmi
= container_of(encoder
, struct imx_hdmi
, encoder
);
1466 int mux
= imx_drm_encoder_get_mux_id(hdmi
->dev
->of_node
, encoder
);
1468 imx_hdmi_set_ipu_di_mux(hdmi
, mux
);
1470 imx_hdmi_poweron(hdmi
);
1473 static struct drm_encoder_funcs imx_hdmi_encoder_funcs
= {
1474 .destroy
= imx_drm_encoder_destroy
,
1477 static struct drm_encoder_helper_funcs imx_hdmi_encoder_helper_funcs
= {
1478 .dpms
= imx_hdmi_encoder_dpms
,
1479 .prepare
= imx_hdmi_encoder_prepare
,
1480 .commit
= imx_hdmi_encoder_commit
,
1481 .mode_set
= imx_hdmi_encoder_mode_set
,
1482 .mode_fixup
= imx_hdmi_encoder_mode_fixup
,
1483 .disable
= imx_hdmi_encoder_disable
,
1486 static struct drm_connector_funcs imx_hdmi_connector_funcs
= {
1487 .dpms
= drm_helper_connector_dpms
,
1488 .fill_modes
= drm_helper_probe_single_connector_modes
,
1489 .detect
= imx_hdmi_connector_detect
,
1490 .destroy
= imx_drm_connector_destroy
,
1493 static struct drm_connector_helper_funcs imx_hdmi_connector_helper_funcs
= {
1494 .get_modes
= imx_hdmi_connector_get_modes
,
1495 .mode_valid
= imx_drm_connector_mode_valid
,
1496 .best_encoder
= imx_hdmi_connector_best_encoder
,
1499 static irqreturn_t
imx_hdmi_hardirq(int irq
, void *dev_id
)
1501 struct imx_hdmi
*hdmi
= dev_id
;
1504 intr_stat
= hdmi_readb(hdmi
, HDMI_IH_PHY_STAT0
);
1506 hdmi_writeb(hdmi
, ~0, HDMI_IH_MUTE_PHY_STAT0
);
1508 return intr_stat
? IRQ_WAKE_THREAD
: IRQ_NONE
;
1511 static irqreturn_t
imx_hdmi_irq(int irq
, void *dev_id
)
1513 struct imx_hdmi
*hdmi
= dev_id
;
1517 intr_stat
= hdmi_readb(hdmi
, HDMI_IH_PHY_STAT0
);
1519 phy_int_pol
= hdmi_readb(hdmi
, HDMI_PHY_POL0
);
1521 if (intr_stat
& HDMI_IH_PHY_STAT0_HPD
) {
1522 if (phy_int_pol
& HDMI_PHY_HPD
) {
1523 dev_dbg(hdmi
->dev
, "EVENT=plugin\n");
1525 hdmi_modb(hdmi
, 0, HDMI_PHY_HPD
, HDMI_PHY_POL0
);
1527 hdmi
->connector_status
= connector_status_connected
;
1528 imx_hdmi_poweron(hdmi
);
1530 dev_dbg(hdmi
->dev
, "EVENT=plugout\n");
1532 hdmi_modb(hdmi
, HDMI_PHY_HPD
, HDMI_PHY_HPD
,
1535 hdmi
->connector_status
= connector_status_disconnected
;
1536 imx_hdmi_poweroff(hdmi
);
1538 drm_helper_hpd_irq_event(hdmi
->connector
.dev
);
1541 hdmi_writeb(hdmi
, intr_stat
, HDMI_IH_PHY_STAT0
);
1542 hdmi_writeb(hdmi
, ~HDMI_IH_PHY_STAT0_HPD
, HDMI_IH_MUTE_PHY_STAT0
);
1547 static int imx_hdmi_register(struct drm_device
*drm
, struct imx_hdmi
*hdmi
)
1551 ret
= imx_drm_encoder_parse_of(drm
, &hdmi
->encoder
,
1552 hdmi
->dev
->of_node
);
1556 hdmi
->connector
.polled
= DRM_CONNECTOR_POLL_HPD
;
1558 drm_encoder_helper_add(&hdmi
->encoder
, &imx_hdmi_encoder_helper_funcs
);
1559 drm_encoder_init(drm
, &hdmi
->encoder
, &imx_hdmi_encoder_funcs
,
1560 DRM_MODE_ENCODER_TMDS
);
1562 drm_connector_helper_add(&hdmi
->connector
,
1563 &imx_hdmi_connector_helper_funcs
);
1564 drm_connector_init(drm
, &hdmi
->connector
, &imx_hdmi_connector_funcs
,
1565 DRM_MODE_CONNECTOR_HDMIA
);
1567 hdmi
->connector
.encoder
= &hdmi
->encoder
;
1569 drm_mode_connector_attach_encoder(&hdmi
->connector
, &hdmi
->encoder
);
1574 static struct platform_device_id imx_hdmi_devtype
[] = {
1576 .name
= "imx6q-hdmi",
1577 .driver_data
= IMX6Q_HDMI
,
1579 .name
= "imx6dl-hdmi",
1580 .driver_data
= IMX6DL_HDMI
,
1581 }, { /* sentinel */ }
1583 MODULE_DEVICE_TABLE(platform
, imx_hdmi_devtype
);
1585 static const struct of_device_id imx_hdmi_dt_ids
[] = {
1586 { .compatible
= "fsl,imx6q-hdmi", .data
= &imx_hdmi_devtype
[IMX6Q_HDMI
], },
1587 { .compatible
= "fsl,imx6dl-hdmi", .data
= &imx_hdmi_devtype
[IMX6DL_HDMI
], },
1590 MODULE_DEVICE_TABLE(of
, imx_hdmi_dt_ids
);
1592 static int imx_hdmi_bind(struct device
*dev
, struct device
*master
, void *data
)
1594 struct platform_device
*pdev
= to_platform_device(dev
);
1595 const struct of_device_id
*of_id
=
1596 of_match_device(imx_hdmi_dt_ids
, dev
);
1597 struct drm_device
*drm
= data
;
1598 struct device_node
*np
= dev
->of_node
;
1599 struct device_node
*ddc_node
;
1600 struct imx_hdmi
*hdmi
;
1601 struct resource
*iores
;
1604 hdmi
= devm_kzalloc(dev
, sizeof(*hdmi
), GFP_KERNEL
);
1609 hdmi
->connector_status
= connector_status_disconnected
;
1610 hdmi
->sample_rate
= 48000;
1614 const struct platform_device_id
*device_id
= of_id
->data
;
1615 hdmi
->dev_type
= device_id
->driver_data
;
1618 ddc_node
= of_parse_phandle(np
, "ddc-i2c-bus", 0);
1620 hdmi
->ddc
= of_find_i2c_adapter_by_node(ddc_node
);
1622 dev_dbg(hdmi
->dev
, "failed to read ddc node\n");
1624 of_node_put(ddc_node
);
1626 dev_dbg(hdmi
->dev
, "no ddc property found\n");
1629 irq
= platform_get_irq(pdev
, 0);
1633 ret
= devm_request_threaded_irq(dev
, irq
, imx_hdmi_hardirq
,
1634 imx_hdmi_irq
, IRQF_SHARED
,
1635 dev_name(dev
), hdmi
);
1639 iores
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1640 hdmi
->regs
= devm_ioremap_resource(dev
, iores
);
1641 if (IS_ERR(hdmi
->regs
))
1642 return PTR_ERR(hdmi
->regs
);
1644 hdmi
->regmap
= syscon_regmap_lookup_by_phandle(np
, "gpr");
1645 if (IS_ERR(hdmi
->regmap
))
1646 return PTR_ERR(hdmi
->regmap
);
1648 hdmi
->isfr_clk
= devm_clk_get(hdmi
->dev
, "isfr");
1649 if (IS_ERR(hdmi
->isfr_clk
)) {
1650 ret
= PTR_ERR(hdmi
->isfr_clk
);
1652 "Unable to get HDMI isfr clk: %d\n", ret
);
1656 ret
= clk_prepare_enable(hdmi
->isfr_clk
);
1659 "Cannot enable HDMI isfr clock: %d\n", ret
);
1663 hdmi
->iahb_clk
= devm_clk_get(hdmi
->dev
, "iahb");
1664 if (IS_ERR(hdmi
->iahb_clk
)) {
1665 ret
= PTR_ERR(hdmi
->iahb_clk
);
1667 "Unable to get HDMI iahb clk: %d\n", ret
);
1671 ret
= clk_prepare_enable(hdmi
->iahb_clk
);
1674 "Cannot enable HDMI iahb clock: %d\n", ret
);
1678 /* Product and revision IDs */
1680 "Detected HDMI controller 0x%x:0x%x:0x%x:0x%x\n",
1681 hdmi_readb(hdmi
, HDMI_DESIGN_ID
),
1682 hdmi_readb(hdmi
, HDMI_REVISION_ID
),
1683 hdmi_readb(hdmi
, HDMI_PRODUCT_ID0
),
1684 hdmi_readb(hdmi
, HDMI_PRODUCT_ID1
));
1686 initialize_hdmi_ih_mutes(hdmi
);
1689 * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
1690 * N and cts values before enabling phy
1692 hdmi_init_clk_regenerator(hdmi
);
1695 * Configure registers related to HDMI interrupt
1696 * generation before registering IRQ.
1698 hdmi_writeb(hdmi
, HDMI_PHY_HPD
, HDMI_PHY_POL0
);
1700 /* Clear Hotplug interrupts */
1701 hdmi_writeb(hdmi
, HDMI_IH_PHY_STAT0_HPD
, HDMI_IH_PHY_STAT0
);
1703 ret
= imx_hdmi_fb_registered(hdmi
);
1707 ret
= imx_hdmi_register(drm
, hdmi
);
1711 /* Unmute interrupts */
1712 hdmi_writeb(hdmi
, ~HDMI_IH_PHY_STAT0_HPD
, HDMI_IH_MUTE_PHY_STAT0
);
1714 dev_set_drvdata(dev
, hdmi
);
1719 clk_disable_unprepare(hdmi
->iahb_clk
);
1721 clk_disable_unprepare(hdmi
->isfr_clk
);
1726 static void imx_hdmi_unbind(struct device
*dev
, struct device
*master
,
1729 struct imx_hdmi
*hdmi
= dev_get_drvdata(dev
);
1731 /* Disable all interrupts */
1732 hdmi_writeb(hdmi
, ~0, HDMI_IH_MUTE_PHY_STAT0
);
1734 hdmi
->connector
.funcs
->destroy(&hdmi
->connector
);
1735 hdmi
->encoder
.funcs
->destroy(&hdmi
->encoder
);
1737 clk_disable_unprepare(hdmi
->iahb_clk
);
1738 clk_disable_unprepare(hdmi
->isfr_clk
);
1739 i2c_put_adapter(hdmi
->ddc
);
1742 static const struct component_ops hdmi_ops
= {
1743 .bind
= imx_hdmi_bind
,
1744 .unbind
= imx_hdmi_unbind
,
1747 static int imx_hdmi_platform_probe(struct platform_device
*pdev
)
1749 return component_add(&pdev
->dev
, &hdmi_ops
);
1752 static int imx_hdmi_platform_remove(struct platform_device
*pdev
)
1754 component_del(&pdev
->dev
, &hdmi_ops
);
1758 static struct platform_driver imx_hdmi_driver
= {
1759 .probe
= imx_hdmi_platform_probe
,
1760 .remove
= imx_hdmi_platform_remove
,
1763 .owner
= THIS_MODULE
,
1764 .of_match_table
= imx_hdmi_dt_ids
,
1768 module_platform_driver(imx_hdmi_driver
);
1770 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
1771 MODULE_DESCRIPTION("i.MX6 HDMI transmitter driver");
1772 MODULE_LICENSE("GPL");
1773 MODULE_ALIAS("platform:imx-hdmi");