From patchwork Wed Oct 23 07:42:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 285541 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EECB02C019B for ; Wed, 23 Oct 2013 19:10:46 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VYt5T-0003Lp-TY; Wed, 23 Oct 2013 07:42:40 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VYt4t-0006UV-Qs; Wed, 23 Oct 2013 07:42:03 +0000 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VYt4p-0006Sk-5m for linux-arm-kernel@lists.infradead.org; Wed, 23 Oct 2013 07:42:00 +0000 Received: from armhf (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp4-g21.free.fr (Postfix) with ESMTP id EC9964C8243; Wed, 23 Oct 2013 09:41:28 +0200 (CEST) Date: Wed, 23 Oct 2013 09:42:04 +0200 From: Jean-Francois Moine To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/10] drm/i2c: tda998x: fix some audio errors Message-ID: <20131023094204.3c92868b@armhf> X-Mailer: Claws Mail 3.9.2 (GTK+ 2.24.21; arm-unknown-linux-gnueabihf) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131023_034159_806840_F4AB5593 X-CRM114-Status: GOOD ( 18.51 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (moinejf[at]free.fr) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jason Cooper , David Airlie , Rob Clark , Darren Etheridge , Russell King , Sebastian Hesselbarth X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org This patch fixes some audio errors: - use constants - set audio FIFO read latency to 'current' - set a large audio divider which works with all input sample rates - compute a CTS from the video clock - use any frequency in the channel status Signed-off-by: Jean-Francois Moine --- drivers/gpu/drm/i2c/tda998x_drv.c | 57 ++++++++++------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index b0eecee..1887108 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c @@ -216,7 +216,12 @@ struct tda998x_priv { # define AIP_CLKSEL_FS(x) (((x) & 3) << 0) # define AIP_CLKSEL_CLK_POL(x) (((x) & 1) << 2) # define AIP_CLKSEL_AIP(x) (((x) & 7) << 3) - +#define SEL_AIP_SPDIF 0 +#define SEL_AIP_I2S 1 +#define CLKPOLDSD_ACLK 0 /* same pol as ACLK */ +#define CLKPOLDSD_NACLK 1 /* inverted */ +#define CTSREF_ACLK 0 /* I2S */ +#define CTSREF_FS64SPDIF 2 /* spdif */ /* Page 02h: PLL settings */ #define REG_PLL_SERIAL_1 REG(0x02, 0x00) /* read/write */ @@ -281,6 +286,7 @@ struct tda998x_priv { # define CA_I2S_CA_I2S(x) (((x) & 31) << 0) # define CA_I2S_HBR_CHSTAT (1 << 6) #define REG_LATENCY_RD REG(0x11, 0x04) /* read/write */ +# define LATENCY_CURRENT 0x80 #define REG_ACR_CTS_0 REG(0x11, 0x05) /* read/write */ #define REG_ACR_CTS_1 REG(0x11, 0x06) /* read/write */ #define REG_ACR_CTS_2 REG(0x11, 0x07) /* read/write */ @@ -717,8 +723,8 @@ static void tda998x_configure_audio(struct tda998x_priv *priv, struct drm_display_mode *mode, struct tda998x_encoder_params *p) { - uint8_t buf[6], clksel_aip, clksel_fs, ca_i2s, cts_n, adiv; - int aclk, n; + uint8_t buf[6], clksel_aip, clksel_fs, cts_n; + int aclk, n, cts; /* Enable audio ports */ reg_write(priv, REG_ENA_AP, priv->audio_ports); @@ -726,42 +732,29 @@ tda998x_configure_audio(struct tda998x_priv *priv, /* Set audio input source */ if (priv->audio == AUDIO_SPDIF) { reg_write(priv, REG_MUX_AP, MUX_AP_SELECT_SPDIF); - clksel_aip = AIP_CLKSEL_AIP(0); - /* FS64SPDIF */ - clksel_fs = AIP_CLKSEL_FS(2); + clksel_aip = AIP_CLKSEL_AIP(SEL_AIP_SPDIF); + clksel_fs = AIP_CLKSEL_FS(CTSREF_FS64SPDIF); aclk = 0x00; /* no clock */ cts_n = CTS_N_M(3) | CTS_N_K(3); - ca_i2s = 0; } else { reg_write(priv, REG_MUX_AP, MUX_AP_SELECT_I2S); - clksel_aip = AIP_CLKSEL_AIP(1); - /* ACLK */ - clksel_fs = AIP_CLKSEL_FS(0); + clksel_aip = AIP_CLKSEL_AIP(SEL_AIP_I2S); + clksel_fs = AIP_CLKSEL_FS(CTSREF_ACLK); aclk = 0x01; /* clock enable */ cts_n = CTS_N_M(3) | CTS_N_K(3); - ca_i2s = CA_I2S_CA_I2S(0); } reg_write(priv, REG_AIP_CLKSEL, clksel_aip); + reg_write(priv, REG_LATENCY_RD, LATENCY_CURRENT); reg_write(priv, REG_ENA_ACLK, aclk); - reg_clear(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_LAYOUT); + reg_clear(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_LAYOUT | /* Enable automatic CTS generation */ - reg_clear(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_ACR_MAN); + AIP_CNTRL_0_ACR_MAN); reg_write(priv, REG_CTS_N, cts_n); - /* - * Audio input somehow depends on HDMI line rate which is - * related to pixclk. Testing showed that modes with pixclk - * >100MHz need a larger divider while <40MHz need the default. - * There is no detailed info in the datasheet, so we just - * assume 100MHz requires larger divider. - */ - if (mode->clock > 100000) - adiv = AUDIO_DIV_SERCLK_16; - else - adiv = AUDIO_DIV_SERCLK_8; - reg_write(priv, REG_AUDIO_DIV, adiv); + /* a large divider works for all input sample rates */ + reg_write(priv, REG_AUDIO_DIV, AUDIO_DIV_SERCLK_32); /* * This is the approximate value of N, which happens to be @@ -770,9 +763,10 @@ tda998x_configure_audio(struct tda998x_priv *priv, n = 128 * AUDIO_SAMPLE; /* acr_n = 128 * sample_rate / 1000 */ /* Write the CTS and N values */ - buf[0] = 0x44; - buf[1] = 0x42; - buf[2] = 0x01; + cts = mode->clock; + buf[0] = cts; + buf[1] = cts >> 8; + buf[2] = cts >> 16; buf[3] = n; buf[4] = n >> 8; buf[5] = n >> 16; @@ -786,10 +780,11 @@ tda998x_configure_audio(struct tda998x_priv *priv, reg_clear(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS); /* Write the channel status */ - buf[0] = 0x04; + buf[0] = (1 << 2); /* copyright unprotected */ buf[1] = 0x00; - buf[2] = 0x00; - buf[3] = 0xf1; + buf[2] = 1; /* freq not indicated */ + buf[3] = (0 << 4) | /* orig freq = not indicated */ + 1; /* max word length 24 bits */ reg_write_range(priv, REG_CH_STAT_B(0), buf, 4); tda998x_audio_mute(priv, true);