Lines Matching defs:tu

314 					struct tu_algo_data *tu)
332 tu->lclk_fp = drm_fixp_from_fraction(in->lclk, 1);
333 tu->pclk_fp = drm_fixp_from_fraction(in->pclk_khz, 1000);
334 tu->lwidth = in->hactive;
335 tu->hbp_relative_to_pclk = in->hporch;
336 tu->nlanes = in->nlanes;
337 tu->bpp = in->bpp;
338 tu->pixelEnc = in->pixel_enc;
339 tu->dsc_en = in->dsc_en;
340 tu->async_en = in->async_en;
341 tu->lwidth_fp = drm_fixp_from_fraction(in->hactive, 1);
342 tu->hbp_relative_to_pclk_fp = drm_fixp_from_fraction(in->hporch, 1);
344 if (tu->pixelEnc == 420) {
346 tu->pclk_fp = drm_fixp_div(tu->pclk_fp, temp1_fp);
347 tu->lwidth_fp = drm_fixp_div(tu->lwidth_fp, temp1_fp);
348 tu->hbp_relative_to_pclk_fp =
349 drm_fixp_div(tu->hbp_relative_to_pclk_fp, 2);
352 if (tu->pixelEnc == 422) {
353 switch (tu->bpp) {
355 tu->bpp = 16;
356 tu->bpc = 8;
359 tu->bpp = 20;
360 tu->bpc = 10;
363 tu->bpp = 16;
364 tu->bpc = 8;
368 tu->bpc = tu->bpp/3;
377 temp2_fp = drm_fixp_mul(tu->lwidth_fp, temp3_fp);
399 temp2_fp = drm_fixp_mul(tu->pclk_fp, dwidth_dsc_fp);
400 temp1_fp = drm_fixp_div(temp2_fp, tu->lwidth_fp);
403 temp1_fp = drm_fixp_div(pclk_dsc_fp, tu->pclk_fp);
404 temp2_fp = drm_fixp_mul(tu->hbp_relative_to_pclk_fp, temp1_fp);
408 tu->pclk_fp = pclk_dsc_fp;
409 tu->lwidth_fp = dwidth_dsc_fp;
410 tu->hbp_relative_to_pclk_fp = hbp_dsc_fp;
415 tu->lclk_fp = drm_fixp_mul(tu->lclk_fp, temp1_fp);
419 static void _tu_valid_boundary_calc(struct tu_algo_data *tu)
424 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
425 temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
427 tu->new_valid_boundary_link = drm_fixp2int_ceil(temp2_fp);
429 temp = (tu->i_upper_boundary_count *
430 tu->new_valid_boundary_link +
431 tu->i_lower_boundary_count *
432 (tu->new_valid_boundary_link-1));
433 tu->average_valid2_fp = drm_fixp_from_fraction(temp,
434 (tu->i_upper_boundary_count +
435 tu->i_lower_boundary_count));
437 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
438 temp2_fp = tu->lwidth_fp;
440 temp2_fp = drm_fixp_div(temp1_fp, tu->average_valid2_fp);
441 tu->n_tus = drm_fixp2int(temp2_fp);
443 tu->n_tus += 1;
445 temp1_fp = drm_fixp_from_fraction(tu->n_tus, 1);
446 temp2_fp = drm_fixp_mul(temp1_fp, tu->average_valid2_fp);
447 temp1_fp = drm_fixp_from_fraction(tu->n_symbols, 1);
449 temp1_fp = drm_fixp_from_fraction(tu->nlanes, 1);
451 tu->n_remainder_symbols_per_lane_fp = temp2_fp;
453 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
454 tu->last_partial_tu_fp =
455 drm_fixp_div(tu->n_remainder_symbols_per_lane_fp,
458 if (tu->n_remainder_symbols_per_lane_fp != 0)
459 tu->remainder_symbols_exist = 1;
461 tu->remainder_symbols_exist = 0;
463 temp1_fp = drm_fixp_from_fraction(tu->n_tus, tu->nlanes);
464 tu->n_tus_per_lane = drm_fixp2int(temp1_fp);
466 tu->paired_tus = (int)((tu->n_tus_per_lane) /
467 (tu->i_upper_boundary_count +
468 tu->i_lower_boundary_count));
470 tu->remainder_tus = tu->n_tus_per_lane - tu->paired_tus *
471 (tu->i_upper_boundary_count +
472 tu->i_lower_boundary_count);
474 if ((tu->remainder_tus - tu->i_upper_boundary_count) > 0) {
475 tu->remainder_tus_upper = tu->i_upper_boundary_count;
476 tu->remainder_tus_lower = tu->remainder_tus -
477 tu->i_upper_boundary_count;
479 tu->remainder_tus_upper = tu->remainder_tus;
480 tu->remainder_tus_lower = 0;
483 temp = tu->paired_tus * (tu->i_upper_boundary_count *
484 tu->new_valid_boundary_link +
485 tu->i_lower_boundary_count *
486 (tu->new_valid_boundary_link - 1)) +
487 (tu->remainder_tus_upper *
488 tu->new_valid_boundary_link) +
489 (tu->remainder_tus_lower *
490 (tu->new_valid_boundary_link - 1));
491 tu->total_valid_fp = drm_fixp_from_fraction(temp, 1);
493 if (tu->remainder_symbols_exist) {
494 temp1_fp = tu->total_valid_fp +
495 tu->n_remainder_symbols_per_lane_fp;
496 temp2_fp = drm_fixp_from_fraction(tu->n_tus_per_lane, 1);
497 temp2_fp = temp2_fp + tu->last_partial_tu_fp;
500 temp2_fp = drm_fixp_from_fraction(tu->n_tus_per_lane, 1);
501 temp1_fp = drm_fixp_div(tu->total_valid_fp, temp2_fp);
503 tu->effective_valid_fp = temp1_fp;
505 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
506 temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
507 tu->n_n_err_fp = tu->effective_valid_fp - temp2_fp;
509 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
510 temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
511 tu->n_err_fp = tu->average_valid2_fp - temp2_fp;
513 tu->even_distribution = tu->n_tus % tu->nlanes == 0 ? 1 : 0;
515 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
516 temp2_fp = tu->lwidth_fp;
518 temp2_fp = drm_fixp_div(temp1_fp, tu->average_valid2_fp);
521 tu->n_tus_incl_last_incomplete_tu = drm_fixp2int_ceil(temp2_fp);
523 tu->n_tus_incl_last_incomplete_tu = 0;
526 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
527 temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
528 temp1_fp = tu->average_valid2_fp - temp2_fp;
529 temp2_fp = drm_fixp_from_fraction(tu->n_tus_incl_last_incomplete_tu, 1);
535 temp = tu->i_upper_boundary_count * tu->nlanes;
536 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
537 temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
538 temp1_fp = drm_fixp_from_fraction(tu->new_valid_boundary_link, 1);
547 tu->extra_required_bytes_new_tmp = (int)(temp1 + temp2);
549 temp1_fp = drm_fixp_from_fraction(8, tu->bpp);
551 tu->extra_required_bytes_new_tmp, 1);
555 tu->extra_pclk_cycles_tmp = drm_fixp2int_ceil(temp1_fp);
557 tu->extra_pclk_cycles_tmp = 0;
559 temp1_fp = drm_fixp_from_fraction(tu->extra_pclk_cycles_tmp, 1);
560 temp2_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
564 tu->extra_pclk_cycles_in_link_clk_tmp =
567 tu->extra_pclk_cycles_in_link_clk_tmp = 0;
569 tu->filler_size_tmp = tu->tu_size - tu->new_valid_boundary_link;
571 tu->lower_filler_size_tmp = tu->filler_size_tmp + 1;
573 tu->delay_start_link_tmp = tu->extra_pclk_cycles_in_link_clk_tmp +
574 tu->lower_filler_size_tmp +
575 tu->extra_buffer_margin;
577 temp1_fp = drm_fixp_from_fraction(tu->delay_start_link_tmp, 1);
578 tu->delay_start_time_fp = drm_fixp_div(temp1_fp, tu->lclk_fp);
580 compare_result_1 = _tu_param_compare(tu->n_n_err_fp, tu->diff_abs_fp);
586 compare_result_2 = _tu_param_compare(tu->n_n_err_fp, tu->err_fp);
592 compare_result_3 = _tu_param_compare(tu->hbp_time_fp,
593 tu->delay_start_time_fp);
599 if (((tu->even_distribution == 1) ||
600 ((tu->even_distribution_BF == 0) &&
601 (tu->even_distribution_legacy == 0))) &&
602 tu->n_err_fp >= 0 && tu->n_n_err_fp >= 0 &&
604 (compare_result_1 || (tu->min_hblank_violated == 1)) &&
605 (tu->new_valid_boundary_link - 1) > 0 &&
607 (tu->delay_start_link_tmp <= 1023)) {
608 tu->upper_boundary_count = tu->i_upper_boundary_count;
609 tu->lower_boundary_count = tu->i_lower_boundary_count;
610 tu->err_fp = tu->n_n_err_fp;
611 tu->boundary_moderation_en = true;
612 tu->tu_size_desired = tu->tu_size;
613 tu->valid_boundary_link = tu->new_valid_boundary_link;
614 tu->effective_valid_recorded_fp = tu->effective_valid_fp;
615 tu->even_distribution_BF = 1;
616 tu->delay_start_link = tu->delay_start_link_tmp;
617 } else if (tu->boundary_mod_lower_err == 0) {
618 compare_result_1 = _tu_param_compare(tu->n_n_err_fp,
619 tu->diff_abs_fp);
621 tu->boundary_mod_lower_err = 1;
629 struct tu_algo_data *tu;
644 tu = kzalloc(sizeof(*tu), GFP_KERNEL);
645 if (!tu)
648 dp_panel_update_tu_timings(in, tu);
650 tu->err_fp = drm_fixp_from_fraction(1000, 1); /* 1000 */
653 temp2_fp = drm_fixp_mul(temp1_fp, tu->lclk_fp);
654 temp_fp = drm_fixp_div(temp2_fp, tu->pclk_fp);
655 tu->extra_buffer_margin = drm_fixp2int_ceil(temp_fp);
657 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
658 temp2_fp = drm_fixp_mul(tu->pclk_fp, temp1_fp);
659 temp1_fp = drm_fixp_from_fraction(tu->nlanes, 1);
661 tu->ratio_fp = drm_fixp_div(temp2_fp, tu->lclk_fp);
663 tu->original_ratio_fp = tu->ratio_fp;
664 tu->boundary_moderation_en = false;
665 tu->upper_boundary_count = 0;
666 tu->lower_boundary_count = 0;
667 tu->i_upper_boundary_count = 0;
668 tu->i_lower_boundary_count = 0;
669 tu->valid_lower_boundary_link = 0;
670 tu->even_distribution_BF = 0;
671 tu->even_distribution_legacy = 0;
672 tu->even_distribution = 0;
673 tu->delay_start_time_fp = 0;
675 tu->err_fp = drm_fixp_from_fraction(1000, 1);
676 tu->n_err_fp = 0;
677 tu->n_n_err_fp = 0;
679 tu->ratio = drm_fixp2int(tu->ratio_fp);
680 temp1_fp = drm_fixp_from_fraction(tu->nlanes, 1);
681 div64_u64_rem(tu->lwidth_fp, temp1_fp, &temp2_fp);
683 !tu->ratio && tu->dsc_en == 0) {
684 tu->ratio_fp = drm_fixp_mul(tu->ratio_fp, RATIO_SCALE_fp);
685 tu->ratio = drm_fixp2int(tu->ratio_fp);
686 if (tu->ratio)
687 tu->ratio_fp = drm_fixp_from_fraction(1, 1);
690 if (tu->ratio > 1)
691 tu->ratio = 1;
693 if (tu->ratio == 1)
696 compare_result_1 = _tu_param_compare(tu->ratio_fp, const_p49_fp);
702 compare_result_2 = _tu_param_compare(tu->ratio_fp, const_p56_fp);
708 if (tu->dsc_en && compare_result_1 && compare_result_2) {
715 for (tu->tu_size = 32; tu->tu_size <= 64; tu->tu_size++) {
716 temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
717 temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
720 tu->n_err_fp = temp1_fp - temp2_fp;
722 if (tu->n_err_fp < tu->err_fp) {
723 tu->err_fp = tu->n_err_fp;
724 tu->tu_size_desired = tu->tu_size;
728 tu->tu_size_minus1 = tu->tu_size_desired - 1;
730 temp1_fp = drm_fixp_from_fraction(tu->tu_size_desired, 1);
731 temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
732 tu->valid_boundary_link = drm_fixp2int_ceil(temp2_fp);
734 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
735 temp2_fp = tu->lwidth_fp;
738 temp1_fp = drm_fixp_from_fraction(tu->valid_boundary_link, 1);
740 tu->n_tus = drm_fixp2int(temp2_fp);
742 tu->n_tus += 1;
744 tu->even_distribution_legacy = tu->n_tus % tu->nlanes == 0 ? 1 : 0;
748 tu->valid_boundary_link, tu->n_tus);
750 temp1_fp = drm_fixp_from_fraction(tu->tu_size_desired, 1);
751 temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
752 temp1_fp = drm_fixp_from_fraction(tu->valid_boundary_link, 1);
754 temp1_fp = drm_fixp_from_fraction(tu->n_tus + 1, 1);
759 tu->extra_bytes = drm_fixp2int_ceil(temp2_fp);
761 tu->extra_bytes = 0;
763 temp1_fp = drm_fixp_from_fraction(tu->extra_bytes, 1);
764 temp2_fp = drm_fixp_from_fraction(8, tu->bpp);
768 tu->extra_pclk_cycles = drm_fixp2int_ceil(temp1_fp);
770 tu->extra_pclk_cycles = drm_fixp2int(temp1_fp);
772 temp1_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
773 temp2_fp = drm_fixp_from_fraction(tu->extra_pclk_cycles, 1);
777 tu->extra_pclk_cycles_in_link_clk = drm_fixp2int_ceil(temp1_fp);
779 tu->extra_pclk_cycles_in_link_clk = drm_fixp2int(temp1_fp);
781 tu->filler_size = tu->tu_size_desired - tu->valid_boundary_link;
783 temp1_fp = drm_fixp_from_fraction(tu->tu_size_desired, 1);
784 tu->ratio_by_tu_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
786 tu->delay_start_link = tu->extra_pclk_cycles_in_link_clk +
787 tu->filler_size + tu->extra_buffer_margin;
789 tu->resulting_valid_fp =
790 drm_fixp_from_fraction(tu->valid_boundary_link, 1);
792 temp1_fp = drm_fixp_from_fraction(tu->tu_size_desired, 1);
793 temp2_fp = drm_fixp_div(tu->resulting_valid_fp, temp1_fp);
794 tu->TU_ratio_err_fp = temp2_fp - tu->original_ratio_fp;
797 temp1_fp = tu->hbp_relative_to_pclk_fp - temp1_fp;
798 tu->hbp_time_fp = drm_fixp_div(temp1_fp, tu->pclk_fp);
800 temp1_fp = drm_fixp_from_fraction(tu->delay_start_link, 1);
801 tu->delay_start_time_fp = drm_fixp_div(temp1_fp, tu->lclk_fp);
803 compare_result_1 = _tu_param_compare(tu->hbp_time_fp,
804 tu->delay_start_time_fp);
806 tu->min_hblank_violated = 1;
808 tu->hactive_time_fp = drm_fixp_div(tu->lwidth_fp, tu->pclk_fp);
810 compare_result_2 = _tu_param_compare(tu->hactive_time_fp,
811 tu->delay_start_time_fp);
813 tu->min_hblank_violated = 1;
815 tu->delay_start_time_fp = 0;
819 tu->delay_start_link_extra_pixclk = EXTRA_PIXCLK_CYCLE_DELAY;
820 tu->diff_abs_fp = tu->resulting_valid_fp - tu->ratio_by_tu_fp;
822 temp = drm_fixp2int(tu->diff_abs_fp);
823 if (!temp && tu->diff_abs_fp <= 0xffff)
824 tu->diff_abs_fp = 0;
827 if (tu->diff_abs_fp < 0)
828 tu->diff_abs_fp = drm_fixp_mul(tu->diff_abs_fp, -1);
830 tu->boundary_mod_lower_err = 0;
831 if ((tu->diff_abs_fp != 0 &&
832 ((tu->diff_abs_fp > BRUTE_FORCE_THRESHOLD_fp) ||
833 (tu->even_distribution_legacy == 0) ||
835 (tu->min_hblank_violated == 1)) {
837 tu->err_fp = drm_fixp_from_fraction(1000, 1);
839 temp1_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
841 tu->delay_start_link_extra_pixclk, 1);
845 tu->extra_buffer_margin =
848 tu->extra_buffer_margin = 0;
850 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
851 temp1_fp = drm_fixp_mul(tu->lwidth_fp, temp1_fp);
854 tu->n_symbols = drm_fixp2int_ceil(temp1_fp);
856 tu->n_symbols = 0;
858 for (tu->tu_size = 32; tu->tu_size <= 64; tu->tu_size++) {
859 for (tu->i_upper_boundary_count = 1;
860 tu->i_upper_boundary_count <= 15;
861 tu->i_upper_boundary_count++) {
862 for (tu->i_lower_boundary_count = 1;
863 tu->i_lower_boundary_count <= 15;
864 tu->i_lower_boundary_count++) {
865 _tu_valid_boundary_calc(tu);
869 tu->delay_start_link_extra_pixclk--;
870 } while (tu->boundary_moderation_en != true &&
871 tu->boundary_mod_lower_err == 1 &&
872 tu->delay_start_link_extra_pixclk != 0);
874 if (tu->boundary_moderation_en == true) {
876 (tu->upper_boundary_count *
877 tu->valid_boundary_link +
878 tu->lower_boundary_count *
879 (tu->valid_boundary_link - 1)), 1);
881 (tu->upper_boundary_count +
882 tu->lower_boundary_count), 1);
883 tu->resulting_valid_fp =
887 tu->tu_size_desired, 1);
888 tu->ratio_by_tu_fp =
889 drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
891 tu->valid_lower_boundary_link =
892 tu->valid_boundary_link - 1;
894 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
895 temp1_fp = drm_fixp_mul(tu->lwidth_fp, temp1_fp);
897 tu->resulting_valid_fp);
898 tu->n_tus = drm_fixp2int(temp2_fp);
900 tu->tu_size_minus1 = tu->tu_size_desired - 1;
901 tu->even_distribution_BF = 1;
904 drm_fixp_from_fraction(tu->tu_size_desired, 1);
906 drm_fixp_div(tu->resulting_valid_fp, temp1_fp);
907 tu->TU_ratio_err_fp = temp2_fp - tu->original_ratio_fp;
911 temp2_fp = drm_fixp_mul(LCLK_FAST_SKEW_fp, tu->lwidth_fp);
918 temp1_fp = drm_fixp_from_fraction(tu->nlanes, 1);
919 temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
920 temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
926 if (tu->async_en)
927 tu->delay_start_link += (int)temp;
929 temp1_fp = drm_fixp_from_fraction(tu->delay_start_link, 1);
930 tu->delay_start_time_fp = drm_fixp_div(temp1_fp, tu->lclk_fp);
933 tu_table->valid_boundary_link = tu->valid_boundary_link;
934 tu_table->delay_start_link = tu->delay_start_link;
935 tu_table->boundary_moderation_en = tu->boundary_moderation_en;
936 tu_table->valid_lower_boundary_link = tu->valid_lower_boundary_link;
937 tu_table->upper_boundary_count = tu->upper_boundary_count;
938 tu_table->lower_boundary_count = tu->lower_boundary_count;
939 tu_table->tu_size_minus1 = tu->tu_size_minus1;
956 kfree(tu);