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

drm/amd/display: Refactor to remove diags specific rgam func

[Why]
It has duplicate code for building regamma curve

[How]
Remove the duplicate code and use the same function for building regamma

Signed-off-by: Anthony Koo <Anthony.Koo@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Reviewed-by: Krunoslav Kovac <Krunoslav.Kovac@amd.com>
Acked-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Anthony Koo and committed by
Alex Deucher
887ff121 819d4b3f

+129 -182
+129 -178
drivers/gpu/drm/amd/display/modules/color/color_gamma.c
··· 1673 1673 1674 1674 #define _EXTRA_POINTS 3 1675 1675 1676 - bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf, 1677 - const struct dc_gamma *ramp, bool mapUserRamp, bool canRomBeUsed, 1678 - const struct freesync_hdr_tf_params *fs_params) 1679 - { 1680 - struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts; 1681 - struct dividers dividers; 1682 - 1683 - struct pwl_float_data *rgb_user = NULL; 1684 - struct pwl_float_data_ex *rgb_regamma = NULL; 1685 - struct gamma_pixel *axis_x = NULL; 1686 - struct pixel_gamma_point *coeff = NULL; 1687 - enum dc_transfer_func_predefined tf = TRANSFER_FUNCTION_SRGB; 1688 - bool ret = false; 1689 - 1690 - if (output_tf->type == TF_TYPE_BYPASS) 1691 - return false; 1692 - 1693 - /* we can use hardcoded curve for plain SRGB TF */ 1694 - if (output_tf->type == TF_TYPE_PREDEFINED && canRomBeUsed == true && 1695 - output_tf->tf == TRANSFER_FUNCTION_SRGB) { 1696 - if (ramp == NULL) 1697 - return true; 1698 - if ((ramp->is_identity && ramp->type != GAMMA_CS_TFM_1D) || 1699 - (!mapUserRamp && ramp->type == GAMMA_RGB_256)) 1700 - return true; 1701 - } 1702 - 1703 - output_tf->type = TF_TYPE_DISTRIBUTED_POINTS; 1704 - 1705 - if (ramp && ramp->type != GAMMA_CS_TFM_1D && 1706 - (mapUserRamp || ramp->type != GAMMA_RGB_256)) { 1707 - rgb_user = kvcalloc(ramp->num_entries + _EXTRA_POINTS, 1708 - sizeof(*rgb_user), 1709 - GFP_KERNEL); 1710 - if (!rgb_user) 1711 - goto rgb_user_alloc_fail; 1712 - 1713 - axis_x = kvcalloc(ramp->num_entries + 3, sizeof(*axis_x), 1714 - GFP_KERNEL); 1715 - if (!axis_x) 1716 - goto axis_x_alloc_fail; 1717 - 1718 - dividers.divider1 = dc_fixpt_from_fraction(3, 2); 1719 - dividers.divider2 = dc_fixpt_from_int(2); 1720 - dividers.divider3 = dc_fixpt_from_fraction(5, 2); 1721 - 1722 - build_evenly_distributed_points( 1723 - axis_x, 1724 - ramp->num_entries, 1725 - dividers); 1726 - 1727 - if (ramp->type == GAMMA_RGB_256 && mapUserRamp) 1728 - scale_gamma(rgb_user, ramp, dividers); 1729 - else if (ramp->type == GAMMA_RGB_FLOAT_1024) 1730 - scale_gamma_dx(rgb_user, ramp, dividers); 1731 - } 1732 - 1733 - rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 1734 - sizeof(*rgb_regamma), 1735 - GFP_KERNEL); 1736 - if (!rgb_regamma) 1737 - goto rgb_regamma_alloc_fail; 1738 - 1739 - coeff = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, sizeof(*coeff), 1740 - GFP_KERNEL); 1741 - if (!coeff) 1742 - goto coeff_alloc_fail; 1743 - 1744 - tf = output_tf->tf; 1745 - if (tf == TRANSFER_FUNCTION_PQ) { 1746 - tf_pts->end_exponent = 7; 1747 - tf_pts->x_point_at_y1_red = 125; 1748 - tf_pts->x_point_at_y1_green = 125; 1749 - tf_pts->x_point_at_y1_blue = 125; 1750 - 1751 - build_pq(rgb_regamma, 1752 - MAX_HW_POINTS, 1753 - coordinates_x, 1754 - output_tf->sdr_ref_white_level); 1755 - } else if (tf == TRANSFER_FUNCTION_GAMMA22 && 1756 - fs_params != NULL && fs_params->skip_tm == 0) { 1757 - build_freesync_hdr(rgb_regamma, 1758 - MAX_HW_POINTS, 1759 - coordinates_x, 1760 - fs_params); 1761 - } else if (tf == TRANSFER_FUNCTION_HLG) { 1762 - build_freesync_hdr(rgb_regamma, 1763 - MAX_HW_POINTS, 1764 - coordinates_x, 1765 - fs_params); 1766 - 1767 - } else { 1768 - tf_pts->end_exponent = 0; 1769 - tf_pts->x_point_at_y1_red = 1; 1770 - tf_pts->x_point_at_y1_green = 1; 1771 - tf_pts->x_point_at_y1_blue = 1; 1772 - 1773 - build_regamma(rgb_regamma, 1774 - MAX_HW_POINTS, 1775 - coordinates_x, tf); 1776 - } 1777 - map_regamma_hw_to_x_user(ramp, coeff, rgb_user, 1778 - coordinates_x, axis_x, rgb_regamma, 1779 - MAX_HW_POINTS, tf_pts, 1780 - (mapUserRamp || (ramp && ramp->type != GAMMA_RGB_256)) && 1781 - (ramp && ramp->type != GAMMA_CS_TFM_1D)); 1782 - 1783 - if (ramp && ramp->type == GAMMA_CS_TFM_1D) 1784 - apply_lut_1d(ramp, MAX_HW_POINTS, tf_pts); 1785 - 1786 - ret = true; 1787 - 1788 - kvfree(coeff); 1789 - coeff_alloc_fail: 1790 - kvfree(rgb_regamma); 1791 - rgb_regamma_alloc_fail: 1792 - kvfree(axis_x); 1793 - axis_x_alloc_fail: 1794 - kvfree(rgb_user); 1795 - rgb_user_alloc_fail: 1796 - return ret; 1797 - } 1798 - 1799 1676 bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf, 1800 1677 const struct regamma_lut *regamma) 1801 1678 { ··· 1920 2043 return ret; 1921 2044 } 1922 2045 1923 - 1924 - bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans, 2046 + static bool calculate_curve(enum dc_transfer_func_predefined trans, 1925 2047 struct dc_transfer_func_distributed_points *points, 2048 + struct pwl_float_data_ex *rgb_regamma, 2049 + const struct freesync_hdr_tf_params *fs_params, 1926 2050 uint32_t sdr_ref_white_level) 1927 2051 { 1928 2052 uint32_t i; 1929 2053 bool ret = false; 1930 - struct pwl_float_data_ex *rgb_regamma = NULL; 1931 2054 1932 2055 if (trans == TRANSFER_FUNCTION_UNITY || 1933 2056 trans == TRANSFER_FUNCTION_LINEAR) { ··· 1937 2060 points->x_point_at_y1_blue = 1; 1938 2061 1939 2062 for (i = 0; i <= MAX_HW_POINTS ; i++) { 1940 - points->red[i] = coordinates_x[i].x; 1941 - points->green[i] = coordinates_x[i].x; 1942 - points->blue[i] = coordinates_x[i].x; 2063 + rgb_regamma[i].r = coordinates_x[i].x; 2064 + rgb_regamma[i].g = coordinates_x[i].x; 2065 + rgb_regamma[i].b = coordinates_x[i].x; 1943 2066 } 2067 + 1944 2068 ret = true; 1945 2069 } else if (trans == TRANSFER_FUNCTION_PQ) { 1946 - rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 1947 - sizeof(*rgb_regamma), 1948 - GFP_KERNEL); 1949 - if (!rgb_regamma) 1950 - goto rgb_regamma_alloc_fail; 1951 2070 points->end_exponent = 7; 1952 2071 points->x_point_at_y1_red = 125; 1953 2072 points->x_point_at_y1_green = 125; 1954 2073 points->x_point_at_y1_blue = 125; 1955 2074 1956 - 1957 2075 build_pq(rgb_regamma, 1958 2076 MAX_HW_POINTS, 1959 2077 coordinates_x, 1960 2078 sdr_ref_white_level); 1961 - for (i = 0; i <= MAX_HW_POINTS ; i++) { 1962 - points->red[i] = rgb_regamma[i].r; 1963 - points->green[i] = rgb_regamma[i].g; 1964 - points->blue[i] = rgb_regamma[i].b; 1965 - } 2079 + 1966 2080 ret = true; 1967 - 1968 - kvfree(rgb_regamma); 1969 - } else if (trans == TRANSFER_FUNCTION_SRGB || 1970 - trans == TRANSFER_FUNCTION_BT709 || 1971 - trans == TRANSFER_FUNCTION_GAMMA22 || 1972 - trans == TRANSFER_FUNCTION_GAMMA24 || 1973 - trans == TRANSFER_FUNCTION_GAMMA26) { 1974 - rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 1975 - sizeof(*rgb_regamma), 1976 - GFP_KERNEL); 1977 - if (!rgb_regamma) 1978 - goto rgb_regamma_alloc_fail; 1979 - points->end_exponent = 0; 1980 - points->x_point_at_y1_red = 1; 1981 - points->x_point_at_y1_green = 1; 1982 - points->x_point_at_y1_blue = 1; 1983 - 1984 - build_regamma(rgb_regamma, 2081 + } else if (trans == TRANSFER_FUNCTION_GAMMA22 && 2082 + fs_params != NULL && fs_params->skip_tm == 0) { 2083 + build_freesync_hdr(rgb_regamma, 1985 2084 MAX_HW_POINTS, 1986 2085 coordinates_x, 1987 - trans); 1988 - for (i = 0; i <= MAX_HW_POINTS ; i++) { 1989 - points->red[i] = rgb_regamma[i].r; 1990 - points->green[i] = rgb_regamma[i].g; 1991 - points->blue[i] = rgb_regamma[i].b; 1992 - } 1993 - ret = true; 2086 + fs_params); 1994 2087 1995 - kvfree(rgb_regamma); 2088 + ret = true; 1996 2089 } else if (trans == TRANSFER_FUNCTION_HLG) { 1997 - rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 1998 - sizeof(*rgb_regamma), 1999 - GFP_KERNEL); 2000 - if (!rgb_regamma) 2001 - goto rgb_regamma_alloc_fail; 2002 2090 points->end_exponent = 4; 2003 2091 points->x_point_at_y1_red = 12; 2004 2092 points->x_point_at_y1_green = 12; ··· 1973 2131 MAX_HW_POINTS, 1974 2132 coordinates_x, 1975 2133 80, 1000); 1976 - for (i = 0; i <= MAX_HW_POINTS ; i++) { 1977 - points->red[i] = rgb_regamma[i].r; 1978 - points->green[i] = rgb_regamma[i].g; 1979 - points->blue[i] = rgb_regamma[i].b; 1980 - } 2134 + 1981 2135 ret = true; 1982 - kvfree(rgb_regamma); 2136 + } else { 2137 + // trans == TRANSFER_FUNCTION_SRGB 2138 + // trans == TRANSFER_FUNCTION_BT709 2139 + // trans == TRANSFER_FUNCTION_GAMMA22 2140 + // trans == TRANSFER_FUNCTION_GAMMA24 2141 + // trans == TRANSFER_FUNCTION_GAMMA26 2142 + points->end_exponent = 0; 2143 + points->x_point_at_y1_red = 1; 2144 + points->x_point_at_y1_green = 1; 2145 + points->x_point_at_y1_blue = 1; 2146 + 2147 + build_regamma(rgb_regamma, 2148 + MAX_HW_POINTS, 2149 + coordinates_x, 2150 + trans); 2151 + 2152 + ret = true; 1983 2153 } 1984 - rgb_regamma_alloc_fail: 2154 + 1985 2155 return ret; 1986 2156 } 1987 2157 2158 + bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf, 2159 + const struct dc_gamma *ramp, bool mapUserRamp, bool canRomBeUsed, 2160 + const struct freesync_hdr_tf_params *fs_params) 2161 + { 2162 + struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts; 2163 + struct dividers dividers; 2164 + 2165 + struct pwl_float_data *rgb_user = NULL; 2166 + struct pwl_float_data_ex *rgb_regamma = NULL; 2167 + struct gamma_pixel *axis_x = NULL; 2168 + struct pixel_gamma_point *coeff = NULL; 2169 + enum dc_transfer_func_predefined tf = TRANSFER_FUNCTION_SRGB; 2170 + bool ret = false; 2171 + 2172 + if (output_tf->type == TF_TYPE_BYPASS) 2173 + return false; 2174 + 2175 + /* we can use hardcoded curve for plain SRGB TF */ 2176 + if (output_tf->type == TF_TYPE_PREDEFINED && canRomBeUsed == true && 2177 + output_tf->tf == TRANSFER_FUNCTION_SRGB) { 2178 + if (ramp == NULL) 2179 + return true; 2180 + if ((ramp->is_identity && ramp->type != GAMMA_CS_TFM_1D) || 2181 + (!mapUserRamp && ramp->type == GAMMA_RGB_256)) 2182 + return true; 2183 + } 2184 + 2185 + output_tf->type = TF_TYPE_DISTRIBUTED_POINTS; 2186 + 2187 + if (ramp && ramp->type != GAMMA_CS_TFM_1D && 2188 + (mapUserRamp || ramp->type != GAMMA_RGB_256)) { 2189 + rgb_user = kvcalloc(ramp->num_entries + _EXTRA_POINTS, 2190 + sizeof(*rgb_user), 2191 + GFP_KERNEL); 2192 + if (!rgb_user) 2193 + goto rgb_user_alloc_fail; 2194 + 2195 + axis_x = kvcalloc(ramp->num_entries + 3, sizeof(*axis_x), 2196 + GFP_KERNEL); 2197 + if (!axis_x) 2198 + goto axis_x_alloc_fail; 2199 + 2200 + dividers.divider1 = dc_fixpt_from_fraction(3, 2); 2201 + dividers.divider2 = dc_fixpt_from_int(2); 2202 + dividers.divider3 = dc_fixpt_from_fraction(5, 2); 2203 + 2204 + build_evenly_distributed_points( 2205 + axis_x, 2206 + ramp->num_entries, 2207 + dividers); 2208 + 2209 + if (ramp->type == GAMMA_RGB_256 && mapUserRamp) 2210 + scale_gamma(rgb_user, ramp, dividers); 2211 + else if (ramp->type == GAMMA_RGB_FLOAT_1024) 2212 + scale_gamma_dx(rgb_user, ramp, dividers); 2213 + } 2214 + 2215 + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, 2216 + sizeof(*rgb_regamma), 2217 + GFP_KERNEL); 2218 + if (!rgb_regamma) 2219 + goto rgb_regamma_alloc_fail; 2220 + 2221 + coeff = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS, sizeof(*coeff), 2222 + GFP_KERNEL); 2223 + if (!coeff) 2224 + goto coeff_alloc_fail; 2225 + 2226 + tf = output_tf->tf; 2227 + 2228 + ret = calculate_curve(tf, 2229 + tf_pts, 2230 + rgb_regamma, 2231 + fs_params, 2232 + output_tf->sdr_ref_white_level); 2233 + 2234 + if (ret) { 2235 + map_regamma_hw_to_x_user(ramp, coeff, rgb_user, 2236 + coordinates_x, axis_x, rgb_regamma, 2237 + MAX_HW_POINTS, tf_pts, 2238 + (mapUserRamp || (ramp && ramp->type != GAMMA_RGB_256)) && 2239 + (ramp && ramp->type != GAMMA_CS_TFM_1D)); 2240 + 2241 + if (ramp && ramp->type == GAMMA_CS_TFM_1D) 2242 + apply_lut_1d(ramp, MAX_HW_POINTS, tf_pts); 2243 + } 2244 + 2245 + kvfree(coeff); 2246 + coeff_alloc_fail: 2247 + kvfree(rgb_regamma); 2248 + rgb_regamma_alloc_fail: 2249 + kvfree(axis_x); 2250 + axis_x_alloc_fail: 2251 + kvfree(rgb_user); 2252 + rgb_user_alloc_fail: 2253 + return ret; 2254 + } 1988 2255 1989 2256 bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans, 1990 2257 struct dc_transfer_func_distributed_points *points)
-4
drivers/gpu/drm/amd/display/modules/color/color_gamma.h
··· 103 103 bool mod_color_calculate_degamma_params(struct dc_transfer_func *output_tf, 104 104 const struct dc_gamma *ramp, bool mapUserRamp); 105 105 106 - bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans, 107 - struct dc_transfer_func_distributed_points *points, 108 - uint32_t sdr_ref_white_level); 109 - 110 106 bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans, 111 107 struct dc_transfer_func_distributed_points *points); 112 108