diff options
Diffstat (limited to 'sound/soc/generic/simple-card.c')
-rw-r--r-- | sound/soc/generic/simple-card.c | 193 |
1 files changed, 177 insertions, 16 deletions
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index b2fbb7075a6c..c0d928138c88 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c | |||
@@ -8,7 +8,8 @@ | |||
8 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | #include <linux/clk.h> | |
12 | #include <linux/of.h> | ||
12 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
14 | #include <sound/simple_card.h> | 15 | #include <sound/simple_card.h> |
@@ -24,7 +25,7 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, | |||
24 | 25 | ||
25 | daifmt |= set->fmt; | 26 | daifmt |= set->fmt; |
26 | 27 | ||
27 | if (!ret && daifmt) | 28 | if (daifmt) |
28 | ret = snd_soc_dai_set_fmt(dai, daifmt); | 29 | ret = snd_soc_dai_set_fmt(dai, daifmt); |
29 | 30 | ||
30 | if (ret == -ENOTSUPP) { | 31 | if (ret == -ENOTSUPP) { |
@@ -57,11 +58,170 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | |||
57 | return 0; | 58 | return 0; |
58 | } | 59 | } |
59 | 60 | ||
61 | static int | ||
62 | asoc_simple_card_sub_parse_of(struct device_node *np, | ||
63 | struct asoc_simple_dai *dai, | ||
64 | struct device_node **node) | ||
65 | { | ||
66 | struct clk *clk; | ||
67 | int ret; | ||
68 | |||
69 | /* | ||
70 | * get node via "sound-dai = <&phandle port>" | ||
71 | * it will be used as xxx_of_node on soc_bind_dai_link() | ||
72 | */ | ||
73 | *node = of_parse_phandle(np, "sound-dai", 0); | ||
74 | if (!*node) | ||
75 | return -ENODEV; | ||
76 | |||
77 | /* get dai->name */ | ||
78 | ret = snd_soc_of_get_dai_name(np, &dai->name); | ||
79 | if (ret < 0) | ||
80 | goto parse_error; | ||
81 | |||
82 | /* | ||
83 | * bitclock-inversion, frame-inversion | ||
84 | * bitclock-master, frame-master | ||
85 | * and specific "format" if it has | ||
86 | */ | ||
87 | dai->fmt = snd_soc_of_parse_daifmt(np, NULL); | ||
88 | |||
89 | /* | ||
90 | * dai->sysclk come from | ||
91 | * "clocks = <&xxx>" (if system has common clock) | ||
92 | * or "system-clock-frequency = <xxx>" | ||
93 | * or device's module clock. | ||
94 | */ | ||
95 | if (of_property_read_bool(np, "clocks")) { | ||
96 | clk = of_clk_get(np, 0); | ||
97 | if (IS_ERR(clk)) { | ||
98 | ret = PTR_ERR(clk); | ||
99 | goto parse_error; | ||
100 | } | ||
101 | |||
102 | dai->sysclk = clk_get_rate(clk); | ||
103 | } else if (of_property_read_bool(np, "system-clock-frequency")) { | ||
104 | of_property_read_u32(np, | ||
105 | "system-clock-frequency", | ||
106 | &dai->sysclk); | ||
107 | } else { | ||
108 | clk = of_clk_get(*node, 0); | ||
109 | if (IS_ERR(clk)) { | ||
110 | ret = PTR_ERR(clk); | ||
111 | goto parse_error; | ||
112 | } | ||
113 | |||
114 | dai->sysclk = clk_get_rate(clk); | ||
115 | } | ||
116 | |||
117 | ret = 0; | ||
118 | |||
119 | parse_error: | ||
120 | of_node_put(*node); | ||
121 | |||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | static int asoc_simple_card_parse_of(struct device_node *node, | ||
126 | struct asoc_simple_card_info *info, | ||
127 | struct device *dev, | ||
128 | struct device_node **of_cpu, | ||
129 | struct device_node **of_codec, | ||
130 | struct device_node **of_platform) | ||
131 | { | ||
132 | struct device_node *np; | ||
133 | char *name; | ||
134 | int ret; | ||
135 | |||
136 | /* get CPU/CODEC common format via simple-audio-card,format */ | ||
137 | info->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") & | ||
138 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); | ||
139 | |||
140 | /* DAPM routes */ | ||
141 | ret = snd_soc_of_parse_audio_routing(&info->snd_card, | ||
142 | "simple-audio-routing"); | ||
143 | if (ret) | ||
144 | return ret; | ||
145 | |||
146 | /* CPU sub-node */ | ||
147 | ret = -EINVAL; | ||
148 | np = of_get_child_by_name(node, "simple-audio-card,cpu"); | ||
149 | if (np) | ||
150 | ret = asoc_simple_card_sub_parse_of(np, | ||
151 | &info->cpu_dai, | ||
152 | of_cpu); | ||
153 | if (ret < 0) | ||
154 | return ret; | ||
155 | |||
156 | /* CODEC sub-node */ | ||
157 | ret = -EINVAL; | ||
158 | np = of_get_child_by_name(node, "simple-audio-card,codec"); | ||
159 | if (np) | ||
160 | ret = asoc_simple_card_sub_parse_of(np, | ||
161 | &info->codec_dai, | ||
162 | of_codec); | ||
163 | if (ret < 0) | ||
164 | return ret; | ||
165 | |||
166 | if (!info->cpu_dai.name || !info->codec_dai.name) | ||
167 | return -EINVAL; | ||
168 | |||
169 | /* card name is created from CPU/CODEC dai name */ | ||
170 | name = devm_kzalloc(dev, | ||
171 | strlen(info->cpu_dai.name) + | ||
172 | strlen(info->codec_dai.name) + 2, | ||
173 | GFP_KERNEL); | ||
174 | sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name); | ||
175 | info->name = info->card = name; | ||
176 | |||
177 | /* simple-card assumes platform == cpu */ | ||
178 | *of_platform = *of_cpu; | ||
179 | |||
180 | dev_dbg(dev, "card-name : %s\n", info->card); | ||
181 | dev_dbg(dev, "platform : %04x\n", info->daifmt); | ||
182 | dev_dbg(dev, "cpu : %s / %04x / %d\n", | ||
183 | info->cpu_dai.name, | ||
184 | info->cpu_dai.fmt, | ||
185 | info->cpu_dai.sysclk); | ||
186 | dev_dbg(dev, "codec : %s / %04x / %d\n", | ||
187 | info->codec_dai.name, | ||
188 | info->codec_dai.fmt, | ||
189 | info->codec_dai.sysclk); | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
60 | static int asoc_simple_card_probe(struct platform_device *pdev) | 194 | static int asoc_simple_card_probe(struct platform_device *pdev) |
61 | { | 195 | { |
62 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; | 196 | struct asoc_simple_card_info *cinfo; |
197 | struct device_node *np = pdev->dev.of_node; | ||
198 | struct device_node *of_cpu, *of_codec, *of_platform; | ||
63 | struct device *dev = &pdev->dev; | 199 | struct device *dev = &pdev->dev; |
64 | 200 | ||
201 | cinfo = NULL; | ||
202 | of_cpu = NULL; | ||
203 | of_codec = NULL; | ||
204 | of_platform = NULL; | ||
205 | if (np && of_device_is_available(np)) { | ||
206 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); | ||
207 | if (cinfo) { | ||
208 | int ret; | ||
209 | cinfo->snd_card.dev = &pdev->dev; | ||
210 | ret = asoc_simple_card_parse_of(np, cinfo, dev, | ||
211 | &of_cpu, | ||
212 | &of_codec, | ||
213 | &of_platform); | ||
214 | if (ret < 0) { | ||
215 | if (ret != -EPROBE_DEFER) | ||
216 | dev_err(dev, "parse error %d\n", ret); | ||
217 | return ret; | ||
218 | } | ||
219 | } | ||
220 | } else { | ||
221 | cinfo->snd_card.dev = &pdev->dev; | ||
222 | cinfo = pdev->dev.platform_data; | ||
223 | } | ||
224 | |||
65 | if (!cinfo) { | 225 | if (!cinfo) { |
66 | dev_err(dev, "no info for asoc-simple-card\n"); | 226 | dev_err(dev, "no info for asoc-simple-card\n"); |
67 | return -EINVAL; | 227 | return -EINVAL; |
@@ -69,10 +229,10 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
69 | 229 | ||
70 | if (!cinfo->name || | 230 | if (!cinfo->name || |
71 | !cinfo->card || | 231 | !cinfo->card || |
72 | !cinfo->codec || | 232 | !cinfo->codec_dai.name || |
73 | !cinfo->platform || | 233 | !(cinfo->codec || of_codec) || |
74 | !cinfo->cpu_dai.name || | 234 | !(cinfo->platform || of_platform) || |
75 | !cinfo->codec_dai.name) { | 235 | !(cinfo->cpu_dai.name || of_cpu)) { |
76 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); | 236 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
77 | return -EINVAL; | 237 | return -EINVAL; |
78 | } | 238 | } |
@@ -86,6 +246,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
86 | cinfo->snd_link.platform_name = cinfo->platform; | 246 | cinfo->snd_link.platform_name = cinfo->platform; |
87 | cinfo->snd_link.codec_name = cinfo->codec; | 247 | cinfo->snd_link.codec_name = cinfo->codec; |
88 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; | 248 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; |
249 | cinfo->snd_link.cpu_of_node = of_cpu; | ||
250 | cinfo->snd_link.codec_of_node = of_codec; | ||
251 | cinfo->snd_link.platform_of_node = of_platform; | ||
89 | cinfo->snd_link.init = asoc_simple_card_dai_init; | 252 | cinfo->snd_link.init = asoc_simple_card_dai_init; |
90 | 253 | ||
91 | /* | 254 | /* |
@@ -95,25 +258,23 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
95 | cinfo->snd_card.owner = THIS_MODULE; | 258 | cinfo->snd_card.owner = THIS_MODULE; |
96 | cinfo->snd_card.dai_link = &cinfo->snd_link; | 259 | cinfo->snd_card.dai_link = &cinfo->snd_link; |
97 | cinfo->snd_card.num_links = 1; | 260 | cinfo->snd_card.num_links = 1; |
98 | cinfo->snd_card.dev = &pdev->dev; | ||
99 | 261 | ||
100 | return snd_soc_register_card(&cinfo->snd_card); | 262 | return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); |
101 | } | 263 | } |
102 | 264 | ||
103 | static int asoc_simple_card_remove(struct platform_device *pdev) | 265 | static const struct of_device_id asoc_simple_of_match[] = { |
104 | { | 266 | { .compatible = "simple-audio-card", }, |
105 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; | 267 | {}, |
106 | 268 | }; | |
107 | return snd_soc_unregister_card(&cinfo->snd_card); | 269 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); |
108 | } | ||
109 | 270 | ||
110 | static struct platform_driver asoc_simple_card = { | 271 | static struct platform_driver asoc_simple_card = { |
111 | .driver = { | 272 | .driver = { |
112 | .name = "asoc-simple-card", | 273 | .name = "asoc-simple-card", |
113 | .owner = THIS_MODULE, | 274 | .owner = THIS_MODULE, |
275 | .of_match_table = asoc_simple_of_match, | ||
114 | }, | 276 | }, |
115 | .probe = asoc_simple_card_probe, | 277 | .probe = asoc_simple_card_probe, |
116 | .remove = asoc_simple_card_remove, | ||
117 | }; | 278 | }; |
118 | 279 | ||
119 | module_platform_driver(asoc_simple_card); | 280 | module_platform_driver(asoc_simple_card); |