Skip to content

Commit 95db3b2

Browse files
Jyri SarhaRussell King
authored andcommitted
drm/i2c: tda998x: Improve tda998x_configure_audio() audio related pdata
Define struct tda998x_audio_params in include/drm/i2c/tda998x.h and use it in pdata and for tda998x_configure_audio() parameters. Also updates tda998x_write_aif() to take struct hdmi_audio_infoframe * directly as a parameter. Signed-off-by: Jyri Sarha <jsarha@ti.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent 3ef500a commit 95db3b2

2 files changed

Lines changed: 64 additions & 48 deletions

File tree

‎drivers/gpu/drm/i2c/tda998x_drv.c‎

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct tda998x_priv {
4141
u8 vip_cntrl_0;
4242
u8 vip_cntrl_1;
4343
u8 vip_cntrl_2;
44-
struct tda998x_encoder_params params;
44+
struct tda998x_audio_params audio_params;
4545

4646
wait_queue_head_t wq_edid;
4747
volatile int wq_edid_wait;
@@ -666,26 +666,16 @@ tda998x_write_if(struct tda998x_priv *priv, u8 bit, u16 addr,
666666
reg_set(priv, REG_DIP_IF_FLAGS, bit);
667667
}
668668

669-
static void
670-
tda998x_write_aif(struct tda998x_priv *priv, struct tda998x_encoder_params *p)
669+
static int tda998x_write_aif(struct tda998x_priv *priv,
670+
struct hdmi_audio_infoframe *cea)
671671
{
672672
union hdmi_infoframe frame;
673673

674-
hdmi_audio_infoframe_init(&frame.audio);
675-
676-
frame.audio.channels = p->audio_frame[1] & 0x07;
677-
frame.audio.channel_allocation = p->audio_frame[4];
678-
frame.audio.level_shift_value = (p->audio_frame[5] & 0x78) >> 3;
679-
frame.audio.downmix_inhibit = (p->audio_frame[5] & 0x80) >> 7;
680-
681-
/*
682-
* L-PCM and IEC61937 compressed audio shall always set sample
683-
* frequency to "refer to stream". For others, see the HDMI
684-
* specification.
685-
*/
686-
frame.audio.sample_frequency = (p->audio_frame[2] & 0x1c) >> 2;
674+
frame.audio = *cea;
687675

688676
tda998x_write_if(priv, DIP_IF_FLAGS_IF4, REG_IF4_HB0, &frame);
677+
678+
return 0;
689679
}
690680

691681
static void
@@ -710,36 +700,51 @@ static void tda998x_audio_mute(struct tda998x_priv *priv, bool on)
710700
}
711701
}
712702

713-
static void
703+
static int
714704
tda998x_configure_audio(struct tda998x_priv *priv,
715-
struct drm_display_mode *mode, struct tda998x_encoder_params *p)
705+
struct tda998x_audio_params *params,
706+
unsigned mode_clock)
716707
{
717708
u8 buf[6], clksel_aip, clksel_fs, cts_n, adiv;
718709
u32 n;
719710

720711
/* Enable audio ports */
721-
reg_write(priv, REG_ENA_AP, p->audio_cfg);
722-
reg_write(priv, REG_ENA_ACLK, p->audio_clk_cfg);
712+
reg_write(priv, REG_ENA_AP, params->config);
723713

724714
/* Set audio input source */
725-
switch (p->audio_format) {
715+
switch (params->format) {
726716
case AFMT_SPDIF:
717+
reg_write(priv, REG_ENA_ACLK, 0);
727718
reg_write(priv, REG_MUX_AP, MUX_AP_SELECT_SPDIF);
728719
clksel_aip = AIP_CLKSEL_AIP_SPDIF;
729720
clksel_fs = AIP_CLKSEL_FS_FS64SPDIF;
730721
cts_n = CTS_N_M(3) | CTS_N_K(3);
731722
break;
732723

733724
case AFMT_I2S:
725+
reg_write(priv, REG_ENA_ACLK, 1);
734726
reg_write(priv, REG_MUX_AP, MUX_AP_SELECT_I2S);
735727
clksel_aip = AIP_CLKSEL_AIP_I2S;
736728
clksel_fs = AIP_CLKSEL_FS_ACLK;
737-
cts_n = CTS_N_M(3) | CTS_N_K(3);
729+
switch (params->sample_width) {
730+
case 16:
731+
cts_n = CTS_N_M(3) | CTS_N_K(1);
732+
break;
733+
case 18:
734+
case 20:
735+
case 24:
736+
cts_n = CTS_N_M(3) | CTS_N_K(2);
737+
break;
738+
default:
739+
case 32:
740+
cts_n = CTS_N_M(3) | CTS_N_K(3);
741+
break;
742+
}
738743
break;
739744

740745
default:
741746
BUG();
742-
return;
747+
return -EINVAL;
743748
}
744749

745750
reg_write(priv, REG_AIP_CLKSEL, clksel_aip);
@@ -755,11 +760,11 @@ tda998x_configure_audio(struct tda998x_priv *priv,
755760
* assume 100MHz requires larger divider.
756761
*/
757762
adiv = AUDIO_DIV_SERCLK_8;
758-
if (mode->clock > 100000)
763+
if (mode_clock > 100000)
759764
adiv++; /* AUDIO_DIV_SERCLK_16 */
760765

761766
/* S/PDIF asks for a larger divider */
762-
if (p->audio_format == AFMT_SPDIF)
767+
if (params->format == AFMT_SPDIF)
763768
adiv++; /* AUDIO_DIV_SERCLK_16 or _32 */
764769

765770
reg_write(priv, REG_AUDIO_DIV, adiv);
@@ -768,7 +773,7 @@ tda998x_configure_audio(struct tda998x_priv *priv,
768773
* This is the approximate value of N, which happens to be
769774
* the recommended values for non-coherent clocks.
770775
*/
771-
n = 128 * p->audio_sample_rate / 1000;
776+
n = 128 * params->sample_rate / 1000;
772777

773778
/* Write the CTS and N values */
774779
buf[0] = 0x44;
@@ -786,20 +791,21 @@ tda998x_configure_audio(struct tda998x_priv *priv,
786791
reg_set(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS);
787792
reg_clear(priv, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS);
788793

789-
/* Write the channel status */
790-
buf[0] = IEC958_AES0_CON_NOT_COPYRIGHT;
791-
buf[1] = 0x00;
792-
buf[2] = IEC958_AES3_CON_FS_NOTID;
793-
buf[3] = IEC958_AES4_CON_ORIGFS_NOTID |
794-
IEC958_AES4_CON_MAX_WORDLEN_24;
794+
/* Write the channel status
795+
* The REG_CH_STAT_B-registers skip IEC958 AES2 byte, because
796+
* there is a separate register for each I2S wire.
797+
*/
798+
buf[0] = params->status[0];
799+
buf[1] = params->status[1];
800+
buf[2] = params->status[3];
801+
buf[3] = params->status[4];
795802
reg_write_range(priv, REG_CH_STAT_B(0), buf, 4);
796803

797804
tda998x_audio_mute(priv, true);
798805
msleep(20);
799806
tda998x_audio_mute(priv, false);
800807

801-
/* Write the audio information packet */
802-
tda998x_write_aif(priv, p);
808+
return tda998x_write_aif(priv, &params->cea);
803809
}
804810

805811
/* DRM encoder functions */
@@ -820,7 +826,7 @@ static void tda998x_encoder_set_config(struct tda998x_priv *priv,
820826
VIP_CNTRL_2_SWAP_F(p->swap_f) |
821827
(p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0);
822828

823-
priv->params = *p;
829+
priv->audio_params = p->audio_params;
824830
}
825831

826832
static void tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)
@@ -1057,9 +1063,11 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
10571063

10581064
tda998x_write_avi(priv, adjusted_mode);
10591065

1060-
if (priv->params.audio_cfg)
1061-
tda998x_configure_audio(priv, adjusted_mode,
1062-
&priv->params);
1066+
if (priv->audio_params.format != AFMT_UNUSED) {
1067+
tda998x_configure_audio(priv,
1068+
&priv->audio_params,
1069+
adjusted_mode->clock);
1070+
}
10631071
}
10641072
}
10651073

‎include/drm/i2c/tda998x.h‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#ifndef __DRM_I2C_TDA998X_H__
22
#define __DRM_I2C_TDA998X_H__
33

4+
#include <linux/hdmi.h>
5+
6+
enum {
7+
AFMT_UNUSED = 0,
8+
AFMT_SPDIF = 1,
9+
AFMT_I2S = 2,
10+
};
11+
12+
struct tda998x_audio_params {
13+
u8 config;
14+
u8 format;
15+
unsigned sample_width;
16+
unsigned sample_rate;
17+
struct hdmi_audio_infoframe cea;
18+
u8 status[5];
19+
};
20+
421
struct tda998x_encoder_params {
522
u8 swap_b:3;
623
u8 mirr_b:1;
@@ -15,16 +32,7 @@ struct tda998x_encoder_params {
1532
u8 swap_e:3;
1633
u8 mirr_e:1;
1734

18-
u8 audio_cfg;
19-
u8 audio_clk_cfg;
20-
u8 audio_frame[6];
21-
22-
enum {
23-
AFMT_SPDIF,
24-
AFMT_I2S
25-
} audio_format;
26-
27-
unsigned audio_sample_rate;
35+
struct tda998x_audio_params audio_params;
2836
};
2937

3038
#endif

0 commit comments

Comments
 (0)