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