From patchwork Tue Feb 13 16:58:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10216891 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 D051760329 for ; Tue, 13 Feb 2018 17:04:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD4B228DD7 for ; Tue, 13 Feb 2018 17:04:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF83628E86; Tue, 13 Feb 2018 17:04:50 +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 A838D28DD7 for ; Tue, 13 Feb 2018 17:04:49 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 1E49B2679CE; Tue, 13 Feb 2018 18:01:38 +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 256C02679D0; Tue, 13 Feb 2018 18:01:37 +0100 (CET) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by alsa0.perex.cz (Postfix) with ESMTP id 71D79267996 for ; Tue, 13 Feb 2018 18:01:32 +0100 (CET) Received: by mail-wr0-f195.google.com with SMTP id m5so7251224wrg.1 for ; Tue, 13 Feb 2018 09:01:32 -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=ubU4NA3gnjL1OFpQ6vKR45QNVGR2PTsWF+aeTHJ02dU=; b=WsUc6b7KxV0kyj/0zrykS8DZ0A5i+QegJvJql+sbmRwQlG85QuMPmmc2UbcjcbfAPc x4n5XIQzPoas8GeFYmWQH4iKV0dMnMbBkJmjV1Jh4lRTSN/IvwU+4qPcXTsKbGa2eQbZ b6LUvRHyN7zDC9RzEwiGR1BX8NIiWArttgKl4= 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=ubU4NA3gnjL1OFpQ6vKR45QNVGR2PTsWF+aeTHJ02dU=; b=gYZbn2KIHfaAhl7GjtNLP//l+jv8Q/50u7tor3HSBKKsDBs2AdAMaWikAO6LasTJXp VhAxp8f9hVufKIbb5bud5Y4aogcCPi6jwSQ3dShTgRH1bsQ7MWrf9Xdhv+pZ7ds1Jhji 3PO0AN8foFMlxmjVioYZm6cCZbYUCLfD+eQG05/8IvgzLk/NxhLxzYB0DxchuihIe2Yl bNVMOdj5sLy44/lrq1W+qiSO+HTIY7HHLGdsL7RojjPDknZ6AVomaOUMWBDgpEJ3dueo SyGKMCkbb3OIoVWRUNyC7KYag+3QH1BlsILbGlLYNZHxndGg2Q3Lhz26aGZbCj30D74U EuFw== X-Gm-Message-State: APf1xPBwXvXa6dD+SYZjF/cCbByKtv56h/56e4gTdfyV10i2WCFZ7ek6 dIGo3T3dny87M651Ijhw85J5DA== X-Google-Smtp-Source: AH8x227f2gvxe3ExBrAuZLsCeqTh8+MOyrW5s6P9TA1T//HGw6Qs/K0/y7ScYw5IX7WScOI7MJe6DA== X-Received: by 10.223.134.104 with SMTP id 37mr1713553wrw.150.1518541290701; Tue, 13 Feb 2018 09:01:30 -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 y145sm7432723wmd.43.2018.02.13.09.01.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 09:01:29 -0800 (PST) From: srinivas.kandagatla@linaro.org To: andy.gross@linaro.org, broonie@kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org Date: Tue, 13 Feb 2018 16:58:24 +0000 Message-Id: <20180213165837.1620-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180213165837.1620-1-srinivas.kandagatla@linaro.org> References: <20180213165837.1620-1-srinivas.kandagatla@linaro.org> Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, bgoswami@codeaurora.org, rohkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, plai@codeaurora.org, tiwai@suse.com, lgirdwood@gmail.com, david.brown@linaro.org, robh+dt@kernel.org, Srinivas Kandagatla , spatakok@qti.qualcomm.com, linux-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [alsa-devel] [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE 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: Srinivas Kandagatla This patch adds support to core apr service, which is used to query status of other static and dynamic services on the dsp. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 5 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6core.c | 235 ++++++++++++++++++++++++++++++++++++++++++ sound/soc/qcom/qdsp6/q6core.h | 9 ++ 4 files changed, 250 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/q6core.c create mode 100644 sound/soc/qcom/qdsp6/q6core.h diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index a14d960b8fe4..8c2d65e0a28e 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -60,6 +60,10 @@ config SND_SOC_QDSP6_ASM tristate default n +config SND_SOC_QDSP6_CORE + tristate + default n + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" depends on QCOM_APR && HAS_DMA @@ -67,6 +71,7 @@ config SND_SOC_QDSP6 select SND_SOC_QDSP6_AFE select SND_SOC_QDSP6_ADM select SND_SOC_QDSP6_ASM + select SND_SOC_QDSP6_CORE 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 eea962315ab3..61f089bc0d25 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o +obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c new file mode 100644 index 000000000000..d4a3ff409a34 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6core.c @@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2011-2017, The Linux Foundation + * Copyright (c) 2018, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6dsp-errno.h" + +#define ADSP_STATE_READY_TIMEOUT_MS 3000 +#define Q6_READY_TIMEOUT_MS 100 +#define AVCS_CMD_ADSP_EVENT_GET_STATE 0x0001290C +#define AVCS_CMDRSP_ADSP_EVENT_GET_STATE 0x0001290D +#define AVCS_GET_VERSIONS 0x00012905 +#define AVCS_GET_VERSIONS_RSP 0x00012906 + +struct avcs_svc_info { + uint32_t service_id; + uint32_t version; +} __packed; + +struct q6core { + struct apr_device *adev; + wait_queue_head_t wait; + uint32_t avcs_state; + bool resp_received; + uint32_t num_services; + struct avcs_svc_info *svcs_info; +}; + +struct q6core *core; + +static int q6core_callback(struct apr_device *adev, + struct apr_client_message *data) +{ + struct q6core *core = dev_get_drvdata(&adev->dev); + struct aprv2_ibasic_rsp_result_t *result; + + result = data->payload; + switch (data->opcode) { + case AVCS_GET_VERSIONS_RSP: + core->num_services = result->status; + + core->svcs_info = kcalloc(core->num_services, + sizeof(*core->svcs_info), + GFP_ATOMIC); + if (!core->svcs_info) + return -ENOMEM; + + /* svc info is after apr result */ + memcpy(core->svcs_info, result + sizeof(*result), + core->num_services * sizeof(*core->svcs_info)); + + core->resp_received = true; + wake_up(&core->wait); + + break; + case AVCS_CMDRSP_ADSP_EVENT_GET_STATE: + core->avcs_state = result->opcode; + + core->resp_received = true; + wake_up(&core->wait); + break; + default: + dev_err(&adev->dev, "Message id from adsp core svc: 0x%x\n", + data->opcode); + break; + } + + return 0; +} + +static int q6core_get_svc_versions(struct q6core *core) +{ + struct apr_device *adev = core->adev; + struct apr_hdr hdr = {0}; + int rc; + + hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, + APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); + hdr.pkt_size = APR_HDR_SIZE; + hdr.opcode = AVCS_GET_VERSIONS; + + rc = apr_send_pkt(adev, &hdr); + if (rc < 0) + return rc; + + rc = wait_event_timeout(core->wait, (core->resp_received), + msecs_to_jiffies(Q6_READY_TIMEOUT_MS)); + if (rc > 0 && core->resp_received) { + core->resp_received = false; + return 0; + } + + return rc; +} + +static bool __q6core_is_adsp_ready(struct q6core *core) +{ + struct apr_device *adev = core->adev; + struct apr_hdr hdr = {0}; + int rc; + + hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, + APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); + hdr.pkt_size = APR_HDR_SIZE; + hdr.opcode = AVCS_CMD_ADSP_EVENT_GET_STATE; + + rc = apr_send_pkt(adev, &hdr); + if (rc < 0) + return false; + + rc = wait_event_timeout(core->wait, (core->resp_received), + msecs_to_jiffies(Q6_READY_TIMEOUT_MS)); + if (rc > 0 && core->resp_received) { + core->resp_received = false; + if (core->avcs_state == 0x1) + return true; + } + + return false; +} + +/** + * q6core_get_svc_version() - Get version number of a service. + * + * @svc_id: service id of the service. + * + * Return: Will be a valid version number on success and zero on failure. + * version number returned contains bits 0 to 15 as Minor version number + * Bits 16 to 31 as Major version number + */ +uint32_t q6core_get_svc_version(int svc_id) +{ + struct apr_device *adev; + struct avcs_svc_info *svcs_info; + int i, ret; + + if (!core) + return 0; + + if (!core->svcs_info) { + ret = q6core_get_svc_versions(core); + if (ret) + return ret; + } + + adev = core->adev; + svcs_info = core->svcs_info; + + for (i = 0; i < core->num_services; i++) + if (svcs_info[i].service_id == svc_id) + return svcs_info[i].version; + + return 0; +} +EXPORT_SYMBOL_GPL(q6core_get_svc_version); + +/** + * q6core_is_adsp_ready() - Get status of adsp + * + * Return: Will be an true if adsp is ready and false if not. + */ +bool q6core_is_adsp_ready(void) +{ + unsigned long timeout; + + if (!core) + return false; + + timeout = jiffies + msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS); + for (;;) { + if (__q6core_is_adsp_ready(core)) + return true; + + if (!time_after(timeout, jiffies)) + return false; + } + + return false; +} +EXPORT_SYMBOL_GPL(q6core_is_adsp_ready); + +static int q6core_probe(struct apr_device *adev) +{ + core = kzalloc(sizeof(*core), GFP_KERNEL); + if (!core) + return -ENOMEM; + + dev_set_drvdata(&adev->dev, core); + + core->adev = adev; + init_waitqueue_head(&core->wait); + + return 0; +} + +static int q6core_exit(struct apr_device *adev) +{ + if (core->svcs_info) + kfree(core->svcs_info); + + kfree(core); + core = NULL; + + return 0; +} + +static const struct of_device_id q6core_device_id[] = { + { .compatible = "qcom,q6core" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6core_device_id); + +static struct apr_driver qcom_q6core_driver = { + .probe = q6core_probe, + .remove = q6core_exit, + .callback = q6core_callback, + .driver = { + .name = "qcom-q6core", + .of_match_table = of_match_ptr(q6core_device_id), + }, +}; + +module_apr_driver(qcom_q6core_driver); +MODULE_DESCRIPTION("q6 core"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/qcom/qdsp6/q6core.h b/sound/soc/qcom/qdsp6/q6core.h new file mode 100644 index 000000000000..2852fbb7756e --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6core.h @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef __Q6CORE_H__ +#define __Q6CORE_H__ + +bool q6core_is_adsp_ready(void); +uint32_t q6core_get_svc_version(int svc_id); + +#endif /* __Q6CORE_H__ */