From patchwork Tue Dec 1 16:09:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 7738301 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7E0C89F7CA for ; Tue, 1 Dec 2015 16:10:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94833206C0 for ; Tue, 1 Dec 2015 16:10:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D4664206A0 for ; Tue, 1 Dec 2015 16:10:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A52C720A3; Tue, 1 Dec 2015 08:10:08 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id D2B6A6E88B for ; Tue, 1 Dec 2015 08:10:05 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C62EEAC0B; Tue, 1 Dec 2015 16:10:01 +0000 (UTC) From: Takashi Iwai To: intel-gfx@lists.freedesktop.org, alsa-devel@alsa-project.org Date: Tue, 1 Dec 2015 17:09:52 +0100 Message-Id: <1448986198-3488-4-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1448986198-3488-1-git-send-email-tiwai@suse.de> References: <1448986198-3488-1-git-send-email-tiwai@suse.de> Cc: Mengdong Lin , Vinod Koul , David Henningsson , Daniel Vetter Subject: [Intel-gfx] [PATCH v2 3/9] drm/i915: refactoring audio component functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have a common loop of encoder to look for the given audio port in two audio component functions. Split out a local helper function to do it for the code simplification. Signed-off-by: Takashi Iwai --- drivers/gpu/drm/i915/intel_audio.c | 61 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c index 1965a61769ea..19958bdb9bd0 100644 --- a/drivers/gpu/drm/i915/intel_audio.c +++ b/drivers/gpu/drm/i915/intel_audio.c @@ -630,17 +630,33 @@ static int i915_audio_component_get_cdclk_freq(struct device *dev) return ret; } +static struct intel_encoder *audio_port_to_encoder(struct drm_device *drm_dev, + int port) +{ + struct intel_encoder *intel_encoder; + struct intel_digital_port *intel_dig_port; + + for_each_intel_encoder(drm_dev, intel_encoder) { + if (intel_encoder->type != INTEL_OUTPUT_HDMI && + intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT) + continue; + intel_dig_port = enc_to_dig_port(&intel_encoder->base); + if (port == intel_dig_port->port) + return intel_encoder; + } + return NULL; +} + static int i915_audio_component_sync_audio_rate(struct device *dev, int port, int rate) { struct drm_i915_private *dev_priv = dev_to_i915(dev); struct drm_device *drm_dev = dev_priv->dev; struct intel_encoder *intel_encoder; - struct intel_digital_port *intel_dig_port; struct intel_crtc *crtc; struct drm_display_mode *mode; struct i915_audio_component *acomp = dev_priv->audio_component; - enum pipe pipe = -1; + enum pipe pipe; u32 tmp; int n; @@ -652,22 +668,14 @@ static int i915_audio_component_sync_audio_rate(struct device *dev, mutex_lock(&dev_priv->av_mutex); /* 1. get the pipe */ - for_each_intel_encoder(drm_dev, intel_encoder) { - if (intel_encoder->type != INTEL_OUTPUT_HDMI) - continue; - intel_dig_port = enc_to_dig_port(&intel_encoder->base); - if (port == intel_dig_port->port) { - crtc = to_intel_crtc(intel_encoder->base.crtc); - pipe = crtc->pipe; - break; - } - } - - if (pipe == INVALID_PIPE) { + intel_encoder = audio_port_to_encoder(drm_dev, port); + if (!intel_encoder || intel_encoder->type != INTEL_OUTPUT_HDMI) { DRM_DEBUG_KMS("no pipe for the port %c\n", port_name(port)); mutex_unlock(&dev_priv->av_mutex); return -ENODEV; } + crtc = to_intel_crtc(intel_encoder->base.crtc); + pipe = crtc->pipe; DRM_DEBUG_KMS("pipe %c connects port %c\n", pipe_name(pipe), port_name(port)); mode = &crtc->config->base.adjusted_mode; @@ -717,23 +725,18 @@ static int i915_audio_component_get_eld(struct device *dev, int port, int ret = -EINVAL; drm_modeset_lock_all(drm_dev); - for_each_intel_encoder(drm_dev, intel_encoder) { - if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT && - intel_encoder->type != INTEL_OUTPUT_HDMI) - continue; + intel_encoder = audio_port_to_encoder(drm_dev, port); + if (intel_encoder) { + ret = 0; intel_dig_port = enc_to_dig_port(&intel_encoder->base); - if (port == intel_dig_port->port) { - ret = 0; - *enabled = intel_dig_port->audio_enabled; - if (!*enabled) - break; + *enabled = intel_dig_port->audio_enabled; + if (*enabled) { connector = drm_select_eld(&intel_encoder->base); - if (!connector) - break; - eld = connector->eld; - ret = drm_eld_size(eld); - memcpy(buf, eld, min(max_bytes, ret)); - break; + if (connector) { + eld = connector->eld; + ret = drm_eld_size(eld); + memcpy(buf, eld, min(max_bytes, ret)); + } } }