paul@62 | 1 | /* |
paul@62 | 2 | * JZ4780 HDMI peripheral support. |
paul@62 | 3 | * |
paul@62 | 4 | * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk> |
paul@62 | 5 | * |
paul@66 | 6 | * Techniques and operations introduced from the Linux DRM bridge driver for |
paul@66 | 7 | * Synopsys DW-HDMI whose authors are as follows: |
paul@66 | 8 | * |
paul@66 | 9 | * Copyright (C) 2013-2015 Mentor Graphics Inc. |
paul@66 | 10 | * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. |
paul@66 | 11 | * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
paul@66 | 12 | * |
paul@62 | 13 | * This program is free software; you can redistribute it and/or |
paul@62 | 14 | * modify it under the terms of the GNU General Public License as |
paul@62 | 15 | * published by the Free Software Foundation; either version 2 of |
paul@62 | 16 | * the License, or (at your option) any later version. |
paul@62 | 17 | * |
paul@62 | 18 | * This program is distributed in the hope that it will be useful, |
paul@62 | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@62 | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@62 | 21 | * GNU General Public License for more details. |
paul@62 | 22 | * |
paul@62 | 23 | * You should have received a copy of the GNU General Public License |
paul@62 | 24 | * along with this program; if not, write to the Free Software |
paul@62 | 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@62 | 26 | * Boston, MA 02110-1301, USA |
paul@66 | 27 | * |
paul@66 | 28 | * ---- |
paul@66 | 29 | * |
paul@66 | 30 | * Some acronyms: |
paul@66 | 31 | * |
paul@66 | 32 | * CEC (Consumer Electronics Control) is a HDMI device control interface for up |
paul@66 | 33 | * to 15 devices. |
paul@66 | 34 | * |
paul@66 | 35 | * CSC (Colour Space Conversion) is the processing needed to convert from one |
paul@66 | 36 | * representation of colours to another. |
paul@66 | 37 | * |
paul@66 | 38 | * HEAC (HDMI Ethernet and Audio Return Channel) is a combination of HEC (HDMI |
paul@66 | 39 | * Ethernet Channel) which provides a 100Mb/s bidirectional link and ARC (Audio |
paul@66 | 40 | * Return Channel) which permits the consumption of audio data from the device. |
paul@66 | 41 | * |
paul@66 | 42 | * MHL (Mobile High-Definition Link) is an adaptation of HDMI for mobile |
paul@66 | 43 | * devices. |
paul@66 | 44 | * |
paul@66 | 45 | * TMDS (Transition-Minimized Differential Signaling) is the method by which |
paul@66 | 46 | * audio, control and video data are all sent to the device. |
paul@62 | 47 | */ |
paul@62 | 48 | |
paul@62 | 49 | #include <l4/devices/hdmi-jz4780.h> |
paul@62 | 50 | #include <l4/devices/hw_mmio_register_block.h> |
paul@66 | 51 | #include <l4/devices/lcd-jz4740-config.h> |
paul@62 | 52 | |
paul@62 | 53 | #include <l4/sys/irq.h> |
paul@62 | 54 | #include <l4/util/util.h> |
paul@62 | 55 | |
paul@62 | 56 | #include <cstdio> |
paul@62 | 57 | |
paul@62 | 58 | /* |
paul@62 | 59 | I2C pins: |
paul@62 | 60 | |
paul@62 | 61 | HDMI: PF25/SMB4_SDA/DDCSDA, PF24/SMB4_SCK/DDCSCK |
paul@62 | 62 | |
paul@62 | 63 | See: http://mipscreator.imgtec.com/CI20/hardware/board/ci20_jz4780_v2.0.pdf |
paul@62 | 64 | */ |
paul@62 | 65 | |
paul@62 | 66 | enum Regs |
paul@62 | 67 | { |
paul@62 | 68 | // Identification. |
paul@62 | 69 | |
paul@66 | 70 | Design_id = 0x000, // DESIGN_ID |
paul@66 | 71 | Revision_id = 0x001, // REVISION_ID |
paul@66 | 72 | Product_id0 = 0x002, // PRODUCT_ID0 |
paul@66 | 73 | Product_id1 = 0x003, // PRODUCT_ID1 |
paul@66 | 74 | Config_id0 = 0x004, // CONFIG_ID0 |
paul@66 | 75 | Config_id1 = 0x005, // CONFIG_ID1 |
paul@66 | 76 | Config_id2 = 0x006, // CONFIG_ID2 |
paul@66 | 77 | Config_id3 = 0x007, // CONFIG_ID3 |
paul@62 | 78 | |
paul@62 | 79 | // Top-level interrupt control. |
paul@62 | 80 | |
paul@66 | 81 | Int_mask = 0x1ff, // MUTE |
paul@62 | 82 | |
paul@62 | 83 | // Interrupt status and mask for various functions. |
paul@62 | 84 | |
paul@66 | 85 | Fc_int_status0 = 0x100, // FC_STAT0 |
paul@66 | 86 | Fc_int_status1 = 0x101, // FC_STAT1 |
paul@66 | 87 | Fc_int_status2 = 0x102, // FC_STAT2 |
paul@66 | 88 | As_int_status = 0x103, // AS_STAT0 |
paul@66 | 89 | Phy_int_status = 0x104, // PHY_STAT0 |
paul@66 | 90 | Cec_int_status = 0x106, // CEC_STAT0 |
paul@66 | 91 | Vp_int_status = 0x107, // VP_STAT0 |
paul@66 | 92 | Ahb_dma_audio_int_status = 0x109, // AHBDMAAUD_STAT0 |
paul@62 | 93 | |
paul@66 | 94 | Fc_int_mask0 = 0x180, // MUTE_FC_STAT0 |
paul@66 | 95 | Fc_int_mask1 = 0x181, // MUTE_FC_STAT1 |
paul@66 | 96 | Fc_int_mask2 = 0x182, // MUTE_FC_STAT2 |
paul@66 | 97 | As_int_mask = 0x183, // MUTE_AS_STAT0 |
paul@66 | 98 | Phy_int_mask = 0x184, // MUTE_PHY_STAT0 |
paul@66 | 99 | Cec_int_mask = 0x186, // MUTE_CEC_STAT0 |
paul@66 | 100 | Vp_int_mask = 0x187, // MUTE_VP_STAT0 |
paul@66 | 101 | Ahb_dma_audio_int_mask = 0x189, // MUTE_AHBDMAAUD_STAT0 |
paul@62 | 102 | |
paul@62 | 103 | // I2C for E-DDC. |
paul@62 | 104 | |
paul@66 | 105 | I2c_int_status = 0x105, // I2CM_STAT0 |
paul@66 | 106 | I2c_int_mask = 0x185, // MUTE_I2CM_STAT0 |
paul@62 | 107 | |
paul@66 | 108 | I2c_device_address = 0x7e00, // I2CM_SLAVE |
paul@66 | 109 | I2c_register = 0x7e01, // I2CM_ADDRESS |
paul@66 | 110 | I2c_data_out = 0x7e02, // I2CM_DATAO |
paul@66 | 111 | I2c_data_in = 0x7e03, // I2CM_DATAI |
paul@66 | 112 | I2c_operation = 0x7e04, // I2CM_OPERATION |
paul@66 | 113 | I2c_int_config0 = 0x7e05, // I2CM_INT |
paul@66 | 114 | I2c_int_config1 = 0x7e06, // I2CM_CTLINT |
paul@66 | 115 | I2c_divider = 0x7e07, // I2CM_DIV |
paul@66 | 116 | I2c_segment_address = 0x7e08, // I2CM_SEGADDR |
paul@66 | 117 | I2c_software_reset = 0x7e09, // I2CM_SOFTRSTZ |
paul@66 | 118 | I2c_segment_pointer = 0x7e0a, // I2CM_SEGPTR |
paul@62 | 119 | |
paul@62 | 120 | // I2C for PHY. |
paul@62 | 121 | |
paul@66 | 122 | I2c_phy_int_status = 0x108, // I2CMPHY_STAT0 |
paul@66 | 123 | I2c_phy_int_mask = 0x188, // MUTE_I2CMPHY_STAT0 |
paul@62 | 124 | |
paul@66 | 125 | I2c_phy_device_address = 0x3020, // PHY_I2CM_SLAVE_ADDR |
paul@66 | 126 | I2c_phy_register = 0x3021, // PHY_I2CM_ADDRESS_ADDR |
paul@66 | 127 | I2c_phy_data_out1 = 0x3022, // PHY_I2CM_DATAO_1_ADDR |
paul@66 | 128 | I2c_phy_data_out0 = 0x3023, // PHY_I2CM_DATAO_0_ADDR |
paul@66 | 129 | I2c_phy_data_in1 = 0x3024, // PHY_I2CM_DATAI_1_ADDR |
paul@66 | 130 | I2c_phy_data_in0 = 0x3025, // PHY_I2CM_DATAI_0_ADDR |
paul@66 | 131 | I2c_phy_operation = 0x3026, // PHY_I2CM_OPERATION_ADDR |
paul@66 | 132 | I2c_phy_int_config0 = 0x3027, // PHY_I2CM_INT_ADDR |
paul@66 | 133 | I2c_phy_int_config1 = 0x3028, // PHY_I2CM_CTLINT_ADDR |
paul@66 | 134 | I2c_phy_divider = 0x3029, // PHY_I2CM_DIV_ADDR |
paul@66 | 135 | I2c_phy_software_reset = 0x302a, // PHY_I2CM_SOFTRSTZ_ADDR |
paul@65 | 136 | |
paul@65 | 137 | // PHY registers. |
paul@65 | 138 | |
paul@66 | 139 | Phy_config = 0x3000, // PHY_CONF0 |
paul@66 | 140 | Phy_test0 = 0x3001, // PHY_TST0 |
paul@66 | 141 | Phy_test1 = 0x3002, // PHY_TST1 |
paul@66 | 142 | Phy_test2 = 0x3003, // PHY_TST2 |
paul@66 | 143 | Phy_status = 0x3004, // PHY_STAT0 |
paul@66 | 144 | Phy_int_config = 0x3005, // PHY_INT0 |
paul@66 | 145 | Phy_mask = 0x3006, // PHY_MASK0 |
paul@66 | 146 | Phy_polarity = 0x3007, // PHY_POL0 |
paul@66 | 147 | |
paul@66 | 148 | // Main controller registers. |
paul@66 | 149 | |
paul@66 | 150 | Main_clock_disable = 0x4001, // MC_CLKDIS |
paul@66 | 151 | Main_software_reset = 0x4002, // MC_SWRSTZ |
paul@66 | 152 | Main_flow_control = 0x4004, // MC_FLOWCTRL |
paul@66 | 153 | Main_reset = 0x4005, // MC_PHYRSTZ |
paul@66 | 154 | Main_heac_phy_reset = 0x4007, // MC_HEACPHY_RST |
paul@66 | 155 | |
paul@66 | 156 | // Frame composer registers for input video. |
paul@66 | 157 | |
paul@66 | 158 | Fc_video_config = 0x1000, // FC_INVIDCONF |
paul@66 | 159 | Fc_horizontal_active_width0 = 0x1001, // FC_INHACTV0 |
paul@66 | 160 | Fc_horizontal_active_width1 = 0x1002, // FC_INHACTV1 |
paul@66 | 161 | Fc_horizontal_blank_width0 = 0x1003, // FC_INHBLANK0 |
paul@66 | 162 | Fc_horizontal_blank_width1 = 0x1004, // FC_INHBLANK1 |
paul@66 | 163 | Fc_vertical_active_height0 = 0x1005, // FC_INVACTV0 |
paul@66 | 164 | Fc_vertical_active_height1 = 0x1006, // FC_INVACTV1 |
paul@66 | 165 | Fc_vertical_blank_height = 0x1007, // FC_INVBLANK |
paul@66 | 166 | |
paul@66 | 167 | // Frame composer registers for sync pulses. |
paul@66 | 168 | |
paul@66 | 169 | Fc_hsync_delay0 = 0x1008, // FC_HSYNCINDELAY0 |
paul@66 | 170 | Fc_hsync_delay1 = 0x1009, // FC_HSYNCINDELAY1 |
paul@66 | 171 | Fc_hsync_width0 = 0x100A, // FC_HSYNCINWIDTH0 |
paul@66 | 172 | Fc_hsync_width1 = 0x100B, // FC_HSYNCINWIDTH1 |
paul@66 | 173 | Fc_vsync_delay = 0x100C, // FC_VSYNCINDELAY |
paul@66 | 174 | Fc_vsync_height = 0x100D, // FC_VSYNCINWIDTH |
paul@66 | 175 | |
paul@66 | 176 | // Frame composer registers for video path configuration. |
paul@66 | 177 | |
paul@66 | 178 | Fc_control_duration = 0x1011, // FC_CTRLDUR |
paul@66 | 179 | Fc_ex_control_duration = 0x1012, // FC_EXCTRLDUR |
paul@66 | 180 | Fc_ex_control_space = 0x1013, // FC_EXCTRLSPAC |
paul@66 | 181 | Fc_channel0_preamble = 0x1014, // FC_CH0PREAM |
paul@66 | 182 | Fc_channel1_preamble = 0x1015, // FC_CH1PREAM |
paul@66 | 183 | Fc_channel2_preamble = 0x1016, // FC_CH2PREAM |
paul@66 | 184 | |
paul@66 | 185 | // Colour space conversion registers. |
paul@66 | 186 | |
paul@66 | 187 | Csc_config = 0x4100, // CSC_CFG |
paul@66 | 188 | Csc_scale = 0x4101, // CSC_SCALE |
paul@66 | 189 | |
paul@66 | 190 | // HDCP registers. |
paul@66 | 191 | |
paul@66 | 192 | Hdcp_config0 = 0x5000, // A_HDCPCFG0 |
paul@66 | 193 | Hdcp_config1 = 0x5001, // A_HDCPCFG1 |
paul@66 | 194 | Hdcp_video_polarity = 0x5009, // A_VIDPOLCFG |
paul@66 | 195 | |
paul@66 | 196 | // Video sample registers. |
paul@66 | 197 | |
paul@66 | 198 | Sample_video_config = 0x0200, // TX_INVID0 |
paul@66 | 199 | Sample_video_stuffing = 0x0201, // TX_INSTUFFING |
paul@66 | 200 | Sample_gy_data0 = 0x0202, // TX_GYDATA0 |
paul@66 | 201 | Sample_gy_data1 = 0x0203, // TX_GYDATA1 |
paul@66 | 202 | Sample_rcr_data0 = 0x0204, // TX_RCRDATA0 |
paul@66 | 203 | Sample_rcr_data1 = 0x0205, // TX_RCRDATA1 |
paul@66 | 204 | Sample_bcb_data0 = 0x0206, // TX_BCBDATA0 |
paul@66 | 205 | Sample_bcb_data1 = 0x0207, // TX_BCBDATA1 |
paul@66 | 206 | |
paul@66 | 207 | // Video packetizer registers. |
paul@66 | 208 | |
paul@66 | 209 | Packet_status = 0x0800, // VP_STATUS |
paul@66 | 210 | Packet_pixel_repeater = 0x0801, // VP_PR_CD |
paul@66 | 211 | Packet_stuffing = 0x0802, // VP_STUFF |
paul@66 | 212 | Packet_remap = 0x0803, // VP_REMAP |
paul@66 | 213 | Packet_config = 0x0804, // VP_CONF |
paul@62 | 214 | }; |
paul@62 | 215 | |
paul@62 | 216 | // Identification values. |
paul@62 | 217 | |
paul@62 | 218 | enum Product_id_values : unsigned |
paul@62 | 219 | { |
paul@65 | 220 | Product_id0_transmitter = 0xa0, // PRODUCT_ID0_HDMI_TX |
paul@62 | 221 | |
paul@65 | 222 | Product_id1_hdcp = 0xc0, // PRODUCT_ID1_HDCP |
paul@65 | 223 | Product_id1_receiver = 0x02, // PRODUCT_ID1_HDMI_RX |
paul@65 | 224 | Product_id1_transmitter = 0x01, // PRODUCT_ID1_HDMI_TX |
paul@62 | 225 | }; |
paul@62 | 226 | |
paul@62 | 227 | // Configuration values. |
paul@62 | 228 | |
paul@62 | 229 | enum Config_id_values : unsigned |
paul@62 | 230 | { |
paul@62 | 231 | Config_id0_i2s = 0x10, // CONFIG0_I2S |
paul@62 | 232 | Config_id0_cec = 0x02, // CONFIG0_CEC |
paul@62 | 233 | |
paul@62 | 234 | Config_id1_ahb = 0x01, // CONFIG1_AHB |
paul@62 | 235 | |
paul@62 | 236 | Config2_dwc_hdmi_tx_phy = 0x00, // DWC_HDMI_TX_PHY |
paul@62 | 237 | Config2_dwc_mhl_phy_heac = 0xb2, // DWC_MHL_PHY_HEAC |
paul@62 | 238 | Config2_dwc_mhl_phy = 0xc2, // DWC_MHL_PHY |
paul@62 | 239 | Config2_dwc_hdmi_3d_tx_phy_heac = 0xe2, // DWC_HDMI_3D_TX_PHY_HEAC |
paul@62 | 240 | Config2_dwc_hdmi_3d_tx_phy = 0xf2, // DWC_HDMI_3D_TX_PHY |
paul@62 | 241 | Config2_dwc_hdmi20_tx_phy = 0xf3, // DWC_HDMI20_TX_PHY |
paul@62 | 242 | Config2_vendor_phy = 0xfe, // VENDOR_PHY |
paul@62 | 243 | |
paul@62 | 244 | Config_id3_ahb_audio_dma = 0x02, // CONFIG3_AHBAUDDMA |
paul@62 | 245 | Config_id3_gp_audio = 0x01, // CONFIG3_GPAUD |
paul@62 | 246 | }; |
paul@62 | 247 | |
paul@62 | 248 | // Status and mask bits. |
paul@62 | 249 | |
paul@62 | 250 | enum Int_mask_bits : unsigned |
paul@62 | 251 | { |
paul@65 | 252 | Int_mask_wakeup = 0x02, |
paul@65 | 253 | Int_mask_all = 0x01, |
paul@62 | 254 | }; |
paul@62 | 255 | |
paul@66 | 256 | // I2C status and mask bits, also for PHY I2C. |
paul@66 | 257 | |
paul@62 | 258 | enum I2c_int_status_bits : unsigned |
paul@62 | 259 | { |
paul@65 | 260 | I2c_int_status_done = 0x02, |
paul@65 | 261 | I2c_int_status_error = 0x01, |
paul@62 | 262 | }; |
paul@62 | 263 | |
paul@62 | 264 | // I2C operation bits. |
paul@62 | 265 | |
paul@62 | 266 | enum I2c_operation_bits : unsigned |
paul@62 | 267 | { |
paul@65 | 268 | I2c_operation_write = 0x10, |
paul@66 | 269 | I2c_operation_segment_read = 0x02, // not PHY I2C |
paul@65 | 270 | I2c_operation_read = 0x01, |
paul@62 | 271 | }; |
paul@62 | 272 | |
paul@66 | 273 | // Device addresses. |
paul@66 | 274 | |
paul@66 | 275 | enum I2c_phy_device_addresses : unsigned |
paul@66 | 276 | { |
paul@66 | 277 | I2c_phy_device_phy_gen2 = 0x69, // PHY_I2CM_SLAVE_ADDR_PHY_GEN2 |
paul@66 | 278 | I2c_phy_device_phy_heac = 0x49, // PHY_I2CM_SLAVE_ADDR_HEAC_PHY |
paul@66 | 279 | }; |
paul@66 | 280 | |
paul@66 | 281 | // Device registers. |
paul@66 | 282 | |
paul@66 | 283 | enum I2c_phy_device_registers : unsigned |
paul@66 | 284 | { |
paul@66 | 285 | I2c_phy_3d_tx_clock_cal_ctrl = 0x05, // 3D_TX_PHY_CKCALCTRL |
paul@66 | 286 | I2c_phy_3d_tx_cpce_ctrl = 0x06, // 3D_TX_PHY_CPCE_CTRL |
paul@66 | 287 | I2c_phy_3d_tx_clock_symbol_ctrl = 0x09, // 3D_TX_PHY_CKSYMTXCTRL |
paul@66 | 288 | I2c_phy_3d_tx_vlevel_ctrl = 0x0e, // 3D_TX_PHY_VLEVCTRL |
paul@66 | 289 | I2c_phy_3d_tx_curr_ctrl = 0x10, // 3D_TX_PHY_CURRCTRL |
paul@66 | 290 | I2c_phy_3d_tx_pll_phby_ctrl = 0x13, // 3D_TX_PHY_PLLPHBYCTRL |
paul@66 | 291 | I2c_phy_3d_tx_gmp_ctrl = 0x15, // 3D_TX_PHY_GMPCTRL |
paul@66 | 292 | I2c_phy_3d_tx_msm_ctrl = 0x17, // 3D_TX_PHY_MSM_CTRL |
paul@66 | 293 | I2c_phy_3d_tx_term = 0x19, // 3D_TX_PHY_TXTERM |
paul@66 | 294 | }; |
paul@66 | 295 | |
paul@66 | 296 | // PHY I2C register values. |
paul@66 | 297 | |
paul@66 | 298 | enum Msm_ctrl_bits : unsigned |
paul@66 | 299 | { |
paul@66 | 300 | Msm_ctrl_clock_output_select_fb = 1 << 3, // 3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK |
paul@66 | 301 | }; |
paul@66 | 302 | |
paul@66 | 303 | enum Clock_cal_ctrl_bits : unsigned |
paul@66 | 304 | { |
paul@66 | 305 | Clock_cal_ctrl_override = 1 << 15, // 3D_TX_PHY_CKCALCTRL_OVERRIDE |
paul@66 | 306 | }; |
paul@66 | 307 | |
paul@66 | 308 | // Interrupt configuration bits, also for PHY I2C. |
paul@62 | 309 | |
paul@62 | 310 | enum I2c_int_config0_bits : unsigned |
paul@62 | 311 | { |
paul@66 | 312 | I2c_int_config0_done_polarity = 0x08, |
paul@66 | 313 | I2c_int_config0_done_mask = 0x04, |
paul@62 | 314 | }; |
paul@62 | 315 | |
paul@62 | 316 | enum I2c_int_config1_bits : unsigned |
paul@62 | 317 | { |
paul@66 | 318 | I2c_int_config1_nack_polarity = 0x80, |
paul@66 | 319 | I2c_int_config1_nack_mask = 0x40, |
paul@66 | 320 | I2c_int_config1_arb_polarity = 0x08, |
paul@66 | 321 | I2c_int_config1_arb_mask = 0x04, |
paul@65 | 322 | }; |
paul@65 | 323 | |
paul@65 | 324 | // PHY configuration values. |
paul@65 | 325 | |
paul@65 | 326 | enum Phy_config_bits : unsigned |
paul@65 | 327 | { |
paul@66 | 328 | Phy_config_powerdown_disable = 0x80, // PHY_CONF0_PDZ_MASK |
paul@66 | 329 | Phy_config_tmds = 0x40, // PHY_CONF0_ENTMDS_MASK |
paul@66 | 330 | Phy_config_svsret = 0x20, // PHY_CONF0_SVSRET_MASK |
paul@66 | 331 | Phy_config_gen2_powerdown = 0x10, // PHY_CONF0_GEN2_PDDQ_MASK |
paul@66 | 332 | Phy_config_gen2_tx_power = 0x08, // PHY_CONF0_GEN2_TXPWRON_MASK |
paul@66 | 333 | Phy_config_gen2_hotplug_detect_rx_sense = 0x04, // PHY_CONF0_GEN2_ENHPDRXSENSE_MASK |
paul@66 | 334 | Phy_config_select_data_enable_polarity = 0x02, // PHY_CONF0_SELDATAENPOL_MASK |
paul@66 | 335 | Phy_config_select_interface_control = 0x01, // PHY_CONF0_SELDIPIF_MASK |
paul@65 | 336 | }; |
paul@65 | 337 | |
paul@65 | 338 | enum Phy_test_bits : unsigned |
paul@65 | 339 | { |
paul@65 | 340 | Phy_test0_clear_mask = 0x20, // PHY_TST0_TSTCLR_MASK |
paul@65 | 341 | Phy_test0_enable_mask = 0x10, // PHY_TST0_TSTEN_MASK |
paul@65 | 342 | Phy_test0_clock_mask = 0x01, // PHY_TST0_TSTCLK_MASK |
paul@65 | 343 | }; |
paul@65 | 344 | |
paul@65 | 345 | // PHY status and mask values. |
paul@65 | 346 | |
paul@65 | 347 | enum Phy_status_bits : unsigned |
paul@65 | 348 | { |
paul@66 | 349 | Phy_status_all = 0xf3, |
paul@65 | 350 | Phy_status_rx_sense_all = 0xf0, |
paul@65 | 351 | Phy_status_rx_sense3 = 0x80, // PHY_RX_SENSE3 |
paul@65 | 352 | Phy_status_rx_sense2 = 0x40, // PHY_RX_SENSE2 |
paul@65 | 353 | Phy_status_rx_sense1 = 0x20, // PHY_RX_SENSE1 |
paul@65 | 354 | Phy_status_rx_sense0 = 0x10, // PHY_RX_SENSE0 |
paul@65 | 355 | Phy_status_hotplug_detect = 0x02, // PHY_HPD |
paul@65 | 356 | Phy_status_tx_phy_lock = 0x01, // PHY_TX_PHY_LOCK |
paul@66 | 357 | Phy_status_none = 0, |
paul@65 | 358 | }; |
paul@65 | 359 | |
paul@66 | 360 | // PHY interrupt status and mask values. |
paul@65 | 361 | |
paul@65 | 362 | enum Phy_int_status_bits : unsigned |
paul@65 | 363 | { |
paul@66 | 364 | Phy_int_status_all = 0x3f, |
paul@65 | 365 | Phy_int_status_rx_sense_all = 0x3c, |
paul@65 | 366 | Phy_int_status_rx_sense3 = 0x20, // IH_PHY_STAT0_RX_SENSE3 |
paul@65 | 367 | Phy_int_status_rx_sense2 = 0x10, // IH_PHY_STAT0_RX_SENSE2 |
paul@65 | 368 | Phy_int_status_rx_sense1 = 0x08, // IH_PHY_STAT0_RX_SENSE1 |
paul@65 | 369 | Phy_int_status_rx_sense0 = 0x04, // IH_PHY_STAT0_RX_SENSE0 |
paul@65 | 370 | Phy_int_status_tx_phy_lock = 0x02, // IH_PHY_STAT0_TX_PHY_LOCK |
paul@65 | 371 | Phy_int_status_hotplug_detect = 0x01, // IH_PHY_STAT0_HPD |
paul@66 | 372 | Phy_int_status_none = 0, |
paul@66 | 373 | }; |
paul@66 | 374 | |
paul@66 | 375 | // PHY main register values. |
paul@66 | 376 | |
paul@66 | 377 | enum Main_heac_phy_reset_bits : unsigned |
paul@66 | 378 | { |
paul@66 | 379 | Main_heac_phy_reset_assert = 0x01, // MC_HEACPHY_RST_ASSERT |
paul@66 | 380 | }; |
paul@66 | 381 | |
paul@66 | 382 | enum Main_flow_control_bits : unsigned |
paul@66 | 383 | { |
paul@66 | 384 | Main_flow_control_csc_active = 0x01, // MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH |
paul@66 | 385 | Main_flow_control_csc_inactive = 0x00, // MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS |
paul@66 | 386 | }; |
paul@66 | 387 | |
paul@66 | 388 | enum Main_clock_disable_bits : unsigned |
paul@66 | 389 | { |
paul@66 | 390 | Main_clock_disable_hdcp = 0x40, // MC_CLKDIS_HDCPCLK_DISABLE |
paul@66 | 391 | Main_clock_disable_cec = 0x20, // MC_CLKDIS_CECCLK_DISABLE |
paul@66 | 392 | Main_clock_disable_csc = 0x10, // MC_CLKDIS_CSCCLK_DISABLE |
paul@66 | 393 | Main_clock_disable_audio = 0x08, // MC_CLKDIS_AUDCLK_DISABLE |
paul@66 | 394 | Main_clock_disable_prep = 0x04, // MC_CLKDIS_PREPCLK_DISABLE |
paul@66 | 395 | Main_clock_disable_tmds = 0x02, // MC_CLKDIS_TMDSCLK_DISABLE |
paul@66 | 396 | Main_clock_disable_pixel = 0x01, // MC_CLKDIS_PIXELCLK_DISABLE |
paul@66 | 397 | }; |
paul@66 | 398 | |
paul@66 | 399 | // Frame composer values. |
paul@66 | 400 | |
paul@66 | 401 | enum Fc_video_config_bits : unsigned |
paul@66 | 402 | { |
paul@66 | 403 | Fc_video_config_hdcp_keepout_active = 0x80, // FC_INVIDCONF_HDCP_KEEPOUT_ACTIVE |
paul@66 | 404 | Fc_video_config_hdcp_keepout_inactive = 0x00, // FC_INVIDCONF_HDCP_KEEPOUT_INACTIVE |
paul@66 | 405 | Fc_video_config_vsync_active_high = 0x40, // FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_HIGH |
paul@66 | 406 | Fc_video_config_vsync_active_low = 0x00, // FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_LOW |
paul@66 | 407 | Fc_video_config_hsync_active_high = 0x20, // FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_HIGH |
paul@66 | 408 | Fc_video_config_hsync_active_low = 0x00, // FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_LOW |
paul@66 | 409 | Fc_video_config_data_enable_active_high = 0x10, // FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH |
paul@66 | 410 | Fc_video_config_data_enable_active_low = 0x00, // FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW |
paul@66 | 411 | Fc_video_config_hdmi_mode = 0x08, // FC_INVIDCONF_DVI_MODEZ_HDMI_MODE |
paul@66 | 412 | Fc_video_config_dvi_mode = 0x00, // FC_INVIDCONF_DVI_MODEZ_DVI_MODE |
paul@66 | 413 | Fc_video_config_osc_active_high = 0x02, // FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH |
paul@66 | 414 | Fc_video_config_osc_active_low = 0x00, // FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW |
paul@66 | 415 | Fc_video_config_interlaced = 0x01, // FC_INVIDCONF_IN_I_P_INTERLACED |
paul@66 | 416 | Fc_video_config_progressive = 0x00, // FC_INVIDCONF_IN_I_P_PROGRESSIVE |
paul@66 | 417 | }; |
paul@66 | 418 | |
paul@66 | 419 | enum Fc_int_status2_bits : unsigned |
paul@66 | 420 | { |
paul@66 | 421 | Fc_int_status2_overflow = 0x03, // FC_STAT2_OVERFLOW_MASK |
paul@66 | 422 | Fc_int_status2_overflow_low = 0x02, // FC_STAT2_LOW_PRIORITY_OVERFLOW |
paul@66 | 423 | Fc_int_status2_overflow_high = 0x01 // FC_STAT2_HIGH_PRIORITY_OVERFLOW, |
paul@66 | 424 | }; |
paul@66 | 425 | |
paul@66 | 426 | // Colour space conversion values. |
paul@66 | 427 | |
paul@66 | 428 | enum Csc_config_bits : unsigned |
paul@66 | 429 | { |
paul@66 | 430 | Csc_config_interpolation_mask = 0x30, // CSC_CFG_INTMODE_MASK |
paul@66 | 431 | Csc_config_interpolation_disable = 0x00, // CSC_CFG_INTMODE_DISABLE |
paul@66 | 432 | Csc_config_interpolation_form1 = 0x10, // CSC_CFG_INTMODE_CHROMA_INT_FORMULA1 |
paul@66 | 433 | Csc_config_interpolation_form2 = 0x20, // CSC_CFG_INTMODE_CHROMA_INT_FORMULA2 |
paul@66 | 434 | Csc_config_decimation_mask = 0x3, // CSC_CFG_DECMODE_MASK |
paul@66 | 435 | Csc_config_decimation_disable = 0x0, // CSC_CFG_DECMODE_DISABLE |
paul@66 | 436 | Csc_config_decimation_form1 = 0x1, // CSC_CFG_DECMODE_CHROMA_INT_FORMULA1 |
paul@66 | 437 | Csc_config_decimation_form2 = 0x2, // CSC_CFG_DECMODE_CHROMA_INT_FORMULA2 |
paul@66 | 438 | Csc_config_decimation_form3 = 0x3, // CSC_CFG_DECMODE_CHROMA_INT_FORMULA3 |
paul@66 | 439 | }; |
paul@66 | 440 | |
paul@66 | 441 | enum Csc_scale_bits : unsigned |
paul@66 | 442 | { |
paul@66 | 443 | Csc_scale_colour_depth_mask = 0xf0, // CSC_SCALE_CSC_COLORDE_PTH_MASK |
paul@66 | 444 | Csc_scale_colour_depth_24bpp = 0x00, // CSC_SCALE_CSC_COLORDE_PTH_24BPP |
paul@66 | 445 | Csc_scale_colour_depth_30bpp = 0x50, // CSC_SCALE_CSC_COLORDE_PTH_30BPP |
paul@66 | 446 | Csc_scale_colour_depth_36bpp = 0x60, // CSC_SCALE_CSC_COLORDE_PTH_36BPP |
paul@66 | 447 | Csc_scale_colour_depth_48bpp = 0x70, // CSC_SCALE_CSC_COLORDE_PTH_48BPP |
paul@66 | 448 | Csc_scale_mask = 0x03, // CSC_SCALE_CSCSCALE_MASK |
paul@66 | 449 | }; |
paul@66 | 450 | |
paul@66 | 451 | // HDCP register values. |
paul@66 | 452 | |
paul@66 | 453 | enum Hdcp_config0_bits : unsigned |
paul@66 | 454 | { |
paul@66 | 455 | Hdcp_config0_rxdetect_enable = 0x4, // A_HDCPCFG0_RXDETECT_ENABLE |
paul@66 | 456 | }; |
paul@66 | 457 | |
paul@66 | 458 | enum Hdcp_config1_bits : unsigned |
paul@66 | 459 | { |
paul@66 | 460 | Hdcp_config1_encryption_disable = 0x2, // A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE |
paul@66 | 461 | }; |
paul@66 | 462 | |
paul@66 | 463 | enum Hdcp_video_polarity_bits : unsigned |
paul@66 | 464 | { |
paul@66 | 465 | Hdcp_video_polarity_data_enable_active_high = 0x10, // A_VIDPOLCFG_DATAENPOL_ACTIVE_HIGH |
paul@66 | 466 | }; |
paul@66 | 467 | |
paul@66 | 468 | // Video sample register values. |
paul@66 | 469 | |
paul@66 | 470 | enum Sample_video_config_bits : unsigned |
paul@66 | 471 | { |
paul@66 | 472 | Sample_video_config_data_enable_active = 0x80, // TX_INVID0_INTERNAL_DE_GENERATOR_ENABLE |
paul@66 | 473 | Sample_video_config_mapping_mask = 0x1f, // TX_INVID0_VIDEO_MAPPING_MASK |
paul@66 | 474 | }; |
paul@66 | 475 | |
paul@66 | 476 | enum Sample_video_stuffing_bits : unsigned |
paul@66 | 477 | { |
paul@66 | 478 | Sample_video_stuffing_bdb_data = 0x04, // TX_INSTUFFING_BDBDATA_STUFFING_ENABLE |
paul@66 | 479 | Sample_video_stuffing_rcr_data = 0x02, // TX_INSTUFFING_RCRDATA_STUFFING_ENABLE |
paul@66 | 480 | Sample_video_stuffing_gy_data = 0x01, // TX_INSTUFFING_GYDATA_STUFFING_ENABLE |
paul@66 | 481 | }; |
paul@66 | 482 | |
paul@66 | 483 | // Video packetizer register values. |
paul@66 | 484 | |
paul@66 | 485 | enum Packet_stuffing_bits : unsigned |
paul@66 | 486 | { |
paul@66 | 487 | Packet_stuffing_default_phase = 0x20, // VP_STUFF_IDEFAULT_PHASE_MASK |
paul@66 | 488 | Packet_stuffing_ifix_pp_to_last = 0x10, // VP_STUFF_IFIX_PP_TO_LAST_MASK |
paul@66 | 489 | Packet_stuffing_icx = 0x08, // VP_STUFF_ICX_GOTO_P0_ST_MASK |
paul@66 | 490 | Packet_stuffing_ycc422 = 0x04, // VP_STUFF_YCC422_STUFFING_STUFFING_MODE |
paul@66 | 491 | Packet_stuffing_pp = 0x02, // VP_STUFF_PP_STUFFING_STUFFING_MODE |
paul@66 | 492 | Packet_stuffing_pr = 0x01, // VP_STUFF_PR_STUFFING_STUFFING_MODE |
paul@66 | 493 | }; |
paul@66 | 494 | |
paul@66 | 495 | enum Packet_config_bits : unsigned |
paul@66 | 496 | { |
paul@66 | 497 | Packet_config_bypass_enable = 0x40, // VP_CONF_BYPASS_EN_ENABLE |
paul@66 | 498 | Packet_config_pp_enable = 0x20, // VP_CONF_PP_EN_ENABLE |
paul@66 | 499 | Packet_config_pr_enable = 0x10, // VP_CONF_PR_EN_ENABLE |
paul@66 | 500 | Packet_config_ycc422_enable = 0x8, // VP_CONF_YCC422_EN_ENABLE |
paul@66 | 501 | Packet_config_bypass_select_packetizer = 0x4, // VP_CONF_BYPASS_SELECT_VID_PACKETIZER |
paul@66 | 502 | Packet_config_output_selector_mask = 0x3, // VP_CONF_OUTPUT_SELECTOR_MASK |
paul@66 | 503 | Packet_config_output_selector_bypass = 0x3, // VP_CONF_OUTPUT_SELECTOR_BYPASS |
paul@66 | 504 | Packet_config_output_selector_ycc422 = 0x1, // VP_CONF_OUTPUT_SELECTOR_YCC422 |
paul@66 | 505 | Packet_config_output_selector_pp = 0x0, // VP_CONF_OUTPUT_SELECTOR_PP |
paul@66 | 506 | }; |
paul@66 | 507 | |
paul@66 | 508 | enum Packet_remap_bits : unsigned |
paul@66 | 509 | { |
paul@66 | 510 | Packet_remap_mask = 0x3, // VP_REMAP_MASK |
paul@66 | 511 | Packet_remap_ycc422_24bit = 0x2, // VP_REMAP_YCC422_24bit |
paul@66 | 512 | Packet_remap_ycc422_20bit = 0x1, // VP_REMAP_YCC422_20bit |
paul@66 | 513 | Packet_remap_ycc422_16bit = 0x0, // VP_REMAP_YCC422_16bit |
paul@66 | 514 | }; |
paul@66 | 515 | |
paul@66 | 516 | enum Packet_pixel_repeater_bits : unsigned |
paul@66 | 517 | { |
paul@66 | 518 | Packet_pixel_repeater_depth_mask = 0xf0, // VP_PR_CD_COLOR_DEPTH_MASK |
paul@66 | 519 | Packet_pixel_repeater_depth_offset = 4, // VP_PR_CD_COLOR_DEPTH_OFFSET |
paul@66 | 520 | Packet_pixel_repeater_factor_mask = 0x0f, // VP_PR_CD_DESIRED_PR_FACTOR_MASK |
paul@66 | 521 | Packet_pixel_repeater_factor_offset = 0, // VP_PR_CD_DESIRED_PR_FACTOR_OFFSET |
paul@66 | 522 | }; |
paul@66 | 523 | |
paul@66 | 524 | |
paul@66 | 525 | |
paul@66 | 526 | // PHY capabilities. |
paul@66 | 527 | |
paul@66 | 528 | static const Phy_capabilities phy_capabilities[] = { |
paul@66 | 529 | // name gen svsret configure |
paul@66 | 530 | {Config2_dwc_hdmi_tx_phy, "DWC_HDMI_TX_PHY", 1, false, false}, |
paul@66 | 531 | {Config2_dwc_mhl_phy_heac, "DWC_MHL_PHY_HEAC", 2, true, true}, |
paul@66 | 532 | {Config2_dwc_mhl_phy, "DWC_MHL_PHY", 2, true, true}, |
paul@66 | 533 | {Config2_dwc_hdmi_3d_tx_phy_heac, "DWC_HDMI_3D_TX_PHY_HEAC", 2, false, true}, |
paul@66 | 534 | {Config2_dwc_hdmi_3d_tx_phy, "DWC_HDMI_3D_TX_PHY", 2, false, true}, |
paul@66 | 535 | {Config2_dwc_hdmi20_tx_phy, "DWC_HDMI20_TX_PHY", 2, true, true}, |
paul@66 | 536 | {0, "Vendor PHY", 0, false, false}, |
paul@66 | 537 | }; |
paul@66 | 538 | |
paul@66 | 539 | |
paul@66 | 540 | |
paul@66 | 541 | // PHY configuration, adopting the Linux driver's tables of values. |
paul@66 | 542 | |
paul@66 | 543 | static const struct Phy_mpll_config phy_mpll_config[] = { |
paul@66 | 544 | // 8bpc 10bpc 12bpc |
paul@66 | 545 | // pixelclock cpce gmp cpce gmp cpce gmp |
paul@66 | 546 | { 45250000, { {0x01e0, 0x0000}, {0x21e1, 0x0000}, {0x41e2, 0x0000} } }, |
paul@66 | 547 | { 92500000, { {0x0140, 0x0005}, {0x2141, 0x0005}, {0x4142, 0x0005} } }, |
paul@66 | 548 | { 148500000, { {0x00a0, 0x000a}, {0x20a1, 0x000a}, {0x40a2, 0x000a} } }, |
paul@66 | 549 | { 216000000, { {0x00a0, 0x000a}, {0x2001, 0x000f}, {0x4002, 0x000f} } }, |
paul@66 | 550 | { ~0UL, { {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000} } } |
paul@66 | 551 | }; |
paul@66 | 552 | |
paul@66 | 553 | static const struct Phy_curr_ctrl phy_curr_ctrl[] = { |
paul@66 | 554 | // pixelclock 8bpc 10bpc 12bpc |
paul@66 | 555 | { 54000000, {0x091c, 0x091c, 0x06dc} }, |
paul@66 | 556 | { 58400000, {0x091c, 0x06dc, 0x06dc} }, |
paul@66 | 557 | { 72000000, {0x06dc, 0x06dc, 0x091c} }, |
paul@66 | 558 | { 74250000, {0x06dc, 0x0b5c, 0x091c} }, |
paul@66 | 559 | { 118800000, {0x091c, 0x091c, 0x06dc} }, |
paul@66 | 560 | { 216000000, {0x06dc, 0x0b5c, 0x091c} }, |
paul@66 | 561 | { ~0UL, {0x0000, 0x0000, 0x0000} } |
paul@66 | 562 | }; |
paul@66 | 563 | |
paul@66 | 564 | static const struct Phy_config phy_config[] = { |
paul@66 | 565 | // pixelclock symbol term vlevel |
paul@66 | 566 | { 216000000, 0x800d, 0x0005, 0x01ad}, |
paul@66 | 567 | { ~0UL, 0x0000, 0x0000, 0x0000} |
paul@62 | 568 | }; |
paul@62 | 569 | |
paul@62 | 570 | |
paul@62 | 571 | |
paul@62 | 572 | // Initialise the HDMI peripheral. |
paul@62 | 573 | |
paul@62 | 574 | Hdmi_jz4780_chip::Hdmi_jz4780_chip(l4_addr_t start, l4_addr_t end, |
paul@66 | 575 | l4_cap_idx_t irq, |
paul@66 | 576 | struct Jz4740_lcd_panel *panel) |
paul@66 | 577 | : _start(start), _end(end), _irq(irq), _panel(panel) |
paul@62 | 578 | { |
paul@62 | 579 | // 8-bit registers with 2-bit address shifting. |
paul@62 | 580 | |
paul@62 | 581 | _regs = new Hw::Mmio_register_block<8>(start, 2); |
paul@62 | 582 | |
paul@66 | 583 | // Initialise I2C state for DDC. |
paul@66 | 584 | |
paul@62 | 585 | _segment_read = false; |
paul@62 | 586 | _device_register = 0; |
paul@62 | 587 | |
paul@66 | 588 | // Initialise I2C state for PHY initialisation. |
paul@66 | 589 | |
paul@66 | 590 | _phy_device_register = 0; |
paul@66 | 591 | |
paul@66 | 592 | // Initialise identifying details and capabilities of the hardware. |
paul@66 | 593 | |
paul@62 | 594 | get_identification(); |
paul@66 | 595 | |
paul@66 | 596 | // Reset interrupts to a minimal, enabled state. |
paul@66 | 597 | |
paul@65 | 598 | irq_init(); |
paul@66 | 599 | |
paul@66 | 600 | // Set up DDC and PHY communication. |
paul@66 | 601 | |
paul@66 | 602 | i2c_init(I2c_software_reset, I2c_divider, I2c_int_config0, I2c_int_config1, |
paul@66 | 603 | I2c_int_status, I2c_int_mask); |
paul@66 | 604 | i2c_init(I2c_phy_software_reset, I2c_phy_divider, I2c_phy_int_config0, I2c_phy_int_config1, |
paul@66 | 605 | I2c_phy_int_status, I2c_phy_int_mask); |
paul@66 | 606 | |
paul@66 | 607 | // Enable PHY interrupts. |
paul@66 | 608 | |
paul@66 | 609 | phy_irq_init(); |
paul@66 | 610 | } |
paul@66 | 611 | |
paul@66 | 612 | // Pixel clock frequency calculation. |
paul@66 | 613 | |
paul@66 | 614 | unsigned long Hdmi_jz4780_chip::get_pixelclock() |
paul@66 | 615 | { |
paul@66 | 616 | return _pixelclock; |
paul@66 | 617 | |
paul@66 | 618 | /* Calculated frequency, which may not be the actual pixelclock frequency... |
paul@66 | 619 | |
paul@66 | 620 | return (_panel->line_start + _panel->width + _panel->line_end + _panel->hsync) * |
paul@66 | 621 | (_panel->frame_start + _panel->height + _panel->frame_end + _panel->vsync) * |
paul@66 | 622 | _panel->frame_rate; |
paul@66 | 623 | */ |
paul@62 | 624 | } |
paul@62 | 625 | |
paul@66 | 626 | |
paul@66 | 627 | |
paul@66 | 628 | // Update a register by enabling/setting or disabling/clearing the given bits. |
paul@66 | 629 | |
paul@66 | 630 | void Hdmi_jz4780_chip::reg_update(uint32_t reg, uint32_t bits, bool enable) |
paul@66 | 631 | { |
paul@66 | 632 | if (enable) |
paul@66 | 633 | _regs[reg] = _regs[reg] | bits; |
paul@66 | 634 | else |
paul@66 | 635 | _regs[reg] = _regs[reg] & ~bits; |
paul@66 | 636 | } |
paul@66 | 637 | |
paul@66 | 638 | // Update a field. The bits must be shifted to coincide with the mask. |
paul@66 | 639 | |
paul@66 | 640 | void Hdmi_jz4780_chip::reg_update_field(uint32_t reg, uint32_t mask, uint32_t bits) |
paul@66 | 641 | { |
paul@66 | 642 | _regs[reg] = (_regs[reg] & ~(mask)) | (bits & mask); |
paul@66 | 643 | } |
paul@66 | 644 | |
paul@66 | 645 | void Hdmi_jz4780_chip::reg_fill_field(uint32_t reg, uint32_t mask) |
paul@66 | 646 | { |
paul@66 | 647 | _regs[reg] = _regs[reg] | mask; |
paul@66 | 648 | } |
paul@66 | 649 | |
paul@66 | 650 | |
paul@66 | 651 | |
paul@66 | 652 | // Chipset querying. |
paul@66 | 653 | |
paul@62 | 654 | void Hdmi_jz4780_chip::get_identification() |
paul@62 | 655 | { |
paul@62 | 656 | _version = (_regs[Design_id] << 8) | _regs[Revision_id]; |
paul@66 | 657 | _phy_type = _regs[Config_id2]; |
paul@66 | 658 | |
paul@66 | 659 | // Initialise a member to any matching capabilities or leave it as the "null" |
paul@66 | 660 | // entry. |
paul@66 | 661 | |
paul@66 | 662 | _phy_def = phy_capabilities; |
paul@66 | 663 | |
paul@66 | 664 | while (_phy_def->gen && (_phy_def->type != _phy_type)) |
paul@66 | 665 | _phy_def++; |
paul@62 | 666 | } |
paul@62 | 667 | |
paul@62 | 668 | void Hdmi_jz4780_chip::get_version(uint8_t *major, uint16_t *minor) |
paul@62 | 669 | { |
paul@66 | 670 | *major = (_version >> 12) & 0xfff; |
paul@62 | 671 | *minor = _version & 0xfff; |
paul@62 | 672 | } |
paul@62 | 673 | |
paul@66 | 674 | void Hdmi_jz4780_chip::get_phy_capabilities(const struct Phy_capabilities **phy_def) |
paul@66 | 675 | { |
paul@66 | 676 | *phy_def = _phy_def; |
paul@66 | 677 | } |
paul@66 | 678 | |
paul@66 | 679 | |
paul@66 | 680 | |
paul@66 | 681 | // Initialisation. |
paul@66 | 682 | |
paul@65 | 683 | void Hdmi_jz4780_chip::irq_init() |
paul@62 | 684 | { |
paul@62 | 685 | // Disable interrupts. |
paul@62 | 686 | |
paul@62 | 687 | _regs[Int_mask] = _regs[Int_mask] | (Int_mask_wakeup | Int_mask_all); |
paul@62 | 688 | |
paul@62 | 689 | // Mask all interrupts. |
paul@62 | 690 | |
paul@62 | 691 | _regs[Fc_int_mask0] = 0xff; |
paul@62 | 692 | _regs[Fc_int_mask1] = 0xff; |
paul@62 | 693 | _regs[Fc_int_mask2] = 0xff; |
paul@62 | 694 | _regs[As_int_mask] = 0xff; |
paul@62 | 695 | _regs[Phy_int_mask] = 0xff; |
paul@62 | 696 | _regs[I2c_int_mask] = 0xff; |
paul@66 | 697 | _regs[I2c_phy_int_mask] = 0xff; |
paul@62 | 698 | _regs[Cec_int_mask] = 0xff; |
paul@62 | 699 | _regs[Vp_int_mask] = 0xff; |
paul@62 | 700 | _regs[Ahb_dma_audio_int_mask] = 0xff; |
paul@62 | 701 | |
paul@62 | 702 | // Enable interrupts. |
paul@62 | 703 | |
paul@62 | 704 | _regs[Int_mask] = _regs[Int_mask] & ~(Int_mask_wakeup | Int_mask_all); |
paul@62 | 705 | } |
paul@62 | 706 | |
paul@66 | 707 | void Hdmi_jz4780_chip::phy_irq_init() |
paul@62 | 708 | { |
paul@65 | 709 | // Set PHY interrupt polarities. |
paul@62 | 710 | |
paul@66 | 711 | _regs[Phy_polarity] = Phy_status_all; |
paul@66 | 712 | |
paul@66 | 713 | // Enable/unmask second-level interrupts. |
paul@66 | 714 | |
paul@66 | 715 | _regs[Phy_mask] = _regs[Phy_mask] & ~(Phy_status_all); |
paul@66 | 716 | |
paul@66 | 717 | // Clear pending interrupts. |
paul@66 | 718 | |
paul@66 | 719 | _regs[Phy_int_status] = Phy_int_status_all; |
paul@66 | 720 | |
paul@66 | 721 | // Enable/unmask interrupts. |
paul@62 | 722 | |
paul@66 | 723 | _regs[Phy_int_mask] = _regs[Phy_int_mask] & ~(Phy_int_status_all); |
paul@66 | 724 | } |
paul@66 | 725 | |
paul@66 | 726 | |
paul@66 | 727 | |
paul@66 | 728 | // I2C support. |
paul@66 | 729 | |
paul@66 | 730 | void Hdmi_jz4780_chip::i2c_init(uint32_t reset, uint32_t divider, |
paul@66 | 731 | uint32_t config0, uint32_t config1, |
paul@66 | 732 | uint32_t status, uint32_t mask) |
paul@66 | 733 | { |
paul@62 | 734 | // Software reset. |
paul@62 | 735 | |
paul@66 | 736 | _regs[reset] = 0; |
paul@62 | 737 | |
paul@62 | 738 | // Standard mode (100kHz). |
paul@62 | 739 | |
paul@66 | 740 | _regs[divider] = 0; |
paul@62 | 741 | |
paul@62 | 742 | // Set interrupt polarities. |
paul@62 | 743 | |
paul@66 | 744 | _regs[config0] = I2c_int_config0_done_polarity; |
paul@66 | 745 | _regs[config1] = I2c_int_config1_nack_polarity | I2c_int_config1_arb_polarity; |
paul@62 | 746 | |
paul@62 | 747 | // Clear and mask/mute interrupts. |
paul@62 | 748 | |
paul@66 | 749 | _regs[status] = I2c_int_status_done | I2c_int_status_error; |
paul@66 | 750 | _regs[mask] = I2c_int_status_done | I2c_int_status_error; |
paul@62 | 751 | } |
paul@62 | 752 | |
paul@66 | 753 | long Hdmi_jz4780_chip::i2c_wait(uint32_t status) |
paul@62 | 754 | { |
paul@62 | 755 | long err; |
paul@65 | 756 | uint8_t int_status; |
paul@65 | 757 | l4_msgtag_t tag; |
paul@62 | 758 | |
paul@65 | 759 | do |
paul@65 | 760 | { |
paul@65 | 761 | tag = l4_irq_receive(_irq, L4_IPC_NEVER); |
paul@62 | 762 | |
paul@65 | 763 | err = l4_ipc_error(tag, l4_utcb()); |
paul@65 | 764 | if (err) |
paul@65 | 765 | return err; |
paul@62 | 766 | |
paul@66 | 767 | int_status = _regs[status]; |
paul@65 | 768 | |
paul@65 | 769 | // Test for an error condition. |
paul@62 | 770 | |
paul@65 | 771 | if (int_status & I2c_int_status_error) |
paul@65 | 772 | return -L4_EIO; |
paul@62 | 773 | |
paul@65 | 774 | // Acknowledge the interrupt. |
paul@62 | 775 | |
paul@66 | 776 | _regs[status] = int_status; |
paul@65 | 777 | |
paul@65 | 778 | } while (!(int_status & I2c_int_status_done)); |
paul@62 | 779 | |
paul@62 | 780 | return L4_EOK; |
paul@62 | 781 | } |
paul@62 | 782 | |
paul@62 | 783 | int Hdmi_jz4780_chip::i2c_read(uint8_t *buf, unsigned int length) |
paul@62 | 784 | { |
paul@62 | 785 | unsigned int i; |
paul@62 | 786 | long err; |
paul@62 | 787 | |
paul@65 | 788 | // Unmask interrupts. |
paul@62 | 789 | |
paul@62 | 790 | _regs[I2c_int_mask] = 0; |
paul@62 | 791 | |
paul@62 | 792 | for (i = 0; i < length; i++) |
paul@62 | 793 | { |
paul@62 | 794 | // Increment the device register. |
paul@62 | 795 | |
paul@62 | 796 | _regs[I2c_register] = _device_register++; |
paul@62 | 797 | _regs[I2c_operation] = _segment_read ? I2c_operation_segment_read |
paul@62 | 798 | : I2c_operation_read; |
paul@62 | 799 | |
paul@62 | 800 | // Wait and then read. |
paul@62 | 801 | |
paul@66 | 802 | err = i2c_wait(I2c_int_status); |
paul@62 | 803 | if (err) |
paul@62 | 804 | break; |
paul@62 | 805 | |
paul@62 | 806 | buf[i] = _regs[I2c_data_in]; |
paul@62 | 807 | } |
paul@62 | 808 | |
paul@62 | 809 | // Mask interrupts again. |
paul@62 | 810 | |
paul@62 | 811 | _regs[I2c_int_mask] = I2c_int_status_done | I2c_int_status_error; |
paul@62 | 812 | |
paul@62 | 813 | return i; |
paul@62 | 814 | } |
paul@62 | 815 | |
paul@66 | 816 | int Hdmi_jz4780_chip::i2c_phy_write(uint8_t address, uint16_t value) |
paul@66 | 817 | { |
paul@66 | 818 | i2c_phy_set_address(address); |
paul@66 | 819 | return i2c_phy_write(&value, 1); |
paul@66 | 820 | } |
paul@66 | 821 | |
paul@66 | 822 | int Hdmi_jz4780_chip::i2c_phy_write(uint16_t *buf, unsigned int length) |
paul@66 | 823 | { |
paul@66 | 824 | unsigned int i; |
paul@66 | 825 | long err; |
paul@66 | 826 | |
paul@66 | 827 | // Unmask interrupts. |
paul@66 | 828 | |
paul@66 | 829 | _regs[I2c_phy_int_mask] = 0; |
paul@66 | 830 | |
paul@66 | 831 | for (i = 0; i < length; i++) |
paul@66 | 832 | { |
paul@66 | 833 | // Increment the device register. |
paul@66 | 834 | |
paul@66 | 835 | _regs[I2c_phy_register] = _device_register++; |
paul@66 | 836 | _regs[I2c_phy_operation] = I2c_operation_write; |
paul@66 | 837 | |
paul@66 | 838 | // Write and then wait. |
paul@66 | 839 | |
paul@66 | 840 | _regs[I2c_phy_data_out1] = (buf[i] >> 8) & 0xff; |
paul@66 | 841 | _regs[I2c_phy_data_out0] = buf[i] & 0xff; |
paul@66 | 842 | |
paul@66 | 843 | err = i2c_wait(I2c_phy_int_status); |
paul@66 | 844 | if (err) |
paul@66 | 845 | break; |
paul@66 | 846 | } |
paul@66 | 847 | |
paul@66 | 848 | // Mask interrupts again. |
paul@66 | 849 | |
paul@66 | 850 | _regs[I2c_phy_int_mask] = I2c_int_status_done | I2c_int_status_error; |
paul@66 | 851 | |
paul@66 | 852 | return i; |
paul@66 | 853 | } |
paul@66 | 854 | |
paul@62 | 855 | void Hdmi_jz4780_chip::i2c_set_address(uint8_t address) |
paul@62 | 856 | { |
paul@62 | 857 | _regs[I2c_device_address] = address; |
paul@62 | 858 | _segment_read = false; |
paul@62 | 859 | i2c_set_register(0); |
paul@62 | 860 | } |
paul@62 | 861 | |
paul@66 | 862 | void Hdmi_jz4780_chip::i2c_phy_set_address(uint8_t address) |
paul@66 | 863 | { |
paul@66 | 864 | // The Linux drivers seem to set the clear field when changing the PHY device |
paul@66 | 865 | // address, presumably because some manual says so. |
paul@66 | 866 | |
paul@66 | 867 | _regs[Phy_test0] = _regs[Phy_test0] | Phy_test0_clear_mask; |
paul@66 | 868 | _regs[I2c_phy_device_address] = address; |
paul@66 | 869 | _regs[Phy_test0] = _regs[Phy_test0] & ~Phy_test0_clear_mask; |
paul@66 | 870 | |
paul@66 | 871 | i2c_phy_set_register(0); |
paul@66 | 872 | } |
paul@66 | 873 | |
paul@62 | 874 | void Hdmi_jz4780_chip::i2c_set_segment(uint8_t segment) |
paul@62 | 875 | { |
paul@62 | 876 | _regs[I2c_segment_address] = 0x30; |
paul@62 | 877 | _regs[I2c_segment_pointer] = segment; |
paul@62 | 878 | _segment_read = true; |
paul@62 | 879 | i2c_set_register(0); |
paul@62 | 880 | } |
paul@62 | 881 | |
paul@62 | 882 | void Hdmi_jz4780_chip::i2c_set_register(uint8_t device_register) |
paul@62 | 883 | { |
paul@62 | 884 | _device_register = device_register; |
paul@62 | 885 | } |
paul@62 | 886 | |
paul@66 | 887 | void Hdmi_jz4780_chip::i2c_phy_set_register(uint8_t device_register) |
paul@66 | 888 | { |
paul@66 | 889 | _phy_device_register = device_register; |
paul@66 | 890 | } |
paul@66 | 891 | |
paul@66 | 892 | |
paul@66 | 893 | |
paul@66 | 894 | // PHY operations. |
paul@66 | 895 | |
paul@66 | 896 | void Hdmi_jz4780_chip::phy_enable_powerdown(bool enable) |
paul@66 | 897 | { |
paul@66 | 898 | reg_update(Phy_config, Phy_config_powerdown_disable, !enable); |
paul@66 | 899 | } |
paul@66 | 900 | |
paul@66 | 901 | void Hdmi_jz4780_chip::phy_enable_tmds(bool enable) |
paul@66 | 902 | { |
paul@66 | 903 | reg_update(Phy_config, Phy_config_tmds, enable); |
paul@66 | 904 | } |
paul@66 | 905 | |
paul@66 | 906 | void Hdmi_jz4780_chip::phy_enable_svsret(bool enable) |
paul@65 | 907 | { |
paul@66 | 908 | reg_update(Phy_config, Phy_config_svsret, enable); |
paul@66 | 909 | } |
paul@66 | 910 | |
paul@66 | 911 | void Hdmi_jz4780_chip::phy_enable_gen2_powerdown(bool enable) |
paul@66 | 912 | { |
paul@66 | 913 | reg_update(Phy_config, Phy_config_gen2_powerdown, enable); |
paul@66 | 914 | } |
paul@66 | 915 | |
paul@66 | 916 | void Hdmi_jz4780_chip::phy_enable_gen2_tx_power(bool enable) |
paul@66 | 917 | { |
paul@66 | 918 | reg_update(Phy_config, Phy_config_gen2_tx_power, enable); |
paul@66 | 919 | } |
paul@66 | 920 | |
paul@66 | 921 | void Hdmi_jz4780_chip::phy_enable_interface(bool enable) |
paul@66 | 922 | { |
paul@66 | 923 | reg_update(Phy_config, Phy_config_select_data_enable_polarity, enable); |
paul@66 | 924 | reg_update(Phy_config, Phy_config_select_interface_control, !enable); |
paul@66 | 925 | } |
paul@66 | 926 | |
paul@66 | 927 | // Configure the PHY. Various things not supported by the JZ4780 PHY are ignored |
paul@66 | 928 | // such as the TDMS clock ratio (dependent on HDMI 2 and content scrambling). |
paul@66 | 929 | |
paul@66 | 930 | long Hdmi_jz4780_chip::phy_configure() |
paul@66 | 931 | { |
paul@66 | 932 | long err; |
paul@65 | 933 | |
paul@66 | 934 | phy_power_off(); |
paul@66 | 935 | |
paul@66 | 936 | if (_phy_def->svsret) |
paul@66 | 937 | phy_enable_svsret(true); |
paul@66 | 938 | |
paul@66 | 939 | phy_reset(); |
paul@66 | 940 | |
paul@66 | 941 | _regs[Main_heac_phy_reset] = Main_heac_phy_reset_assert; |
paul@66 | 942 | |
paul@66 | 943 | i2c_phy_set_address(I2c_phy_device_phy_gen2); |
paul@66 | 944 | |
paul@66 | 945 | if (_phy_def->configure) |
paul@66 | 946 | { |
paul@66 | 947 | err = phy_configure_specific(); |
paul@66 | 948 | if (err) |
paul@66 | 949 | return err; |
paul@66 | 950 | } |
paul@66 | 951 | |
paul@66 | 952 | // NOTE: TMDS clock delay here in Linux driver. |
paul@66 | 953 | |
paul@66 | 954 | phy_power_on(); |
paul@65 | 955 | |
paul@66 | 956 | return L4_EOK; |
paul@66 | 957 | } |
paul@66 | 958 | |
paul@66 | 959 | // Configure for the JZ4780 specifically. |
paul@66 | 960 | |
paul@66 | 961 | long Hdmi_jz4780_chip::phy_configure_specific() |
paul@66 | 962 | { |
paul@66 | 963 | const struct Phy_mpll_config *m = phy_mpll_config; |
paul@66 | 964 | const struct Phy_curr_ctrl *c = phy_curr_ctrl; |
paul@66 | 965 | const struct Phy_config *p = phy_config; |
paul@66 | 966 | unsigned long pixelclock = get_pixelclock(); |
paul@66 | 967 | |
paul@66 | 968 | // Find MPLL, CURR_CTRL and PHY configuration settings appropriate for the |
paul@66 | 969 | // pixel clock frequency. |
paul@66 | 970 | |
paul@66 | 971 | while (m->pixelclock && (pixelclock > m->pixelclock)) |
paul@66 | 972 | m++; |
paul@66 | 973 | |
paul@66 | 974 | while (c->pixelclock && (pixelclock > c->pixelclock)) |
paul@66 | 975 | c++; |
paul@66 | 976 | |
paul@66 | 977 | while (p->pixelclock && (pixelclock > p->pixelclock)) |
paul@66 | 978 | p++; |
paul@66 | 979 | |
paul@66 | 980 | printf("MPLL for %ld; CURR_CTRL for %ld; PHY for %ld\n", m->pixelclock, c->pixelclock, p->pixelclock); |
paul@65 | 981 | |
paul@66 | 982 | if (!m->pixelclock || !c->pixelclock || !p->pixelclock) |
paul@66 | 983 | return -L4_EINVAL; |
paul@66 | 984 | |
paul@66 | 985 | // Using values for 8bpc from the tables. |
paul@66 | 986 | |
paul@66 | 987 | // Initialise MPLL. |
paul@66 | 988 | |
paul@66 | 989 | i2c_phy_write(I2c_phy_3d_tx_cpce_ctrl, m->res[Phy_resolution_8bpc].cpce); |
paul@66 | 990 | i2c_phy_write(I2c_phy_3d_tx_gmp_ctrl, m->res[Phy_resolution_8bpc].gmp); |
paul@66 | 991 | |
paul@66 | 992 | // Initialise CURRCTRL. |
paul@66 | 993 | |
paul@66 | 994 | i2c_phy_write(I2c_phy_3d_tx_cpce_ctrl, c->curr[Phy_resolution_8bpc]); |
paul@66 | 995 | |
paul@66 | 996 | // Initialise PHY_CONFIG. |
paul@66 | 997 | |
paul@66 | 998 | i2c_phy_write(I2c_phy_3d_tx_pll_phby_ctrl, 0); |
paul@66 | 999 | i2c_phy_write(I2c_phy_3d_tx_msm_ctrl, Msm_ctrl_clock_output_select_fb); |
paul@66 | 1000 | |
paul@66 | 1001 | i2c_phy_write(I2c_phy_3d_tx_term, p->term); |
paul@66 | 1002 | i2c_phy_write(I2c_phy_3d_tx_clock_symbol_ctrl, p->symbol); |
paul@66 | 1003 | i2c_phy_write(I2c_phy_3d_tx_vlevel_ctrl, p->vlevel); |
paul@65 | 1004 | |
paul@66 | 1005 | // Override and disable clock termination. |
paul@66 | 1006 | |
paul@66 | 1007 | i2c_phy_write(I2c_phy_3d_tx_clock_cal_ctrl, Clock_cal_ctrl_override); |
paul@66 | 1008 | |
paul@66 | 1009 | return L4_EOK; |
paul@66 | 1010 | } |
paul@66 | 1011 | |
paul@66 | 1012 | long Hdmi_jz4780_chip::phy_init() |
paul@66 | 1013 | { |
paul@66 | 1014 | printf("phy_init...\n"); |
paul@66 | 1015 | |
paul@66 | 1016 | long err; |
paul@66 | 1017 | int i; |
paul@66 | 1018 | |
paul@66 | 1019 | // Initialisation repeated for HDMI PHY specification reasons. |
paul@66 | 1020 | |
paul@66 | 1021 | for (i = 0; i < 2; i++) |
paul@66 | 1022 | { |
paul@66 | 1023 | phy_enable_interface(true); |
paul@66 | 1024 | err = phy_configure(); |
paul@66 | 1025 | if (err) |
paul@66 | 1026 | return err; |
paul@66 | 1027 | } |
paul@65 | 1028 | |
paul@66 | 1029 | return L4_EOK; |
paul@66 | 1030 | } |
paul@66 | 1031 | |
paul@66 | 1032 | void Hdmi_jz4780_chip::phy_reset() |
paul@66 | 1033 | { |
paul@66 | 1034 | _regs[Main_reset] = 1; |
paul@66 | 1035 | _regs[Main_reset] = 0; |
paul@66 | 1036 | } |
paul@66 | 1037 | |
paul@66 | 1038 | void Hdmi_jz4780_chip::phy_power_off() |
paul@66 | 1039 | { |
paul@66 | 1040 | printf("phy_power_off...\n"); |
paul@66 | 1041 | |
paul@66 | 1042 | if (_phy_def && (_phy_def->gen == 1)) |
paul@66 | 1043 | { |
paul@66 | 1044 | phy_enable_tmds(false); |
paul@66 | 1045 | phy_enable_powerdown(true); |
paul@66 | 1046 | return; |
paul@66 | 1047 | } |
paul@66 | 1048 | |
paul@66 | 1049 | phy_enable_gen2_tx_power(false); |
paul@66 | 1050 | |
paul@66 | 1051 | wait_for_tx_phy_lock(0); |
paul@65 | 1052 | |
paul@66 | 1053 | phy_enable_gen2_powerdown(true); |
paul@66 | 1054 | } |
paul@66 | 1055 | |
paul@66 | 1056 | void Hdmi_jz4780_chip::phy_power_on() |
paul@66 | 1057 | { |
paul@66 | 1058 | printf("phy_power_on...\n"); |
paul@65 | 1059 | |
paul@66 | 1060 | if (_phy_def && (_phy_def->gen == 1)) |
paul@66 | 1061 | { |
paul@66 | 1062 | phy_enable_powerdown(false); |
paul@66 | 1063 | phy_enable_tmds(false); |
paul@66 | 1064 | phy_enable_tmds(true); |
paul@66 | 1065 | return; |
paul@66 | 1066 | } |
paul@66 | 1067 | |
paul@66 | 1068 | phy_enable_gen2_tx_power(true); |
paul@66 | 1069 | phy_enable_gen2_powerdown(false); |
paul@66 | 1070 | |
paul@66 | 1071 | wait_for_tx_phy_lock(1); |
paul@65 | 1072 | } |
paul@65 | 1073 | |
paul@66 | 1074 | |
paul@66 | 1075 | |
paul@66 | 1076 | // Hotplug detection. |
paul@66 | 1077 | |
paul@65 | 1078 | bool Hdmi_jz4780_chip::connected() |
paul@65 | 1079 | { |
paul@65 | 1080 | return (_regs[Phy_status] & Phy_status_hotplug_detect) != 0; |
paul@65 | 1081 | } |
paul@65 | 1082 | |
paul@65 | 1083 | long Hdmi_jz4780_chip::wait_for_connection() |
paul@65 | 1084 | { |
paul@66 | 1085 | return wait_for_phy_irq(Phy_int_status_hotplug_detect, Phy_status_hotplug_detect, |
paul@66 | 1086 | Phy_status_hotplug_detect); |
paul@66 | 1087 | } |
paul@66 | 1088 | |
paul@66 | 1089 | // General PHY interrupt handling. |
paul@66 | 1090 | |
paul@66 | 1091 | long Hdmi_jz4780_chip::wait_for_phy_irq(uint32_t int_status_flags, |
paul@66 | 1092 | uint32_t status_flags, |
paul@66 | 1093 | uint32_t status_values) |
paul@66 | 1094 | { |
paul@65 | 1095 | long err; |
paul@66 | 1096 | uint8_t int_status, status; |
paul@66 | 1097 | uint8_t status_unchanged = ~(status_values) & status_flags; |
paul@65 | 1098 | l4_msgtag_t tag; |
paul@65 | 1099 | |
paul@65 | 1100 | do |
paul@65 | 1101 | { |
paul@65 | 1102 | tag = l4_irq_receive(_irq, L4_IPC_NEVER); |
paul@65 | 1103 | |
paul@65 | 1104 | err = l4_ipc_error(tag, l4_utcb()); |
paul@65 | 1105 | if (err) |
paul@65 | 1106 | return err; |
paul@65 | 1107 | |
paul@65 | 1108 | // Obtain the details. |
paul@65 | 1109 | |
paul@65 | 1110 | int_status = _regs[Phy_int_status]; |
paul@66 | 1111 | status = _regs[Phy_status]; |
paul@65 | 1112 | |
paul@65 | 1113 | // Acknowledge the interrupt. |
paul@65 | 1114 | |
paul@66 | 1115 | _regs[Phy_int_status] = int_status_flags; |
paul@66 | 1116 | |
paul@66 | 1117 | // Continue without a handled event. |
paul@66 | 1118 | // An event is handled when detected and when the status differs from |
paul@66 | 1119 | // the unchanged state. |
paul@66 | 1120 | |
paul@66 | 1121 | printf("Status: %x versus %x\n", status & status_flags, status_unchanged); |
paul@66 | 1122 | |
paul@66 | 1123 | } while (!((int_status & int_status_flags) && |
paul@66 | 1124 | ((status & status_flags) ^ status_unchanged))); |
paul@66 | 1125 | |
paul@66 | 1126 | return L4_EOK; |
paul@66 | 1127 | } |
paul@66 | 1128 | |
paul@66 | 1129 | // Wait for TX_PHY_LOCK to become high or low. |
paul@66 | 1130 | |
paul@66 | 1131 | long Hdmi_jz4780_chip::wait_for_tx_phy_lock(int level) |
paul@66 | 1132 | { |
paul@66 | 1133 | if (!!(_regs[Phy_status] & Phy_status_tx_phy_lock) == level) |
paul@66 | 1134 | return L4_EOK; |
paul@66 | 1135 | |
paul@66 | 1136 | return wait_for_phy_irq(Phy_int_status_tx_phy_lock, Phy_status_tx_phy_lock, |
paul@66 | 1137 | level ? Phy_status_tx_phy_lock : Phy_status_none); |
paul@66 | 1138 | } |
paul@66 | 1139 | |
paul@66 | 1140 | |
paul@66 | 1141 | |
paul@66 | 1142 | // Output setup operations. |
paul@66 | 1143 | |
paul@66 | 1144 | long Hdmi_jz4780_chip::enable(unsigned long pixelclock) |
paul@66 | 1145 | { |
paul@66 | 1146 | _pixelclock = pixelclock; |
paul@66 | 1147 | |
paul@66 | 1148 | // Disable frame composer overflow interrupts. |
paul@66 | 1149 | |
paul@66 | 1150 | enable_overflow_irq(false); |
paul@65 | 1151 | |
paul@66 | 1152 | // NOTE: Here, CEA modes are normally detected and thus the output encoding. |
paul@66 | 1153 | // NOTE: Instead, a fixed RGB output encoding and format is used. |
paul@66 | 1154 | // NOTE: Meanwhile, the input encoding and format will also be fixed to a RGB |
paul@66 | 1155 | // NOTE: representation. |
paul@66 | 1156 | |
paul@66 | 1157 | // _bits_per_channel = 8; |
paul@66 | 1158 | // _data_enable_polarity = true; |
paul@66 | 1159 | |
paul@66 | 1160 | // HDMI initialisation "step B.1": video frame initialisation. |
paul@66 | 1161 | |
paul@66 | 1162 | frame_init(); |
paul@66 | 1163 | |
paul@66 | 1164 | // HDMI initialisation "step B.2": PHY initialisation. |
paul@66 | 1165 | |
paul@66 | 1166 | long err = phy_init(); |
paul@66 | 1167 | if (err) |
paul@66 | 1168 | return err; |
paul@65 | 1169 | |
paul@66 | 1170 | // HDMI initialisation "step B.3": video signal initialisation. |
paul@66 | 1171 | |
paul@66 | 1172 | data_path_init(); |
paul@66 | 1173 | |
paul@66 | 1174 | // With audio, various clock updates are needed. |
paul@66 | 1175 | |
paul@66 | 1176 | // NOTE: DVI mode is being assumed for now, for simplicity. |
paul@66 | 1177 | |
paul@66 | 1178 | // In non-DVI mode, the AVI, vendor-specific infoframe and regular infoframe |
paul@66 | 1179 | // are set up. |
paul@66 | 1180 | |
paul@66 | 1181 | packet_init(); |
paul@66 | 1182 | csc_init(); |
paul@66 | 1183 | sample_init(); |
paul@66 | 1184 | hdcp_init(); |
paul@66 | 1185 | |
paul@66 | 1186 | // Enable frame composer overflow interrupts. |
paul@66 | 1187 | |
paul@66 | 1188 | enable_overflow_irq(true); |
paul@65 | 1189 | |
paul@65 | 1190 | return L4_EOK; |
paul@65 | 1191 | } |
paul@65 | 1192 | |
paul@66 | 1193 | void Hdmi_jz4780_chip::enable_overflow_irq(bool enable) |
paul@66 | 1194 | { |
paul@66 | 1195 | reg_update(Fc_int_mask2, Fc_int_status2_overflow, !enable); |
paul@66 | 1196 | } |
paul@66 | 1197 | |
paul@66 | 1198 | void Hdmi_jz4780_chip::frame_init() |
paul@66 | 1199 | { |
paul@66 | 1200 | printf("frame_init...\n"); |
paul@66 | 1201 | |
paul@66 | 1202 | // Initialise the video configuration. This is rather like the initialisation |
paul@66 | 1203 | // of the LCD controller. The sync and data enable polarities are set up, plus |
paul@66 | 1204 | // extras like HDCP, DVI mode, progressive/interlace. |
paul@66 | 1205 | // NOTE: Here, the JZ4740-specific configuration is used to store the picture |
paul@66 | 1206 | // NOTE: properties, but a neutral structure should be adopted. |
paul@66 | 1207 | |
paul@66 | 1208 | uint8_t config = 0; |
paul@66 | 1209 | |
paul@66 | 1210 | config |= (_panel->config & Jz4740_lcd_hsync_negative) |
paul@66 | 1211 | ? Fc_video_config_hsync_active_low |
paul@66 | 1212 | : Fc_video_config_hsync_active_high; |
paul@66 | 1213 | |
paul@66 | 1214 | config |= (_panel->config & Jz4740_lcd_vsync_negative) |
paul@66 | 1215 | ? Fc_video_config_vsync_active_low |
paul@66 | 1216 | : Fc_video_config_vsync_active_high; |
paul@66 | 1217 | |
paul@66 | 1218 | config |= (_panel->config & Jz4740_lcd_de_negative) |
paul@66 | 1219 | ? Fc_video_config_data_enable_active_low |
paul@66 | 1220 | : Fc_video_config_data_enable_active_high; |
paul@66 | 1221 | |
paul@66 | 1222 | // NOTE: Only supporting DVI mode so far. |
paul@66 | 1223 | |
paul@66 | 1224 | config |= Fc_video_config_dvi_mode; |
paul@66 | 1225 | |
paul@66 | 1226 | // NOTE: Not supporting HDCP. |
paul@66 | 1227 | |
paul@66 | 1228 | config |= Fc_video_config_hdcp_keepout_inactive; |
paul@66 | 1229 | |
paul@66 | 1230 | // NOTE: Only supporting progressive scan so far. |
paul@66 | 1231 | |
paul@66 | 1232 | config |= Fc_video_config_progressive; |
paul@66 | 1233 | config |= Fc_video_config_osc_active_low; |
paul@66 | 1234 | |
paul@66 | 1235 | _regs[Fc_video_config] = config; |
paul@66 | 1236 | |
paul@66 | 1237 | printf("Fc_video_config (%x) = %x\n", Fc_video_config, (uint8_t) _regs[Fc_video_config]); |
paul@66 | 1238 | |
paul@66 | 1239 | // Then, the frame characteristics (visible area, sync pulse) are set. Indeed, |
paul@66 | 1240 | // the frame area details should be practically the same as those used by the |
paul@66 | 1241 | // LCD controller. |
paul@66 | 1242 | |
paul@66 | 1243 | uint16_t hblank = _panel->line_start + _panel->line_end + _panel->hsync, |
paul@66 | 1244 | vblank = _panel->frame_start + _panel->frame_end + _panel->vsync, |
paul@66 | 1245 | hsync_delay = _panel->line_end, |
paul@66 | 1246 | vsync_delay = _panel->frame_end, |
paul@66 | 1247 | hsync_width = _panel->hsync, |
paul@66 | 1248 | vsync_height = _panel->vsync; |
paul@66 | 1249 | |
paul@66 | 1250 | _regs[Fc_horizontal_active_width1] = (_panel->width >> 8) & 0xff; |
paul@66 | 1251 | _regs[Fc_horizontal_active_width0] = _panel->width & 0xff; |
paul@66 | 1252 | |
paul@66 | 1253 | _regs[Fc_horizontal_blank_width1] = (hblank >> 8) & 0xff; |
paul@66 | 1254 | _regs[Fc_horizontal_blank_width0] = hblank & 0xff; |
paul@66 | 1255 | |
paul@66 | 1256 | _regs[Fc_vertical_active_height1] = (_panel->height >> 8) & 0xff; |
paul@66 | 1257 | _regs[Fc_vertical_active_height0] = _panel->height & 0xff; |
paul@66 | 1258 | |
paul@66 | 1259 | _regs[Fc_vertical_blank_height] = vblank & 0xff; |
paul@66 | 1260 | |
paul@66 | 1261 | _regs[Fc_hsync_delay1] = (hsync_delay >> 8) & 0xff; |
paul@66 | 1262 | _regs[Fc_hsync_delay0] = hsync_delay & 0xff; |
paul@66 | 1263 | |
paul@66 | 1264 | _regs[Fc_vsync_delay] = vsync_delay & 0xff; |
paul@66 | 1265 | |
paul@66 | 1266 | _regs[Fc_hsync_width1] = (hsync_width >> 8) & 0xff; |
paul@66 | 1267 | _regs[Fc_hsync_width0] = hsync_width & 0xff; |
paul@66 | 1268 | |
paul@66 | 1269 | _regs[Fc_vsync_height] = vsync_height & 0xff; |
paul@66 | 1270 | } |
paul@66 | 1271 | |
paul@66 | 1272 | void Hdmi_jz4780_chip::data_path_init() |
paul@66 | 1273 | { |
paul@66 | 1274 | printf("data_path_init...\n"); |
paul@66 | 1275 | |
paul@66 | 1276 | // Initialise the path of the video data. Here, the elements of the data |
paul@66 | 1277 | // stream are defined such as the control period duration, data channel |
paul@66 | 1278 | // characteristics, pixel and TMDS clocks, and the involvement of colour space |
paul@66 | 1279 | // conversion. |
paul@66 | 1280 | |
paul@66 | 1281 | // Control period minimum duration. |
paul@66 | 1282 | |
paul@66 | 1283 | _regs[Fc_control_duration] = 12; |
paul@66 | 1284 | _regs[Fc_ex_control_duration] = 32; |
paul@66 | 1285 | _regs[Fc_ex_control_space] = 1; |
paul@66 | 1286 | |
paul@66 | 1287 | // Set to fill TMDS data channels. |
paul@66 | 1288 | |
paul@66 | 1289 | _regs[Fc_channel0_preamble] = 0x0b; |
paul@66 | 1290 | _regs[Fc_channel1_preamble] = 0x16; |
paul@66 | 1291 | _regs[Fc_channel2_preamble] = 0x21; |
paul@66 | 1292 | |
paul@66 | 1293 | // Apparent two-stage clock activation. |
paul@66 | 1294 | |
paul@66 | 1295 | uint8_t clock_disable = Main_clock_disable_hdcp | |
paul@66 | 1296 | Main_clock_disable_csc | |
paul@66 | 1297 | Main_clock_disable_audio | |
paul@66 | 1298 | Main_clock_disable_prep | |
paul@66 | 1299 | Main_clock_disable_tmds; |
paul@66 | 1300 | |
paul@66 | 1301 | // Activate the pixel clock. |
paul@66 | 1302 | |
paul@66 | 1303 | _regs[Main_clock_disable] = clock_disable; |
paul@66 | 1304 | |
paul@66 | 1305 | // Then activate the TMDS clock. |
paul@66 | 1306 | |
paul@66 | 1307 | clock_disable &= ~(Main_clock_disable_tmds); |
paul@66 | 1308 | _regs[Main_clock_disable] = clock_disable; |
paul@66 | 1309 | |
paul@66 | 1310 | // NOTE: Bypass colour space conversion for now. |
paul@66 | 1311 | |
paul@66 | 1312 | _regs[Main_flow_control] = Main_flow_control_csc_inactive; |
paul@66 | 1313 | } |
paul@66 | 1314 | |
paul@66 | 1315 | void Hdmi_jz4780_chip::packet_init() |
paul@66 | 1316 | { |
paul@66 | 1317 | printf("packet_init...\n"); |
paul@66 | 1318 | |
paul@66 | 1319 | // Initialise the video packet details. |
paul@66 | 1320 | // NOTE: With 24bpp RGB output only for now, no pixel repetition. |
paul@66 | 1321 | |
paul@66 | 1322 | int colour_depth = 4; |
paul@66 | 1323 | |
paul@66 | 1324 | _regs[Packet_pixel_repeater] = |
paul@66 | 1325 | ((colour_depth << Packet_pixel_repeater_depth_offset) & |
paul@66 | 1326 | Packet_pixel_repeater_depth_mask); |
paul@66 | 1327 | |
paul@66 | 1328 | _regs[Packet_remap] = Packet_remap_ycc422_16bit; |
paul@66 | 1329 | |
paul@66 | 1330 | reg_fill_field(Packet_stuffing, Packet_stuffing_pr | |
paul@66 | 1331 | Packet_stuffing_default_phase | |
paul@66 | 1332 | Packet_stuffing_pp | |
paul@66 | 1333 | Packet_stuffing_ycc422); |
paul@66 | 1334 | |
paul@66 | 1335 | // Disable pixel repeater. |
paul@66 | 1336 | |
paul@66 | 1337 | reg_update_field(Packet_config, Packet_config_pr_enable | |
paul@66 | 1338 | Packet_config_bypass_select_packetizer | |
paul@66 | 1339 | Packet_config_bypass_enable | |
paul@66 | 1340 | Packet_config_pp_enable | |
paul@66 | 1341 | Packet_config_ycc422_enable | |
paul@66 | 1342 | Packet_config_output_selector_mask, |
paul@66 | 1343 | Packet_config_bypass_select_packetizer | |
paul@66 | 1344 | Packet_config_bypass_enable | |
paul@66 | 1345 | Packet_config_output_selector_bypass); |
paul@66 | 1346 | } |
paul@66 | 1347 | |
paul@66 | 1348 | void Hdmi_jz4780_chip::csc_init() |
paul@66 | 1349 | { |
paul@66 | 1350 | printf("csc_init...\n"); |
paul@66 | 1351 | |
paul@66 | 1352 | // Initialise the colour space conversion details. |
paul@66 | 1353 | // NOTE: No conversion will be done yet (see data_path_init). |
paul@66 | 1354 | |
paul@66 | 1355 | _regs[Csc_config] = Csc_config_interpolation_disable | |
paul@66 | 1356 | Csc_config_decimation_disable; |
paul@66 | 1357 | |
paul@66 | 1358 | // NOTE: Use 8bpc (24bpp) for now. |
paul@66 | 1359 | |
paul@66 | 1360 | reg_update_field(Csc_scale, Csc_scale_colour_depth_mask, Csc_scale_colour_depth_24bpp); |
paul@66 | 1361 | |
paul@66 | 1362 | // NOTE: Coefficients should be set here. |
paul@66 | 1363 | } |
paul@66 | 1364 | |
paul@66 | 1365 | void Hdmi_jz4780_chip::sample_init() |
paul@66 | 1366 | { |
paul@66 | 1367 | printf("sample_init...\n"); |
paul@66 | 1368 | |
paul@66 | 1369 | // Initialise the mapping of video input data. |
paul@66 | 1370 | // NOTE: With 24bpp RGB input only for now. |
paul@66 | 1371 | |
paul@66 | 1372 | int colour_format = 0x01; |
paul@66 | 1373 | |
paul@66 | 1374 | // Data enable inactive. |
paul@66 | 1375 | |
paul@66 | 1376 | _regs[Sample_video_config] = (colour_format & Sample_video_config_mapping_mask); |
paul@66 | 1377 | |
paul@66 | 1378 | // Transmission stuffing when data enable is inactive. |
paul@66 | 1379 | |
paul@66 | 1380 | _regs[Sample_video_stuffing] = Sample_video_stuffing_bdb_data | |
paul@66 | 1381 | Sample_video_stuffing_rcr_data | |
paul@66 | 1382 | Sample_video_stuffing_gy_data; |
paul@66 | 1383 | |
paul@66 | 1384 | _regs[Sample_gy_data0] = 0; |
paul@66 | 1385 | _regs[Sample_gy_data1] = 0; |
paul@66 | 1386 | _regs[Sample_rcr_data0] = 0; |
paul@66 | 1387 | _regs[Sample_rcr_data1] = 0; |
paul@66 | 1388 | _regs[Sample_bcb_data0] = 0; |
paul@66 | 1389 | _regs[Sample_bcb_data1] = 0; |
paul@66 | 1390 | } |
paul@66 | 1391 | |
paul@66 | 1392 | void Hdmi_jz4780_chip::hdcp_init() |
paul@66 | 1393 | { |
paul@66 | 1394 | printf("hdcp_init...\n"); |
paul@66 | 1395 | |
paul@66 | 1396 | // Initialise HDCP registers, mostly turning things off. |
paul@66 | 1397 | |
paul@66 | 1398 | reg_update(Hdcp_config0, Hdcp_config0_rxdetect_enable, false); |
paul@66 | 1399 | |
paul@66 | 1400 | reg_update(Hdcp_video_polarity, |
paul@66 | 1401 | Hdcp_video_polarity_data_enable_active_high, |
paul@66 | 1402 | !(_panel->config & Jz4740_lcd_de_negative)); |
paul@66 | 1403 | |
paul@66 | 1404 | reg_update(Hdcp_config1, Hdcp_config1_encryption_disable, true); |
paul@66 | 1405 | } |
paul@66 | 1406 | |
paul@62 | 1407 | |
paul@62 | 1408 | |
paul@62 | 1409 | // C language interface functions. |
paul@62 | 1410 | |
paul@66 | 1411 | void *jz4780_hdmi_init(l4_addr_t start, l4_addr_t end, l4_cap_idx_t irq, |
paul@66 | 1412 | struct Jz4740_lcd_panel *panel) |
paul@62 | 1413 | { |
paul@66 | 1414 | return (void *) new Hdmi_jz4780_chip(start, end, irq, panel); |
paul@62 | 1415 | } |
paul@62 | 1416 | |
paul@62 | 1417 | void jz4780_hdmi_get_version(void *hdmi, uint8_t *major, uint16_t *minor) |
paul@62 | 1418 | { |
paul@62 | 1419 | static_cast<Hdmi_jz4780_chip *>(hdmi)->get_version(major, minor); |
paul@62 | 1420 | } |
paul@62 | 1421 | |
paul@66 | 1422 | void jz4780_hdmi_get_phy_capabilities(void *hdmi, const struct Phy_capabilities **phy_def) |
paul@66 | 1423 | { |
paul@66 | 1424 | static_cast<Hdmi_jz4780_chip *>(hdmi)->get_phy_capabilities(phy_def); |
paul@66 | 1425 | } |
paul@66 | 1426 | |
paul@62 | 1427 | int jz4780_hdmi_i2c_read(void *hdmi, uint8_t *buf, unsigned int length) |
paul@62 | 1428 | { |
paul@62 | 1429 | return static_cast<Hdmi_jz4780_chip *>(hdmi)->i2c_read(buf, length); |
paul@62 | 1430 | } |
paul@62 | 1431 | |
paul@62 | 1432 | void jz4780_hdmi_i2c_set_address(void *hdmi, uint8_t address) |
paul@62 | 1433 | { |
paul@62 | 1434 | static_cast<Hdmi_jz4780_chip *>(hdmi)->i2c_set_address(address); |
paul@62 | 1435 | } |
paul@62 | 1436 | |
paul@62 | 1437 | void jz4780_hdmi_i2c_set_segment(void *hdmi, uint8_t segment) |
paul@62 | 1438 | { |
paul@62 | 1439 | static_cast<Hdmi_jz4780_chip *>(hdmi)->i2c_set_segment(segment); |
paul@62 | 1440 | } |
paul@62 | 1441 | |
paul@62 | 1442 | void jz4780_hdmi_i2c_set_register(void *hdmi, uint8_t device_register) |
paul@62 | 1443 | { |
paul@62 | 1444 | static_cast<Hdmi_jz4780_chip *>(hdmi)->i2c_set_register(device_register); |
paul@62 | 1445 | } |
paul@65 | 1446 | |
paul@65 | 1447 | int jz4780_hdmi_connected(void *hdmi) |
paul@65 | 1448 | { |
paul@65 | 1449 | return (int) static_cast<Hdmi_jz4780_chip *>(hdmi)->connected(); |
paul@65 | 1450 | } |
paul@65 | 1451 | |
paul@65 | 1452 | long jz4780_hdmi_wait_for_connection(void *hdmi) |
paul@65 | 1453 | { |
paul@65 | 1454 | return static_cast<Hdmi_jz4780_chip *>(hdmi)->wait_for_connection(); |
paul@65 | 1455 | } |
paul@66 | 1456 | |
paul@66 | 1457 | long jz4780_hdmi_enable(void *hdmi, unsigned long pixelclock) |
paul@66 | 1458 | { |
paul@66 | 1459 | return static_cast<Hdmi_jz4780_chip *>(hdmi)->enable(pixelclock); |
paul@66 | 1460 | } |