1
2
3
4
5
6
7
8
9#include <linux/module.h>
10#include <linux/of_address.h>
11#include <sound/soc.h>
12
13#include "fsl_utils.h"
14
15
16
17
18
19
20
21
22
23
24
25
26
27int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
28 const char *name,
29 struct snd_soc_dai_link *dai,
30 unsigned int *dma_channel_id,
31 unsigned int *dma_id)
32{
33 struct resource res;
34 struct device_node *dma_channel_np, *dma_np;
35 const __be32 *iprop;
36 int ret;
37
38 dma_channel_np = of_parse_phandle(ssi_np, name, 0);
39 if (!dma_channel_np)
40 return -EINVAL;
41
42 if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) {
43 of_node_put(dma_channel_np);
44 return -EINVAL;
45 }
46
47
48
49
50
51
52
53
54
55 ret = of_address_to_resource(dma_channel_np, 0, &res);
56 if (ret) {
57 of_node_put(dma_channel_np);
58 return ret;
59 }
60 snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%pOFn",
61 (unsigned long long) res.start, dma_channel_np);
62
63 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
64 if (!iprop) {
65 of_node_put(dma_channel_np);
66 return -EINVAL;
67 }
68 *dma_channel_id = be32_to_cpup(iprop);
69
70 dma_np = of_get_parent(dma_channel_np);
71 iprop = of_get_property(dma_np, "cell-index", NULL);
72 if (!iprop) {
73 of_node_put(dma_np);
74 of_node_put(dma_channel_np);
75 return -EINVAL;
76 }
77 *dma_id = be32_to_cpup(iprop);
78
79 of_node_put(dma_np);
80 of_node_put(dma_channel_np);
81
82 return 0;
83}
84EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
85
86MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
87MODULE_DESCRIPTION("Freescale ASoC utility code");
88MODULE_LICENSE("GPL v2");
89