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: 10216987 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 2569060329 for ; Tue, 13 Feb 2018 17:10:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F10228EB2 for ; Tue, 13 Feb 2018 17:10:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7C928ED6; Tue, 13 Feb 2018 17:10:37 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CF79128F60 for ; Tue, 13 Feb 2018 17:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZG2u4McLSEj2Z5+7uwUxe74NtNLV1ejuGploX9Qwkfo=; b=A7QbSUsDDi5oK9UeIQiieOfWf+ VnEP720p0t0ls5LH0fThotcVdiZpyW0vsZh+0utddqyiUw/iGvAkhFQiZb7OaZ8KJy2UbqZbtk6qb 363ixBnfGmMnkZ1rRE+jnNJN5zZsZb76r1na43S4/Lj1vQEmdbX/B+AJYFtbTAc6xp2zt975QboR4 WAdh/O3LhBTLS94wPcZQWt7k0cDOXo5/fs4sB2LK/9hmLv6v9PMpB8qF+IYH/Hz+xRwnPuV0oivg9 UJY5Ws64wvNJI6liOlaqwmIxh7ujMsaT7UmfVjBjBmjJDUOYAOghznk2/MYokmmfqR0O9ZptJyQts XhafWeLA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ele6B-0004hE-Bz; Tue, 13 Feb 2018 17:10:31 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eldxf-0003gD-Q2 for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2018 17:02:18 +0000 Received: by mail-wr0-x242.google.com with SMTP id y3so19304586wrh.3 for ; Tue, 13 Feb 2018 09:01:33 -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=F4HUAsEB+nl0An9EBtS3C/y3NkwVyK8ORHT2zNcs8YYXHCD6Ppido5osxMb5WKabBx B8ZEcIuI16g4XBNbWibc5LZAYYUkWTQHn62EIuNYCEUejaHyoOFxdAeMYKnF0ZvHVx1L OkGD5/n2jlLbtNDrXEoMledXS0XfM62X59imwbC5Hd4S7VSQQLB15SRA6EK5Cooyhhew /kuhvYpSkE0gKPxZR4t9m+UHIffRWaV2kwysXSJhnrgVQ+fGDacP3tNxjIcRYA2BklwX t0aarzWdAsCPXC8K3Zj9rG/pB6jUVCX+CNDkrBlzt3uNwjHoARb20OWfqmjNqTSj0MSG vsLg== X-Gm-Message-State: APf1xPCOGxVV3vFVy5YeBlvRVX/mViSa681Mv4ykHaRsTXY8No7IqatD TXzMS0powAiSlY0oqTLpu2J1XQ== 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 Subject: [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180213_090145_276888_2FF9CE9D X-CRM114-Status: GOOD ( 19.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, perex@perex.cz, 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 MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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__ */