From patchwork Tue Feb 13 16:58:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10216835 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 274D260329 for ; Tue, 13 Feb 2018 17:02:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16FE3274A3 for ; Tue, 13 Feb 2018 17:02:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AE1127E63; Tue, 13 Feb 2018 17:02:36 +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=ham 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 1AF01274A3 for ; Tue, 13 Feb 2018 17:02: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=MLipzGOatQpdm7CqMCVy+iPzj5VvWo2lZQ21k38+7PY=; b=SVopeU2nBtkqpnl28T9yzsljvY 69CkYZQ8brRlQ6cWIQAxO5dJtBcGxUR0HmTlM8OrVNUkcrRaAD+F2Vc1CgP6PaIf4qy8H6NUoqAip oZkcT5tG5YkpIYMboCH1mz0e0jWd9DbusSpaO0ap2EY/DUk4UI+64xdvUsphkXz3L231IwRkf39LA pjmqKuhClN3UhR9MIE+c0SNNehB1kkXbhcHWp8q03b0I+zQPuXyPTY5EsOPl0WUCT/Gi4nshVotle i2e5XgW0pjSzeDzC2alXq/kgEbIBu5Q+zPZ453WXjPstWg+fdwFDIWI4tSq9jO1iMTTRrsZKLK8nR msCAwzyQ==; 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 1eldyF-0004Ap-OQ; Tue, 13 Feb 2018 17:02:19 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eldxQ-0003Ze-50 for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2018 17:01:30 +0000 Received: by mail-wm0-x241.google.com with SMTP id r71so17415796wmd.1 for ; Tue, 13 Feb 2018 09:01:20 -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=jhdcbiKz2Td+mlYElzEBOMwo944IbX1u5Rx7uh5b5sQ=; b=jZjpP19oaUKiRQ3yvuNj43pVPFydEkpM1Dtf0M64tKMKA4OI5gP0Dz7wJy/QHPm+wb 2x5yKCFLI56gE/MJSXyVyJ00aFordYlTu6ss2lj6RC7BxwbzgzjR5XlHORXAyAZlzxaY miwqcSvY9tJZI5WjAG9QTIUJsxQN5C6gkrC7I= 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=jhdcbiKz2Td+mlYElzEBOMwo944IbX1u5Rx7uh5b5sQ=; b=MoLQU42zpvbYRt4oZ3BAWvO/V3ZQZPG6UC82cKrB2aFQ4XM4LQcIgAm1VYNlZF8EXv nZZzLONKULd7idxI2uD3N3vXCyj0+VHlPSYW2QAC56oL7nAo9RTNdHQvZr0DgFXxviN/ Bl/K3U5kjVlzEv5C8HzXEy0J+idkLtntikB1Afw66GWR6UMXCjRCajBvakuezhYhQXUr gpBAy1GC3v8TMGY6xk4RE+cJcRoRLYYO/DGBsRxCi/SAKBB80S49+XF6SQgyFgIhwPND EaAlJKCpnSthoZum5Og1gpBnbHiSUU/yVqyJ4i0Zya/r6uPJ0Qqg3apJ9CvKSefXi1XB mVgg== X-Gm-Message-State: APf1xPA3pKUrHaUewNJu0hJsPtZnXFQOy36lVlL0Z+P5qw9ARe6GO3dx hwU68OvcQdzXe4KSJ5hxr4QjRA== X-Google-Smtp-Source: AH8x2249jcBSU3miTlwngTAj/w1h8n0Hah8iRtrNLJTKO9ykgy3g/XQS0iCsRv6QDEr+HADJUNGzBA== X-Received: by 10.28.113.150 with SMTP id d22mr1816629wmi.127.1518541279020; Tue, 13 Feb 2018 09:01:19 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 09:01:18 -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 03/25] ASoC: qcom: qdsp6: Add common qdsp6 helper functions Date: Tue, 13 Feb 2018 16:58:15 +0000 Message-Id: <20180213165837.1620-4-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_090128_239669_9C314975 X-CRM114-Status: GOOD ( 18.12 ) 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 some common helper functions like translating dsp error to linux error codes and channel mappings etc. These functions are used in all the following qdsp6 drivers. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 14 ++++++ sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6dsp-common.c | 67 +++++++++++++++++++++++++ sound/soc/qcom/qdsp6/q6dsp-common.h | 24 +++++++++ sound/soc/qcom/qdsp6/q6dsp-errno.h | 97 +++++++++++++++++++++++++++++++++++++ 5 files changed, 203 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/Makefile create mode 100644 sound/soc/qcom/qdsp6/q6dsp-common.c create mode 100644 sound/soc/qcom/qdsp6/q6dsp-common.h create mode 100644 sound/soc/qcom/qdsp6/q6dsp-errno.h diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 8ec9a074b38b..b01f347b427d 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -43,3 +43,17 @@ config SND_SOC_APQ8016_SBC Support for Qualcomm Technologies LPASS audio block in APQ8016 SOC-based systems. Say Y if you want to use audio devices on MI2S. + +config SND_SOC_QDSP6_COMMON + tristate + default n + +config SND_SOC_QDSP6 + tristate "SoC ALSA audio driver for QDSP6" + depends on QCOM_APR && HAS_DMA + select SND_SOC_QDSP6_COMMON + help + To add support for MSM QDSP6 Soc Audio. + This will enable sound soc platform specific + audio drivers. This includes q6asm, q6adm, + q6afe interfaces to DSP using apr. diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile new file mode 100644 index 000000000000..accebdb49306 --- /dev/null +++ b/sound/soc/qcom/qdsp6/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o diff --git a/sound/soc/qcom/qdsp6/q6dsp-common.c b/sound/soc/qcom/qdsp6/q6dsp-common.c new file mode 100644 index 000000000000..3fe5b7942c4c --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6dsp-common.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2011-2017, The Linux Foundation + * Copyright (c) 2018, Linaro Limited + */ +#include "q6dsp-common.h" +#include +#include +#include +#include + +int q6dsp_map_channels(u8 ch_map[PCM_FORMAT_MAX_NUM_CHANNEL], int ch) +{ + memset(ch_map, 0, PCM_FORMAT_MAX_NUM_CHANNEL); + + switch (ch) { + case 1: + ch_map[0] = PCM_CHANNEL_FC; + break; + case 2: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + break; + case 3: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + ch_map[2] = PCM_CHANNEL_FC; + break; + case 4: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + ch_map[2] = PCM_CHANNEL_LS; + ch_map[3] = PCM_CHANNEL_RS; + break; + case 5: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + ch_map[2] = PCM_CHANNEL_FC; + ch_map[3] = PCM_CHANNEL_LS; + ch_map[4] = PCM_CHANNEL_RS; + break; + case 6: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + ch_map[2] = PCM_CHANNEL_LFE; + ch_map[3] = PCM_CHANNEL_FC; + ch_map[4] = PCM_CHANNEL_LS; + ch_map[5] = PCM_CHANNEL_RS; + break; + case 8: + ch_map[0] = PCM_CHANNEL_FL; + ch_map[1] = PCM_CHANNEL_FR; + ch_map[2] = PCM_CHANNEL_LFE; + ch_map[3] = PCM_CHANNEL_FC; + ch_map[4] = PCM_CHANNEL_LS; + ch_map[5] = PCM_CHANNEL_RS; + ch_map[6] = PCM_CHANNEL_LB; + ch_map[7] = PCM_CHANNEL_RB; + break; + default: + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(q6dsp_map_channels); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/qcom/qdsp6/q6dsp-common.h b/sound/soc/qcom/qdsp6/q6dsp-common.h new file mode 100644 index 000000000000..32386f4a6432 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6dsp-common.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef __Q6DSP_COMMON_H__ +#define __Q6DSP_COMMON_H__ + +#include + +#define PCM_FORMAT_MAX_NUM_CHANNEL 8 +#define PCM_CHANNEL_NULL 0 + +#define PCM_CHANNEL_FL 1 /* Front left channel. */ +#define PCM_CHANNEL_FR 2 /* Front right channel. */ +#define PCM_CHANNEL_FC 3 /* Front center channel. */ +#define PCM_CHANNEL_LS 4 /* Left surround channel. */ +#define PCM_CHANNEL_RS 5 /* Right surround channel. */ +#define PCM_CHANNEL_LFE 6 /* Low frequency effect channel. */ +#define PCM_CHANNEL_CS 7 /* Center surround channel; Rear center ch */ +#define PCM_CHANNEL_LB 8 /* Left back channel; Rear left channel. */ +#define PCM_CHANNEL_RB 9 /* Right back channel; Rear right channel. */ +#define PCM_CHANNELS 10 /* Top surround channel. */ + +int q6dsp_map_channels(u8 ch_map[PCM_FORMAT_MAX_NUM_CHANNEL], int ch); + +#endif /* __Q6DSP_COMMON_H__ */ diff --git a/sound/soc/qcom/qdsp6/q6dsp-errno.h b/sound/soc/qcom/qdsp6/q6dsp-errno.h new file mode 100644 index 000000000000..763c19bb4a13 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6dsp-errno.h @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef __Q6DSP_ERR_NO_H__ +#define __Q6DSP_ERR_NO_H__ +#include + +/* Success. The operation completed with no errors. */ +#define ADSP_EOK 0x00000000 +/* General failure. */ +#define ADSP_EFAILED 0x00000001 +/* Bad operation parameter. */ +#define ADSP_EBADPARAM 0x00000002 +/* Unsupported routine or operation. */ +#define ADSP_EUNSUPPORTED 0x00000003 +/* Unsupported version. */ +#define ADSP_EVERSION 0x00000004 +/* Unexpected problem encountered. */ +#define ADSP_EUNEXPECTED 0x00000005 +/* Unhandled problem occurred. */ +#define ADSP_EPANIC 0x00000006 +/* Unable to allocate resource. */ +#define ADSP_ENORESOURCE 0x00000007 +/* Invalid handle. */ +#define ADSP_EHANDLE 0x00000008 +/* Operation is already processed. */ +#define ADSP_EALREADY 0x00000009 +/* Operation is not ready to be processed. */ +#define ADSP_ENOTREADY 0x0000000A +/* Operation is pending completion. */ +#define ADSP_EPENDING 0x0000000B +/* Operation could not be accepted or processed. */ +#define ADSP_EBUSY 0x0000000C +/* Operation aborted due to an error. */ +#define ADSP_EABORTED 0x0000000D +/* Operation preempted by a higher priority. */ +#define ADSP_EPREEMPTED 0x0000000E +/* Operation requests intervention to complete. */ +#define ADSP_ECONTINUE 0x0000000F +/* Operation requests immediate intervention to complete. */ +#define ADSP_EIMMEDIATE 0x00000010 +/* Operation is not implemented. */ +#define ADSP_ENOTIMPL 0x00000011 +/* Operation needs more data or resources. */ +#define ADSP_ENEEDMORE 0x00000012 +/* Operation does not have memory. */ +#define ADSP_ENOMEMORY 0x00000014 +/* Item does not exist. */ +#define ADSP_ENOTEXIST 0x00000015 +/* Max count for adsp error code sent to HLOS*/ + +struct q6dsp_err_code { + int lnx_err_code; + char *adsp_err_str; +}; + +static struct q6dsp_err_code q6dsp_err_codes[] = { + [ADSP_EFAILED] = { -ENOTRECOVERABLE, "ADSP_EFAILED"}, + [ADSP_EBADPARAM] = { -EINVAL, "ADSP_EBADPARAM"}, + [ADSP_EUNSUPPORTED] = { -ENOSYS, "ADSP_EUNSUPPORTED"}, + [ADSP_EVERSION] = { -ENOPROTOOPT, "ADSP_EVERSION"}, + [ADSP_EUNEXPECTED] = { -ENOTRECOVERABLE, "ADSP_EUNEXPECTED"}, + [ADSP_EPANIC] = { -ENOTRECOVERABLE, "ADSP_EPANIC"}, + [ADSP_ENORESOURCE] = { -ENOSPC, "ADSP_ENORESOURCE"}, + [ADSP_EHANDLE] = { -EBADR, "ADSP_EHANDLE"}, + [ADSP_EALREADY] = { -EALREADY, "ADSP_EALREADY"}, + [ADSP_ENOTREADY] = { -EPERM, "ADSP_ENOTREADY"}, + [ADSP_EPENDING] = { -EINPROGRESS, "ADSP_EPENDING"}, + [ADSP_EBUSY] = { -EBUSY, "ADSP_EBUSY"}, + [ADSP_EABORTED] = { -ECANCELED, "ADSP_EABORTED"}, + [ADSP_EPREEMPTED] = { -EAGAIN, "ADSP_EPREEMPTED"}, + [ADSP_ECONTINUE] = { -EAGAIN, "ADSP_ECONTINUE"}, + [ADSP_EIMMEDIATE] = { -EAGAIN, "ADSP_EIMMEDIATE"}, + [ADSP_ENOTIMPL] = { -EAGAIN, "ADSP_ENOTIMPL"}, + [ADSP_ENEEDMORE] = { -ENODATA, "ADSP_ENEEDMORE"}, + [ADSP_ENOMEMORY] = { -EINVAL, "ADSP_ENOMEMORY"}, + [ADSP_ENOTEXIST] = { -ENOENT, "ADSP_ENOTEXIST"}, +}; + +static inline int q6dsp_errno(u32 error) +{ + int ret = -EINVAL; + + if (error <= ARRAY_SIZE(q6dsp_err_codes)) + ret = q6dsp_err_codes[error].lnx_err_code; + + return ret; +} + +static inline char *q6dsp_strerror(u32 error) +{ + if (error <= ARRAY_SIZE(q6dsp_err_codes)) + return q6dsp_err_codes[error].adsp_err_str; + + return "ADSP_ERR_MAX"; +} + +#endif /*__Q6DSP_ERR_NO_H__ */