Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amd/display: Remove unused regamma functions

calculate_user_regamma_coeff() and calculate_user_regamma_ramp() were
added in 2018 in commit
55a01d4023ce ("drm/amd/display: Add user_regamma to color module")

but never used.

Remove them and their helpers.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Dr. David Alan Gilbert and committed by
Alex Deucher
370e8fdb 8fe7cf58

-318
-307
drivers/gpu/drm/amd/display/modules/color/color_gamma.c
··· 1399 1399 pwl_rgb[i-1].b, 2), pwl_rgb[i-2].b); 1400 1400 } 1401 1401 1402 - /* todo: all these scale_gamma functions are inherently the same but 1403 - * take different structures as params or different format for ramp 1404 - * values. We could probably implement it in a more generic fashion 1405 - */ 1406 - static void scale_user_regamma_ramp(struct pwl_float_data *pwl_rgb, 1407 - const struct regamma_ramp *ramp, 1408 - struct dividers dividers) 1409 - { 1410 - unsigned short max_driver = 0xFFFF; 1411 - unsigned short max_os = 0xFF00; 1412 - unsigned short scaler = max_os; 1413 - uint32_t i; 1414 - struct pwl_float_data *rgb = pwl_rgb; 1415 - struct pwl_float_data *rgb_last = rgb + GAMMA_RGB_256_ENTRIES - 1; 1416 - 1417 - i = 0; 1418 - do { 1419 - if (ramp->gamma[i] > max_os || 1420 - ramp->gamma[i + 256] > max_os || 1421 - ramp->gamma[i + 512] > max_os) { 1422 - scaler = max_driver; 1423 - break; 1424 - } 1425 - i++; 1426 - } while (i != GAMMA_RGB_256_ENTRIES); 1427 - 1428 - i = 0; 1429 - do { 1430 - rgb->r = dc_fixpt_from_fraction( 1431 - ramp->gamma[i], scaler); 1432 - rgb->g = dc_fixpt_from_fraction( 1433 - ramp->gamma[i + 256], scaler); 1434 - rgb->b = dc_fixpt_from_fraction( 1435 - ramp->gamma[i + 512], scaler); 1436 - 1437 - ++rgb; 1438 - ++i; 1439 - } while (i != GAMMA_RGB_256_ENTRIES); 1440 - 1441 - rgb->r = dc_fixpt_mul(rgb_last->r, 1442 - dividers.divider1); 1443 - rgb->g = dc_fixpt_mul(rgb_last->g, 1444 - dividers.divider1); 1445 - rgb->b = dc_fixpt_mul(rgb_last->b, 1446 - dividers.divider1); 1447 - 1448 - ++rgb; 1449 - 1450 - rgb->r = dc_fixpt_mul(rgb_last->r, 1451 - dividers.divider2); 1452 - rgb->g = dc_fixpt_mul(rgb_last->g, 1453 - dividers.divider2); 1454 - rgb->b = dc_fixpt_mul(rgb_last->b, 1455 - dividers.divider2); 1456 - 1457 - ++rgb; 1458 - 1459 - rgb->r = dc_fixpt_mul(rgb_last->r, 1460 - dividers.divider3); 1461 - rgb->g = dc_fixpt_mul(rgb_last->g, 1462 - dividers.divider3); 1463 - rgb->b = dc_fixpt_mul(rgb_last->b, 1464 - dividers.divider3); 1465 - } 1466 - 1467 1402 /* 1468 1403 * RS3+ color transform DDI - 1D LUT adjustment is composed with regamma here 1469 1404 * Input is evenly distributed in the output color space as specified in ··· 1598 1663 return true; 1599 1664 } 1600 1665 1601 - /* The "old" interpolation uses a complicated scheme to build an array of 1602 - * coefficients while also using an array of 0-255 normalized to 0-1 1603 - * Then there's another loop using both of the above + new scaled user ramp 1604 - * and we concatenate them. It also searches for points of interpolation and 1605 - * uses enums for positions. 1606 - * 1607 - * This function uses a different approach: 1608 - * user ramp is always applied on X with 0/255, 1/255, 2/255, ..., 255/255 1609 - * To find index for hwX , we notice the following: 1610 - * i/255 <= hwX < (i+1)/255 <=> i <= 255*hwX < i+1 1611 - * See apply_lut_1d which is the same principle, but on 4K entry 1D LUT 1612 - * 1613 - * Once the index is known, combined Y is simply: 1614 - * user_ramp(index) + (hwX-index/255)*(user_ramp(index+1) - user_ramp(index) 1615 - * 1616 - * We should switch to this method in all cases, it's simpler and faster 1617 - * ToDo one day - for now this only applies to ADL regamma to avoid regression 1618 - * for regular use cases (sRGB and PQ) 1619 - */ 1620 - static void interpolate_user_regamma(uint32_t hw_points_num, 1621 - struct pwl_float_data *rgb_user, 1622 - bool apply_degamma, 1623 - struct dc_transfer_func_distributed_points *tf_pts) 1624 - { 1625 - uint32_t i; 1626 - uint32_t color = 0; 1627 - int32_t index; 1628 - int32_t index_next; 1629 - struct fixed31_32 *tf_point; 1630 - struct fixed31_32 hw_x; 1631 - struct fixed31_32 norm_factor = 1632 - dc_fixpt_from_int(255); 1633 - struct fixed31_32 norm_x; 1634 - struct fixed31_32 index_f; 1635 - struct fixed31_32 lut1; 1636 - struct fixed31_32 lut2; 1637 - struct fixed31_32 delta_lut; 1638 - struct fixed31_32 delta_index; 1639 - const struct fixed31_32 one = dc_fixpt_from_int(1); 1640 - 1641 - i = 0; 1642 - /* fixed_pt library has problems handling too small values */ 1643 - while (i != 32) { 1644 - tf_pts->red[i] = dc_fixpt_zero; 1645 - tf_pts->green[i] = dc_fixpt_zero; 1646 - tf_pts->blue[i] = dc_fixpt_zero; 1647 - ++i; 1648 - } 1649 - while (i <= hw_points_num + 1) { 1650 - for (color = 0; color < 3; color++) { 1651 - if (color == 0) 1652 - tf_point = &tf_pts->red[i]; 1653 - else if (color == 1) 1654 - tf_point = &tf_pts->green[i]; 1655 - else 1656 - tf_point = &tf_pts->blue[i]; 1657 - 1658 - if (apply_degamma) { 1659 - if (color == 0) 1660 - hw_x = coordinates_x[i].regamma_y_red; 1661 - else if (color == 1) 1662 - hw_x = coordinates_x[i].regamma_y_green; 1663 - else 1664 - hw_x = coordinates_x[i].regamma_y_blue; 1665 - } else 1666 - hw_x = coordinates_x[i].x; 1667 - 1668 - if (dc_fixpt_le(one, hw_x)) 1669 - hw_x = one; 1670 - 1671 - norm_x = dc_fixpt_mul(norm_factor, hw_x); 1672 - index = dc_fixpt_floor(norm_x); 1673 - if (index < 0 || index > 255) 1674 - continue; 1675 - 1676 - index_f = dc_fixpt_from_int(index); 1677 - index_next = (index == 255) ? index : index + 1; 1678 - 1679 - if (color == 0) { 1680 - lut1 = rgb_user[index].r; 1681 - lut2 = rgb_user[index_next].r; 1682 - } else if (color == 1) { 1683 - lut1 = rgb_user[index].g; 1684 - lut2 = rgb_user[index_next].g; 1685 - } else { 1686 - lut1 = rgb_user[index].b; 1687 - lut2 = rgb_user[index_next].b; 1688 - } 1689 - 1690 - // we have everything now, so interpolate 1691 - delta_lut = dc_fixpt_sub(lut2, lut1); 1692 - delta_index = dc_fixpt_sub(norm_x, index_f); 1693 - 1694 - *tf_point = dc_fixpt_add(lut1, 1695 - dc_fixpt_mul(delta_index, delta_lut)); 1696 - } 1697 - ++i; 1698 - } 1699 - } 1700 - 1701 1666 static void build_new_custom_resulted_curve( 1702 1667 uint32_t hw_points_num, 1703 1668 struct dc_transfer_func_distributed_points *tf_pts) ··· 1615 1780 tf_pts->blue[i], dc_fixpt_zero, 1616 1781 dc_fixpt_one); 1617 1782 1618 - ++i; 1619 - } 1620 - } 1621 - 1622 - static void apply_degamma_for_user_regamma(struct pwl_float_data_ex *rgb_regamma, 1623 - uint32_t hw_points_num, struct calculate_buffer *cal_buffer) 1624 - { 1625 - uint32_t i; 1626 - 1627 - struct gamma_coefficients coeff; 1628 - struct pwl_float_data_ex *rgb = rgb_regamma; 1629 - const struct hw_x_point *coord_x = coordinates_x; 1630 - 1631 - build_coefficients(&coeff, TRANSFER_FUNCTION_SRGB); 1632 - 1633 - i = 0; 1634 - while (i != hw_points_num + 1) { 1635 - rgb->r = translate_from_linear_space_ex( 1636 - coord_x->x, &coeff, 0, cal_buffer); 1637 - rgb->g = rgb->r; 1638 - rgb->b = rgb->r; 1639 - ++coord_x; 1640 - ++rgb; 1641 1783 ++i; 1642 1784 } 1643 1785 } ··· 1666 1854 } 1667 1855 1668 1856 #define _EXTRA_POINTS 3 1669 - 1670 - bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf, 1671 - const struct regamma_lut *regamma, 1672 - struct calculate_buffer *cal_buffer, 1673 - const struct dc_gamma *ramp) 1674 - { 1675 - struct gamma_coefficients coeff; 1676 - const struct hw_x_point *coord_x = coordinates_x; 1677 - uint32_t i = 0; 1678 - 1679 - do { 1680 - coeff.a0[i] = dc_fixpt_from_fraction( 1681 - regamma->coeff.A0[i], 10000000); 1682 - coeff.a1[i] = dc_fixpt_from_fraction( 1683 - regamma->coeff.A1[i], 1000); 1684 - coeff.a2[i] = dc_fixpt_from_fraction( 1685 - regamma->coeff.A2[i], 1000); 1686 - coeff.a3[i] = dc_fixpt_from_fraction( 1687 - regamma->coeff.A3[i], 1000); 1688 - coeff.user_gamma[i] = dc_fixpt_from_fraction( 1689 - regamma->coeff.gamma[i], 1000); 1690 - 1691 - ++i; 1692 - } while (i != 3); 1693 - 1694 - i = 0; 1695 - /* fixed_pt library has problems handling too small values */ 1696 - while (i != 32) { 1697 - output_tf->tf_pts.red[i] = dc_fixpt_zero; 1698 - output_tf->tf_pts.green[i] = dc_fixpt_zero; 1699 - output_tf->tf_pts.blue[i] = dc_fixpt_zero; 1700 - ++coord_x; 1701 - ++i; 1702 - } 1703 - while (i != MAX_HW_POINTS + 1) { 1704 - output_tf->tf_pts.red[i] = translate_from_linear_space_ex( 1705 - coord_x->x, &coeff, 0, cal_buffer); 1706 - output_tf->tf_pts.green[i] = translate_from_linear_space_ex( 1707 - coord_x->x, &coeff, 1, cal_buffer); 1708 - output_tf->tf_pts.blue[i] = translate_from_linear_space_ex( 1709 - coord_x->x, &coeff, 2, cal_buffer); 1710 - ++coord_x; 1711 - ++i; 1712 - } 1713 - 1714 - if (ramp && ramp->type == GAMMA_CS_TFM_1D) 1715 - apply_lut_1d(ramp, MAX_HW_POINTS, &output_tf->tf_pts); 1716 - 1717 - // this function just clamps output to 0-1 1718 - build_new_custom_resulted_curve(MAX_HW_POINTS, &output_tf->tf_pts); 1719 - output_tf->type = TF_TYPE_DISTRIBUTED_POINTS; 1720 - 1721 - return true; 1722 - } 1723 - 1724 - bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf, 1725 - const struct regamma_lut *regamma, 1726 - struct calculate_buffer *cal_buffer, 1727 - const struct dc_gamma *ramp) 1728 - { 1729 - struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts; 1730 - struct dividers dividers; 1731 - 1732 - struct pwl_float_data *rgb_user = NULL; 1733 - struct pwl_float_data_ex *rgb_regamma = NULL; 1734 - bool ret = false; 1735 - 1736 - if (regamma == NULL) 1737 - return false; 1738 - 1739 - output_tf->type = TF_TYPE_DISTRIBUTED_POINTS; 1740 - 1741 - rgb_user = kcalloc(GAMMA_RGB_256_ENTRIES + _EXTRA_POINTS, 1742 - sizeof(*rgb_user), 1743 - GFP_KERNEL); 1744 - if (!rgb_user) 1745 - goto rgb_user_alloc_fail; 1746 - 1747 - rgb_regamma = kcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 1748 - sizeof(*rgb_regamma), 1749 - GFP_KERNEL); 1750 - if (!rgb_regamma) 1751 - goto rgb_regamma_alloc_fail; 1752 - 1753 - dividers.divider1 = dc_fixpt_from_fraction(3, 2); 1754 - dividers.divider2 = dc_fixpt_from_int(2); 1755 - dividers.divider3 = dc_fixpt_from_fraction(5, 2); 1756 - 1757 - scale_user_regamma_ramp(rgb_user, &regamma->ramp, dividers); 1758 - 1759 - if (regamma->flags.bits.applyDegamma == 1) { 1760 - apply_degamma_for_user_regamma(rgb_regamma, MAX_HW_POINTS, cal_buffer); 1761 - copy_rgb_regamma_to_coordinates_x(coordinates_x, 1762 - MAX_HW_POINTS, rgb_regamma); 1763 - } 1764 - 1765 - interpolate_user_regamma(MAX_HW_POINTS, rgb_user, 1766 - regamma->flags.bits.applyDegamma, tf_pts); 1767 - 1768 - // no custom HDR curves! 1769 - tf_pts->end_exponent = 0; 1770 - tf_pts->x_point_at_y1_red = 1; 1771 - tf_pts->x_point_at_y1_green = 1; 1772 - tf_pts->x_point_at_y1_blue = 1; 1773 - 1774 - if (ramp && ramp->type == GAMMA_CS_TFM_1D) 1775 - apply_lut_1d(ramp, MAX_HW_POINTS, &output_tf->tf_pts); 1776 - 1777 - // this function just clamps output to 0-1 1778 - build_new_custom_resulted_curve(MAX_HW_POINTS, tf_pts); 1779 - 1780 - ret = true; 1781 - 1782 - kfree(rgb_regamma); 1783 - rgb_regamma_alloc_fail: 1784 - kfree(rgb_user); 1785 - rgb_user_alloc_fail: 1786 - return ret; 1787 - } 1788 1857 1789 1858 bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps, 1790 1859 struct dc_transfer_func *input_tf,
-11
drivers/gpu/drm/amd/display/modules/color/color_gamma.h
··· 115 115 struct dc_transfer_func *output_tf, 116 116 const struct dc_gamma *ramp, bool mapUserRamp); 117 117 118 - bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf, 119 - const struct regamma_lut *regamma, 120 - struct calculate_buffer *cal_buffer, 121 - const struct dc_gamma *ramp); 122 - 123 - bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf, 124 - const struct regamma_lut *regamma, 125 - struct calculate_buffer *cal_buffer, 126 - const struct dc_gamma *ramp); 127 - 128 - 129 118 #endif /* COLOR_MOD_COLOR_GAMMA_H_ */