From patchwork Wed Jul 14 15:30:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476796 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676383jao; Wed, 14 Jul 2021 08:31:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS3ILERsHhETt9HgnUqHyRau9asM3JSV6ldrGDEhj3L+HMb227Sh0hsh6pfeF3bwqpWUpP X-Received: by 2002:a05:6e02:c7:: with SMTP id r7mr7083323ilq.52.1626276664685; Wed, 14 Jul 2021 08:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276664; cv=none; d=google.com; s=arc-20160816; b=ijSPLKp213y6gPdAwPmDvvfDdQrpHTd7cAchhAt1D39RpORBovVqJZ0+YiXFrxkIpA /vM4AJWvQdv7hkiQLMh/zJtF/ocJc+oRcoS6ecIbQMStDBNfL64XYiAr209r2lyPnp4l GcD9h4bFLvY9sjfA9u97CGwYjLj16cySpCJypSf1depYK01TH5TJg6Kv0a7HnKAtjPdp BM6b6hGCAQqo86N6YLtTVAT+6Eyv4p20LhpHhIo1qQLaJksRD5jQhrvv//sx0LfDMvrY zpk6PDavz+jJhN3iefNrJChuNENL2+r87Y9Lex7thPgtU2+VdZt7VFlZiPcCNu1p37/3 L7fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xiCF2nRgXBkkZxRW+nKblAu8sGXdLERpAmm5UZ/e/m8=; b=d4c0ZD0uT5732KPzm8lpq02g5rrHnOi+VY4XdCHZfbcFP1NBOjP7WJ3ADrf0NW+e+s c6XfCJj2jdYb4sHNdJKWtZ2DweSKhUamPk2y7Q3T9YavFwDIW7WFGhpofENt2K2CpbUv cuuAe43QscOC82uBwn7UQeo5Lt7NWEt6mRPuKSQ+26bfWNl61/p2uSmEMpDKJ7UJM+EM RBaKc0H0zFeaCf9soxG3BvdkvKiwP1umTYEYyCZ14CqgBhAoLIcM7qkM/pzkD2oBfl1m HjHr3JEkRzbJWG+hM5EfXJXJY8qOaoWT3XbB3p2XMUkqfABw2m41veCcPUHGwMvOhPkJ hGJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRhSOcNw; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.04; Wed, 14 Jul 2021 08:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRhSOcNw; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239650AbhGNPdt (ORCPT + 7 others); Wed, 14 Jul 2021 11:33:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239607AbhGNPdt (ORCPT ); Wed, 14 Jul 2021 11:33:49 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C37F5C06175F for ; Wed, 14 Jul 2021 08:30:56 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id n4so1862568wms.1 for ; Wed, 14 Jul 2021 08:30:56 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=xiCF2nRgXBkkZxRW+nKblAu8sGXdLERpAmm5UZ/e/m8=; b=SRhSOcNwWN+ksk7Vs4KchDJ5/wH8TgYYFftErjY+9pbOkYNwDha7sNoYZzFCOjEfZc lY1Dw+HqNQ8AeiorkcGTa5q2YsGSgM//zTCf4DONWjgNRuN8RgK9qSi6aMfR9NlapphG hsimlLmoze5ccvvySMp4Dou4BUjHp6MMGbXq2gvMyECV7Tfh+hBr+BQbAS0JFTM95Orz K46foeXTtB2XGa/aB9Ip4syGkC/ulMZba2MyYBBbp16TP+DN2i7yGM2Sbywp6AAzMuXq Gt2UJg2fWZAuRCMt+oX7eBebrMAi3BtUJIepBy4DNWc7s3A5IC+EknMgD7u8VlnUhOu4 gpUA== 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:mime-version:content-transfer-encoding; bh=xiCF2nRgXBkkZxRW+nKblAu8sGXdLERpAmm5UZ/e/m8=; b=jKFG8/V7Nt+MSFiEo/uyuYI+SK/U45VxKcW+ocb0G1YEgdek1ZrQKL5ALtPHHGYVws 5RfmeoFUWfrVHhPCRn6Xk8OgqS0jUwS34oaKtvbCGfOX9Ej07SslPswHqv30OgqvlKR+ J1dxJDjMMV8Xs+uuQ1SFY75Z+da9qMsGuRVoowXargKiBklOyuigiFaCEBR1tJV6ABbC vEWCIy961qtZmiK2bLXOxuf6+0rAUDnDuYHhFB7jVo3lCCFCYjN6M0Cr9GU5kg/X5gQc aFpCMjrmNixLvJBu1xlDe7+R+Gga2fjw2qfg7t6mdZtNAQdiuzvjpWXtv44WhduRyCij vq+A== X-Gm-Message-State: AOAM53218HH70aO/OwgdDwEiEqttv44Hd7F1cXiiFQ/EhtveWyci/wDW 2qfOF5Q5af7rM9ZZxPOLyYgiK/n5WELrdw== X-Received: by 2002:a05:600c:3b93:: with SMTP id n19mr4770604wms.3.1626276655306; Wed, 14 Jul 2021 08:30:55 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:30:54 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 01/16] soc: dt-bindings: qcom: add gpr bindings Date: Wed, 14 Jul 2021 16:30:24 +0100 Message-Id: <20210714153039.28373-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Qualcomm Generic Packet router aka GPR is the IPC mechanism found in AudioReach next generation signal processing framework to perform command and response messages between various processors. GPR has concepts of static and dynamic port, all static services like APM (Audio Processing Manager), PRM (Proxy resource manager) have fixed port numbers where as dynamic services like graphs have dynamic port numbers which are allocated at runtime. All GPR packet messages will have source and destination domain and port along with opcode and payload. Signed-off-by: Srinivas Kandagatla --- .../bindings/soc/qcom/qcom,gpr.yaml | 83 +++++++++++++++++++ include/dt-bindings/soc/qcom,gpr.h | 18 ++++ 2 files changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,gpr.yaml create mode 100644 include/dt-bindings/soc/qcom,gpr.h -- 2.21.0 diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,gpr.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,gpr.yaml new file mode 100644 index 000000000000..d6dda44b655e --- /dev/null +++ b/Documentation/devicetree/bindings/soc/qcom/qcom,gpr.yaml @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/soc/qcom/qcom,gpr.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Qualcomm Generic Packet Router binding + +maintainers: + - Srinivas Kandagatla + +description: | + This binding describes the Qualcomm Generic Packet Router,Shared Memory Manager, + used to send and receive packets between Audio DSP and Application processor. + +properties: + compatible: + const: qcom,gpr + + qcom,glink-channels: + const: adsp_apps + description: + glink channel associated with gpr function + + qcom,protection-domain: + $ref: /schemas/types.yaml#/definitions/string-array + description: protection domain service name and path for gpr service + has dependency on. + items: + - const: avs/audio + - const: msm/adsp/audio_pd + + qcom,gpr-domain: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [1, 2, 3] + description: + Selects the processor domain for gpr + 1 = Modem Domain + 2 = Audio DSP Domain + 3 = Application Processor Domain + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +#GPR Services +patternProperties: + 'gprservice@[0-9]+$': + type: object + description: + GPR node's client devices use subnodes for desired static port services. + + properties: + reg: + maxItems: 1 + description: Service port id + + additionalProperties: false + +required: + - compatible + - qcom,glink-channels + - qcom,gpr-domain + +additionalProperties: false + +examples: + - | + #include + gpr { + compatible = "qcom,gpr"; + qcom,glink-channels = "adsp_apps"; + qcom,gpr-domain = ; + qcom,protection-domain = "avs/audio", "msm/adsp/audio_pd"; + #address-cells = <1>; + #size-cells = <0>; + + gprservice@1 { + reg = ; + }; + }; diff --git a/include/dt-bindings/soc/qcom,gpr.h b/include/dt-bindings/soc/qcom,gpr.h new file mode 100644 index 000000000000..1c68906e079c --- /dev/null +++ b/include/dt-bindings/soc/qcom,gpr.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DT_BINDINGS_QCOM_GPR_H +#define __DT_BINDINGS_QCOM_GPR_H + +/* DOMAINS */ + +#define GPR_DOMAIN_ID_MODEM 1 +#define GPR_DOMAIN_ID_ADSP 2 +#define GPR_DOMAIN_ID_APPS 3 + +/* Static Services */ + +#define GPR_APM_MODULE_IID 1 +#define GPR_PRM_MODULE_IID 2 +#define GPR_AMDB_MODULE_IID 3 +#define GPR_VCPM_MODULE_IID 4 + +#endif /* __DT_BINDINGS_QCOM_GPR_H */ From patchwork Wed Jul 14 15:30:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476797 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676423jao; Wed, 14 Jul 2021 08:31:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhG+f+aBTCgbpkPZo1QUYsfa9cpKCHH+4pvPDl7h2Y7XFBF8uVpOMcn3c0y636lGVNVtmp X-Received: by 2002:a92:d8d1:: with SMTP id l17mr6908367ilo.187.1626276666971; Wed, 14 Jul 2021 08:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276666; cv=none; d=google.com; s=arc-20160816; b=os4+ozJirAUvPomaNpvKPNGZFwa4MJIe+JScs32pxktLU7S/QTMoe31JvVCnG6rxUZ rbM/osRD85aOpfEc6nMynYhktVYrLmXCF1iGzOG2v8ZIMtWoLu22qETKQ4xNnjPaTfT3 AJQj8YceRzh3/lhyKHtZ5WWTnVgPkA0fjsXL+IUqsaEEwEMnHi3BxqPw/bzDOOH9zcTz V5zBIBfDfcLUALZ5LILvNSYIpWVCl1dxL/xcxN+iAmzDnc81YlYRXChtS44pPaILB8cM omowho1axTsoVSI32/PDyjAFiULGP79apqyMd1QqXmC6I4+5tT3aeQi1Dmy5TWkEVK4v 4uwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n2fQXlbWm/XbP2BcHl2KzS0fs/PMFgpzjb1GFrIF3YE=; b=skc06++4j5COOs2BVxpVod0+3YX1Q54JE+sb3NNnoZDlN1R+cFyB8q2fflgXB6PVCK t4uNTpLLnDSsmrjRwV1qY9v6uCIcbQOOsXNRWLXixlA/R1Ft6/GlfOyJ6TMNfmZg8kQP L5tNYfD1pmuOV6fATGbOAPpTaoCHMkyPYwlbjSaXn8Ppt0wQOqwRLg8FzK9xNdYuUJ0+ M6Nqdvr9BRdKD1D6lGcek4DWSolmn1gut2VuVbD50n8Ymyki5qC2BQ9kFcNJI/PihIfJ Tp3cFVjuS9ORxpvy42z6ZPQW/O5AkCbjg1j8vHouR/VrihkFeOYy+9NdMHH49vOEnkps QoUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l7BBoh0C; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.06; Wed, 14 Jul 2021 08:31:06 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l7BBoh0C; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239688AbhGNPdu (ORCPT + 7 others); Wed, 14 Jul 2021 11:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239647AbhGNPdu (ORCPT ); Wed, 14 Jul 2021 11:33:50 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0C6C061762 for ; Wed, 14 Jul 2021 08:30:57 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d2so3811128wrn.0 for ; Wed, 14 Jul 2021 08:30:57 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=n2fQXlbWm/XbP2BcHl2KzS0fs/PMFgpzjb1GFrIF3YE=; b=l7BBoh0CaxG4Xt9f7uqJmc/mSOH4nWIh2chVOkwEfOqQt/IaOd0gmww++CUXmPVjjE L1m+jLsyBr/q4QIazlruSRt+P9eM5ps5YVCevd5Z3sESuVTUssHBel6LEBcZ/Kn8aHJi xtoQGEZipYEzZX6n8pNeZGPhoau6GxjHypdIXWgB/ab0iYsztLWhoi3wA+BP7JwMW/6B SgnT788RrM4HYdArQ9prs0SongTCT/LN5KpAUw1PLsWUXrp/V0BPIS3WUa9YaaEabLae 11/9XbPcTizazNx0ZvKUob+ZBuaVj+BddkLDE9tCNLoS7FGalyzDodCJ8VGrg8eKoafh rt0Q== 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:mime-version:content-transfer-encoding; bh=n2fQXlbWm/XbP2BcHl2KzS0fs/PMFgpzjb1GFrIF3YE=; b=JyQXYht0vQaTVbROwhqBcrP324XtJPA9iAfB1pKWeEKJhs75Zfev5TxQhpmVdB2oZz QgcALDvNMHY2jJ6fkqAURtAgxJL86H5p6oRNU4lHRPxJ1NZ8d/ONmzKH86EpSpNnbEX6 /37jBvEJXLxl7VVX321xlNaTaylBIgxolIf7QpkbJ9Zujk0RW3DM3a1XniouD7YAFwZe Qp7uay1C00aq0N+BnKlnusoeKcHPwdYiWvCk7QW9Ng+pBpKmshISNBfk5mBchsEyrPkS mO5WmyXbT3LTRrcKwpxOFxU9nlWmAae2QWlxnzms+mySetJKpJA7JmLHb5rdsnAA/iAX 8eZw== X-Gm-Message-State: AOAM532RV5THmUGMLnWbwlRS3kNkemVdcgfpUTqDBJVqEdbplPgFAeWe mX17zi449Svd2aegkuhi/7GzbA== X-Received: by 2002:a5d:5048:: with SMTP id h8mr13989089wrt.292.1626276656505; Wed, 14 Jul 2021 08:30:56 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:30:56 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 02/16] soc: qcom: apr: make code more reuseable Date: Wed, 14 Jul 2021 16:30:25 +0100 Message-Id: <20210714153039.28373-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org APR and other packet routers like GPR are pretty much same and interact with other drivers in similar way. Ex: GPR ports can be considered as APR services, only difference is they are allocated dynamically. Other difference is packet layout, which should not matter with the apis abstracted. Apart from this the rest of the functionality is pretty much identical across APR and GPR. Make the apr code more reusable by abstracting it service level, rather than device level so that we do not need to write new drivers for other new packet routers like GPR. This patch is in preparation to add GPR support to this driver. Signed-off-by: Srinivas Kandagatla --- drivers/soc/qcom/apr.c | 113 +++++++++++++++++++++-------------- include/linux/soc/qcom/apr.h | 11 +++- 2 files changed, 79 insertions(+), 45 deletions(-) -- 2.21.0 Reported-by: kernel test robot diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 7abfc8c4fdc7..ef49d26c6848 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -15,13 +15,18 @@ #include #include -struct apr { +enum { + PR_TYPE_APR = 0, +}; + +struct packet_router { struct rpmsg_endpoint *ch; struct device *dev; spinlock_t svcs_lock; spinlock_t rx_lock; struct idr svcs_idr; int dest_domain_id; + int type; struct pdr_handle *pdr; struct workqueue_struct *rxwq; struct work_struct rx_work; @@ -44,21 +49,21 @@ struct apr_rx_buf { */ int apr_send_pkt(struct apr_device *adev, struct apr_pkt *pkt) { - struct apr *apr = dev_get_drvdata(adev->dev.parent); + struct packet_router *apr = dev_get_drvdata(adev->dev.parent); struct apr_hdr *hdr; unsigned long flags; int ret; - spin_lock_irqsave(&adev->lock, flags); + spin_lock_irqsave(&adev->svc.lock, flags); hdr = &pkt->hdr; hdr->src_domain = APR_DOMAIN_APPS; - hdr->src_svc = adev->svc_id; + hdr->src_svc = adev->svc.id; hdr->dest_domain = adev->domain_id; - hdr->dest_svc = adev->svc_id; + hdr->dest_svc = adev->svc.id; ret = rpmsg_trysend(apr->ch, pkt, hdr->pkt_size); - spin_unlock_irqrestore(&adev->lock, flags); + spin_unlock_irqrestore(&adev->svc.lock, flags); return ret ? ret : hdr->pkt_size; } @@ -74,7 +79,7 @@ static void apr_dev_release(struct device *dev) static int apr_callback(struct rpmsg_device *rpdev, void *buf, int len, void *priv, u32 addr) { - struct apr *apr = dev_get_drvdata(&rpdev->dev); + struct packet_router *apr = dev_get_drvdata(&rpdev->dev); struct apr_rx_buf *abuf; unsigned long flags; @@ -100,8 +105,7 @@ static int apr_callback(struct rpmsg_device *rpdev, void *buf, return 0; } - -static int apr_do_rx_callback(struct apr *apr, struct apr_rx_buf *abuf) +static int apr_do_rx_callback(struct packet_router *apr, struct apr_rx_buf *abuf) { uint16_t hdr_size, msg_type, ver, svc_id; struct apr_device *svc = NULL; @@ -171,13 +175,19 @@ static int apr_do_rx_callback(struct apr *apr, struct apr_rx_buf *abuf) static void apr_rxwq(struct work_struct *work) { - struct apr *apr = container_of(work, struct apr, rx_work); + struct packet_router *apr = container_of(work, struct packet_router, rx_work); struct apr_rx_buf *abuf, *b; unsigned long flags; if (!list_empty(&apr->rx_list)) { list_for_each_entry_safe(abuf, b, &apr->rx_list, node) { - apr_do_rx_callback(apr, abuf); + switch (apr->type) { + case PR_TYPE_APR: + apr_do_rx_callback(apr, abuf); + break; + default: + break; + } spin_lock_irqsave(&apr->rx_lock, flags); list_del(&abuf->node); spin_unlock_irqrestore(&apr->rx_lock, flags); @@ -201,7 +211,7 @@ static int apr_device_match(struct device *dev, struct device_driver *drv) while (id->domain_id != 0 || id->svc_id != 0) { if (id->domain_id == adev->domain_id && - id->svc_id == adev->svc_id) + id->svc_id == adev->svc.id) return 1; id++; } @@ -221,14 +231,14 @@ static int apr_device_remove(struct device *dev) { struct apr_device *adev = to_apr_device(dev); struct apr_driver *adrv; - struct apr *apr = dev_get_drvdata(adev->dev.parent); + struct packet_router *apr = dev_get_drvdata(adev->dev.parent); if (dev->driver) { adrv = to_apr_driver(dev->driver); if (adrv->remove) adrv->remove(adev); spin_lock(&apr->svcs_lock); - idr_remove(&apr->svcs_idr, adev->svc_id); + idr_remove(&apr->svcs_idr, adev->svc.id); spin_unlock(&apr->svcs_lock); } @@ -257,28 +267,39 @@ struct bus_type aprbus = { EXPORT_SYMBOL_GPL(aprbus); static int apr_add_device(struct device *dev, struct device_node *np, - const struct apr_device_id *id) + u32 svc_id, u32 domain_id) { - struct apr *apr = dev_get_drvdata(dev); + struct packet_router *apr = dev_get_drvdata(dev); struct apr_device *adev = NULL; + struct pkt_router_svc *svc; int ret; adev = kzalloc(sizeof(*adev), GFP_KERNEL); if (!adev) return -ENOMEM; - spin_lock_init(&adev->lock); + adev->svc_id = svc_id; + svc = &adev->svc; + + svc->id = svc_id; + svc->pr = apr; + svc->priv = adev; + svc->dev = dev; + spin_lock_init(&svc->lock); + + adev->domain_id = domain_id; - adev->svc_id = id->svc_id; - adev->domain_id = id->domain_id; - adev->version = id->svc_version; if (np) snprintf(adev->name, APR_NAME_SIZE, "%pOFn", np); - else - strscpy(adev->name, id->name, APR_NAME_SIZE); - dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name, - id->domain_id, id->svc_id); + switch (apr->type) { + case PR_TYPE_APR: + dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name, + domain_id, svc_id); + break; + default: + break; + } adev->dev.bus = &aprbus; adev->dev.parent = dev; @@ -287,8 +308,7 @@ static int apr_add_device(struct device *dev, struct device_node *np, adev->dev.driver = NULL; spin_lock(&apr->svcs_lock); - idr_alloc(&apr->svcs_idr, adev, id->svc_id, - id->svc_id + 1, GFP_ATOMIC); + idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC); spin_unlock(&apr->svcs_lock); of_property_read_string_index(np, "qcom,protection-domain", @@ -308,7 +328,7 @@ static int apr_add_device(struct device *dev, struct device_node *np, static int of_apr_add_pd_lookups(struct device *dev) { const char *service_name, *service_path; - struct apr *apr = dev_get_drvdata(dev); + struct packet_router *apr = dev_get_drvdata(dev); struct device_node *node; struct pdr_service *pds; int ret; @@ -338,13 +358,14 @@ static int of_apr_add_pd_lookups(struct device *dev) static void of_register_apr_devices(struct device *dev, const char *svc_path) { - struct apr *apr = dev_get_drvdata(dev); + struct packet_router *apr = dev_get_drvdata(dev); struct device_node *node; const char *service_path; int ret; for_each_child_of_node(dev->of_node, node) { - struct apr_device_id id = { {0} }; + u32 svc_id; + u32 domain_id; /* * This function is called with svc_path NULL during @@ -374,13 +395,13 @@ static void of_register_apr_devices(struct device *dev, const char *svc_path) continue; } - if (of_property_read_u32(node, "reg", &id.svc_id)) + if (of_property_read_u32(node, "reg", &svc_id)) continue; - id.domain_id = apr->dest_domain_id; + domain_id = apr->dest_domain_id; - if (apr_add_device(dev, node, &id)) - dev_err(dev, "Failed to add apr %d svc\n", id.svc_id); + if (apr_add_device(dev, node, svc_id, domain_id)) + dev_err(dev, "Failed to add apr %d svc\n", svc_id); } } @@ -400,7 +421,7 @@ static int apr_remove_device(struct device *dev, void *svc_path) static void apr_pd_status(int state, char *svc_path, void *priv) { - struct apr *apr = (struct apr *)priv; + struct packet_router *apr = (struct packet_router *)priv; switch (state) { case SERVREG_SERVICE_STATE_UP: @@ -415,16 +436,20 @@ static void apr_pd_status(int state, char *svc_path, void *priv) static int apr_probe(struct rpmsg_device *rpdev) { struct device *dev = &rpdev->dev; - struct apr *apr; + struct packet_router *apr; int ret; apr = devm_kzalloc(dev, sizeof(*apr), GFP_KERNEL); if (!apr) return -ENOMEM; - ret = of_property_read_u32(dev->of_node, "qcom,apr-domain", &apr->dest_domain_id); + if (of_device_is_compatible(dev->of_node, "qcom,apr")) { + ret = of_property_read_u32(dev->of_node, "qcom,apr-domain", &apr->dest_domain_id); + apr->type = PR_TYPE_APR; + } + if (ret) { - dev_err(dev, "APR Domain ID not specified in DT\n"); + dev_err(dev, "Domain ID not specified in DT\n"); return ret; } @@ -467,7 +492,7 @@ static int apr_probe(struct rpmsg_device *rpdev) static void apr_remove(struct rpmsg_device *rpdev) { - struct apr *apr = dev_get_drvdata(&rpdev->dev); + struct packet_router *apr = dev_get_drvdata(&rpdev->dev); pdr_handle_release(apr->pdr); device_for_each_child(&rpdev->dev, NULL, apr_remove_device); @@ -504,20 +529,20 @@ void apr_driver_unregister(struct apr_driver *drv) } EXPORT_SYMBOL_GPL(apr_driver_unregister); -static const struct of_device_id apr_of_match[] = { +static const struct of_device_id pkt_router_of_match[] = { { .compatible = "qcom,apr"}, { .compatible = "qcom,apr-v2"}, {} }; -MODULE_DEVICE_TABLE(of, apr_of_match); +MODULE_DEVICE_TABLE(of, pkt_router_of_match); -static struct rpmsg_driver apr_driver = { +static struct rpmsg_driver packet_router_driver = { .probe = apr_probe, .remove = apr_remove, .callback = apr_callback, .drv = { .name = "qcom,apr", - .of_match_table = apr_of_match, + .of_match_table = pkt_router_of_match, }, }; @@ -527,7 +552,7 @@ static int __init apr_init(void) ret = bus_register(&aprbus); if (!ret) - ret = register_rpmsg_driver(&apr_driver); + ret = register_rpmsg_driver(&packet_router_driver); else bus_unregister(&aprbus); @@ -537,7 +562,7 @@ static int __init apr_init(void) static void __exit apr_exit(void) { bus_unregister(&aprbus); - unregister_rpmsg_driver(&apr_driver); + unregister_rpmsg_driver(&packet_router_driver); } subsys_initcall(apr_init); diff --git a/include/linux/soc/qcom/apr.h b/include/linux/soc/qcom/apr.h index 137f9f2ac4c3..6dc0e160131b 100644 --- a/include/linux/soc/qcom/apr.h +++ b/include/linux/soc/qcom/apr.h @@ -79,6 +79,15 @@ struct apr_resp_pkt { #define APR_SVC_MAJOR_VERSION(v) ((v >> 16) & 0xFF) #define APR_SVC_MINOR_VERSION(v) (v & 0xFF) +struct packet_router; +struct pkt_router_svc { + struct device *dev; + struct packet_router *pr; + spinlock_t lock; + int id; + void *priv; +}; + struct apr_device { struct device dev; uint16_t svc_id; @@ -86,7 +95,7 @@ struct apr_device { uint32_t version; char name[APR_NAME_SIZE]; const char *service_path; - spinlock_t lock; + struct pkt_router_svc svc; struct list_head node; }; From patchwork Wed Jul 14 15:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476798 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676430jao; Wed, 14 Jul 2021 08:31:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzK4KDzaZ2615ws6uvc1j1cO4F+9Y+VQ0Iaus69eBbIafYEwv/UljcFshIgtaQq91I/st3 X-Received: by 2002:a92:d302:: with SMTP id x2mr7095663ila.161.1626276667262; Wed, 14 Jul 2021 08:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276667; cv=none; d=google.com; s=arc-20160816; b=GgzocHrf3F0jnQMqoVBkD7TomUegmsJuOiV7NC1DqVESBie2Dc0iSQgsjIapuyZZGF Xd5J0FJgYndrJ4c25tCfYUofZUrr+/EGYAlxbFD9U9UHrxkEG9IvwX5aT1obAqhJ/UJ/ XcYFlTzFouuU5EckmasZD+SPKjVs+4YjJjFMB5HAjH6njyHbn2R6b6Xa9A83xJZcmH8V PDbZG1g0SbtPe0NFGGdRCscFNQW/CdLtnzpqeyULEwz+1T3b5kxTRSneQQyCCl067PPQ HMtTvdZlD4pF+bU9QNUDE9LHeFQk/MUm5xQmI9d8tsS2R7+48932b7BuJiDxvhmMifqj rsEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cyAk2v6poN79l/B5El2Lg5vZD9WF0qfTOCiPdf+Otvs=; b=lwYFVRn6Wqq4NZLEqdMfdn5CSL8u6WsmkMpr8ARE6qgIHOyPYoGwzPtHZEnl5JqQ+/ 81cp1KKylffI2sDMcbDnv8gNLTRDrfTB+n0rOI/9roEX8cX2i6JKAA44aS23Mrrio7L7 oOJucynRUdictxZ8Qx2TNnrRYYYLU3b+1G+FaKp5d7OacmpT79CX6oZpxotnE5wTInHj IzjCyC++OyNqbU5ecY+X9ebnoqNUXBB0EAe/Zip0Y/wThX3EDpE4ZcQv5qQg5ycwmjh/ UYWd/D88pJqMygxb1cE+nAolylAAldCV0ROi/iSx+jvY8PLzImdsMcI3KASj5dU6hwb7 kFFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQ81BEeq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.07; Wed, 14 Jul 2021 08:31:07 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQ81BEeq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239701AbhGNPdw (ORCPT + 7 others); Wed, 14 Jul 2021 11:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239693AbhGNPdv (ORCPT ); Wed, 14 Jul 2021 11:33:51 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3423C06175F for ; Wed, 14 Jul 2021 08:30:58 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id u1so3775775wrs.1 for ; Wed, 14 Jul 2021 08:30:58 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=cyAk2v6poN79l/B5El2Lg5vZD9WF0qfTOCiPdf+Otvs=; b=IQ81BEeqHSAOKWWAGUEj0WQM1Y9dLNj45SvUf/i6Fg/S4caLxT3GSgCk2astVt6tGx wTNnrt2lyu548zAuYOe1c5opM3TR7OX09cewGWgWbUKHIO/ppLtB/1aL99wQ4MdnmmOG kreNMt7Y5RVV/b+bi/OjrunewMu/+hO+80yfLCly/sLel7tn47skrRbJTYl6lmLcVf+d gjN8wcUPgeaPbWhMA2EO/nhTzKeYLrmpkNq8RfrUTN0G653S2bk0uze5TdyokKMQii22 aZS04uYdnZI4MagUnzeyCNQflCCctT9WTstTeBcm+ZIP9dVZW7UFpb2nd148Oowos9QT lwcg== 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:mime-version:content-transfer-encoding; bh=cyAk2v6poN79l/B5El2Lg5vZD9WF0qfTOCiPdf+Otvs=; b=rLzc5J8UNYirl1nYLh5KcloGSA4P3R7lJFkXuB8B0PbazSZbZQ81lePEx87PWWREMW JuqK5xwne2BqqfPFYamX2o+7YRGWSyxM3gJ15UkRQnZ3CyqI6fSUTzy87cv6NP6c9yRP wUnLQJMZrtBPOAPC4ZgOsxSbHgcC9fWTcj9gOSYIz7Fgbwn5VRaf18Qf55yNZyy68pmZ hH6danom87atEQJOhCoD78r1rXNXsJUHkU5yhnRsnwgWy2fCzWpD0W2L/g3N0RbL9Q4l +RdJ+TM+XuVfk4jKpw1B1XbP2sku0T8+bHxtEk/sPPDb2MZkwDXGa/WreUdh4gqyr46k OM5A== X-Gm-Message-State: AOAM532pAgQOjDlPTe/8l+6g+r+xJEqLOZE2RnKdVQEbL6+4WbxTN8Ml 2IIj6xF+7atSlACgdVqLm5m9WQ== X-Received: by 2002:adf:facf:: with SMTP id a15mr13664180wrs.39.1626276657504; Wed, 14 Jul 2021 08:30:57 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:30:57 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 03/16] soc: qcom: apr: Add GPR support Date: Wed, 14 Jul 2021 16:30:26 +0100 Message-Id: <20210714153039.28373-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Qualcomm Generic Packet router aka GPR is the IPC mechanism found in AudioReach next generation signal processing framework to perform command and response messages between various processors. GPR has concepts of static and dynamic port, all static services like APM (Audio Processing Manager), PRM (Proxy resource manager) have fixed port numbers where as dynamic services like graphs have dynamic port numbers which are allocated at runtime. All GPR packet messages will have source and destination domain and port along with opcode and payload. Signed-off-by: Srinivas Kandagatla --- drivers/soc/qcom/Kconfig | 8 ++ drivers/soc/qcom/apr.c | 157 ++++++++++++++++++++++++++++++++++- include/linux/soc/qcom/apr.h | 58 +++++++++++++ 3 files changed, 221 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 79b568f82a1c..0b6e6412c98e 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -209,4 +209,12 @@ config QCOM_APR application processor and QDSP6. APR is used by audio driver to configure QDSP6 ASM, ADM and AFE modules. + +config QCOM_GPR + tristate "Qualcomm GPR Bus (Generic Packet Router)" + select QCOM_APR + help + Enable GPR IPC protocol support between + application processor and QDSP6. GPR is + used by audio driver to configure QDSP6. endmenu diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index ef49d26c6848..b8ef77ab993a 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -17,8 +17,13 @@ enum { PR_TYPE_APR = 0, + PR_TYPE_GPR, }; +/* Some random values tbh which does not collide with static modules */ +#define GPR_DYNAMIC_PORT_START 0x10000000 +#define GPR_DYNAMIC_PORT_END 0x20000000 + struct packet_router { struct rpmsg_endpoint *ch; struct device *dev; @@ -69,6 +74,85 @@ int apr_send_pkt(struct apr_device *adev, struct apr_pkt *pkt) } EXPORT_SYMBOL_GPL(apr_send_pkt); +void gpr_free_port(gpr_port_t *port) +{ + struct packet_router *gpr = port->pr; + unsigned long flags; + + spin_lock_irqsave(&gpr->svcs_lock, flags); + idr_remove(&gpr->svcs_idr, port->id); + spin_unlock_irqrestore(&gpr->svcs_lock, flags); + + kfree(port); +} +EXPORT_SYMBOL_GPL(gpr_free_port); + +gpr_port_t *gpr_alloc_port(struct apr_device *gdev, struct device *dev, + gpr_port_cb cb, void *priv) +{ + struct packet_router *pr = dev_get_drvdata(gdev->dev.parent); + gpr_port_t *port; + struct pkt_router_svc *svc; + int id; + + port = kzalloc(sizeof(*port), GFP_KERNEL); + if (!port) + return ERR_PTR(-ENOMEM); + + svc = port; + svc->callback = cb; + svc->pr = pr; + svc->priv = priv; + svc->dev = dev; + spin_lock_init(&svc->lock); + + spin_lock(&pr->svcs_lock); + id = idr_alloc_cyclic(&pr->svcs_idr, svc, GPR_DYNAMIC_PORT_START, + GPR_DYNAMIC_PORT_END, GFP_ATOMIC); + if (id < 0) { + dev_err(dev, "Unable to allocate dynamic GPR src port\n"); + kfree(port); + spin_unlock(&pr->svcs_lock); + return ERR_PTR(-ENOMEM); + } + + svc->id = id; + spin_unlock(&pr->svcs_lock); + + dev_info(dev, "Adding GPR src port (%x)\n", svc->id); + + return port; +} +EXPORT_SYMBOL_GPL(gpr_alloc_port); + +static int pkt_router_send_svc_pkt(struct pkt_router_svc *svc, struct gpr_pkt *pkt) +{ + struct packet_router *pr = svc->pr; + struct gpr_hdr *hdr; + unsigned long flags; + int ret; + + hdr = &pkt->hdr; + + spin_lock_irqsave(&svc->lock, flags); + ret = rpmsg_trysend(pr->ch, pkt, hdr->pkt_size); + spin_unlock_irqrestore(&svc->lock, flags); + + return ret ? ret : hdr->pkt_size; +} + +int gpr_send_pkt(struct apr_device *gdev, struct gpr_pkt *pkt) +{ + return pkt_router_send_svc_pkt(&gdev->svc, pkt); +} +EXPORT_SYMBOL_GPL(gpr_send_pkt); + +int gpr_send_port_pkt(gpr_port_t *port, struct gpr_pkt *pkt) +{ + return pkt_router_send_svc_pkt(port, pkt); +} +EXPORT_SYMBOL_GPL(gpr_send_port_pkt); + static void apr_dev_release(struct device *dev) { struct apr_device *adev = to_apr_device(dev); @@ -173,6 +257,59 @@ static int apr_do_rx_callback(struct packet_router *apr, struct apr_rx_buf *abuf return 0; } +static int gpr_do_rx_callback(struct packet_router *gpr, struct apr_rx_buf *abuf) +{ + uint16_t hdr_size, ver; + struct pkt_router_svc *svc = NULL; + struct gpr_resp_pkt resp; + struct gpr_hdr *hdr; + unsigned long flags; + void *buf = abuf->buf; + int len = abuf->len; + + hdr = buf; + ver = hdr->version; + if (ver > GPR_PKT_VER + 1) + return -EINVAL; + + hdr_size = hdr->hdr_size; + if (hdr_size < GPR_PKT_HEADER_WORD_SIZE) { + dev_err(gpr->dev, "GPR: Wrong hdr size:%d\n", hdr_size); + return -EINVAL; + } + + if (hdr->pkt_size < GPR_PKT_HEADER_BYTE_SIZE || hdr->pkt_size != len) { + dev_err(gpr->dev, "GPR: Wrong packet size\n"); + return -EINVAL; + } + + resp.hdr = *hdr; + resp.payload_size = hdr->pkt_size - (hdr_size * 4); + + /* + * NOTE: hdr_size is not same as GPR_HDR_SIZE as remote can include + * optional headers in to gpr_hdr which should be ignored + */ + if (resp.payload_size > 0) + resp.payload = buf + (hdr_size * 4); + + + spin_lock_irqsave(&gpr->svcs_lock, flags); + svc = idr_find(&gpr->svcs_idr, hdr->dest_port); + spin_unlock_irqrestore(&gpr->svcs_lock, flags); + + if (!svc) { + dev_err(gpr->dev, "GPR: Port(%x) is not registered\n", + hdr->dest_port); + return -EINVAL; + } + + if (svc->callback) + svc->callback(&resp, svc->priv, 0); + + return 0; +} + static void apr_rxwq(struct work_struct *work) { struct packet_router *apr = container_of(work, struct packet_router, rx_work); @@ -185,6 +322,9 @@ static void apr_rxwq(struct work_struct *work) case PR_TYPE_APR: apr_do_rx_callback(apr, abuf); break; + case PR_TYPE_GPR: + gpr_do_rx_callback(apr, abuf); + break; default: break; } @@ -223,8 +363,13 @@ static int apr_device_probe(struct device *dev) { struct apr_device *adev = to_apr_device(dev); struct apr_driver *adrv = to_apr_driver(dev->driver); + int ret; - return adrv->probe(adev); + ret = adrv->probe(adev); + if (!ret) + adev->svc.callback = adrv->gpr_callback; + + return ret; } static int apr_device_remove(struct device *dev) @@ -297,6 +442,10 @@ static int apr_add_device(struct device *dev, struct device_node *np, dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name, domain_id, svc_id); break; + case PR_TYPE_GPR: + dev_set_name(&adev->dev, "gprsvc:%s:%x:%x", adev->name, + domain_id, svc_id); + break; default: break; } @@ -314,7 +463,7 @@ static int apr_add_device(struct device *dev, struct device_node *np, of_property_read_string_index(np, "qcom,protection-domain", 1, &adev->service_path); - dev_info(dev, "Adding APR dev: %s\n", dev_name(&adev->dev)); + dev_info(dev, "Adding APR/GPR dev: %s\n", dev_name(&adev->dev)); ret = device_register(&adev->dev); if (ret) { @@ -446,6 +595,9 @@ static int apr_probe(struct rpmsg_device *rpdev) if (of_device_is_compatible(dev->of_node, "qcom,apr")) { ret = of_property_read_u32(dev->of_node, "qcom,apr-domain", &apr->dest_domain_id); apr->type = PR_TYPE_APR; + } else if (of_device_is_compatible(dev->of_node, "qcom,gpr")) { + ret = of_property_read_u32(dev->of_node, "qcom,gpr-domain", &apr->dest_domain_id); + apr->type = PR_TYPE_GPR; } if (ret) { @@ -532,6 +684,7 @@ EXPORT_SYMBOL_GPL(apr_driver_unregister); static const struct of_device_id pkt_router_of_match[] = { { .compatible = "qcom,apr"}, { .compatible = "qcom,apr-v2"}, + { .compatible = "qcom,gpr"}, {} }; MODULE_DEVICE_TABLE(of, pkt_router_of_match); diff --git a/include/linux/soc/qcom/apr.h b/include/linux/soc/qcom/apr.h index 6dc0e160131b..10024a4ef18e 100644 --- a/include/linux/soc/qcom/apr.h +++ b/include/linux/soc/qcom/apr.h @@ -7,6 +7,7 @@ #include #include #include +#include extern struct bus_type aprbus; @@ -75,19 +76,65 @@ struct apr_resp_pkt { int payload_size; }; +struct gpr_hdr { + uint32_t version:4; + uint32_t hdr_size:4; + uint32_t pkt_size:24; + uint32_t dest_domain:8; + uint32_t src_domain:8; + uint32_t reserved:16; + uint32_t src_port; + uint32_t dest_port; + uint32_t token; + uint32_t opcode; +} __packed; + +struct gpr_pkt { + struct gpr_hdr hdr; + uint32_t payload[0]; +}; + +struct gpr_resp_pkt { + struct gpr_hdr hdr; + void *payload; + int payload_size; +}; + +#define GPR_HDR_SIZE sizeof(struct gpr_hdr) +#define GPR_PKT_VER 0x0 +#define GPR_PKT_HEADER_WORD_SIZE ((sizeof(struct gpr_pkt) + 3) >> 2) +#define GPR_PKT_HEADER_BYTE_SIZE (GPR_PKT_HEADER_WORD_SIZE << 2) + +#define GPR_BASIC_RSP_RESULT 0x02001005 + +struct gpr_ibasic_rsp_result_t { + uint32_t opcode; + uint32_t status; +}; + +#define GPR_BASIC_EVT_ACCEPTED 0x02001006 + +struct gpr_ibasic_rsp_accepted_t { + uint32_t opcode; +}; + /* Bits 0 to 15 -- Minor version, Bits 16 to 31 -- Major version */ #define APR_SVC_MAJOR_VERSION(v) ((v >> 16) & 0xFF) #define APR_SVC_MINOR_VERSION(v) (v & 0xFF) +typedef int (*gpr_port_cb) (struct gpr_resp_pkt *d, void *priv, int op); struct packet_router; struct pkt_router_svc { struct device *dev; + gpr_port_cb callback; struct packet_router *pr; spinlock_t lock; int id; void *priv; }; +typedef struct pkt_router_svc gpr_port_t; + struct apr_device { struct device dev; uint16_t svc_id; @@ -99,6 +146,8 @@ struct apr_device { struct list_head node; }; +typedef struct apr_device gpr_device_t; + #define to_apr_device(d) container_of(d, struct apr_device, dev) struct apr_driver { @@ -106,10 +155,12 @@ struct apr_driver { int (*remove)(struct apr_device *sl); int (*callback)(struct apr_device *a, struct apr_resp_pkt *d); + int (*gpr_callback)(struct gpr_resp_pkt *d, void *data, int op); struct device_driver driver; const struct apr_device_id *id_table; }; +typedef struct apr_driver gpr_driver_t; #define to_apr_driver(d) container_of(d, struct apr_driver, driver) /* @@ -132,7 +183,14 @@ void apr_driver_unregister(struct apr_driver *drv); #define module_apr_driver(__apr_driver) \ module_driver(__apr_driver, apr_driver_register, \ apr_driver_unregister) +#define module_gpr_driver(__gpr_driver) module_apr_driver(__gpr_driver) int apr_send_pkt(struct apr_device *adev, struct apr_pkt *pkt); +gpr_port_t *gpr_alloc_port(gpr_device_t *gdev, struct device *dev, + gpr_port_cb cb, void *priv); +void gpr_free_port(gpr_port_t *port); +int gpr_send_port_pkt(gpr_port_t *port, struct gpr_pkt *pkt); +int gpr_send_pkt(gpr_device_t *gdev, struct gpr_pkt *pkt); + #endif /* __QCOM_APR_H_ */ From patchwork Wed Jul 14 15:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476799 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676461jao; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVUg45H4Bn5lhjFB8PhJNwa/LPSIXqf0QOKMSO9OQ0J2uynOlX0cM7VdY1z0LOQVRoFm3Y X-Received: by 2002:a92:c64a:: with SMTP id 10mr7106855ill.159.1626276669584; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276669; cv=none; d=google.com; s=arc-20160816; b=qF/C1HezwaKP+iMfCxm6IImNITCjtwGAXlG47p7R5HL0OpK6f3Oln38x7tujJIlUX0 qBY4pmlTyHQYQ2NTpwYvPnSE1UoE8SKtTRZodnya+pYMJYNTjFoU5R1V2hfv2OaBYnaY Kkni0jpZN7NYgel4NfruKlFQr4+UBxQY1J87n//w3a+5NXjYZzpLpJOihHK4gBRGl25F t6QK/iTGAWHDwGNLhZ/j56uuIwRAj5yYnR6MqKqu/4cg5p7anpi5Ss6S06szPSRIhMbd z2N8BpiQ8mS+JbprM0YDchE7HX4kW+o+F8g+AD+6wedzKrAJ1cdrxr08hQBc3yo64Jky Tmag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UrNm6WC6FkrE8NCfyfqxMMW9r3LTd4X3kSslIi+iafU=; b=sWhGXOOkyfmmzBq25crRQqZdnebdJr5/OIAot5pcj8v0Q5OoOH7HnD2Dt9RiPtAeIJ grjTK/x7qaXZUUMK+0bZJqoFovqo5/3d4EW/L8h6TTHbGsyagbBRFvC+HuWtXCyI38QW Xiks7Bz3Xqq6X1aFjUHKHRu4Drny1rw3spkyTS3BFMShE6p85l5uuHOAadSThbDKz5gE rz7ARfp7mxOXxu/WjnabmNHMtO9VHCT44uIefQJPDaun0DaeBM9fZeNp4lycoM/jGk2i C7a7lqALSz8uSsBFQoPaplE6pl4nqPVU8z5hPUJsyD3Tw85P9pvY7ns7af1CqaVac7kh iYCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c7nJy1CC; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.09; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c7nJy1CC; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239709AbhGNPd5 (ORCPT + 7 others); Wed, 14 Jul 2021 11:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239686AbhGNPd5 (ORCPT ); Wed, 14 Jul 2021 11:33:57 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EF6FC06175F for ; Wed, 14 Jul 2021 08:31:05 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l8-20020a05600c1d08b02902333d79327aso1085340wms.3 for ; Wed, 14 Jul 2021 08:31:05 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=UrNm6WC6FkrE8NCfyfqxMMW9r3LTd4X3kSslIi+iafU=; b=c7nJy1CCafNyk5ARpsiv/GYzpBo97LDBfVc80FFOF4i68EHkl2hENl466304IAHD8G yYw0pOQteFnLeco5tvonZN3X7BTWQ5jaHKJ14BbQ/WCwLCVoYKxy9Vsjpkvtvs1vx7yO Cn3OI4BJYMEfNhV2v4gMq1XRf/S8GGP7iOFeVjbWbHeeSWjrDQuUJE7gfLsnqV1lFXXu YuXkFpwNiDhAqTr+v/XPB6gzozxExO5smbc2rCTIKbYhxoMqyoE3vqoSHRDSR5eAGExG 49UK23sNKp85mVjdOIe6eOn5fmmypNRHCJQ5/18mPeqLuqp0A8Dhev+MDg0aSSIpdwQw z21w== 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:mime-version:content-transfer-encoding; bh=UrNm6WC6FkrE8NCfyfqxMMW9r3LTd4X3kSslIi+iafU=; b=AHMWe/jdnypG8ajRIOI+A9qtrpDmYmEQ5aY7WO7IDHdlKDEMx2LYBL+8ZJrbUUv+sZ wS9MNg1TBARwXk7zjEWbHZE2leehqkz2PIS09N6iJFIuqBxGTJxdNT7qwM1VTKeJgkMt Qsugp+LtdQD9C5h6cjAa2hy+JpeZBmN6tmjpQ3GkduLGsVNYiIqpVyxbOA3VzBAFbuxP 7InzhlQxbaSttkBBqB2n/OZtYUBfXPJeXsnaTZ44oUAyE9hPfzxyLGQ+eHUuEgMgbjja KP338eLLhkbnf3sv9Qb+j4Vtgv38VRiqUuaSQ25Y+KPAPDVggCUe6ac5k6zqLbW2zrPF BiHA== X-Gm-Message-State: AOAM531WLumwwUPyl5eJL9M5PjMiFkq37CsvpVZ/vPm8BK9Lwke2rvLI XI76tagfU82IC4+fODaMUjkCCQ== X-Received: by 2002:a1c:143:: with SMTP id 64mr11940913wmb.187.1626276658727; Wed, 14 Jul 2021 08:30:58 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:30:58 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 04/16] ASoC: qcom: dt-bindings: add bindings Audio Processing manager Date: Wed, 14 Jul 2021 16:30:27 +0100 Message-Id: <20210714153039.28373-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds bindings support for Qualcomm Audio Processing Manager service in Audio DSP. Audio Process Manager is one of the static service in DSP which is responsible for Command/response handling, graph Management and Control/Event management between modules. Signed-off-by: Srinivas Kandagatla --- .../devicetree/bindings/sound/qcom,q6apm.yaml | 87 +++++++++++++++++++ include/dt-bindings/sound/qcom,q6apm.h | 8 ++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/qcom,q6apm.yaml create mode 100644 include/dt-bindings/sound/qcom,q6apm.h -- 2.21.0 diff --git a/Documentation/devicetree/bindings/sound/qcom,q6apm.yaml b/Documentation/devicetree/bindings/sound/qcom,q6apm.yaml new file mode 100644 index 000000000000..6f27567523a9 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/qcom,q6apm.yaml @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/sound/qcom,q6apm.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Qualcomm Audio Process Manager binding + +maintainers: + - Srinivas Kandagatla + +description: | + This binding describes the Qualcomm Audio Process Manager service in DSP + +properties: + compatible: + const: qcom,q6apm + + reg: + maxItems: 1 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +#APM Services +patternProperties: + 'apm@[0-9]+$': + type: object + description: + APM devices use subnodes for services. + + properties: + compatible: + enum: + - qcom,q6apm-dais + - qcom,q6apm-bedais + + iommus: + maxItems: 1 + + "#sound-dai-cells": + const: 1 + + reg: + maxItems: 1 + + required: + - compatible + - reg + - '#sound-dai-cells' + + additionalProperties: false + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + gpr { + #address-cells = <1>; + #size-cells = <0>; + gprservice@1 { + compatible = "qcom,q6apm"; + reg = <1>; + + #address-cells = <1>; + #size-cells = <0>; + + apm@1 { + compatible = "qcom,q6apm-dais"; + #sound-dai-cells = <1>; + reg = <1>; + }; + + apm@2 { + compatible = "qcom,q6apm-bedais"; + #sound-dai-cells = <1>; + reg = <2>; + }; + }; + }; diff --git a/include/dt-bindings/sound/qcom,q6apm.h b/include/dt-bindings/sound/qcom,q6apm.h new file mode 100644 index 000000000000..3c3987eb6e95 --- /dev/null +++ b/include/dt-bindings/sound/qcom,q6apm.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DT_BINDINGS_Q6_APM_H__ +#define __DT_BINDINGS_Q6_APM_H__ + +/* Audio Process Manager (APM) virtual ports IDs */ +#include + +#endif /* __DT_BINDINGS_Q6_APM_H__ */ From patchwork Wed Jul 14 15:30:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476800 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676495jao; Wed, 14 Jul 2021 08:31:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBJI+Mtc9acakDh+CbRRcpJxcDHkADjFiSOGxVSsY3qGcfg0CYyW5exlLtl4kymh3eK6LK X-Received: by 2002:a92:8712:: with SMTP id m18mr6591615ild.132.1626276671395; Wed, 14 Jul 2021 08:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276671; cv=none; d=google.com; s=arc-20160816; b=0/UWRngqXN2dLgZe5PnaTisbPnARx323Gy1zBq8HgMBcwKRiOtoT8DTND47LK6l/rU a54mWz5rSwzGv0c4TT0qFzvssxKiHRbz4Td4yD0DXBJ/4QDznFZXTC7MuZxPLgwBRljr emkEo/uXBkRCOkAYJ1DfpYZQyA6pUd5jRMqox5Yw4d809ZWBSPWQIHVthQAIU7kb9FIn V+zCrgkO5rsUIKwTkccqdo75++pTK3eDJaY5djj7aX2tjP0Fo5rONE267t6Ww/MXAxqs Tm5f9siBLW/NW78oCNsSpi2crxM/d6d8f5H4euJIVI0HO3wFbZK/6Nr0ELk9Mj/kk8YS 5l6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TOW0xtVmjFZwoE2WPoy9oLyoY5igmiFrh7tl1HYciYs=; b=k71TSdpILvj7KfyMoLZjYbM26bn2jVr0XTC1XkkOyQMxPorLq1hRbZrTVwqltpGwGh ZMDOp/oDAzbTkbd9fbk7Cjt7e5SgBLQJR4KgIEXrIPdAoaU58kgkhCJv9QMaSgffAF7B P+5XHRV8Hu6Ee46uenQzyNcpvbkVgPPNXE5gtSTdQgQlO/L8VKrLXx044zoilNgkXvMW 6FB9Kq6J6qYAioAG5gzRr1onbt02O9jRhRGOYT7CdKAE7TPbzdkGg8GQnIReqnhL9yva Nw0RypJ+q0A2lvnQ5u86S5zH1zyFOrVK3KFSdrNJdpyjN0/n611oTX46RTw48AFAuuZ6 Tkkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Jcvj/hE3"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.11; Wed, 14 Jul 2021 08:31:11 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Jcvj/hE3"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239746AbhGNPd7 (ORCPT + 7 others); Wed, 14 Jul 2021 11:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239743AbhGNPd6 (ORCPT ); Wed, 14 Jul 2021 11:33:58 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7F34C06175F for ; Wed, 14 Jul 2021 08:31:06 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id w13so1847247wmc.3 for ; Wed, 14 Jul 2021 08:31:06 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=TOW0xtVmjFZwoE2WPoy9oLyoY5igmiFrh7tl1HYciYs=; b=Jcvj/hE3Wcpj5K/yQ+mDVCgrCXATUAHqmP5z/UMvEvUqwJh6c7KQVGuT73xBco8n// pF9cozBBuJOuIl9Lt1scJm2OPNYsLSXyrWPDBRc5s90cpyqKv/raTkywMfTtgBP7BJoP ogW51NSHBJZiqjjG/L9+pTwtp01GX7AydumCGvD1/ol7eLRzdAYujjG30WqlzbM3PhWw LueJUY2fOAYZ5K8Kg5mZOP8piQhN69NLDdQLuCkrbtHPxJker/zCKNrynGt1E6UCZ7mG QRyP1N9DzMjwjkoB4n6TrqlZIM5TJIPpUCcFu6CYkLlL0eiWN0FJDZEQzNSC/S1PjBaL xf0A== 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:mime-version:content-transfer-encoding; bh=TOW0xtVmjFZwoE2WPoy9oLyoY5igmiFrh7tl1HYciYs=; b=nB7N2A2YZEAS86Le9CBfwtO6RWZsal6PHohs/esxIQgx8UW741jCHOApW9nP8NDtQ+ Tq5hu4bRzulb+D0qeoLKkQBux/XqNBgtYCBdlxqhTgvYHYOCLBb413FzskamnrRd7sND lzPP3cJiOzoMY4av+n56aACeigenU+Scqr8LXR8pqwbmkw5OHzLSWolBamCopqV9nQ9D DssU+6dqf5nzmG0PKydrsu6ctfvRpyMs1gN0+Vqts7ETi4/4mG7bXd+MZWSY8VlLOzfw j7lb4iKpT4qfHBiHWHdYIleI9TpJPxpYVuKdtxSchwWvtIZrPnxWN4u/pYHpbcSkN3ck iWHQ== X-Gm-Message-State: AOAM5326/TAW2fXd8Bof9I5si0n80uHZDUDCw5HsEhSQ8lM36773b33W N4nKzWYX17w2O8Zy4yWhH9fXhr+MQau1HA== X-Received: by 2002:a1c:63d6:: with SMTP id x205mr12146657wmb.42.1626276665261; Wed, 14 Jul 2021 08:31:05 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:04 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 05/16] ASoC: qcom: audioreach: add basic pkt alloc support Date: Wed, 14 Jul 2021 16:30:28 +0100 Message-Id: <20210714153039.28373-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 6 + sound/soc/qcom/Makefile | 1 + sound/soc/qcom/audioreach/Makefile | 6 + sound/soc/qcom/audioreach/audioreach.c | 272 +++++++++++ sound/soc/qcom/audioreach/audioreach.h | 624 +++++++++++++++++++++++++ 5 files changed, 909 insertions(+) create mode 100644 sound/soc/qcom/audioreach/Makefile create mode 100644 sound/soc/qcom/audioreach/audioreach.c create mode 100644 sound/soc/qcom/audioreach/audioreach.h -- 2.21.0 diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index cc7c1de2f1d9..721ea56b2cb5 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -103,6 +103,12 @@ config SND_SOC_QDSP6 audio drivers. This includes q6asm, q6adm, q6afe interfaces to DSP using apr. +config SND_SOC_QCOM_AUDIOREACH + tristate "SoC ALSA audio drives for Qualcomm AUDIOREACH" + depends on QCOM_GPR + help + Support for AudioReach in QDSP + config SND_SOC_MSM8996 tristate "SoC Machine driver for MSM8996 and APQ8096 boards" depends on QCOM_APR diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile index 1600ae55bd34..bfa5d44f9592 100644 --- a/sound/soc/qcom/Makefile +++ b/sound/soc/qcom/Makefile @@ -33,3 +33,4 @@ obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o #DSP lib obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/ +obj-${CONFIG_SND_SOC_QCOM_AUDIOREACH} += audioreach/ diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile new file mode 100644 index 000000000000..575edbed29a2 --- /dev/null +++ b/sound/soc/qcom/audioreach/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +snd-ar-objs := audioreach.o + +obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o + + diff --git a/sound/soc/qcom/audioreach/audioreach.c b/sound/soc/qcom/audioreach/audioreach.c new file mode 100644 index 000000000000..4cda274d59a6 --- /dev/null +++ b/sound/soc/qcom/audioreach/audioreach.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020, Linaro Limited + +#include +#include +#include +#include +#include "audioreach.h" + +/* SubGraph Config */ +struct apm_sub_graph_data { + struct apm_sub_graph_cfg sub_graph_cfg; + struct apm_prop_data perf_data; + struct apm_sg_prop_id_perf_mode perf; + struct apm_prop_data dir_data; + struct apm_sg_prop_id_direction dir; + struct apm_prop_data sid_data; + struct apm_sg_prop_id_scenario_id sid; + +} __packed; + +#define APM_SUB_GRAPH_CFG_NPROP 3 + +struct apm_sub_graph_params { + struct apm_module_param_data param_data; + uint32_t num_sub_graphs; + struct apm_sub_graph_data sg_cfg[0]; +} __packed; + +#define APM_SUB_GRAPH_PSIZE(n) ALIGN(sizeof(struct apm_sub_graph_params) + \ + n * sizeof(struct apm_sub_graph_data), 8) +/* container config */ +struct apm_container_obj { + struct apm_container_cfg container_cfg; + /* Capablity ID list */ + struct apm_prop_data cap_data; + uint32_t num_capablity_id; + uint32_t capability_id; + + /* Container graph Position */ + struct apm_prop_data pos_data; + struct apm_cont_prop_id_graph_pos pos; + + /* Container Stack size */ + struct apm_prop_data stack_data; + struct apm_cont_prop_id_stack_size stack; + + /* Container proc domain id */ + struct apm_prop_data domain_data; + struct apm_cont_prop_id_domain domain; +} __packed; + +struct apm_container_params { + struct apm_module_param_data param_data; + uint32_t num_containers; + struct apm_container_obj cont_obj[0]; +} __packed; + +#define APM_CONTAINER_PSIZE(n) ALIGN(sizeof(struct apm_container_params) + \ + n * sizeof(struct apm_container_obj), 8) + +/* Module List config */ +struct apm_mod_list_obj { + /* Modules list cfg */ + uint32_t sub_graph_id; + uint32_t container_id; + uint32_t num_modules; + struct apm_module_obj mod_cfg[0]; +} __packed; + +struct apm_module_list_params { + struct apm_module_param_data param_data; + uint32_t num_modules_list; + /* Module list config array */ + struct apm_mod_list_obj mod_list_obj[0]; + +} __packed; + +#define APM_MOD_LIST_OBJ_PSIZE(m) (sizeof(struct apm_mod_list_obj) + \ + m * sizeof(struct apm_module_obj)) + +/* n modules list m mod per list */ +#define APM_MOD_LIST_PSIZE(n, m) ALIGN(sizeof(struct apm_module_list_params) + \ + n * (sizeof(struct apm_mod_list_obj) + \ + m * sizeof(struct apm_module_obj)), 8) + +/* Module Properties */ +struct apm_mod_prop_obj { + u32 instance_id; + u32 num_props; + struct apm_prop_data prop_data_1; + struct apm_module_prop_id_port_info prop_id_port; +} __packed; + +struct apm_prop_list_params { + struct apm_module_param_data param_data; + u32 num_modules_prop_cfg; + struct apm_mod_prop_obj mod_prop_obj[0]; + +} __packed; + +#define APM_MOD_PROP_PSIZE(n) ALIGN(sizeof(struct apm_prop_list_params) + \ + n * sizeof(struct apm_mod_prop_obj), 8) + +/* Module Connections */ +struct apm_mod_conn_list_params { + struct apm_module_param_data param_data; + u32 num_connections; + struct apm_module_conn_obj conn_obj[0]; + +} __packed; + +#define APM_MOD_CONN_PSIZE(n) ALIGN(sizeof(struct apm_mod_conn_list_params) + \ + n * sizeof(struct apm_module_conn_obj), 8) + +struct apm_graph_open_params { + struct apm_cmd_header *cmd_header; + struct apm_sub_graph_params *sg_data; + struct apm_container_params *cont_data; + struct apm_module_list_params *mod_list_data; + struct apm_prop_list_params *mod_prop_data; + struct apm_mod_conn_list_params *mod_conn_list_data; +} __packed; + +struct apm_pcm_module_media_fmt_cmd { + struct apm_module_param_data param_data; + struct param_id_pcm_output_format_cfg header; + struct payload_pcm_output_format_cfg media_cfg; +} __packed; + +struct apm_rd_shmem_module_config_cmd { + struct apm_module_param_data param_data; + struct param_id_rd_sh_mem_cfg cfg; +} __packed; + +struct apm_sh_module_media_fmt_cmd { + struct media_format header; + struct payload_media_fmt_pcm cfg; +} __packed; + +#define APM_SHMEM_FMT_CFG_PSIZE(n) ALIGN( \ + sizeof(struct apm_sh_module_media_fmt_cmd) + \ + n * sizeof(uint8_t), 8) + +/* num of channels as argument */ +#define APM_PCM_MODULE_FMT_CMD_PSIZE(n) ALIGN( \ + sizeof(struct apm_pcm_module_media_fmt_cmd) + \ + n * sizeof(uint8_t), 8) +#define APM_PCM_OUT_FMT_CFG_PSIZE(n) ALIGN((sizeof( \ + struct payload_pcm_output_format_cfg) + \ + n * sizeof(uint8_t)), 4) + +struct apm_i2s_module_intf_cfg { + struct apm_module_param_data param_data; + struct param_id_i2s_intf_cfg cfg; +} __packed; +#define APM_I2S_INTF_CFG_PSIZE ALIGN(sizeof(struct apm_i2s_module_intf_cfg), \ + 8) + +struct apm_module_hw_ep_mf_cfg { + struct apm_module_param_data param_data; + struct param_id_hw_ep_mf mf; +} __packed; +#define APM_HW_EP_CFG_PSIZE ALIGN( \ + sizeof(struct apm_module_hw_ep_mf_cfg), \ + 8) + +struct apm_module_frame_size_factor_cfg { + struct apm_module_param_data param_data; + uint32_t frame_size_factor; +} __packed; +#define APM_FS_CFG_PSIZE ALIGN( \ + sizeof(struct apm_module_frame_size_factor_cfg), \ + 8) + +struct apm_module_hw_ep_power_mode_cfg { + struct apm_module_param_data param_data; + struct param_id_hw_ep_power_mode_cfg power_mode; +} __packed; +#define APM_HW_EP_PMODE_CFG_PSIZE ALIGN( \ + sizeof(struct apm_module_hw_ep_power_mode_cfg), \ + 8) + +struct apm_module_hw_ep_dma_data_align_cfg { + struct apm_module_param_data param_data; + struct param_id_hw_ep_dma_data_align align; +} __packed; +#define APM_HW_EP_DALIGN_CFG_PSIZE ALIGN( \ + sizeof(struct apm_module_hw_ep_dma_data_align_cfg), \ + 8) + +struct apm_gain_module_cfg { + struct apm_module_param_data param_data; + struct param_id_gain_cfg gain_cfg; +} __packed; +#define APM_GAIN_CFG_PSIZE ALIGN(sizeof(struct apm_gain_module_cfg), 8) + +struct apm_codec_dma_module_intf_cfg { + struct apm_module_param_data param_data; + struct param_id_codec_dma_intf_cfg cfg; +} __packed; +#define APM_CDMA_INTF_CFG_PSIZE ALIGN( \ + sizeof(struct apm_codec_dma_module_intf_cfg), 8) + +static void *__audioreach_alloc_pkt(int payload_size, uint32_t opcode, + uint32_t token, uint32_t src_port, + uint32_t dest_port, bool has_cmd_hdr) +{ + struct apm_cmd_header *cmd_header; + struct gpr_pkt *pkt; + void *p; + int pkt_size = GPR_HDR_SIZE + payload_size; + + if (has_cmd_hdr) + pkt_size += APM_CMD_HDR_SIZE; + + p = kzalloc(pkt_size, GFP_ATOMIC); + if (!p) + return ERR_PTR(-ENOMEM); + + pkt = p; + pkt->hdr.version = GPR_PKT_VER; + pkt->hdr.hdr_size = 6; + pkt->hdr.pkt_size = pkt_size; + pkt->hdr.dest_port = dest_port; + pkt->hdr.src_port = src_port; + + pkt->hdr.dest_domain = GPR_DOMAIN_ID_ADSP; + pkt->hdr.src_domain = GPR_DOMAIN_ID_APPS; + pkt->hdr.token = token; + pkt->hdr.opcode = opcode; + + if (has_cmd_hdr) { + p = p + GPR_HDR_SIZE; + cmd_header = p; + cmd_header->payload_size = payload_size; + } + + return pkt; +} + +void *audioreach_alloc_pkt(int payload_size, uint32_t opcode, + uint32_t token, uint32_t src_port, + uint32_t dest_port) +{ + return __audioreach_alloc_pkt(payload_size, opcode, token, src_port, + dest_port, false); +} + +void *audioreach_alloc_apm_pkt(int pkt_size, uint32_t opcode, + uint32_t token, uint32_t src_port) +{ + return __audioreach_alloc_pkt(pkt_size, opcode, token, src_port, + APM_MODULE_INSTANCE_ID, false); +} + +void *audioreach_alloc_cmd_pkt(int payload_size, uint32_t opcode, + uint32_t token, uint32_t src_port, + uint32_t dest_port) +{ + return __audioreach_alloc_pkt(payload_size, opcode, token, src_port, + dest_port, true); +} + +void *audioreach_alloc_apm_cmd_pkt(int pkt_size, uint32_t opcode, + uint32_t token) +{ + return __audioreach_alloc_pkt(pkt_size, opcode, token, + GPR_APM_MODULE_IID, + APM_MODULE_INSTANCE_ID, + true); +} diff --git a/sound/soc/qcom/audioreach/audioreach.h b/sound/soc/qcom/audioreach/audioreach.h new file mode 100644 index 000000000000..952c97bd88d7 --- /dev/null +++ b/sound/soc/qcom/audioreach/audioreach.h @@ -0,0 +1,624 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __AUDIOREACH_H__ +#define __AUDIOREACH_H__ +#include +#include +#include + +/* Module IDs */ +#define MODULE_ID_WR_SHARED_MEM_EP 0x07001000 +#define MODULE_ID_RD_SHARED_MEM_EP 0x07001001 +#define MODULE_ID_GAIN 0x07001002 +#define MODULE_ID_PCM_CNV 0x07001003 +#define MODULE_ID_PCM_ENC 0x07001004 +#define MODULE_ID_PCM_DEC 0x07001005 +#define MODULE_ID_CODEC_DMA_SINK 0x07001023 +#define MODULE_ID_CODEC_DMA_SOURCE 0x07001024 +#define MODULE_ID_I2S_SINK 0x0700100A +#define MODULE_ID_I2S_SOURCE 0x0700100b +#define MODULE_ID_DATA_LOGGING 0x0700101A + +#define APM_CMD_GET_SPF_STATE 0x01001021 +#define APM_CMD_RSP_GET_SPF_STATE 0x02001007 + +#define APM_MODULE_INSTANCE_ID 0x00000001 +#define PRM_MODULE_INSTANCE_ID 0x00000002 +#define AMDB_MODULE_INSTANCE_ID 0x00000003 +#define VCPM_MODULE_INSTANCE_ID 0x00000004 + +#define APM_CMD_GRAPH_OPEN 0x01001000 +#define APM_CMD_GRAPH_PREPARE 0x01001001 +#define APM_CMD_GRAPH_START 0x01001002 +#define APM_CMD_GRAPH_STOP 0x01001003 +#define APM_CMD_GRAPH_CLOSE 0x01001004 +#define APM_CMD_GRAPH_FLUSH 0x01001005 +#define APM_CMD_SET_CFG 0x01001006 +#define APM_CMD_GET_CFG 0x01001007 +#define APM_CMD_SHARED_MEM_MAP_REGIONS 0x0100100c +#define APM_CMD_SHARED_MEM_UNMAP_REGIONS 0x0100100d +#define APM_CMD_RSP_SHARED_MEM_MAP_REGIONS 0x02001001 +#define APM_CMD_RSP_GET_CFG 0x02001000 +#define APM_CMD_CLOSE_ALL 0x01001013 +#define APM_CMD_REGISTER_SHARED_CFG 0x0100100A + +#define APM_MEMORY_MAP_SHMEM8_4K_POOL 3 +struct apm_cmd_shared_mem_map_regions { + uint16_t mem_pool_id; + uint16_t num_regions; + uint32_t property_flag; +} __packed; + +struct apm_shared_map_region_payload { + uint32_t shm_addr_lsw; + uint32_t shm_addr_msw; + uint32_t mem_size_bytes; +} __packed; + +struct apm_cmd_shared_mem_unmap_regions { + uint32_t mem_map_handle; +} __packed; + +struct apm_cmd_rsp_shared_mem_map_regions { + uint32_t mem_map_handle; +} __packed; + +/* APM module */ +#define APM_PARAM_ID_SUB_GRAPH_LIST 0x08001005 + +#define APM_PARAM_ID_MODULE_LIST 0x08001002 +struct apm_param_id_modules_list { + uint32_t num_modules_list; +} __packed; + +#define APM_PARAM_ID_MODULE_PROP 0x08001003 +struct apm_param_id_module_prop { + uint32_t num_modules_prop_cfg; +} __packed; + +struct apm_module_prop_cfg { + uint32_t instance_id; + uint32_t num_props; +} __packed; + +#define APM_PARAM_ID_MODULE_CONN 0x08001004 +struct apm_param_id_module_conn { + uint32_t num_connections; +} __packed; + +struct apm_module_conn_obj { + uint32_t src_mod_inst_id; + uint32_t src_mod_op_port_id; + uint32_t dst_mod_inst_id; + uint32_t dst_mod_ip_port_id; +} __packed; + +#define APM_PARAM_ID_GAIN 0x08001006 +struct param_id_gain_cfg { + uint16_t gain; + uint16_t reserved; +}; + +#define PARAM_ID_PCM_OUTPUT_FORMAT_CFG 0x08001008 +struct param_id_pcm_output_format_cfg { + uint32_t data_format; + uint32_t fmt_id; + uint32_t payload_size; +} __packed; + +struct payload_pcm_output_format_cfg { + uint16_t bit_width; + uint16_t alignment; + uint16_t bits_per_sample; + uint16_t q_factor; + uint16_t endianness; + uint16_t interleaved; + uint16_t reserved; + uint16_t num_channels; + uint8_t channel_mapping[0]; +} __packed; + +#define PARAM_ID_ENC_BITRATE 0x08001052 +struct param_id_enc_bitrate_param { + uint32_t bitrate; +} __packed; + +#define DATA_FORMAT_FIXED_POINT 1 +#define PCM_LSB_ALIGNED 1 +#define PCM_MSB_ALIGNED 2 +#define PCM_LITTLE_ENDIAN 1 +#define PCM_BIT_ENDIAN 2 + +#define MEDIA_FMT_ID_PCM 0x09001000 +#define PCM_CHANNEL_L 1 +#define PCM_CHANNEL_R 2 +#define SAMPLE_RATE_48K 48000 +#define BIT_WIDTH_16 16 + +#define APM_PARAM_ID_PROP_PORT_INFO 0x08001015 +struct apm_modules_prop_info { + uint32_t max_ip_port; + uint32_t max_op_port; +} __packed; + +//Shared memory module +#define DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER 0x04001000 +#define WR_SH_MEM_EP_TIMESTAMP_VALID_FLAG BIT(31) +#define WR_SH_MEM_EP_LAST_BUFFER_FLAG BIT(30) +#define WR_SH_MEM_EP_TS_CONTINUE_FLAG BIT(29) +#define WR_SH_MEM_EP_EOF_FLAG BIT(4) +struct apm_data_cmd_wr_sh_mem_ep_data_buffer { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t buf_size; + uint32_t timestamp_lsw; + uint32_t timestamp_msw; + uint32_t flags; +} __packed; + +#define DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER_V2 0x0400100A +struct apm_data_cmd_wr_sh_mem_ep_data_buffer_v2 { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t buf_size; + uint32_t timestamp_lsw; + uint32_t timestamp_msw; + uint32_t flags; + uint32_t md_addr_lsw; + uint32_t md_addr_msw; + uint32_t md_map_handle; + uint32_t md_buf_size; +} __packed; + +#define DATA_CMD_RSP_WR_SH_MEM_EP_DATA_BUFFER_DONE 0x05001000 +struct data_cmd_rsp_wr_sh_mem_ep_data_buffer_done { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t status; + +} __packed; + +#define DATA_CMD_RSP_WR_SH_MEM_EP_DATA_BUFFER_DONE_V2 0x05001004 +struct data_cmd_rsp_wr_sh_mem_ep_data_buffer_done_v2 { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t status; + uint32_t md_buf_addr_lsw; + uint32_t md_buf_addr_msw; + uint32_t md_mem_map_handle; + uint32_t md_status; +} __packed; + +#define PARAM_ID_MEDIA_FORMAT 0x0800100C +#define DATA_CMD_WR_SH_MEM_EP_MEDIA_FORMAT 0x04001001 +struct apm_media_format { + uint32_t data_format; + uint32_t fmt_id; + uint32_t payload_size; +} __packed; + +#define DATA_CMD_WR_SH_MEM_EP_EOS 0x04001002 +#define WR_SH_MEM_EP_EOS_POLICY_LAST 1 +#define WR_SH_MEM_EP_EOS_POLICY_EACH 2 + +struct data_cmd_wr_sh_mem_ep_eos { + uint32_t policy; + +} __packed; + +#define DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER 0x04001003 +struct data_cmd_rd_sh_mem_ep_data_buffer { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t buf_size; +}; + +#define DATA_CMD_RSP_RD_SH_MEM_EP_DATA_BUFFER 0x05001002 +struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done { + uint32_t status; + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t data_size; + uint32_t offset; + uint32_t timestamp_lsw; + uint32_t timestamp_msw; + uint32_t flags; + uint32_t num_frames; +}; + +#define DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER_V2 0x0400100B +struct data_cmd_rd_sh_mem_ep_data_buffer_v2 { + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t buf_size; + uint32_t md_buf_addr_lsw; + uint32_t md_buf_addr_msw; + uint32_t md_mem_map_handle; + uint32_t md_buf_size; +}; + +#define DATA_CMD_RSP_RD_SH_MEM_EP_DATA_BUFFER_V2 0x05001005 +struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 { + uint32_t status; + uint32_t buf_addr_lsw; + uint32_t buf_addr_msw; + uint32_t mem_map_handle; + uint32_t data_size; + uint32_t offset; + uint32_t timestamp_lsw; + uint32_t timestamp_msw; + uint32_t flags; + uint32_t num_frames; + uint32_t md_status; + uint32_t md_buf_addr_lsw; + uint32_t md_buf_addr_msw; + uint32_t md_mem_map_handle; + uint32_t md_size; +} __packed; + +#define PARAM_ID_RD_SH_MEM_CFG 0x08001007 +struct param_id_rd_sh_mem_cfg { + uint32_t num_frames_per_buffer; + uint32_t metadata_control_flags; + +} __packed; +#define DATA_CMD_WR_SH_MEM_EP_EOS_RENDERED 0x05001001 +struct data_cmd_wr_sh_mem_ep_eos_rendered { + uint32_t module_instance_id; + uint32_t render_status; +} __packed; + +#define MODULE_ID_WR_SHARED_MEM_EP 0x07001000 + +struct apm_cmd_header { + uint32_t payload_address_lsw; + uint32_t payload_address_msw; + uint32_t mem_map_handle; + uint32_t payload_size; +} __packed; + +#define APM_CMD_HDR_SIZE sizeof(struct apm_cmd_header) + +struct apm_module_param_data { + uint32_t module_instance_id; + uint32_t param_id; + uint32_t param_size; + uint32_t error_code; +} __packed; + +#define APM_MODULE_PARAM_DATA_SIZE sizeof(struct apm_module_param_data) +struct apm_module_param_shared_data { + uint32_t param_id; + uint32_t param_size; +} __packed; + +struct apm_prop_data { + uint32_t prop_id; + uint32_t prop_size; +} __packed; + +/* Sub-Graph Properties */ +#define APM_PARAM_ID_SUB_GRAPH_CONFIG 0x08001001 + +struct apm_param_id_sub_graph_cfg { + uint32_t num_sub_graphs; +} __packed; + +struct apm_sub_graph_cfg { + uint32_t sub_graph_id; + uint32_t num_sub_graph_prop; +} __packed; + +#define APM_SUB_GRAPH_PROP_ID_PERF_MODE 0x0800100E + +struct apm_sg_prop_id_perf_mode { + uint32_t perf_mode; +} __packed; + +#define APM_SG_PROP_ID_PERF_MODE_SIZE 4 + +#define APM_SUB_GRAPH_PROP_ID_DIRECTION 0x0800100F + +struct apm_sg_prop_id_direction { + uint32_t direction; +} __packed; + +#define APM_SG_PROP_ID_DIR_SIZE 4 + +#define APM_SUB_GRAPH_PROP_ID_SCENARIO_ID 0x08001010 +#define APM_SUB_GRAPH_SID_AUDIO_PLAYBACK 0x1 +#define APM_SUB_GRAPH_SID_AUDIO_RECORD 0x2 +#define APM_SUB_GRAPH_SID_AUDIO_VOICE_CALL 0x3 + +struct apm_sg_prop_id_scenario_id { + uint32_t scenario_id; +} __packed; + +#define APM_SG_PROP_ID_SID_SIZE 4 +//container api +#define APM_PARAM_ID_CONTAINER_CONFIG 0x08001000 +struct apm_param_id_container_cfg { + uint32_t num_containers; +} __packed; + +struct apm_container_cfg { + uint32_t container_id; + uint32_t num_prop; +} __packed; + +struct apm_cont_capablity { + uint32_t capability_id; +} __packed; + +#define APM_CONTAINER_PROP_ID_CAPABILITY_LIST 0x08001011 +#define APM_CONTAINER_PROP_ID_CAPABILITY_SIZE 8 + +#define APM_PROP_ID_INVALID 0x0 +#define APM_CONTAINER_CAP_ID_PP 0x1 +#define APM_CONTAINER_CAP_ID_PP 0x1 + +struct apm_cont_prop_id_cap_list { + uint32_t num_capablity_id; +} __packed; + +#define APM_CONTAINER_PROP_ID_GRAPH_POS 0x08001012 + +struct apm_cont_prop_id_graph_pos { + uint32_t graph_pos; +} __packed; + +#define APM_CONTAINER_PROP_ID_STACK_SIZE 0x08001013 +struct apm_cont_prop_id_stack_size { + uint32_t stack_size; +} __packed; + +#define APM_CONTAINER_PROP_ID_PROC_DOMAIN 0x08001014 +struct apm_cont_prop_id_domain { + uint32_t proc_domain; +} __packed; + +#define PARAM_ID_I2S_INTF_CFG 0x08001019 +struct param_id_i2s_intf_cfg { + uint32_t lpaif_type; + uint32_t intf_idx; + uint16_t sd_line_idx; + uint16_t ws_src; +} __packed; + +#define I2S_INTF_TYPE_PRIMARY 0 +#define I2S_INTF_TYPE_SECOINDARY 1 +#define I2S_INTF_TYPE_TERTINARY 2 +#define I2S_INTF_TYPE_QUATERNARY 3 +#define I2S_INTF_TYPE_QUINARY 4 +#define I2S_SD0 1 +#define I2S_SD1 2 +#define I2S_SD2 3 +#define I2S_SD3 4 + +#define PORT_ID_I2S_INPUT 2 +#define PORT_ID_I2S_OUPUT 1 +#define I2S_STACK_SIZE 2048 + +#define PARAM_ID_HW_EP_MF_CFG 0x08001017 +struct param_id_hw_ep_mf { + uint32_t sample_rate; + uint16_t bit_width; + uint16_t num_channels; + uint32_t data_format; +} __packed; + +#define PARAM_ID_HW_EP_FRAME_SIZE_FACTOR 0x08001018 + +struct param_id_fram_size_factor { + uint32_t frame_size_factor; +} __packed; + +#define APM_CONTAINER_PROP_ID_PARENT_CONTAINER_ID 0x080010CB +struct apm_cont_prop_id_parent_container { + uint32_t parent_container_id; +} __packed; + +#define APM_CONTAINER_PROP_ID_HEAP_ID 0x08001174 +#define APM_CONT_HEAP_DEFAULT 0x1 +#define APM_CONT_HEAP_LOW_POWER 0x2 +struct apm_cont_prop_id_headp_id { + uint32_t heap_id; +} __packed; + +struct apm_modules_list { + uint32_t sub_graph_id; + uint32_t container_id; + uint32_t num_modules; +} __packed; + +struct apm_module_obj { + uint32_t module_id; + uint32_t instance_id; +} __packed; + +#define APM_MODULE_PROP_ID_PORT_INFO 0x08001015 +#define APM_MODULE_PROP_ID_PORT_INFO_SZ 8 +struct apm_module_prop_id_port_info { + uint32_t max_ip_port; + uint32_t max_op_port; +} __packed; + +#define DATA_LOGGING_MAX_INPUT_PORTS 0x1 +#define DATA_LOGGING_MAX_OUTPUT_PORTS 0x1 +#define DATA_LOGGING_STACK_SIZE 2048 +#define PARAM_ID_DATA_LOGGING_CONFIG 0x08001031 +struct data_logging_config { + uint32_t log_code; + uint32_t log_tap_point_id; + uint32_t mode; +} __packed; + +#define PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT 0x08001024 +struct param_id_mfc_media_format { + uint32_t sample_rate; + uint16_t bit_width; + uint16_t num_channels; + uint16_t channel_mapping[0]; +} __packed; + +struct media_format { + uint32_t data_format; + uint32_t fmt_id; + uint32_t payload_size; +} __packed; + +struct payload_media_fmt_pcm { + uint32_t sample_rate; + uint16_t bit_width; + uint16_t alignment; + uint16_t bits_per_sample; + uint16_t q_factor; + uint16_t endianness; + uint16_t num_channels; + uint8_t channel_mapping[0]; +} __packed; + +#define PARAM_ID_CODEC_DMA_INTF_CFG 0x08001063 +struct param_id_codec_dma_intf_cfg { + /* 1 - RXTX + * 2 - WSA + * 3 - VA + * 4 - AXI + */ + uint32_t lpaif_type; + /* + * RX0 | TX0 = 1 + * RX1 | TX1 = 2 + * RX2 | TX2 = 3... so on + */ + uint32_t intf_index; + uint32_t active_channels_mask; +} __packed; + +struct audio_hw_clk_cfg { + uint32_t clock_id; + uint32_t clock_freq; + uint32_t clock_attri; + uint32_t clock_root; +} __packed; + +#define PARAM_ID_HW_EP_POWER_MODE_CFG 0x8001176 +#define POWER_MODE_0 0 /* default */ +#define POWER_MODE_1 1 /* XO Shutdown allowed */ +#define POWER_MODE_2 2 /* XO Shutdown not allowed */ +struct param_id_hw_ep_power_mode_cfg { + uint32_t power_mode; +} __packed; + +#define PARAM_ID_HW_EP_DMA_DATA_ALIGN 0x08001233 +#define DMA_DATA_ALIGN_MSB 0 +#define DMA_DATA_ALIGN_LSB 1 + +#define PCM_MAX_NUM_CHANNEL 8 +struct param_id_hw_ep_dma_data_align { + uint32_t dma_data_align; +} __packed; + +/* Graph */ +struct audioreach_connection { + /* Connections */ + uint32_t src_mod_inst_id; + uint32_t src_mod_op_port_id; + uint32_t dst_mod_inst_id; + uint32_t dst_mod_ip_port_id; + struct list_head node; +}; + +struct audioreach_graph_info { + int id; + uint32_t num_sub_graphs; + struct list_head sg_list; + struct list_head connection_list; + spinlock_t sg_list_lock; +}; + +struct audioreach_sub_graph { + uint32_t sub_graph_id; + uint32_t perf_mode; + uint32_t direction; + uint32_t scenario_id; + struct list_head node; + + struct audioreach_graph_info *info; + uint32_t num_containers; + struct list_head container_list; +}; + +struct audioreach_container { + uint32_t container_id; + uint32_t capability_id; + uint32_t graph_pos; + uint32_t stack_size; + uint32_t proc_domain; + struct list_head node; + + uint32_t num_modules; + struct list_head modules_list; + struct audioreach_sub_graph *sub_graph; +}; + +struct audioreach_module { + uint32_t module_id; + uint32_t instance_id; + + uint32_t max_ip_port; + uint32_t max_op_port; + + uint32_t in_port; + uint32_t out_port; + + /* Connections */ + uint32_t src_mod_inst_id; + uint32_t src_mod_op_port_id; + uint32_t dst_mod_inst_id; + uint32_t dst_mod_ip_port_id; + + /* Format specifics */ + uint32_t ch_fmt; + uint32_t rate; + uint32_t bit_depth; + + /* I2S module Specfic */ + uint32_t hw_interface_idx; + uint32_t sd_line_idx; + uint32_t ws_src; + uint32_t frame_size_factor; + uint32_t data_format; + uint32_t hw_interface_type; + + /* PCM module specific */ + uint32_t interleave_type; + + /* GAIN/Vol Control Module */ + uint16_t gain; + /* Logging */ + uint32_t log_code; + uint32_t log_tap_point_id; + uint32_t mode; + struct list_head node; + struct audioreach_container *container; + struct snd_soc_dapm_widget *widget; +}; + +/* Packet Allocation routines */ +void *audioreach_alloc_apm_cmd_pkt(int pkt_size, uint32_t opcode, uint32_t + token); +void *audioreach_alloc_cmd_pkt(int pkt_size, uint32_t opcode, uint32_t token, + uint32_t src_port, uint32_t dest_port); +void *audioreach_alloc_apm_pkt(int pkt_size, uint32_t opcode, uint32_t token, + uint32_t src_port); +void *audioreach_alloc_pkt(int pkt_size, uint32_t opcode, uint32_t token, + uint32_t src_port, uint32_t dest_port); +#endif /* __AUDIOREACH_H__ */ From patchwork Wed Jul 14 15:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476803 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676605jao; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUmJhQX7F4DSG3ZKvQLzcIu/3I+jz9V5/WLOBkCUft7hwVVNIbawtcSomPKRhLCaa0FF0K X-Received: by 2002:a05:6e02:c7:: with SMTP id r7mr7084160ilq.52.1626276678252; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276678; cv=none; d=google.com; s=arc-20160816; b=rP8Bhgp2O770m4nGHlyiA9jVmp+DXlS4AfTJUporA3ZDyFGQ2djsJwTp34UOR3k/sh RqDhpqmiXymASUo1ikhE+gpv7KJnyzvGDSR3kZr2FILMoxH6KXl2DtsC4LPDb2H3xlMI Jv4ygOsmzux3NPN2VWuEwLEESmNkMsJa0AyHnIBothbPf6T2FNBt7VzJZuP58kCtUySU A11dDFnSgNfnvvdIGXaO47I9h/EXfKT4HAhJQ2bsebIpsfik6/meRBeXOQbjyUG/kgwb XQqemhiHZIaPO2acM68qSeP5xzHNZ1JAhgekGenBqvqe5LQkaE+a+WmLGCp3hcYYP1hD hayA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=02JQtdQ21ajVEezSYP64GRQGP5rMHyCbtGsDSd+slIg=; b=Bal0RLc9bAWBVBEhPsfrh4xnYlVNPi1KOCJmeF2z3kqDr8maq5NBfJ8flJcJY1xW5z 4gm2Pb6C7dyjM+rI8Jb6QmS0IKoR8OK0KqJzRo6UsPLi4Y/0wy85OlJmzLalCjsUXTdV FeOydCY0w7B+L62UGC1D4EihHdXcH38vx6Vrhxl4cb726+y2w5eWZyKW3nYfYjCW9CXH oSzTyY1CxpmSn42pkmhe9qp4dbcSoywTLY4e+6dcdNPvl68KAwRa+nL0GUHcdFp17MBO oEND4D2J1Jt8S9ENS27Sc9XJwzCFp5G3GnfeFAsIE39mZ/oqXR0P24iky31pagao+Hhf K99w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qYPXmNsf; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.18; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qYPXmNsf; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239757AbhGNPeB (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239755AbhGNPeA (ORCPT ); Wed, 14 Jul 2021 11:34:00 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22BADC06175F for ; Wed, 14 Jul 2021 08:31:08 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id j34so1837182wms.5 for ; Wed, 14 Jul 2021 08:31:08 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=02JQtdQ21ajVEezSYP64GRQGP5rMHyCbtGsDSd+slIg=; b=qYPXmNsfR6lJ8bR7RG3flzwqCcbj+i2FBPQyu23ORgS834g1ijjJP9Pdq7hauEC18b 5PZ8xwdmJ2bZ1S/h+UPubTvj7ggCDUj59PsFbTyiiOUQrmTiiGtHViyD4/pXlvf6UA0j k7oZCgENNNQXYw+5QeJROooZIlaZyNrg91pTgyNiiPCvR5H2ppBPnwYWAgqzFyOLaM1Z cB0jLSNBX9TUb0PO7eShZSFE+Grv4THb8jj1nRKHH/RWsoGpLzsEpfKuvYIGJ0d/3NYO u6VfyJ8u7hkeTrTB3RvgIpUxpUug9xxUjFk9rljfFH+n1nVLxnOxrjWX1g+8uGVI4U+/ Caew== 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:mime-version:content-transfer-encoding; bh=02JQtdQ21ajVEezSYP64GRQGP5rMHyCbtGsDSd+slIg=; b=Q3fWl3Y259oSVdeGWiKaqr8i8zZona2zofUvvZTiONY297wVETyBjzf0JdVGwaDXhr omyIXzXHW7gNRcprrI6z4/oLSd7NhAzgD0eeZFgRi/3ZmZa7YEnernZMCqPlfbT6PAiD KjYAan+/qwDkxQuBJTpFZCF/I0gPM2iBDy8hI8W5KRgl16F4wsmjc1BhNkDVWSwHaecP sXL+oDfQeVXpCDcQ5I+EO5lPl1XaWhsxfitNPLHiuwMK7K3BCTmJ5XDno0Rt37QwNBmO UL+3Po/WODpuJPrVJTmQHZZwA3FHF0gxXY/sg/b7WHKUKfdZKzmPnAaqUGDOGVJ30Tlj ROIw== X-Gm-Message-State: AOAM531YyveBAXFy3rnM3WxA2e5pnLZrwI8Km/p9YNxMYmcC5FyBPQMt iiHRC9C7j5j0gOKKE4z6BsI1mA== X-Received: by 2002:a05:600c:2ca4:: with SMTP id h4mr11774052wmc.37.1626276666560; Wed, 14 Jul 2021 08:31:06 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:06 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 06/16] ASoC: qcom: audioreach: add q6apm support Date: Wed, 14 Jul 2021 16:30:29 +0100 Message-Id: <20210714153039.28373-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support to q6apm (Audio Process Manager) component which is core Audioreach service running in the DSP. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/audioreach/Makefile | 2 +- sound/soc/qcom/audioreach/audioreach.c | 308 ++++++++++- sound/soc/qcom/audioreach/audioreach.h | 23 + sound/soc/qcom/audioreach/q6apm.c | 697 +++++++++++++++++++++++++ sound/soc/qcom/audioreach/q6apm.h | 174 ++++++ 5 files changed, 1202 insertions(+), 2 deletions(-) create mode 100644 sound/soc/qcom/audioreach/q6apm.c create mode 100644 sound/soc/qcom/audioreach/q6apm.h -- 2.21.0 diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile index 575edbed29a2..d76afc51556b 100644 --- a/sound/soc/qcom/audioreach/Makefile +++ b/sound/soc/qcom/audioreach/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -snd-ar-objs := audioreach.o +snd-ar-objs := audioreach.o q6apm.o obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o diff --git a/sound/soc/qcom/audioreach/audioreach.c b/sound/soc/qcom/audioreach/audioreach.c index 4cda274d59a6..22197b88e686 100644 --- a/sound/soc/qcom/audioreach/audioreach.c +++ b/sound/soc/qcom/audioreach/audioreach.c @@ -5,6 +5,7 @@ #include #include #include +#include "q6apm.h" #include "audioreach.h" /* SubGraph Config */ @@ -32,7 +33,7 @@ struct apm_sub_graph_params { /* container config */ struct apm_container_obj { struct apm_container_cfg container_cfg; - /* Capablity ID list */ + /* Capability ID list */ struct apm_prop_data cap_data; uint32_t num_capablity_id; uint32_t capability_id; @@ -270,3 +271,308 @@ void *audioreach_alloc_apm_cmd_pkt(int pkt_size, uint32_t opcode, APM_MODULE_INSTANCE_ID, true); } + +static void apm_populate_container_config( + struct apm_container_obj *cfg, + struct audioreach_container *cont) +{ + + /* Container Config */ + cfg->container_cfg.container_id = cont->container_id; + cfg->container_cfg.num_prop = 4; + + /* Capablity list */ + cfg->cap_data.prop_id = APM_CONTAINER_PROP_ID_CAPABILITY_LIST; + cfg->cap_data.prop_size = APM_CONTAINER_PROP_ID_CAPABILITY_SIZE; + cfg->num_capablity_id = 1; + cfg->capability_id = cont->capability_id; + + /* Graph Position */ + cfg->pos_data.prop_id = APM_CONTAINER_PROP_ID_GRAPH_POS; + cfg->pos_data.prop_size = sizeof(struct apm_cont_prop_id_graph_pos); + cfg->pos.graph_pos = cont->graph_pos; + + /* Stack size */ + cfg->stack_data.prop_id = APM_CONTAINER_PROP_ID_STACK_SIZE; + cfg->stack_data.prop_size = sizeof(struct + apm_cont_prop_id_stack_size); + cfg->stack.stack_size = cont->stack_size; + + /* Proc domain */ + cfg->domain_data.prop_id = APM_CONTAINER_PROP_ID_PROC_DOMAIN; + cfg->domain_data.prop_size = sizeof(struct + apm_cont_prop_id_domain); + cfg->domain.proc_domain = cont->proc_domain; +} + +static void apm_populate_sub_graph_config( + struct apm_sub_graph_data *cfg, + struct audioreach_sub_graph *sg) +{ + cfg->sub_graph_cfg.sub_graph_id = sg->sub_graph_id; + cfg->sub_graph_cfg.num_sub_graph_prop = APM_SUB_GRAPH_CFG_NPROP; + + /* Perf Mode */ + cfg->perf_data.prop_id = APM_SUB_GRAPH_PROP_ID_PERF_MODE; + cfg->perf_data.prop_size = APM_SG_PROP_ID_PERF_MODE_SIZE; + cfg->perf.perf_mode = sg->perf_mode; + + /* Direction */ + cfg->dir_data.prop_id = APM_SUB_GRAPH_PROP_ID_DIRECTION; + cfg->dir_data.prop_size = APM_SG_PROP_ID_DIR_SIZE; + cfg->dir.direction = sg->direction; + + /* Scenario ID */ + cfg->sid_data.prop_id = APM_SUB_GRAPH_PROP_ID_SCENARIO_ID; + cfg->sid_data.prop_size = APM_SG_PROP_ID_SID_SIZE; + cfg->sid.scenario_id = sg->scenario_id; +} + +static void apm_populate_connection_obj(struct apm_module_conn_obj *obj, + struct audioreach_module *module) +{ + obj->src_mod_inst_id = module->src_mod_inst_id; + obj->src_mod_op_port_id = module->src_mod_op_port_id; + obj->dst_mod_inst_id = module->instance_id; + obj->dst_mod_ip_port_id = module->in_port; +} + +static void apm_populate_module_prop_obj(struct apm_mod_prop_obj *obj, + struct audioreach_module *module) +{ + + obj->instance_id = module->instance_id; + obj->num_props = 1; + obj->prop_data_1.prop_id = APM_MODULE_PROP_ID_PORT_INFO; + obj->prop_data_1.prop_size = APM_MODULE_PROP_ID_PORT_INFO_SZ; + obj->prop_id_port.max_ip_port = module->max_ip_port; + obj->prop_id_port.max_op_port = module->max_op_port; +} + +struct audioreach_module *audioreach_get_container_last_module( + struct audioreach_container *container) +{ + struct audioreach_module *module; + + list_for_each_entry(module, &container->modules_list, node) { + if (module->dst_mod_inst_id == 0) + return module; + } + + return NULL; +} + +static bool is_module_in_container(struct audioreach_container *container, int + module_iid) +{ + struct audioreach_module *module; + + list_for_each_entry(module, &container->modules_list, node) { + if (module->instance_id == module_iid) + return true; + } + + return false; +} +struct audioreach_module *audioreach_get_container_first_module( + struct audioreach_container *container) +{ + struct audioreach_module *module; + bool found = false; + + list_for_each_entry(module, &container->modules_list, node) { + if (module->src_mod_inst_id == 0 || + !is_module_in_container(container, module->src_mod_inst_id)) + return module; + } + return NULL; +} + +struct audioreach_module *audioreach_get_container_next_module( + struct audioreach_container *container, + struct audioreach_module *module) +{ + int nmodule_iid = module->dst_mod_inst_id; + struct audioreach_module *nmodule; + + list_for_each_entry(nmodule, &container->modules_list, node) { + if (nmodule->instance_id == nmodule_iid) + return nmodule; + } + + return NULL; +} + +static void apm_populate_module_list_obj(struct apm_mod_list_obj *obj, + struct audioreach_container *container, + int sub_graph_id) +{ + struct audioreach_module *module; + int i; + + obj->sub_graph_id = sub_graph_id; + obj->container_id = container->container_id; + obj->num_modules = container->num_modules; + i = 0; + list_for_each_container_module(module, container) { + obj->mod_cfg[i].module_id = module->module_id; + obj->mod_cfg[i].instance_id = module->instance_id; + i++; + } +} + +static void audioreach_populate_graph(struct apm_graph_open_params *open, + struct list_head *sg_list, + int num_sub_graphs) +{ + struct apm_sub_graph_params *sg_data = open->sg_data; + struct apm_container_params *c_data = open->cont_data; + struct apm_module_list_params *ml_data = open->mod_list_data; + struct apm_prop_list_params *mp_data = open->mod_prop_data; + struct apm_mod_conn_list_params *mc_data = open->mod_conn_list_data; + struct apm_container_obj *cobj; + struct audioreach_container *container; + struct audioreach_module *module; + struct apm_mod_list_obj *mlobj; + struct apm_mod_prop_obj *module_prop_obj; + struct apm_module_conn_obj *conn_obj; + int ncontainer = 0, nmodule = 0, nconn = 0; + struct audioreach_sub_graph *sg; + int i = 0; + + mlobj = &ml_data->mod_list_obj[0]; + + list_for_each_entry(sg, sg_list, node) { + struct apm_sub_graph_data *sg_cfg = &sg_data->sg_cfg[i++]; + + apm_populate_sub_graph_config(sg_cfg, sg); + + list_for_each_entry(container, &sg->container_list, node) { + cobj = &c_data->cont_obj[ncontainer]; + + apm_populate_container_config(cobj, container); + apm_populate_module_list_obj(mlobj, container, + sg->sub_graph_id); + + list_for_each_container_module(module, container) { + uint32_t src_mod_inst_id; + + src_mod_inst_id = module->src_mod_inst_id; + + module_prop_obj = &mp_data->mod_prop_obj[nmodule]; + apm_populate_module_prop_obj(module_prop_obj, + module); + + if (src_mod_inst_id /*&& dst_mod_inst_id*/) { + conn_obj = &mc_data->conn_obj[nconn]; + apm_populate_connection_obj(conn_obj, module); + nconn++; + } + + nmodule++; + } + mlobj = (void *) mlobj + + APM_MOD_LIST_OBJ_PSIZE(container->num_modules); + + ncontainer++; + } + } +} + +void *audioreach_alloc_graph_pkt(struct q6apm *apm, + struct list_head *sg_list, + int graph_id) +{ + void *p; + int payload_size, sg_sz, cont_sz, ml_sz, mp_sz, mc_sz; + struct gpr_pkt *pkt; + struct apm_graph_open_params params; + struct apm_module_param_data *param_data; + struct audioreach_container *container; + int num_containers = 0; + int num_modules = 0; + int num_modules_list; + int num_modules_per_list; + int num_connections = 0; + int num_sub_graphs = 0; + struct audioreach_sub_graph *sgs; + struct audioreach_module *module; + + list_for_each_entry(sgs, sg_list, node) { + num_sub_graphs++; + list_for_each_entry(container, &sgs->container_list, node) { + num_containers++; + num_modules += container->num_modules; + list_for_each_container_module(module, container) { + if (module->src_mod_inst_id) + num_connections++; + } + } + } + + num_modules_list = num_containers; + num_modules_per_list = num_modules/num_containers; + sg_sz = APM_SUB_GRAPH_PSIZE(num_sub_graphs); + cont_sz = APM_CONTAINER_PSIZE(num_containers); + ml_sz = APM_MOD_LIST_PSIZE(num_modules_list, num_modules_per_list); + mp_sz = APM_MOD_PROP_PSIZE(num_modules); + mc_sz = APM_MOD_CONN_PSIZE(num_connections); + + payload_size = sg_sz + cont_sz + ml_sz + mp_sz + mc_sz; + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_GRAPH_OPEN, 0); + if (IS_ERR(p)) + return p; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + /* SubGraph */ + params.sg_data = p; + param_data = ¶ms.sg_data->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_SUB_GRAPH_CONFIG; + param_data->param_size = sg_sz - APM_MODULE_PARAM_DATA_SIZE; + params.sg_data->num_sub_graphs = num_sub_graphs; + p += sg_sz; + + /* Container */ + params.cont_data = p; + param_data = ¶ms.cont_data->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_CONTAINER_CONFIG; + param_data->param_size = cont_sz - APM_MODULE_PARAM_DATA_SIZE; + params.cont_data->num_containers = num_containers; + p += cont_sz; + + /* Module List*/ + params.mod_list_data = p; + param_data = ¶ms.mod_list_data->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_MODULE_LIST; + param_data->param_size = ml_sz - APM_MODULE_PARAM_DATA_SIZE; + params.mod_list_data->num_modules_list = num_sub_graphs; + p += ml_sz; + + /* Module Properties */ + params.mod_prop_data = p; + param_data = ¶ms.mod_prop_data->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_MODULE_PROP; + param_data->param_size = mp_sz - APM_MODULE_PARAM_DATA_SIZE; + params.mod_prop_data->num_modules_prop_cfg = num_modules; + p += mp_sz; + + /* Module Connections */ + params.mod_conn_list_data = p; + param_data = ¶ms.mod_conn_list_data->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_MODULE_CONN; + param_data->param_size = mc_sz - APM_MODULE_PARAM_DATA_SIZE; + params.mod_conn_list_data->num_connections = num_connections; + p += mc_sz; + + audioreach_populate_graph(¶ms, sg_list, num_sub_graphs); + + return pkt; +} + diff --git a/sound/soc/qcom/audioreach/audioreach.h b/sound/soc/qcom/audioreach/audioreach.h index 952c97bd88d7..cd5111a23a6a 100644 --- a/sound/soc/qcom/audioreach/audioreach.h +++ b/sound/soc/qcom/audioreach/audioreach.h @@ -5,6 +5,9 @@ #include #include #include +struct q6apm; +struct q6apm_graph; + /* Module IDs */ #define MODULE_ID_WR_SHARED_MEM_EP 0x07001000 @@ -26,6 +29,13 @@ #define PRM_MODULE_INSTANCE_ID 0x00000002 #define AMDB_MODULE_INSTANCE_ID 0x00000003 #define VCPM_MODULE_INSTANCE_ID 0x00000004 +#define AR_MODULE_INSTANCE_ID_START 0x00006000 +#define AR_MODULE_INSTANCE_ID_END 0x00007000 +#define AR_MODULE_DYNAMIC_INSTANCE_ID_START 0x00007000 +#define AR_MODULE_DYNAMIC_INSTANCE_ID_END 0x00008000 +#define AR_CONT_INSTANCE_ID_START 0x00005000 +#define AR_CONT_INSTANCE_ID_END 0x00006000 +#define AR_SG_INSTANCE_ID_START 0x00004000 #define APM_CMD_GRAPH_OPEN 0x01001000 #define APM_CMD_GRAPH_PREPARE 0x01001001 @@ -621,4 +631,17 @@ void *audioreach_alloc_apm_pkt(int pkt_size, uint32_t opcode, uint32_t token, uint32_t src_port); void *audioreach_alloc_pkt(int pkt_size, uint32_t opcode, uint32_t token, uint32_t src_port, uint32_t dest_port); +void *audioreach_alloc_graph_pkt(struct q6apm *apm, + struct list_head *sg_list, + int graph_id); +struct audioreach_module *audioreach_get_container_last_module( + struct audioreach_container *container); +struct audioreach_module *audioreach_get_container_first_module( + struct audioreach_container *container); +struct audioreach_module *audioreach_get_container_next_module( + struct audioreach_container *container, + struct audioreach_module *module); +#define list_for_each_container_module(mod, cont) \ + for (mod = audioreach_get_container_first_module(cont); mod != NULL; \ + mod = audioreach_get_container_next_module(cont, mod)) #endif /* __AUDIOREACH_H__ */ diff --git a/sound/soc/qcom/audioreach/q6apm.c b/sound/soc/qcom/audioreach/q6apm.c new file mode 100644 index 000000000000..9b804b863834 --- /dev/null +++ b/sound/soc/qcom/audioreach/q6apm.c @@ -0,0 +1,697 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "audioreach.h" +#include "q6apm.h" + +/* Graph Management */ +struct apm_graph_mgmt_cmd { + struct apm_module_param_data param_data; + uint32_t num_sub_graphs; + uint32_t sub_graph_id_list[0]; +} __packed; + +#define APM_GRAPH_MGMT_PSIZE(n) ALIGN(sizeof(struct apm_graph_mgmt_cmd) + \ + n * sizeof(uint32_t), 8) + +int q6apm_send_cmd(struct q6apm *apm, struct gpr_pkt *pkt) +{ + int rc; + + mutex_lock(&apm->cmd_lock); + rc = gpr_send_pkt(apm->gdev, pkt); + mutex_unlock(&apm->cmd_lock); + + return rc; +} + +int q6apm_send_cmd_sync(struct q6apm *apm, struct gpr_pkt *pkt, + uint32_t rsp_opcode) +{ + gpr_device_t *gdev = apm->gdev; + struct gpr_hdr *hdr = &pkt->hdr; + int rc; + + mutex_lock(&apm->cmd_lock); + apm->result.opcode = 0; + apm->result.status = 0; + + rc = gpr_send_pkt(apm->gdev, pkt); + if (rc < 0) + goto err; + + if (rsp_opcode) + rc = wait_event_timeout(apm->wait, + (apm->result.opcode == hdr->opcode) || + (apm->result.opcode == rsp_opcode), + 5 * HZ); + else + rc = wait_event_timeout(apm->wait, + (apm->result.opcode == hdr->opcode), + 5 * HZ); + + if (!rc) { + dev_err(&gdev->dev, "CMD timeout for [%x] opcode\n", + hdr->opcode); + rc = -ETIMEDOUT; + } else if (apm->result.status > 0) { + dev_err(&gdev->dev, "DSP returned error[%x] %x\n", hdr->opcode, + apm->result.status); + rc = -EINVAL; + } else { + dev_err(&gdev->dev, "DSP returned [%x]\n", + apm->result.status); + rc = 0; + } + +err: + mutex_unlock(&apm->cmd_lock); + return rc; +} + +static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, + uint32_t graph_id) +{ + struct audioreach_graph *graph = NULL; + struct audioreach_graph_info *info; + unsigned long flags; + + spin_lock_irqsave(&apm->lock, flags); + graph = idr_find(&apm->graph_idr, graph_id); + spin_unlock_irqrestore(&apm->lock, flags); + + if (graph) { + kref_get(&graph->refcount); + return graph; + } + + info = idr_find(&apm->graph_info_idr, graph_id); + + if (!info) + return ERR_PTR(-ENODEV); + + graph = kzalloc(sizeof(*graph), GFP_KERNEL); + if (!graph) + return ERR_PTR(-ENOMEM); + + graph->apm = apm; + graph->info = info; + graph->id = graph_id; + + /* Assuming Linear Graphs only for now! */ + graph->graph = audioreach_alloc_graph_pkt(apm, &info->sg_list, graph_id); + if (IS_ERR(graph->graph)) + return ERR_PTR(-ENOMEM); + + spin_lock(&apm->lock); + idr_alloc(&apm->graph_idr, graph, graph_id, + graph_id + 1, GFP_ATOMIC); + spin_unlock(&apm->lock); + + kref_init(&graph->refcount); + + q6apm_send_cmd_sync(apm, graph->graph, 0); + + return graph; +} + +static int audioreach_graph_mgmt_cmd(struct audioreach_graph *graph, + uint32_t opcode) +{ + struct gpr_pkt *pkt; + void *p; + int i = 0, rc, payload_size; + struct q6apm *apm = graph->apm; + struct audioreach_graph_info *info = graph->info; + int num_sub_graphs = info->num_sub_graphs; + struct apm_graph_mgmt_cmd *mgmt_cmd; + struct apm_module_param_data *param_data; + struct audioreach_sub_graph *sg; + + payload_size = APM_GRAPH_MGMT_PSIZE(num_sub_graphs); + + p = audioreach_alloc_apm_cmd_pkt(payload_size, opcode, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + mgmt_cmd = p; + mgmt_cmd->num_sub_graphs = num_sub_graphs; + + param_data = &mgmt_cmd->param_data; + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; + param_data->param_id = APM_PARAM_ID_SUB_GRAPH_LIST; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + + list_for_each_entry(sg, &info->sg_list, node) { + mgmt_cmd->sub_graph_id_list[i++] = sg->sub_graph_id; + } + + rc = q6apm_send_cmd_sync(apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +static void q6apm_put_audioreach_graph(struct kref *ref) +{ + struct audioreach_graph *graph; + struct q6apm *apm; + unsigned long flags; + + graph = container_of(ref, struct audioreach_graph, refcount); + apm = graph->apm; + + audioreach_graph_mgmt_cmd(graph, APM_CMD_GRAPH_CLOSE); + + spin_lock_irqsave(&apm->lock, flags); + graph = idr_remove(&apm->graph_idr, graph->id); + spin_unlock_irqrestore(&apm->lock, flags); + + kfree(graph->graph); + kfree(graph); +} + +static bool q6apm_get_apm_state(struct q6apm *apm) +{ + struct gpr_pkt *pkt; + + pkt = audioreach_alloc_apm_cmd_pkt(0, APM_CMD_GET_SPF_STATE, 0); + if (IS_ERR(pkt)) + return -ENOMEM; + + q6apm_send_cmd_sync(apm, pkt, APM_CMD_RSP_GET_SPF_STATE); + + kfree(pkt); + + return !apm->state ? false : true; +} + +static struct audioreach_module *__q6apm_find_module_by_mid(struct q6apm *apm, + struct audioreach_graph_info *info, + uint32_t mid) +{ + struct audioreach_sub_graph *sgs; + struct audioreach_container *container; + struct audioreach_module *module; + + list_for_each_entry(sgs, &info->sg_list, node) { + list_for_each_entry(container, &sgs->container_list, node) { + list_for_each_entry(module, &container->modules_list, node) { + if (mid == module->module_id) + return module; + } + } + } + + return NULL; +} + +static struct audioreach_module *q6apm_graph_get_last_module(struct q6apm *apm, + u32 sgid) +{ + struct audioreach_sub_graph *sg; + struct audioreach_module *module; + struct audioreach_container *container; + + spin_lock(&apm->lock); + sg = idr_find(&apm->sub_graphs_idr, sgid); + spin_unlock(&apm->lock); + if (!sg) + return NULL; + + container = list_last_entry(&sg->container_list, struct audioreach_container, node); + module = audioreach_get_container_last_module(container); + + return module; +} + +static struct audioreach_module *q6apm_graph_get_first_module(struct q6apm *apm, + u32 sgid) +{ + struct audioreach_sub_graph *sg; + struct audioreach_module *module; + struct audioreach_container *container; + + spin_lock(&apm->lock); + sg = idr_find(&apm->sub_graphs_idr, sgid); + spin_unlock(&apm->lock); + if (!sg) + return NULL; + + container = list_first_entry(&sg->container_list, struct audioreach_container, node); + module = audioreach_get_container_first_module(container); + + return module; +} + +bool q6apm_is_sub_graphs_connected(struct q6apm *apm, u32 src_sgid, u32 dst_sgid) +{ + struct audioreach_module *module; + u32 iid; + + module = q6apm_graph_get_last_module(apm, src_sgid); + if (!module) + return false; + + iid = module->instance_id; + module = q6apm_graph_get_first_module(apm, dst_sgid); + if (!module) + return false; + + if (module->src_mod_inst_id == iid) + return true; + + return false; +} + +int q6apm_connect_sub_graphs(struct q6apm *apm, u32 src_sgid, + u32 dst_sgid, bool connect) +{ + + struct audioreach_module *module; + u32 iid; + + if (connect) { + module = q6apm_graph_get_last_module(apm, src_sgid); + if (!module) + return -ENODEV; + + iid = module->instance_id; + } else { + iid = 0; + } + + module = q6apm_graph_get_first_module(apm, dst_sgid); + if (!module) + return -ENODEV; + + /* set src module in dst subgraph first module */ + module->src_mod_inst_id = iid; + + return 0; +} + +int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph) +{ + struct audioreach_module *module; + + module = q6apm_find_module_by_mid(graph, MODULE_ID_WR_SHARED_MEM_EP); + if (!module) + return -ENODEV; + + return module->instance_id; + +} +EXPORT_SYMBOL_GPL(q6apm_graph_get_rx_shmem_module_iid); + +static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op) +{ + struct q6apm_graph *graph = priv; + struct device *dev = graph->dev; + struct gpr_hdr *hdr = &data->hdr; + struct gpr_ibasic_rsp_result_t *result; + int ret = -EINVAL; + uint32_t client_event = 0; + + result = data->payload; + + switch (hdr->opcode) { + case DATA_CMD_RSP_WR_SH_MEM_EP_DATA_BUFFER_DONE_V2: + client_event = APM_CLIENT_EVENT_DATA_WRITE_DONE; + if (graph) { + struct data_cmd_rsp_wr_sh_mem_ep_data_buffer_done_v2 *done; + phys_addr_t phys; + unsigned long flags; + int token = hdr->token & APM_WRITE_TOKEN_MASK; + + spin_lock_irqsave(&graph->lock, flags); + + done = data->payload; + phys = graph->rx_data.buf[token].phys; + + if (lower_32_bits(phys) != done->buf_addr_lsw || + upper_32_bits(phys) != done->buf_addr_msw) { + dev_err(dev, "WR BUFF Expected Token %d addr %pa\n", token, &phys); + ret = -EINVAL; + } else { + ret = 0; + graph->result.opcode = hdr->opcode; + graph->result.status = done->status; + } + spin_unlock_irqrestore(&graph->lock, flags); + } else { + dev_err(dev, "No SH Mem module found\n"); + ret = -EINVAL; + } + if (graph->cb) + graph->cb(client_event, hdr->token, data->payload, + graph->priv); + + break; + case APM_CMD_RSP_SHARED_MEM_MAP_REGIONS: + if (graph) { + struct apm_cmd_rsp_shared_mem_map_regions *rsp; + + graph->result.opcode = hdr->opcode; + graph->result.status = 0; + rsp = data->payload; + + if (hdr->token == SNDRV_PCM_STREAM_PLAYBACK) + graph->rx_data.mem_map_handle = rsp->mem_map_handle; + else + graph->tx_data.mem_map_handle = rsp->mem_map_handle; + + wake_up(&graph->cmd_wait); + ret = 0; + } + break; + case DATA_CMD_RSP_RD_SH_MEM_EP_DATA_BUFFER_V2: + if (graph) { + struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 *done; + unsigned long flags; + phys_addr_t phys; + + done = data->payload; + spin_lock_irqsave(&graph->lock, flags); + phys = graph->tx_data.buf[hdr->token].phys; + if (upper_32_bits(phys) != done->buf_addr_msw || + lower_32_bits(phys) != done->buf_addr_lsw) { + dev_err(dev, "RD BUFF Expected addr %pa %08x-%08x\n", + &phys, + done->buf_addr_lsw, + done->buf_addr_msw); + ret = -EINVAL; + } else { + ret = 0; + } + spin_unlock_irqrestore(&graph->lock, flags); + client_event = APM_CLIENT_EVENT_DATA_READ_DONE; + wake_up(&graph->cmd_wait); + + if (graph->cb) + graph->cb(client_event, hdr->token, data->payload, + graph->priv); + } + + break; + case DATA_CMD_WR_SH_MEM_EP_EOS_RENDERED: + break; + case GPR_BASIC_RSP_RESULT: + switch (result->opcode) { + case APM_CMD_SHARED_MEM_UNMAP_REGIONS: + if (graph) { + graph->result.opcode = result->opcode; + graph->result.status = 0; + if (hdr->token == SNDRV_PCM_STREAM_PLAYBACK) + graph->rx_data.mem_map_handle = 0; + else + graph->tx_data.mem_map_handle = 0; + + wake_up(&graph->cmd_wait); + ret = 0; + } + + break; + case APM_CMD_SHARED_MEM_MAP_REGIONS: + case DATA_CMD_WR_SH_MEM_EP_MEDIA_FORMAT: + case APM_CMD_SET_CFG: + graph->result.opcode = result->opcode; + graph->result.status = result->status; + if (result->status) { + dev_err(dev, + "Error (%d) Processing 0x%08x cmd\n", + result->status, result->opcode); + ret = -EINVAL; + } else { + ret = 0; + } + wake_up(&graph->cmd_wait); + if (graph->cb) + graph->cb(client_event, hdr->token, data->payload, + graph->priv); + + } + break; + } + + return ret; +} + +struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb, + void *priv, int graph_id) +{ + struct q6apm *apm = dev_get_drvdata(dev->parent); + struct q6apm_graph *graph; + struct audioreach_graph *ar_graph; + int ret; + + dev_err(dev, "%s :graph id %d\n", __func__, graph_id); + ar_graph = q6apm_get_audioreach_graph(apm, graph_id); + if (IS_ERR(ar_graph)) { + dev_err(dev, "No graph found with id %d\n", graph_id); + return ERR_CAST(ar_graph); + } + + graph = kzalloc(sizeof(*graph), GFP_KERNEL); + if (!graph) { + ret = -ENOMEM; + goto err; + } + + graph->apm = apm; + graph->priv = priv; + graph->cb = cb; + graph->info = ar_graph->info; + graph->ar_graph = ar_graph; + graph->id = ar_graph->id; + graph->dev = dev; + + spin_lock_init(&graph->lock); + init_waitqueue_head(&graph->cmd_wait); + mutex_init(&graph->cmd_lock); + + graph->port = gpr_alloc_port(apm->gdev, dev, graph_callback, graph); + if (!graph->port) { + kfree(graph); + ret = -ENOMEM; + goto err; + } + + dev_dbg(dev, "%s: GRAPH-DEBUG Opening graph id %d with port id 0x%08x\n", __func__, + graph_id, graph->port->id); + + return graph; +err: + kref_put(&ar_graph->refcount, q6apm_put_audioreach_graph); + return ERR_PTR(ret); +} + +int q6apm_graph_close(struct q6apm_graph *graph) +{ + struct audioreach_graph *ar_graph = graph->ar_graph; + + gpr_free_port(graph->port); + graph->port = NULL; + kref_put(&ar_graph->refcount, q6apm_put_audioreach_graph); + kfree(graph); + + return 0; +} + +int q6apm_graph_prepare(struct q6apm_graph *graph) +{ + return audioreach_graph_mgmt_cmd(graph->ar_graph, + APM_CMD_GRAPH_PREPARE); +} + +int q6apm_graph_start(struct q6apm_graph *graph) +{ + struct audioreach_graph *ar_graph = graph->ar_graph; + int ret = 0; + + if (ar_graph->start_count == 0) + ret = audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_START); + + ar_graph->start_count++; + + return ret; +} + +int q6apm_graph_stop(struct q6apm_graph *graph) +{ + struct audioreach_graph *ar_graph = graph->ar_graph; + + if (--ar_graph->start_count > 0) + return 0; + + return audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP); +} + +int q6apm_graph_flush(struct q6apm_graph *graph) +{ + return audioreach_graph_mgmt_cmd(graph->ar_graph, APM_CMD_GRAPH_FLUSH); +} + +static int q6apm_audio_probe(struct snd_soc_component *component) +{ + return 0; +} + +static void q6apm_audio_remove(struct snd_soc_component *component) +{ +} + +#define APM_AUDIO_DRV_NAME "q6apm-audio" + +static const struct snd_soc_component_driver q6apm_audio_component = { + .name = APM_AUDIO_DRV_NAME, + .probe = q6apm_audio_probe, + .remove = q6apm_audio_remove, +}; + +static int apm_probe(gpr_device_t *gdev) +{ + struct device *dev = &gdev->dev; + struct q6apm *apm; + + apm = devm_kzalloc(dev, sizeof(*apm), GFP_KERNEL); + if (!apm) + return -ENOMEM; + + dev_set_drvdata(dev, apm); + + mutex_init(&apm->cmd_lock); + apm->dev = dev; + apm->gdev = gdev; + init_waitqueue_head(&apm->wait); + + idr_init(&apm->graph_idr); + idr_init(&apm->graph_info_idr); + idr_init(&apm->sub_graphs_idr); + idr_init(&apm->containers_idr); + + idr_init(&apm->modules_idr); + spin_lock_init(&apm->lock); + + q6apm_get_apm_state(apm); + + devm_snd_soc_register_component(dev, &q6apm_audio_component, NULL, 0); + + return of_platform_populate(dev->of_node, NULL, NULL, dev); +} + +static int apm_exit(gpr_device_t *gdev) +{ + struct q6apm *apm = dev_get_drvdata(&gdev->dev); + + kfree(apm); + + return 0; +} + +struct audioreach_module *q6apm_find_module_by_mid(struct q6apm_graph *graph, + uint32_t mid) +{ + struct audioreach_graph_info *info = graph->info; + struct q6apm *apm = graph->apm; + + return __q6apm_find_module_by_mid(apm, info, mid); + +} + +struct audioreach_module *q6apm_find_module(struct q6apm *apm, uint32_t iid) +{ + struct audioreach_module *module; + unsigned long flags; + + spin_lock_irqsave(&apm->lock, flags); + module = idr_find(&apm->modules_idr, iid); + spin_unlock_irqrestore(&apm->lock, flags); + + return module; +} + +static int apm_callback(struct gpr_resp_pkt *data, void *priv, int op) +{ + gpr_device_t *gdev = priv; + struct q6apm *apm = dev_get_drvdata(&gdev->dev); + struct device *dev = &gdev->dev; + struct gpr_ibasic_rsp_result_t *result; + struct gpr_hdr *hdr = &data->hdr; + int ret = -EINVAL; + + result = data->payload; + + switch (hdr->opcode) { + case APM_CMD_RSP_GET_SPF_STATE: + apm->result.opcode = hdr->opcode; + apm->result.status = 0; + /* First word of result it state */ + apm->state = result->opcode; + wake_up(&apm->wait); + break; + case GPR_BASIC_RSP_RESULT: + switch (result->opcode) { + case APM_CMD_GRAPH_START: + case APM_CMD_GRAPH_OPEN: + case APM_CMD_GRAPH_PREPARE: + case APM_CMD_GRAPH_CLOSE: + case APM_CMD_GRAPH_FLUSH: + case APM_CMD_GRAPH_STOP: + case APM_CMD_SET_CFG: + apm->result.opcode = result->opcode; + apm->result.status = result->status; + if (result->status) { + dev_err(dev, + "Error (%d) Processing 0x%08x cmd\n", + result->status, result->opcode); + ret = -EINVAL; + } else { + ret = 0; + } + wake_up(&apm->wait); + + } + break; + } + + return ret; +} + +static const struct of_device_id apm_device_id[] = { + { .compatible = "qcom,q6apm" }, + {}, +}; +MODULE_DEVICE_TABLE(of, apm_device_id); + +static gpr_driver_t apm_driver = { + .probe = apm_probe, + .remove = apm_exit, + .gpr_callback = apm_callback, + .driver = { + .name = "qcom-apm", + .of_match_table = of_match_ptr(apm_device_id), + }, +}; + +module_gpr_driver(apm_driver); +MODULE_DESCRIPTION("Audio Process Manager"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/qcom/audioreach/q6apm.h b/sound/soc/qcom/audioreach/q6apm.h new file mode 100644 index 000000000000..09a312571436 --- /dev/null +++ b/sound/soc/qcom/audioreach/q6apm.h @@ -0,0 +1,174 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __Q6APM_H__ +#define __Q6APM_H__ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "audioreach.h" + +#define APM_PORT_MAX 127 +#define APM_PORT_MAX_AUDIO_CHAN_CNT 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. */ + +#define NO_TIMESTAMP 0xFF00 +#define FORMAT_LINEAR_PCM 0x0000 +/* APM client callback events */ +#define CMD_EOS 0x0003 +#define APM_CLIENT_EVENT_CMD_EOS_DONE 0x1003 +#define CMD_CLOSE 0x0004 +#define APM_CLIENT_EVENT_CMD_CLOSE_DONE 0x1004 +#define APM_CLIENT_EVENT_CMD_RUN_DONE 0x1008 +#define APM_CLIENT_EVENT_DATA_WRITE_DONE 0x1009 +#define APM_CLIENT_EVENT_DATA_READ_DONE 0x100a +#define APM_WRITE_TOKEN_MASK GENMASK(15, 0) +#define APM_WRITE_TOKEN_LEN_MASK GENMASK(31, 16) +#define APM_WRITE_TOKEN_LEN_SHIFT 16 + +#define MAX_SESSIONS 8 + +struct q6apm { + struct device *dev; + gpr_port_t *port; + gpr_device_t *gdev; + /* For Graph OPEN/START/STOP/CLOSE operations */ + wait_queue_head_t wait; + struct gpr_ibasic_rsp_result_t result; + + struct mutex cmd_lock; + uint32_t state; + + spinlock_t lock; + struct idr graph_idr; + struct idr graph_info_idr; + struct idr sub_graphs_idr; + struct idr containers_idr; + struct idr modules_idr; +}; + +struct audio_buffer { + phys_addr_t phys; + uint32_t size; /* size of buffer */ +}; + +struct audioreach_graph_data { + struct audio_buffer *buf; + uint32_t num_periods; + uint32_t dsp_buf; + uint32_t mem_map_handle; +}; + +struct audioreach_graph { + struct audioreach_graph_info *info; + uint32_t id; + int state; + int start_count; + /* Cached Graph data */ + void *graph; + struct kref refcount; + struct q6apm *apm; +}; + +typedef void (*q6apm_cb) (uint32_t opcode, uint32_t token, + void *payload, void *priv); +struct q6apm_graph { + void *priv; + q6apm_cb cb; + uint32_t id; + struct device *dev; + struct q6apm *apm; + gpr_port_t *port; + struct audioreach_graph_data rx_data; + struct audioreach_graph_data tx_data; + struct gpr_ibasic_rsp_result_t result; + spinlock_t lock; + wait_queue_head_t cmd_wait; + struct mutex cmd_lock; + struct audioreach_graph *ar_graph; + struct audioreach_graph_info *info; +}; + +/* Graph Operations */ +struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb, + void *priv, int graph_id); +int q6apm_graph_close(struct q6apm_graph *graph); +int q6apm_graph_prepare(struct q6apm_graph *graph); +int q6apm_graph_start(struct q6apm_graph *graph); +int q6apm_graph_stop(struct q6apm_graph *graph); +int q6apm_graph_flush(struct q6apm_graph *graph); + +/* Media Format */ +int q6apm_graph_media_format_pcm(struct q6apm_graph *graph, int direction, + uint32_t rate, uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample); + +int q6apm_graph_media_format_shmem(struct q6apm_graph *graph, int direction, + uint32_t rate, uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample); + +/* read/write related */ +int q6apm_send_eos_nowait(struct q6apm_graph *graph); +int q6apm_read(struct q6apm_graph *graph); +int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts, + uint32_t lsw_ts, uint32_t flags); + +/* Memory Map related */ +int q6apm_map_memory_regions(struct q6apm_graph *graph, + unsigned int dir, + phys_addr_t phys, + size_t bufsz, unsigned int bufcnt); +int q6apm_unmap_memory_regions(struct q6apm_graph *graph, + unsigned int dir); +/* Helpers */ +struct audioreach_module *q6apm_find_module(struct q6apm *apm, uint32_t iid); +int q6apm_send_cmd(struct q6apm *apm, struct gpr_pkt *pkt); +int q6apm_send_cmd_sync(struct q6apm *apm, struct gpr_pkt *pkt, + uint32_t rsp_opcode); + +/* Callback for graph specific */ +struct audioreach_module *q6apm_find_module_by_mid(struct q6apm_graph *graph, + uint32_t mid); + + +struct q6apm_cdc_dma_cfg { + u16 sample_rate; + u16 bit_width; + u16 data_format; + u16 num_channels; + u16 active_channels_mask; +}; + +struct q6apm_port_config { + struct q6apm_cdc_dma_cfg dma_cfg; +}; + +void q6apm_set_fe_dai_ops(struct snd_soc_dai_driver *dai_drv); +int q6apm_connect_sub_graphs(struct q6apm *apm, u32 src_sgid, u32 dst_sgid, + bool connect); +bool q6apm_is_sub_graphs_connected(struct q6apm *apm, u32 src_sgid, + u32 dst_sgid); +int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph); + +#endif /* __APM_GRAPH_ */ From patchwork Wed Jul 14 15:30:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476802 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676600jao; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm8nPFKm/uQKUbvgacMOAd4Q/aG78QxhsG1sI6LiqPu1aIOjnEJwWIxaQo7codYOlZf60d X-Received: by 2002:a02:9f89:: with SMTP id a9mr9567298jam.51.1626276677934; Wed, 14 Jul 2021 08:31:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276677; cv=none; d=google.com; s=arc-20160816; b=J7CQKecVHhrVZugmaE/TYtQOu6xFUKi/SMCyrlW5WhfrXYJoE4C7Ff1HeRjRD5k0lI Cq+6Spalk9X9FWKIKW3QBosYQvBKJhq0yR5NMLk6b2/tSDAwxUnJ7mjj8lNWFZTWpD3t DUk8YbKbfXCkyxr+aIY+SYlL600hGD49W9tdd+HUzAYoiM0KVIXP3F08TZP0TyukS0XJ rDZMhmIksPdHAxSanEUNh915iB5Rrg/LiKyEvL5uycgI2OzjNKw/HJJ5BqXqlOGHynG2 rZX2tIFVCQAQoRbBvMaVknGpNIXFH+Mfk9w1ZHfWtx4wCaAyQjQ/0rVK6IAp3r1D+viE 56qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mWgB42DkR3oAmcAFsk9sfCjZmso4PBmA64A1HykXauE=; b=Zq/jflNR1SQj4EfheYaVQDs9qMGCu51EmRZPk58mSIZxd1f/KxRh9mahjUERkoirjs PTkxXJfZAWGgnPUG/AABv2g3OxTUdwT4HKlSZuS4+S7rBPqE1++LZld0BuiDN+LNHVWC NPjULlQtp9KMpDnPIajcTGTvauumy5jtZ1vLRX0z1NgBYTZ50rtUVQCqztPX3pkzX0w4 q1TrkzrK8x2PKeK7o83gNbsbLDImPq/UPemXshGnQ5UoUZohygbvUulUPEapVGY57Zwy oHogxCwNiXYiWyeoTucHfnap9G78zsR1YpDcgqn/sUl9rC4FsxA93wHUCyxywWsgw6vV WqEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="sQpqQ/V8"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.17; Wed, 14 Jul 2021 08:31:17 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="sQpqQ/V8"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239755AbhGNPeC (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232360AbhGNPeB (ORCPT ); Wed, 14 Jul 2021 11:34:01 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DCDCC061764 for ; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l4-20020a05600c4f04b0290220f8455631so1709159wmq.1 for ; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=mWgB42DkR3oAmcAFsk9sfCjZmso4PBmA64A1HykXauE=; b=sQpqQ/V8rktSA9xqzlq2cAdVpjd43I2bNIPxQfVnO0v2rieeYOgsXSxOIwYQCbOgaY 9gLGUJILzqmxxq98vL4cEpHzTZY+e/4x8YeVKSEbbb/kKtyDLCUXbcV9N1C11mHEa3D7 vfGoQlIYvTKqHUQUyIixBFGjptic98E6+LpPn/DjN3VF6aOpIYe0WQBK0rJ6Rvdc6jrx PbkSmKJCLEj1wB9VX5ZrNGvCG0t6X2BvMBYeO+kij4fnSGXJTyEPn72biz9N17OB258f QxP+/oiVY6RLvVYQJjCH9UanhaGKXS5Mba4zHK2arEiJhI+2DTzb8q36LeSaCrKa7bGr X+rg== 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:mime-version:content-transfer-encoding; bh=mWgB42DkR3oAmcAFsk9sfCjZmso4PBmA64A1HykXauE=; b=UHsKrG4rNXxm8Pozy287V+byWUM28FjLWFJ3mlUXuy6xkUcjqB4IorgN+LF2Peecy4 y75afvwCMBEymylENQFmc1KhsdTtPcGQD0mQNID9UG2+A7kB9Fjnq/1b4p38e4JVteku Lt6jAd8A/dbUKdcJF2ynzsRlMBl476835j44DlM8zRLKPZQdQXlZDjTyxXpVaAeETKFl YYgjuwRZd1XlbbecrRUlEpmxCjtuzqjZtJTTUf9xXdgo0wQ2scUIhBSFOQRRQFaN4SQZ It+0Ui8ezRT2xfsolbkm9xppovmuyyuTdjVkQIxkthWJi6H8m3s1ldZIfcO/6+ElMEIz yeog== X-Gm-Message-State: AOAM531S6oESe07rmyQR4eLXQD2iR13gY+FOoA15M6HUiwBHYtEnmr6l eMOSyH/lQFrhN9Mh43csT4opPQ== X-Received: by 2002:a1c:4b0a:: with SMTP id y10mr11729600wma.178.1626276667862; Wed, 14 Jul 2021 08:31:07 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:07 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 07/16] ASoC: qcom: audioreach: add module configuration command helpers Date: Wed, 14 Jul 2021 16:30:30 +0100 Message-Id: <20210714153039.28373-8-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Audioreach module configuration helpers, which will be used by the q6apm-dai driver. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/audioreach/audioreach.c | 550 +++++++++++++++++++++++++ sound/soc/qcom/audioreach/audioreach.h | 21 + sound/soc/qcom/audioreach/q6apm.c | 264 ++++++++++++ 3 files changed, 835 insertions(+) -- 2.21.0 diff --git a/sound/soc/qcom/audioreach/audioreach.c b/sound/soc/qcom/audioreach/audioreach.c index 22197b88e686..1839d872fd5f 100644 --- a/sound/soc/qcom/audioreach/audioreach.c +++ b/sound/soc/qcom/audioreach/audioreach.c @@ -576,3 +576,553 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm, return pkt; } +int audioreach_graph_send_cmd_sync(struct q6apm_graph *graph, + struct gpr_pkt *pkt, uint32_t rsp_opcode) +{ + + struct device *dev = graph->dev; + struct gpr_hdr *hdr = &pkt->hdr; + int rc; + + mutex_lock(&graph->cmd_lock); + graph->result.opcode = 0; + graph->result.status = 0; + + rc = gpr_send_port_pkt(graph->port, pkt); + if (rc < 0) + goto err; + + if (rsp_opcode) + rc = wait_event_timeout(graph->cmd_wait, + (graph->result.opcode == hdr->opcode) || + (graph->result.opcode == rsp_opcode), + 5 * HZ); + else + rc = wait_event_timeout(graph->cmd_wait, + (graph->result.opcode == hdr->opcode), + 5 * HZ); + + if (!rc) { + dev_err(dev, "CMD timeout for [%x] opcode\n", hdr->opcode); + rc = -ETIMEDOUT; + } else if (graph->result.status > 0) { + dev_err(dev, "DSP returned error[%x] %x\n", hdr->opcode, + graph->result.status); + rc = -EINVAL; + } else { + dev_err(dev, "DSP returned [%x]\n", graph->result.status); + rc = 0; + } + +err: + mutex_unlock(&graph->cmd_lock); + return rc; +} +EXPORT_SYMBOL_GPL(audioreach_graph_send_cmd_sync); + +static int audioreach_codec_dma_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t num_channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct apm_module_param_data *param_data; + struct apm_codec_dma_module_intf_cfg *intf_cfg; + struct apm_module_hw_ep_mf_cfg *hw_cfg; + struct apm_module_frame_size_factor_cfg *fs_cfg; + struct apm_module_hw_ep_power_mode_cfg *pm_cfg; + int ic_sz, ep_sz, fs_sz, pm_sz, dl_sz; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + ic_sz = APM_CDMA_INTF_CFG_PSIZE; + ep_sz = APM_HW_EP_CFG_PSIZE; + fs_sz = APM_FS_CFG_PSIZE; + pm_sz = APM_HW_EP_PMODE_CFG_PSIZE; + dl_sz = 0; + + payload_size = ic_sz + ep_sz + fs_sz + pm_sz + dl_sz; + + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + hw_cfg = p; + param_data = &hw_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_HW_EP_MF_CFG; + param_data->param_size = ep_sz - APM_MODULE_PARAM_DATA_SIZE; + + hw_cfg->mf.sample_rate = rate; + hw_cfg->mf.bit_width = bits_per_sample; + hw_cfg->mf.num_channels = num_channels; + hw_cfg->mf.data_format = module->data_format; + p += ep_sz; + + fs_cfg = p; + param_data = &fs_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_HW_EP_FRAME_SIZE_FACTOR; + param_data->param_size = fs_sz - APM_MODULE_PARAM_DATA_SIZE; + fs_cfg->frame_size_factor = 1; + p += fs_sz; + + intf_cfg = p; + param_data = &intf_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_CODEC_DMA_INTF_CFG; + param_data->param_size = ic_sz - APM_MODULE_PARAM_DATA_SIZE; + + intf_cfg->cfg.lpaif_type = module->hw_interface_type; + intf_cfg->cfg.intf_index = module->hw_interface_idx; + intf_cfg->cfg.active_channels_mask = (1 << num_channels) - 1; + p += ic_sz; + + pm_cfg = p; + param_data = &pm_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_HW_EP_POWER_MODE_CFG; + param_data->param_size = pm_sz - APM_MODULE_PARAM_DATA_SIZE; + pm_cfg->power_mode.power_mode = 0; + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +static int audioreach_i2s_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t num_channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct apm_module_frame_size_factor_cfg *fs_cfg; + struct apm_module_param_data *param_data; + struct apm_i2s_module_intf_cfg *intf_cfg; + struct apm_module_hw_ep_mf_cfg *hw_cfg; + int ic_sz, ep_sz, fs_sz; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + ic_sz = APM_I2S_INTF_CFG_PSIZE; + ep_sz = APM_HW_EP_CFG_PSIZE; + fs_sz = APM_FS_CFG_PSIZE; + + payload_size = ic_sz + ep_sz + fs_sz; + + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + intf_cfg = p; + + param_data = &intf_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_I2S_INTF_CFG; + param_data->param_size = ic_sz - APM_MODULE_PARAM_DATA_SIZE; + + intf_cfg->cfg.intf_idx = module->hw_interface_idx; + intf_cfg->cfg.sd_line_idx = module->sd_line_idx; + intf_cfg->cfg.ws_src = module->ws_src; + + p += ic_sz; + hw_cfg = p; + param_data = &hw_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_HW_EP_MF_CFG; + param_data->param_size = ep_sz - APM_MODULE_PARAM_DATA_SIZE; + + hw_cfg->mf.sample_rate = rate; + hw_cfg->mf.bit_width = bits_per_sample; + hw_cfg->mf.num_channels = num_channels; + hw_cfg->mf.data_format = module->data_format; + + p += ep_sz; + fs_cfg = p; + param_data = &fs_cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_HW_EP_FRAME_SIZE_FACTOR; + param_data->param_size = fs_sz - APM_MODULE_PARAM_DATA_SIZE; + fs_cfg->frame_size_factor = 1; + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +static int audioreach_logging_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module) +{ + struct apm_module_param_data *param_data; + struct data_logging_config *cfg; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + payload_size = sizeof(*cfg) + APM_MODULE_PARAM_DATA_SIZE; + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + param_data = p; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_DATA_LOGGING_CONFIG; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + + p = p + APM_MODULE_PARAM_DATA_SIZE; + cfg = p; + cfg->log_code = module->log_code; + cfg->log_tap_point_id = module->log_tap_point_id; + cfg->mode = module->mode; + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +static int audioreach_pcm_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t num_channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct apm_pcm_module_media_fmt_cmd *cfg; + struct apm_module_param_data *param_data; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + payload_size = APM_PCM_MODULE_FMT_CMD_PSIZE(num_channels); + + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + cfg = p; + + param_data = &cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_PCM_OUTPUT_FORMAT_CFG; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + + cfg->header.data_format = DATA_FORMAT_FIXED_POINT; + cfg->header.fmt_id = MEDIA_FMT_ID_PCM; + cfg->header.payload_size = APM_PCM_OUT_FMT_CFG_PSIZE(num_channels); + + cfg->media_cfg.alignment = PCM_LSB_ALIGNED; + cfg->media_cfg.bit_width = bits_per_sample; + cfg->media_cfg.endianness = PCM_LITTLE_ENDIAN; + cfg->media_cfg.interleaved = module->interleave_type; + cfg->media_cfg.num_channels = num_channels; + cfg->media_cfg.q_factor = bits_per_sample - 1; + cfg->media_cfg.bits_per_sample = bits_per_sample; + + if (num_channels == 1) { + cfg->media_cfg.channel_mapping[0] = PCM_CHANNEL_L; + } else if (num_channels == 2) { + cfg->media_cfg.channel_mapping[0] = PCM_CHANNEL_L; + cfg->media_cfg.channel_mapping[1] = PCM_CHANNEL_R; + } else { + dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels); + } + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +static int audioreach_shmem_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t num_channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct apm_module_param_data *param_data; + struct payload_media_fmt_pcm *cfg; + struct media_format *header; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + if (num_channels < 0 || num_channels > 2) + dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels); + + payload_size = APM_SHMEM_FMT_CFG_PSIZE(num_channels) + APM_MODULE_PARAM_DATA_SIZE; + + p = audioreach_alloc_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0, + graph->port->id, module->instance_id); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + param_data = p; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_MEDIA_FORMAT; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + p = p + APM_MODULE_PARAM_DATA_SIZE; + + header = p; + header->data_format = DATA_FORMAT_FIXED_POINT; + header->fmt_id = MEDIA_FMT_ID_PCM; + header->payload_size = payload_size - sizeof(*header); + + p = p + sizeof(*header); + cfg = p; + cfg->sample_rate = rate; + cfg->bit_width = bits_per_sample; + cfg->alignment = PCM_LSB_ALIGNED; + cfg->bits_per_sample = bits_per_sample; + cfg->q_factor = bits_per_sample - 1; + cfg->endianness = PCM_LITTLE_ENDIAN; + cfg->num_channels = num_channels; + + if (num_channels == 1) { + cfg->channel_mapping[0] = PCM_CHANNEL_L; + } else if (num_channels == 2) { + cfg->channel_mapping[0] = PCM_CHANNEL_L; + cfg->channel_mapping[1] = PCM_CHANNEL_R; + } else { + dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels); + } + + rc = audioreach_graph_send_cmd_sync(graph, pkt, 0); + + kfree(pkt); + + return rc; +} + +static int audioreach_gain_set(struct q6apm_graph *graph, + struct audioreach_module *module) +{ + struct apm_module_param_data *param_data; + struct apm_gain_module_cfg *cfg; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + payload_size = APM_GAIN_CFG_PSIZE; + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + cfg = p; + + param_data = &cfg->param_data; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = APM_PARAM_ID_GAIN; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + + cfg->gain_cfg.gain = module->gain; + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + + kfree(pkt); + + return rc; +} + +int audioreach_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + int rc; + + switch (module->module_id) { + case MODULE_ID_DATA_LOGGING: + rc = audioreach_logging_set_media_format(graph, module); + break; + case MODULE_ID_PCM_DEC: + case MODULE_ID_PCM_ENC: + case MODULE_ID_PCM_CNV: + rc = audioreach_pcm_set_media_format(graph, module, + direction, rate, + channels, channel_map, + bits_per_sample); + break; + case MODULE_ID_I2S_SINK: + rc = audioreach_i2s_set_media_format(graph, module, + direction, rate, + channels, channel_map, + bits_per_sample); + break; + case MODULE_ID_WR_SHARED_MEM_EP: + rc = audioreach_shmem_set_media_format(graph, module, + direction, rate, + channels, channel_map, + bits_per_sample); + break; + case MODULE_ID_GAIN: + rc = audioreach_gain_set(graph, module); + break; + case MODULE_ID_CODEC_DMA_SINK: + case MODULE_ID_CODEC_DMA_SOURCE: + rc = audioreach_codec_dma_set_media_format(graph, module, + direction, rate, + channels, channel_map, + bits_per_sample); + break; + default: + rc = 0; + } + + return rc; +} +EXPORT_SYMBOL_GPL(audioreach_set_media_format); + +void audioreach_graph_free_buf(struct q6apm_graph *graph) +{ + struct audioreach_graph_data *port; + unsigned long flags; + + spin_lock_irqsave(&graph->lock, flags); + port = &graph->rx_data; + port->num_periods = 0; + kfree(port->buf); + port->buf = NULL; + + port = &graph->tx_data; + port->num_periods = 0; + kfree(port->buf); + port->buf = NULL; + spin_unlock_irqrestore(&graph->lock, flags); +} +EXPORT_SYMBOL_GPL(audioreach_graph_free_buf); + +int audioreach_map_memory_regions(struct q6apm_graph *graph, + unsigned int dir, size_t period_sz, + unsigned int periods, + bool is_contiguous) +{ + struct apm_shared_map_region_payload *mregions; + struct apm_cmd_shared_mem_map_regions *cmd; + uint32_t num_regions, buf_sz, payload_size; + struct audioreach_graph_data *data; + struct audio_buffer *ab; + unsigned long flags; + struct gpr_pkt *pkt; + void *p; + int rc, i; + + if (dir == SNDRV_PCM_STREAM_PLAYBACK) + data = &graph->rx_data; + else + data = &graph->tx_data; + + if (is_contiguous) { + num_regions = 1; + buf_sz = period_sz * periods; + } else { + buf_sz = period_sz; + num_regions = periods; + } + + /* DSP expects size should be aligned to 4K */ + buf_sz = ALIGN(buf_sz, 4096); + + payload_size = sizeof(*cmd) + (sizeof(*mregions) * num_regions); + + p = audioreach_alloc_apm_pkt(payload_size, + APM_CMD_SHARED_MEM_MAP_REGIONS, dir, + graph->port->id); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE; + cmd = p; + cmd->mem_pool_id = APM_MEMORY_MAP_SHMEM8_4K_POOL; + cmd->num_regions = num_regions; + + cmd->property_flag = 0x0; + + mregions = p + sizeof(*cmd); + + spin_lock_irqsave(&graph->lock, flags); + + for (i = 0; i < num_regions; i++) { + ab = &data->buf[i]; + mregions->shm_addr_lsw = lower_32_bits(ab->phys); + mregions->shm_addr_msw = upper_32_bits(ab->phys); + mregions->mem_size_bytes = buf_sz; + ++mregions; + } + spin_unlock_irqrestore(&graph->lock, flags); + + rc = audioreach_graph_send_cmd_sync(graph, pkt, + APM_CMD_RSP_SHARED_MEM_MAP_REGIONS); + + kfree(pkt); + + return rc; +} +EXPORT_SYMBOL_GPL(audioreach_map_memory_regions); + +int audioreach_shared_memory_send_eos(struct q6apm_graph *graph) +{ + struct data_cmd_wr_sh_mem_ep_eos *eos; + struct gpr_pkt *pkt; + int rc = 0, iid; + void *p; + + iid = q6apm_graph_get_rx_shmem_module_iid(graph); + p = audioreach_alloc_cmd_pkt(sizeof(*eos), + DATA_CMD_WR_SH_MEM_EP_EOS, + 0, + graph->port->id, iid); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + eos = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + eos->policy = WR_SH_MEM_EP_EOS_POLICY_LAST; + + rc = gpr_send_port_pkt(graph->port, pkt); + kfree(pkt); + + return rc; +} +EXPORT_SYMBOL_GPL(audioreach_shared_memory_send_eos); diff --git a/sound/soc/qcom/audioreach/audioreach.h b/sound/soc/qcom/audioreach/audioreach.h index cd5111a23a6a..6279ddc3c5ce 100644 --- a/sound/soc/qcom/audioreach/audioreach.h +++ b/sound/soc/qcom/audioreach/audioreach.h @@ -634,6 +634,27 @@ void *audioreach_alloc_pkt(int pkt_size, uint32_t opcode, uint32_t token, void *audioreach_alloc_graph_pkt(struct q6apm *apm, struct list_head *sg_list, int graph_id); +/* Topology specific */ +int audioreach_tplg_init(struct snd_soc_component *component); + +/* Module specific */ +void audioreach_graph_free_buf(struct q6apm_graph *graph); +int audioreach_map_memory_regions(struct q6apm_graph *graph, + unsigned int dir, size_t period_sz, + unsigned int periods, + bool is_contiguous); +int audioreach_graph_send_cmd_sync(struct q6apm_graph *graph, + struct gpr_pkt *pkt, + uint32_t rsp_opcode); +int audioreach_set_media_format(struct q6apm_graph *graph, + struct audioreach_module *module, + int direction, uint32_t rate, + uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample); +int audioreach_shared_memory_send_eos(struct q6apm_graph *graph); +int audioreach_gain_set_vol_ctrl(struct q6apm *apm, + struct audioreach_module *module, int vol); struct audioreach_module *audioreach_get_container_last_module( struct audioreach_container *container); struct audioreach_module *audioreach_get_container_first_module( diff --git a/sound/soc/qcom/audioreach/q6apm.c b/sound/soc/qcom/audioreach/q6apm.c index 9b804b863834..c18a688c9d1f 100644 --- a/sound/soc/qcom/audioreach/q6apm.c +++ b/sound/soc/qcom/audioreach/q6apm.c @@ -309,6 +309,171 @@ int q6apm_connect_sub_graphs(struct q6apm *apm, u32 src_sgid, return 0; } +int q6apm_graph_media_format_shmem(struct q6apm_graph *graph, + int direction, uint32_t rate, + uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct audioreach_module *module; + + if (direction == SNDRV_PCM_STREAM_CAPTURE) + module = q6apm_find_module_by_mid(graph, + MODULE_ID_RD_SHARED_MEM_EP); + else + module = q6apm_find_module_by_mid(graph, + MODULE_ID_WR_SHARED_MEM_EP); + + if (!module) + return -ENODEV; + + audioreach_set_media_format(graph, module, direction, rate, + channels, channel_map, + bits_per_sample); + + return 0; + +} +EXPORT_SYMBOL_GPL(q6apm_graph_media_format_shmem); + +int q6apm_map_memory_regions(struct q6apm_graph *graph, + unsigned int dir, phys_addr_t phys, + size_t period_sz, unsigned int periods) +{ + struct audioreach_graph_data *data; + struct audio_buffer *buf; + unsigned long flags; + int cnt; + int rc; + + if (dir == SNDRV_PCM_STREAM_PLAYBACK) + data = &graph->rx_data; + else + data = &graph->tx_data; + + spin_lock_irqsave(&graph->lock, flags); + + if (data->buf) { + dev_err(graph->dev, "Buffer already allocated\n"); + spin_unlock_irqrestore(&graph->lock, flags); + return 0; + } + + buf = kzalloc(((sizeof(struct audio_buffer)) * periods), GFP_ATOMIC); + if (!buf) { + spin_unlock_irqrestore(&graph->lock, flags); + return -ENOMEM; + } + + if (dir == SNDRV_PCM_STREAM_PLAYBACK) + data = &graph->rx_data; + else + data = &graph->tx_data; + + data->buf = buf; + + buf[0].phys = phys; + buf[0].size = period_sz; + + for (cnt = 1; cnt < periods; cnt++) { + if (period_sz > 0) { + buf[cnt].phys = buf[0].phys + (cnt * period_sz); + buf[cnt].size = period_sz; + } + } + data->num_periods = periods; + + spin_unlock_irqrestore(&graph->lock, flags); + + rc = audioreach_map_memory_regions(graph, dir, period_sz, + periods, 1); + if (rc < 0) { + dev_err(graph->dev, "Memory_map_regions failed\n"); + audioreach_graph_free_buf(graph); + } + + return rc; +} +EXPORT_SYMBOL_GPL(q6apm_map_memory_regions); + +int q6apm_unmap_memory_regions(struct q6apm_graph *graph, + unsigned int dir) +{ + struct audioreach_graph_data *data; + struct apm_cmd_shared_mem_unmap_regions *cmd = NULL; + struct gpr_pkt *pkt; + void *p; + int rc; + + if (dir == SNDRV_PCM_STREAM_PLAYBACK) + data = &graph->rx_data; + else + data = &graph->tx_data; + + if (!data->mem_map_handle) + return 0; + + p = audioreach_alloc_apm_pkt(sizeof(*cmd), + APM_CMD_SHARED_MEM_UNMAP_REGIONS, dir, + graph->port->id); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + cmd = p + GPR_HDR_SIZE; + cmd->mem_map_handle = data->mem_map_handle; + + rc = audioreach_graph_send_cmd_sync(graph, pkt, APM_CMD_SHARED_MEM_UNMAP_REGIONS); + kfree(pkt); + + audioreach_graph_free_buf(graph); + + return rc; +} +EXPORT_SYMBOL_GPL(q6apm_unmap_memory_regions); + +int q6apm_graph_media_format_pcm(struct q6apm_graph *graph, + int direction, uint32_t rate, + uint32_t channels, + u8 channel_map[PCM_MAX_NUM_CHANNEL], + uint16_t bits_per_sample) +{ + struct audioreach_graph_info *info = graph->info; + struct audioreach_sub_graph *sgs; + struct audioreach_container *container; + struct audioreach_module *module; + + list_for_each_entry(sgs, &info->sg_list, node) { + list_for_each_entry(container, &sgs->container_list, node) { + list_for_each_entry(module, &container->modules_list, node) { + if ((module->module_id == MODULE_ID_WR_SHARED_MEM_EP) || + (module->module_id == MODULE_ID_WR_SHARED_MEM_EP)) + continue; + + audioreach_set_media_format(graph, module, direction, rate, + channels, channel_map, + bits_per_sample); + } + } + } + + return 0; + +} +EXPORT_SYMBOL_GPL(q6apm_graph_media_format_pcm); + +static int q6apm_graph_get_tx_shmem_module_iid(struct q6apm_graph *graph) +{ + struct audioreach_module *module; + + module = q6apm_find_module_by_mid(graph, MODULE_ID_RD_SHARED_MEM_EP); + if (!module) + return -ENODEV; + + return module->instance_id; + +} + int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph) { struct audioreach_module *module; @@ -322,6 +487,105 @@ int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph) } EXPORT_SYMBOL_GPL(q6apm_graph_get_rx_shmem_module_iid); +int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts, + uint32_t lsw_ts, uint32_t wflags) +{ + struct gpr_pkt *pkt; + void *p; + int rc, payload_size, iid; + struct apm_data_cmd_wr_sh_mem_ep_data_buffer_v2 *write; + struct audio_buffer *ab; + unsigned long flags; + + payload_size = sizeof(*write); + + iid = q6apm_graph_get_rx_shmem_module_iid(graph); + p = audioreach_alloc_pkt(payload_size, + DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER_V2, + graph->rx_data.dsp_buf | (len << APM_WRITE_TOKEN_LEN_SHIFT), + graph->port->id, iid); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE; + write = p; + + spin_lock_irqsave(&graph->lock, flags); + ab = &graph->rx_data.buf[graph->rx_data.dsp_buf]; + + write->buf_addr_lsw = lower_32_bits(ab->phys); + write->buf_addr_msw = upper_32_bits(ab->phys); + write->buf_size = len; + write->timestamp_lsw = lsw_ts; + write->timestamp_msw = msw_ts; + write->mem_map_handle = graph->rx_data.mem_map_handle; + + //FIXME use other flags + if (wflags == NO_TIMESTAMP) + write->flags = 0; + else + write->flags = 0x80000000; + + graph->rx_data.dsp_buf++; + + if (graph->rx_data.dsp_buf >= graph->rx_data.num_periods) + graph->rx_data.dsp_buf = 0; + + spin_unlock_irqrestore(&graph->lock, flags); + + rc = gpr_send_port_pkt(graph->port, pkt); + + kfree(pkt); + + return rc; +} +EXPORT_SYMBOL_GPL(q6apm_write_async); + +int q6apm_read(struct q6apm_graph *graph) +{ + struct data_cmd_rd_sh_mem_ep_data_buffer_v2 *read; + struct audioreach_graph_data *port; + struct audio_buffer *ab; + struct gpr_pkt *pkt; + unsigned long flags; + int rc = 0, iid; + void *p; + + iid = q6apm_graph_get_tx_shmem_module_iid(graph); + p = audioreach_alloc_pkt(sizeof(*read), + DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER_V2, + graph->tx_data.dsp_buf, + graph->port->id, iid); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + read = p + GPR_HDR_SIZE; + + spin_lock_irqsave(&graph->lock, flags); + port = &graph->tx_data; + ab = &port->buf[port->dsp_buf]; + + read->buf_addr_lsw = lower_32_bits(ab->phys); + read->buf_addr_msw = upper_32_bits(ab->phys); + read->mem_map_handle = port->mem_map_handle; + read->buf_size = ab->size; + + port->dsp_buf++; + + if (port->dsp_buf >= port->num_periods) + port->dsp_buf = 0; + + spin_unlock_irqrestore(&graph->lock, flags); + + rc = gpr_send_port_pkt(graph->port, pkt); + kfree(pkt); + + return rc; +} +EXPORT_SYMBOL_GPL(q6apm_read); + static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op) { struct q6apm_graph *graph = priv; From patchwork Wed Jul 14 15:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476805 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676613jao; Wed, 14 Jul 2021 08:31:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFPiFtoTGkE2ROSwnyEnG030cS9lG3oVwc2KvS2KouXS5y3jFA/O2Aiu0u5Y6GkPiRy9KW X-Received: by 2002:a92:c7c4:: with SMTP id g4mr7032126ilk.252.1626276679581; Wed, 14 Jul 2021 08:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276679; cv=none; d=google.com; s=arc-20160816; b=GodE88lkTK01/aaDBw9IBGBRQUExQqByGJvn5XH6LhA0by6U7LU6r2l1bh5TdbFTY8 nWUM8YIFzdHSbaqcheeYQf1iK3Jg0usaYhei9ze0tzRt91hxRGKKUvcBEY6QuutbiKIB HqVqrmQ/sXMcBMCK2Hfe3eGpA4j2T99XIvwXa9/UYGSuTB9bLIBx2oNr3k8+GxplwV0N RwO/4KkgFa/PqB0zP6R5auCk8fDHrpbcNWR6jAkYldoEcX9ScaCjsLcQ/4XTbdpUV91w oDH1zkyEuxIBBIDssXwBxzL4hFbHhl0Jqfh6ryctNx6Lv5ck6gL9TKk/bwQZjRXk4xDE TNzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CVV8es9VGAn6TCTZJehfAtmoLco5lZpg7htRCnMJl2c=; b=gKYd0RwAe8R0cS3YF0QPdhg6Sx82R4kf+KWgG1u20xmWiebAcqCJu2kba1Ydg2Ag/O 8/Mq3vV4npjkTBIgOAGdNcwpCcHNrybuWyNOx67Sz8KNZJEUD9WCYPiXurTNE76EUV4A H7lH0v19drJRiqxeMkkCvRSms//WUs3QjYkGe4mw63MKQ9/5BQD0VJMKgDQD+PEcrGzu WvaKDxkUW0+62Cs19nkERzwMKjZkpQ2j8IvMcCsomHtx/cDRpBtbgM0kBt5ptyNMMe2V ArKaKgftphB79pBcRCCgxC1FTFIGWlTW5OB9CRaDY62h+mGkg+GdXsEKtjS3bTeiFu4H C28A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KwiCP/Li"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.19; Wed, 14 Jul 2021 08:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KwiCP/Li"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239740AbhGNPeJ (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239762AbhGNPeD (ORCPT ); Wed, 14 Jul 2021 11:34:03 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3E10C061764 for ; Wed, 14 Jul 2021 08:31:10 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so4182452wms.1 for ; Wed, 14 Jul 2021 08:31:10 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=CVV8es9VGAn6TCTZJehfAtmoLco5lZpg7htRCnMJl2c=; b=KwiCP/LiNZMmsuhcSzI6B+90mCflbdT1ggnEu6Z17uuKMxgBwejYwPf0vUO9viR/Zz 5XdCiQ0gHeZCxPrwFj9OuS5okvi2tMFOCfpvbFj8BKknZbxOHne966dcVPTim3x8t1on m8w9qwmKCuzNdiZtjUlBKmIr9MkPRcBNdLMvSWP24Slb23VS6PQN9H5xNWoxpYoamJo+ 8Cm43cEVOyyTvbsA2gKbe7ghwmyvP8cDua4UE22V8wrxpXJmi5XIm6D+pS3+jvXY/TrT Rl3WihagQ4IRMr0hnhL4WTacXub5adLXg1vgt2EpT50OJBwR4MIV2iy3tAKATPsQOXgw 5rhQ== 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:mime-version:content-transfer-encoding; bh=CVV8es9VGAn6TCTZJehfAtmoLco5lZpg7htRCnMJl2c=; b=YSRvyK0IOYznb+YHrOfXiAM4UVgEYcUPUXxh52qPkg/0iaHZbfou6cM6EWtuRUUJy7 GLCKIrWKznaBetUSPe3ELSMWQc/6b1peVtpDLTyIHVC0axU4E+XFmY6VrqYj7NR7bppO dtaCM5kmuRy1ynJKhicGmxAzQK6yMMZjgXEq3RRb0OvvOQ7+1vc+tQoMdyklCNrZoKZ4 RLxpRhGDEW325uDKtUhZL0g5TCGJrVoG1fxasJfjTPodFeHiUbQzI0bdqhI/3JnoCqh3 7PP5P01ZiAepOmBoXRp0n0x1m07nRLAdpgQz2t5xGytWNkt0bYTeVP6H26+zjNIfDnsE OGZQ== X-Gm-Message-State: AOAM530iyMU71gLkzyql9f2ONHsrTPWyQ3pwhFkY6vsiF70a1teI2upr EJTOKv54C/z1SuT+nteQITcIDw== X-Received: by 2002:a1c:f016:: with SMTP id a22mr12091909wmb.65.1626276669082; Wed, 14 Jul 2021 08:31:09 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:08 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 08/16] ASoC: qcom: audioreach: add topology support Date: Wed, 14 Jul 2021 16:30:31 +0100 Message-Id: <20210714153039.28373-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add ASoC topology support in audioreach Signed-off-by: Srinivas Kandagatla --- include/uapi/sound/snd_ar_tokens.h | 198 +++++ sound/soc/qcom/Kconfig | 1 + sound/soc/qcom/audioreach/Makefile | 2 +- sound/soc/qcom/audioreach/q6apm.c | 4 +- sound/soc/qcom/audioreach/topology.c | 1015 ++++++++++++++++++++++++++ 5 files changed, 1218 insertions(+), 2 deletions(-) create mode 100644 include/uapi/sound/snd_ar_tokens.h create mode 100644 sound/soc/qcom/audioreach/topology.c -- 2.21.0 diff --git a/include/uapi/sound/snd_ar_tokens.h b/include/uapi/sound/snd_ar_tokens.h new file mode 100644 index 000000000000..977e5e07697b --- /dev/null +++ b/include/uapi/sound/snd_ar_tokens.h @@ -0,0 +1,198 @@ +#ifndef __SND_AR_TOKENS_H__ +#define __SND_AR_TOKENS_H__ + +#define APM_SUB_GRAPH_PERF_MODE_LOW_POWER 0x1 +#define APM_SUB_GRAPH_PERF_MODE_LOW_LATENCY 0x2 + +#define APM_SUB_GRAPH_DIRECTION_TX 0x1 +#define APM_SUB_GRAPH_DIRECTION_RX 0x2 + +/** Scenario ID Audio Playback */ +#define APM_SUB_GRAPH_SID_AUDIO_PLAYBACK 0x1 +/* Scenario ID Audio Record */ +#define APM_SUB_GRAPH_SID_AUDIO_RECORD 0x2 +/* Scenario ID Voice call. */ +#define APM_SUB_GRAPH_SID_VOICE_CALL 0x3 + +/* container capability ID Pre/Post Processing (PP) */ +#define APM_CONTAINER_CAP_ID_PP 0x1 +/* container capability ID Compression/Decompression (CD) */ +#define APM_CONTAINER_CAP_ID_CD 0x2 +/* container capability ID End Point(EP) */ +#define APM_CONTAINER_CAP_ID_EP 0x3 +/* container capability ID Offload (OLC) */ +#define APM_CONTAINER_CAP_ID_OLC 0x4 + +/* container graph position Stream */ +#define APM_CONT_GRAPH_POS_STREAM 0x1 +/* container graph position Per Stream Per Device*/ +#define APM_CONT_GRAPH_POS_PER_STR_PER_DEV 0x2 +/* container graph position Stream-Device */ +#define APM_CONT_GRAPH_POS_STR_DEV 0x3 +/* container graph position Global Device */ +#define APM_CONT_GRAPH_POS_GLOBAL_DEV 0x4 + +#define APM_PROC_DOMAIN_ID_MDSP 0x1 +#define APM_PROC_DOMAIN_ID_ADSP 0x2 +#define APM_PROC_DOMAIN_ID_SDSP 0x4 +#define APM_PROC_DOMAIN_ID_CDSP 0x5 + +#define PCM_INTERLEAVED 1 +#define PCM_DEINTERLEAVED_PACKED 2 +#define PCM_DEINTERLEAVED_UNPACKED 3 +#define AR_I2S_WS_SRC_EXTERNAL 0 +#define AR_I2S_WS_SRC_INTERNAL 1 + +/* + * Kcontrol IDs + */ +#define SND_SOC_AR_TPLG_FE_BE_GRAPH_CTL_MIX 256 +#define SND_SOC_AR_TPLG_VOL_CTL 257 + +/** + * %AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: Sub Graph Instance Id + * + * %AR_TKN_U32_SUB_GRAPH_PERF_MODE: Performance mode of subgraph + * APM_SUB_GRAPH_PERF_MODE_LOW_POWER = 1, + * APM_SUB_GRAPH_PERF_MODE_LOW_LATENCY = 2 + * + * %AR_TKN_U32_SUB_GRAPH_DIRECTION: Direction of subgraph + * APM_SUB_GRAPH_DIRECTION_TX = 1, + * APM_SUB_GRAPH_DIRECTION_RX = 2 + * + * %AR_TKN_U32_SUB_GRAPH_SCENARIO_ID: Scenario ID for subgraph + * APM_SUB_GRAPH_SID_AUDIO_PLAYBACK = 1, + * APM_SUB_GRAPH_SID_AUDIO_RECORD = 2, + * APM_SUB_GRAPH_SID_VOICE_CALL = 3 + * + * %AR_TKN_U32_CONAINER_INSTANCE_ID: Container Instance ID + * + * %AR_TKN_U32_CONAINER_CAPABILITY_ID: Container capability ID + * APM_CONTAINER_CAP_ID_PP = 1, + * APM_CONTAINER_CAP_ID_CD = 2, + * APM_CONTAINER_CAP_ID_EP = 3, + * APM_CONTAINER_CAP_ID_OLC = 4 + * + * %AR_TKN_U32_CONAINER_STACK_SIZE: Stack size in the container. + * + * %AR_TKN_U32_CONAINER_GRAPH_POS: Graph Position + * APM_CONT_GRAPH_POS_STREAM = 1, + * APM_CONT_GRAPH_POS_PER_STR_PER_DEV = 2, + * APM_CONT_GRAPH_POS_STR_DEV = 3, + * APM_CONT_GRAPH_POS_GLOBAL_DEV = 4 + * + * %AR_TKN_U32_CONAINER_PROC_DOMAIN: Processor domain of container + * APM_PROC_DOMAIN_ID_MDSP = 1, + * APM_PROC_DOMAIN_ID_ADSP = 2, + * APM_PROC_DOMAIN_ID_SDSP = 4, + * APM_PROC_DOMAIN_ID_CDSP = 5 + * + * %AR_TKN_U32_MODULE_ID: Module ID + * + * %AR_TKN_U32_MODULE_INSTANCE_ID: Module Instance ID. + * + * %AR_TKN_U32_MODULE_MAX_IP_PORTS: Module maximum input ports + * + * %AR_TKN_U32_MODULE_MAX_OP_PORTS: Module maximum output ports. + * + * %AR_TKN_U32_MODULE_IN_PORTS: Number of in ports + * + * %AR_TKN_U32_MODULE_OUT_PORTS: Number of out ports. + * + * %AR_TKN_U32_MODULE_SRC_OP_PORT_ID: Source module output port ID + * + * %AR_TKN_U32_MODULE_DST_IN_PORT_ID: Destination module input port ID + * + * %AR_TKN_U32_MODULE_HW_IF_IDX: Interface index types for I2S/LPAIF + * + * %AR_TKN_U32_MODULE_HW_IF_TYPE: Interface type + * LPAIF = 0, + * LPAIF_RXTX = 1, + * LPAIF_WSA = 2, + * LPAIF_VA = 3, + * LPAIF_AXI = 4 + * + * %AR_TKN_U32_MODULE_FMT_INTERLEAVE: PCM Interleaving + * PCM_INTERLEAVED = 1, + * PCM_DEINTERLEAVED_PACKED = 2, + * PCM_DEINTERLEAVED_UNPACKED = 3 + * + * %AR_TKN_U32_MODULE_FMT_DATA: data format + * FIXED POINT = 1, + * IEC60958 PACKETIZED = 3, + * IEC60958 PACKETIZED NON LINEAR = 8, + * COMPR OVER PCM PACKETIZED = 7, + * IEC61937 PACKETIZED = 2, + * GENERIC COMPRESSED = 5 + * + * %AR_TKN_U32_MODULE_FMT_FREQ: bit rate + * + * %AR_TKN_U32_MODULE_FMT_BIT_DEPTH: bit depth + * + * %AR_TKN_U32_MODULE_SD_LINE_IDX: I2S serial data line idx + * I2S_SD0 = 1, + * I2S_SD1 = 2, + * I2S_SD2 = 3, + * I2S_SD3 = 4, + * I2S_QUAD01 = 5, + * I2S_QUAD23 = 6, + * I2S_6CHS = 7, + * I2S_8CHS = 8 + * + * %AR_TKN_U32_MODULE_WS_SRC: Word Select Source + * AR_I2S_WS_SRC_EXTERNAL = 0, + * AR_I2S_WS_SRC_INTERNAL = 1, + * + * %AR_TKN_U32_MODULE_FRAME_SZ_FACTOR: Frame size factor + * + * %AR_TKN_U32_MODULE_LOG_CODE: Log Module Code + * + * %AR_TKN_U32_MODULE_LOG_TAP_POINT_ID: logging tap point of this module + * + * %AR_TKN_U32_MODULE_LOG_MODE: logging mode + * LOG_WAIT = 0, + * LOG_IMMEDIATELY = 1 + * + * %AR_TKN_DAI_INDEX: dai index + * + */ + +/* DAI Tokens */ +#define AR_TKN_DAI_INDEX 1 +/* SUB GRAPH Tokens */ +#define AR_TKN_U32_SUB_GRAPH_INSTANCE_ID 2 +#define AR_TKN_U32_SUB_GRAPH_PERF_MODE 3 +#define AR_TKN_U32_SUB_GRAPH_DIRECTION 4 +#define AR_TKN_U32_SUB_GRAPH_SCENARIO_ID 5 + +/* Container Tokens */ +#define AR_TKN_U32_CONAINER_INSTANCE_ID 100 +#define AR_TKN_U32_CONAINER_CAPABILITY_ID 101 +#define AR_TKN_U32_CONAINER_STACK_SIZE 102 +#define AR_TKN_U32_CONAINER_GRAPH_POS 103 +#define AR_TKN_U32_CONAINER_PROC_DOMAIN 104 + +/* Module Tokens */ +#define AR_TKN_U32_MODULE_ID 200 +#define AR_TKN_U32_MODULE_INSTANCE_ID 201 +#define AR_TKN_U32_MODULE_MAX_IP_PORTS 202 +#define AR_TKN_U32_MODULE_MAX_OP_PORTS 203 +#define AR_TKN_U32_MODULE_IN_PORTS 204 +#define AR_TKN_U32_MODULE_OUT_PORTS 205 +#define AR_TKN_U32_MODULE_SRC_OP_PORT_ID 206 +#define AR_TKN_U32_MODULE_DST_IN_PORT_ID 207 + +#define AR_TKN_U32_MODULE_HW_IF_IDX 250 +#define AR_TKN_U32_MODULE_HW_IF_TYPE 251 +#define AR_TKN_U32_MODULE_FMT_INTERLEAVE 252 +#define AR_TKN_U32_MODULE_FMT_DATA 253 +#define AR_TKN_U32_MODULE_FMT_FREQ 254 +#define AR_TKN_U32_MODULE_FMT_BIT_DEPTH 255 +#define AR_TKN_U32_MODULE_SD_LINE_IDX 256 +#define AR_TKN_U32_MODULE_WS_SRC 257 +#define AR_TKN_U32_MODULE_FRAME_SZ_FACTOR 258 +#define AR_TKN_U32_MODULE_LOG_CODE 259 +#define AR_TKN_U32_MODULE_LOG_TAP_POINT_ID 260 +#define AR_TKN_U32_MODULE_LOG_MODE 261 + +#endif /* __SND_AR_TOKENS_H__ */ diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 721ea56b2cb5..af555e390c0a 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -106,6 +106,7 @@ config SND_SOC_QDSP6 config SND_SOC_QCOM_AUDIOREACH tristate "SoC ALSA audio drives for Qualcomm AUDIOREACH" depends on QCOM_GPR + select SND_SOC_TOPOLOGY help Support for AudioReach in QDSP diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile index d76afc51556b..65ea488e4cc8 100644 --- a/sound/soc/qcom/audioreach/Makefile +++ b/sound/soc/qcom/audioreach/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -snd-ar-objs := audioreach.o q6apm.o +snd-ar-objs := audioreach.o q6apm.o topology.o obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o diff --git a/sound/soc/qcom/audioreach/q6apm.c b/sound/soc/qcom/audioreach/q6apm.c index c18a688c9d1f..53359faa1d8b 100644 --- a/sound/soc/qcom/audioreach/q6apm.c +++ b/sound/soc/qcom/audioreach/q6apm.c @@ -816,11 +816,13 @@ int q6apm_graph_flush(struct q6apm_graph *graph) static int q6apm_audio_probe(struct snd_soc_component *component) { - return 0; + return audioreach_tplg_init(component); } static void q6apm_audio_remove(struct snd_soc_component *component) { + /* remove topology */ + snd_soc_tplg_component_remove(component); } #define APM_AUDIO_DRV_NAME "q6apm-audio" diff --git a/sound/soc/qcom/audioreach/topology.c b/sound/soc/qcom/audioreach/topology.c new file mode 100644 index 000000000000..8080243a47ef --- /dev/null +++ b/sound/soc/qcom/audioreach/topology.c @@ -0,0 +1,1015 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6apm.h" +#include "audioreach.h" + +struct snd_ar_control { + u32 sgid; /* Sub Graph ID */ + struct snd_soc_component *scomp; +}; + +static struct audioreach_graph_info *audioreach_tplg_alloc_graph_info( + struct q6apm *apm, uint32_t graph_id, + bool *found) +{ + struct audioreach_graph_info *info; + int ret; + + spin_lock(&apm->lock); + info = idr_find(&apm->graph_info_idr, graph_id); + spin_unlock(&apm->lock); + + if (info) { + *found = true; + return info; + } + + *found = false; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); + + + INIT_LIST_HEAD(&info->sg_list); + spin_lock_init(&info->sg_list_lock); + + spin_lock(&apm->lock); + ret = idr_alloc(&apm->graph_info_idr, info, graph_id, + graph_id + 1, GFP_ATOMIC); + spin_unlock(&apm->lock); + + if (ret < 0) { + dev_err(apm->dev, "Failed to allocate Graph ID (%x)\n", graph_id); + return ERR_PTR(ret); + } + + info->id = ret; + + return info; +} + +static void audioreach_tplg_add_sub_graph(struct audioreach_sub_graph *sg, + struct audioreach_graph_info *info) +{ + list_add_tail(&sg->node, &info->sg_list); + sg->info = info; + info->num_sub_graphs++; +} + + +static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph( + struct q6apm *apm, + uint32_t sub_graph_id, + bool *found) +{ + struct audioreach_sub_graph *sg = NULL; + int ret; + + if (!sub_graph_id) + return ERR_PTR(-EINVAL); + + /* Find if there is already a matching sub-graph */ + spin_lock(&apm->lock); + sg = idr_find(&apm->sub_graphs_idr, sub_graph_id); + spin_unlock(&apm->lock); + + + if (sg) { + *found = true; + return sg; + } + + *found = false; + sg = kzalloc(sizeof(*sg), GFP_KERNEL); + if (!sg) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&sg->container_list); + + spin_lock(&apm->lock); + ret = idr_alloc(&apm->sub_graphs_idr, sg, sub_graph_id, + sub_graph_id + 1, GFP_ATOMIC); + spin_unlock(&apm->lock); + + if (ret < 0) { + dev_err(apm->dev, + "Failed to allocate Sub-Graph Instance ID (%x)\n", + sub_graph_id); + return ERR_PTR(ret); + } + + sg->sub_graph_id = ret; + + return sg; +} + +static struct audioreach_container *audioreach_tplg_alloc_container(struct q6apm *apm, + struct audioreach_sub_graph *sg, + uint32_t container_id, + bool *found) +{ + struct audioreach_container *cont = NULL; + int ret; + + if (!container_id) + return ERR_PTR(-EINVAL); + + spin_lock(&apm->lock); + cont = idr_find(&apm->containers_idr, container_id); + spin_unlock(&apm->lock); + + if (cont) { + *found = true; + return cont; + } + *found = false; + + cont = kzalloc(sizeof(*cont), GFP_KERNEL); + if (!cont) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&cont->modules_list); + + spin_lock(&apm->lock); + ret = idr_alloc(&apm->containers_idr, cont, container_id, + container_id + 1, GFP_ATOMIC); + spin_unlock(&apm->lock); + + if (ret < 0) { + dev_err(apm->dev, + "Failed to allocate Container Instance ID (%x)\n", + container_id); + return ERR_PTR(ret); + } + + cont->container_id = ret; + cont->sub_graph = sg; + /* add to container list */ + list_add_tail(&cont->node, &sg->container_list); + sg->num_containers++; + + return cont; +} + +static struct audioreach_module *audioreach_tplg_alloc_module(struct q6apm *apm, + struct audioreach_container *cont, + struct snd_soc_dapm_widget *w, + uint32_t module_id, + bool *found) +{ + struct audioreach_module *mod = NULL; + int ret; + + spin_lock(&apm->lock); + mod = idr_find(&apm->modules_idr, module_id); + spin_unlock(&apm->lock); + + if (mod) { + *found = true; + return mod; + } + *found = false; + mod = kzalloc(sizeof(*mod), GFP_KERNEL); + if (!mod) + return ERR_PTR(-ENOMEM); + + spin_lock(&apm->lock); + if (!module_id) { /* alloc module id dynamically */ + ret = idr_alloc_cyclic(&apm->modules_idr, mod, + AR_MODULE_DYNAMIC_INSTANCE_ID_START, + AR_MODULE_DYNAMIC_INSTANCE_ID_END, + GFP_ATOMIC); + } else { + ret = idr_alloc(&apm->modules_idr, mod, module_id, + module_id + 1, GFP_ATOMIC); + } + spin_unlock(&apm->lock); + + if (ret < 0) { + dev_err(apm->dev, + "Failed to allocate Module Instance ID (%x)\n", module_id); + return ERR_PTR(ret); + } + + mod->instance_id = ret; + dev_err(apm->dev, "Module Instance ID (0x%08x) allocated\n", ret); + /* add to module list */ + list_add_tail(&mod->node, &cont->modules_list); + mod->container = cont; + mod->widget = w; + cont->num_modules++; + + return mod; +} + +static struct snd_soc_tplg_vendor_array *audioreach_get_sg_array( + struct snd_soc_tplg_private *private) +{ + struct snd_soc_tplg_vendor_array *sg_array; + struct snd_soc_tplg_vendor_value_elem *sg_elem; + int tkn_count = 0; + bool found = false; + int sz = 0; + + for (sz = 0; !found && (sz < le32_to_cpu(private->size)); ) { + sg_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz); + sg_elem = sg_array->value; + sz = sz + le32_to_cpu(sg_array->size); + tkn_count = 0; + while (!found && tkn_count <= (le32_to_cpu(sg_array->num_elems) - 1)) { + switch (le32_to_cpu(sg_elem->token)) { + case AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: + found = true; + break; + default: + break; + } + tkn_count++; + sg_elem++; + } + } + + if (found) + return sg_array; + + return NULL; +} + +static struct snd_soc_tplg_vendor_array *audioreach_get_cont_array( + struct snd_soc_tplg_private *private) +{ + struct snd_soc_tplg_vendor_array *cont_array; + struct snd_soc_tplg_vendor_value_elem *cont_elem; + int tkn_count = 0; + bool found = false; + int sz = 0; + + for (sz = 0; !found && (sz < le32_to_cpu(private->size)); ) { + cont_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz); + cont_elem = cont_array->value; + sz = sz + le32_to_cpu(cont_array->size); + tkn_count = 0; + while (!found && tkn_count <= (le32_to_cpu(cont_array->num_elems) - 1)) { + switch (le32_to_cpu(cont_elem->token)) { + case AR_TKN_U32_CONAINER_INSTANCE_ID: + found = true; + break; + default: + break; + } + tkn_count++; + cont_elem++; + } + } + + if (found) + return cont_array; + + return NULL; +} + +static struct snd_soc_tplg_vendor_array *audioreach_get_module_array( + struct snd_soc_tplg_private *private) +{ + struct snd_soc_tplg_vendor_array *mod_array = private->array; + struct snd_soc_tplg_vendor_value_elem *mod_elem = mod_array->value; + int tkn_count = 0; + bool found = false; + int sz = 0; + + for (sz = 0; !found && (sz < le32_to_cpu(private->size)); ) { + mod_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz); + mod_elem = mod_array->value; + sz = sz + le32_to_cpu(mod_array->size); + tkn_count = 0; + while (!found && tkn_count <= (le32_to_cpu(mod_array->num_elems) - 1)) { + switch (le32_to_cpu(mod_elem->token)) { + case AR_TKN_U32_MODULE_INSTANCE_ID: + found = true; + break; + default: + break; + } + tkn_count++; + mod_elem++; + } + } + + if (found) + return mod_array; + + return NULL; +} + +static struct audioreach_sub_graph *audioreach_parse_sg_tokens(struct q6apm *apm, + struct snd_soc_tplg_private *private) +{ + struct audioreach_graph_info *info = NULL; + struct snd_soc_tplg_vendor_array *sg_array; + struct snd_soc_tplg_vendor_value_elem *sg_elem; + struct audioreach_sub_graph *sg; + int graph_id, sub_graph_id, tkn_count = 0; + bool found; + + sg_array = audioreach_get_sg_array(private); + sg_elem = sg_array->value; + + while (tkn_count <= (le32_to_cpu(sg_array->num_elems) - 1)) { + switch (le32_to_cpu(sg_elem->token)) { + case AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: + sub_graph_id = le32_to_cpu(sg_elem->value); + sg = audioreach_tplg_alloc_sub_graph(apm, sub_graph_id, &found); + if (IS_ERR(sg)) { + return sg; + } else if (found) { + /* Already parsed data for this sub-graph */ + return sg; + } + dev_err(apm->dev, "%s: New subgraph id : 0x%08x\n", __func__, + sub_graph_id); + break; + case AR_TKN_DAI_INDEX: + /* Sub graph is associated with predefined graph */ + graph_id = le32_to_cpu(sg_elem->value); + info = audioreach_tplg_alloc_graph_info(apm, graph_id, &found); + if (IS_ERR(info)) + return ERR_CAST(info); + break; + case AR_TKN_U32_SUB_GRAPH_PERF_MODE: + sg->perf_mode = le32_to_cpu(sg_elem->value); + break; + case AR_TKN_U32_SUB_GRAPH_DIRECTION: + sg->direction = le32_to_cpu(sg_elem->value); + break; + case AR_TKN_U32_SUB_GRAPH_SCENARIO_ID: + sg->scenario_id = le32_to_cpu(sg_elem->value); + break; + default: + dev_err(apm->dev, "Not a valid token %d for graph\n", + sg_elem->token); + break; + + } + tkn_count++; + sg_elem++; + } + + /* Sub graph is associated with predefined graph */ + if (info) { + dev_err(apm->dev, "%s: adding subgraph id : 0x%08x -> %d\n", __func__, + sub_graph_id, graph_id); + + audioreach_tplg_add_sub_graph(sg, info); + } + + return sg; +} + +static struct audioreach_container *audioreach_parse_cont_tokens(struct q6apm *apm, + struct audioreach_sub_graph *sg, + struct snd_soc_tplg_private *private) +{ + struct snd_soc_tplg_vendor_array *cont_array; + struct snd_soc_tplg_vendor_value_elem *cont_elem; + struct audioreach_container *cont; + int container_id, tkn_count = 0; + bool found = false; + + cont_array = audioreach_get_cont_array(private); + cont_elem = cont_array->value; + + while (tkn_count <= (le32_to_cpu(cont_array->num_elems) - 1)) { + switch (le32_to_cpu(cont_elem->token)) { + case AR_TKN_U32_CONAINER_INSTANCE_ID: + container_id = le32_to_cpu(cont_elem->value); + cont = audioreach_tplg_alloc_container(apm, sg, container_id, &found); + if (IS_ERR(cont)) + return ERR_PTR(-ENOMEM); + else if (found) /* Already parsed container data */ + return cont; + + break; + case AR_TKN_U32_CONAINER_CAPABILITY_ID: + cont->capability_id = le32_to_cpu(cont_elem->value); + break; + case AR_TKN_U32_CONAINER_STACK_SIZE: + cont->stack_size = le32_to_cpu(cont_elem->value); + break; + case AR_TKN_U32_CONAINER_GRAPH_POS: + cont->graph_pos = le32_to_cpu(cont_elem->value); + break; + case AR_TKN_U32_CONAINER_PROC_DOMAIN: + cont->proc_domain = le32_to_cpu(cont_elem->value); + break; + default: + dev_err(apm->dev, "Not a valid token %d for graph\n", + cont_elem->token); + break; + + } + tkn_count++; + cont_elem++; + } + + return cont; +} + +static struct audioreach_module *audioreach_parse_common_tokens(struct q6apm *apm, + struct audioreach_container *cont, + struct snd_soc_tplg_private *private, + struct snd_soc_dapm_widget *w) +{ + struct snd_soc_tplg_vendor_array *mod_array; + struct snd_soc_tplg_vendor_value_elem *mod_elem; + uint32_t max_ip_port, max_op_port, in_port, out_port; + uint32_t src_mod_inst_id, src_mod_op_port_id; + uint32_t dst_mod_inst_id, dst_mod_ip_port_id; + int module_id, instance_id, tkn_count = 0; + struct audioreach_module *mod = NULL; + bool found; + + mod_array = audioreach_get_module_array(private); + mod_elem = mod_array->value; + + while (tkn_count <= (le32_to_cpu(mod_array->num_elems) - 1)) { + switch (le32_to_cpu(mod_elem->token)) { + /* common module info */ + case AR_TKN_U32_MODULE_ID: + module_id = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_INSTANCE_ID: + instance_id = le32_to_cpu(mod_elem->value); + mod = audioreach_tplg_alloc_module(apm, cont, w, + instance_id, &found); + if (IS_ERR(mod)) { + return ERR_PTR(-ENOMEM); + } else if (found) { + dev_err(apm->dev, "Duplicate Module Instance ID 0x%08x found\n", + instance_id); + return ERR_PTR(-EINVAL); + } + + break; + case AR_TKN_U32_MODULE_MAX_IP_PORTS: + max_ip_port = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_MAX_OP_PORTS: + max_op_port = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_IN_PORTS: + in_port = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_OUT_PORTS: + out_port = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_SRC_OP_PORT_ID: + src_mod_op_port_id = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_DST_IN_PORT_ID: + dst_mod_ip_port_id = le32_to_cpu(mod_elem->value); + + default: + break; + + } + tkn_count++; + mod_elem++; + } + + if (mod) { + mod->module_id = module_id; + mod->max_ip_port = max_ip_port; + mod->max_op_port = max_op_port; + mod->in_port = in_port; + mod->out_port = out_port; + mod->src_mod_inst_id = src_mod_inst_id; + mod->src_mod_op_port_id = src_mod_op_port_id; + mod->dst_mod_inst_id = dst_mod_inst_id; + mod->dst_mod_ip_port_id = dst_mod_ip_port_id; + } + + return mod; +} + +static int audioreach_widget_load_module_common(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + struct q6apm *apm = dev_get_drvdata(component->dev); + struct audioreach_sub_graph *sg; + struct audioreach_container *cont; + struct audioreach_module *mod; + struct snd_soc_dobj *dobj; + + sg = audioreach_parse_sg_tokens(apm, &tplg_w->priv); + if (IS_ERR(sg)) + return PTR_ERR(sg); + + cont = audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv); + if (IS_ERR(cont)) + return PTR_ERR(cont); + + mod = audioreach_parse_common_tokens(apm, cont, &tplg_w->priv, w); + if (IS_ERR(mod)) + return PTR_ERR(mod); + + dobj = &w->dobj; + dobj->private = mod; + + return 0; +} + +static int audioreach_widget_load_pcm(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + return audioreach_widget_load_module_common(component, index, w, + tplg_w); +} + +static int audioreach_widget_load_enc_dec_cnv(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + struct snd_soc_tplg_vendor_array *mod_array; + struct snd_soc_tplg_vendor_value_elem *mod_elem; + struct audioreach_module *mod; + struct snd_soc_dobj *dobj; + int tkn_count = 0; + int ret; + + ret = audioreach_widget_load_module_common(component, index, w, tplg_w); + if (ret) + return ret; + + dobj = &w->dobj; + mod = dobj->private; + mod_array = audioreach_get_module_array(&tplg_w->priv); + mod_elem = mod_array->value; + + while (tkn_count <= (le32_to_cpu(mod_array->num_elems) - 1)) { + switch (le32_to_cpu(mod_elem->token)) { + case AR_TKN_U32_MODULE_FMT_INTERLEAVE: + mod->interleave_type = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_FMT_FREQ: + mod->rate = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_FMT_BIT_DEPTH: + mod->bit_depth = le32_to_cpu(mod_elem->value); + break; + default: + break; + } + tkn_count++; + mod_elem++; + } + + return 0; +} + +static int audioreach_widget_log_module_load(struct audioreach_module *mod, + struct snd_soc_tplg_vendor_array *mod_array) +{ + struct snd_soc_tplg_vendor_value_elem *mod_elem; + int tkn_count = 0; + + mod_elem = mod_array->value; + + while (tkn_count <= (le32_to_cpu(mod_array->num_elems) - 1)) { + switch (le32_to_cpu(mod_elem->token)) { + + case AR_TKN_U32_MODULE_LOG_CODE: + mod->log_code = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_LOG_TAP_POINT_ID: + mod->log_tap_point_id = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_LOG_MODE: + mod->mode = le32_to_cpu(mod_elem->value); + break; + default: + break; + } + tkn_count++; + mod_elem++; + } + + return 0; +} + +static int audioreach_widget_dma_module_load(struct audioreach_module *mod, + struct snd_soc_tplg_vendor_array *mod_array) +{ + struct snd_soc_tplg_vendor_value_elem *mod_elem; + int tkn_count = 0; + + mod_elem = mod_array->value; + + while (tkn_count <= (le32_to_cpu(mod_array->num_elems) - 1)) { + switch (le32_to_cpu(mod_elem->token)) { + case AR_TKN_U32_MODULE_HW_IF_IDX: + mod->hw_interface_idx = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_FMT_DATA: + mod->data_format = le32_to_cpu(mod_elem->value); + break; + case AR_TKN_U32_MODULE_HW_IF_TYPE: + mod->hw_interface_type = le32_to_cpu(mod_elem->value); + break; + default: + break; + } + tkn_count++; + mod_elem++; + } + + return 0; +} + +static int audioreach_widget_load_buffer(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + struct snd_soc_tplg_vendor_array *mod_array; + struct audioreach_module *mod; + struct snd_soc_dobj *dobj; + int ret; + + ret = audioreach_widget_load_module_common(component, index, w, tplg_w); + if (ret) + return ret; + + dobj = &w->dobj; + mod = dobj->private; + + mod_array = audioreach_get_module_array(&tplg_w->priv); + + switch (mod->module_id) { + case MODULE_ID_CODEC_DMA_SINK: + case MODULE_ID_CODEC_DMA_SOURCE: + audioreach_widget_dma_module_load(mod, mod_array); + break; + case MODULE_ID_DATA_LOGGING: + audioreach_widget_log_module_load(mod, mod_array); + break; + } + + return 0; +} + +static int audioreach_widget_load_mixer(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + struct snd_soc_tplg_vendor_value_elem *w_elem; + struct snd_soc_tplg_vendor_array *w_array; + struct snd_ar_control *scontrol; + struct snd_soc_dobj *dobj; + int tkn_count = 0; + + w_array = &tplg_w->priv.array[0]; + + scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL); + if (!scontrol) + return -ENOMEM; + + scontrol->scomp = component; + dobj = &w->dobj; + dobj->private = scontrol; + + w_elem = w_array->value; + while (tkn_count <= (le32_to_cpu(w_array->num_elems) - 1)) { + switch (le32_to_cpu(w_elem->token)) { + case AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: + scontrol->sgid = le32_to_cpu(w_elem->value); + break; + default: /* ignore other tokens */ + break; + } + tkn_count++; + w_elem++; + } + + return 0; +} + +static int audioreach_widget_ready(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + switch (w->id) { + case snd_soc_dapm_aif_in: + case snd_soc_dapm_aif_out: + audioreach_widget_load_buffer(component, index, w, tplg_w); + break; + case snd_soc_dapm_decoder: + case snd_soc_dapm_encoder: + case snd_soc_dapm_src: + audioreach_widget_load_enc_dec_cnv(component, index, w, tplg_w); + break; + case snd_soc_dapm_buffer: + audioreach_widget_load_buffer(component, index, w, tplg_w); + break; + case snd_soc_dapm_mixer: + return audioreach_widget_load_mixer(component, index, w, tplg_w); + case snd_soc_dapm_dai_link: + case snd_soc_dapm_pga: + case snd_soc_dapm_scheduler: + case snd_soc_dapm_out_drv: + default: + dev_err(component->dev, "Widget type (0x%x) not yet supported\n", + w->id); + break; + } + + return 0; +} + + +static int audioreach_widget_unload(struct snd_soc_component *scomp, + struct snd_soc_dobj *dobj) +{ + struct q6apm *apm = dev_get_drvdata(scomp->dev); + struct audioreach_container *cont; + struct audioreach_module *mod; + struct snd_ar_control *scontrol = dobj->private; + struct snd_soc_dapm_widget *w = + container_of(dobj, struct snd_soc_dapm_widget, dobj); + + mod = dobj->private; + cont = mod->container; + + if (w->id == snd_soc_dapm_mixer) { + /* virtual widget */ + kfree(dobj->private); + return 0; + } + + spin_lock(&apm->lock); + idr_remove(&apm->modules_idr, mod->instance_id); + cont->num_modules--; + + /* delete list */ + list_del(&mod->node); + /* free memory */ + kfree(mod); + + if (list_empty(&cont->modules_list)) { /* remove container */ + struct audioreach_sub_graph *sg = cont->sub_graph; + + idr_remove(&apm->containers_idr, cont->container_id); + list_del(&cont->node); + sg->num_containers--; + kfree(cont); + if (list_empty(&sg->container_list)) { /* remove sg */ + struct audioreach_graph_info *info = sg->info; + + idr_remove(&apm->sub_graphs_idr, sg->sub_graph_id); + list_del(&sg->node); + info->num_sub_graphs--; + kfree(sg); + if (list_empty(&info->sg_list)) { /* remove graph info */ + idr_remove(&apm->graph_info_idr, info->id); + kfree(info); + } + } + } + + spin_unlock(&apm->lock); + + return 0; +} + +static struct audioreach_module *audioreach_find_widget(struct snd_soc_component *comp, + const char *name) +{ + struct q6apm *apm = dev_get_drvdata(comp->dev); + struct audioreach_module *module; + int id; + + idr_for_each_entry(&apm->modules_idr, module, id) { + if (!strcmp(name, module->widget->name)) + return module; + } + + return NULL; +} + +static int audioreach_route_load(struct snd_soc_component *scomp, int index, + struct snd_soc_dapm_route *route) +{ + struct audioreach_module *src, *sink; + + src = audioreach_find_widget(scomp, route->source); + sink = audioreach_find_widget(scomp, route->sink); + + if (src && sink) { + src->dst_mod_inst_id = sink->instance_id; + sink->src_mod_inst_id = src->instance_id; + } + + return 0; +} + +static int audioreach_route_unload(struct snd_soc_component *scomp, + struct snd_soc_dobj *dobj) +{ + + return 0; +} + +static void audioreach_tplg_complete(struct snd_soc_component *component) +{ + /* TBD */ +} + +/* DAI link - used for any driver specific init */ +static int audioreach_link_load(struct snd_soc_component *component, int index, + struct snd_soc_dai_link *link, + struct snd_soc_tplg_link_config *cfg) +{ + link->nonatomic = true; + link->dynamic = true; + link->platforms->name = NULL; + link->platforms->of_node = of_get_compatible_child(component->dev->of_node, + "qcom,q6apm-dais"); + link->trigger[0] = SND_SOC_DPCM_TRIGGER_POST; + link->trigger[1] = SND_SOC_DPCM_TRIGGER_POST; + + return 0; +} + +static int audioreach_get_audio_mixer(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_widget *dw = snd_soc_dapm_kcontrol_widget(kcontrol); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_component *c = snd_soc_dapm_to_component(dapm); + struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; + struct snd_ar_control *scontrol = mc->dobj.private; + struct snd_ar_control *dapm_scontrol = dw->dobj.private; + struct q6apm *data = dev_get_drvdata(c->dev); + bool connected; + + connected = q6apm_is_sub_graphs_connected(data, scontrol->sgid, + dapm_scontrol->sgid); + if (connected) + ucontrol->value.integer.value[0] = 1; + else + ucontrol->value.integer.value[0] = 0; + + return 0; +} + +static int audioreach_put_audio_mixer(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_widget *dw = snd_soc_dapm_kcontrol_widget(kcontrol); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_component *c = snd_soc_dapm_to_component(dapm); + struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; + struct snd_ar_control *scontrol = mc->dobj.private; + struct snd_ar_control *dapm_scontrol = dw->dobj.private; + struct q6apm *data = dev_get_drvdata(c->dev); + struct snd_soc_dapm_update *update = NULL; + + if (ucontrol->value.integer.value[0]) { + q6apm_connect_sub_graphs(data, scontrol->sgid, + dapm_scontrol->sgid, true); + snd_soc_dapm_mixer_update_power(dapm, kcontrol, 1, update); + } else { + q6apm_connect_sub_graphs(data, scontrol->sgid, + dapm_scontrol->sgid, false); + snd_soc_dapm_mixer_update_power(dapm, kcontrol, 0, update); + } + return 0; +} + +static int audioreach_control_load_mix(struct snd_soc_component *scomp, + struct snd_ar_control *scontrol, + struct snd_kcontrol_new *kc, + struct snd_soc_tplg_ctl_hdr *hdr) +{ + struct snd_soc_tplg_mixer_control *mc = container_of(hdr, struct snd_soc_tplg_mixer_control, hdr); + struct snd_soc_tplg_vendor_array *c_array = (struct snd_soc_tplg_vendor_array *)mc->priv.data; + int tkn_count = 0; + struct snd_soc_tplg_vendor_value_elem *c_elem; + + c_elem = c_array->value; + + while (tkn_count <= (le32_to_cpu(c_array->num_elems) - 1)) { + switch (le32_to_cpu(c_elem->token)) { + case AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: + scontrol->sgid = le32_to_cpu(c_elem->value); + break; + default: + /* Ignore other tokens */ + break; + + } + c_elem++; + tkn_count++; + } + + return 0; +} + +static int audioreach_control_load(struct snd_soc_component *scomp, int index, + struct snd_kcontrol_new *kc, + struct snd_soc_tplg_ctl_hdr *hdr) +{ + struct snd_ar_control *scontrol; + struct snd_soc_dobj *dobj; + struct soc_mixer_control *sm; + int ret; + + scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL); + if (!scontrol) + return -ENOMEM; + + scontrol->scomp = scomp; + + switch (le32_to_cpu(hdr->ops.get)) { + case SND_SOC_AR_TPLG_FE_BE_GRAPH_CTL_MIX: + sm = (struct soc_mixer_control *)kc->private_value; + dobj = &sm->dobj; + ret = audioreach_control_load_mix(scomp, scontrol, kc, hdr); + break; + default: + dev_warn(scomp->dev, "control type not supported %d:%d:%d\n", + hdr->ops.get, hdr->ops.put, hdr->ops.info); + kfree(scontrol); + break; + } + + dobj->private = scontrol; + return ret; +} + +static int audioreach_control_unload(struct snd_soc_component *scomp, + struct snd_soc_dobj *dobj) +{ + struct snd_ar_control *scontrol = dobj->private; + + kfree(scontrol); + + return 0; +} + +static const struct snd_soc_tplg_kcontrol_ops audioreach_io_ops[] = { + {SND_SOC_AR_TPLG_FE_BE_GRAPH_CTL_MIX, audioreach_get_audio_mixer, + audioreach_put_audio_mixer, snd_soc_info_volsw}, +}; + +static struct snd_soc_tplg_ops audioreach_tplg_ops = { + .io_ops = audioreach_io_ops, + .io_ops_count = ARRAY_SIZE(audioreach_io_ops), + + .control_load = audioreach_control_load, + .control_unload = audioreach_control_unload, + + .widget_ready = audioreach_widget_ready, + .widget_unload = audioreach_widget_unload, + + .complete = audioreach_tplg_complete, + .link_load = audioreach_link_load, + + .dapm_route_load = audioreach_route_load, + .dapm_route_unload = audioreach_route_unload, +}; + +int audioreach_tplg_init(struct snd_soc_component *component) +{ + struct device *dev = component->dev; + const struct firmware *fw; + int ret; + + ret = request_firmware(&fw, "audioreach.bin", dev); + if (ret < 0) { + dev_err(dev, "tplg fw audioreach.bin load failed with %d\n", ret); + return ret; + } + + ret = snd_soc_tplg_component_load(component, &audioreach_tplg_ops, fw); + if (ret < 0) { + dev_err(dev, "tplg component load failed%d\n", ret); + release_firmware(fw); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(audioreach_tplg_init); From patchwork Wed Jul 14 15:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476807 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676664jao; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxid+AnEL2kiEvoucBHJFhR40ancUNNOgzIG3TDhCczqRgZzV+9+RIcmaGoyqMIaoGig6j7 X-Received: by 2002:a05:6638:100b:: with SMTP id r11mr9440285jab.85.1626276682459; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276682; cv=none; d=google.com; s=arc-20160816; b=QjuENToNlvLBN3VUW1ZPSbBtO/mbLPKazKUt54i9a9yfLevIoeHfob7bym7ARymkzV UfjBMANlR9TuNJnWGcsarE82OjHrvIECjKXKn6CtT/8JEkKF84KM3Geu++IN4ahGAAeb ipUDYBzKd6H3Fz9hHV5cbNYGOvj8CtSoOYAt59QErRpBbzqz+mQwf+v1p0srczlrM6N0 4srFf8IZa3/dxs/S7ekNuIdUsMzEcygr7qfAkBZPd7YLRDhiTuq2Xuo0mnfokYkeOmmM GdO2Ene9yd4p908xjfHAGwkcjtQr5Vpbbl0v6fCkSO0rQp9xuWLPHUTuvOjFdjwVzsbV AlGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GijL4OLNpAtKURZK4jz9kqTgMFdCe7RUsV03bNxrXYk=; b=UdXqujyE5574XxGGYcMm5E6RBBjaq8zK+Nidv2QwZ9CD+33VmyRnhbUop+rpO8/l5B msr/ak4UETCmhb8PHC4R3ZeOaHg10+vKD2xUInbtgbgxNVS5q4GFTb+4bDyZzwVgZ8pz Opyg8BgLs9CMePvp+ogbLRY7ZKpXv5xBaHWm/1BBPT7uHOjtUbX5FHHWARD7E/aKRD3C uNJA9pYM6R1pyECL89OhDLE6Fs/eooXXedtqqSJCNIZ9tAYcE89ozGpi1dBjM6sQwVS7 EFiAsskd7QPPOBG9ckHhsMFa0YSpWvmai6F+U7ok9+g7O7kMy9xAvzRCjAN6AnYwbvFP /9ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i9EXmyHj; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.22; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i9EXmyHj; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239849AbhGNPeK (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239806AbhGNPeG (ORCPT ); Wed, 14 Jul 2021 11:34:06 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A31AC061767 for ; Wed, 14 Jul 2021 08:31:12 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso4163899wmh.4 for ; Wed, 14 Jul 2021 08:31:12 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=GijL4OLNpAtKURZK4jz9kqTgMFdCe7RUsV03bNxrXYk=; b=i9EXmyHjVUSoczIqnJEF8NO7rW1YG2fpZeQisb9Z1OVmHbUz9mMZ1vRR+MUxeCZDCH ArWsubhI87GEHqx44bLrPnHqHEWFnJOSF4j35gitA6vX4uN/77vQTZMweSgILAXgvF+5 mCWtI8CyhsFVy+V1FKrhaS4tcVLulX1kYXWDBoX2I8kwAWWMhE6T66Xp5A8f4feAoDuS F3CVta2353n4Ffy+2Fu8OwB31s1u7HMMV/PONwibXCSGKM3U1Lp4qSxJT9g0O3UyLZnn jLVMQ+KSesP0ipuNNlP4iyu2VCOQBxJzwqYTyjw/Kn4iLpsTL7vKgPvwbCP6KTQ4kmJG wyEw== 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:mime-version:content-transfer-encoding; bh=GijL4OLNpAtKURZK4jz9kqTgMFdCe7RUsV03bNxrXYk=; b=ScforQhAnxk5P0eyLiFQ9Lj/V+sKsMaBhO8QTAGqowFTRI2YAhv4ww7Cuq6hyJOSek e8xxqSp+1kBllIljqf/XkshcImPBXkDmaqAb8ygVb9mSSQvV+CNKUXGj+3eLAzkZ/M1f hQKVEepjwWwPA2ZNM/NMbP1hYyhKyKblXhrDrq54mOuUIudHaHuGZ+mdTs6mnR0OQIn1 t1JIoa3/o314RgyOXClp7JzcglcA9RVnCu/HTJZIxgOCB2Afh7VvkJj2ppFEDZtPYMxH fhcqbiM1KhVxNRl8lhXbc9y8ml0znWT13wEz1q7ijQagjerakGvjnc7t+xsTm2RN+0Kj JB6g== X-Gm-Message-State: AOAM533TtNGYJIubekAQCS2n++hCYHNDurTP2RgzeVZOJ3TWo42thNtx 4hRWeAv3aUaW/0FQ4sTguqg/Hg== X-Received: by 2002:a05:600c:154b:: with SMTP id f11mr4960382wmg.82.1626276670577; Wed, 14 Jul 2021 08:31:10 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:09 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 09/16] ASoC: qcom: audioreach: add q6apm-dai support Date: Wed, 14 Jul 2021 16:30:32 +0100 Message-Id: <20210714153039.28373-10-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/audioreach/Makefile | 2 + sound/soc/qcom/audioreach/q6apm-dai.c | 494 ++++++++++++++++++++++++++ 3 files changed, 500 insertions(+) create mode 100644 sound/soc/qcom/audioreach/q6apm-dai.c -- 2.21.0 diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index af555e390c0a..4efbf41539c5 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -103,10 +103,14 @@ config SND_SOC_QDSP6 audio drivers. This includes q6asm, q6adm, q6afe interfaces to DSP using apr. +config SND_SOC_QCOM_APM_DAI + tristate + config SND_SOC_QCOM_AUDIOREACH tristate "SoC ALSA audio drives for Qualcomm AUDIOREACH" depends on QCOM_GPR select SND_SOC_TOPOLOGY + select SND_SOC_QCOM_APM_DAI help Support for AudioReach in QDSP diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile index 65ea488e4cc8..7160bddbb1fb 100644 --- a/sound/soc/qcom/audioreach/Makefile +++ b/sound/soc/qcom/audioreach/Makefile @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only snd-ar-objs := audioreach.o q6apm.o topology.o +snd-apm-dai-objs := q6apm-dai.o obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o +obj-$(CONFIG_SND_SOC_QCOM_APM_DAI) += snd-apm-dai.o diff --git a/sound/soc/qcom/audioreach/q6apm-dai.c b/sound/soc/qcom/audioreach/q6apm-dai.c new file mode 100644 index 000000000000..13d8e40dd05a --- /dev/null +++ b/sound/soc/qcom/audioreach/q6apm-dai.c @@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2021, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6apm.h" + +#define DRV_NAME "q6apm-dai" + +#define PLAYBACK_MIN_NUM_PERIODS 2 +#define PLAYBACK_MAX_NUM_PERIODS 8 +#define PLAYBACK_MAX_PERIOD_SIZE 65536 +#define PLAYBACK_MIN_PERIOD_SIZE 128 +#define CAPTURE_MIN_NUM_PERIODS 2 +#define CAPTURE_MAX_NUM_PERIODS 8 +#define CAPTURE_MAX_PERIOD_SIZE 4096 +#define CAPTURE_MIN_PERIOD_SIZE 320 +#define BUFFER_BYTES_MAX (PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE) +#define BUFFER_BYTES_MIN (PLAYBACK_MIN_NUM_PERIODS * PLAYBACK_MIN_PERIOD_SIZE) + +#define SID_MASK_DEFAULT 0xF + +enum stream_state { + Q6APM_STREAM_IDLE = 0, + Q6APM_STREAM_STOPPED, + Q6APM_STREAM_RUNNING, +}; + +struct q6apm_dai_rtd { + struct snd_pcm_substream *substream; + struct snd_compr_stream *cstream; + struct snd_compr_params codec_param; + struct snd_dma_buffer dma_buffer; + spinlock_t lock; + phys_addr_t phys; + unsigned int pcm_size; + unsigned int pcm_count; + unsigned int pcm_irq_pos; /* IRQ position */ + unsigned int periods; + unsigned int bytes_sent; + unsigned int bytes_received; + unsigned int copied_total; + uint16_t bits_per_sample; + uint16_t source; /* Encoding source bit mask */ + uint16_t session_id; + enum stream_state state; + struct q6apm_graph *graph; +}; + +struct q6apm_dai_data { + long long int sid; +}; + +static struct snd_pcm_hardware q6apm_dai_hardware_capture = { + .info = (SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), + .formats = (SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S24_LE), + .rates = SNDRV_PCM_RATE_8000_48000, + .rate_min = 8000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 4, + .buffer_bytes_max = CAPTURE_MAX_NUM_PERIODS * + CAPTURE_MAX_PERIOD_SIZE, + .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, + .period_bytes_max = CAPTURE_MAX_PERIOD_SIZE, + .periods_min = CAPTURE_MIN_NUM_PERIODS, + .periods_max = CAPTURE_MAX_NUM_PERIODS, + .fifo_size = 0, +}; + +static struct snd_pcm_hardware q6apm_dai_hardware_playback = { + .info = (SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), + .formats = (SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S24_LE), + .rates = SNDRV_PCM_RATE_8000_192000, + .rate_min = 8000, + .rate_max = 192000, + .channels_min = 2, + .channels_max = 8, + .buffer_bytes_max = (PLAYBACK_MAX_NUM_PERIODS * + PLAYBACK_MAX_PERIOD_SIZE), + .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, + .period_bytes_max = PLAYBACK_MAX_PERIOD_SIZE, + .periods_min = PLAYBACK_MIN_NUM_PERIODS, + .periods_max = PLAYBACK_MAX_NUM_PERIODS, + .fifo_size = 0, +}; + +static void event_handler(uint32_t opcode, uint32_t token, + uint32_t *payload, void *priv) +{ + struct q6apm_dai_rtd *prtd = priv; + struct snd_pcm_substream *substream = prtd->substream; + + switch (opcode) { + case APM_CLIENT_EVENT_CMD_EOS_DONE: + prtd->state = Q6APM_STREAM_STOPPED; + break; + case APM_CLIENT_EVENT_DATA_WRITE_DONE: { + prtd->pcm_irq_pos += prtd->pcm_count; + snd_pcm_period_elapsed(substream); + if (prtd->state == Q6APM_STREAM_RUNNING) { + q6apm_write_async(prtd->graph, + prtd->pcm_count, 0, 0, NO_TIMESTAMP); + } + + break; + } + case APM_CLIENT_EVENT_DATA_READ_DONE: + prtd->pcm_irq_pos += prtd->pcm_count; + snd_pcm_period_elapsed(substream); + if (prtd->state == Q6APM_STREAM_RUNNING) + q6apm_read(prtd->graph); + + break; + default: + break; + } +} + +static int q6apm_dai_prepare(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct q6apm_dai_rtd *prtd = runtime->private_data; + struct q6apm_dai_data *pdata; + int ret, i; + + pdata = snd_soc_component_get_drvdata(component); + if (!pdata) + return -EINVAL; + + if (!prtd || !prtd->graph) { + dev_err(component->dev, "%s: private data null or audio client freed\n", + __func__); + return -EINVAL; + } + + prtd->pcm_count = snd_pcm_lib_period_bytes(substream); + prtd->pcm_irq_pos = 0; + /* rate and channels are sent to audio driver */ + ret = q6apm_graph_media_format_shmem(prtd->graph, + substream->stream, + runtime->rate, + runtime->channels, + NULL, + prtd->bits_per_sample); + + if (ret < 0) { + dev_err(component->dev, "%s: q6apm_open_write failed\n", __func__); + return ret; + } + + ret = q6apm_graph_media_format_pcm(prtd->graph, + substream->stream, + runtime->rate, + runtime->channels, + NULL, + prtd->bits_per_sample); + if (ret < 0) + pr_info("%s: CMD Format block failed\n", __func__); + + ret = q6apm_map_memory_regions(prtd->graph, + substream->stream, + prtd->phys, + (prtd->pcm_size / prtd->periods), + prtd->periods); + + if (ret < 0) { + dev_err(component->dev, "Audio Start: Buffer Allocation failed rc = %d\n", + ret); + return -ENOMEM; + } + + ret = q6apm_graph_prepare(prtd->graph); + ret = q6apm_graph_start(prtd->graph); + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + /* Queue the buffers */ + for (i = 0; i < runtime->periods; i++) + q6apm_read(prtd->graph); + + } + prtd->state = Q6APM_STREAM_RUNNING; + + return 0; +} + +static int q6apm_dai_trigger(struct snd_soc_component *component, + struct snd_pcm_substream *substream, int cmd) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct q6apm_dai_rtd *prtd = runtime->private_data; + int ret = 0; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, NO_TIMESTAMP); + break; + case SNDRV_PCM_TRIGGER_STOP: + prtd->state = Q6APM_STREAM_STOPPED; + //ret = q6apm_cmd_nowait(prtd->graph, CMD_EOS); + break; + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + //ret = q6apm_cmd_nowait(prtd->graph, CMD_PAUSE); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static int q6apm_dai_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_prtd, 0); + struct q6apm_dai_rtd *prtd; + struct q6apm_dai_data *pdata; + struct device *dev = component->dev; + int ret; + int graph_id; + + graph_id = cpu_dai->driver->id; + + pdata = snd_soc_component_get_drvdata(component); + if (!pdata) { + dev_err(component->dev, "Drv data not found ..\n"); + return -EINVAL; + } + + prtd = kzalloc(sizeof(*prtd), GFP_KERNEL); + if (prtd == NULL) + return -ENOMEM; + + prtd->substream = substream; + + prtd->graph = q6apm_graph_open(dev, (q6apm_cb)event_handler, + prtd, graph_id); + if (IS_ERR(prtd->graph)) { + pr_info("%s: Could not allocate memory\n", __func__); + ret = PTR_ERR(prtd->graph); + kfree(prtd); + return ret; + } + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + runtime->hw = q6apm_dai_hardware_playback; + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) + runtime->hw = q6apm_dai_hardware_capture; + + /* Ensure that buffer size is a multiple of period size */ + ret = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (ret < 0) + dev_err(dev, "snd_pcm_hw_constraint_integer failed\n"); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + ret = snd_pcm_hw_constraint_minmax(runtime, + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, + BUFFER_BYTES_MIN, BUFFER_BYTES_MAX); + if (ret < 0) { + dev_err(dev, "constraint for buffer bytes min max ret = %d\n", + ret); + } + } + + ret = snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32); + if (ret < 0) { + dev_err(dev, "constraint for period bytes step ret = %d\n", + ret); + } + ret = snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32); + if (ret < 0) { + dev_err(dev, "constraint for buffer bytes step ret = %d\n", + ret); + } + + runtime->private_data = prtd; + runtime->dma_bytes = BUFFER_BYTES_MAX; + if (pdata->sid < 0) + prtd->phys = substream->dma_buffer.addr; + else + prtd->phys = substream->dma_buffer.addr | (pdata->sid << 32); + + snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); + + return 0; +} + +static int q6apm_dai_close(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct q6apm_dai_rtd *prtd = runtime->private_data; + + if (prtd && prtd->graph) { + q6apm_graph_stop(prtd->graph); + + q6apm_unmap_memory_regions(prtd->graph, + substream->stream); + q6apm_graph_close(prtd->graph); + prtd->graph = NULL; + kfree(prtd); + runtime->private_data = NULL; + } + + return 0; +} + +static snd_pcm_uframes_t q6apm_dai_pointer(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + + struct snd_pcm_runtime *runtime = substream->runtime; + struct q6apm_dai_rtd *prtd = runtime->private_data; + + if (prtd->pcm_irq_pos >= prtd->pcm_size) + prtd->pcm_irq_pos = 0; + + return bytes_to_frames(runtime, (prtd->pcm_irq_pos)); +} + +static int q6apm_dai_mmap(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + struct vm_area_struct *vma) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct device *dev = component->dev; + + return dma_mmap_coherent(dev, vma, + runtime->dma_area, runtime->dma_addr, + runtime->dma_bytes); +} + +static int q6apm_dai_hw_params(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct q6apm_dai_rtd *prtd = runtime->private_data; + + prtd->pcm_size = params_buffer_bytes(params); + prtd->periods = params_periods(params); + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + prtd->bits_per_sample = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + prtd->bits_per_sample = 24; + break; + } + + return 0; +} + +static int q6apm_dai_pcm_new(struct snd_soc_component *component, + struct snd_soc_pcm_runtime *rtd) +{ + struct snd_pcm_substream *psubstream, *csubstream; + struct snd_pcm *pcm = rtd->pcm; + struct device *dev; + int size, ret; + + dev = component->dev; + size = BUFFER_BYTES_MAX; + psubstream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + if (psubstream) { + ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, + &psubstream->dma_buffer); + if (ret) { + dev_err(dev, "Cannot allocate buffer(s)\n"); + return ret; + } + } + + csubstream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; + if (csubstream) { + ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, + &csubstream->dma_buffer); + if (ret) { + dev_err(dev, "Cannot allocate buffer(s)\n"); + if (psubstream) + snd_dma_free_pages(&psubstream->dma_buffer); + return ret; + } + } + + return 0; +} + +static void q6apm_dai_pcm_free(struct snd_soc_component *component, + struct snd_pcm *pcm) +{ + struct snd_pcm_substream *substream; + int i; + + if (!pcm->streams) + return; + + for (i = 0; i < ARRAY_SIZE(pcm->streams); i++) { + substream = pcm->streams[i].substream; + if (substream) { + snd_dma_free_pages(&substream->dma_buffer); + substream->dma_buffer.area = NULL; + substream->dma_buffer.addr = 0; + } + } +} + +static const struct snd_soc_component_driver q6apm_fe_dai_component = { + .name = DRV_NAME, + .open = q6apm_dai_open, + .close = q6apm_dai_close, + .prepare = q6apm_dai_prepare, + .pcm_construct = q6apm_dai_pcm_new, + .pcm_destruct = q6apm_dai_pcm_free, + .mmap = q6apm_dai_mmap, + .hw_params = q6apm_dai_hw_params, + .pointer = q6apm_dai_pointer, + .trigger = q6apm_dai_trigger, +}; + +static int q6apm_dai_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; + struct of_phandle_args args; + struct q6apm_dai_data *pdata; + int rc; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + rc = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); + if (rc < 0) + pdata->sid = -1; + else + pdata->sid = args.args[0] & SID_MASK_DEFAULT; + + dev_set_drvdata(dev, pdata); + + return devm_snd_soc_register_component(dev, &q6apm_fe_dai_component, + NULL, 0); +} + +static const struct of_device_id q6apm_dai_device_id[] = { + { .compatible = "qcom,q6apm-dais" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6apm_dai_device_id); + +static struct platform_driver q6apm_dai_platform_driver = { + .driver = { + .name = "q6apm-dai", + .of_match_table = of_match_ptr(q6apm_dai_device_id), + }, + .probe = q6apm_dai_probe, +}; +module_platform_driver(q6apm_dai_platform_driver); + +MODULE_DESCRIPTION("Q6APM dai driver"); +MODULE_LICENSE("GPL v2"); From patchwork Wed Jul 14 15:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476806 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676657jao; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtnwj3lWSobAh1CrKcXu+3ouVnomFXI2Z7ZGsDOE0aj0vVBc42QpP7NmtQbA+EyjmBLAQd X-Received: by 2002:a05:6602:2285:: with SMTP id d5mr7199406iod.24.1626276682120; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276682; cv=none; d=google.com; s=arc-20160816; b=S3WhsOYUs8jOnpt61bGclh7YZzekKDX0Ql4cO7FSvAcAlK1kfbeNsPJz01zWlWntLw lVVdBXnMr9keGfYt1W7pyuww8XdC6forrR1IrNf/B+RNyRI49S37rn2RVDKeI1jClktR SSqiIuxDJXegWIbbhHmrXNsp83Q0FQ7DgSJsOfuWBI9X0QQomTfD2QcxbRVjC/7ug7T7 BdE7Awa8tqqWiEX8366pHERhddsBsRy4mt1VJaGrIY9J8fr/sjx3jKgaSxYdKy9iVW5g bZBp5zINM0F4s+titD8fsgkDM1hNO7GTfMyy1EKAHvJAH/G7DOSDGjD3W8LGHwpTfcub DJJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SqDX3/H+P3MgM7k2fcZh+x2DKwo90wk8jZBHjomVZNU=; b=xgJzKuY4fpts2kLxHek98VawyU032hxJc87nMs3FxIirOaiH/DWL5WkG3kGxr01j7p 1EFKVNFXE18qpYY0+2Az3jiDMgqZTHy412RiFOtmFYyRNhwh7wlRGhoLdYcbqI70FiJ3 Iia5DfSE0IBBZ0Qp3qcwXIEbImMrYsNsb2bd2gnLCb+ILYxJWKtMXEeSsHuuEuLqUEXx KVSz7pnRa4ceo+OcksipV8dE/AVM1OVkENwbSnplp45t1n3k4d8Iy/ApQcbh8TnGum66 6AtpkhiOj6hT2FDHBqcLSTZPUVpyjhKBNy/em7Kl5kM8O931y5dPZbJRXQ4F1rP8Ja8Z lBNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ygfH7FFw; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.21; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ygfH7FFw; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239805AbhGNPeK (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239811AbhGNPeG (ORCPT ); Wed, 14 Jul 2021 11:34:06 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48CC1C0613E0 for ; Wed, 14 Jul 2021 08:31:13 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id j34so1837376wms.5 for ; Wed, 14 Jul 2021 08:31:13 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=SqDX3/H+P3MgM7k2fcZh+x2DKwo90wk8jZBHjomVZNU=; b=ygfH7FFwIX7K6B46iUM65aV3MpkLizbqEGOu137M4GV7D3OTqI0ln7xVng2oNrADQs K21sa7DrnrlkEb2rSc8CbG7p34nUfao2b5oWbMCyKA5wnDM5uhdIaObE3Fi5I1CoRc/n ncsyVUJeutYhuWEmDZJJ/r3cNDYtm15J7JL2XiPrjKghWuhjKD2U4xKc+N8c4BtEELBZ i1YBhdHBfLJus/hCacevRNI0YKL6ghAbplm+RNj7VmYHn1x78jSaH18be78AhsyeazFe 3hsPHC1RvuW85GUOtK/7ZeLpuZork28fs0cr6rMRKdO4ENG5CPzwJo7as1CSgZVKC+M4 VnBA== 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:mime-version:content-transfer-encoding; bh=SqDX3/H+P3MgM7k2fcZh+x2DKwo90wk8jZBHjomVZNU=; b=JuJak6yX87a3SjjEJ/lVdW9sJ6CyRyJ8w30w0HbIcp4NCmyiXAcOJExNQzTDterXGv Jtv4kVzuaTfBS29Wo8fADDZSeXX95f3RgGDN0iXnvd/D/QwDkQd4UAKzMPrLZHEf9TKg zTVIPPEbIJv/rj2mACRIbBdWnOXl4nc2a9W1K8iTa+7HQTt0htJo9FVY0D59NhsroJ/s x7TXMuAPVg1xHKGwFsXwobhjosRtavukjOyndk8OpHtAM2qKw7vu0E6xPasB+JogFuOy 5L9L73ZaBaVnb2nBGh+MF2jUz4bfkaqXne9ScL7Wl7qJKL1z8lav9UcA7ZUMRiaGmZU4 BURg== X-Gm-Message-State: AOAM533NesnylRpypOxaq/uSp4ON02ET2qAhhb6LGiyN7C7JE6zOkrZa s6divdNE8dUXUbShEsPzuy6JYA== X-Received: by 2002:a1c:4d06:: with SMTP id o6mr11917907wmh.55.1626276671837; Wed, 14 Jul 2021 08:31:11 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:11 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 10/16] ASoC: qcom: audioreach: add bedai support Date: Wed, 14 Jul 2021 16:30:33 +0100 Message-Id: <20210714153039.28373-11-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/audioreach/Makefile | 2 + sound/soc/qcom/audioreach/q6apm-bedai.c | 323 ++++++++++++++++++++++++ 3 files changed, 329 insertions(+) create mode 100644 sound/soc/qcom/audioreach/q6apm-bedai.c -- 2.21.0 diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 4efbf41539c5..eb4446206710 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -106,11 +106,15 @@ config SND_SOC_QDSP6 config SND_SOC_QCOM_APM_DAI tristate +config SND_SOC_QCOM_APM_BEDAI + tristate + config SND_SOC_QCOM_AUDIOREACH tristate "SoC ALSA audio drives for Qualcomm AUDIOREACH" depends on QCOM_GPR select SND_SOC_TOPOLOGY select SND_SOC_QCOM_APM_DAI + select SND_SOC_QCOM_APM_BEDAI help Support for AudioReach in QDSP diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile index 7160bddbb1fb..e8651455b206 100644 --- a/sound/soc/qcom/audioreach/Makefile +++ b/sound/soc/qcom/audioreach/Makefile @@ -1,8 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only snd-ar-objs := audioreach.o q6apm.o topology.o snd-apm-dai-objs := q6apm-dai.o +snd-apm-bedai-objs := q6apm-bedai.o obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o obj-$(CONFIG_SND_SOC_QCOM_APM_DAI) += snd-apm-dai.o +obj-$(CONFIG_SND_SOC_QCOM_APM_BEDAI) += snd-apm-bedai.o diff --git a/sound/soc/qcom/audioreach/q6apm-bedai.c b/sound/soc/qcom/audioreach/q6apm-bedai.c new file mode 100644 index 000000000000..d5d0e1f1bd6c --- /dev/null +++ b/sound/soc/qcom/audioreach/q6apm-bedai.c @@ -0,0 +1,323 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2021, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "audioreach.h" +#include "q6apm.h" + +#define Q6APM_CDC_DMA_RX_DAI(did) { \ + .playback = { \ + .stream_name = #did" Playback", \ + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ + SNDRV_PCM_RATE_176400, \ + .formats = SNDRV_PCM_FMTBIT_S16_LE | \ + SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S32_LE, \ + .channels_min = 1, \ + .channels_max = 8, \ + .rate_min = 8000, \ + .rate_max = 176400, \ + }, \ + .name = #did, \ + .ops = &q6dma_ops, \ + .id = did, \ + } + +#define Q6APM_CDC_DMA_TX_DAI(did) { \ + .capture = { \ + .stream_name = #did" Capture", \ + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ + SNDRV_PCM_RATE_176400, \ + .formats = SNDRV_PCM_FMTBIT_S16_LE | \ + SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S32_LE, \ + .channels_min = 1, \ + .channels_max = 8, \ + .rate_min = 8000, \ + .rate_max = 176400, \ + }, \ + .name = #did, \ + .ops = &q6dma_ops, \ + .id = did, \ + } + +#define AUDIOREACH_BE_PCM_BASE 16 + +struct q6apm_bedai_data { + struct q6apm_graph *graph[APM_PORT_MAX]; + uint16_t bits_per_sample[APM_PORT_MAX]; + bool is_port_started[APM_PORT_MAX]; + struct q6apm_port_config port_config[APM_PORT_MAX]; +}; + +static int q6dma_set_channel_map(struct snd_soc_dai *dai, + unsigned int tx_num, unsigned int *tx_ch_mask, + unsigned int rx_num, unsigned int *rx_ch_mask) +{ + + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct q6apm_cdc_dma_cfg *cfg = &dai_data->port_config[dai->id].dma_cfg; + int ch_mask; + int rc = 0; + + switch (dai->id) { + case WSA_CODEC_DMA_TX_0: + case WSA_CODEC_DMA_TX_1: + case WSA_CODEC_DMA_TX_2: + case VA_CODEC_DMA_TX_0: + case VA_CODEC_DMA_TX_1: + case VA_CODEC_DMA_TX_2: + case TX_CODEC_DMA_TX_0: + case TX_CODEC_DMA_TX_1: + case TX_CODEC_DMA_TX_2: + case TX_CODEC_DMA_TX_3: + case TX_CODEC_DMA_TX_4: + case TX_CODEC_DMA_TX_5: + if (!tx_ch_mask) { + dev_err(dai->dev, "tx slot not found\n"); + return -EINVAL; + } + + if (tx_num > PCM_MAX_NUM_CHANNEL) { + dev_err(dai->dev, "invalid tx num %d\n", + tx_num); + return -EINVAL; + } + ch_mask = *tx_ch_mask; + + break; + case WSA_CODEC_DMA_RX_0: + case WSA_CODEC_DMA_RX_1: + case RX_CODEC_DMA_RX_0: + case RX_CODEC_DMA_RX_1: + case RX_CODEC_DMA_RX_2: + case RX_CODEC_DMA_RX_3: + case RX_CODEC_DMA_RX_4: + case RX_CODEC_DMA_RX_5: + case RX_CODEC_DMA_RX_6: + case RX_CODEC_DMA_RX_7: + /* rx */ + if (!rx_ch_mask) { + dev_err(dai->dev, "rx slot not found\n"); + return -EINVAL; + } + if (rx_num > APM_PORT_MAX_AUDIO_CHAN_CNT) { + dev_err(dai->dev, "invalid rx num %d\n", + rx_num); + return -EINVAL; + } + ch_mask = *rx_ch_mask; + + break; + default: + dev_err(dai->dev, "%s: invalid dai id 0x%x\n", + __func__, dai->id); + return -EINVAL; + } + + cfg->active_channels_mask = ch_mask; + + return rc; +} + +static int q6dma_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct q6apm_cdc_dma_cfg *cfg = &dai_data->port_config[dai->id].dma_cfg; + + cfg->bit_width = params_width(params); + cfg->sample_rate = params_rate(params); + cfg->num_channels = params_channels(params); + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + dai_data->bits_per_sample[dai->id] = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + dai_data->bits_per_sample[dai->id] = 24; + break; + } + + return 0; +} + +static void q6apm_bedai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + int rc; + + if (!dai_data->is_port_started[dai->id]) + return; + rc = q6apm_graph_stop(dai_data->graph[dai->id]); + if (rc < 0) + dev_err(dai->dev, "fail to close APM port (%d)\n", rc); + + q6apm_graph_close(dai_data->graph[dai->id]); + dai_data->is_port_started[dai->id] = false; + +} + +static int q6apm_bedai_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct q6apm_cdc_dma_cfg *cfg = &dai_data->port_config[dai->id].dma_cfg; + int graph_id = dai->id; + int rc; + int ret; + struct q6apm_graph *graph; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + graph = q6apm_graph_open(dai->dev, NULL, dai->dev, graph_id); + if (IS_ERR(graph)) { + dev_err(dai->dev, "Failed to open graph (%d)\n", + graph_id); + ret = PTR_ERR(graph); + return ret; + } + dai_data->graph[graph_id] = graph; + } + + rc = q6apm_graph_media_format_pcm(dai_data->graph[dai->id], + substream->stream, cfg->sample_rate, + cfg->num_channels, NULL, cfg->bit_width); + + rc = q6apm_graph_prepare(dai_data->graph[dai->id]); + rc = q6apm_graph_start(dai_data->graph[dai->id]); + if (rc < 0) { + dev_err(dai->dev, "fail to start APM port %x\n", dai->id); + return rc; + } + dai_data->is_port_started[dai->id] = true; + + return 0; +} + +static int q6apm_bedai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + int graph_id = dai->id, ret; + struct q6apm_graph *graph; + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + graph = q6apm_graph_open(dai->dev, NULL, dai->dev, graph_id); + if (IS_ERR(graph)) { + dev_err(dai->dev, "Failed to open graph (%d)\n", + graph_id); + ret = PTR_ERR(graph); + return ret; + } + dai_data->graph[graph_id] = graph; + } + + return 0; +} + +static const struct snd_soc_dai_ops q6dma_ops = { + .prepare = q6apm_bedai_prepare, + .startup = q6apm_bedai_startup, + .shutdown = q6apm_bedai_shutdown, + .set_channel_map = q6dma_set_channel_map, + .hw_params = q6dma_hw_params, +}; + +static struct snd_soc_dai_driver q6apm_be_dais[] = { + Q6APM_CDC_DMA_RX_DAI(WSA_CODEC_DMA_RX_0), + Q6APM_CDC_DMA_TX_DAI(WSA_CODEC_DMA_TX_0), + Q6APM_CDC_DMA_RX_DAI(WSA_CODEC_DMA_RX_1), + Q6APM_CDC_DMA_TX_DAI(WSA_CODEC_DMA_TX_1), + Q6APM_CDC_DMA_TX_DAI(WSA_CODEC_DMA_TX_2), + Q6APM_CDC_DMA_TX_DAI(VA_CODEC_DMA_TX_0), + Q6APM_CDC_DMA_TX_DAI(VA_CODEC_DMA_TX_1), + Q6APM_CDC_DMA_TX_DAI(VA_CODEC_DMA_TX_2), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_0), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_0), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_1), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_1), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_2), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_2), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_3), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_3), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_4), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_4), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_5), + Q6APM_CDC_DMA_TX_DAI(TX_CODEC_DMA_TX_5), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_6), + Q6APM_CDC_DMA_RX_DAI(RX_CODEC_DMA_RX_7), +}; + +static int q6apm_of_xlate_dai_name(struct snd_soc_component *component, + const struct of_phandle_args *args, + const char **dai_name) +{ + int id = args->args[0]; + int ret = -EINVAL; + int i; + + for (i = 0; i < ARRAY_SIZE(q6apm_be_dais); i++) { + if (q6apm_be_dais[i].id == id) { + *dai_name = q6apm_be_dais[i].name; + ret = 0; + break; + } + } + + return ret; +} + +static const struct snd_soc_component_driver q6apm_bedai_component = { + .name = "q6apm-be-dai-component", + .of_xlate_dai_name = q6apm_of_xlate_dai_name, + .be_pcm_base = AUDIOREACH_BE_PCM_BASE, + .use_dai_pcm_id = true, +}; + +static int q6apm_bedai_dev_probe(struct platform_device *pdev) +{ + struct q6apm_bedai_data *dai_data; + struct device *dev = &pdev->dev; + + dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL); + if (!dai_data) + return -ENOMEM; + + dev_set_drvdata(dev, dai_data); + + return devm_snd_soc_register_component(dev, &q6apm_bedai_component, + q6apm_be_dais, + ARRAY_SIZE(q6apm_be_dais)); +} + +#ifdef CONFIG_OF +static const struct of_device_id q6apm_bedai_device_id[] = { + { .compatible = "qcom,q6apm-bedais" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6apm_bedai_device_id); +#endif + +static struct platform_driver q6apm_bedai_platform_driver = { + .driver = { + .name = "q6apm-bedai", + .of_match_table = of_match_ptr(q6apm_bedai_device_id), + }, + .probe = q6apm_bedai_dev_probe, +}; +module_platform_driver(q6apm_bedai_platform_driver); + +MODULE_DESCRIPTION("AUDIOREACH Audio BackEnd dai driver"); +MODULE_LICENSE("GPL"); From patchwork Wed Jul 14 15:30:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476804 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676621jao; Wed, 14 Jul 2021 08:31:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOsZ6PKmpgGih8ydv8fJk2XzN93/ZoZ1JJ7tC33eMHZTlQJAR2FPE/3NjVFskISegWg7vY X-Received: by 2002:a92:c64a:: with SMTP id 10mr7107533ill.159.1626276679914; Wed, 14 Jul 2021 08:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276679; cv=none; d=google.com; s=arc-20160816; b=dE9Wzj0Up7DjewjOlEp2OWydnp5SQpNrm6sZUcQMyLKRuq7lADpmLtyuuBUaxTOAUr bRIi0RKZojhNQIpi8Oq5mXqQilnjWbLfAYFWNzBBd60M+j2DYd8ZBonNiJm1Wo/owdpG iujAWQvI/raY3uXil6OfDYmKQGxAunPgln7pvoYZYN1NCbP4K4b2RS1Epzf1qQcZ2ZkL RegYKBYovwXaB3dbOXn9QjxJyhaEevRDLdmtgN9S9w2qOYSnJA5L5WeK/OQVGPmDAikL +sKIsTfBJinxObn3Q98yEvE0rm7j4eCL4qFa8E/vR23HZPw61QTpbTFyNo4IOn1ZMhQr 6wHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=idmBojPKMaEqXxTsPN9NMivz3VoeKNs2nUJ6x42cpzc=; b=q4Mect62e5B7UqckNAA8h9IhtVrgaR85hDAK50EQcEGHvv8dZjGR7Vqca7+d1M3/1V YJK9RXjmjJG9A0nALMunE6tqMj454SkQcxAMx/1H9h5PTiNAr8gbLZ1A8aJQOvQP7HEP 6PlnWiZ6IWWnrciW3XwLdCQrXisMdpj3gaBQ1oTSzhsPXORnLcUxfUJiF8NQpKYcVx6x isQ+TyiK1ru91faTcrIvqz1eaInNpGVprfiqxvS8c/msyjSN64uc7RVWBGlzwEs5O+0X uEx2EeJaoNIPP8v1d3VGfUryDS/L9tL6oY00aGz0DHCw9OgBGss9ehShetrxY86w2D87 bAGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=agLBPgKG; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.19; Wed, 14 Jul 2021 08:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=agLBPgKG; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239774AbhGNPeJ (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239819AbhGNPeH (ORCPT ); Wed, 14 Jul 2021 11:34:07 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69EE8C061766 for ; Wed, 14 Jul 2021 08:31:14 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l8-20020a05600c1d08b02902333d79327aso1085614wms.3 for ; Wed, 14 Jul 2021 08:31:14 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=idmBojPKMaEqXxTsPN9NMivz3VoeKNs2nUJ6x42cpzc=; b=agLBPgKG6NCQ7IVxrRVEplMT6waFwhNQPFhzQQpnpJKX7/YBMSJxK8w0vmN7DtVDGL n6ikaA3s1XieoJ4wRldmKO6pq8vcxxFdy8IS5k8GTYZzMzC+iKIUz673QMQaI8WmL9cZ hv2rjCDIlmlUxI4wLEsVn8lUOjIJugBtWJ6S4X1UsBmQM4Usmmy6uM++A73uREFhxFYd aFSNA+OW9gwsGk0HhsAlBlgQ3DRIlFuYyzyi6gDhUb+1/Erymzr82qHYGhfPHpJnB2dx u35VhguFMJxpiwV+YLjjbLR8WZ0BgLRIrGShF2Wvn25hY2xJVgDmnOKLaz0v/UjyFavT FeEg== 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:mime-version:content-transfer-encoding; bh=idmBojPKMaEqXxTsPN9NMivz3VoeKNs2nUJ6x42cpzc=; b=FUhx2XzLDfJTX1Urov5+YqpUX1SGxrZJkTvk9mKWY3GCMb/QPeNYCewsWu9TlDZJ2a ahUwHlLnZlGIDX3Kr1qcdmSQWZs60MJPvUibTVClxWy3n0lkh3puvG9bgAPLtDt4NWXX j1knWiNFs/ykiKrDHrpziJQ9hYnnllftnrmZ4IBR3mgyjbyHhxE/ItvSaOsq1y8FuX3m dKgLD0vAHWqQp9czIXWIVzrW4EWvX+/6F6J9Mh7pRNhfbybC84MAB0kwVJ1Mq0b/GLhd Jj8yWEH/0i9Fk0vlhBQYFDO4WyYxUwu1ugeanquyO3rNmM+dYqYSf4ks57dqVWCxvbJO Yr4g== X-Gm-Message-State: AOAM531pa7mZm/h84SNDDQ/5qT2Kvw4LXMGhVmY2MqcwrXOuXcPodqXe 8dRxsUIv4oRCIqiels+WjzZdVg== X-Received: by 2002:a1c:80cd:: with SMTP id b196mr4732641wmd.179.1626276672854; Wed, 14 Jul 2021 08:31:12 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:12 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 11/16] ASoC: qcom: dt-bindings: add bindings for Proxy Resource Manager Date: Wed, 14 Jul 2021 16:30:34 +0100 Message-Id: <20210714153039.28373-12-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds bindings support for Qualcomm Proxy Resource Manager service in Audio DSP. Signed-off-by: Srinivas Kandagatla --- .../devicetree/bindings/sound/qcom,q6prm.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/qcom,q6prm.yaml -- 2.21.0 diff --git a/Documentation/devicetree/bindings/sound/qcom,q6prm.yaml b/Documentation/devicetree/bindings/sound/qcom,q6prm.yaml new file mode 100644 index 000000000000..6f14146c1ea1 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/qcom,q6prm.yaml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/qcom,q6prm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Q6 Proxy Resource Manager + +maintainers: + - Srinivas Kandagatla + +description: | + Proxy Resource Manager module is core module used to manage + core dsp resources like clocks + +properties: + compatible: + const: qcom,q6prm + + reg: + maxItems: 1 + + '#clock-cells': + const: 2 + +required: + - compatible + - reg + - '#clock-cells' + +additionalProperties: false + +examples: + - | + gpr { + #address-cells = <1>; + #size-cells = <0>; + gprservice@2 { + compatible = "qcom,q6prm"; + reg = <2>; + #clock-cells = <2>; + }; + }; From patchwork Wed Jul 14 15:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476813 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp677350jao; Wed, 14 Jul 2021 08:32:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk4m6NLAbBcXesbQdfpaA3IYBRLan1i2qQFElGcQoCbs7XW4UG2JW2DbkNxl8NBSjGahIF X-Received: by 2002:a5e:9e02:: with SMTP id i2mr7762345ioq.198.1626276723185; Wed, 14 Jul 2021 08:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276723; cv=none; d=google.com; s=arc-20160816; b=Kn/VW6v3mWcf0tlWPBw7VbSDViJAeW/JKCKDHgzboTZjar2cCMpHXhzldW0tX6kMZk Fk0EIpRVLwRqHt7r/rNl4G4+ZYqAgb9D/zG4xL2WsNNWbMEfmIGusZG36hufpZzncg9N 8Q9X4RXXrFQswJ0HEB/nGWhoUB395TzygUKcunsD6Mr9mGDVO/v6r4iVKcgjENN6znfz hlaNk8YsTKzqyTwWr6MQAz4qoKZIQraRETUQWz03nfav0X1DG5EmGAtZYatoSG48G18V BbqYqcBNqPpCktLMJtDowNw/kFG1dwmHKGK5qwz23rywG2ogshjj9V473+Lxdjtx1GU9 S/sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9zXg7JnOukTkaW805QlJ4HiJSk9V/bsFHbeJb75Yd94=; b=yQO7h3ddvrchf4aBuFvH/aD3Me1vuTrN38S7PG1380Yi9SSefFTeL8QRihfEHlzJdJ uyBA/+z0nyL44/CPFdhrZPrFHvlHBKnSA8pBph+gRgcVz8v0vUQA/oYjMN0zd9S+AhzC noXRrCAdi01qpbrtVn+ul+TgllG6E6/xmxu+ppNeL9kT877yOzy8Cbt92hmR8FcGsWJb 1BcRTDfWxpV9mRmEzYqwYkGOZXv4el1Fjlg1V3pAMIGRQ65Fz2DHRdRCi+y2Na4wzSfH +qqujjgkmAd2D8N9hxWnLmNKq21/YXqUctOo9F/+pOR/bEfzQS3r9bbVV8kGh3tDa0wl MXfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cbrreCeq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j8si3345523jak.26.2021.07.14.08.32.03; Wed, 14 Jul 2021 08:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cbrreCeq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239969AbhGNPex (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239862AbhGNPeI (ORCPT ); Wed, 14 Jul 2021 11:34:08 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB82C061765 for ; Wed, 14 Jul 2021 08:31:15 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l7so3726677wrv.7 for ; Wed, 14 Jul 2021 08:31:15 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=9zXg7JnOukTkaW805QlJ4HiJSk9V/bsFHbeJb75Yd94=; b=cbrreCeqRLBXjQBmTNCVBoekSxhIKcycZ5/p6UsoDMm1kQABQLNB6ug0Dzdi5Yo1hb UoYKQ5KVJlGSE9SevBU3NkkKtCrQ1w9SR6nmpui7tr7MBIMiCCQ8MqawyBi2nKIVsOKT Nn+M9bZmj1dcDjsLkYD2PrtxkkCpsgpAh3dyhx1jPT+EpdgzgLs/IM5Qs+O20cJH6DKy bYJvgqaJNZgttPpmqcyr2oxhShsRBPxxNpe3nly8Hguo/ouIb/T6+y7zHODzqlaCRX2F CpY9iCBA9zgx74pMU7PFvcXIF4NuMv99r5ch3uekMgbZUqc3st6WW7DXzyJzuXPRCkAf Ojyw== 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:mime-version:content-transfer-encoding; bh=9zXg7JnOukTkaW805QlJ4HiJSk9V/bsFHbeJb75Yd94=; b=uj2c91krv7HOAOgbqwd71xYTKQ3CmMBuGlmYlRUyAIFfFcsjcQV6lmkitLWkjjxtQX JCgUzZMLfSUhNziptH/o9ned/QS11Ge/JcZrc/EzMRlt4ZZKF19KOx3xthmyvGVJJuGj V9f9SLUXnJwRH6mBGm5MJp4njftXSzXm8abNWUpYnOy0qWVwOoXP71ShHw7qbRCsZe+O ipHItDXEk353GRj8LYSSg0UWUB45y+ws80LP87PmTKIm+8afJiATWfnVPotBXnipSZ9Q H/vh5PQGt3qFtsJMgzLK2JHYp4FE8cOLXiWaPexrjMv6ZE+AHHYARHeyngdUII+kKIfU VysA== X-Gm-Message-State: AOAM530x0hzUqOn5BY6rNC8bfWg5nxIGx3+RiU3ZkkOIUmKWdhErCImQ gMaGRiuClzF5SNljecf9DRQs3Q== X-Received: by 2002:a05:6000:136a:: with SMTP id q10mr13903003wrz.25.1626276673889; Wed, 14 Jul 2021 08:31:13 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:13 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 12/16] ASoC: qcom: audioreach: add q6prm support Date: Wed, 14 Jul 2021 16:30:35 +0100 Message-Id: <20210714153039.28373-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support to q6prm (Proxy Resource Manager) module used for clock resources Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/audioreach/Makefile | 2 + sound/soc/qcom/audioreach/q6prm.c | 414 +++++++++++++++++++++++++++++ 3 files changed, 420 insertions(+) create mode 100644 sound/soc/qcom/audioreach/q6prm.c -- 2.21.0 Reported-by: kernel test robot diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index eb4446206710..5f7d7d956355 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -109,12 +109,16 @@ config SND_SOC_QCOM_APM_DAI config SND_SOC_QCOM_APM_BEDAI tristate +config SND_SOC_QCOM_PRM + tristate + config SND_SOC_QCOM_AUDIOREACH tristate "SoC ALSA audio drives for Qualcomm AUDIOREACH" depends on QCOM_GPR select SND_SOC_TOPOLOGY select SND_SOC_QCOM_APM_DAI select SND_SOC_QCOM_APM_BEDAI + select SND_SOC_QCOM_PRM help Support for AudioReach in QDSP diff --git a/sound/soc/qcom/audioreach/Makefile b/sound/soc/qcom/audioreach/Makefile index e8651455b206..d9904201ccf0 100644 --- a/sound/soc/qcom/audioreach/Makefile +++ b/sound/soc/qcom/audioreach/Makefile @@ -2,9 +2,11 @@ snd-ar-objs := audioreach.o q6apm.o topology.o snd-apm-dai-objs := q6apm-dai.o snd-apm-bedai-objs := q6apm-bedai.o +snd-prm-objs := q6prm.o obj-$(CONFIG_SND_SOC_QCOM_AUDIOREACH) += snd-ar.o obj-$(CONFIG_SND_SOC_QCOM_APM_DAI) += snd-apm-dai.o obj-$(CONFIG_SND_SOC_QCOM_APM_BEDAI) += snd-apm-bedai.o +obj-$(CONFIG_SND_SOC_QCOM_PRM) += snd-prm.o diff --git a/sound/soc/qcom/audioreach/q6prm.c b/sound/soc/qcom/audioreach/q6prm.c new file mode 100644 index 000000000000..2cadb7b28a1c --- /dev/null +++ b/sound/soc/qcom/audioreach/q6prm.c @@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2021, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "audioreach.h" + +#define Q6PRM_MAX_CLK_ID 104 + +#define Q6PRM_CLK(id) &(struct q6prm_clk) { \ + .clk_id = id, \ + .afe_clk_id = Q6PRM_##id, \ + .name = #id, \ + .attributes = LPASS_CLK_ATTRIBUTE_COUPLE_NO, \ + .rate = 19200000, \ + .hw.init = &(struct clk_init_data) { \ + .ops = &clk_q6prm_ops, \ + .name = #id, \ + }, \ + } + +#define Q6PRM_VOTE_CLK(id, blkid) &(struct q6prm_clk) { \ + .clk_id = id, \ + .afe_clk_id = blkid, \ + .hw.init = &(struct clk_init_data) { \ + .ops = &clk_vote_q6prm_ops, \ + .name = #id, \ + }, \ + } + +struct q6prm_clk { + struct device *dev; + int clk_id; + int afe_clk_id; + char *name; + int attributes; + int rate; + uint32_t handle; + struct clk_hw hw; +}; +#define to_q6prm_clk(_hw) container_of(_hw, struct q6prm_clk, hw) + +struct q6prm { + struct device *dev; + gpr_device_t *gdev; + wait_queue_head_t wait; + struct gpr_ibasic_rsp_result_t result; + struct mutex lock; + struct q6prm_clk **clks; + int num_clks; +}; + +#define PRM_CMD_REQUEST_HW_RSC 0x0100100F +#define PRM_CMD_RSP_REQUEST_HW_RSC 0x02001002 +#define PRM_CMD_RELEASE_HW_RSC 0x01001010 +#define PRM_CMD_RSP_RELEASE_HW_RSC 0x02001003 + +#define PARAM_ID_RSC_HW_CORE 0x08001032 +#define PARAM_ID_RSC_LPASS_CORE 0x0800102B +#define PARAM_ID_RSC_AUDIO_HW_CLK 0x0800102C + +#define Q6PRM_LPASS_CLK_ID_WSA_CORE_MCLK 0x305 +#define Q6PRM_LPASS_CLK_ID_WSA_CORE_NPL_MCLK 0x306 + +#define Q6PRM_LPASS_CLK_ID_VA_CORE_MCLK 0x307 +#define Q6PRM_LPASS_CLK_ID_VA_CORE_2X_MCLK 0x308 + +#define Q6PRM_LPASS_CLK_ID_TX_CORE_MCLK 0x30c +#define Q6PRM_LPASS_CLK_ID_TX_CORE_NPL_MCLK 0x30d + +#define Q6PRM_LPASS_CLK_ID_RX_CORE_MCLK 0x30e +#define Q6PRM_LPASS_CLK_ID_RX_CORE_NPL_MCLK 0x30f + +#define Q6PRM_LPASS_CLK_SRC_INTERNAL 1 +#define Q6PRM_LPASS_CLK_ROOT_DEFAULT 0 +#define Q6PRM_HW_CORE_ID_LPASS 1 +#define Q6PRM_HW_CORE_ID_DCODEC 2 + +struct prm_cmd_request_hw_core { + struct apm_module_param_data param_data; + uint32_t hw_clk_id; +} __packed; + +struct prm_cmd_request_rsc { + struct apm_module_param_data param_data; + uint32_t num_clk_id; + struct audio_hw_clk_cfg clock_ids[1]; +} __packed; + +struct prm_cmd_release_rsc { + struct apm_module_param_data param_data; + uint32_t num_clk_id; + struct audio_hw_clk_cfg clock_ids[1]; +} __packed; + +static int q6prm_send_cmd_sync(struct q6prm *prm, struct gpr_pkt *pkt, + uint32_t rsp_opcode) +{ + gpr_device_t *gdev = prm->gdev; + struct gpr_hdr *hdr = &pkt->hdr; + int rc; + + mutex_lock(&prm->lock); + prm->result.opcode = 0; + prm->result.status = 0; + + rc = gpr_send_pkt(prm->gdev, pkt); + if (rc < 0) + goto err; + + if (rsp_opcode) + rc = wait_event_timeout(prm->wait, + (prm->result.opcode == hdr->opcode) || + (prm->result.opcode == rsp_opcode), + 5 * HZ); + else + rc = wait_event_timeout(prm->wait, + (prm->result.opcode == hdr->opcode), + 5 * HZ); + + if (!rc) { + dev_err(&gdev->dev, "CMD timeout for [%x] opcode\n", + hdr->opcode); + rc = -ETIMEDOUT; + } else if (prm->result.status > 0) { + dev_err(&gdev->dev, "DSP returned error[%x] %x\n", hdr->opcode, + prm->result.status); + rc = -EINVAL; + } else { + dev_err(&gdev->dev, "DSP returned [%x]\n", + prm->result.status); + rc = 0; + } + +err: + mutex_unlock(&prm->lock); + return rc; +} + +static int q6prm_set_hw_core_req(struct device *dev, uint32_t hw_block_id, bool enable) +{ + struct prm_cmd_request_hw_core *req; + struct apm_module_param_data *param_data; + struct gpr_pkt *pkt; + struct q6prm *prm = dev_get_drvdata(dev); + gpr_device_t *gdev = prm->gdev; + void *p; + int rc = 0; + uint32_t opcode, rsp_opcode; + + if (enable) { + opcode = PRM_CMD_REQUEST_HW_RSC; + rsp_opcode = PRM_CMD_RSP_REQUEST_HW_RSC; + } else { + opcode = PRM_CMD_RELEASE_HW_RSC; + rsp_opcode = PRM_CMD_RSP_RELEASE_HW_RSC; + } + + p = audioreach_alloc_cmd_pkt(sizeof(*req), opcode, 0, gdev->svc.id, + GPR_PRM_MODULE_IID); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + req = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + param_data = &req->param_data; + + param_data->module_instance_id = GPR_PRM_MODULE_IID; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_RSC_HW_CORE; + param_data->param_size = sizeof(*req) - APM_MODULE_PARAM_DATA_SIZE; + + req->hw_clk_id = hw_block_id; + + q6prm_send_cmd_sync(prm, pkt, rsp_opcode); + + kfree(pkt); + + return rc; +} + +static int q6prm_set_lpass_clock(struct device *dev, int clk_id, int clk_attr, + int clk_root, unsigned int freq) +{ + struct prm_cmd_request_rsc *req; + struct apm_module_param_data *param_data; + struct gpr_pkt *pkt; + struct q6prm *prm = dev_get_drvdata(dev); + gpr_device_t *gdev = prm->gdev; + void *p; + int rc = 0; + + p = audioreach_alloc_cmd_pkt(sizeof(*req), PRM_CMD_REQUEST_HW_RSC, + 0, gdev->svc.id, GPR_PRM_MODULE_IID); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + req = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + param_data = &req->param_data; + + param_data->module_instance_id = GPR_PRM_MODULE_IID; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_RSC_AUDIO_HW_CLK; + param_data->param_size = sizeof(*req) - APM_MODULE_PARAM_DATA_SIZE; + + req->num_clk_id = 1; + req->clock_ids[0].clock_id = clk_id; + req->clock_ids[0].clock_freq = freq; + req->clock_ids[0].clock_attri = clk_attr; + req->clock_ids[0].clock_root = clk_root; + + q6prm_send_cmd_sync(prm, pkt, PRM_CMD_RSP_REQUEST_HW_RSC); + + kfree(pkt); + + return rc; +} + +static int prm_callback(struct gpr_resp_pkt *data, void *priv, int op) +{ + gpr_device_t *gdev = priv; + struct q6prm *prm = dev_get_drvdata(&gdev->dev); + struct gpr_ibasic_rsp_result_t *result; + struct gpr_hdr *hdr = &data->hdr; + + result = data->payload; + + switch (hdr->opcode) { + case PRM_CMD_RSP_REQUEST_HW_RSC: + case PRM_CMD_RSP_RELEASE_HW_RSC: + prm->result.opcode = hdr->opcode; + prm->result.status = result->status; + wake_up(&prm->wait); + break; + default: + break; + } + + return 0; +} + +static int clk_q6prm_prepare(struct clk_hw *hw) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + return q6prm_set_lpass_clock(clk->dev, clk->afe_clk_id, clk->attributes, + Q6PRM_LPASS_CLK_ROOT_DEFAULT, clk->rate); +} + +static void clk_q6prm_unprepare(struct clk_hw *hw) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + q6prm_set_lpass_clock(clk->dev, clk->afe_clk_id, clk->attributes, + Q6PRM_LPASS_CLK_ROOT_DEFAULT, 0); +} + +static int clk_q6prm_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + clk->rate = rate; + + return 0; +} + +static unsigned long clk_q6prm_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + return clk->rate; +} + +static long clk_q6prm_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + return rate; +} + +static const struct clk_ops clk_q6prm_ops = { + .prepare = clk_q6prm_prepare, + .unprepare = clk_q6prm_unprepare, + .set_rate = clk_q6prm_set_rate, + .round_rate = clk_q6prm_round_rate, + .recalc_rate = clk_q6prm_recalc_rate, +}; + +static int clk_vote_q6prm_block(struct clk_hw *hw) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + return q6prm_set_hw_core_req(clk->dev, clk->afe_clk_id, true); +} + +static void clk_unvote_q6prm_block(struct clk_hw *hw) +{ + struct q6prm_clk *clk = to_q6prm_clk(hw); + + q6prm_set_hw_core_req(clk->dev, clk->afe_clk_id, false); +} + +static const struct clk_ops clk_vote_q6prm_ops = { + .prepare = clk_vote_q6prm_block, + .unprepare = clk_unvote_q6prm_block, +}; + +static struct q6prm_clk *q6prm_clks[Q6PRM_MAX_CLK_ID] = { + [LPASS_CLK_ID_WSA_CORE_MCLK] = Q6PRM_CLK(LPASS_CLK_ID_WSA_CORE_MCLK), + [LPASS_CLK_ID_WSA_CORE_NPL_MCLK] = + Q6PRM_CLK(LPASS_CLK_ID_WSA_CORE_NPL_MCLK), + [LPASS_CLK_ID_VA_CORE_MCLK] = Q6PRM_CLK(LPASS_CLK_ID_VA_CORE_MCLK), + [LPASS_CLK_ID_TX_CORE_MCLK] = Q6PRM_CLK(LPASS_CLK_ID_TX_CORE_MCLK), + [LPASS_CLK_ID_TX_CORE_NPL_MCLK] = + Q6PRM_CLK(LPASS_CLK_ID_TX_CORE_NPL_MCLK), + [LPASS_CLK_ID_RX_CORE_MCLK] = Q6PRM_CLK(LPASS_CLK_ID_RX_CORE_MCLK), + [LPASS_CLK_ID_RX_CORE_NPL_MCLK] = + Q6PRM_CLK(LPASS_CLK_ID_RX_CORE_NPL_MCLK), + [LPASS_CLK_ID_VA_CORE_2X_MCLK] = + Q6PRM_CLK(LPASS_CLK_ID_VA_CORE_2X_MCLK), + [LPASS_HW_MACRO_VOTE] = Q6PRM_VOTE_CLK(LPASS_HW_MACRO_VOTE, + Q6PRM_HW_CORE_ID_LPASS), + [LPASS_HW_DCODEC_VOTE] = Q6PRM_VOTE_CLK(LPASS_HW_DCODEC_VOTE, + Q6PRM_HW_CORE_ID_DCODEC), +}; + +static struct clk_hw *q6prm_of_clk_hw_get(struct of_phandle_args *clkspec, + void *data) +{ + struct q6prm *cc = data; + unsigned int idx = clkspec->args[0]; + unsigned int attr = clkspec->args[1]; + + if (idx >= cc->num_clks || attr > LPASS_CLK_ATTRIBUTE_COUPLE_DIVISOR) { + dev_err(cc->dev, "Invalid clk specifier (%d, %d)\n", idx, attr); + return ERR_PTR(-EINVAL); + } + + if (cc->clks[idx]) { + cc->clks[idx]->attributes = attr; + return &cc->clks[idx]->hw; + } + + return ERR_PTR(-ENOENT); +} + +static int prm_probe(gpr_device_t *gdev) +{ + struct device *dev = &gdev->dev; + struct q6prm *cc; + int i, ret; + + cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL); + if (!cc) + return -ENOMEM; + + cc->dev = dev; + cc->gdev = gdev; + mutex_init(&cc->lock); + init_waitqueue_head(&cc->wait); + cc->clks = &q6prm_clks[0]; + cc->num_clks = ARRAY_SIZE(q6prm_clks); + for (i = 0; i < ARRAY_SIZE(q6prm_clks); i++) { + if (!q6prm_clks[i]) + continue; + + q6prm_clks[i]->dev = dev; + + ret = devm_clk_hw_register(dev, &q6prm_clks[i]->hw); + if (ret) + return ret; + } + + ret = of_clk_add_hw_provider(dev->of_node, q6prm_of_clk_hw_get, cc); + if (ret) + return ret; + + dev_set_drvdata(dev, cc); + + return 0; +} + +static const struct of_device_id prm_device_id[] = { + { .compatible = "qcom,q6prm" }, + {}, +}; +MODULE_DEVICE_TABLE(of, prm_device_id); + +static gpr_driver_t prm_driver = { + .probe = prm_probe, + .gpr_callback = prm_callback, + .driver = { + .name = "qcom-prm", + .of_match_table = of_match_ptr(prm_device_id), + }, +}; + +module_gpr_driver(prm_driver); +MODULE_DESCRIPTION("Audio Process Manager"); +MODULE_LICENSE("GPL v2"); From patchwork Wed Jul 14 15:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476808 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676670jao; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbXPEPYduws4MjBo7HtAfkCVPxqwcIgP+wGxSNP+iiCVZ3ZDnZEX1/iJG2uRCb8gYbG1ky X-Received: by 2002:a92:cb52:: with SMTP id f18mr5794359ilq.97.1626276682789; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276682; cv=none; d=google.com; s=arc-20160816; b=RF87DtY8hPOqDakmV10uZr3gvgn8lthjJPovfe3JZPx/nHmzDx406rye4r7oZrty2y MuXzpPzteNOFGvkG1BQcef7vfbcT+I+iBWL/nA7VbsdZ54j9R6JIbKmT+qEadte3k4uw H91em+53Mzfm2frORMcTYAHL/T6vnlDQrwdFiu9b/FTduXmQxS4QMGR+mBr2zaqlN84a W2s+DdQp9O/7wwZ79pIwhd5yE3lfyldArNuyVgMBcZ/L30FNnihd0cF2zvjveTprQI1v Pcyi/3nnWgvNlfx+K76nuDGK+/3sqTW9opLAEhwGnOYZJHeQH3wF8nijjklEJANgV+5w PYmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4M0Qy9u7qpzLdCXZMtfpQrDY8UIAvDYX27th6ZO86XE=; b=KSQZeiMGRHIPdztFpTOExwaZBfM0Dgp48/5usGRJouLBIgUVzqlJbBPVWHFPb9b+n6 anM8/Q7gzXXdSyqdc2GInx0Kvfz7PVxsQjqty/KzoB8KJ9WNRMV8EfpODAU6qIm4fE5k ezlAKC0P4pNuujK7JSWsNnPStSjSozBM0VvSwHneGKizyaDfdGZwWZO7Ee72/zoKZTwa tY1U5TqBLJu5hGF+tOHYTYvIsmSW+DjmNB3YfDB7BscjtTXOllIF5GTeFPp0hKeP0ysM 32iW4Mvx61Z1prpioESA5dfEfqfCm1SHe4YvUVeGsgpEYUFnbuv0VT4qVve/JH/A2mwL 5kVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MLzir5u+; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.22; Wed, 14 Jul 2021 08:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MLzir5u+; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239885AbhGNPeL (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239853AbhGNPeI (ORCPT ); Wed, 14 Jul 2021 11:34:08 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB9BC061762 for ; Wed, 14 Jul 2021 08:31:16 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id b14-20020a1c1b0e0000b02901fc3a62af78so4172228wmb.3 for ; Wed, 14 Jul 2021 08:31:16 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=4M0Qy9u7qpzLdCXZMtfpQrDY8UIAvDYX27th6ZO86XE=; b=MLzir5u+L1TZw0QCQvWIj9BP6JSBDcbHCeK5bRrSwvdLa2ZhQVK4+yyzIaISzzKzSX 169ZnI3j7fQaCN+EencL2dLJsdRxk8Ku1PtgQKiCtFpE+Crp52msf9n99sJ5zmiUvZzu WQepkEyiONQcRCNtSStAwa2C++VUJWivAXu7hYkbhtw/TA+oA723d7vFUbRbtLuP1sZI ZUncQyZ/tfYV26h3iMGyP42gHwRe1bzlCs8zoDmgIC/2dYNarsV5f0HsvzmRQiVpbnaw uxn/to7S+vpKSyjK/UJ/IpP/jo0xzvPWBv4T8XREcrTMpf3P9PE2sXG8L9h1zOuUWFCq VSVQ== 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:mime-version:content-transfer-encoding; bh=4M0Qy9u7qpzLdCXZMtfpQrDY8UIAvDYX27th6ZO86XE=; b=p8/Hm7LiJhxOgQ0hpM0R2v0g4HDHFcXZ6b7iodVsLCBOPmkGFQwc/duLLwQC1Ss6IK gCMrgBmhcySXQXr3hHC7BftFe3RHOR/zTqef0KNDFD3+I09Y9hYSVuvvAiEvxcHDyijK zJNLGTEH/KHul6PtPxnSGm600vdcAC61CSqfxrymcTmWBZW/LBjcVhMa1suzvjEGLDWj voIgWYrF61HuC7drplSTvozwM+lnuZNKJT6NbZ4/JgKwAsBU0k00jvlsKSpwn/U/j42G QxvKUy1Pw9Mot/Z0mmPSxCn4pSEQK2mZ7dNqviLcd2ONZVlncecuF1TAwlqEljTjOMtK 8aJw== X-Gm-Message-State: AOAM533UYS+SLV/v1+t6Je+Od3atR4poy9+i5MvLtUqTn7mrAHXeXxN2 OT85YzGTanTJE/Y8WbNFvAIrkWdwas7cUw== X-Received: by 2002:a05:600c:2ca4:: with SMTP id h4mr11774924wmc.37.1626276675086; Wed, 14 Jul 2021 08:31:15 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:14 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 13/16] ASoC: qcom: dt-bindings: add audioreach soundcard compatibles Date: Wed, 14 Jul 2021 16:30:36 +0100 Message-Id: <20210714153039.28373-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add compatible strings for AudioReach DSP firmware based soundcards. Signed-off-by: Srinivas Kandagatla --- .../bindings/sound/qcom,sm8250.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) -- 2.21.0 diff --git a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml index 72ad9ab91832..2f61bc4a2d7e 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -18,6 +18,8 @@ properties: oneOf: - const: qcom,sm8250-sndcard - const: qcom,qrb5165-rb5-sndcard + - const: qcom,sm8250-audioreach-sndcard + - const: qcom,qrb5165-rb5-audioreach-sndcard audio-routing: $ref: /schemas/types.yaml#/definitions/non-unique-string-array @@ -152,6 +154,47 @@ examples: sound-dai = <&q6routing>; }; + codec { + sound-dai = <&vamacro 0>; + }; + }; + }; +#--------------------------- +# AudioReach based dai links +#--------------------------- + - | + #include + sound { + compatible = "qcom,qrb5165-rb5-audioreach-sndcard"; + model = "Qualcomm-qrb5165-RB5-WSA8815-Speakers-DMIC0"; + audio-routing = "SpkrLeft IN", "WSA_SPK1 OUT", + "SpkrRight IN", "WSA_SPK2 OUT"; + + wsa-dai-link { + link-name = "WSA Playback"; + cpu { + sound-dai = <&q6apmbedai WSA_CODEC_DMA_RX_0>; + }; + + platform { + sound-dai = <&q6apm>; + }; + + codec { + sound-dai = <&left_spkr>, <&right_spkr>, <&swr0 0>, <&wsamacro>; + }; + }; + + va-dai-link { + link-name = "VA Capture"; + cpu { + sound-dai = <&q6apmbedai VA_CODEC_DMA_TX_0>; + }; + + platform { + sound-dai = <&q6apm>; + }; + codec { sound-dai = <&vamacro 0>; }; From patchwork Wed Jul 14 15:30:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476811 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676833jao; Wed, 14 Jul 2021 08:31:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGZP7e6TU/2bmIYDOLwQ987NQsg0rb2rPtCjxuIsrRuwNHTN1K0l0nkPLmiegv2y3tEOT8 X-Received: by 2002:a02:942e:: with SMTP id a43mr9508811jai.74.1626276692217; Wed, 14 Jul 2021 08:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276692; cv=none; d=google.com; s=arc-20160816; b=m6cNFWECfrmUuY1xGHkr0RGleBQjzpD2h20ERdYDRGL1AdNlkBe0v0whB1AtAZhj47 BCnjm2yeTtkA/g4jGlsW53hlLuPhhcrVonA6+7lyCToLhXZpn878/VcvUmLYtgvOCGWv tPH94L7vcTR3sQnITwGYa1v9lSy/lk1BUes507f8xVzSX+JkEyNVWerbMhuhlIKW9P1Z z0MssU9N1FPRtbe/IUm/FujDVfzJxPvN3MMw0vJ5mQdUwrbOdL9Lh/kCTb/3OLN83cIn EnzzUe336HN78M6yMXBXOgb3g8NK4Ir8uDVGck8c0XoAt8C7nao9PEmMqCdDSDzsYSjP 8DFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2Lp0zZwDjM0o67Qr8IPD9fZg8MpkDEKyh4GA3N2Mu00=; b=U8o358MnWC4xrWB5881ty8iJrpWrGiQK7ZzNbwvF1iPi/HO0EdSt5eR+4S9EFMNAFw X1HmNEYKwbdQSJgOzp7WsBk5qcDYas8ElC//7Gl45oPBe40DDnX9mfVxZwmqnpbPNo+M q15uEonmrOCigL/spqu6nFh6IjkLzkvxvyUMYoHKHPL+KC2RSFsDxvfjRWfbPgo+pAkY WE/RhKsFaJHm1/hUFJ++h9wldncbL1TB3TNPDXilQgYzl9VTj0gsA0jJ8Q0j+Agjzrh7 3HkjGAvckP8v3WNPY+o7Hl98koqix/f5N6l9bUTdtKmYvf8mCohz6Djkl8l7uzdrQQCs /DwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LiBvy+mq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si2951797jaj.31.2021.07.14.08.31.32; Wed, 14 Jul 2021 08:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LiBvy+mq; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239806AbhGNPeR (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239731AbhGNPeJ (ORCPT ); Wed, 14 Jul 2021 11:34:09 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89339C06175F for ; Wed, 14 Jul 2021 08:31:17 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id l7so3726843wrv.7 for ; Wed, 14 Jul 2021 08:31:17 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=2Lp0zZwDjM0o67Qr8IPD9fZg8MpkDEKyh4GA3N2Mu00=; b=LiBvy+mqpa9juYGqFMgrRvy5qkizs2Cp8TjMp41i3uDErqMjPTy02avYokshjxleW6 bc1hwBPPYIsfV7pBtWCoifHgQ9FfYoUO9hOq0l8TJo1HQt6OLIla5X1ML3tpEgt5BcO6 sSjVsVgBrpyBXn1mEIC6umg5vFMMYI2b5+3gX6BWw9YW26HcONQruouX0g8FTfeeXx/6 VY8TWQYizMW/apMc0EjejQ9rpreX5Y606+0mEus2tAg2M13x0xZsplXFX/VcgWZCN0iX 7SCDdx/Prl/ngUI36WoeotLi+1Npj2/9pMlwmnVrVW8q5v9+sW6+zgAIafvkW/QXFCFf 8kLw== 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:mime-version:content-transfer-encoding; bh=2Lp0zZwDjM0o67Qr8IPD9fZg8MpkDEKyh4GA3N2Mu00=; b=pQ+otOveO2UuG9cicY3XdcUnVLLUUN3CoaO0WuiMr39M9J1OXsp+FFka4hnUr3L2YG N2TZ+N7Tf4qiMWGTzwWDn8rEUo7sUt5dA6rP3JmCLYCZzzkzaEMGcUBcgTY8U1nthIDA 912HBjBZybzpayuVJLOIBi/hoQeU+tjph1iubnFjtfMj84yVz4PbE3Mjbez0ivIOUuWx R6muUc8swjYhDEnN/TzzaYUhbJPtNFF7noJG1WTUkuBDQNpW1+kYOPwRF/RAVj+xhglo dA8B40WN7FPqpXpPfnZLY1fUqmTrikC3wQtgHbnTlncw1YlbaZDAJQc4XO2+GxWuxel5 WuJA== X-Gm-Message-State: AOAM532ugkS8kFcWYJnKuah6V4AWIJTYQ3Fye6shd787HyNPTVvgW7/V H1RLPw5UQKaDymgn+2rejA3PnQ== X-Received: by 2002:adf:facf:: with SMTP id a15mr13666345wrs.39.1626276676193; Wed, 14 Jul 2021 08:31:16 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:15 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 14/16] ASoC: qcom: audioreach: add volume ctrl module support Date: Wed, 14 Jul 2021 16:30:37 +0100 Message-Id: <20210714153039.28373-15-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/audioreach/audioreach.c | 34 ++++++++++++++++++++++++++ sound/soc/qcom/audioreach/audioreach.h | 8 ++++++ 2 files changed, 42 insertions(+) -- 2.21.0 diff --git a/sound/soc/qcom/audioreach/audioreach.c b/sound/soc/qcom/audioreach/audioreach.c index 1839d872fd5f..5a50eede4496 100644 --- a/sound/soc/qcom/audioreach/audioreach.c +++ b/sound/soc/qcom/audioreach/audioreach.c @@ -928,6 +928,40 @@ static int audioreach_shmem_set_media_format(struct q6apm_graph *graph, return rc; } +int audioreach_gain_set_vol_ctrl(struct q6apm *apm, struct audioreach_module + *module, int vol) +{ + struct apm_module_param_data *param_data; + struct param_id_vol_ctrl_master_gain *cfg; + int rc, payload_size; + struct gpr_pkt *pkt; + void *p; + + payload_size = sizeof(*cfg) + APM_MODULE_PARAM_DATA_SIZE; + p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0); + if (IS_ERR(p)) + return -ENOMEM; + + pkt = p; + p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + param_data = p; + param_data->module_instance_id = module->instance_id; + param_data->error_code = 0; + param_data->param_id = PARAM_ID_VOL_CTRL_MASTER_GAIN; + param_data->param_size = payload_size - APM_MODULE_PARAM_DATA_SIZE; + + p = p + APM_MODULE_PARAM_DATA_SIZE; + cfg = p; + cfg->master_gain = vol; + rc = q6apm_send_cmd_sync(apm, pkt, 0); + + kfree(pkt); + + return rc; +} +EXPORT_SYMBOL_GPL(audioreach_gain_set_vol_ctrl); + static int audioreach_gain_set(struct q6apm_graph *graph, struct audioreach_module *module) { diff --git a/sound/soc/qcom/audioreach/audioreach.h b/sound/soc/qcom/audioreach/audioreach.h index 6279ddc3c5ce..2c6d5f4e66b4 100644 --- a/sound/soc/qcom/audioreach/audioreach.h +++ b/sound/soc/qcom/audioreach/audioreach.h @@ -536,6 +536,14 @@ struct param_id_hw_ep_dma_data_align { uint32_t dma_data_align; } __packed; +#define PARAM_ID_VOL_CTRL_MASTER_GAIN 0x08001035 +#define VOL_CTRL_DEFAULT_GAIN 0x2000 +struct param_id_vol_ctrl_master_gain { + uint16_t master_gain; + uint16_t reserved; +} __packed; + + /* Graph */ struct audioreach_connection { /* Connections */ From patchwork Wed Jul 14 15:30:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476809 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676678jao; Wed, 14 Jul 2021 08:31:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwowKPm3H72Rh25aQyhut4EmfE1BIm0+adi4bFmHnH5kad0Iy9RvrEeOGKWZMGoRmzJqOKi X-Received: by 2002:a05:6e02:550:: with SMTP id i16mr7039359ils.207.1626276683074; Wed, 14 Jul 2021 08:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276683; cv=none; d=google.com; s=arc-20160816; b=B915H9dmdAoVGt+O1jpBLamKrcJG0GKkabJlVjmeS91jnl0vGUZT+AsdmjYkgXv00a MCMZLlnBmkv15QjF/7tkgSukhjROrYJSjgX6ZWTUjwIQHUNXSuvVM1AJot1vEnbceTEz IGOQF+U2gyQIH3H754nRmRvhPo/Z+VwfsZZ6B/81TalgpF4XagzZPGA7kVdeVNvt2fvC sEhcpQXd7hpEnbu8Y9J+XHQS4lkxH4gOTkmrVjEaB14pIw2RuGLbQ0ViaQPjzHNxrIaE lrg1fnvJN2lT60Z7690gl42hFA4zjCCI2CGcKMs6ePpRAUAG19ERxpGA+W12S7+ApwqR uQQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/OyLLqXUZS1RpS+YuJ/yD57hTXnorkIuGBmzsYS7+c4=; b=O4BJ8aOCwBMSuiBMwleOwxvRfSFOyQsWiYbTHUYwbYNzjH37EIMF3AoPh6kF5Aj3tj KZq2B6G3Ra2aKilgNcTlVjqxJtfq0w7sHJR22WawJSYtCeseGNBqM3aTd9zvjSb4MEle HpM/yoKxPFfv12MCZbaYnnMO7vpD6Jak60MceYZs6ZJOq07arZl5bxDczM+WO+d4RbwR yAbaevihnmr3yJN8UPjc1IAHxmLb+7Clf7/8NJzYUqaKgs9Gc+/WQiPhmefEwYhnQJ8l 3JdwJrcYXuaaIoA0ycStiwPuoueWpbZdnhgbKz7sEMBzZknS2/Ngaa0jJMAfSiHQIJo9 cXww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I9awJWJ0; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si2936383jao.12.2021.07.14.08.31.22; Wed, 14 Jul 2021 08:31:23 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I9awJWJ0; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239853AbhGNPeM (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239811AbhGNPeK (ORCPT ); Wed, 14 Jul 2021 11:34:10 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE62C061762 for ; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id b14-20020a1c1b0e0000b02901fc3a62af78so4172306wmb.3 for ; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=/OyLLqXUZS1RpS+YuJ/yD57hTXnorkIuGBmzsYS7+c4=; b=I9awJWJ0TeowLx8ez7hQQZ/8uuMucKaiP0yybxoMUtTzmz+q9AuGACZsNk4a1dv1vn 3zsplkFV6BR0AaOQKcx+YX73pjEwcEboTLS2zlV1drc9hjq15nfUlPo8y60oKguSMZn1 ffeEPFk0EekBEpfBL0jXzkhgvuXrXN30/ZXkeu1LZry0im3i3gOGtxFC4dcUttgzwq9j 5cWwAbbiXdgSbwUrZNLpef0zckbyjC77iqz2aLQG62TWbEyPNlqVIEQtzPs/vELhVeDa 8ebT5xlk91pGSlnmm0z81JflnM7bgGD/Vl9kB8gnaKpmsyw92587tFyKWXyCLVVY+hyp rGNg== 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:mime-version:content-transfer-encoding; bh=/OyLLqXUZS1RpS+YuJ/yD57hTXnorkIuGBmzsYS7+c4=; b=PA0GqC6guOn3vMKSoQw93+CK1ik1VShkAEUoSuFVIaSDN5BvaWFzfOx21CyhUgP5vT rSEzcW6A3M3MJPDVetz2kKnPG9/Os7hKWHl6hGJZqLFvwAqHAIWFwiGWk++j7k80Etm1 9NA43cAYJ8U1gYUiIPGhWa8B3J44MshBXHAn4w0Yf6iTFnwF/uDRkOTg4dAtHnqmlqKI ztFR0ONRIDT3lKWXIBW/LnL4PG0XhfUojEPjFWnDibRj/zGMPkG1+aYszQh5uQifsb8a 60cUEEBQja3auaEWdbOtD+H/FN9M0lKAHgOGj7d9fQ2gN9X/vqRKoUyIWNlTjRFx2wBk C8SQ== X-Gm-Message-State: AOAM533Dw/ZIrWfVl4u1PDalWMM5cEnUZnSYEPsB6eBzfvDn+H1nHqor 0RH+AAUXt05V8HZi0jHksgWR9w== X-Received: by 2002:a1c:9dd6:: with SMTP id g205mr12006785wme.82.1626276677494; Wed, 14 Jul 2021 08:31:17 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:16 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 15/16] ASoC: qcom: audioreach: topology add dapm pga support Date: Wed, 14 Jul 2021 16:30:38 +0100 Message-Id: <20210714153039.28373-16-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/audioreach/topology.c | 62 +++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/sound/soc/qcom/audioreach/topology.c b/sound/soc/qcom/audioreach/topology.c index 8080243a47ef..14ecb115e63e 100644 --- a/sound/soc/qcom/audioreach/topology.c +++ b/sound/soc/qcom/audioreach/topology.c @@ -706,6 +706,25 @@ static int audioreach_widget_load_mixer(struct snd_soc_component *component, return 0; } +static int audioreach_widget_load_pga(struct snd_soc_component *component, + int index, struct snd_soc_dapm_widget *w, + struct snd_soc_tplg_dapm_widget *tplg_w) +{ + struct audioreach_module *mod; + struct snd_soc_dobj *dobj; + int ret; + + ret = audioreach_widget_load_module_common(component, index, w, tplg_w); + if (ret) + return ret; + + dobj = &w->dobj; + mod = dobj->private; + mod->gain = VOL_CTRL_DEFAULT_GAIN; + + return 0; +} + static int audioreach_widget_ready(struct snd_soc_component *component, int index, struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w) @@ -725,8 +744,9 @@ static int audioreach_widget_ready(struct snd_soc_component *component, break; case snd_soc_dapm_mixer: return audioreach_widget_load_mixer(component, index, w, tplg_w); - case snd_soc_dapm_dai_link: case snd_soc_dapm_pga: + return audioreach_widget_load_pga(component, index, w, tplg_w); + case snd_soc_dapm_dai_link: case snd_soc_dapm_scheduler: case snd_soc_dapm_out_drv: default: @@ -898,6 +918,40 @@ static int audioreach_put_audio_mixer(struct snd_kcontrol *kcontrol, return 0; } +static int audioreach_get_vol_ctrl_audio_mixer(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_widget *dw = snd_soc_dapm_kcontrol_widget(kcontrol); + struct audioreach_module *mod = dw->dobj.private; + + /* Check if the graph is active or not */ + ucontrol->value.integer.value[0] = mod->gain; + + return 0; +} + +static int audioreach_put_vol_ctrl_audio_mixer(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_widget *dw = snd_soc_dapm_kcontrol_widget(kcontrol); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_component *c = snd_soc_dapm_to_component(dapm); + struct audioreach_module *mod = dw->dobj.private; + struct q6apm *apm = dev_get_drvdata(c->dev); + int vol = ucontrol->value.integer.value[0]; + + /* Check if the graph is active or not */ + if (dw->power) { + audioreach_gain_set_vol_ctrl(apm, mod, vol); + mod->gain = vol; + return 1; + } + + dev_err(apm->dev, "Unable to set volume as graph is not active\n"); + return 0; + +} + static int audioreach_control_load_mix(struct snd_soc_component *scomp, struct snd_ar_control *scontrol, struct snd_kcontrol_new *kc, @@ -948,6 +1002,10 @@ static int audioreach_control_load(struct snd_soc_component *scomp, int index, dobj = &sm->dobj; ret = audioreach_control_load_mix(scomp, scontrol, kc, hdr); break; + case SND_SOC_AR_TPLG_VOL_CTL: + sm = (struct soc_mixer_control *)kc->private_value; + dobj = &sm->dobj; + break; default: dev_warn(scomp->dev, "control type not supported %d:%d:%d\n", hdr->ops.get, hdr->ops.put, hdr->ops.info); @@ -972,6 +1030,8 @@ static int audioreach_control_unload(struct snd_soc_component *scomp, static const struct snd_soc_tplg_kcontrol_ops audioreach_io_ops[] = { {SND_SOC_AR_TPLG_FE_BE_GRAPH_CTL_MIX, audioreach_get_audio_mixer, audioreach_put_audio_mixer, snd_soc_info_volsw}, + {SND_SOC_AR_TPLG_VOL_CTL, audioreach_get_vol_ctrl_audio_mixer, + audioreach_put_vol_ctrl_audio_mixer, snd_soc_info_volsw}, }; static struct snd_soc_tplg_ops audioreach_tplg_ops = { From patchwork Wed Jul 14 15:30:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 476812 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp676829jao; Wed, 14 Jul 2021 08:31:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytqIuTV+b2cVwSIUIiHCpUE6BrWlS5MdjZ0ubtujatmV2eNWV/UcxNhWtrZ8irGqLoCa+e X-Received: by 2002:a6b:490d:: with SMTP id u13mr7742790iob.176.1626276691925; Wed, 14 Jul 2021 08:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626276691; cv=none; d=google.com; s=arc-20160816; b=YDBqTo6mVOSPb6EPjus15rbtjE9iA0eCuYzw6lIRKYXM9YuEDigGScThyDPYFpJ1hk JbHme8+WNIbyOEnZYF3ow48Gqh9VBpiF1Cvmuv/qaEshGiyvKbDZiW2LJCCSndbV5ouc lMGaSI54cuPtPymyuW4j8NnzvuPkTBCG+Ck1+zvTsyM77BbTurxgdySMRSuVyDw80ykd 3Y+IyA2wlw6lETvhQRJ0KmYqPrHRBi2YDwbQzmQEdWQmD55cj2OlyinvUWtGIlaBc3qR aVLALMPl6GayAJQwbLO5DO7K+uwI1s4f0xTe3LmDu4dBqtPEvUIoGQ9SH4auyoL7mY/j ihrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZEdZ+N0eteL07jx0I8YEw4d+MAwVooRKuXAZfHn0G4c=; b=JjSW05qm6O5xE5Py5hCA75p3TPNuoEEMFPJ+0g0/cjLoiYF4Lpkj2x5jHpz1ArRqYg mbxy2zS82tXdjCfSlk/iasU4MLmykcpL+2SU7TJ0p1/6aDZH+C4iu7rfG0NqMA/p4Zav uibcL9Jd2UgL2nr+5+5BQtIBOwrPy4JtrAlvPaqnK1m0ykVLnWHQgCvLBECW4izvFwNT kfGbACGLHpjSLQeKU4DbriP0pR1/JTGkDo2tYxF9pHQG6vl2JJ7i/r0QUrey2TR+weuG Rfq019utjR7E2Isqq31JgRn+Ju9zZpUAyUdHJ3LQgMNayebpkI2KajlkkbSLMeE/fKSZ ADsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o8OW1Ijb; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si2951797jaj.31.2021.07.14.08.31.31; Wed, 14 Jul 2021 08:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o8OW1Ijb; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239763AbhGNPeQ (ORCPT + 7 others); Wed, 14 Jul 2021 11:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239806AbhGNPeM (ORCPT ); Wed, 14 Jul 2021 11:34:12 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24ED8C061766 for ; Wed, 14 Jul 2021 08:31:20 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id f190so282941wmf.4 for ; Wed, 14 Jul 2021 08:31:20 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=ZEdZ+N0eteL07jx0I8YEw4d+MAwVooRKuXAZfHn0G4c=; b=o8OW1IjbQQi6PtfzBXMIEY4tiI0ap0Kt2MGwbR8boavQl52oeAP5UXZvaeWqaouKmD LtIfYmHledzcF5ZIZJfec+Vp4q4/jCUxWDg13hEcjltXz4oIVTEwxostfSpqfCtJeDDT TS2CJaTjHqIr3mNnNiVQeRBpIGQAsSGkTqhZ+mo5e8m2rXsF0ADLSLDr/zRWpESZlFaA AFcPtm/LzZMs4mc9MAnnR4HE5olfQ0m4oJhIi1OZdnd3DCnqCNhxt6NPYEA3dgCzNsJg 3U82hCMZf6la8KXXJbcnUj9agzFhAVQutht5hmY3aXOaj/IcMpiSyo8MomJryKTMWbLe kRMA== 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:mime-version:content-transfer-encoding; bh=ZEdZ+N0eteL07jx0I8YEw4d+MAwVooRKuXAZfHn0G4c=; b=YEQcARe7uFnlGkgXZMYdFxPM627xL5jXM6yuFOTtwZ6eswX7tkXj1F5fNRoV0csbj5 3SoLi4yRS5364dRJg+ypKdZOQs6M9mar91tPqpGPNm4HwBuFQYedz4dAiREJ8c/15klb v+VWznqxODlVoTPpC4OgA7CgKMcCK8xs7ig1glpr1KzJ94GqKIagG700K46eKsrf+WtV tIcQ/1ZRhfotzbxuBhLDKGu8T6APhKTviQNm2xgN9Rqid0i0NUFcqAJ7mwsJoB8lgLm0 7uyoLHEqE8fVTjnF9Cuz8f7stlozHPpHJhnoqFBCcVd5cFuBOUjpfcoKE+ngpDbwbK2c L2/g== X-Gm-Message-State: AOAM531jkYgeJ/ODgQi7MM2EnU5RskZPuuOdF3Zjh8YqVoL1Xvru/62z PwOJrJYFfiLgEwTahGbtfTHl32RTHpddiA== X-Received: by 2002:a05:600c:3b93:: with SMTP id n19mr4772987wms.3.1626276678690; Wed, 14 Jul 2021 08:31:18 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id y6sm2465174wma.48.2021.07.14.08.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 08:31:18 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v2 16/16] ASoC: qcom: sm8250: Add audioreach support Date: Wed, 14 Jul 2021 16:30:39 +0100 Message-Id: <20210714153039.28373-17-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> References: <20210714153039.28373-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds support for parsing dt for AudioReach based soundcards which only have backend DAI links in DT. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/sm8250.c | 144 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index fe8fd7367e21..421f9d1d2bed 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -20,6 +20,141 @@ struct sm8250_snd_data { struct sdw_stream_runtime *sruntime[AFE_PORT_MAX]; }; +static int qcom_audioreach_snd_parse_of(struct snd_soc_card *card) +{ + struct device_node *np; + struct device_node *codec = NULL; + struct device_node *platform = NULL; + struct device_node *cpu = NULL; + struct device *dev = card->dev; + struct snd_soc_dai_link *link; + struct of_phandle_args args; + struct snd_soc_dai_link_component *dlc; + int ret, num_links; + + ret = snd_soc_of_parse_card_name(card, "model"); + if (ret) { + dev_err(dev, "Error parsing card name: %d\n", ret); + return ret; + } + + /* DAPM routes */ + if (of_property_read_bool(dev->of_node, "audio-routing")) { + ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); + if (ret) + return ret; + } + + /* Populate links */ + num_links = of_get_child_count(dev->of_node); + + /* Allocate the DAI link array */ + card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL); + if (!card->dai_link) + return -ENOMEM; + + card->num_links = num_links; + link = card->dai_link; + + for_each_child_of_node(dev->of_node, np) { + + dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL); + if (!dlc) { + ret = -ENOMEM; + goto err_put_np; + } + + link->cpus = &dlc[0]; + link->platforms = &dlc[1]; + + link->num_cpus = 1; + link->num_platforms = 1; + + + ret = of_property_read_string(np, "link-name", &link->name); + if (ret) { + dev_err(card->dev, "error getting codec dai_link name\n"); + goto err_put_np; + } + + cpu = of_get_child_by_name(np, "cpu"); + platform = of_get_child_by_name(np, "platform"); + codec = of_get_child_by_name(np, "codec"); + if (!cpu) { + dev_err(dev, "%s: Can't find cpu DT node\n", link->name); + ret = -EINVAL; + goto err; + } + + if (!platform) { + dev_err(dev, "%s: Can't find platform DT node\n", link->name); + ret = -EINVAL; + goto err; + } + + if (!codec) { + dev_err(dev, "%s: Can't find codec DT node\n", link->name); + ret = -EINVAL; + goto err; + } + + ret = of_parse_phandle_with_args(cpu, "sound-dai", "#sound-dai-cells", 0, &args); + if (ret) { + dev_err(card->dev, "%s: error getting cpu phandle\n", link->name); + goto err; + } + + link->cpus->of_node = args.np; + link->id = args.args[0]; + + ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name); + if (ret) { + if (ret != -EPROBE_DEFER) + dev_err(card->dev, "%s: error getting cpu dai name: %d\n", + link->name, ret); + goto err; + } + + link->platforms->of_node = of_parse_phandle(platform, "sound-dai", 0); + if (!link->platforms->of_node) { + dev_err(card->dev, "%s: platform dai not found\n", link->name); + ret = -EINVAL; + goto err; + } + + ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); + if (ret < 0) { + if (ret != -EPROBE_DEFER) + dev_err(card->dev, "%s: codec dai not found: %d\n", + link->name, ret); + goto err; + } + + /* DPCM backend */ + link->no_pcm = 1; + link->ignore_pmdown_time = 1; + link->ignore_suspend = 1; + + link->stream_name = link->name; + snd_soc_dai_link_set_capabilities(link); + link++; + + of_node_put(cpu); + of_node_put(codec); + of_node_put(platform); + + } + + return 0; +err: + of_node_put(cpu); + of_node_put(codec); + of_node_put(platform); +err_put_np: + of_node_put(np); + return ret; +} + static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { @@ -199,7 +334,12 @@ static int sm8250_platform_probe(struct platform_device *pdev) card->dev = dev; dev_set_drvdata(dev, card); snd_soc_card_set_drvdata(card, data); - ret = qcom_snd_parse_of(card); + if (of_device_is_compatible(dev->of_node, "qcom,sm8250-audioreach-sndcard") || + of_device_is_compatible(dev->of_node, "qcom,qrb5165-rb5-audioreach-sndcard")) + ret = qcom_audioreach_snd_parse_of(card); + else + ret = qcom_snd_parse_of(card); + if (ret) return ret; @@ -211,6 +351,8 @@ static int sm8250_platform_probe(struct platform_device *pdev) static const struct of_device_id snd_sm8250_dt_match[] = { {.compatible = "qcom,sm8250-sndcard"}, {.compatible = "qcom,qrb5165-rb5-sndcard"}, + {.compatible = "qcom,sm8250-audioreach-sndcard" }, + {.compatible = "qcom,qrb5165-rb5-audioreach-sndcard" }, {} };