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