• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) ST-Ericsson SA 2012
4  *
5  * Author: Ola Lilja (ola.o.lilja@stericsson.com)
6  *         for ST-Ericsson.
7  *
8  * License terms:
9  */
10 
11 #include <asm/mach-types.h>
12 
13 #include <linux/module.h>
14 #include <linux/io.h>
15 #include <linux/spi/spi.h>
16 #include <linux/of.h>
17 
18 #include <sound/soc.h>
19 #include <sound/initval.h>
20 
21 #include "ux500_pcm.h"
22 #include "ux500_msp_dai.h"
23 
24 #include "mop500_ab8500.h"
25 
26 /* Define the whole MOP500 soundcard, linking platform to the codec-drivers  */
27 SND_SOC_DAILINK_DEFS(link1,
28 	DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.1")),
29 	DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.0")),
30 	DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.1")));
31 
32 SND_SOC_DAILINK_DEFS(link2,
33 	DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.3")),
34 	DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.1")),
35 	DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.3")));
36 
37 static struct snd_soc_dai_link mop500_dai_links[] = {
38 	{
39 		.name = "ab8500_0",
40 		.stream_name = "ab8500_0",
41 		.init = mop500_ab8500_machine_init,
42 		.ops = mop500_ab8500_ops,
43 		SND_SOC_DAILINK_REG(link1),
44 	},
45 	{
46 		.name = "ab8500_1",
47 		.stream_name = "ab8500_1",
48 		.init = NULL,
49 		.ops = mop500_ab8500_ops,
50 		SND_SOC_DAILINK_REG(link2),
51 	},
52 };
53 
54 static struct snd_soc_card mop500_card = {
55 	.name = "MOP500-card",
56 	.owner = THIS_MODULE,
57 	.probe = NULL,
58 	.dai_link = mop500_dai_links,
59 	.num_links = ARRAY_SIZE(mop500_dai_links),
60 };
61 
mop500_of_node_put(void)62 static void mop500_of_node_put(void)
63 {
64 	int i;
65 
66 	for (i = 0; i < 2; i++) {
67 		of_node_put(mop500_dai_links[i].cpus->of_node);
68 		of_node_put(mop500_dai_links[i].codecs->of_node);
69 	}
70 }
71 
mop500_of_probe(struct platform_device * pdev,struct device_node * np)72 static int mop500_of_probe(struct platform_device *pdev,
73 			   struct device_node *np)
74 {
75 	struct device_node *codec_np, *msp_np[2];
76 	int i;
77 
78 	msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
79 	msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
80 	codec_np  = of_parse_phandle(np, "stericsson,audio-codec", 0);
81 
82 	if (!(msp_np[0] && msp_np[1] && codec_np)) {
83 		dev_err(&pdev->dev, "Phandle missing or invalid\n");
84 		mop500_of_node_put();
85 		return -EINVAL;
86 	}
87 
88 	for (i = 0; i < 2; i++) {
89 		mop500_dai_links[i].cpus->of_node = msp_np[i];
90 		mop500_dai_links[i].cpus->dai_name = NULL;
91 		mop500_dai_links[i].platforms->of_node = msp_np[i];
92 		mop500_dai_links[i].platforms->name = NULL;
93 		mop500_dai_links[i].codecs->of_node = codec_np;
94 		mop500_dai_links[i].codecs->name = NULL;
95 	}
96 
97 	snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
98 
99 	return 0;
100 }
101 
mop500_probe(struct platform_device * pdev)102 static int mop500_probe(struct platform_device *pdev)
103 {
104 	struct device_node *np = pdev->dev.of_node;
105 	int ret;
106 
107 	dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
108 
109 	mop500_card.dev = &pdev->dev;
110 
111 	if (np) {
112 		ret = mop500_of_probe(pdev, np);
113 		if (ret)
114 			return ret;
115 	}
116 
117 	dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
118 		__func__, mop500_card.name);
119 
120 	snd_soc_card_set_drvdata(&mop500_card, NULL);
121 
122 	dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
123 		__func__, mop500_card.name, mop500_card.num_links);
124 	dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
125 		__func__, mop500_card.name, mop500_card.dai_link[0].name);
126 	dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
127 		__func__, mop500_card.name,
128 		mop500_card.dai_link[0].stream_name);
129 
130 	ret = snd_soc_register_card(&mop500_card);
131 	if (ret)
132 		dev_err(&pdev->dev,
133 			"Error: snd_soc_register_card failed (%d)!\n", ret);
134 
135 	return ret;
136 }
137 
mop500_remove(struct platform_device * pdev)138 static int mop500_remove(struct platform_device *pdev)
139 {
140 	struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
141 
142 	pr_debug("%s: Enter.\n", __func__);
143 
144 	snd_soc_unregister_card(mop500_card);
145 	mop500_ab8500_remove(mop500_card);
146 	mop500_of_node_put();
147 
148 	return 0;
149 }
150 
151 static const struct of_device_id snd_soc_mop500_match[] = {
152 	{ .compatible = "stericsson,snd-soc-mop500", },
153 	{},
154 };
155 MODULE_DEVICE_TABLE(of, snd_soc_mop500_match);
156 
157 static struct platform_driver snd_soc_mop500_driver = {
158 	.driver = {
159 		.name = "snd-soc-mop500",
160 		.of_match_table = snd_soc_mop500_match,
161 	},
162 	.probe = mop500_probe,
163 	.remove = mop500_remove,
164 };
165 
166 module_platform_driver(snd_soc_mop500_driver);
167 
168 MODULE_LICENSE("GPL v2");
169 MODULE_DESCRIPTION("ASoC MOP500 board driver");
170 MODULE_AUTHOR("Ola Lilja");
171