]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - sound/soc/ux500/mop500.c
ASoC: codecs: Enable AB8500 CODEC for Device Tree
[mirror_ubuntu-artful-kernel.git] / sound / soc / ux500 / mop500.c
CommitLineData
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
27#include <mop500_ab8500.h>
28
29/* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
30struct 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 .platform_name = "ux500-pcm.0",
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",
46 .platform_name = "ux500-pcm.0",
47 .codec_name = "ab8500-codec.0",
48 .init = NULL,
49 .ops = mop500_ab8500_ops,
50 },
51};
52
53static struct snd_soc_card mop500_card = {
54 .name = "MOP500-card",
55 .probe = NULL,
56 .dai_link = mop500_dai_links,
57 .num_links = ARRAY_SIZE(mop500_dai_links),
58};
59
0af541ce
LJ
60static int __devinit mop500_of_probe(struct platform_device *pdev,
61 struct device_node *np)
62{
63 struct device_node *codec_np, *msp_np[2];
64 int i;
65
66 msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
67 msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
68 codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0);
69
70 if (!(msp_np[0] && msp_np[1] && codec_np)) {
71 dev_err(&pdev->dev, "Phandle missing or invalid\n");
72 return -EINVAL;
73 }
74
75 for (i = 0; i < 2; i++) {
76 mop500_dai_links[i].cpu_of_node = msp_np[i];
77 mop500_dai_links[i].cpu_dai_name = NULL;
78 mop500_dai_links[i].codec_of_node = codec_np;
79 mop500_dai_links[i].codec_name = NULL;
80 }
81
82 snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
83
84 return 0;
85}
e0690385
OL
86static int __devinit mop500_probe(struct platform_device *pdev)
87{
0af541ce 88 struct device_node *np = pdev->dev.of_node;
e0690385
OL
89 int ret;
90
91 pr_debug("%s: Enter.\n", __func__);
92
93 dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
94
95 mop500_card.dev = &pdev->dev;
96
0af541ce
LJ
97 if (np) {
98 ret = mop500_of_probe(pdev, np);
99 if (ret)
100 return ret;
101 }
102
e0690385
OL
103 dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
104 __func__, mop500_card.name);
105 platform_set_drvdata(pdev, &mop500_card);
106
107 snd_soc_card_set_drvdata(&mop500_card, NULL);
108
109 dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
110 __func__, mop500_card.name, mop500_card.num_links);
111 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
112 __func__, mop500_card.name, mop500_card.dai_link[0].name);
113 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
114 __func__, mop500_card.name,
115 mop500_card.dai_link[0].stream_name);
116
117 ret = snd_soc_register_card(&mop500_card);
118 if (ret)
119 dev_err(&pdev->dev,
120 "Error: snd_soc_register_card failed (%d)!\n",
121 ret);
122
123 return ret;
124}
125
126static int __devexit mop500_remove(struct platform_device *pdev)
127{
128 struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
129
130 pr_debug("%s: Enter.\n", __func__);
131
132 snd_soc_unregister_card(mop500_card);
133 mop500_ab8500_remove(mop500_card);
134
135 return 0;
136}
137
0af541ce
LJ
138static const struct of_device_id snd_soc_mop500_match[] = {
139 { .compatible = "stericsson,snd-soc-mop500", },
140 {},
141};
142
e0690385
OL
143static struct platform_driver snd_soc_mop500_driver = {
144 .driver = {
145 .owner = THIS_MODULE,
146 .name = "snd-soc-mop500",
0af541ce 147 .of_match_table = snd_soc_mop500_match,
e0690385
OL
148 },
149 .probe = mop500_probe,
150 .remove = __devexit_p(mop500_remove),
151};
152
153module_platform_driver(snd_soc_mop500_driver);