From patchwork Tue Dec 5 22:18:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120770 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6314577qgn; Tue, 5 Dec 2017 14:24:34 -0800 (PST) X-Google-Smtp-Source: AGs4zMa/mzb1Eln/KXpQkX7Lu2oEf6uu7pZgpGphkf4Jl97tCCgGSD7W3oQDephVfCYEzHdXkHL0 X-Received: by 10.99.55.92 with SMTP id g28mr19368319pgn.293.1512512674276; Tue, 05 Dec 2017 14:24:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512512674; cv=none; d=google.com; s=arc-20160816; b=DrJBLV6pzmaqaqUcK61PLXwF55dQVijJ9LRU+ag0tOOHke5NZlWwq7/BPflEvvF1Qk 6rcH7z4LDXjyGDpVdUoWkqgi5wbKOq2+w458ziK2n2oPfr2xY/iFvXmcLtzwcnYa8mg8 qKm89U0TPJD33V+svCfjY+rpup8tUb4eS69CZMqCFZz7lVkQJDhkLJ/N1JFFHlRbHhXL n0kqar/ETf0zAnkAAe1rhiJXKR+dYTIH3rejbJv1v1JNPq6gCXMAyyoz/uXO4kOCSHt0 uoB6SPFmMaBSUwYnie8NvMrUcslpF9FH5H+Am7uf4LVxTj9lBzRrLwSBBlC5t8yuZ+1m GEaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tAxYC3cXQPrm1YcwsAy1bsUKpTEsDemMkDHSVQFs+ok=; b=MzrLh40jwzXPnJWthrBtOfVgVGRbyZInz/R1OTxdc0h5ybuX1u+vGXIgNWGtFotomF gLZcIMn9OCXT38wn8TEV2frLCrAm95Gl4bBvEqhHIDyxbI8n/CvTvyhkETXKh0Ki+ql7 Uv62nNYLLR6Lj1yxthhmL72CCnMrnQvBugntOrpfXOT+TzKgTsUMMOvVUbRIu40s/HTc LKZ5ym1Dvsgm3gbnSLVR4EMJctwQEJ5RCiverPdJqq+SNrCbRJubHa6PEcVuXMfXG23n RRBGY2Gp9voOyGVuDxhFBzZoB/DP3epyjNdzeVRHFx6eTGDdOOAOJMXWdsbsHvR5iVC7 sQWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bAUbHUnf; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si797091pfi.343.2017.12.05.14.24.34; Tue, 05 Dec 2017 14:24:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bAUbHUnf; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752143AbdLEWYc (ORCPT + 10 others); Tue, 5 Dec 2017 17:24:32 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:46941 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752470AbdLEWU1 (ORCPT ); Tue, 5 Dec 2017 17:20:27 -0500 Received: by mail-wr0-f194.google.com with SMTP id x49so1902158wrb.13 for ; Tue, 05 Dec 2017 14:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EaGdKQ75qLPmdkyoqpfr5BGU14ZHnd8D48G7JV0Vh08=; b=bAUbHUnfEv6NWPkdMG+S4BeFwJnGxlpBE09P5Zll3yiy1zEKEjcOYzgdVrkX1kP2Rz QnUaB0uP+e+2ZZDDzyuezt3mvTpVifrN+AnmfOhFgF5RVG/84A3jhat85GQDVxEP2YTj jr9DpjFcj2InbNT/VAVMSwy7WdlCkeUrxbiN8= 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:in-reply-to :references; bh=EaGdKQ75qLPmdkyoqpfr5BGU14ZHnd8D48G7JV0Vh08=; b=ng2EUggF69tssMIirpGmSjS7RzgHScvOM0nWOntamsClAjSa5EousT3ghtgoqp8ykS aKfrzNJ0288Hz0ChZ5ObdCtDuS4OMgI6+XHbiLwLXQQJ2SWmKobvvqJL+Ww+IL1N+etK zy7jgJLPu/eQqxlTBB5sRT/zl005zJRSZg8EbGvQZbzi3bC4keIEaQropJTvAqQQN9xb ypy2YWYXFCuVo0dIusmNB+sP1btpEVufu9PmzhDI8mWyz3OBvUzZAic2KJMkY6t2F92R DqnKZwCGOAXtIMtzr/l4Hef+BTcYxoAcvroy7rUs91WwoBAY8A3ear7KHKLeD42WQoks a69A== X-Gm-Message-State: AJaThX62TfjG0sZTXHRS2JHJXBJRGfG8PFJvtb7FBHqOkIjjpVAqeheD x88Y43z/f+4VWDC905JRHJSnPQ== X-Received: by 10.223.152.1 with SMTP id v1mr19620391wrb.234.1512512425875; Tue, 05 Dec 2017 14:20:25 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id t138sm1633154wme.16.2017.12.05.14.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Dec 2017 14:20:25 -0800 (PST) From: srinivas.kandagatla@linaro.org To: broonie@kernel.org, bgoswami@codeaurora.org Cc: alsa-devel@alsa-project.org, tiwai@suse.com, plai@codeaurora.org, kwestfie@codeaurora.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, lkasam@qti.qualcomm.com, Srinivas Kandagatla Subject: [PATCH v2 06/15] ASoC: qcom: qdsp6: Add support to Q6ASM Date: Tue, 5 Dec 2017 22:18:03 +0000 Message-Id: <20171205221812.25641-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171205221812.25641-1-srinivas.kandagatla@linaro.org> References: <20171205221812.25641-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Srinivas Kandagatla This patch adds basic support to Q6 ASM (Audio Stream Manager) module on Q6DSP. ASM supports up to 8 concurrent streams. each stream can be setup as playback/capture. ASM provides top control functions like Pause/flush/resume for playback and record. ASM can Create/destroy encoder, decoder and also provides POPP dynamic services. This patch adds support to basic features to allow hdmi playback. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 5 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6asm.c | 250 ++++++++++++++++++++++++++++++++++++++++++ sound/soc/qcom/qdsp6/q6asm.h | 14 +++ 4 files changed, 270 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/q6asm.c create mode 100644 sound/soc/qcom/qdsp6/q6asm.h -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index a307880dc992..7ebdb879a8a3 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -52,10 +52,15 @@ config SND_SOC_QDSP6_ADM tristate default n +config SND_SOC_QDSP6_ASM + tristate + default n + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" select SND_SOC_QDSP6_AFE select SND_SOC_QDSP6_ADM + select SND_SOC_QDSP6_ASM help To add support for MSM QDSP6 Soc Audio. This will enable sound soc platform specific diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 052813ea7062..49dd3ccab27b 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o +obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c new file mode 100644 index 000000000000..9cc583afef4d --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6asm.c @@ -0,0 +1,250 @@ +/* SPDX-License-Identifier: GPL-2.0 +* Copyright (c) 2011-2016, The Linux Foundation +* Copyright (c) 2017, Linaro Limited +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6asm.h" +#include "common.h" + +#define TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */ +#define SYNC_IO_MODE 0x0001 +#define ASYNC_IO_MODE 0x0002 + +struct audio_client { + int session; + app_cb cb; + int cmd_state; + void *priv; + uint32_t io_mode; + uint64_t time_stamp; + struct apr_device *adev; + struct mutex cmd_lock; + wait_queue_head_t cmd_wait; + int perf_mode; + int stream_id; + struct device *dev; +}; + +struct q6asm { + struct apr_device *adev; + int mem_state; + struct device *dev; + wait_queue_head_t mem_wait; + struct mutex session_lock; + struct platform_device *pcmdev; + struct audio_client *session[MAX_SESSIONS + 1]; +}; + +static int q6asm_session_alloc(struct audio_client *ac, struct q6asm *a) +{ + int n = -EINVAL; + + mutex_lock(&a->session_lock); + for (n = 1; n <= MAX_SESSIONS; n++) { + if (!a->session[n]) { + a->session[n] = ac; + break; + } + } + mutex_unlock(&a->session_lock); + + return n; +} + +static bool q6asm_is_valid_audio_client(struct audio_client *ac) +{ + struct q6asm *a = dev_get_drvdata(ac->dev->parent); + int n; + + for (n = 1; n <= MAX_SESSIONS; n++) { + if (a->session[n] == ac) + return 1; + } + + return 0; +} + +static void q6asm_session_free(struct audio_client *ac) +{ + struct q6asm *a = dev_get_drvdata(ac->dev->parent); + + if (!a) + return; + + mutex_lock(&a->session_lock); + a->session[ac->session] = 0; + ac->session = 0; + ac->perf_mode = LEGACY_PCM_MODE; + mutex_unlock(&a->session_lock); +} + +/** + * q6asm_audio_client_free() - Freee allocated audio client + * + * @ac: audio client to free + */ +void q6asm_audio_client_free(struct audio_client *ac) +{ + q6asm_session_free(ac); + kfree(ac); +} +EXPORT_SYMBOL_GPL(q6asm_audio_client_free); + +static struct audio_client *q6asm_get_audio_client(struct q6asm *a, + int session_id) +{ + if ((session_id <= 0) || (session_id > MAX_SESSIONS)) { + dev_err(a->dev, "invalid session: %d\n", session_id); + goto err; + } + + if (!a->session[session_id]) { + dev_err(a->dev, "session not active: %d\n", session_id); + goto err; + } + return a->session[session_id]; +err: + return NULL; +} + +static int q6asm_srvc_callback(struct apr_device *adev, struct apr_client_data *data) +{ + struct q6asm *q6asm = dev_get_drvdata(&adev->dev); + struct audio_client *ac = NULL; + uint32_t sid = 0; + uint32_t *payload; + + if (!data) { + dev_err(&adev->dev, "%s: Invalid CB\n", __func__); + return 0; + } + + payload = data->payload; + sid = (data->token >> 8) & 0x0F; + ac = q6asm_get_audio_client(q6asm, sid); + if (!ac) { + dev_err(&adev->dev, "Audio Client not active\n"); + return 0; + } + + if (ac->cb) + ac->cb(data->opcode, data->token, data->payload, ac->priv); + return 0; +} + +/** + * q6asm_get_session_id() - get session id for audio client + * + * @ac: audio client pointer + * + * Return: Will be an session id of the audio client. + */ +int q6asm_get_session_id(struct audio_client *c) +{ + return c->session; +} +EXPORT_SYMBOL_GPL(q6asm_get_session_id); + +/** + * q6asm_audio_client_alloc() - Allocate a new audio client + * + * @dev: Pointer to asm child device. + * @cb: event callback. + * @priv: private data associated with this client. + * + * Return: Will be an error pointer on error or a valid audio client + * on success. + */ +struct audio_client *q6asm_audio_client_alloc(struct device *dev, + app_cb cb, void *priv) +{ + struct q6asm *a = dev_get_drvdata(dev->parent); + struct audio_client *ac; + int n; + + ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL); + if (!ac) + return NULL; + + n = q6asm_session_alloc(ac, a); + if (n <= 0) { + dev_err(dev, "ASM Session alloc fail n=%d\n", n); + kfree(ac); + return NULL; + } + + ac->session = n; + ac->cb = cb; + ac->dev = dev; + ac->priv = priv; + ac->io_mode = SYNC_IO_MODE; + ac->perf_mode = LEGACY_PCM_MODE; + /* DSP expects stream id from 1 */ + ac->stream_id = 1; + ac->adev = a->adev; + + init_waitqueue_head(&ac->cmd_wait); + mutex_init(&ac->cmd_lock); + ac->cmd_state = 0; + + return ac; +} +EXPORT_SYMBOL_GPL(q6asm_audio_client_alloc); + + +static int q6asm_probe(struct apr_device *adev) +{ + struct q6asm *q6asm; + + q6asm = devm_kzalloc(&adev->dev, sizeof(*q6asm), GFP_KERNEL); + if (!q6asm) + return -ENOMEM; + + q6asm->dev = &adev->dev; + q6asm->adev = adev; + q6asm->mem_state = 0; + init_waitqueue_head(&q6asm->mem_wait); + mutex_init(&q6asm->session_lock); + dev_set_drvdata(&adev->dev, q6asm); + + q6asm->pcmdev = platform_device_register_data(&adev->dev, + "q6asm_dai", -1, NULL, 0); + + return 0; +} + +static int q6asm_remove(struct apr_device *adev) +{ + struct q6asm *q6asm = dev_get_drvdata(&adev->dev); + + platform_device_unregister(q6asm->pcmdev); + + return 0; +} + +static const struct apr_device_id q6asm_id[] = { + {"Q6ASM", APR_DOMAIN_ADSP, APR_SVC_ASM, APR_CLIENT_AUDIO}, + {} +}; + +static struct apr_driver qcom_q6asm_driver = { + .probe = q6asm_probe, + .remove = q6asm_remove, + .callback = q6asm_srvc_callback, + .id_table = q6asm_id, + .driver = { + .name = "qcom-q6asm", + }, +}; + +module_apr_driver(qcom_q6asm_driver); +MODULE_DESCRIPTION("Q6 Audio Stream Manager driver"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/qcom/qdsp6/q6asm.h b/sound/soc/qcom/qdsp6/q6asm.h new file mode 100644 index 000000000000..7a8a9039fd89 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6asm.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __Q6_ASM_H__ +#define __Q6_ASM_H__ + +#define MAX_SESSIONS 16 + +typedef void (*app_cb) (uint32_t opcode, uint32_t token, + uint32_t *payload, void *priv); +struct audio_client; +struct audio_client *q6asm_audio_client_alloc(struct device *dev, + app_cb cb, void *priv); +void q6asm_audio_client_free(struct audio_client *ac); +int q6asm_get_session_id(struct audio_client *ac); +#endif /* __Q6_ASM_H__ */