xref: /openbmc/linux/sound/soc/ux500/mop500.c (revision 5d0e4d78)
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>
19 #include <linux/of.h>
20 
21 #include <sound/soc.h>
22 #include <sound/initval.h>
23 
24 #include "ux500_pcm.h"
25 #include "ux500_msp_dai.h"
26 
27 #include "mop500_ab8500.h"
28 
29 /* Define the whole MOP500 soundcard, linking platform to the codec-drivers  */
30 static struct snd_soc_dai_link mop500_dai_links[] = {
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",
36 		.codec_name = "ab8500-codec.0",
37 		.init = mop500_ab8500_machine_init,
38 		.ops = mop500_ab8500_ops,
39 	},
40 	{
41 		.name = "ab8500_1",
42 		.stream_name = "ab8500_1",
43 		.cpu_dai_name = "ux500-msp-i2s.3",
44 		.codec_dai_name = "ab8500-codec-dai.1",
45 		.codec_name = "ab8500-codec.0",
46 		.init = NULL,
47 		.ops = mop500_ab8500_ops,
48 	},
49 };
50 
51 static struct snd_soc_card mop500_card = {
52 	.name = "MOP500-card",
53 	.owner = THIS_MODULE,
54 	.probe = NULL,
55 	.dai_link = mop500_dai_links,
56 	.num_links = ARRAY_SIZE(mop500_dai_links),
57 };
58 
59 static void mop500_of_node_put(void)
60 {
61 	int i;
62 
63 	for (i = 0; i < 2; i++) {
64 		of_node_put(mop500_dai_links[i].cpu_of_node);
65 		of_node_put(mop500_dai_links[i].codec_of_node);
66 	}
67 }
68 
69 static int mop500_of_probe(struct platform_device *pdev,
70 			   struct device_node *np)
71 {
72 	struct device_node *codec_np, *msp_np[2];
73 	int i;
74 
75 	msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
76 	msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
77 	codec_np  = of_parse_phandle(np, "stericsson,audio-codec", 0);
78 
79 	if (!(msp_np[0] && msp_np[1] && codec_np)) {
80 		dev_err(&pdev->dev, "Phandle missing or invalid\n");
81 		mop500_of_node_put();
82 		return -EINVAL;
83 	}
84 
85 	for (i = 0; i < 2; i++) {
86 		mop500_dai_links[i].cpu_of_node = msp_np[i];
87 		mop500_dai_links[i].cpu_dai_name = NULL;
88 		mop500_dai_links[i].codec_of_node = codec_np;
89 		mop500_dai_links[i].codec_name = NULL;
90 	}
91 
92 	snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
93 
94 	return 0;
95 }
96 
97 static int mop500_probe(struct platform_device *pdev)
98 {
99 	struct device_node *np = pdev->dev.of_node;
100 	int ret;
101 
102 	dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
103 
104 	mop500_card.dev = &pdev->dev;
105 
106 	if (np) {
107 		ret = mop500_of_probe(pdev, np);
108 		if (ret)
109 			return ret;
110 	}
111 
112 	dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
113 		__func__, mop500_card.name);
114 	platform_set_drvdata(pdev, &mop500_card);
115 
116 	snd_soc_card_set_drvdata(&mop500_card, NULL);
117 
118 	dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
119 		__func__, mop500_card.name, mop500_card.num_links);
120 	dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
121 		__func__, mop500_card.name, mop500_card.dai_link[0].name);
122 	dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
123 		__func__, mop500_card.name,
124 		mop500_card.dai_link[0].stream_name);
125 
126 	ret = snd_soc_register_card(&mop500_card);
127 	if (ret)
128 		dev_err(&pdev->dev,
129 			"Error: snd_soc_register_card failed (%d)!\n", ret);
130 
131 	return ret;
132 }
133 
134 static int mop500_remove(struct platform_device *pdev)
135 {
136 	struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
137 
138 	pr_debug("%s: Enter.\n", __func__);
139 
140 	snd_soc_unregister_card(mop500_card);
141 	mop500_ab8500_remove(mop500_card);
142 	mop500_of_node_put();
143 
144 	return 0;
145 }
146 
147 static const struct of_device_id snd_soc_mop500_match[] = {
148 	{ .compatible = "stericsson,snd-soc-mop500", },
149 	{},
150 };
151 MODULE_DEVICE_TABLE(of, snd_soc_mop500_match);
152 
153 static struct platform_driver snd_soc_mop500_driver = {
154 	.driver = {
155 		.name = "snd-soc-mop500",
156 		.of_match_table = snd_soc_mop500_match,
157 	},
158 	.probe = mop500_probe,
159 	.remove = mop500_remove,
160 };
161 
162 module_platform_driver(snd_soc_mop500_driver);
163