.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * OMAP5 HDMI CORE IP driver library |
---|
3 | 4 | * |
---|
.. | .. |
---|
7 | 8 | * Mythri pk |
---|
8 | 9 | * Archit Taneja <archit@ti.com> |
---|
9 | 10 | * Tomi Valkeinen <tomi.valkeinen@ti.com> |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or modify it |
---|
12 | | - * under the terms of the GNU General Public License version 2 as published by |
---|
13 | | - * the Free Software Foundation. |
---|
14 | | - * |
---|
15 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
17 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
18 | | - * more details. |
---|
19 | | - * |
---|
20 | | - * You should have received a copy of the GNU General Public License along with |
---|
21 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | 11 | */ |
---|
23 | 12 | |
---|
24 | 13 | #include <linux/kernel.h> |
---|
.. | .. |
---|
34 | 23 | |
---|
35 | 24 | #include "hdmi5_core.h" |
---|
36 | 25 | |
---|
37 | | -/* only 24 bit color depth used for now */ |
---|
38 | | -static const struct csc_table csc_table_deepcolor[] = { |
---|
39 | | - /* HDMI_DEEP_COLOR_24BIT */ |
---|
40 | | - [0] = { 7036, 0, 0, 32, 0, 7036, 0, 32, 0, 0, 7036, 32, }, |
---|
41 | | - /* HDMI_DEEP_COLOR_30BIT */ |
---|
42 | | - [1] = { 7015, 0, 0, 128, 0, 7015, 0, 128, 0, 0, 7015, 128, }, |
---|
43 | | - /* HDMI_DEEP_COLOR_36BIT */ |
---|
44 | | - [2] = { 7010, 0, 0, 512, 0, 7010, 0, 512, 0, 0, 7010, 512, }, |
---|
45 | | - /* FULL RANGE */ |
---|
46 | | - [3] = { 8192, 0, 0, 0, 0, 8192, 0, 0, 0, 0, 8192, 0, }, |
---|
47 | | -}; |
---|
48 | | - |
---|
49 | | -static void hdmi_core_ddc_init(struct hdmi_core_data *core) |
---|
| 26 | +void hdmi5_core_ddc_init(struct hdmi_core_data *core) |
---|
50 | 27 | { |
---|
51 | 28 | void __iomem *base = core->base; |
---|
52 | 29 | const unsigned long long iclk = 266000000; /* DSS L3 ICLK */ |
---|
53 | | - const unsigned int ss_scl_high = 4600; /* ns */ |
---|
54 | | - const unsigned int ss_scl_low = 5400; /* ns */ |
---|
| 30 | + const unsigned int ss_scl_high = 4700; /* ns */ |
---|
| 31 | + const unsigned int ss_scl_low = 5500; /* ns */ |
---|
55 | 32 | const unsigned int fs_scl_high = 600; /* ns */ |
---|
56 | 33 | const unsigned int fs_scl_low = 1300; /* ns */ |
---|
57 | 34 | const unsigned int sda_hold = 1000; /* ns */ |
---|
.. | .. |
---|
125 | 102 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x0, 2, 2); |
---|
126 | 103 | } |
---|
127 | 104 | |
---|
128 | | -static void hdmi_core_ddc_uninit(struct hdmi_core_data *core) |
---|
| 105 | +void hdmi5_core_ddc_uninit(struct hdmi_core_data *core) |
---|
129 | 106 | { |
---|
130 | 107 | void __iomem *base = core->base; |
---|
131 | 108 | |
---|
.. | .. |
---|
135 | 112 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2); |
---|
136 | 113 | } |
---|
137 | 114 | |
---|
138 | | -static int hdmi_core_ddc_edid(struct hdmi_core_data *core, u8 *pedid, u8 ext) |
---|
| 115 | +int hdmi5_core_ddc_read(void *data, u8 *buf, unsigned int block, size_t len) |
---|
139 | 116 | { |
---|
| 117 | + struct hdmi_core_data *core = data; |
---|
140 | 118 | void __iomem *base = core->base; |
---|
141 | 119 | u8 cur_addr; |
---|
142 | | - char checksum = 0; |
---|
143 | 120 | const int retries = 1000; |
---|
144 | | - u8 seg_ptr = ext / 2; |
---|
145 | | - u8 edidbase = ((ext % 2) * 0x80); |
---|
| 121 | + u8 seg_ptr = block / 2; |
---|
| 122 | + u8 edidbase = ((block % 2) * EDID_LENGTH); |
---|
146 | 123 | |
---|
147 | 124 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SEGPTR, seg_ptr, 7, 0); |
---|
148 | 125 | |
---|
.. | .. |
---|
150 | 127 | * TODO: We use polling here, although we probably should use proper |
---|
151 | 128 | * interrupts. |
---|
152 | 129 | */ |
---|
153 | | - for (cur_addr = 0; cur_addr < 128; ++cur_addr) { |
---|
| 130 | + for (cur_addr = 0; cur_addr < len; ++cur_addr) { |
---|
154 | 131 | int i; |
---|
155 | 132 | |
---|
156 | 133 | /* clear ERROR and DONE */ |
---|
.. | .. |
---|
187 | 164 | return -EIO; |
---|
188 | 165 | } |
---|
189 | 166 | |
---|
190 | | - pedid[cur_addr] = REG_GET(base, HDMI_CORE_I2CM_DATAI, 7, 0); |
---|
191 | | - checksum += pedid[cur_addr]; |
---|
| 167 | + buf[cur_addr] = REG_GET(base, HDMI_CORE_I2CM_DATAI, 7, 0); |
---|
192 | 168 | } |
---|
193 | 169 | |
---|
194 | 170 | return 0; |
---|
195 | 171 | |
---|
196 | | -} |
---|
197 | | - |
---|
198 | | -int hdmi5_read_edid(struct hdmi_core_data *core, u8 *edid, int len) |
---|
199 | | -{ |
---|
200 | | - int r, n, i; |
---|
201 | | - int max_ext_blocks = (len / 128) - 1; |
---|
202 | | - |
---|
203 | | - if (len < 128) |
---|
204 | | - return -EINVAL; |
---|
205 | | - |
---|
206 | | - hdmi_core_ddc_init(core); |
---|
207 | | - |
---|
208 | | - r = hdmi_core_ddc_edid(core, edid, 0); |
---|
209 | | - if (r) |
---|
210 | | - goto out; |
---|
211 | | - |
---|
212 | | - n = edid[0x7e]; |
---|
213 | | - |
---|
214 | | - if (n > max_ext_blocks) |
---|
215 | | - n = max_ext_blocks; |
---|
216 | | - |
---|
217 | | - for (i = 1; i <= n; i++) { |
---|
218 | | - r = hdmi_core_ddc_edid(core, edid + i * EDID_LENGTH, i); |
---|
219 | | - if (r) |
---|
220 | | - goto out; |
---|
221 | | - } |
---|
222 | | - |
---|
223 | | -out: |
---|
224 | | - hdmi_core_ddc_uninit(core); |
---|
225 | | - |
---|
226 | | - return r ? r : len; |
---|
227 | 172 | } |
---|
228 | 173 | |
---|
229 | 174 | void hdmi5_core_dump(struct hdmi_core_data *core, struct seq_file *s) |
---|
.. | .. |
---|
287 | 232 | } |
---|
288 | 233 | |
---|
289 | 234 | static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg, |
---|
290 | | - struct hdmi_config *cfg) |
---|
| 235 | + const struct hdmi_config *cfg) |
---|
291 | 236 | { |
---|
292 | 237 | DSSDBG("hdmi_core_init\n"); |
---|
293 | 238 | |
---|
.. | .. |
---|
325 | 270 | |
---|
326 | 271 | /* DSS_HDMI_CORE_VIDEO_CONFIG */ |
---|
327 | 272 | static void hdmi_core_video_config(struct hdmi_core_data *core, |
---|
328 | | - struct hdmi_core_vid_config *cfg) |
---|
| 273 | + const struct hdmi_core_vid_config *cfg) |
---|
329 | 274 | { |
---|
330 | 275 | void __iomem *base = core->base; |
---|
331 | | - struct videomode *vm = &cfg->v_fc_config.vm; |
---|
| 276 | + const struct videomode *vm = &cfg->v_fc_config.vm; |
---|
332 | 277 | unsigned char r = 0; |
---|
333 | 278 | bool vsync_pol, hsync_pol; |
---|
334 | 279 | |
---|
.. | .. |
---|
408 | 353 | REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 2, 1, 0); |
---|
409 | 354 | } |
---|
410 | 355 | |
---|
411 | | -static void hdmi_core_config_csc(struct hdmi_core_data *core) |
---|
412 | | -{ |
---|
413 | | - int clr_depth = 0; /* 24 bit color depth */ |
---|
414 | | - |
---|
415 | | - /* CSC_COLORDEPTH */ |
---|
416 | | - REG_FLD_MOD(core->base, HDMI_CORE_CSC_SCALE, clr_depth, 7, 4); |
---|
417 | | -} |
---|
418 | | - |
---|
419 | 356 | static void hdmi_core_config_video_sampler(struct hdmi_core_data *core) |
---|
420 | 357 | { |
---|
421 | 358 | int video_mapping = 1; /* for 24 bit color depth */ |
---|
.. | .. |
---|
480 | 417 | REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, pr, 3, 0); |
---|
481 | 418 | } |
---|
482 | 419 | |
---|
483 | | -static void hdmi_core_csc_config(struct hdmi_core_data *core, |
---|
484 | | - struct csc_table csc_coeff) |
---|
| 420 | +static void hdmi_core_write_csc(struct hdmi_core_data *core, |
---|
| 421 | + const struct csc_table *csc_coeff) |
---|
485 | 422 | { |
---|
486 | 423 | void __iomem *base = core->base; |
---|
487 | 424 | |
---|
488 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_MSB, csc_coeff.a1 >> 8 , 6, 0); |
---|
489 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_LSB, csc_coeff.a1, 7, 0); |
---|
490 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_MSB, csc_coeff.a2 >> 8, 6, 0); |
---|
491 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_LSB, csc_coeff.a2, 7, 0); |
---|
492 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_MSB, csc_coeff.a3 >> 8, 6, 0); |
---|
493 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_LSB, csc_coeff.a3, 7, 0); |
---|
494 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_MSB, csc_coeff.a4 >> 8, 6, 0); |
---|
495 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_LSB, csc_coeff.a4, 7, 0); |
---|
496 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_MSB, csc_coeff.b1 >> 8, 6, 0); |
---|
497 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_LSB, csc_coeff.b1, 7, 0); |
---|
498 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_MSB, csc_coeff.b2 >> 8, 6, 0); |
---|
499 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_LSB, csc_coeff.b2, 7, 0); |
---|
500 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_MSB, csc_coeff.b3 >> 8, 6, 0); |
---|
501 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_LSB, csc_coeff.b3, 7, 0); |
---|
502 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_MSB, csc_coeff.b4 >> 8, 6, 0); |
---|
503 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_LSB, csc_coeff.b4, 7, 0); |
---|
504 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_MSB, csc_coeff.c1 >> 8, 6, 0); |
---|
505 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_LSB, csc_coeff.c1, 7, 0); |
---|
506 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_MSB, csc_coeff.c2 >> 8, 6, 0); |
---|
507 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_LSB, csc_coeff.c2, 7, 0); |
---|
508 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_MSB, csc_coeff.c3 >> 8, 6, 0); |
---|
509 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_LSB, csc_coeff.c3, 7, 0); |
---|
510 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_MSB, csc_coeff.c4 >> 8, 6, 0); |
---|
511 | | - REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_LSB, csc_coeff.c4, 7, 0); |
---|
| 425 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_MSB, csc_coeff->a1 >> 8, 6, 0); |
---|
| 426 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_LSB, csc_coeff->a1, 7, 0); |
---|
| 427 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_MSB, csc_coeff->a2 >> 8, 6, 0); |
---|
| 428 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_LSB, csc_coeff->a2, 7, 0); |
---|
| 429 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_MSB, csc_coeff->a3 >> 8, 6, 0); |
---|
| 430 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_LSB, csc_coeff->a3, 7, 0); |
---|
| 431 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_MSB, csc_coeff->a4 >> 8, 6, 0); |
---|
| 432 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_LSB, csc_coeff->a4, 7, 0); |
---|
| 433 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_MSB, csc_coeff->b1 >> 8, 6, 0); |
---|
| 434 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_LSB, csc_coeff->b1, 7, 0); |
---|
| 435 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_MSB, csc_coeff->b2 >> 8, 6, 0); |
---|
| 436 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_LSB, csc_coeff->b2, 7, 0); |
---|
| 437 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_MSB, csc_coeff->b3 >> 8, 6, 0); |
---|
| 438 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_LSB, csc_coeff->b3, 7, 0); |
---|
| 439 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_MSB, csc_coeff->b4 >> 8, 6, 0); |
---|
| 440 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_LSB, csc_coeff->b4, 7, 0); |
---|
| 441 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_MSB, csc_coeff->c1 >> 8, 6, 0); |
---|
| 442 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_LSB, csc_coeff->c1, 7, 0); |
---|
| 443 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_MSB, csc_coeff->c2 >> 8, 6, 0); |
---|
| 444 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_LSB, csc_coeff->c2, 7, 0); |
---|
| 445 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_MSB, csc_coeff->c3 >> 8, 6, 0); |
---|
| 446 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_LSB, csc_coeff->c3, 7, 0); |
---|
| 447 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_MSB, csc_coeff->c4 >> 8, 6, 0); |
---|
| 448 | + REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_LSB, csc_coeff->c4, 7, 0); |
---|
512 | 449 | |
---|
| 450 | + /* enable CSC */ |
---|
513 | 451 | REG_FLD_MOD(base, HDMI_CORE_MC_FLOWCTRL, 0x1, 0, 0); |
---|
514 | 452 | } |
---|
515 | 453 | |
---|
516 | | -static void hdmi_core_configure_range(struct hdmi_core_data *core) |
---|
| 454 | +static void hdmi_core_configure_range(struct hdmi_core_data *core, |
---|
| 455 | + enum hdmi_quantization_range range) |
---|
517 | 456 | { |
---|
518 | | - struct csc_table csc_coeff = { 0 }; |
---|
| 457 | + static const struct csc_table csc_limited_range = { |
---|
| 458 | + 7036, 0, 0, 32, 0, 7036, 0, 32, 0, 0, 7036, 32 |
---|
| 459 | + }; |
---|
| 460 | + static const struct csc_table csc_full_range = { |
---|
| 461 | + 8192, 0, 0, 0, 0, 8192, 0, 0, 0, 0, 8192, 0 |
---|
| 462 | + }; |
---|
| 463 | + const struct csc_table *csc_coeff; |
---|
519 | 464 | |
---|
520 | | - /* support limited range with 24 bit color depth for now */ |
---|
521 | | - csc_coeff = csc_table_deepcolor[0]; |
---|
| 465 | + /* CSC_COLORDEPTH = 24 bits*/ |
---|
| 466 | + REG_FLD_MOD(core->base, HDMI_CORE_CSC_SCALE, 0, 7, 4); |
---|
522 | 467 | |
---|
523 | | - hdmi_core_csc_config(core, csc_coeff); |
---|
| 468 | + switch (range) { |
---|
| 469 | + case HDMI_QUANTIZATION_RANGE_FULL: |
---|
| 470 | + csc_coeff = &csc_full_range; |
---|
| 471 | + break; |
---|
| 472 | + |
---|
| 473 | + case HDMI_QUANTIZATION_RANGE_DEFAULT: |
---|
| 474 | + case HDMI_QUANTIZATION_RANGE_LIMITED: |
---|
| 475 | + default: |
---|
| 476 | + csc_coeff = &csc_limited_range; |
---|
| 477 | + break; |
---|
| 478 | + } |
---|
| 479 | + |
---|
| 480 | + hdmi_core_write_csc(core, csc_coeff); |
---|
524 | 481 | } |
---|
525 | 482 | |
---|
526 | 483 | static void hdmi_core_enable_video_path(struct hdmi_core_data *core) |
---|
.. | .. |
---|
611 | 568 | struct videomode vm; |
---|
612 | 569 | struct hdmi_video_format video_format; |
---|
613 | 570 | struct hdmi_core_vid_config v_core_cfg; |
---|
| 571 | + enum hdmi_quantization_range range; |
---|
614 | 572 | |
---|
615 | 573 | hdmi_core_mask_interrupts(core); |
---|
| 574 | + |
---|
| 575 | + if (cfg->hdmi_dvi_mode == HDMI_HDMI) { |
---|
| 576 | + char vic = cfg->infoframe.video_code; |
---|
| 577 | + |
---|
| 578 | + /* All CEA modes other than VIC 1 use limited quantization range. */ |
---|
| 579 | + range = vic > 1 ? HDMI_QUANTIZATION_RANGE_LIMITED : |
---|
| 580 | + HDMI_QUANTIZATION_RANGE_FULL; |
---|
| 581 | + } else { |
---|
| 582 | + range = HDMI_QUANTIZATION_RANGE_FULL; |
---|
| 583 | + } |
---|
616 | 584 | |
---|
617 | 585 | hdmi_core_init(&v_core_cfg, cfg); |
---|
618 | 586 | |
---|
.. | .. |
---|
627 | 595 | |
---|
628 | 596 | hdmi_wp_video_config_interface(wp, &vm); |
---|
629 | 597 | |
---|
630 | | - /* support limited range with 24 bit color depth for now */ |
---|
631 | | - hdmi_core_configure_range(core); |
---|
632 | | - cfg->infoframe.quantization_range = HDMI_QUANTIZATION_RANGE_LIMITED; |
---|
| 598 | + hdmi_core_configure_range(core, range); |
---|
| 599 | + cfg->infoframe.quantization_range = range; |
---|
633 | 600 | |
---|
634 | 601 | /* |
---|
635 | 602 | * configure core video part, set software reset in the core |
---|
.. | .. |
---|
639 | 606 | hdmi_core_video_config(core, &v_core_cfg); |
---|
640 | 607 | |
---|
641 | 608 | hdmi_core_config_video_packetizer(core); |
---|
642 | | - hdmi_core_config_csc(core); |
---|
643 | 609 | hdmi_core_config_video_sampler(core); |
---|
644 | 610 | |
---|
645 | 611 | if (cfg->hdmi_dvi_mode == HDMI_HDMI) |
---|
.. | .. |
---|
809 | 775 | struct hdmi_audio_format audio_format; |
---|
810 | 776 | struct hdmi_audio_dma audio_dma; |
---|
811 | 777 | struct hdmi_core_audio_config core_cfg; |
---|
812 | | - int err, n, cts, channel_count; |
---|
| 778 | + int n, cts, channel_count; |
---|
813 | 779 | unsigned int fs_nr; |
---|
814 | 780 | bool word_length_16b = false; |
---|
815 | 781 | |
---|
.. | .. |
---|
852 | 818 | return -EINVAL; |
---|
853 | 819 | } |
---|
854 | 820 | |
---|
855 | | - err = hdmi_compute_acr(pclk, fs_nr, &n, &cts); |
---|
| 821 | + hdmi_compute_acr(pclk, fs_nr, &n, &cts); |
---|
856 | 822 | core_cfg.n = n; |
---|
857 | 823 | core_cfg.cts = cts; |
---|
858 | 824 | |
---|