From: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx> Use drm_hdmi_acr_get_n_cts() helper instead of calculating N and CTS values in the DW-HDMI driver. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx> --- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 90 +++---------------------------- 1 file changed, 8 insertions(+), 82 deletions(-) diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index 0890add5f7070f13fefad923526e92f516f06764..b8775e677233ca96c2d4a06fb5697aa3c0bd45c3 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -558,68 +558,6 @@ static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts, hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1); } -static unsigned int hdmi_compute_n(unsigned int freq, unsigned long pixel_clk) -{ - unsigned int n = (128 * freq) / 1000; - unsigned int mult = 1; - - while (freq > 48000) { - mult *= 2; - freq /= 2; - } - - switch (freq) { - case 32000: - if (pixel_clk == 25175000) - n = 4576; - else if (pixel_clk == 27027000) - n = 4096; - else if (pixel_clk == 74176000 || pixel_clk == 148352000) - n = 11648; - else if (pixel_clk == 297000000) - n = 3072; - else - n = 4096; - n *= mult; - break; - - case 44100: - if (pixel_clk == 25175000) - n = 7007; - else if (pixel_clk == 74176000) - n = 17836; - else if (pixel_clk == 148352000) - n = 8918; - else if (pixel_clk == 297000000) - n = 4704; - else - n = 6272; - n *= mult; - break; - - case 48000: - if (pixel_clk == 25175000) - n = 6864; - else if (pixel_clk == 27027000) - n = 6144; - else if (pixel_clk == 74176000) - n = 11648; - else if (pixel_clk == 148352000) - n = 5824; - else if (pixel_clk == 297000000) - n = 5120; - else - n = 6144; - n *= mult; - break; - - default: - break; - } - - return n; -} - /* * When transmitting IEC60958 linear PCM audio, these registers allow to * configure the channel status information of all the channel status @@ -646,32 +584,20 @@ static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, unsigned long ftdms = pixel_clk; unsigned int n, cts; u8 config3; - u64 tmp; - n = hdmi_compute_n(sample_rate, pixel_clk); + drm_hdmi_acr_get_n_cts(ftdms, sample_rate, &n, &cts); config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); /* Compute CTS when using internal AHB audio or General Parallel audio*/ - if ((config3 & HDMI_CONFIG3_AHBAUDDMA) || (config3 & HDMI_CONFIG3_GPAUD)) { - /* - * Compute the CTS value from the N value. Note that CTS and N - * can be up to 20 bits in total, so we need 64-bit math. Also - * note that our TDMS clock is not fully accurate; it is - * accurate to kHz. This can introduce an unnecessary remainder - * in the calculation below, so we don't try to warn about that. - */ - tmp = (u64)ftdms * n; - do_div(tmp, 128 * sample_rate); - cts = tmp; - - dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", - __func__, sample_rate, - ftdms / 1000000, (ftdms / 1000) % 1000, - n, cts); - } else { + if (!(config3 & HDMI_CONFIG3_AHBAUDDMA) && + !(config3 & HDMI_CONFIG3_GPAUD)) cts = 0; - } + + dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", + __func__, sample_rate, + ftdms / 1000000, (ftdms / 1000) % 1000, + n, cts); spin_lock_irq(&hdmi->audio_lock); hdmi->audio_n = n; -- 2.39.5