From patchwork Tue Dec 5 22:18:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120767 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6313448qgn; Tue, 5 Dec 2017 14:23:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMajT+9OOH73oY2lH0pEx3/5ZBT+tWQwhmOtDC94kQ/41kxPl4eJ17RBxGE/LAlRIfzUEYOo X-Received: by 10.84.215.146 with SMTP id l18mr19703636pli.451.1512512586051; Tue, 05 Dec 2017 14:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512512586; cv=none; d=google.com; s=arc-20160816; b=d+rtbEElkdsInapeP07wXxcHjyxPdpRg1wsVg3faRXUVB/eMVH39d8hNbcvghRNrmw GnxG1BIOoAQl2Po6+tF2nRhKZEcpKCyWUJ+XEy/QLbI/LGUUWaJtAkOsnAB4KY6fSODm A7Tbiag6RqMyGLu9rD9YcRajwb0Rv5odB0HiL+QjFb/pu7h5bCruxkFTlZRsaNr6xlvk 2wUrcQxNEYck8pzs9/i2pfgwW/sJx/aApjZeBu+4lKgV/jfXQRAfsvEImrcPTjJXCqLc y86ohfs4nyDDi/ToYrPpLwtmM72U/jAZjdE1LPZ1XMP0Fm83IWiBS0Fg1tSwdsPK8Rxo DkXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4U6sPacbpCKTZG/bErM8IDVbkcvYgiQnLu3UgSEgOfY=; b=WzLKrr46LLCWXb6/FIJEKbrvKnA70TWlWhm51AJ9kOBEQFjc0tYtXv2JMpk3OK7V5K rbxKc4GkRXNExLhUEZ4NoqSV+NruIQKjw4SZwlQ7YjHw9usJrCvlBLrWaK2+wYHCg8x9 1zACbS+5BEzEKFC8MFcz0rX3vxZKVA9o6faQVGSODfc3BVNKwsWar1HGkW4SHgHkE9bT 4zCyLTv5zpo4xYR/ymFuaUoipE4mxX2YycynZKtsytbA4oYOwkDZ+73XOzkSreoo0yyl rBZs2dlj4HPzm2WFV69RR6MiwaAXzLxOXHLqPyRDAmRZqa9cOB+sN+51h/7b+3to4uhO gRgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QcHfQrFl; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u13si723136pgc.615.2017.12.05.14.23.05; Tue, 05 Dec 2017 14:23:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QcHfQrFl; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752668AbdLEWXC (ORCPT + 10 others); Tue, 5 Dec 2017 17:23:02 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39627 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbdLEWUc (ORCPT ); Tue, 5 Dec 2017 17:20:32 -0500 Received: by mail-wm0-f65.google.com with SMTP id i11so3941575wmf.4 for ; Tue, 05 Dec 2017 14:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/6OvCdALqvPvLxUhpXcW0GuutrQiSpZnYZoud1azjzg=; b=QcHfQrFldrN6RsuDNszMYRjwDZ8HEs/8pAmLxXwMy/OvF5Wnd7QUI9DAS/riZcudDL UsgEbAjnlfNVq0SSb93F4FjJdZRu0q4trdLoR1uYlKhTFcSqUUwssvy8hFmRDPG1ryWZ wiV9Jz9fzpmO4qaRwet8qeYjhtDIwiVzEKsJc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/6OvCdALqvPvLxUhpXcW0GuutrQiSpZnYZoud1azjzg=; b=Pckq1oYfLACjShtiaNszmfCq45/XQxNTHmogW7b5Sqx5DEnx/p7SGq4zvkIZ9r7/DI a2PvwHkRWK/d75sDjfJ04/wBFMeErmYKdHEcfzTZkm7HHNrrn/ZLr34fWzpCC6xNJFYV auDfaLku9kh4bBOcZh6TVTaic3uMI/O4VjkTX6WwBPa+bmbY62lLPMiaTckokMUhp5D0 u3bI2Pa4qY4TF0SZQ8rz26tz1xVZ62xG/oW4yxXCwJPthGbTXaIqdIOpSxm1eS9Xyky2 IO5E76E6ZtVS2JVgErjSfaqLBoud5L1KWLYQgMFsK0I4SISEudVIDszqAIrlnaLzDHsZ jkvw== X-Gm-Message-State: AKGB3mKbMc64zD4KYV0C2m2wlIVJWI9nR+UeOM+ZQQpP3zSvEatxrfn5 VkNffGkTvs+Gn2sXN07Y4Rx6jA== X-Received: by 10.28.88.65 with SMTP id m62mr12581419wmb.111.1512512431245; Tue, 05 Dec 2017 14:20:31 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id t138sm1633154wme.16.2017.12.05.14.20.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Dec 2017 14:20:30 -0800 (PST) From: srinivas.kandagatla@linaro.org To: broonie@kernel.org, bgoswami@codeaurora.org Cc: alsa-devel@alsa-project.org, tiwai@suse.com, plai@codeaurora.org, kwestfie@codeaurora.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, lkasam@qti.qualcomm.com, Srinivas Kandagatla Subject: [PATCH v2 11/15] ASoC: qcom: qdsp6: Add support to q6afe dai driver Date: Tue, 5 Dec 2017 22:18:08 +0000 Message-Id: <20171205221812.25641-12-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171205221812.25641-1-srinivas.kandagatla@linaro.org> References: <20171205221812.25641-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Srinivas Kandagatla This patch adds support to q6afe backend dais driver. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 5 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6afe-dai.c | 241 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index dd8fb0cde614..003ce182691c 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -64,6 +64,10 @@ config SND_SOC_QDSP6_ROUTING tristate default n +config SND_SOC_QDSP6_AFE_DAI + tristate + default n + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" select SND_SOC_QDSP6_AFE @@ -71,6 +75,7 @@ config SND_SOC_QDSP6 select SND_SOC_QDSP6_ASM select SND_SOC_QDSP6_CORE select SND_SOC_QDSP6_ROUTING + select SND_SOC_QDSP6_AFE_DAI help To add support for MSM QDSP6 Soc Audio. This will enable sound soc platform specific diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index c1ad060a2341..bd8bd02bf09e 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o obj-$(CONFIG_SND_SOC_QDSP6_ROUTING) += q6routing.o +obj-$(CONFIG_SND_SOC_QDSP6_AFE_DAI) += q6afe-dai.o diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c new file mode 100644 index 000000000000..e9865c684bcb --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c @@ -0,0 +1,241 @@ +/* SPDX-License-Identifier: GPL-2.0 +* Copyright (c) 2011-2016, The Linux Foundation +* Copyright (c) 2017, Linaro Limited +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6afe.h" + +struct q6hdmi_dai_data { + struct q6afe_port *port; + struct q6afe_hdmi_cfg port_config; + bool is_port_started; +}; + +static int q6hdmi_format_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct q6hdmi_dai_data *dai_data = kcontrol->private_data; + int value = ucontrol->value.integer.value[0]; + + dai_data->port_config.datatype = value; + + return 0; +} + +static int q6hdmi_format_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + + struct q6hdmi_dai_data *dai_data = kcontrol->private_data; + + ucontrol->value.integer.value[0] = + dai_data->port_config.datatype; + + return 0; +} + +static const char * const hdmi_format[] = { + "LPCM", + "Compr" +}; + +static const struct soc_enum hdmi_config_enum[] = { + SOC_ENUM_SINGLE_EXT(2, hdmi_format), +}; + +static const struct snd_kcontrol_new hdmi_config_controls[] = { + SOC_ENUM_EXT("HDMI RX Format", hdmi_config_enum[0], + q6hdmi_format_get, + q6hdmi_format_put), +}; + +static int q6hdmi_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev); + int channels = params_channels(params); + + dai_data->port_config.sample_rate = params_rate(params); + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + dai_data->port_config.bit_width = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + dai_data->port_config.bit_width = 24; + break; + } + + /*refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4*/ + switch (channels) { + case 2: + dai_data->port_config.channel_allocation = 0; + break; + case 3: + dai_data->port_config.channel_allocation = 0x02; + break; + case 4: + dai_data->port_config.channel_allocation = 0x06; + break; + case 5: + dai_data->port_config.channel_allocation = 0x0A; + break; + case 6: + dai_data->port_config.channel_allocation = 0x0B; + break; + case 7: + dai_data->port_config.channel_allocation = 0x12; + break; + case 8: + dai_data->port_config.channel_allocation = 0x13; + break; + default: + dev_err(dai->dev, "invalid Channels = %u\n", channels); + return -EINVAL; + } + + return 0; +} + +static int q6hdmi_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev); + + dai_data->is_port_started = false; + + return 0; +} + +static void q6hdmi_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev); + int rc; + + rc = q6afe_port_stop(dai_data->port); + if (rc < 0) + dev_err(dai->dev, "fail to close AFE port\n"); + + dai_data->is_port_started = false; + +} + +static int q6hdmi_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev); + int rc; + + if (dai_data->is_port_started) { + /* stop the port and restart with new port config */ + rc = q6afe_port_stop(dai_data->port); + if (rc < 0) { + dev_err(dai->dev, "fail to close AFE port\n"); + return rc; + } + } + + q6afe_hdmi_port_prepare(dai_data->port, &dai_data->port_config); + rc = q6afe_port_start(dai_data->port); + if (rc < 0) { + dev_err(dai->dev, "fail to start AFE port %x\n", dai->id); + return rc; + } + dai_data->is_port_started = true; + + return 0; +} + +static const struct snd_soc_dapm_route hdmi_dapm_routes[] = { + {"HDMI Playback", NULL, "HDMI"}, +}; + +static struct snd_soc_dai_ops q6hdmi_ops = { + .prepare = q6hdmi_prepare, + .hw_params = q6hdmi_hw_params, + .shutdown = q6hdmi_shutdown, + .startup = q6hdmi_startup, +}; + +static struct snd_soc_dai_driver q6afe_dai_hdmi_rx = { + .playback = { + .stream_name = "HDMI Playback", + .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, + .channels_min = 2, + .channels_max = 8, + .rate_max = 192000, + .rate_min = 48000, + }, + .ops = &q6hdmi_ops, + .id = AFE_PORT_HDMI_RX, + .name = "HDMI", +}; + +static const struct snd_soc_dapm_widget hdmi_dapm_widgets[] = { + SND_SOC_DAPM_AIF_OUT("HDMI", "HDMI Playback", 0, 0, 0, 0), + SND_SOC_DAPM_OUTPUT("HDMI-RX"), +}; + +static const struct snd_soc_component_driver msm_dai_hdmi_q6_component = { + .name = "msm-dai-q6-hdmi", + .dapm_widgets = hdmi_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(hdmi_dapm_widgets), + .controls = hdmi_config_controls, + .num_controls = ARRAY_SIZE(hdmi_config_controls), + .dapm_routes = hdmi_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(hdmi_dapm_routes), +}; + +static int q6afe_dai_dev_probe(struct platform_device *pdev) +{ + struct q6hdmi_dai_data *dai_data; + int rc = 0; + struct q6afe_port *port; + + dai_data = devm_kzalloc(&pdev->dev, sizeof(*dai_data), GFP_KERNEL); + if (!dai_data) + rc = -ENOMEM; + + port = q6afe_port_get_from_id(&pdev->dev, AFE_PORT_HDMI_RX); + if (IS_ERR(port)) { + dev_err(&pdev->dev, "Unable to get afe port\n"); + return -EPROBE_DEFER; + } + dai_data->port = port; + dev_set_drvdata(&pdev->dev, dai_data); + + return devm_snd_soc_register_component(&pdev->dev, + &msm_dai_hdmi_q6_component, + &q6afe_dai_hdmi_rx, 1); +} + +static int q6afe_dai_dev_remove(struct platform_device *pdev) +{ + struct q6hdmi_dai_data *dai_data = dev_get_drvdata(&pdev->dev); + + q6afe_port_put(dai_data->port); + + return 0; +} + +static struct platform_driver q6afe_dai_driver = { + .probe = q6afe_dai_dev_probe, + .remove = q6afe_dai_dev_remove, + .driver = { + .name = "q6afe_dai", + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(q6afe_dai_driver);