From patchwork Thu Dec 3 17:10:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 7761971 Return-Path: X-Original-To: patchwork-alsa-devel@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 95A519F30B for ; Thu, 3 Dec 2015 17:10:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C34702049E for ; Thu, 3 Dec 2015 17:10:28 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 59BC120494 for ; Thu, 3 Dec 2015 17:10:27 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id A2316260577; Thu, 3 Dec 2015 18:10:25 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C31F926052B; Thu, 3 Dec 2015 18:10:17 +0100 (CET) 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 7E988260542; Thu, 3 Dec 2015 18:10:16 +0100 (CET) Received: from mail1.bemta5.messagelabs.com (mail1.bemta5.messagelabs.com [195.245.231.148]) by alsa0.perex.cz (Postfix) with ESMTP id 4E7D12604F0 for ; Thu, 3 Dec 2015 18:10:09 +0100 (CET) Received: from [85.158.139.51] by server-12.bemta-5.messagelabs.com id 2F/A1-12831-07770665; Thu, 03 Dec 2015 17:10:08 +0000 X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-12.tower-180.messagelabs.com!1449162608!8163822!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 7.19.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21801 invoked from network); 3 Dec 2015 17:10:08 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-12.tower-180.messagelabs.com with AES128-SHA encrypted SMTP; 3 Dec 2015 17:10:08 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.248.2; Thu, 3 Dec 2015 17:10:07 +0000 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id BBFA73FB45; Thu, 3 Dec 2015 17:10:07 +0000 (GMT) Message-ID: From: Adam Thomson Date: Thu, 3 Dec 2015 17:10:07 +0000 To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Support Opensource Subject: [alsa-devel] [PATCH v2] ASoC: da7218: Enable mic level detection reporting to user-space 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support to the codec driver to handle mic level detect related IRQs, and report these to user-space using a uevent variable. The uevent variable string "EVENT=MIC_LEVEL_DETECT" is sent to user-space, if the mic level detect feature is enabled, and the audio captured at the chosen mic(s) is above a certain threshold. User-space can then handle the event accordingly (e.g. process audio capture stream). This method was chosen over ALSA control notification for a couple of reasons: 1) There's no requirement here for a control to read state from. The event is the only thing that's required and of interest. 2) tinyalsa support for control notifications does not exist so on platforms using this over alsa-lib there is a need to add code to support this event handling. Another possible option would be to use the standard Jack reporting framework but this really does not fit for this kind of event. Finally, use of the input device framework is not being encouraged, due to difficulties in enabling apps to access input devices, so this has also been avoided. Signed-off-by: Adam Thomson --- Changes in v2: - More verbose and descriptive commit message added. sound/soc/codecs/da7218.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) -- 1.9.3 diff --git a/sound/soc/codecs/da7218.c b/sound/soc/codecs/da7218.c index 4fee7ae..752ed04 100644 --- a/sound/soc/codecs/da7218.c +++ b/sound/soc/codecs/da7218.c @@ -2202,6 +2202,16 @@ int da7218_hpldet(struct snd_soc_codec *codec, struct snd_soc_jack *jack) } EXPORT_SYMBOL_GPL(da7218_hpldet); +static void da7218_micldet_irq(struct snd_soc_codec *codec) +{ + char *envp[] = { + "EVENT=MIC_LEVEL_DETECT", + NULL, + }; + + kobject_uevent_env(&codec->dev->kobj, KOBJ_CHANGE, envp); +} + static void da7218_hpldet_irq(struct snd_soc_codec *codec) { struct da7218_priv *da7218 = snd_soc_codec_get_drvdata(codec); @@ -2232,6 +2242,10 @@ static irqreturn_t da7218_irq_thread(int irq, void *data) if (!status) return IRQ_NONE; + /* Mic level detect */ + if (status & DA7218_LVL_DET_EVENT_MASK) + da7218_micldet_irq(codec); + /* HP detect */ if (status & DA7218_HPLDET_JACK_EVENT_MASK) da7218_hpldet_irq(codec); @@ -2936,11 +2950,6 @@ static int da7218_probe(struct snd_soc_codec *codec) } if (da7218->irq) { - /* Mask off mic level events, currently not handled */ - snd_soc_update_bits(codec, DA7218_EVENT_MASK, - DA7218_LVL_DET_EVENT_MSK_MASK, - DA7218_LVL_DET_EVENT_MSK_MASK); - ret = devm_request_threaded_irq(codec->dev, da7218->irq, NULL, da7218_irq_thread, IRQF_TRIGGER_LOW | IRQF_ONESHOT,