From patchwork Mon Aug 28 06:36:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yu Chao X-Patchwork-Id: 9924205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D44E60311 for ; Mon, 28 Aug 2017 06:37:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C77628673 for ; Mon, 28 Aug 2017 06:37:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7110128680; Mon, 28 Aug 2017 06:37:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F62E28673 for ; Mon, 28 Aug 2017 06:37:37 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C25F6266D45; Mon, 28 Aug 2017 08:37:07 +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 4C217266D55; Mon, 28 Aug 2017 08:37:06 +0200 (CEST) Received: from mail-pg0-f46.google.com (mail-pg0-f46.google.com [74.125.83.46]) by alsa0.perex.cz (Postfix) with ESMTP id 8C5D9266C78 for ; Mon, 28 Aug 2017 08:37:02 +0200 (CEST) Received: by mail-pg0-f46.google.com with SMTP id 83so21117528pgb.4 for ; Sun, 27 Aug 2017 23:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=dv00FyeBMPkR+tMn4MK3oVywdjUl71i2fo5cb7SmFuU=; b=EZwfU8aQtZc7+NgFgy5Nk0pSuVsEP0yJQKnkTspUFXaNNFXX7rNVpmtz2ivo+FWjrh wK3cOeZI5icItSt4x5njQ/Sv32IGtY2dCVnFILn58yjZIVxgSJp13Oeu08fVe1Xu6/mE MlbxSAS8SLCqcfL1FO0NAszc5ANMS8Nx7DctY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dv00FyeBMPkR+tMn4MK3oVywdjUl71i2fo5cb7SmFuU=; b=ZWOvltB+g1jRQDWYpE3pEvEPg7HGqt4FduVJh/VBgH3Hk0+NJLbEJtVSbivMrvFzmi eCWYw2sH4G2l8s23KvZ+CS9dR7tVXnvCzs3XXXZsoDc71g4Pbn3UUXwVXPPmyxzEDWHE kUygvJI9+9kyMNGJ9UEj0tC8Z2OLyiJ/WPVjDhM3Gx1QTVWZQAkOK2HJS2zRB45brgjW qZBEuPCpWXrGSI/2sJGARUjz82wcsypQ257WgFPYRt8oJUpE4WvxJlL7AmKW5LBURcEw 0KOp6wHO2TvUCd1WAsdIxTeknxRDMoYY1od3iVakgh1vsg8aKjYQw9u1v7JXXoBpRZmZ E7gA== X-Gm-Message-State: AHYfb5gyodq5a71Np5N1dM2SrqcxPcWYWFxSiV/qCsQQMSEVx6rwxpZP sFiui5v7X2XLGOa/ X-Received: by 10.98.43.78 with SMTP id r75mr6375986pfr.269.1503902220040; Sun, 27 Aug 2017 23:37:00 -0700 (PDT) Received: from hychaoz840.tpe.corp.google.com ([2401:fa00:1:b:8098:bc01:a067:52bc]) by smtp.gmail.com with ESMTPSA id g26sm20980965pfk.139.2017.08.27.23.36.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 23:36:58 -0700 (PDT) From: Hsin-Yu Chao To: broonie@kernel.org, lgirdwood@gmail.com Date: Mon, 28 Aug 2017 14:36:52 +0800 Message-Id: <20170828063652.87941-1-hychao@chromium.org> X-Mailer: git-send-email 2.12.2 Cc: oder_chiou@realtek.com, alsa-devel@alsa-project.org, Hsin-Yu Chao Subject: [alsa-devel] [PATCH] ASoC: rt5514: expose Hotword Model control 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 This change exposes mixer control 'Hotword Model' for switching hotword model in runtime. This new function requires updated firmware to load hotword model at address 0x4ff80000. Note that if the rt5514-spi driver is not enabled in kernel, hotword model will not be loaded when "DSP Voice Wake Up" is set to turn on DSP mode, and an error is logged instead. Signed-off-by: Hsin-Yu Chao --- sound/soc/codecs/rt5514.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5514.h | 3 +++ 2 files changed, 66 insertions(+) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index a2722177470e..250581082e9d 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -335,6 +335,39 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, fw = NULL; } + if (rt5514->model_buf && rt5514->model_len) { +#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI) + int ret; + + ret = rt5514_spi_burst_write(0x4ff80000, + rt5514->model_buf, + ((rt5514->model_len / 8) + 1) * 8); + if (ret) { + dev_err(codec->dev, + "Model load failed %d\n", ret); + return ret; + } +#else + dev_err(codec->dev, + "No SPI driver for loading firmware\n"); +#endif + } else { + request_firmware(&fw, RT5514_FIRMWARE3, + codec->dev); + if (fw) { +#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI) + rt5514_spi_burst_write(0x4ff80000, + fw->data, + ((fw->size/8)+1)*8); +#else + dev_err(codec->dev, + "No SPI driver to load fw\n"); +#endif + release_firmware(fw); + fw = NULL; + } + } + /* DSP run */ regmap_write(rt5514->i2c_regmap, 0x18002f00, 0x00055148); @@ -349,6 +382,34 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, return 0; } +static int rt5514_hotword_model_put(struct snd_kcontrol *kcontrol, + const unsigned int __user *bytes, unsigned int size) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); + struct snd_soc_codec *codec = rt5514->codec; + int ret = 0; + + if (rt5514->model_buf || rt5514->model_len < size) { + if (rt5514->model_buf) + devm_kfree(codec->dev, rt5514->model_buf); + rt5514->model_buf = devm_kmalloc(codec->dev, size, GFP_KERNEL); + if (!rt5514->model_buf) { + ret = -ENOMEM; + goto done; + } + } + + /* Skips the TLV header. */ + bytes += 2; + + if (copy_from_user(rt5514->model_buf, bytes, size)) + ret = -EFAULT; +done: + rt5514->model_len = (ret ? 0 : size); + return ret; +} + static const struct snd_kcontrol_new rt5514_snd_controls[] = { SOC_DOUBLE_TLV("MIC Boost Volume", RT5514_ANA_CTRL_MICBST, RT5514_SEL_BSTL_SFT, RT5514_SEL_BSTR_SFT, 8, 0, bst_tlv), @@ -360,6 +421,8 @@ static const struct snd_kcontrol_new rt5514_snd_controls[] = { adc_vol_tlv), SOC_SINGLE_EXT("DSP Voice Wake Up", SND_SOC_NOPM, 0, 1, 0, rt5514_dsp_voice_wake_up_get, rt5514_dsp_voice_wake_up_put), + SND_SOC_BYTES_TLV("Hotword Model", 0x8504, + NULL, rt5514_hotword_model_put), }; /* ADC Mixer*/ diff --git a/sound/soc/codecs/rt5514.h b/sound/soc/codecs/rt5514.h index 02bc212a86d9..07475a9918d2 100644 --- a/sound/soc/codecs/rt5514.h +++ b/sound/soc/codecs/rt5514.h @@ -236,6 +236,7 @@ #define RT5514_FIRMWARE1 "rt5514_dsp_fw1.bin" #define RT5514_FIRMWARE2 "rt5514_dsp_fw2.bin" +#define RT5514_FIRMWARE3 "rt5514_dsp_fw3.bin" /* System Clock Source */ enum { @@ -262,6 +263,8 @@ struct rt5514_priv { int pll_in; int pll_out; int dsp_enabled; + u8 *model_buf; + unsigned int model_len; }; #endif /* __RT5514_H__ */