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