linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: rohitkr@codeaurora.org (Rohit Kumar)
To: linux-arm-kernel@lists.infradead.org
Subject: [alsa-devel] [PATCH v3 14/25] ASoC: qcom: qdsp6: Add support to q6afe dai driver
Date: Mon, 19 Feb 2018 16:02:24 +0530	[thread overview]
Message-ID: <84723548-02a4-10e7-3de1-b347416d4fb0@codeaurora.org> (raw)
In-Reply-To: <20180213165837.1620-15-srinivas.kandagatla@linaro.org>



On 2/13/2018 10:28 PM, srinivas.kandagatla at linaro.org wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>
> This patch adds support to q6afe backend dais driver.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
>   sound/soc/qcom/qdsp6/Makefile    |   2 +-
>   sound/soc/qcom/qdsp6/q6afe-dai.c | 280 +++++++++++++++++++++++++++++++++++++++
>   sound/soc/qcom/qdsp6/q6afe.h     |   3 +
>   3 files changed, 284 insertions(+), 1 deletion(-)
>   create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c
>
> diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
> index 660afcab98fd..c7833842b878 100644
> --- a/sound/soc/qcom/qdsp6/Makefile
> +++ b/sound/soc/qcom/qdsp6/Makefile
> @@ -1,5 +1,5 @@
>   obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
> -obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
> +obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o q6afe-dai.o
depmod: ERROR: Cycle detected: q6afe -> q6afe_dai -> q6afe
need to use like:
+qdsp6_afe-objs := q6afe.o q6afe-dai.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += qdsp6_afe.o
similarly for asm and adm
>   obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o q6routing.o
>   obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
>   obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.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..f6a618e9db9e
> --- /dev/null
> +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
> @@ -0,0 +1,280 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2011-2016, The Linux Foundation
> + * Copyright (c) 2018, Linaro Limited
> + */
> +
> +#include <linux/err.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/device.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <sound/pcm.h>
> +#include <sound/soc.h>
> +#include <sound/pcm_params.h>
> +#include "q6afe.h"
> +
> +struct q6afe_dai_data {
> +	struct q6afe_port *port[AFE_PORT_MAX];
> +	struct q6afe_port_config port_config[AFE_PORT_MAX];
> +	bool is_port_started[AFE_PORT_MAX];
> +};
> +
> +static int q6hdmi_format_put(struct snd_kcontrol *kcontrol,
> +				struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct q6afe_dai_data *dai_data = kcontrol->private_data;
> +	int value = ucontrol->value.integer.value[0];
> +
> +	dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.datatype = value;
> +
> +	return 0;
> +}
> +
> +static int q6hdmi_format_get(struct snd_kcontrol *kcontrol,
> +				struct snd_ctl_elem_value *ucontrol)
> +{
> +
> +	struct q6afe_dai_data *dai_data = kcontrol->private_data;
> +
> +	ucontrol->value.integer.value[0] =
> +		dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.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 q6afe_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 q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +	int channels = params_channels(params);
> +	struct q6afe_hdmi_cfg *hdmi = &dai_data->port_config[dai->id].hdmi;
> +
> +	hdmi->sample_rate = params_rate(params);
> +	switch (params_format(params)) {
> +	case SNDRV_PCM_FORMAT_S16_LE:
> +		hdmi->bit_width = 16;
> +		break;
> +	case SNDRV_PCM_FORMAT_S24_LE:
> +		hdmi->bit_width = 24;
> +		break;
> +	}
> +
> +	/*refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4*/
> +	switch (channels) {
> +	case 2:
> +		hdmi->channel_allocation = 0;
> +		break;
> +	case 3:
> +		hdmi->channel_allocation = 0x02;
> +		break;
> +	case 4:
> +		hdmi->channel_allocation = 0x06;
> +		break;
> +	case 5:
> +		hdmi->channel_allocation = 0x0A;
> +		break;
> +	case 6:
> +		hdmi->channel_allocation = 0x0B;
> +		break;
> +	case 7:
> +		hdmi->channel_allocation = 0x12;
> +		break;
> +	case 8:
> +		hdmi->channel_allocation = 0x13;
> +		break;
> +	default:
> +		dev_err(dai->dev, "invalid Channels = %u\n", channels);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int q6afe_dai_startup(struct snd_pcm_substream *substream,
> +				struct snd_soc_dai *dai)
> +{
> +	struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +
> +	dai_data->is_port_started[dai->id] = false;
> +
> +	return 0;
> +}
> +
> +static void q6afe_dai_shutdown(struct snd_pcm_substream *substream,
> +				struct snd_soc_dai *dai)
> +{
> +	struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +	int rc;
> +
> +	rc = q6afe_port_stop(dai_data->port[dai->id]);
> +	if (rc < 0)
> +		dev_err(dai->dev, "fail to close AFE port\n");
> +
> +	dai_data->is_port_started[dai->id] = false;
> +
> +}
> +
> +static int q6afe_dai_prepare(struct snd_pcm_substream *substream,
> +		struct snd_soc_dai *dai)
> +{
> +	struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +	int rc;
> +
> +	if (dai_data->is_port_started[dai->id]) {
> +		/* stop the port and restart with new port config */
> +		rc = q6afe_port_stop(dai_data->port[dai->id]);
> +		if (rc < 0) {
> +			dev_err(dai->dev, "fail to close AFE port\n");
> +			return rc;
> +		}
> +	}
> +
> +	if (dai->id == AFE_PORT_HDMI_RX)
> +		q6afe_hdmi_port_prepare(dai_data->port[dai->id],
> +					&dai_data->port_config[dai->id].hdmi);
> +
> +	rc = q6afe_port_start(dai_data->port[dai->id]);
> +	if (rc < 0) {
> +		dev_err(dai->dev, "fail to start AFE port %x\n", dai->id);
> +		return rc;
> +	}
> +	dai_data->is_port_started[dai->id] = true;
> +
> +	return 0;
> +}
> +
> +static const struct snd_soc_dapm_route q6afe_dapm_routes[] = {
> +	{"HDMI Playback", NULL, "HDMI_RX"},
> +};
> +
> +static struct snd_soc_dai_ops q6hdmi_ops = {
> +	.prepare	= q6afe_dai_prepare,
> +	.hw_params	= q6hdmi_hw_params,
> +	.shutdown	= q6afe_dai_shutdown,
> +	.startup	= q6afe_dai_startup,
> +};
> +
> +static int msm_dai_q6_dai_probe(struct snd_soc_dai *dai)
> +{
> +	struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +	struct snd_soc_dapm_context *dapm;
> +	struct q6afe_port *port;
> +
> +	dapm = snd_soc_component_get_dapm(dai->component);
> +
> +	port = q6afe_port_get_from_id(dai->dev, dai->id);
> +	if (IS_ERR(port)) {
> +		dev_err(dai->dev, "Unable to get afe port\n");
> +		return -EINVAL;
> +	}
> +	dai_data->port[dai->id] = port;
> +
> +	return 0;
> +}
> +
> +static int msm_dai_q6_dai_remove(struct snd_soc_dai *dai)
> +{
> +	struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
> +
> +	q6afe_port_put(dai_data->port[dai->id]);
> +
> +	return 0;
> +}
> +
> +static struct snd_soc_dai_driver q6afe_dais[] = {
> +	{
> +		.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",
> +		.probe = msm_dai_q6_dai_probe,
> +		.remove = msm_dai_q6_dai_remove,
> +	},
> +};
> +
> +static int q6afe_of_xlate_dai_name(struct snd_soc_component *component,
> +				   struct of_phandle_args *args,
> +				   const char **dai_name)
> +{
> +	int id = args->args[0];
> +	int i, ret = -EINVAL;
> +
> +	for (i = 0; i  < ARRAY_SIZE(q6afe_dais); i++) {
> +		if (q6afe_dais[i].id == id) {
> +			*dai_name = q6afe_dais[i].name;
> +			ret = 0;
> +			break;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
> +static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = {
> +	SND_SOC_DAPM_AIF_OUT("HDMI_RX", "HDMI Playback", 0, 0, 0, 0),
> +};
> +
> +static const struct snd_soc_component_driver q6afe_dai_component = {
> +	.name		= "q6afe-dai-component",
> +	.dapm_widgets = q6afe_dai_widgets,
> +	.num_dapm_widgets = ARRAY_SIZE(q6afe_dai_widgets),
> +	.controls = q6afe_config_controls,
> +	.num_controls = ARRAY_SIZE(q6afe_config_controls),
> +	.dapm_routes = q6afe_dapm_routes,
> +	.num_dapm_routes = ARRAY_SIZE(q6afe_dapm_routes),
> +	.of_xlate_dai_name = q6afe_of_xlate_dai_name,
> +
> +};
> +
> +int q6afe_dai_dev_probe(struct device *dev)
> +{
> +	int rc = 0;
> +	struct q6afe_dai_data *dai_data;
> +
> +	dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL);
> +	if (!dai_data)
> +		rc = -ENOMEM;
> +
> +	q6afe_set_dai_data(dev, dai_data);
> +
> +	return  devm_snd_soc_register_component(dev, &q6afe_dai_component,
> +					  q6afe_dais, ARRAY_SIZE(q6afe_dais));
> +}
> +EXPORT_SYMBOL_GPL(q6afe_dai_dev_probe);
> +
> +int q6afe_dai_dev_remove(struct device *dev)
> +{
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(q6afe_dai_dev_remove);
> +MODULE_DESCRIPTION("Q6 Audio Fronend dai driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/sound/soc/qcom/qdsp6/q6afe.h b/sound/soc/qcom/qdsp6/q6afe.h
> index 43df524f01bb..647ed2d15545 100644
> --- a/sound/soc/qcom/qdsp6/q6afe.h
> +++ b/sound/soc/qcom/qdsp6/q6afe.h
> @@ -26,6 +26,9 @@ struct q6afe_port;
>   void q6afe_set_dai_data(struct device *dev, void *data);
>   void *q6afe_get_dai_data(struct device *dev);
>   
> +int q6afe_dai_dev_probe(struct device *dev);
> +int q6afe_dai_dev_remove(struct device *dev);
> +
>   struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id);
>   int q6afe_port_start(struct q6afe_port *port);
>   int q6afe_port_stop(struct q6afe_port *port);

  reply	other threads:[~2018-02-19 10:32 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 16:58 [PATCH v3 00/25] ASoC: qcom: Add support to QDSP based Audio srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 01/25] dt-bindings: soc: qcom: Add bindings for APR bus srinivas.kandagatla at linaro.org
2018-02-13 23:12   ` Rob Herring
2018-02-14  9:13     ` Srinivas Kandagatla
2018-02-18 23:04       ` Rob Herring
2018-02-20  9:33         ` Srinivas Kandagatla
2018-02-22  0:14           ` Rob Herring
2018-02-22 10:03             ` Srinivas Kandagatla
2018-02-28 18:55               ` Srinivas Kandagatla
2018-03-01 20:34               ` Mark Brown
2018-03-02 13:13                 ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 02/25] soc: qcom: add support to APR bus driver srinivas.kandagatla at linaro.org
2018-02-19  3:08   ` Rob Herring
2018-02-20  9:33     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 03/25] ASoC: qcom: qdsp6: Add common qdsp6 helper functions srinivas.kandagatla at linaro.org
2018-03-01 21:04   ` Mark Brown
2018-02-13 16:58 ` [PATCH v3 04/25] dt-bindings: sound: qcom: Add bindings for q6afe srinivas.kandagatla at linaro.org
2018-03-01 20:41   ` Mark Brown
2018-02-13 16:58 ` [PATCH v3 05/25] ASoC: qcom: qdsp6: Add support to Q6AFE srinivas.kandagatla at linaro.org
2018-02-19 10:30   ` [alsa-devel] " Rohit Kumar
2018-02-20  9:34     ` Srinivas Kandagatla
2018-03-01 20:42     ` Mark Brown
2018-03-01 20:59   ` Mark Brown
2018-03-02 13:13     ` Srinivas Kandagatla
2018-03-02 17:54       ` Mark Brown
2018-03-02 18:51         ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 06/25] dt-bindings: sound: qcom: Add bindings for q6adm srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 07/25] ASoC: qcom: qdsp6: Add support to Q6ADM srinivas.kandagatla at linaro.org
2018-03-01 21:24   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 08/25] dt-bindings: sound: qcom: Add bindings for q6asm srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 09/25] ASoC: qcom: qdsp6: Add support to Q6ASM srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 10/25] ASoC: qcom: q6asm: Add support to memory map and unmap srinivas.kandagatla at linaro.org
2018-03-01 21:28   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 11/25] ASoC: qcom: q6asm: add support to audio stream apis srinivas.kandagatla at linaro.org
2018-03-01 21:33   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE srinivas.kandagatla at linaro.org
2018-02-19 10:33   ` [alsa-devel] " Rohit Kumar
2018-02-13 16:58 ` [PATCH v3 13/25] ASoC: qcom: qdsp6: Add support to q6routing driver srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 14/25] ASoC: qcom: qdsp6: Add support to q6afe dai driver srinivas.kandagatla at linaro.org
2018-02-19 10:32   ` Rohit Kumar [this message]
2018-02-20  9:36     ` [alsa-devel] " Srinivas Kandagatla
     [not found]   ` <20180302125054.GH6255@sirena.org.uk>
2018-03-02 13:52     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 15/25] ASoC: qcom: qdsp6: Add support to q6asm " srinivas.kandagatla at linaro.org
2018-02-21 11:14   ` [alsa-devel] " Rohit Kumar
2018-02-22 11:16     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 16/25] ASoC: qcom: q6afe: add SLIMBus port Support srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 17/25] ASoC: qcom: q6afe-dai: add support to slim afe dais srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 18/25] ASoC: qcom: q6routing: add support to all SLIMBus Mixers srinivas.kandagatla at linaro.org
2018-05-21 15:47   ` Applied "ASoC: qdsp6: q6routing: Add support to all SLIMBus Mixers" to the asoc tree Mark Brown
2018-02-13 16:58 ` [PATCH v3 19/25] ASoC: qcom: q6afe: add support to MI2S ports srinivas.kandagatla at linaro.org
2018-03-07  9:35   ` [alsa-devel] " Rohit Kumar
2018-02-13 16:58 ` [PATCH v3 20/25] ASoC: qcom: q6afe: add support to MI2S sysclks srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 21/25] ASoC: qcom: q6afe-dai: add support to 4 MI2S ports srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 22/25] ASoC: qcom: q6routing: add support to MI2S Mixers srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 23/25] dt-bindings: sound: qcom: Add devicetree bindings for apq8096 srinivas.kandagatla at linaro.org
2018-02-13 16:58 ` [PATCH v3 24/25] ASoC: qcom: apq8096: Add db820c machine driver srinivas.kandagatla at linaro.org
2018-02-22 11:00   ` [alsa-devel] " Rohit Kumar
2018-02-22 11:13     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 25/25] arm64: dts: msm8996: db820c: Add sound card support srinivas.kandagatla at linaro.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84723548-02a4-10e7-3de1-b347416d4fb0@codeaurora.org \
    --to=rohitkr@codeaurora.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).