Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions |
| 5 | * are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer in |
| 10 | * the documentation and/or other materials provided with the |
| 11 | * distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 19 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 20 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 22 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 23 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 24 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 26 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | #ifndef EDP_H |
| 30 | #define EDP_H |
| 31 | |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 32 | #include <reg.h> |
| 33 | #include <debug.h> |
| 34 | #include <err.h> |
| 35 | #include <platform/iomap.h> |
| 36 | #include <platform/clock.h> |
Kuogee Hsieh | ad69c3c | 2013-08-01 14:34:29 -0700 | [diff] [blame] | 37 | #include <platform/timer.h> |
| 38 | |
| 39 | #include "msm_panel.h" |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 40 | |
| 41 | #define edp_read(offset) readl_relaxed((offset)) |
| 42 | #define edp_write(offset, data) writel_relaxed((data), (offset)) |
| 43 | |
Kuogee Hsieh | e3b50dd | 2013-09-25 14:40:25 -0700 | [diff] [blame] | 44 | #define EDP_MAX_LANE 4 |
Kuogee Hsieh | ad69c3c | 2013-08-01 14:34:29 -0700 | [diff] [blame] | 45 | |
| 46 | #define AUX_CMD_FIFO_LEN 144 |
| 47 | #define AUX_CMD_MAX 16 |
| 48 | #define AUX_CMD_I2C_MAX 128 |
| 49 | |
| 50 | #define EDP_PORT_MAX 1 |
| 51 | #define EDP_SINK_CAP_LEN 16 |
| 52 | |
| 53 | #define EDP_AUX_ERR_NONE 0 |
| 54 | #define EDP_AUX_ERR_ADDR -1 |
| 55 | #define EDP_AUX_ERR_TOUT -2 |
| 56 | #define EDP_AUX_ERR_NACK -3 |
| 57 | |
| 58 | /* 4 bits of aux command */ |
| 59 | #define EDP_CMD_AUX_WRITE 0x8 |
| 60 | #define EDP_CMD_AUX_READ 0x9 |
| 61 | |
| 62 | /* 4 bits of i2c command */ |
| 63 | #define EDP_CMD_I2C_MOT 0x4 /* i2c middle of transaction */ |
| 64 | #define EDP_CMD_I2C_WRITE 0x0 |
| 65 | #define EDP_CMD_I2C_READ 0x1 |
| 66 | #define EDP_CMD_I2C_STATUS 0x2 /* i2c write status request */ |
| 67 | |
| 68 | /* cmd reply: bit 0, 1 for aux */ |
| 69 | #define EDP_AUX_ACK 0x0 |
| 70 | #define EDP_AUX_NACK 0x1 |
| 71 | #define EDP_AUX_DEFER 0x2 |
| 72 | |
| 73 | /* cmd reply: bit 2, 3 for i2c */ |
| 74 | #define EDP_I2C_ACK 0x0 |
| 75 | #define EDP_I2C_NACK 0x4 |
| 76 | #define EDP_I2C_DEFER 0x8 |
| 77 | |
| 78 | #define EDP_CMD_TIMEOUT 400 /* us */ |
| 79 | #define EDP_CMD_LEN 16 |
| 80 | |
| 81 | |
| 82 | /* isr */ |
| 83 | #define EDP_INTR_HPD BIT(0) |
| 84 | #define EDP_INTR_AUX_I2C_DONE BIT(3) |
| 85 | #define EDP_INTR_WRONG_ADDR BIT(6) |
| 86 | #define EDP_INTR_TIMEOUT BIT(9) |
| 87 | #define EDP_INTR_NACK_DEFER BIT(12) |
| 88 | #define EDP_INTR_WRONG_DATA_CNT BIT(15) |
| 89 | #define EDP_INTR_I2C_NACK BIT(18) |
| 90 | #define EDP_INTR_I2C_DEFER BIT(21) |
| 91 | #define EDP_INTR_PLL_UNLOCKED BIT(24) |
| 92 | #define EDP_INTR_AUX_ERROR BIT(27) |
| 93 | |
| 94 | |
| 95 | #define EDP_INTR_STATUS1 \ |
| 96 | (EDP_INTR_HPD | EDP_INTR_AUX_I2C_DONE| \ |
| 97 | EDP_INTR_WRONG_ADDR | EDP_INTR_TIMEOUT | \ |
| 98 | EDP_INTR_NACK_DEFER | EDP_INTR_WRONG_DATA_CNT | \ |
| 99 | EDP_INTR_I2C_NACK | EDP_INTR_I2C_DEFER | \ |
| 100 | EDP_INTR_PLL_UNLOCKED | EDP_INTR_AUX_ERROR) |
| 101 | |
| 102 | #define EDP_INTR_MASK1 (EDP_INTR_STATUS1 << 2) |
| 103 | |
| 104 | |
| 105 | #define EDP_INTR_READY_FOR_VIDEO BIT(0) |
| 106 | #define EDP_INTR_IDLE_PATTERNs_SENT BIT(3) |
| 107 | #define EDP_INTR_FRAME_END BIT(6) |
| 108 | #define EDP_INTR_CRC_UPDATED BIT(9) |
| 109 | |
| 110 | #define EDP_INTR_STATUS2 \ |
| 111 | (EDP_INTR_READY_FOR_VIDEO | EDP_INTR_IDLE_PATTERNs_SENT | \ |
| 112 | EDP_INTR_FRAME_END | EDP_INTR_CRC_UPDATED) |
| 113 | |
| 114 | #define EDP_INTR_MASK2 (EDP_INTR_STATUS2 << 2) |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | #define EDP_MAINLINK_CTRL 0x004 |
| 121 | #define EDP_STATE_CTRL 0x008 |
| 122 | #define EDP_MAINLINK_READY 0x084 |
| 123 | |
| 124 | #define EDP_AUX_CTRL 0x300 |
| 125 | #define EDP_INTERRUPT_STATUS 0x308 |
| 126 | #define EDP_INTERRUPT_STATUS_2 0x30c |
| 127 | #define EDP_AUX_DATA 0x314 |
| 128 | #define EDP_AUX_TRANS_CTRL 0x318 |
| 129 | #define EDP_AUX_STATUS 0x324 |
| 130 | |
| 131 | #define EDP_PHY_EDPPHY_GLB_VM_CFG0 0x510 |
| 132 | #define EDP_PHY_EDPPHY_GLB_VM_CFG1 0x514 |
| 133 | |
| 134 | struct edp_cmd{ |
| 135 | char read; /* 1 == read, 0 == write */ |
| 136 | char i2c; /* 1 == i2c cmd, 0 == native cmd */ |
| 137 | int addr; /* 20 bits */ |
| 138 | char *datap; |
| 139 | int len; /* len to be tx OR len to be rx for read */ |
| 140 | char next; /* next command */ |
| 141 | }; |
| 142 | |
| 143 | struct edp_buf { |
| 144 | char *start; /* buffer start addr */ |
| 145 | char *end; /* buffer end addr */ |
| 146 | int size; /* size of buffer */ |
| 147 | char *data; /* data pointer */ |
| 148 | int len; /* dara length */ |
| 149 | char trans_num; /* transaction number */ |
| 150 | char i2c; /* 1 == i2c cmd, 0 == native cmd */ |
| 151 | }; |
| 152 | |
| 153 | #define DPCD_ENHANCED_FRAME BIT(0) |
| 154 | #define DPCD_TPS3 BIT(1) |
| 155 | #define DPCD_MAX_DOWNSPREAD_0_5 BIT(2) |
| 156 | #define DPCD_NO_AUX_HANDSHAKE BIT(3) |
| 157 | #define DPCD_PORT_0_EDID_PRESENTED BIT(4) |
| 158 | |
| 159 | |
| 160 | |
| 161 | #define DPCD_LINK_VOLTAGE_MAX 4 |
| 162 | #define DPCD_LINK_PRE_EMPHASIS_MAX 4 |
| 163 | |
| 164 | struct dpcd_cap { |
| 165 | char major; |
| 166 | char minor; |
| 167 | char max_lane_count; |
| 168 | char num_rx_port; |
| 169 | char i2c_speed_ctrl; |
| 170 | char scrambler_reset; |
| 171 | char enhanced_frame; |
| 172 | int max_link_rate; /* 162, 270 and 540 Mb, divided by 10 */ |
| 173 | int flags; |
| 174 | int rx_port0_buf_size; |
| 175 | int training_read_interval;/* us */ |
| 176 | }; |
| 177 | |
| 178 | |
| 179 | struct display_timing_desc { |
| 180 | uint32_t pclk; |
| 181 | uint32_t h_addressable; /* addressable + boder = active */ |
| 182 | uint32_t h_border; |
| 183 | uint32_t h_blank; /* fporch + bporch + sync_pulse = blank */ |
| 184 | uint32_t h_fporch; |
| 185 | uint32_t h_sync_pulse; |
| 186 | uint32_t v_addressable; /* addressable + boder = active */ |
| 187 | uint32_t v_border; |
| 188 | uint32_t v_blank; /* fporch + bporch + sync_pulse = blank */ |
| 189 | uint32_t v_fporch; |
| 190 | uint32_t v_sync_pulse; |
| 191 | uint32_t width_mm; |
| 192 | uint32_t height_mm; |
| 193 | uint32_t interlaced; |
| 194 | uint32_t stereo; |
| 195 | uint32_t sync_type; |
| 196 | uint32_t sync_separate; |
| 197 | uint32_t vsync_pol; |
| 198 | uint32_t hsync_pol; |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | struct edp_edid { |
| 203 | char id_name[4]; |
| 204 | short id_product; |
| 205 | char version; |
| 206 | char revision; |
| 207 | char video_intf; /* edp == 0x5 */ |
| 208 | char color_depth; /* 6, 8, 10, 12 and 14 bits */ |
| 209 | char color_format; /* RGB 4:4:4, YCrCb 4:4:4, Ycrcb 4:2:2 */ |
| 210 | char dpm; /* display power management */ |
| 211 | char sync_digital; /* 1 = digital */ |
| 212 | char sync_separate; /* 1 = separate */ |
| 213 | char vsync_pol; /* 0 = negative, 1 = positive */ |
| 214 | char hsync_pol; /* 0 = negative, 1 = positive */ |
| 215 | char ext_block_cnt; |
| 216 | struct display_timing_desc timing[4]; |
| 217 | }; |
| 218 | |
| 219 | struct dpcd_link_status { |
| 220 | char lane_01_status; |
| 221 | char lane_23_status; |
| 222 | char interlane_align_done; |
| 223 | char downstream_port_status_changed; |
| 224 | char link_status_updated; |
| 225 | char port_0_in_sync; |
| 226 | char port_1_in_sync; |
| 227 | char req_voltage_swing[4]; |
| 228 | char req_pre_emphasis[4]; |
| 229 | }; |
| 230 | |
| 231 | struct edp_aux_ctrl { |
| 232 | int aux_cmd_busy; |
| 233 | int aux_cmd_i2c; |
| 234 | int aux_trans_num; |
| 235 | int aux_error_num; |
| 236 | int aux_ctrl_reg; |
| 237 | struct edp_buf txp; |
| 238 | struct edp_buf rxp; |
| 239 | char txbuf[256]; |
| 240 | char rxbuf[256]; |
| 241 | struct dpcd_link_status link_status; |
| 242 | char link_rate; |
| 243 | char lane_cnt; |
| 244 | char v_level; |
| 245 | char p_level; |
| 246 | |
| 247 | /* transfer unit */ |
| 248 | char tu_desired; |
| 249 | char valid_boundary; |
| 250 | char delay_start; |
| 251 | int bpp; |
| 252 | |
| 253 | struct edp_edid edid; |
| 254 | struct dpcd_cap dpcd; |
| 255 | }; |
| 256 | |
| 257 | |
| 258 | void edp_phy_pll_reset(void); |
| 259 | void edp_mainlink_reset(void); |
| 260 | void edp_aux_reset(void); |
| 261 | void edp_phy_powerup(int enable); |
| 262 | void edp_lane_power_ctrl(int max_lane, int up); |
| 263 | |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 264 | void edp_phy_sw_reset(void); |
Kuogee Hsieh | ad69c3c | 2013-08-01 14:34:29 -0700 | [diff] [blame] | 265 | void edp_pll_configure(unsigned int rate); |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 266 | void edp_enable_lane_bist(int lane, int enable); |
| 267 | void edp_enable_mainlink(int enable); |
| 268 | void edp_hw_powerup(int enable); |
| 269 | void edp_config_clk(void); |
| 270 | void edp_unconfig_clk(void); |
| 271 | void edp_phy_misc_cfg(void); |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 272 | int edp_on(void); |
| 273 | int edp_off(void); |
| 274 | int edp_config(void *pdata); |
Kuogee Hsieh | ad69c3c | 2013-08-01 14:34:29 -0700 | [diff] [blame] | 275 | void mdss_edp_dpcd_cap_read(void); |
| 276 | void mdss_edp_dpcd_status_read(void); |
| 277 | void mdss_edp_edid_read(void); |
| 278 | int mdss_edp_link_train(void); |
| 279 | void mdss_edp_aux_init(void); |
| 280 | void mdss_edp_irq_enable(void); |
| 281 | void mdss_edp_irq_disable(void); |
| 282 | void mdss_edp_wait_for_hpd(void); |
| 283 | void mdss_edp_wait_for_video_ready(void); |
| 284 | void mdss_edp_lane_power_ctrl(int up); |
| 285 | int mdss_edp_phy_pll_ready(void); |
| 286 | void mdss_edp_pll_configure(void); |
| 287 | void edp_cap2pinfo(struct msm_panel_info *pinfo); |
| 288 | void edp_edid2pinfo(struct msm_panel_info *pinfo); |
| 289 | int edp_aux_write_cmds(struct edp_aux_ctrl *ep, |
| 290 | struct edp_cmd *cmd); |
| 291 | int edp_aux_read_cmds(struct edp_aux_ctrl *ep, |
| 292 | struct edp_cmd *cmds); |
| 293 | int edp_aux_write_buf(struct edp_aux_ctrl *ep, int addr, |
| 294 | char *buf, int len, int i2c); |
| 295 | int edp_aux_read_buf(struct edp_aux_ctrl *ep, int addr, |
| 296 | int len, int i2c); |
| 297 | char *edp_buf_init(struct edp_buf *eb, char *buf, int size); |
Asaf Penso | b8f524c | 2013-05-20 12:32:31 +0300 | [diff] [blame] | 298 | |
| 299 | #endif /* EDP_H */ |