diff options
-rw-r--r-- | Documentation/devicetree/bindings/sound/simple-card.txt | 68 | ||||
-rw-r--r-- | sound/soc/generic/simple-card.c | 159 |
2 files changed, 221 insertions, 6 deletions
diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt new file mode 100644 index 000000000000..769a346f890c --- /dev/null +++ b/Documentation/devicetree/bindings/sound/simple-card.txt | |||
@@ -0,0 +1,68 @@ | |||
1 | Simple-Card: | ||
2 | |||
3 | Simple-Card specifies audio DAI connection of SoC <-> codec. | ||
4 | |||
5 | Required properties: | ||
6 | |||
7 | - compatible : "simple-audio-card" | ||
8 | |||
9 | Optional properties: | ||
10 | |||
11 | - simple-audio-card,format : CPU/CODEC common audio format. | ||
12 | "i2s", "right_j", "left_j" , "dsp_a" | ||
13 | "dsp_b", "ac97", "pdm", "msb", "lsb" | ||
14 | Required subnodes: | ||
15 | |||
16 | - simple-audio-card,cpu : CPU sub-node | ||
17 | - simple-audio-card,codec : CODEC sub-node | ||
18 | |||
19 | Required CPU/CODEC subnodes properties: | ||
20 | |||
21 | - sound-dai : phandle and port of CPU/CODEC | ||
22 | |||
23 | Optional CPU/CODEC subnodes properties: | ||
24 | |||
25 | - format : CPU/CODEC specific audio format if needed. | ||
26 | see simple-audio-card,format | ||
27 | - frame-master : bool property. add this if subnode is frame master | ||
28 | - bitclock-master : bool property. add this if subnode is bitclock master | ||
29 | - bitclock-inversion : bool property. add this if subnode has clock inversion | ||
30 | - frame-inversion : bool property. add this if subnode has frame inversion | ||
31 | - clocks / system-clock-frequency : specify subnode's clock if needed. | ||
32 | it can be specified via "clocks" if system has | ||
33 | clock node (= common clock), or "system-clock-frequency" | ||
34 | (if system doens't support common clock) | ||
35 | |||
36 | Example: | ||
37 | |||
38 | sound { | ||
39 | compatible = "simple-audio-card"; | ||
40 | simple-audio-card,format = "left_j"; | ||
41 | |||
42 | simple-audio-card,cpu { | ||
43 | sound-dai = <&sh_fsi2 0>; | ||
44 | }; | ||
45 | |||
46 | simple-audio-card,codec { | ||
47 | sound-dai = <&ak4648>; | ||
48 | bitclock-master; | ||
49 | frame-master; | ||
50 | clocks = <&osc>; | ||
51 | }; | ||
52 | }; | ||
53 | |||
54 | &i2c0 { | ||
55 | ak4648: ak4648@12 { | ||
56 | #sound-dai-cells = <0>; | ||
57 | compatible = "asahi-kasei,ak4648"; | ||
58 | reg = <0x12>; | ||
59 | }; | ||
60 | }; | ||
61 | |||
62 | sh_fsi2: sh_fsi2@ec230000 { | ||
63 | #sound-dai-cells = <1>; | ||
64 | compatible = "renesas,sh_fsi2"; | ||
65 | reg = <0xec230000 0x400>; | ||
66 | interrupt-parent = <&gic>; | ||
67 | interrupts = <0 146 0x4>; | ||
68 | }; | ||
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index b2fbb7075a6c..be7c1db5388f 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> |
@@ -57,11 +58,147 @@ 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 | */ | ||
94 | clk = of_clk_get(np, 0); | ||
95 | if (IS_ERR(clk)) | ||
96 | of_property_read_u32(np, | ||
97 | "system-clock-frequency", | ||
98 | &dai->sysclk); | ||
99 | else | ||
100 | dai->sysclk = clk_get_rate(clk); | ||
101 | |||
102 | ret = 0; | ||
103 | |||
104 | parse_error: | ||
105 | of_node_put(*node); | ||
106 | |||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | static int asoc_simple_card_parse_of(struct device_node *node, | ||
111 | struct asoc_simple_card_info *info, | ||
112 | struct device *dev, | ||
113 | struct device_node **of_cpu, | ||
114 | struct device_node **of_codec, | ||
115 | struct device_node **of_platform) | ||
116 | { | ||
117 | struct device_node *np; | ||
118 | char *name; | ||
119 | int ret = 0; | ||
120 | |||
121 | /* get CPU/CODEC common format via simple-audio-card,format */ | ||
122 | info->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") & | ||
123 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); | ||
124 | |||
125 | /* CPU sub-node */ | ||
126 | ret = -EINVAL; | ||
127 | np = of_get_child_by_name(node, "simple-audio-card,cpu"); | ||
128 | if (np) | ||
129 | ret = asoc_simple_card_sub_parse_of(np, | ||
130 | &info->cpu_dai, | ||
131 | of_cpu); | ||
132 | if (ret < 0) | ||
133 | return ret; | ||
134 | |||
135 | /* CODEC sub-node */ | ||
136 | ret = -EINVAL; | ||
137 | np = of_get_child_by_name(node, "simple-audio-card,codec"); | ||
138 | if (np) | ||
139 | ret = asoc_simple_card_sub_parse_of(np, | ||
140 | &info->codec_dai, | ||
141 | of_codec); | ||
142 | if (ret < 0) | ||
143 | return ret; | ||
144 | |||
145 | if (!info->cpu_dai.name || !info->codec_dai.name) | ||
146 | return -EINVAL; | ||
147 | |||
148 | /* card name is created from CPU/CODEC dai name */ | ||
149 | name = devm_kzalloc(dev, | ||
150 | strlen(info->cpu_dai.name) + | ||
151 | strlen(info->codec_dai.name) + 2, | ||
152 | GFP_KERNEL); | ||
153 | sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name); | ||
154 | info->name = info->card = name; | ||
155 | |||
156 | /* simple-card assumes platform == cpu */ | ||
157 | *of_platform = *of_cpu; | ||
158 | |||
159 | dev_dbg(dev, "card-name : %s\n", info->card); | ||
160 | dev_dbg(dev, "platform : %04x\n", info->daifmt); | ||
161 | dev_dbg(dev, "cpu : %s / %04x / %d\n", | ||
162 | info->cpu_dai.name, | ||
163 | info->cpu_dai.fmt, | ||
164 | info->cpu_dai.sysclk); | ||
165 | dev_dbg(dev, "codec : %s / %04x / %d\n", | ||
166 | info->codec_dai.name, | ||
167 | info->codec_dai.fmt, | ||
168 | info->codec_dai.sysclk); | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
60 | static int asoc_simple_card_probe(struct platform_device *pdev) | 173 | static int asoc_simple_card_probe(struct platform_device *pdev) |
61 | { | 174 | { |
62 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; | 175 | struct asoc_simple_card_info *cinfo; |
176 | struct device_node *np = pdev->dev.of_node; | ||
177 | struct device_node *of_cpu, *of_codec, *of_platform; | ||
63 | struct device *dev = &pdev->dev; | 178 | struct device *dev = &pdev->dev; |
64 | 179 | ||
180 | cinfo = NULL; | ||
181 | of_cpu = NULL; | ||
182 | of_codec = NULL; | ||
183 | of_platform = NULL; | ||
184 | if (np && of_device_is_available(np)) { | ||
185 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); | ||
186 | if (cinfo) { | ||
187 | int ret; | ||
188 | ret = asoc_simple_card_parse_of(np, cinfo, dev, | ||
189 | &of_cpu, | ||
190 | &of_codec, | ||
191 | &of_platform); | ||
192 | if (ret < 0) { | ||
193 | if (ret != -EPROBE_DEFER) | ||
194 | dev_err(dev, "parse error %d\n", ret); | ||
195 | return ret; | ||
196 | } | ||
197 | } | ||
198 | } else { | ||
199 | cinfo = pdev->dev.platform_data; | ||
200 | } | ||
201 | |||
65 | if (!cinfo) { | 202 | if (!cinfo) { |
66 | dev_err(dev, "no info for asoc-simple-card\n"); | 203 | dev_err(dev, "no info for asoc-simple-card\n"); |
67 | return -EINVAL; | 204 | return -EINVAL; |
@@ -69,10 +206,10 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
69 | 206 | ||
70 | if (!cinfo->name || | 207 | if (!cinfo->name || |
71 | !cinfo->card || | 208 | !cinfo->card || |
72 | !cinfo->codec || | 209 | !cinfo->codec_dai.name || |
73 | !cinfo->platform || | 210 | !(cinfo->codec || of_codec) || |
74 | !cinfo->cpu_dai.name || | 211 | !(cinfo->platform || of_platform) || |
75 | !cinfo->codec_dai.name) { | 212 | !(cinfo->cpu_dai.name || of_cpu)) { |
76 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); | 213 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
77 | return -EINVAL; | 214 | return -EINVAL; |
78 | } | 215 | } |
@@ -86,6 +223,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
86 | cinfo->snd_link.platform_name = cinfo->platform; | 223 | cinfo->snd_link.platform_name = cinfo->platform; |
87 | cinfo->snd_link.codec_name = cinfo->codec; | 224 | cinfo->snd_link.codec_name = cinfo->codec; |
88 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; | 225 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; |
226 | cinfo->snd_link.cpu_of_node = of_cpu; | ||
227 | cinfo->snd_link.codec_of_node = of_codec; | ||
228 | cinfo->snd_link.platform_of_node = of_platform; | ||
89 | cinfo->snd_link.init = asoc_simple_card_dai_init; | 229 | cinfo->snd_link.init = asoc_simple_card_dai_init; |
90 | 230 | ||
91 | /* | 231 | /* |
@@ -107,10 +247,17 @@ static int asoc_simple_card_remove(struct platform_device *pdev) | |||
107 | return snd_soc_unregister_card(&cinfo->snd_card); | 247 | return snd_soc_unregister_card(&cinfo->snd_card); |
108 | } | 248 | } |
109 | 249 | ||
250 | static const struct of_device_id asoc_simple_of_match[] = { | ||
251 | { .compatible = "simple-audio-card", }, | ||
252 | {}, | ||
253 | }; | ||
254 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); | ||
255 | |||
110 | static struct platform_driver asoc_simple_card = { | 256 | static struct platform_driver asoc_simple_card = { |
111 | .driver = { | 257 | .driver = { |
112 | .name = "asoc-simple-card", | 258 | .name = "asoc-simple-card", |
113 | .owner = THIS_MODULE, | 259 | .owner = THIS_MODULE, |
260 | .of_match_table = asoc_simple_of_match, | ||
114 | }, | 261 | }, |
115 | .probe = asoc_simple_card_probe, | 262 | .probe = asoc_simple_card_probe, |
116 | .remove = asoc_simple_card_remove, | 263 | .remove = asoc_simple_card_remove, |