ASoC: qcom: add sdm845 sound card support
Subsystems (5)
PATCH 1/1 ASoC: qcom: add sdm845 sound card support
This patch adds sdm845 audio machine driver support.
--- .../devicetree/bindings/sound/qcom,sdm845.txt | 87 ++++ sound/soc/qcom/Kconfig | 9 + sound/soc/qcom/Makefile | 2 + sound/soc/qcom/sdm845.c | 539 +++++++++++++++++++++ 4 files changed, 637 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt create mode 100644 sound/soc/qcom/sdm845.c
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +87 -0
@@ -0,0 +1,87 @@ +* Qualcomm Technologies Inc. SDM845 ASoC sound card driver + +This binding describes the SDM845 sound card, which uses qdsp for audio. + +- compatible: + Usage: required + Value type: <stringlist> + Definition: must be "qcom,sdm845-sndcard" + +- qcom,audio-routing: + Usage: Optional + Value type: <stringlist> + Definition: A list of the connections between audio components. + Each entry is a pair of strings, the first being the + connection's sink, the second being the connection's + source. Valid names could be power supplies, MicBias + of codec and the jacks on the board. + +- cdc-vdd-supply: + Usage: Optional + Value type: <phandle> + Definition: phandle of regulator supply required for codec vdd. + += dailinks +Each subnode of sndcard represents either a dailink, and subnodes of each +dailinks would be cpu/codec/platform dais. + +- link-name: + Usage: required + Value type: <string> + Definition: User friendly name for dai link + += CPU, PLATFORM, CODEC dais subnodes +- cpu: + Usage: required + Value type: <subnode> + Definition: cpu dai sub-node + +- codec: + Usage: required + Value type: <subnode> + Definition: codec dai sub-node + +- platform: + Usage: opional + Value type: <subnode> + Definition: platform dai sub-node + +- sound-dai: + Usage: required + Value type: <phandle> + Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node. + +Example: + +audio { + compatible = "qcom,sdm845-sndcard"; + qcom,model = "sdm845-snd-card"; + pinctrl-names = "pri_active", "pri_sleep"; + pinctrl-0 = <&pri_mi2s_active &pri_mi2s_ws_active>; + pinctrl-1 = <&pri_mi2s_sleep &pri_mi2s_ws_sleep>; + + qcom,audio-routing = "PRI_MI2S_RX Audio Mixer", "Pri-mi2s-gpio"; + + cdc-vdd-supply = <&pm8998_l14>; + + fe@1 { + link-name = "MultiMedia1"; + cpu { + sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>; + }; + platform { + sound-dai = <&q6asmdai>; + }; + }; + + be@1 { + link-name = "PRI MI2S Playback"; + cpu { + sound-dai = <&q6afedai PRIMARY_MI2S_RX>; + }; + + platform { + sound-dai = <&q6routing>; + }; + }; +};
sound/soc/qcom/Kconfig +9 -0
@@ -90,3 +90,12 @@ config SND_SOC_MSM8996 Support for Qualcomm Technologies LPASS audio block in APQ8096 SoC-based systems. Say Y if you want to use audio device on this SoCs + +config SND_SOC_SDM845 + tristate "SoC Machine driver for SDM845 boards" + depends on QCOM_APR + select SND_SOC_QDSP6 + help + To add support for audio on Qualcomm Technologies Inc. + SDM845 SoC-based systems. + Say Y if you want to use audio device on this SoCs
sound/soc/qcom/Makefile +2 -0
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o snd-soc-storm-objs := storm.o snd-soc-apq8016-sbc-objs := apq8016_sbc.o snd-soc-apq8096-objs := apq8096.o +snd-soc-sdm845-objs := sdm845.o obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o ++obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o #DSP lib obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
sound/soc/qcom/sdm845.c new file +539 -0
539 lines not on this page · raw message
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
sound/soc/qcom/sdm845.c line 29
Quoted 8 lines · Rohit kumar
sound/soc/qcom/sdm845.c new file +8
-0+struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock;
any reason why the locks can't be part of sdm845_snd_data? Also why do we need two locks ?
sound/soc/qcom/sdm845.c line 31
Quoted 2 lines
sound/soc/qcom/sdm845.c new file +2
-0+static atomic_t pri_mi2s_clk_count; +static atomic_t quat_tdm_clk_count;
Any specific reason for using atomic variables?
sound/soc/qcom/sdm845.c line 44
Quoted 12 lines
sound/soc/qcom/sdm845.c new file +12
-0+static unsigned int tdm_slot_offset[8 ] = {0 ,4 ,8 ,12 ,16 ,20 ,24 ,28 }; + +static int sdm845_tdm_snd_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +int ret =0 ; +int channels, slot_width; + + channels =params_channels (params); +if (channels <1 || channels >8 ) {
I though ch = 0 would be caught by framework and IIRC ASoC doesn't support more than 8 channels
Quoted 4 lines
sound/soc/qcom/sdm845.c new file +4
-0+pr_err ("%s: invalid param channels %d\n" , + __func__, channels); +return -EINVAL ; + }
sound/soc/qcom/sdm845.c line 58
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+ +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S32_LE : +case SNDRV_PCM_FORMAT_S24_LE : +case SNDRV_PCM_FORMAT_S16_LE : + slot_width =32 ; +break ; +default : +pr_err ("%s: invalid param format 0x%x\n" , + __func__,params_format (params));
why not use dev_err, bonus you get device name printer with the logs :)
sound/soc/qcom/sdm845.c line 124
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+static int sdm845_snd_startup (struct snd_pcm_substream *substream) +{ +unsigned int fmt =SND_SOC_DAIFMT_CBS_CFS ; +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + +pr_debug ("%s: dai_id: 0x%x\n" , __func__, cpu_dai->id);
It is good for debug but not very useful here, so removing it would be good
sound/soc/qcom/sdm845.c line 137
Quoted 13 lines
sound/soc/qcom/sdm845.c new file +13
-0+switch (cpu_dai->id) { +case PRIMARY_MI2S_RX : +case PRIMARY_MI2S_TX : +mutex_lock (&pri_mi2s_res_lock); +if (atomic_inc_return (&pri_mi2s_clk_count) ==1 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_MCLK_1 , +DEFAULT_MCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT , +DEFAULT_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + } +mutex_unlock (&pri_mi2s_res_lock);
why do we need locking here? Can you please explain that.
Review
Quoted 2 lines
(quoted diff) +2
-0+ snd_soc_dai_set_fmt(cpu_dai, fmt); + break;
empty line after break helps in readability
Quoted 13 lines
sound/soc/qcom/sdm845.c new file +13
-0+static int sdm845_sbc_parse_of (struct snd_soc_card *card) +{ +struct device *dev = card->dev; +struct snd_soc_dai_link *link; +struct device_node *np, *codec, *platform, *cpu, *node; +int ret, num_links; +struct sdm845_snd_data *data; + + ret =snd_soc_of_parse_card_name (card,"qcom,model" ); +if (ret) { +dev_err (dev,"Error parsing card name: %d\n" , ret); +return ret; + }
sound/soc/qcom/sdm845.c line 240
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+ + node = dev->of_node; + +/* DAPM routes */ +if (of_property_read_bool (node,"qcom,audio-routing" )) { + ret =snd_soc_of_parse_audio_routing (card, +"qcom,audio-routing" ); +if (ret) +return ret; + }
so if we dont find audio-routing, then? we seems to continue..
Signature · 1 line
~Vinod
Thanks Rohit for the patch!
Quoted 10 lines · Rohit kumar
This patch adds sdm845 audio machine driver support.
Signed-off-by Rohit kumar <[email protected]>--- .../devicetree/bindings/sound/qcom,sdm845.txt | 87 ++++ sound/soc/qcom/Kconfig | 9 + sound/soc/qcom/Makefile | 2 + sound/soc/qcom/sdm845.c | 539 +++++++++++++++++++++ 4 files changed, 637 insertions(+)create mode 100644
Documentation/devicetree/bindings/sound/qcom,sdm845.txt
Split the bindings into a separate patch!
Quoted 43 lines
create mode 100644
sound/soc/qcom/sdm845.cDocumentation/devicetree/bindings/sound/qcom,sdm845.txt new file +35
-0@@ -0,0 +1,87 @@ +* Qualcomm Technologies Inc. SDM845 ASoC sound card driver + +This binding describes the SDM845 sound card, which uses qdsp for audio. + +- compatible: + Usage: required + Value type: <stringlist> + Definition: must be "qcom,sdm845-sndcard" + +- qcom,audio-routing: + Usage: Optional + Value type: <stringlist> + Definition: A list of the connections between audio components. + Each entry is a pair of strings, the first being the + connection's sink, the second being the connection's + source. Valid names could be power supplies, MicBias + of codec and the jacks on the board. + +- cdc-vdd-supply: + Usage: Optional + Value type: <phandle> + Definition: phandle of regulator supply required for codec vdd. + += dailinks +Each subnode of sndcard represents either a dailink, and subnodes of each +dailinks would be cpu/codec/platform dais. + +- link-name: + Usage: required + Value type: <string> + Definition: User friendly name for dai link + += CPU, PLATFORM, CODEC dais subnodes +- cpu: + Usage: required
Documentation/devicetree/bindings/sound/qcom,sdm845.txt line 45
Quoted 10 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +10
-0+ Value type: <subnode> + Definition: cpu dai sub-node + +- codec: + Usage: required + Value type: <subnode> + Definition: codec dai sub-node + +- platform: + Usage: opional
Optional
Quoted 12 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +12
-0+ Value type: <subnode> + Definition: platform dai sub-node + +- sound-dai: + Usage: required + Value type: <phandle> + Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node. + +Example: + +audio { + compatible = "qcom,sdm845-sndcard";
Documentation/devicetree/bindings/sound/qcom,sdm845.txt line 67
Quoted 10 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +10
-0+ qcom,model = "sdm845-snd-card"; + pinctrl-names = "pri_active", "pri_sleep"; + pinctrl-0 = <&pri_mi2s_active &pri_mi2s_ws_active>; + pinctrl-1 = <&pri_mi2s_sleep &pri_mi2s_ws_sleep>; + + qcom,audio-routing = "PRI_MI2S_RX Audio Mixer", "Pri-mi2s-gpio"; + + cdc-vdd-supply = <&pm8998_l14>; + + fe@1 {
Lets not use fe or be reference here, its just a link.
Documentation/devicetree/bindings/sound/qcom,sdm845.txt line 74
Quoted 7 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +7
-0+ link-name = "MultiMedia1"; + cpu { + sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>; + }; + platform { + sound-dai = <&q6asmdai>; + };
asmdai has sound-cell specifier as 1, so this will dtc will throw warning for this.
have a look at how 8996 is done.
Quoted 35 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +13
-0+ }; + + be@1 { + link-name = "PRI MI2S Playback"; + cpu { + sound-dai = <&q6afedai PRIMARY_MI2S_RX>; + }; + + platform { + sound-dai = <&q6routing>; + }; + }; +};sound/soc/qcom/Kconfig +9
-0@@ -90,3 +90,12 @@ config SND_SOC_MSM8996 Support for Qualcomm Technologies LPASS audio block in APQ8096 SoC-based systems. Say Y if you want to use audio device on this SoCs + +config SND_SOC_SDM845 + tristate "SoC Machine driver for SDM845 boards" + depends on QCOM_APR + select SND_SOC_QDSP6 + help + To add support for audio on Qualcomm Technologies Inc. + SDM845 SoC-based systems. + Say Y if you want to use audio device on this SoCssound/soc/qcom/Makefile +0
-0
sound/soc/qcom/Makefile obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o · line 22
Quoted 9 lines
sound/soc/qcom/Makefile +2
-0@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o snd-soc-storm-objs := storm.o snd-soc-apq8016-sbc-objs := apq8016_sbc.o snd-soc-apq8096-objs := apq8096.o +snd-soc-sdm845-objs := sdm845.o obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o ++obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
?? looks like typo here.
Quoted 63 lines
sound/soc/qcom/Makefile +0
-0#DSP lib obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/sound/soc/qcom/sdm845.c new file +53
-0@@ -0,0 +1,539 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018, The Linux Foundation. All rights reserved. +*/ + +#include <linux/module.h> +#include <linux/component.h> +#include <linux/platform_device.h> +#include <linux/regulator/consumer.h> +#include <linux/atomic.h> +#include <linux/of_device.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <linux/soc/qcom/apr.h> +#include "qdsp6/q6afe.h" + +#define DEFAULT_SAMPLE_RATE_48K 48000 +#define DEFAULT_MCLK_RATE 24576000 +#define DEFAULT_BCLK_RATE 1536000 + +struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock; +static atomic_t pri_mi2s_clk_count; +static atomic_t quat_tdm_clk_count; + +static unsigned int tdm_slot_offset[8 ] = {0 ,4 ,8 ,12 ,16 ,20 ,24 ,28 }; +static int sdm845_snd_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +int ret =0 ; + +switch (cpu_dai->id) { +case QUATERNARY_TDM_RX_0 : +case QUATERNARY_TDM_TX_0 : + ret =sdm845_tdm_snd_hw_params (substream, params); +break ; +default : +pr_err ("%s: invalid dai id 0x%x\n" , __func__, cpu_dai->id); +break ; + } +return ret; +} + +static int sdm845_snd_startup (struct snd_pcm_substream *substream)
sound/soc/qcom/sdm845.c line 128
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+{ +unsigned int fmt =SND_SOC_DAIFMT_CBS_CFS ; +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + +pr_debug ("%s: dai_id: 0x%x\n" , __func__, cpu_dai->id); +switch (cpu_dai->id) { +case PRIMARY_MI2S_RX : +case PRIMARY_MI2S_TX : +mutex_lock (&pri_mi2s_res_lock);
Mutex and atomic variables looks redundant here.
Can you explain why do you need both?
Quoted 27 lines
sound/soc/qcom/sdm845.c new file +27
-0+ if (atomic_inc_return(&pri_mi2s_clk_count) == 1) { > + snd_soc_dai_set_sysclk(cpu_dai, +Q6AFE_LPASS_CLK_ID_MCLK_1 , +DEFAULT_MCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT , +DEFAULT_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + } +mutex_unlock (&pri_mi2s_res_lock); +snd_soc_dai_set_fmt (cpu_dai, fmt); +break ; +case QUATERNARY_TDM_RX_0 : +case QUATERNARY_TDM_TX_0 : +mutex_lock (&quat_tdm_res_lock); +if (atomic_inc_return (&quat_tdm_clk_count) ==1 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_QUAD_TDM_IBIT , +DEFAULT_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + } +mutex_unlock (&quat_tdm_res_lock); +break ; +default : +pr_err ("%s: invalid dai id 0x%x\n" , __func__, cpu_dai->id); +break ; + } +return 0 ; +} +
...
Quoted 19 lines
sound/soc/qcom/sdm845.c new file +19
-0+ +static int sdm845_sbc_parse_of (struct snd_soc_card *card) +{ +struct device *dev = card->dev; +struct snd_soc_dai_link *link; +struct device_node *np, *codec, *platform, *cpu, *node; +int ret, num_links; +struct sdm845_snd_data *data; + + ret =snd_soc_of_parse_card_name (card,"qcom,model" ); +if (ret) { +dev_err (dev,"Error parsing card name: %d\n" , ret); +return ret; + } + + node = dev->of_node; + +/* DAPM routes */ +if (of_property_read_bool (node,"qcom,audio-routing" )) {
sound/soc/qcom/sdm845.c line 245
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+ ret =snd_soc_of_parse_audio_routing (card, +"qcom,audio-routing" ); +if (ret) +return ret; + } + +/* Populate links */ + num_links =of_get_child_count (node); + +dev_info (dev,"Found %d child audio dai links..\n" , num_links);
Looks unnessary!
Quoted 53 lines
sound/soc/qcom/sdm845.c new file +53
-0+/* Allocate the private data and the DAI link array */ + data =kzalloc (sizeof (*data) +sizeof (*link) * num_links, +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + card->dai_link = &data->dai_link[0 ]; + card->num_links = num_links; + card->dapm_widgets = sdm845_widgets; + card->num_dapm_widgets =ARRAY_SIZE (sdm845_widgets); + + link = data->dai_link; + data->card = card; + +for_each_child_of_node (node, 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,"Can't find cpu DT node\n" ); + ret = -EINVAL ; + goto fail; + } + + link->cpu_of_node =of_parse_phandle (cpu,"sound-dai" ,0 ); +if (!link->cpu_of_node) { +dev_err (card->dev,"error getting cpu phandle\n" ); + ret = -EINVAL ; + goto fail; + } + + link->platform_of_node =of_parse_phandle (platform, +"sound-dai" ,0 ); +if (!link->platform_of_node) { +dev_err (card->dev,"error getting platform phandle\n" ); + ret = -EINVAL ; + goto fail; + } + + ret =snd_soc_of_get_dai_name (cpu, &link->cpu_dai_name); +if (ret) { +dev_err (card->dev,"error getting cpu dai name\n" ); + goto fail; + } + +if (codec) { + ret =snd_soc_of_get_dai_link_codecs (dev, codec, link); +if (ret <0 ) { +dev_err (card->dev,"error getting codec dai name\n" ); + goto fail; + } + link->no_pcm =1 ;
sound/soc/qcom/sdm845.c line 308
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+ link->ignore_suspend =1 ; + link->ignore_pmdown_time =1 ; + link->ops = &sdm845_be_ops; + link->be_hw_params_fixup = sdm845_be_hw_params_fixup; + }else { + link->dynamic =1 ; + link->codec_dai_name ="snd-soc-dummy-dai" ; + link->codec_name ="snd-soc-dummy" ; + } +
You could optimize this code, have a look at apq8096.c which does exactly same thing.
Quoted 20 lines
sound/soc/qcom/sdm845.c new file +20
-0+ ret =of_property_read_string (np,"link-name" , &link->name); +if (ret) { +dev_err (card->dev, +"error getting codec dai_link name\n" ); + goto fail; + } + + link->dpcm_playback =1 ; + link->dpcm_capture =1 ; + link->stream_name = link->name; + link++; + } +dev_set_drvdata (dev, card); +snd_soc_card_set_drvdata (card, data); + +return ret; +fail: +kfree (data); +return ret; +}
...
Quoted 34 lines
sound/soc/qcom/sdm845.c new file +34
-0+ +static void sdm845_unbind (struct device *dev) +{ +struct snd_soc_card *card =dev_get_drvdata (dev); +struct sdm845_snd_data *data =snd_soc_card_get_drvdata (card); + +mutex_destroy (&pri_mi2s_res_lock); +mutex_destroy (&quat_tdm_res_lock); +if (data->vdd_supply) +regulator_put (data->vdd_supply); +component_unbind_all (dev, card); +snd_soc_unregister_card (card); +kfree (data); +kfree (card); +} + +static const struct component_master_ops sdm845_ops = { + .bind = sdm845_bind, + .unbind = sdm845_unbind, +}; + +static int sdm845_runtime_resume (struct device *dev) +{ +struct snd_soc_card *card =dev_get_drvdata (dev); +struct sdm845_snd_data *data =snd_soc_card_get_drvdata (card); + +if (!data->vdd_supply) { +dev_dbg (dev,"no supplies defined\n" ); +return 0 ; + } + +if (regulator_enable (data->vdd_supply)) +dev_err (dev,"Enable regulator supply failed\n" ); +
sound/soc/qcom/sdm845.c
Quoted 10 lines
sound/soc/qcom/sdm845.c new file +10
-0+return 0 ; +} + +static struct platform_driver sdm845_snd_driver = { + .probe = sdm845_snd_platform_probe, + .remove = sdm845_snd_platform_remove, + .driver = { + .name ="msm-snd-sdm845" , + .pm = &sdm845_pm_ops, + .owner =THIS_MODULE ,
not necessary!
Quoted 8 lines
sound/soc/qcom/sdm845.c new file +7
-0+ .of_match_table = of_match_ptr(sdm845_snd_device_id), + }, +}; +module_platform_driver (sdm845_snd_driver); + +MODULE_DESCRIPTION ("sdm845 ASoC Machine Driver" ); +MODULE_LICENSE ("GPL v2" );
Thanks Vinod for reviewing.
Quoted 12 lines · Vinod
sound/soc/qcom/sdm845.c line 29
Quoted 8 lines · Rohit kumar
sound/soc/qcom/sdm845.c new file +8
-0+struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock;any reason why the locks can't be part of
sdm845_snd_data? Also why do we need two locks ?
No specific reason, I will move it to sdm845_snd_data.
These locks are used to protect enable/disable of bit clocks. We have Primary MI2S RX/TX and Quaternary TDM RX/TX interfaces. For primary mi2s rx/tx, we have single clock which is synchronized with pri_mi2s_res_lock. For Quat TDM RX/TX, we are using quat_tdm_res_lock. We need two locks as we are protecting two different resources.
Quoted 4 lines
sound/soc/qcom/sdm845.c line 31
Quoted 3 lines
sound/soc/qcom/sdm845.c new file +2
-0+static atomic_t pri_mi2s_clk_count; +static atomic_t quat_tdm_clk_count;Any specific reason for using atomic variables?
Nothing as such. As we are using mutex to synchronize, we can make it non- atomic. Will do it in next-spin.
Quoted 15 lines
sound/soc/qcom/sdm845.c line 44
Quoted 13 lines
sound/soc/qcom/sdm845.c new file +12
-0+static unsigned int tdm_slot_offset[8 ] = {0 ,4 ,8 ,12 ,16 ,20 ,24 ,28 }; + +static int sdm845_tdm_snd_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +int ret =0 ; +int channels, slot_width; + + channels =params_channels (params); +if (channels <1 || channels >8 ) {I though ch = 0 would be caught by framework and IIRC ASoC doesn't support more than 8 channels
OK. Will check and remove.
Quoted 7 lines
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+pr_err ("%s: invalid param channels %d\n" , + __func__, channels); +return -EINVAL ; + } + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S32_LE :
Quoted 8 lines
sound/soc/qcom/sdm845.c line 58
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+case SNDRV_PCM_FORMAT_S24_LE : +case SNDRV_PCM_FORMAT_S16_LE : + slot_width =32 ; +break ; +default : +pr_err ("%s: invalid param format 0x%x\n" , + __func__,params_format (params));why not use
dev_err, bonus you get device name printer with the logs :)
Sure. Will change it.
Quoted 9 lines
sound/soc/qcom/sdm845.c line 124
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+static int sdm845_snd_startup (struct snd_pcm_substream *substream) +{ +unsigned int fmt =SND_SOC_DAIFMT_CBS_CFS ; +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + +pr_debug ("%s: dai_id: 0x%x\n" , __func__, cpu_dai->id);It is good for debug but not very useful here, so removing it would be good
OK
Quoted 6 lines
Quoted 6 lines
sound/soc/qcom/sdm845.c new file +6
-0+switch (cpu_dai->id) { +case PRIMARY_MI2S_RX : +case PRIMARY_MI2S_TX : +mutex_lock (&pri_mi2s_res_lock); +if (atomic_inc_return (&pri_mi2s_clk_count) ==1 ) { + snd_soc_dai_set_sysclk(cpu_dai,
Quoted 8 lines
sound/soc/qcom/sdm845.c line 137
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+Q6AFE_LPASS_CLK_ID_MCLK_1 , + DEFAULT_MCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK); +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT , +DEFAULT_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + } +mutex_unlock (&pri_mi2s_res_lock);why do we need locking here? Can you please explain that.
So, we can have two usecases: one with primary mi2s rx and other with primary mi2s tx. Lock is required to increment pri_mi2s_clk_count and enable clock so that disable of one usecase does not disable the clock.
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ snd_soc_dai_set_fmt(cpu_dai, fmt); + break;empty line after break helps in readability
Sure. Will add that change.
Quoted 16 lines
Quoted 16 lines
sound/soc/qcom/sdm845.c new file +16
-0+static int sdm845_sbc_parse_of (struct snd_soc_card *card) +{ +struct device *dev = card->dev; +struct snd_soc_dai_link *link; +struct device_node *np, *codec, *platform, *cpu, *node; +int ret, num_links; +struct sdm845_snd_data *data; + + ret =snd_soc_of_parse_card_name (card,"qcom,model" ); +if (ret) { +dev_err (dev,"Error parsing card name: %d\n" , ret); +return ret; + } + + node = dev->of_node; +
Quoted 8 lines
sound/soc/qcom/sdm845.c line 240
Quoted 7 lines
sound/soc/qcom/sdm845.c new file +7
-0+/* DAPM routes */ +if (of_property_read_bool (node,"qcom,audio-routing" )) { + ret =snd_soc_of_parse_audio_routing (card, +"qcom,audio-routing" ); +if (ret) +return ret; + }so if we dont find audio-routing, then? we seems to continue..
Right. Its not mandatory to have qcom,audio-routing in device tree.
Regards,
Rohit
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Thanks Srinivas for reviewing.
Quoted 15 lines · Srinivas Kandagatla
Thanks Rohit for the patch!
Quoted 11 lines · Rohit kumar
This patch adds sdm845 audio machine driver support.
Signed-off-by Rohit kumar <[email protected]>---
.../devicetree/bindings/sound/qcom,sdm845.txt | 87 ++++ sound/soc/qcom/Kconfig | 9 + sound/soc/qcom/Makefile | 2 + sound/soc/qcom/sdm845.c | 539
+++++++++++++++++++++4 files changed, 637 insertions(+)create mode 100644
Documentation/devicetree/bindings/sound/qcom,sdm845.txt
Quoted 1 line
Split the bindings into a separate patch!
Sure, will do it in next spin.
Quoted 14 lines
Quoted 14 lines
create mode 100644
sound/soc/qcom/sdm845.cDocumentation/devicetree/bindings/sound/qcom,sdm845.txt new file +3
-0@@ -0,0 +1,87 @@ +* Qualcomm Technologies Inc. SDM845 ASoC sound card driver + +This binding describes the SDM845 sound card, which uses qdsp foraudio.
[..]
Quoted 10 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt line 45
Quoted 8 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +8
-0+ +- codec: + Usage: required + Value type: <subnode> + Definition: codec dai sub-node + +- platform: + Usage: opionalOptional
okay
Quoted 15 lines
Quoted 15 lines
+ Value type: <subnode>
+ Definition: platform dai sub-nodeDocumentation/devicetree/bindings/sound/qcom,sdm845.txt new file +13
-0+ +- sound-dai: + Usage: required + Value type: <phandle> + Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node. + +Example: + +audio { + compatible = "qcom,sdm845-sndcard"; + qcom,model = "sdm845-snd-card"; + pinctrl-names = "pri_active", "pri_sleep"; + pinctrl-0 = <&pri_mi2s_active &pri_mi2s_ws_active>;
Quoted 8 lines
Documentation/devicetree/bindings/sound/qcom,sdm845.txt line 67
Quoted 7 lines
+ pinctrl-1 = <
&pri_mi2s_sleep&pri_mi2s_ws_sleep>;Documentation/devicetree/bindings/sound/qcom,sdm845.txt new file +6
-0+ + qcom,audio-routing = "PRI_MI2S_RX Audio Mixer", "Pri-mi2s-gpio"; + + cdc-vdd-supply = <&pm8998_l14>; + + fe@1 {Lets not use fe or be reference here, its just a link.
okay
Quoted 11 lines
Quoted 8 lines
+ link-name = "MultiMedia1";
+ cpu {
+ sound-dai = <&q6asmdaiMSM_FRONTEND_DAI_MULTIMEDIA1>; + };
+ platform {
+ sound-dai = <&q6asmdai>;
+ };asmdai has sound-cell specifier as 1, so this will dtc will throw warning for this.
have a look at how 8996 is done.
ok, sure
Quoted 5 lines
Quoted 5 lines
+ };
+
+ be@1 {
[..]
Quoted 8 lines
Quoted 8 lines
sound/soc/qcom/Makefile +0
-0@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) +=snd-soc-lpass-apq8016.o
snd-soc-storm-objs := storm.o
snd-soc-apq8016-sbc-objs := apq8016_sbc.o
Quoted 9 lines
Quoted 6 lines
snd-soc-apq8096-objs := apq8096.o +snd-soc-sdm845-objs := sdm845.o obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o ++obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
?? looks like typo here.
Right. Will update.
Quoted 16 lines
Quoted 16 lines
#DSP lib
obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/sound/soc/qcom/sdm845.c new file +7
-0@@ -0,0 +1,539 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018, The Linux Foundation. All rights reserved. +*/ + +#include <linux/module.h> +#include <linux/component.h>
[..]
Quoted 8 lines
Quoted 8 lines
sound/soc/qcom/sdm845.c new file +8
-0+} + +static int sdm845_snd_startup (struct snd_pcm_substream *substream) +{ + unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS; + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +
Quoted 8 lines
Quoted 5 lines
+
pr_debug("%s: dai_id: 0x%x\n", __func__, cpu_dai->id); + switch (cpu_dai->id) {
+ casePRIMARY_MI2S_RX:
+ casePRIMARY_MI2S_TX:
+mutex_lock(&pri_mi2s_res_lock);Mutex and atomic variables looks redundant here.
Can you explain why do you need both?
Right. Only mutex is required here. I will make count as non-atomic.
Quoted 25 lines
...
Quoted 23 lines
sound/soc/qcom/sdm845.c new file +23
-0+ +static int sdm845_sbc_parse_of (struct snd_soc_card *card) +{ + struct device *dev = card->dev; + struct snd_soc_dai_link *link; + struct device_node *np, *codec, *platform, *cpu, *node; + int ret, num_links; + struct sdm845_snd_data *data; + + ret = snd_soc_of_parse_card_name(card, "qcom,model"); + if (ret) { + dev_err(dev, "Error parsing card name: %d\n", ret); + return ret; + } + + node = dev->of_node; + + /* DAPM routes */ + if (of_property_read_bool(node, "qcom,audio-routing")) { + ret = snd_soc_of_parse_audio_routing(card, + "qcom,audio-routing"); + if (ret) + return ret;
Quoted 8 lines
sound/soc/qcom/sdm845.c line 245
Quoted 6 lines
+ }
sound/soc/qcom/sdm845.c new file +5
-0+ + /* Populate links */ + num_links = of_get_child_count(node); + + dev_info(dev, "Found %d child audio dai links..\n", num_links);Looks unnessary!
Ok . Will remove it in next patchset.
Quoted 27 lines
Quoted 27 lines
sound/soc/qcom/sdm845.c new file +26
-0+ + link->platform_of_node = of_parse_phandle(platform, + "sound-dai", 0); + if (!link->platform_of_node) { + dev_err(card->dev, "error getting platform phandle\n"); + ret = -EINVAL; + goto fail; + } + + ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name); + if (ret) { + dev_err(card->dev, "error getting cpu dai name\n"); + goto fail; + } + + if (codec) { + ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); + if (ret < 0) { + dev_err(card->dev, "error getting codec dai name\n"); + goto fail; + } + link->no_pcm = 1; + link->ignore_suspend = 1; + link->ignore_pmdown_time = 1; + link->ops = &sdm845_be_ops; + link->be_hw_params_fixup = sdm845_be_hw_params_fixup;
Quoted 9 lines
Quoted 6 lines
+ } else {
+link->dynamic= 1;
+link->codec_dai_name= "snd-soc-dummy-dai"; +link->codec_name= "snd-soc-dummy"; + }
+You could optimize this code, have a look at
apq8096.cwhich does exactly same thing.
Okay. will check and update.
Quoted 38 lines
...
Quoted 37 lines
sound/soc/qcom/sdm845.c new file +37
-0+ +static void sdm845_unbind (struct device *dev) +{ + struct snd_soc_card *card = dev_get_drvdata(dev); + struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card); + + mutex_destroy(&pri_mi2s_res_lock); + mutex_destroy(&quat_tdm_res_lock); + if (data->vdd_supply) + regulator_put(data->vdd_supply); + component_unbind_all(dev, card); + snd_soc_unregister_card(card); + kfree(data); + kfree(card); +} + +static const struct component_master_ops sdm845_ops = { + .bind = sdm845_bind, + .unbind = sdm845_unbind, +}; + +static int sdm845_runtime_resume (struct device *dev) +{ + struct snd_soc_card *card = dev_get_drvdata(dev); + struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card); + + if (!data->vdd_supply) { + dev_dbg(dev, "no supplies defined\n"); + return 0; + } + + if (regulator_enable(data->vdd_supply)) + dev_err(dev, "Enable regulator supply failed\n"); + + return 0; +} +
Quoted 8 lines
Quoted 7 lines
+static struct
platform_driversdm845_snd_driver= { + .probe =sdm845_snd_platform_probe,
+ .remove =sdm845_snd_platform_remove,
+ .driver = {
+ .name = "msm-snd-sdm845",
+ .pm =&sdm845_pm_ops,
+ .owner =THIS_MODULE,not necessary!
Okay. Will remove it.
Quoted 4 lines
Quoted 4 lines
+ .of_match_table =
of_match_ptr(sdm845_snd_device_id), + },sound/soc/qcom/sdm845.c new file +2
-0+}; +module_platform_driver (sdm845_snd_driver);
Quoted 8 lines
sound/soc/qcom/sdm845.c line 539
Quoted 4 lines
sound/soc/qcom/sdm845.c new file +3
-0+ +MODULE_DESCRIPTION ("sdm845 ASoC Machine Driver" ); +MODULE_LICENSE ("GPL v2" );_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Regards,
Rohit
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Hi Rohit,
Quoted 13 lines · Rohit Kumar
Quoted 12 lines · Vinod
sound/soc/qcom/sdm845.c line 29
Quoted 8 lines · Rohit kumar
sound/soc/qcom/sdm845.c new file +8
-0+struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock;any reason why the locks can't be part of
sdm845_snd_data? Also why do we need two locks ?
Quoted 8 lines
No specific reason, I will move it to
sdm845_snd_data.
These locks are used to protect enable/disable of bit clocks. We have Primary MI2S RX/TX
and Quaternary TDM RX/TX interfaces. For primary mi2s rx/tx, we have single clock which is
synchronized withpri_mi2s_res_lock. For Quat TDM RX/TX, we are usingquat_tdm_res_lock.
We need two locks as we are protecting two different resources.
I think bigger question is why do you need any locks? What is the race scenario you envision which needs protection
Signature · 1 line
~Vinod
Hello Vinod,
Quoted 24 lines · Vinod
Hi Rohit,
Quoted 13 lines · Rohit Kumar
Quoted 12 lines · Vinod
sound/soc/qcom/sdm845.c line 29
Quoted 8 lines · Rohit kumar
sound/soc/qcom/sdm845.c new file +8
-0+struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock;any reason why the locks can't be part of
sdm845_snd_data? Also why do we need two locks ?Quoted 8 lines
No specific reason, I will move it to
sdm845_snd_data.
These locks are used to protect enable/disable of bit clocks. We have Primary MI2S RX/TX
and Quaternary TDM RX/TX interfaces. For primary mi2s rx/tx, we have single clock which is
synchronized withpri_mi2s_res_lock. For Quat TDM RX/TX, we are usingquat_tdm_res_lock.
We need two locks as we are protecting two different resources.
Quoted 3 lines
I think bigger question is why do you need any locks? What is the race scenario you envision which needs protection
Below is one of the race condition:
Thread1 | Thread2
----------------------------------------------------------
startup() |
count++; | startup()
read count (count = 1) |
enable_clock() | count++; //count = 2 shutdown() |
count--;// count = 1 |
| read count (count = 1) | enable_clock()
Here clock will be enabled twice but disable will be called only once when count = 0.
This will make the clock always enabled. So, I think we should keep either mutex lock or atomic variable to synchronize this.
Regards,
Rohit
Signature · 7 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Hi Rohit,
Quoted 39 lines · Rohit Kumar
Quoted 22 lines · Rohit Kumar
Quoted 13 lines · Vinod
Quoted 12 lines · Rohit kumar
sound/soc/qcom/sdm845.c line 29
Quoted 9 lines
sound/soc/qcom/sdm845.c new file +8
-0+struct sdm845_snd_data { +struct snd_soc_card *card; +struct regulator *vdd_supply; +struct snd_soc_dai_link dai_link[]; +}; + +static struct mutex pri_mi2s_res_lock; +static struct mutex quat_tdm_res_lock;any reason why the locks can't be part of
sdm845_snd_data? Also why do we need two locks ?Quoted 8 lines
No specific reason, I will move it to
sdm845_snd_data.
These locks are used to protect enable/disable of bit clocks. We have Primary MI2S RX/TX
and Quaternary TDM RX/TX interfaces. For primary mi2s rx/tx, we have single clock which is
synchronized withpri_mi2s_res_lock. For Quat TDM RX/TX, we are usingquat_tdm_res_lock.
We need two locks as we are protecting two different resources.Quoted 3 lines
I think bigger question is why do you need any locks? What is the race scenario you envision which needs protection
Below is one of the race condition:
Thread1 | Thread2
----------------------------------------------------------
startup() |
count++; |startup()
read count (count = 1) |
enable_clock() | count++; //count = 2 shutdown() |
count--;// count = 1 |
| read count (count = 1) |enable_clock()
Quoted 5 lines
Here clock will be enabled twice but disable will be called only once when count = 0.
This will make the clock always enabled. So, I think we should keep either mutex lock or atomic variable to synchronize this.
we are using DPCM here right?
Signature · 1 line
~Vinod
Quoted 6 lines · Vinod
Quoted 5 lines
Here clock will be enabled twice but disable will be called only once when count = 0.
This will make the clock always enabled. So, I think we should keep either mutex lock or atomic variable to synchronize this.
we are using DPCM here right?
We should probably model this clk as DAPM widget so we do not need to handle this in machine code.
--srini
Quoted 10 lines · Srinivas Kandagatla
Quoted 6 lines · Vinod
Quoted 5 lines
Here clock will be enabled twice but disable will be called only once when count = 0.
This will make the clock always enabled. So, I think we should keep either mutex lock or atomic variable to synchronize this.
we are using DPCM here right?
We should probably model this clk as DAPM widget so we do not need to handle this in machine code.
Sure that would be even better, but my point was that we need not worry about .startup racing in case of DPCM as it holds a card mutex before it calls PCM ops.. so it is already serialized..
Signature · 1 line
~Vinod