diff options
author | Jean-Francois Moine <moinejf@free.fr> | 2014-01-15 10:51:41 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-03 07:45:33 -0500 |
commit | 201a0eac7fe5e7a8fa33f0742304f885bc344d0d (patch) | |
tree | 738c13491b53bd00fe3f622c0a2b3a206e3f2a40 | |
parent | 2bee991460a838ee3c8064a6d880c4e7bc41717a (diff) |
ASoC: simple-card: simplify code
The OF pointers are put in the stack and then copied to the card
descriptor.
Put them directly at their right place.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | sound/soc/generic/simple-card.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 7c5dc7336c0b..89f83b32d86d 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c | |||
@@ -60,8 +60,9 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | |||
60 | static int | 60 | static int |
61 | asoc_simple_card_sub_parse_of(struct device_node *np, | 61 | asoc_simple_card_sub_parse_of(struct device_node *np, |
62 | struct asoc_simple_dai *dai, | 62 | struct asoc_simple_dai *dai, |
63 | struct device_node **node) | 63 | const struct device_node **p_node) |
64 | { | 64 | { |
65 | struct device_node *node; | ||
65 | struct clk *clk; | 66 | struct clk *clk; |
66 | int ret; | 67 | int ret; |
67 | 68 | ||
@@ -69,9 +70,10 @@ asoc_simple_card_sub_parse_of(struct device_node *np, | |||
69 | * get node via "sound-dai = <&phandle port>" | 70 | * get node via "sound-dai = <&phandle port>" |
70 | * it will be used as xxx_of_node on soc_bind_dai_link() | 71 | * it will be used as xxx_of_node on soc_bind_dai_link() |
71 | */ | 72 | */ |
72 | *node = of_parse_phandle(np, "sound-dai", 0); | 73 | node = of_parse_phandle(np, "sound-dai", 0); |
73 | if (!*node) | 74 | if (!node) |
74 | return -ENODEV; | 75 | return -ENODEV; |
76 | *p_node = node; | ||
75 | 77 | ||
76 | /* get dai->name */ | 78 | /* get dai->name */ |
77 | ret = snd_soc_of_get_dai_name(np, &dai->name); | 79 | ret = snd_soc_of_get_dai_name(np, &dai->name); |
@@ -104,7 +106,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np, | |||
104 | "system-clock-frequency", | 106 | "system-clock-frequency", |
105 | &dai->sysclk); | 107 | &dai->sysclk); |
106 | } else { | 108 | } else { |
107 | clk = of_clk_get(*node, 0); | 109 | clk = of_clk_get(node, 0); |
108 | if (!IS_ERR(clk)) | 110 | if (!IS_ERR(clk)) |
109 | dai->sysclk = clk_get_rate(clk); | 111 | dai->sysclk = clk_get_rate(clk); |
110 | } | 112 | } |
@@ -112,17 +114,14 @@ asoc_simple_card_sub_parse_of(struct device_node *np, | |||
112 | ret = 0; | 114 | ret = 0; |
113 | 115 | ||
114 | parse_error: | 116 | parse_error: |
115 | of_node_put(*node); | 117 | of_node_put(node); |
116 | 118 | ||
117 | return ret; | 119 | return ret; |
118 | } | 120 | } |
119 | 121 | ||
120 | static int asoc_simple_card_parse_of(struct device_node *node, | 122 | static int asoc_simple_card_parse_of(struct device_node *node, |
121 | struct asoc_simple_card_info *info, | 123 | struct asoc_simple_card_info *info, |
122 | struct device *dev, | 124 | struct device *dev) |
123 | struct device_node **of_cpu, | ||
124 | struct device_node **of_codec, | ||
125 | struct device_node **of_platform) | ||
126 | { | 125 | { |
127 | struct device_node *np; | 126 | struct device_node *np; |
128 | char *name; | 127 | char *name; |
@@ -146,7 +145,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, | |||
146 | if (np) | 145 | if (np) |
147 | ret = asoc_simple_card_sub_parse_of(np, | 146 | ret = asoc_simple_card_sub_parse_of(np, |
148 | &info->cpu_dai, | 147 | &info->cpu_dai, |
149 | of_cpu); | 148 | &info->snd_link.cpu_of_node); |
150 | if (ret < 0) | 149 | if (ret < 0) |
151 | return ret; | 150 | return ret; |
152 | 151 | ||
@@ -156,7 +155,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, | |||
156 | if (np) | 155 | if (np) |
157 | ret = asoc_simple_card_sub_parse_of(np, | 156 | ret = asoc_simple_card_sub_parse_of(np, |
158 | &info->codec_dai, | 157 | &info->codec_dai, |
159 | of_codec); | 158 | &info->snd_link.codec_of_node); |
160 | if (ret < 0) | 159 | if (ret < 0) |
161 | return ret; | 160 | return ret; |
162 | 161 | ||
@@ -173,7 +172,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, | |||
173 | info->snd_link.name = info->snd_link.stream_name = name; | 172 | info->snd_link.name = info->snd_link.stream_name = name; |
174 | 173 | ||
175 | /* simple-card assumes platform == cpu */ | 174 | /* simple-card assumes platform == cpu */ |
176 | *of_platform = *of_cpu; | 175 | info->snd_link.platform_of_node = info->snd_link.cpu_of_node; |
177 | 176 | ||
178 | dev_dbg(dev, "card-name : %s\n", name); | 177 | dev_dbg(dev, "card-name : %s\n", name); |
179 | dev_dbg(dev, "platform : %04x\n", info->daifmt); | 178 | dev_dbg(dev, "platform : %04x\n", info->daifmt); |
@@ -193,34 +192,29 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
193 | { | 192 | { |
194 | struct asoc_simple_card_info *cinfo; | 193 | struct asoc_simple_card_info *cinfo; |
195 | struct device_node *np = pdev->dev.of_node; | 194 | struct device_node *np = pdev->dev.of_node; |
196 | struct device_node *of_cpu, *of_codec, *of_platform; | ||
197 | struct device *dev = &pdev->dev; | 195 | struct device *dev = &pdev->dev; |
198 | int ret; | 196 | int ret; |
199 | 197 | ||
200 | cinfo = NULL; | ||
201 | of_cpu = NULL; | ||
202 | of_codec = NULL; | ||
203 | of_platform = NULL; | ||
204 | |||
205 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); | 198 | cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL); |
206 | if (!cinfo) | 199 | if (!cinfo) |
207 | return -ENOMEM; | 200 | return -ENOMEM; |
208 | 201 | ||
202 | /* | ||
203 | * init snd_soc_card | ||
204 | */ | ||
205 | cinfo->snd_card.owner = THIS_MODULE; | ||
206 | cinfo->snd_card.dev = dev; | ||
207 | cinfo->snd_card.dai_link = &cinfo->snd_link; | ||
208 | cinfo->snd_card.num_links = 1; | ||
209 | |||
209 | if (np && of_device_is_available(np)) { | 210 | if (np && of_device_is_available(np)) { |
210 | cinfo->snd_card.dev = dev; | ||
211 | 211 | ||
212 | ret = asoc_simple_card_parse_of(np, cinfo, dev, | 212 | ret = asoc_simple_card_parse_of(np, cinfo, dev); |
213 | &of_cpu, | ||
214 | &of_codec, | ||
215 | &of_platform); | ||
216 | if (ret < 0) { | 213 | if (ret < 0) { |
217 | if (ret != -EPROBE_DEFER) | 214 | if (ret != -EPROBE_DEFER) |
218 | dev_err(dev, "parse error %d\n", ret); | 215 | dev_err(dev, "parse error %d\n", ret); |
219 | return ret; | 216 | return ret; |
220 | } | 217 | } |
221 | cinfo->snd_link.cpu_of_node = of_cpu; | ||
222 | cinfo->snd_link.codec_of_node = of_codec; | ||
223 | cinfo->snd_link.platform_of_node = of_platform; | ||
224 | } else { | 218 | } else { |
225 | if (!dev->platform_data) { | 219 | if (!dev->platform_data) { |
226 | dev_err(dev, "no info for asoc-simple-card\n"); | 220 | dev_err(dev, "no info for asoc-simple-card\n"); |
@@ -228,8 +222,6 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
228 | } | 222 | } |
229 | 223 | ||
230 | memcpy(cinfo, dev->platform_data, sizeof(*cinfo)); | 224 | memcpy(cinfo, dev->platform_data, sizeof(*cinfo)); |
231 | cinfo->snd_card.dev = dev; | ||
232 | |||
233 | if (!cinfo->name || | 225 | if (!cinfo->name || |
234 | !cinfo->card || | 226 | !cinfo->card || |
235 | !cinfo->codec_dai.name || | 227 | !cinfo->codec_dai.name || |
@@ -254,13 +246,6 @@ static int asoc_simple_card_probe(struct platform_device *pdev) | |||
254 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; | 246 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; |
255 | cinfo->snd_link.init = asoc_simple_card_dai_init; | 247 | cinfo->snd_link.init = asoc_simple_card_dai_init; |
256 | 248 | ||
257 | /* | ||
258 | * init snd_soc_card | ||
259 | */ | ||
260 | cinfo->snd_card.owner = THIS_MODULE; | ||
261 | cinfo->snd_card.dai_link = &cinfo->snd_link; | ||
262 | cinfo->snd_card.num_links = 1; | ||
263 | |||
264 | snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo); | 249 | snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo); |
265 | 250 | ||
266 | return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); | 251 | return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); |