Skip to content

Commit

Permalink
ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()
Browse files Browse the repository at this point in the history
Now that we have updated qcom_snd_parse_of() to handle the device
tree bindings used for apq8016_sbc, update the apq8016_sbc driver
to use the common function and remove the duplicated code.

Signed-off-by: Stephan Gerhold <[email protected]>
Tested-by: Srinivas Kandagatla <[email protected]>
Reviewed-by: Srinivas Kandagatla <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
stephan-gh authored and broonie committed Jul 24, 2020
1 parent f0d67fd commit 118205d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 106 deletions.
1 change: 1 addition & 0 deletions sound/soc/qcom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ config SND_SOC_APQ8016_SBC
tristate "SoC Audio support for APQ8016 SBC platforms"
depends on SND_SOC_QCOM
select SND_SOC_LPASS_APQ8016
select SND_SOC_QCOM_COMMON
help
Support for Qualcomm Technologies LPASS audio block in
APQ8016 SOC-based systems.
Expand Down
120 changes: 14 additions & 106 deletions sound/soc/qcom/apq8016_sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#include <sound/soc.h>
#include <uapi/linux/input-event-codes.h>
#include <dt-bindings/sound/apq8016-lpass.h>
#include "common.h"

struct apq8016_sbc_data {
struct snd_soc_card card;
void __iomem *mic_iomux;
void __iomem *spkr_iomux;
struct snd_soc_jack jack;
bool jack_setup;
struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
};

#define MIC_CTRL_TER_WS_SLAVE_SEL BIT(21)
Expand Down Expand Up @@ -110,107 +111,13 @@ static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
return 0;
}

static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
static void apq8016_sbc_add_ops(struct snd_soc_card *card)
{
struct device *dev = card->dev;
struct snd_soc_dai_link *link;
struct device_node *np, *codec, *cpu, *node = dev->of_node;
struct apq8016_sbc_data *data;
struct snd_soc_dai_link_component *dlc;
int ret, num_links;

ret = snd_soc_of_parse_card_name(card, "qcom,model");
if (ret) {
dev_err(dev, "Error parsing card name: %d\n", ret);
return ERR_PTR(ret);
}

/* 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 ERR_PTR(ret);
}


/* Populate links */
num_links = of_get_child_count(node);

/* Allocate the private data and the DAI link array */
data = devm_kzalloc(dev,
struct_size(data, dai_link, num_links),
GFP_KERNEL);
if (!data)
return ERR_PTR(-ENOMEM);

card->dai_link = &data->dai_link[0];
card->num_links = num_links;

link = data->dai_link;

for_each_child_of_node(node, np) {
dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
if (!dlc)
return ERR_PTR(-ENOMEM);

link->cpus = &dlc[0];
link->platforms = &dlc[1];

link->num_cpus = 1;
link->num_platforms = 1;

cpu = of_get_child_by_name(np, "cpu");
codec = of_get_child_by_name(np, "codec");

if (!cpu || !codec) {
dev_err(dev, "Can't find cpu/codec DT node\n");
ret = -EINVAL;
goto error;
}
int i;

link->cpus->of_node = of_parse_phandle(cpu, "sound-dai", 0);
if (!link->cpus->of_node) {
dev_err(card->dev, "error getting cpu phandle\n");
ret = -EINVAL;
goto error;
}

ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
if (ret) {
dev_err(card->dev, "error getting cpu dai name\n");
goto error;
}

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 error;
}

link->platforms->of_node = link->cpus->of_node;
ret = of_property_read_string(np, "link-name", &link->name);
if (ret) {
dev_err(card->dev, "error getting codec dai_link name\n");
goto error;
}

link->stream_name = link->name;
for_each_card_prelinks(card, i, link)
link->init = apq8016_sbc_dai_init;
link++;

of_node_put(cpu);
of_node_put(codec);
}

return data;

error:
of_node_put(np);
of_node_put(cpu);
of_node_put(codec);
return ERR_PTR(ret);
}

static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets[] = {
Expand All @@ -228,20 +135,20 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)
struct snd_soc_card *card;
struct apq8016_sbc_data *data;
struct resource *res;
int ret;

card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

card = &data->card;
card->dev = dev;
card->dapm_widgets = apq8016_sbc_dapm_widgets;
card->num_dapm_widgets = ARRAY_SIZE(apq8016_sbc_dapm_widgets);
data = apq8016_sbc_parse_of(card);
if (IS_ERR(data)) {
dev_err(&pdev->dev, "Error resolving dai links: %ld\n",
PTR_ERR(data));
return PTR_ERR(data);
}

ret = qcom_snd_parse_of(card);
if (ret)
return ret;

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mic-iomux");
data->mic_iomux = devm_ioremap_resource(dev, res);
Expand All @@ -255,6 +162,7 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)

snd_soc_card_set_drvdata(card, data);

apq8016_sbc_add_ops(card);
return devm_snd_soc_register_card(&pdev->dev, card);
}

Expand Down

0 comments on commit 118205d

Please sign in to comment.