Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Elyes HAOUAS | 27d02d8 | 2019-05-15 21:11:39 +0200 | [diff] [blame] | 2 | |
| 3 | #include <commonlib/helpers.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 6 | #include <delay.h> |
| 7 | #include <timer.h> |
| 8 | #include <soc/addressmap.h> |
| 9 | #include <soc/clock.h> |
| 10 | #include <device/device.h> |
| 11 | #include <edid.h> |
| 12 | #include <soc/nvidia/tegra/types.h> |
| 13 | #include <soc/nvidia/tegra/dc.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 14 | #include <soc/display.h> |
| 15 | #include <soc/mipi_dsi.h> |
| 16 | #include <soc/mipi_display.h> |
| 17 | #include <soc/tegra_dsi.h> |
| 18 | #include <soc/mipi-phy.h> |
Elyes HAOUAS | 27d02d8 | 2019-05-15 21:11:39 +0200 | [diff] [blame] | 19 | #include <types.h> |
| 20 | |
| 21 | #include "chip.h" |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 22 | #include "jdi_25x18_display/panel-jdi-lpm102a188a.h" |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 23 | |
| 24 | struct tegra_mipi_device mipi_device_data[NUM_DSI]; |
| 25 | |
| 26 | struct tegra_dsi dsi_data[NUM_DSI] = { |
| 27 | { |
| 28 | .regs = (void *)TEGRA_DSIA_BASE, |
| 29 | .channel = 0, |
| 30 | .slave = &dsi_data[DSI_B], |
| 31 | .master = NULL, |
| 32 | .video_fifo_depth = MAX_DSI_VIDEO_FIFO_DEPTH, |
| 33 | .host_fifo_depth = MAX_DSI_HOST_FIFO_DEPTH, |
| 34 | }, |
| 35 | { |
| 36 | .regs = (void *)TEGRA_DSIB_BASE, |
| 37 | .channel = 0, |
| 38 | .slave = NULL, |
| 39 | .master = &dsi_data[DSI_A], |
| 40 | .video_fifo_depth = MAX_DSI_VIDEO_FIFO_DEPTH, |
| 41 | .host_fifo_depth = MAX_DSI_HOST_FIFO_DEPTH, |
| 42 | }, |
| 43 | }; |
| 44 | |
| 45 | static const u32 init_reg[] = { |
| 46 | DSI_INT_ENABLE, |
| 47 | DSI_INT_STATUS, |
| 48 | DSI_INT_MASK, |
| 49 | DSI_INIT_SEQ_DATA_0, |
| 50 | DSI_INIT_SEQ_DATA_1, |
| 51 | DSI_INIT_SEQ_DATA_2, |
| 52 | DSI_INIT_SEQ_DATA_3, |
| 53 | DSI_INIT_SEQ_DATA_4, |
| 54 | DSI_INIT_SEQ_DATA_5, |
| 55 | DSI_INIT_SEQ_DATA_6, |
| 56 | DSI_INIT_SEQ_DATA_7, |
| 57 | DSI_INIT_SEQ_DATA_15, |
| 58 | DSI_DCS_CMDS, |
| 59 | DSI_PKT_SEQ_0_LO, |
| 60 | DSI_PKT_SEQ_1_LO, |
| 61 | DSI_PKT_SEQ_2_LO, |
| 62 | DSI_PKT_SEQ_3_LO, |
| 63 | DSI_PKT_SEQ_4_LO, |
| 64 | DSI_PKT_SEQ_5_LO, |
| 65 | DSI_PKT_SEQ_0_HI, |
| 66 | DSI_PKT_SEQ_1_HI, |
| 67 | DSI_PKT_SEQ_2_HI, |
| 68 | DSI_PKT_SEQ_3_HI, |
| 69 | DSI_PKT_SEQ_4_HI, |
| 70 | DSI_PKT_SEQ_5_HI, |
| 71 | DSI_CONTROL, |
| 72 | DSI_HOST_CONTROL, |
| 73 | DSI_PAD_CONTROL_0, |
| 74 | DSI_PAD_CONTROL_CD, |
| 75 | DSI_SOL_DELAY, |
| 76 | DSI_MAX_THRESHOLD, |
| 77 | DSI_TRIGGER, |
| 78 | DSI_TX_CRC, |
| 79 | DSI_INIT_SEQ_CONTROL, |
| 80 | DSI_PKT_LEN_0_1, |
| 81 | DSI_PKT_LEN_2_3, |
| 82 | DSI_PKT_LEN_4_5, |
| 83 | DSI_PKT_LEN_6_7, |
| 84 | }; |
| 85 | |
| 86 | static inline struct tegra_dsi *host_to_tegra(struct mipi_dsi_host *host) |
| 87 | { |
| 88 | return container_of(host, struct tegra_dsi, host); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * non-burst mode with sync pulses |
| 93 | */ |
| 94 | static const u32 pkt_seq_video_non_burst_sync_pulses[NUM_PKT_SEQ] = { |
| 95 | [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) | |
| 96 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 97 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) | |
| 98 | PKT_LP, |
| 99 | [ 1] = 0, |
| 100 | [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END) | PKT_LEN0(0) | |
| 101 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 102 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) | |
| 103 | PKT_LP, |
| 104 | [ 3] = 0, |
| 105 | [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 106 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 107 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) | |
| 108 | PKT_LP, |
| 109 | [ 5] = 0, |
| 110 | [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 111 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 112 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0), |
| 113 | [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) | |
| 114 | PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) | |
| 115 | PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4), |
| 116 | [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 117 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 118 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) | |
| 119 | PKT_LP, |
| 120 | [ 9] = 0, |
| 121 | [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 122 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) | |
| 123 | PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0), |
| 124 | [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) | |
| 125 | PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) | |
| 126 | PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4), |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * non-burst mode with sync events |
| 131 | */ |
| 132 | static const u32 pkt_seq_video_non_burst_sync_events[NUM_PKT_SEQ] = { |
| 133 | [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) | |
| 134 | PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) | |
| 135 | PKT_LP, |
| 136 | [ 1] = 0, |
| 137 | [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 138 | PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) | |
| 139 | PKT_LP, |
| 140 | [ 3] = 0, |
| 141 | [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 142 | PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) | |
| 143 | PKT_LP, |
| 144 | [ 5] = 0, |
| 145 | |
| 146 | [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 147 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) | |
| 148 | PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3), |
| 149 | |
| 150 | [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4), |
| 151 | [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 152 | PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) | |
| 153 | PKT_LP, |
| 154 | [ 9] = 0, |
| 155 | |
| 156 | [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) | |
| 157 | PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) | |
| 158 | PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3), |
| 159 | |
| 160 | [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4), |
| 161 | }; |
| 162 | |
| 163 | static const u32 pkt_seq_command_mode[NUM_PKT_SEQ] = { |
| 164 | [ 0] = 0, |
| 165 | [ 1] = 0, |
| 166 | [ 2] = 0, |
| 167 | [ 3] = 0, |
| 168 | [ 4] = 0, |
| 169 | [ 5] = 0, |
| 170 | [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(3) | PKT_LP, |
| 171 | [ 7] = 0, |
| 172 | [ 8] = 0, |
| 173 | [ 9] = 0, |
| 174 | [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(5) | PKT_LP, |
| 175 | [11] = 0, |
| 176 | }; |
| 177 | |
| 178 | static int tegra_dsi_set_phy_timing(struct tegra_dsi *dsi) |
| 179 | { |
| 180 | int err; |
| 181 | |
| 182 | err = mipi_dphy_set_timing(dsi); |
| 183 | if (err < 0) { |
| 184 | printk(BIOS_ERR, "failed to set D-PHY timing: %d\n", err); |
| 185 | return err; |
| 186 | } |
| 187 | |
| 188 | if (dsi->slave) |
| 189 | tegra_dsi_set_phy_timing(dsi->slave); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format, |
| 194 | unsigned int *mulp, unsigned int *divp) |
| 195 | { |
| 196 | switch (format) { |
| 197 | case MIPI_DSI_FMT_RGB666_PACKED: |
| 198 | case MIPI_DSI_FMT_RGB888: |
| 199 | *mulp = 3; |
| 200 | *divp = 1; |
| 201 | break; |
| 202 | |
| 203 | case MIPI_DSI_FMT_RGB565: |
| 204 | *mulp = 2; |
| 205 | *divp = 1; |
| 206 | break; |
| 207 | |
| 208 | case MIPI_DSI_FMT_RGB666: |
| 209 | *mulp = 9; |
| 210 | *divp = 4; |
| 211 | break; |
| 212 | |
| 213 | default: |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format, |
| 220 | enum tegra_dsi_format *fmt) |
| 221 | { |
| 222 | switch (format) { |
| 223 | case MIPI_DSI_FMT_RGB888: |
| 224 | *fmt = TEGRA_DSI_FORMAT_24P; |
| 225 | break; |
| 226 | |
| 227 | case MIPI_DSI_FMT_RGB666: |
| 228 | *fmt = TEGRA_DSI_FORMAT_18NP; |
| 229 | break; |
| 230 | |
| 231 | case MIPI_DSI_FMT_RGB666_PACKED: |
| 232 | *fmt = TEGRA_DSI_FORMAT_18P; |
| 233 | break; |
| 234 | |
| 235 | case MIPI_DSI_FMT_RGB565: |
| 236 | *fmt = TEGRA_DSI_FORMAT_16P; |
| 237 | break; |
| 238 | |
| 239 | default: |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static void tegra_dsi_ganged_enable(struct tegra_dsi *dsi, unsigned int start, |
| 246 | unsigned int size) |
| 247 | { |
| 248 | u32 value; |
| 249 | |
| 250 | tegra_dsi_writel(dsi, start, DSI_GANGED_MODE_START); |
| 251 | tegra_dsi_writel(dsi, size << 16 | size, DSI_GANGED_MODE_SIZE); |
| 252 | |
| 253 | value = DSI_GANGED_MODE_CONTROL_ENABLE; |
| 254 | tegra_dsi_writel(dsi, value, DSI_GANGED_MODE_CONTROL); |
| 255 | } |
| 256 | |
| 257 | static void tegra_dsi_enable(struct tegra_dsi *dsi) |
| 258 | { |
| 259 | u32 value; |
| 260 | |
| 261 | value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); |
| 262 | value |= DSI_POWER_CONTROL_ENABLE; |
| 263 | tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); |
| 264 | |
| 265 | if (dsi->slave) |
| 266 | tegra_dsi_enable(dsi->slave); |
| 267 | } |
| 268 | |
| 269 | static int tegra_dsi_configure(struct tegra_dsi *dsi, unsigned int pipe, |
| 270 | const struct soc_nvidia_tegra210_config *mode) |
| 271 | { |
| 272 | unsigned int hact, hsw, hbp, hfp, i, mul, div; |
| 273 | enum tegra_dsi_format format; |
| 274 | const u32 *pkt_seq; |
| 275 | u32 value; |
| 276 | int err; |
| 277 | |
| 278 | if (dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) { |
| 279 | printk(BIOS_SPEW, "Non-burst video mode with sync pulses\n"); |
| 280 | pkt_seq = pkt_seq_video_non_burst_sync_pulses; |
| 281 | } else if (dsi->flags & MIPI_DSI_MODE_VIDEO) { |
| 282 | printk(BIOS_SPEW, "Non-burst video mode with sync events\n"); |
| 283 | pkt_seq = pkt_seq_video_non_burst_sync_events; |
| 284 | } else { |
| 285 | printk(BIOS_SPEW, "Command mode\n"); |
| 286 | pkt_seq = pkt_seq_command_mode; |
| 287 | } |
| 288 | |
| 289 | err = tegra_dsi_get_muldiv(dsi->format, &mul, &div); |
| 290 | if (err < 0) |
| 291 | return err; |
| 292 | |
| 293 | err = tegra_dsi_get_format(dsi->format, &format); |
| 294 | if (err < 0) |
| 295 | return err; |
| 296 | |
| 297 | value = DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format) | |
| 298 | DSI_CONTROL_LANES(dsi->lanes - 1) | |
| 299 | DSI_CONTROL_SOURCE(pipe); |
| 300 | tegra_dsi_writel(dsi, value, DSI_CONTROL); |
| 301 | |
| 302 | tegra_dsi_writel(dsi, dsi->video_fifo_depth, DSI_MAX_THRESHOLD); |
| 303 | |
| 304 | value = DSI_HOST_CONTROL_HS; |
| 305 | tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); |
| 306 | |
| 307 | value = tegra_dsi_readl(dsi, DSI_CONTROL); |
| 308 | |
| 309 | if (dsi->flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) |
| 310 | value |= DSI_CONTROL_HS_CLK_CTRL; |
| 311 | |
| 312 | value &= ~DSI_CONTROL_TX_TRIG(3); |
| 313 | |
| 314 | /* enable DCS commands for command mode */ |
| 315 | if (dsi->flags & MIPI_DSI_MODE_VIDEO) |
| 316 | value &= ~DSI_CONTROL_DCS_ENABLE; |
| 317 | else |
| 318 | value |= DSI_CONTROL_DCS_ENABLE; |
| 319 | |
| 320 | value |= DSI_CONTROL_VIDEO_ENABLE; |
| 321 | value &= ~DSI_CONTROL_HOST_ENABLE; |
| 322 | tegra_dsi_writel(dsi, value, DSI_CONTROL); |
| 323 | |
| 324 | for (i = 0; i < NUM_PKT_SEQ; i++) |
| 325 | tegra_dsi_writel(dsi, pkt_seq[i], DSI_PKT_SEQ_0_LO + i); |
| 326 | |
| 327 | if (dsi->flags & MIPI_DSI_MODE_VIDEO) { |
| 328 | /* horizontal active pixels */ |
| 329 | hact = mode->xres * mul / div; |
| 330 | |
| 331 | /* horizontal sync width */ |
| 332 | hsw = (hsync_end(mode) - hsync_start(mode)) * mul / div; |
| 333 | |
| 334 | /* horizontal back porch */ |
| 335 | hbp = (htotal(mode) - hsync_end(mode)) * mul / div; |
| 336 | if ((dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) == 0) |
| 337 | hbp += hsw; |
| 338 | |
| 339 | /* horizontal front porch */ |
| 340 | hfp = (hsync_start(mode) - mode->xres) * mul / div; |
| 341 | |
| 342 | /* subtract packet overhead */ |
| 343 | hsw -= 10; |
| 344 | hbp -= 14; |
| 345 | hfp -= 8; |
| 346 | |
| 347 | tegra_dsi_writel(dsi, hsw << 16 | 0, DSI_PKT_LEN_0_1); |
| 348 | tegra_dsi_writel(dsi, hact << 16 | hbp, DSI_PKT_LEN_2_3); |
| 349 | tegra_dsi_writel(dsi, hfp, DSI_PKT_LEN_4_5); |
| 350 | tegra_dsi_writel(dsi, 0x0f0f << 16, DSI_PKT_LEN_6_7); |
| 351 | |
| 352 | /* set SOL delay (for non-burst mode only) */ |
| 353 | tegra_dsi_writel(dsi, 8 * mul / div, DSI_SOL_DELAY); |
| 354 | |
| 355 | /* TODO: implement ganged mode */ |
| 356 | } else { |
| 357 | u16 bytes; |
| 358 | if (dsi->ganged_mode) { |
| 359 | /* |
| 360 | * For ganged mode, assume symmetric left-right mode. |
| 361 | */ |
| 362 | bytes = 1 + (mode->xres / 2) * mul / div; |
| 363 | } else { |
| 364 | /* 1 byte (DCS command) + pixel data */ |
| 365 | bytes = 1 + mode->xres * mul / div; |
| 366 | } |
| 367 | |
| 368 | tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_0_1); |
Jacob Garber | 9777048 | 2019-07-23 15:30:45 -0600 | [diff] [blame] | 369 | tegra_dsi_writel(dsi, (u32)bytes << 16, DSI_PKT_LEN_2_3); |
| 370 | tegra_dsi_writel(dsi, (u32)bytes << 16, DSI_PKT_LEN_4_5); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 371 | tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_6_7); |
| 372 | |
| 373 | value = MIPI_DCS_WRITE_MEMORY_START << 8 | |
| 374 | MIPI_DCS_WRITE_MEMORY_CONTINUE; |
| 375 | tegra_dsi_writel(dsi, value, DSI_DCS_CMDS); |
| 376 | |
| 377 | /* set SOL delay */ |
| 378 | if (dsi->ganged_mode) { |
| 379 | unsigned long delay, bclk, bclk_ganged; |
| 380 | unsigned int lanes = dsi->ganged_lanes; |
| 381 | |
| 382 | /* SOL to valid, valid to FIFO and FIFO write delay */ |
| 383 | delay = 4 + 4 + 2; |
| 384 | delay = DIV_ROUND_UP(delay * mul, div * lanes); |
| 385 | /* FIFO read delay */ |
| 386 | delay = delay + 6; |
| 387 | |
| 388 | bclk = DIV_ROUND_UP(htotal(mode) * mul, div * lanes); |
| 389 | bclk_ganged = DIV_ROUND_UP(bclk * lanes / 2, lanes); |
| 390 | value = bclk - bclk_ganged + delay + 20; |
| 391 | } else { |
| 392 | /* TODO: revisit for non-ganged mode */ |
| 393 | value = 8 * mul / div; |
| 394 | } |
| 395 | |
| 396 | tegra_dsi_writel(dsi, value, DSI_SOL_DELAY); |
| 397 | } |
| 398 | |
| 399 | if (dsi->slave) { |
| 400 | err = tegra_dsi_configure(dsi->slave, pipe, mode); |
| 401 | if (err < 0) |
| 402 | return err; |
| 403 | |
| 404 | /* |
| 405 | * enable ganged mode |
| 406 | */ |
| 407 | if (dsi->ganged_mode) { |
| 408 | tegra_dsi_ganged_enable(dsi, mode->xres / 2, |
| 409 | mode->xres / 2); |
| 410 | tegra_dsi_ganged_enable(dsi->slave, 0, mode->xres / 2); |
| 411 | } |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int tegra_output_dsi_enable(struct tegra_dsi *dsi, |
| 417 | const struct soc_nvidia_tegra210_config *config) |
| 418 | { |
| 419 | int err; |
| 420 | |
| 421 | if (dsi->enabled) |
| 422 | return 0; |
| 423 | |
| 424 | err = tegra_dsi_configure(dsi, 0, config); |
| 425 | if (err < 0) { |
| 426 | printk(BIOS_ERR, "DSI configuration failed\n"); |
| 427 | return err; |
| 428 | } |
| 429 | |
| 430 | /* enable DSI controller */ |
| 431 | tegra_dsi_enable(dsi); |
| 432 | |
| 433 | dsi->enabled = true; |
| 434 | return 0; |
| 435 | } |
| 436 | |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 437 | static void tegra_dsi_set_timeout(struct tegra_dsi *dsi, unsigned long bclk, |
| 438 | unsigned int vrefresh) |
| 439 | { |
| 440 | unsigned int timeout; |
| 441 | u32 value; |
| 442 | |
| 443 | /* one frame high-speed transmission timeout */ |
| 444 | timeout = (bclk / vrefresh) / 512; |
| 445 | value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout); |
| 446 | tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0); |
| 447 | |
| 448 | /* 2 ms peripheral timeout for panel */ |
| 449 | timeout = 2 * bclk / 512 * 1000; |
| 450 | value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000); |
| 451 | tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1); |
| 452 | |
| 453 | value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0); |
| 454 | tegra_dsi_writel(dsi, value, DSI_TO_TALLY); |
| 455 | |
| 456 | if (dsi->slave) |
| 457 | tegra_dsi_set_timeout(dsi->slave, bclk, vrefresh); |
| 458 | } |
| 459 | |
| 460 | static int tegra_output_dsi_setup_clock(struct tegra_dsi *dsi, |
| 461 | const struct soc_nvidia_tegra210_config *config) |
| 462 | { |
| 463 | unsigned int mul, div, num_lanes; |
| 464 | unsigned long bclk; |
| 465 | unsigned long pclk = config->pixel_clock; |
| 466 | int plld; |
| 467 | int err; |
| 468 | struct display_controller *disp_ctrl = |
| 469 | (void *)config->display_controller; |
| 470 | unsigned int shift_clk_div; |
| 471 | |
| 472 | err = tegra_dsi_get_muldiv(dsi->format, &mul, &div); |
| 473 | if (err < 0) |
| 474 | return err; |
| 475 | |
| 476 | /* |
| 477 | * In ganged mode, account for the total number of lanes across both |
| 478 | * DSI channels so that the bit clock is properly computed. |
| 479 | */ |
| 480 | if (dsi->ganged_mode) |
| 481 | num_lanes = dsi->ganged_lanes; |
| 482 | else |
| 483 | num_lanes = dsi->lanes; |
| 484 | |
| 485 | /* compute byte clock */ |
| 486 | bclk = (pclk * mul) / (div * num_lanes); |
| 487 | |
| 488 | /* |
| 489 | * Compute bit clock and round up to the next MHz. |
| 490 | */ |
| 491 | plld = DIV_ROUND_UP(bclk * 8, USECS_PER_SEC) * USECS_PER_SEC; |
| 492 | |
| 493 | /* |
| 494 | * the actual rate on PLLD_OUT0 is 1/2 plld |
| 495 | */ |
| 496 | dsi->clk_rate = plld / 2; |
| 497 | if (dsi->slave) |
| 498 | dsi->slave->clk_rate = dsi->clk_rate; |
| 499 | |
| 500 | /* set up plld */ |
| 501 | plld = clock_configure_plld(plld); |
| 502 | if (plld == 0) { |
| 503 | printk(BIOS_ERR, "%s: clock init failed\n", __func__); |
| 504 | return -1; |
| 505 | } else |
| 506 | printk(BIOS_INFO, "%s: plld is configured to: %u\n", |
| 507 | __func__, plld); |
| 508 | |
| 509 | /* |
| 510 | * Derive pixel clock from bit clock using the shift clock divider. |
| 511 | * Note that this is only half of what we would expect, but we need |
| 512 | * that to make up for the fact that we divided the bit clock by a |
| 513 | * factor of two above. |
| 514 | */ |
| 515 | shift_clk_div = ((8 * mul) / (div * num_lanes)) - 2; |
| 516 | update_display_shift_clock_divider(disp_ctrl, shift_clk_div); |
| 517 | |
| 518 | tegra_dsi_set_timeout(dsi, bclk, config->refresh); |
| 519 | return plld/1000000; |
| 520 | } |
| 521 | |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 522 | static int tegra_dsi_pad_enable(struct tegra_dsi *dsi) |
| 523 | { |
| 524 | unsigned long value; |
| 525 | |
| 526 | value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0); |
| 527 | tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi) |
| 532 | { |
| 533 | u32 value; |
| 534 | |
| 535 | tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0); |
| 536 | tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1); |
| 537 | tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2); |
| 538 | tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3); |
| 539 | tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4); |
| 540 | |
| 541 | /* start calibration */ |
| 542 | tegra_dsi_pad_enable(dsi); |
| 543 | |
| 544 | value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) | |
| 545 | DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) | |
| 546 | DSI_PAD_OUT_CLK(0x0); |
| 547 | tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2); |
| 548 | |
| 549 | value = DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) | |
| 550 | DSI_PAD_PREEMP_PD(0x03) | DSI_PAD_PREEMP_PU(0x3); |
| 551 | tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_3); |
| 552 | |
| 553 | return tegra_mipi_calibrate(dsi->mipi); |
| 554 | } |
| 555 | |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 556 | static const char *const error_report[16] = { |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 557 | "SoT Error", |
| 558 | "SoT Sync Error", |
| 559 | "EoT Sync Error", |
| 560 | "Escape Mode Entry Command Error", |
| 561 | "Low-Power Transmit Sync Error", |
| 562 | "Peripheral Timeout Error", |
| 563 | "False Control Error", |
| 564 | "Contention Detected", |
| 565 | "ECC Error, single-bit", |
| 566 | "ECC Error, multi-bit", |
| 567 | "Checksum Error", |
| 568 | "DSI Data Type Not Recognized", |
| 569 | "DSI VC ID Invalid", |
| 570 | "Invalid Transmission Length", |
| 571 | "Reserved", |
| 572 | "DSI Protocol Violation", |
| 573 | }; |
| 574 | |
| 575 | static int tegra_dsi_read_response(struct tegra_dsi *dsi, |
| 576 | const struct mipi_dsi_msg *msg, |
| 577 | unsigned int count) |
| 578 | { |
| 579 | u8 *rx = msg->rx_buf; |
| 580 | unsigned int i, j, k; |
| 581 | size_t size = 0; |
| 582 | u16 errors; |
| 583 | u32 value; |
| 584 | |
| 585 | /* read and parse packet header */ |
| 586 | value = tegra_dsi_readl(dsi, DSI_RD_DATA); |
| 587 | |
| 588 | switch (value & 0x3f) { |
| 589 | case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT: |
| 590 | errors = (value >> 8) & 0xffff; |
| 591 | printk(BIOS_ERR, "Acknowledge and error report: %04x\n", |
| 592 | errors); |
| 593 | for (i = 0; i < ARRAY_SIZE(error_report); i++) |
| 594 | if (errors & BIT(i)) |
| 595 | printk(BIOS_INFO, " %2u: %s\n", i, |
| 596 | error_report[i]); |
| 597 | break; |
| 598 | |
| 599 | case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE: |
| 600 | rx[0] = (value >> 8) & 0xff; |
| 601 | break; |
| 602 | |
| 603 | case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE: |
| 604 | rx[0] = (value >> 8) & 0xff; |
| 605 | rx[1] = (value >> 16) & 0xff; |
| 606 | break; |
| 607 | |
| 608 | case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE: |
| 609 | size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff); |
| 610 | break; |
| 611 | |
| 612 | case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE: |
| 613 | size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff); |
| 614 | break; |
| 615 | |
| 616 | default: |
| 617 | printk(BIOS_ERR, "unhandled response type: %02x\n", |
| 618 | value & 0x3f); |
| 619 | break; |
| 620 | } |
| 621 | |
| 622 | size = MIN(size, msg->rx_len); |
| 623 | |
| 624 | if (msg->rx_buf && size > 0) { |
| 625 | for (i = 0, j = 0; i < count - 1; i++, j += 4) { |
| 626 | value = tegra_dsi_readl(dsi, DSI_RD_DATA); |
| 627 | |
| 628 | for (k = 0; k < 4 && (j + k) < msg->rx_len; k++) |
| 629 | rx[j + k] = (value >> (k << 3)) & 0xff; |
| 630 | } |
| 631 | } |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static int tegra_dsi_transmit(struct tegra_dsi *dsi, unsigned long timeout_ms) |
| 636 | { |
| 637 | u32 poll_interval_us = 2000; |
| 638 | u32 timeout_us = timeout_ms * 1000; |
| 639 | |
| 640 | tegra_dsi_writel(dsi, DSI_TRIGGER_HOST, DSI_TRIGGER); |
| 641 | udelay(poll_interval_us); |
| 642 | |
| 643 | do { |
| 644 | u32 value = tegra_dsi_readl(dsi, DSI_TRIGGER); |
| 645 | if ((value & DSI_TRIGGER_HOST) == 0) |
| 646 | return 0; |
| 647 | |
| 648 | //usleep_range(1000, 2000); |
| 649 | if (timeout_us > poll_interval_us) |
| 650 | timeout_us -= poll_interval_us; |
| 651 | else |
| 652 | break; |
| 653 | |
| 654 | udelay(poll_interval_us); |
| 655 | } while (1); |
| 656 | |
| 657 | printk(BIOS_ERR, "%s: ERROR: timeout waiting for transmission" |
| 658 | " to complete\n", __func__); |
| 659 | return -ETIMEDOUT; |
| 660 | } |
| 661 | |
| 662 | static int tegra_dsi_wait_for_response(struct tegra_dsi *dsi, |
| 663 | unsigned long timeout_ms) |
| 664 | { |
| 665 | u32 poll_interval_us = 2000; |
| 666 | u32 timeout_us = timeout_ms * 1000; |
| 667 | |
| 668 | do { |
| 669 | u32 value = tegra_dsi_readl(dsi, DSI_STATUS); |
| 670 | u8 count = value & 0x1f; |
| 671 | |
| 672 | if (count > 0) |
| 673 | return count; |
| 674 | |
| 675 | if (timeout_us > poll_interval_us) |
| 676 | timeout_us -= poll_interval_us; |
| 677 | else |
| 678 | break; |
| 679 | |
| 680 | udelay(poll_interval_us); |
| 681 | } while (1); |
| 682 | |
| 683 | printk(BIOS_ERR, "%s: ERROR: timeout\n", __func__); |
| 684 | |
| 685 | return -ETIMEDOUT; |
| 686 | } |
| 687 | |
| 688 | static ssize_t tegra_dsi_host_transfer(struct mipi_dsi_host *host, |
| 689 | const struct mipi_dsi_msg *msg) |
| 690 | { |
| 691 | struct tegra_dsi *dsi = host_to_tegra(host); |
| 692 | const u8 *tx = msg->tx_buf; |
| 693 | unsigned int count, i, j; |
| 694 | u32 value; |
| 695 | int err; |
| 696 | |
| 697 | if (msg->tx_len > dsi->video_fifo_depth * 4) |
| 698 | return -ENOSPC; |
| 699 | |
| 700 | /* reset underflow/overflow flags */ |
| 701 | value = tegra_dsi_readl(dsi, DSI_STATUS); |
| 702 | if (value & (DSI_STATUS_UNDERFLOW | DSI_STATUS_OVERFLOW)) { |
| 703 | value = DSI_HOST_CONTROL_FIFO_RESET; |
| 704 | tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); |
| 705 | udelay(20); // usleep_range(10, 20); |
| 706 | } |
| 707 | |
| 708 | value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); |
| 709 | value |= DSI_POWER_CONTROL_ENABLE; |
| 710 | tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); |
| 711 | |
| 712 | udelay(7000); //usleep_range(5000, 10000); |
| 713 | |
| 714 | value = DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST | |
| 715 | DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC; |
| 716 | |
| 717 | if ((msg->flags & MIPI_DSI_MSG_USE_LPM) == 0) |
| 718 | value |= DSI_HOST_CONTROL_HS; |
| 719 | |
| 720 | /* |
| 721 | * The host FIFO has a maximum of 64 words, so larger transmissions |
| 722 | * need to use the video FIFO. |
| 723 | */ |
| 724 | if (msg->tx_len > dsi->host_fifo_depth * 4) |
| 725 | value |= DSI_HOST_CONTROL_FIFO_SEL; |
| 726 | |
| 727 | tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); |
| 728 | |
| 729 | /* |
| 730 | * For reads and messages with explicitly requested ACK, generate a |
| 731 | * BTA sequence after the transmission of the packet. |
| 732 | */ |
| 733 | if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) || |
| 734 | (msg->rx_buf && msg->rx_len > 0)) { |
| 735 | value = tegra_dsi_readl(dsi, DSI_HOST_CONTROL); |
| 736 | value |= DSI_HOST_CONTROL_PKT_BTA; |
| 737 | tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); |
| 738 | } |
| 739 | |
| 740 | value = DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE; |
| 741 | tegra_dsi_writel(dsi, value, DSI_CONTROL); |
| 742 | |
| 743 | /* write packet header */ |
| 744 | value = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f); |
| 745 | |
| 746 | if (tx && msg->tx_len > 0) |
| 747 | value |= tx[0] << 8; |
| 748 | |
| 749 | if (tx && msg->tx_len > 1) |
| 750 | value |= tx[1] << 16; |
| 751 | |
| 752 | tegra_dsi_writel(dsi, value, DSI_WR_DATA); |
| 753 | |
| 754 | /* write payload (if any) */ |
Jacob Garber | bd00fb1 | 2019-07-23 15:45:20 -0600 | [diff] [blame] | 755 | if (tx && msg->tx_len > 2) { |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 756 | for (j = 2; j < msg->tx_len; j += 4) { |
| 757 | value = 0; |
| 758 | |
| 759 | for (i = 0; i < 4 && j + i < msg->tx_len; i++) |
| 760 | value |= tx[j + i] << (i << 3); |
| 761 | |
| 762 | tegra_dsi_writel(dsi, value, DSI_WR_DATA); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | err = tegra_dsi_transmit(dsi, 250); |
| 767 | if (err < 0) { |
| 768 | printk(BIOS_INFO, "Failed to transmit. %d\n", err); |
| 769 | return err; |
| 770 | } |
| 771 | |
| 772 | if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) || |
| 773 | (msg->rx_buf && msg->rx_len > 0)) { |
| 774 | err = tegra_dsi_wait_for_response(dsi, 250); |
| 775 | if (err < 0) { |
| 776 | printk(BIOS_INFO, "Failed to read response. %d\n", err); |
| 777 | return err; |
| 778 | } |
| 779 | count = err; |
| 780 | |
| 781 | value = tegra_dsi_readl(dsi, DSI_RD_DATA); |
| 782 | switch (value) { |
| 783 | case 0x84: |
| 784 | printk(BIOS_INFO, "ACK\n"); |
| 785 | break; |
| 786 | |
| 787 | case 0x87: |
| 788 | printk(BIOS_INFO, "ESCAPE\n"); |
| 789 | break; |
| 790 | |
| 791 | default: |
| 792 | printk(BIOS_INFO, "unknown status: %08x\n", value); |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | if (count > 1) { |
| 797 | err = tegra_dsi_read_response(dsi, msg, count); |
| 798 | if (err < 0) |
| 799 | printk(BIOS_INFO, |
| 800 | "failed to parse response: %d\n", |
| 801 | err); |
| 802 | else { |
| 803 | /* |
| 804 | * For read commands, return the number of |
| 805 | * bytes returned by the peripheral. |
| 806 | */ |
| 807 | count = err; |
| 808 | } |
| 809 | } |
| 810 | } else { |
| 811 | /* |
| 812 | * For write commands, we have transmitted the 4-byte header |
| 813 | * plus the variable-length payload. |
| 814 | */ |
| 815 | count = 4 + msg->tx_len; |
| 816 | } |
| 817 | |
| 818 | return count; |
| 819 | } |
| 820 | |
| 821 | static int tegra_dsi_ganged_setup(struct tegra_dsi *dsi, |
| 822 | struct tegra_dsi *slave) |
| 823 | { |
| 824 | /* |
| 825 | * The number of ganged lanes is the sum of lanes of all peripherals |
| 826 | * in the gang. |
| 827 | */ |
| 828 | dsi->slave->ganged_lanes = dsi->lanes + dsi->slave->lanes; |
| 829 | dsi->slave->ganged_mode = 1; |
| 830 | |
| 831 | dsi->ganged_lanes = dsi->lanes + dsi->slave->lanes; |
| 832 | dsi->ganged_mode = 1; |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static int tegra_dsi_host_attach(struct mipi_dsi_host *host, |
| 837 | struct mipi_dsi_device *device) |
| 838 | { |
| 839 | struct tegra_dsi *dsi = host_to_tegra(host); |
| 840 | int err; |
| 841 | |
| 842 | dsi->flags = device->mode_flags; |
| 843 | dsi->format = device->format; |
| 844 | dsi->lanes = device->lanes; |
| 845 | |
| 846 | if (dsi->master) { |
| 847 | err = tegra_dsi_ganged_setup(dsi->master, dsi); |
| 848 | if (err < 0) { |
| 849 | printk(BIOS_ERR, "failed to set up ganged mode: %d\n", |
| 850 | err); |
| 851 | return err; |
| 852 | } |
| 853 | } |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | static const struct mipi_dsi_host_ops tegra_dsi_host_ops = { |
| 858 | .attach = tegra_dsi_host_attach, |
| 859 | .transfer = tegra_dsi_host_transfer, |
| 860 | }; |
| 861 | |
| 862 | static int dsi_probe_if(int dsi_index, |
| 863 | struct soc_nvidia_tegra210_config *config) |
| 864 | { |
| 865 | struct tegra_dsi *dsi = &dsi_data[dsi_index]; |
| 866 | int err; |
| 867 | |
| 868 | tegra_dsi_writel(dsi, 0, DSI_INIT_SEQ_CONTROL); |
| 869 | |
| 870 | /* |
| 871 | * Set default value. Will be taken from attached device once detected |
| 872 | */ |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 873 | dsi->flags = 0; |
| 874 | dsi->format = MIPI_DSI_FMT_RGB888; |
| 875 | dsi->lanes = 4; |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 876 | |
| 877 | /* get tegra_mipi_device */ |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 878 | dsi->mipi = tegra_mipi_request(&mipi_device_data[dsi_index], dsi_index); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 879 | |
| 880 | /* calibrate */ |
| 881 | err = tegra_dsi_pad_calibrate(dsi); |
| 882 | if (err < 0) { |
| 883 | printk(BIOS_ERR, "MIPI calibration failed: %d\n", err); |
| 884 | return err; |
| 885 | } |
| 886 | |
| 887 | dsi->host.ops = &tegra_dsi_host_ops; |
| 888 | err = mipi_dsi_host_register(&dsi->host); |
| 889 | if (err < 0) { |
| 890 | printk(BIOS_ERR, "failed to register DSI host: %d\n", err); |
| 891 | return err; |
| 892 | } |
| 893 | |
| 894 | /* get panel */ |
| 895 | dsi->panel = panel_jdi_dsi_probe((struct mipi_dsi_device *)dsi->host.dev); |
| 896 | if (IS_ERR_PTR(dsi->panel)) { |
| 897 | printk(BIOS_ERR, "failed to get dsi panel\n"); |
| 898 | return -EPTR; |
| 899 | } |
| 900 | dsi->panel->mode = config; |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int dsi_probe(struct soc_nvidia_tegra210_config *config) |
| 905 | { |
| 906 | dsi_probe_if(DSI_A, config); |
| 907 | dsi_probe_if(DSI_B, config); |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static void tegra_dsi_init_regs(struct tegra_dsi *dsi) |
| 912 | { |
| 913 | int i; |
| 914 | for (i = 0; i < ARRAY_SIZE(init_reg); i++) |
| 915 | tegra_dsi_writel(dsi, 0, init_reg[i]); |
| 916 | |
| 917 | if (dsi->slave) |
| 918 | tegra_dsi_init_regs(dsi->slave); |
| 919 | } |
| 920 | |
| 921 | static int dsi_enable(struct soc_nvidia_tegra210_config *config) |
| 922 | { |
| 923 | struct tegra_dsi *dsi_a = &dsi_data[DSI_A]; |
| 924 | |
| 925 | dsi_probe(config); |
| 926 | |
| 927 | /* set up clock and TimeOutRegisters */ |
| 928 | tegra_output_dsi_setup_clock(dsi_a, config); |
| 929 | |
| 930 | /* configure APB_MISC_GP_MIPI_PAD_CTRL_0 */ |
| 931 | write32((unsigned int *)APB_MISC_GP_MIPI_PAD_CTRL_0, DSIB_MODE_DSI); |
| 932 | |
| 933 | /* configure phy interface timing registers */ |
| 934 | tegra_dsi_set_phy_timing(dsi_a); |
| 935 | |
| 936 | /* Initialize DSI registers */ |
| 937 | tegra_dsi_init_regs(dsi_a); |
| 938 | |
| 939 | /* prepare panel */ |
| 940 | panel_jdi_prepare(dsi_a->panel); |
| 941 | |
| 942 | /* enable dsi */ |
| 943 | if (tegra_output_dsi_enable(dsi_a, config)) { |
| 944 | printk(BIOS_ERR,"%s: Error: failed to enable dsi output.\n", |
| 945 | __func__); |
| 946 | return -1; |
| 947 | } |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
Elyes HAOUAS | 3fcb218 | 2018-05-25 10:03:57 +0200 | [diff] [blame] | 952 | void dsi_display_startup(struct device *dev) |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 953 | { |
| 954 | struct soc_nvidia_tegra210_config *config = dev->chip_info; |
| 955 | struct display_controller *disp_ctrl = |
| 956 | (void *)config->display_controller; |
| 957 | u32 plld_rate; |
| 958 | |
| 959 | u32 framebuffer_size_mb = config->framebuffer_size / MiB; |
| 960 | u32 framebuffer_base_mb= config->framebuffer_base / MiB; |
| 961 | |
| 962 | printk(BIOS_INFO, "%s: entry: disp_ctrl: %p.\n", |
| 963 | __func__, disp_ctrl); |
| 964 | |
| 965 | if (disp_ctrl == NULL) { |
| 966 | printk(BIOS_ERR, "Error: No dc is assigned by dt.\n"); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | if (framebuffer_size_mb == 0){ |
| 971 | framebuffer_size_mb = ALIGN_UP(config->display_xres * |
| 972 | config->display_yres * |
| 973 | (config->framebuffer_bits_per_pixel / 8), MiB)/MiB; |
| 974 | } |
| 975 | |
| 976 | config->framebuffer_size = framebuffer_size_mb * MiB; |
| 977 | config->framebuffer_base = framebuffer_base_mb * MiB; |
| 978 | |
| 979 | /* |
| 980 | * The plld is programmed with the assumption of the SHIFT_CLK_DIVIDER |
| 981 | * and PIXEL_CLK_DIVIDER are zero (divide by 1). See the |
| 982 | * update_display_mode() for detail. |
| 983 | */ |
| 984 | /* set default plld */ |
| 985 | plld_rate = clock_configure_plld(config->pixel_clock * 2); |
| 986 | if (plld_rate == 0) { |
| 987 | printk(BIOS_ERR, "dc: clock init failed\n"); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | /* set disp1's clock source to PLLD_OUT0 */ |
| 992 | clock_configure_source(disp1, PLLD_OUT0, (plld_rate/KHz)); |
| 993 | |
| 994 | /* Init dc */ |
| 995 | if (tegra_dc_init(disp_ctrl)) { |
| 996 | printk(BIOS_ERR, "dc: init failed\n"); |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | /* Configure dc mode */ |
| 1001 | if (update_display_mode(disp_ctrl, config)) { |
| 1002 | printk(BIOS_ERR, "dc: failed to configure display mode.\n"); |
| 1003 | return; |
| 1004 | } |
| 1005 | |
| 1006 | /* Configure and enable dsi controller and panel */ |
| 1007 | if (dsi_enable(config)) { |
| 1008 | printk(BIOS_ERR, "%s: failed to enable dsi controllers.\n", |
| 1009 | __func__); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | /* Set up window */ |
| 1014 | update_window(config); |
| 1015 | printk(BIOS_INFO, "%s: display init done.\n", __func__); |
| 1016 | |
| 1017 | /* Save panel information to cb tables */ |
| 1018 | pass_mode_info_to_payload(config); |
| 1019 | |
| 1020 | /* |
| 1021 | * After this point, it is payload's responsibility to allocate |
| 1022 | * framebuffer and sets the base address to dc's |
| 1023 | * WINBUF_START_ADDR register and enables window by setting dc's |
| 1024 | * DISP_DISP_WIN_OPTIONS register. |
| 1025 | */ |
| 1026 | } |