From patchwork Tue Apr 28 12:43:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lin, Mengdong" X-Patchwork-Id: 6288521 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 45A24BEEE1 for ; Tue, 28 Apr 2015 12:33:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6A70F20328 for ; Tue, 28 Apr 2015 12:33:24 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1C8BB201C8 for ; Tue, 28 Apr 2015 12:33:23 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3E07C260670; Tue, 28 Apr 2015 14:33:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E3EF5260687; Tue, 28 Apr 2015 14:33:01 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1ED5E26154F; Tue, 28 Apr 2015 14:33:00 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 7B430260687 for ; Tue, 28 Apr 2015 14:32:36 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 28 Apr 2015 05:32:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,663,1422950400"; d="scan'208";a="486664002" Received: from amanda-hsw-pc.sh.intel.com ([10.239.159.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Apr 2015 05:32:34 -0700 From: mengdong.lin@intel.com To: alsa-devel@alsa-project.org, tiwai@suse.de Date: Tue, 28 Apr 2015 20:43:19 +0800 Message-Id: <1430224999-22271-1-git-send-email-mengdong.lin@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <4530387c0b63ccfafb5dbb3399a39b4093651c48.1429880424.git.mengdong.lin@intel.com> References: <4530387c0b63ccfafb5dbb3399a39b4093651c48.1429880424.git.mengdong.lin@intel.com> Cc: Mengdong Lin Subject: [alsa-devel] [PATCH v2 3/3] ALSA: hda - implement a refcount for i915 power well switch X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mengdong Lin This is to check the refcount of audio driver and reduce calling to i915. Signed-off-by: Mengdong Lin diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c index 52a85d8..e831691 100644 --- a/sound/pci/hda/hda_i915.c +++ b/sound/pci/hda/hda_i915.c @@ -42,11 +42,16 @@ int hda_display_power(struct hda_intel *hda, bool enable) dev_dbg(&hda->chip.pci->dev, "display power %s\n", enable ? "enable" : "disable"); - if (enable) - acomp->ops->get_power(acomp->dev); - else - acomp->ops->put_power(acomp->dev); - + mutex_lock(&hda->display_power.lock); + if (enable) { + if (!hda->display_power.use_count++) + acomp->ops->get_power(acomp->dev); + } else { + WARN_ON(!hda->display_power.use_count); + if (!--hda->display_power.use_count) + acomp->ops->put_power(acomp->dev); + } + mutex_unlock(&hda->display_power.lock); return 0; } @@ -171,6 +176,8 @@ int hda_i915_init(struct hda_intel *hda) dev_dbg(dev, "bound to i915 component master\n"); + mutex_init(&hda->display_power.lock); + return 0; out_master_del: component_master_del(dev, &hda_component_master_ops); diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h index 2069898..3ca000a 100644 --- a/sound/pci/hda/hda_intel.h +++ b/sound/pci/hda/hda_intel.h @@ -19,6 +19,11 @@ #include #include "hda_controller.h" +struct i915_display_power { + struct mutex lock; + int use_count; +}; + struct hda_intel { struct azx chip; @@ -46,6 +51,7 @@ struct hda_intel { /* i915 component interface */ struct i915_audio_component audio_component; + struct i915_display_power display_power; }; #ifdef CONFIG_SND_HDA_I915