Skip to content

Commit f143778

Browse files
committed
drm/vc4: hdmi: Remove redundant variables
The vc4_hdmi_audio_prepare function and the functions it's calling have in several occurences multiple dereferences of either the sample rate or the number of channels. It turns out that these variables are also passed through the hdmi codec parameters structure. Convert all the users to use this structure, and if it's used multiple times use a variable to store it instead of dereferencing it every time. Reviewed-by: Nicolas Saenz Julienne <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent d793b8f commit f143778

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

drivers/gpu/drm/vc4/vc4_hdmi.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,12 +1184,13 @@ static u32 vc5_hdmi_channel_map(struct vc4_hdmi *vc4_hdmi, u32 channel_mask)
11841184
}
11851185

11861186
/* HDMI audio codec callbacks */
1187-
static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *vc4_hdmi)
1187+
static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *vc4_hdmi,
1188+
unsigned int samplerate)
11881189
{
11891190
u32 hsm_clock = clk_get_rate(vc4_hdmi->audio_clock);
11901191
unsigned long n, m;
11911192

1192-
rational_best_approximation(hsm_clock, vc4_hdmi->audio.samplerate,
1193+
rational_best_approximation(hsm_clock, samplerate,
11931194
VC4_HD_MAI_SMP_N_MASK >>
11941195
VC4_HD_MAI_SMP_N_SHIFT,
11951196
(VC4_HD_MAI_SMP_M_MASK >>
@@ -1201,12 +1202,11 @@ static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *vc4_hdmi)
12011202
VC4_SET_FIELD(m - 1, VC4_HD_MAI_SMP_M));
12021203
}
12031204

1204-
static void vc4_hdmi_set_n_cts(struct vc4_hdmi *vc4_hdmi)
1205+
static void vc4_hdmi_set_n_cts(struct vc4_hdmi *vc4_hdmi, unsigned int samplerate)
12051206
{
12061207
struct drm_connector *connector = &vc4_hdmi->connector;
12071208
struct drm_crtc *crtc = connector->state->crtc;
12081209
const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
1209-
u32 samplerate = vc4_hdmi->audio.samplerate;
12101210
u32 n, cts;
12111211
u64 tmp;
12121212

@@ -1340,27 +1340,25 @@ static int vc4_hdmi_audio_prepare(struct device *dev, void *data,
13401340
{
13411341
struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
13421342
struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base;
1343+
unsigned int sample_rate = params->sample_rate;
1344+
unsigned int channels = params->channels;
13431345
u32 audio_packet_config, channel_mask;
13441346
u32 channel_map;
13451347
u32 mai_audio_format;
13461348
u32 mai_sample_rate;
13471349

13481350
dev_dbg(dev, "%s: %u Hz, %d bit, %d channels\n", __func__,
1349-
params->sample_rate, params->sample_width,
1350-
params->channels);
1351-
1352-
vc4_hdmi->audio.channels = params->channels;
1353-
vc4_hdmi->audio.samplerate = params->sample_rate;
1351+
sample_rate, params->sample_width, channels);
13541352

13551353
HDMI_WRITE(HDMI_MAI_CTL,
1356-
VC4_SET_FIELD(params->channels, VC4_HD_MAI_CTL_CHNUM) |
1354+
VC4_SET_FIELD(channels, VC4_HD_MAI_CTL_CHNUM) |
13571355
VC4_HD_MAI_CTL_WHOLSMP |
13581356
VC4_HD_MAI_CTL_CHALIGN |
13591357
VC4_HD_MAI_CTL_ENABLE);
13601358

1361-
vc4_hdmi_audio_set_mai_clock(vc4_hdmi);
1359+
vc4_hdmi_audio_set_mai_clock(vc4_hdmi, sample_rate);
13621360

1363-
mai_sample_rate = sample_rate_to_mai_fmt(vc4_hdmi->audio.samplerate);
1361+
mai_sample_rate = sample_rate_to_mai_fmt(sample_rate);
13641362
if (params->iec.status[0] & IEC958_AES0_NONAUDIO &&
13651363
params->channels == 8)
13661364
mai_audio_format = VC4_HDMI_MAI_FORMAT_HBR;
@@ -1378,7 +1376,7 @@ static int vc4_hdmi_audio_prepare(struct device *dev, void *data,
13781376
VC4_HDMI_AUDIO_PACKET_ZERO_DATA_ON_INACTIVE_CHANNELS |
13791377
VC4_SET_FIELD(0x8, VC4_HDMI_AUDIO_PACKET_B_FRAME_IDENTIFIER);
13801378

1381-
channel_mask = GENMASK(vc4_hdmi->audio.channels - 1, 0);
1379+
channel_mask = GENMASK(channels - 1, 0);
13821380
audio_packet_config |= VC4_SET_FIELD(channel_mask,
13831381
VC4_HDMI_AUDIO_PACKET_CEA_MASK);
13841382

@@ -1397,7 +1395,7 @@ static int vc4_hdmi_audio_prepare(struct device *dev, void *data,
13971395
channel_map = vc4_hdmi->variant->channel_map(vc4_hdmi, channel_mask);
13981396
HDMI_WRITE(HDMI_MAI_CHANNEL_MAP, channel_map);
13991397
HDMI_WRITE(HDMI_AUDIO_PACKET_CONFIG, audio_packet_config);
1400-
vc4_hdmi_set_n_cts(vc4_hdmi);
1398+
vc4_hdmi_set_n_cts(vc4_hdmi, sample_rate);
14011399

14021400
memcpy(&vc4_hdmi->audio.infoframe, &params->cea, sizeof(params->cea));
14031401
vc4_hdmi_set_audio_infoframe(encoder);

drivers/gpu/drm/vc4/vc4_hdmi.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ struct vc4_hdmi_audio {
111111
struct snd_soc_dai_link_component cpu;
112112
struct snd_soc_dai_link_component codec;
113113
struct snd_soc_dai_link_component platform;
114-
int samplerate;
115-
int channels;
116114
struct snd_dmaengine_dai_dma_data dma_data;
117115
struct hdmi_audio_infoframe infoframe;
118116
bool streaming;

0 commit comments

Comments
 (0)