blob: 4e0c0e502ade2c228a00db3a44c44ecfa4c9978d [file] [log] [blame]
Ola Liljae0690382012-06-12 08:50:08 +02001/*
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>
Lee Jones0af541c2012-07-26 16:48:34 +010019#include <linux/of.h>
Ola Liljae0690382012-06-12 08:50:08 +020020
21#include <sound/soc.h>
22#include <sound/initval.h>
23
24#include "ux500_pcm.h"
25#include "ux500_msp_dai.h"
26
Lee Jones9fc4cd82013-01-31 12:34:00 +000027#include "mop500_ab8500.h"
Ola Liljae0690382012-06-12 08:50:08 +020028
29/* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
Lars-Peter Clausenaba1e2b2013-05-14 22:19:55 +020030static struct snd_soc_dai_link mop500_dai_links[] = {
Ola Liljae0690382012-06-12 08:50:08 +020031 {
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",
Lee Jones1428c202012-11-23 13:05:41 +000036 .platform_name = "ux500-msp-i2s.1",
Ola Liljae0690382012-06-12 08:50:08 +020037 .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",
Lee Jones1428c202012-11-23 13:05:41 +000046 .platform_name = "ux500-msp-i2s.3",
Ola Liljae0690382012-06-12 08:50:08 +020047 .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",
Wei Yongjune7c8c582013-07-02 17:25:37 +080055 .owner = THIS_MODULE,
Ola Liljae0690382012-06-12 08:50:08 +020056 .probe = NULL,
57 .dai_link = mop500_dai_links,
58 .num_links = ARRAY_SIZE(mop500_dai_links),
59};
60
Lee Jones39013bd2012-10-15 14:13:25 +010061static void mop500_of_node_put(void)
62{
63 int i;
64
65 for (i = 0; i < 2; i++) {
Markus Elfring1679b532014-12-02 17:15:11 +010066 of_node_put(mop500_dai_links[i].cpu_of_node);
67 of_node_put(mop500_dai_links[i].codec_of_node);
Lee Jones39013bd2012-10-15 14:13:25 +010068 }
69}
70
Bill Pembertonda794872012-12-07 09:26:35 -050071static int mop500_of_probe(struct platform_device *pdev,
72 struct device_node *np)
Lee Jones0af541c2012-07-26 16:48:34 +010073{
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");
Lee Jones39013bd2012-10-15 14:13:25 +010083 mop500_of_node_put();
Lee Jones0af541c2012-07-26 16:48:34 +010084 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;
Lee Jonesae276e92013-12-19 15:55:01 +000090 mop500_dai_links[i].platform_of_node = msp_np[i];
91 mop500_dai_links[i].platform_name = NULL;
Lee Jones0af541c2012-07-26 16:48:34 +010092 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}
Lee Jones39013bd2012-10-15 14:13:25 +0100100
Bill Pembertonda794872012-12-07 09:26:35 -0500101static int mop500_probe(struct platform_device *pdev)
Ola Liljae0690382012-06-12 08:50:08 +0200102{
Lee Jones0af541c2012-07-26 16:48:34 +0100103 struct device_node *np = pdev->dev.of_node;
Ola Liljae0690382012-06-12 08:50:08 +0200104 int ret;
105
Ola Liljae0690382012-06-12 08:50:08 +0200106 dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
107
108 mop500_card.dev = &pdev->dev;
109
Lee Jones0af541c2012-07-26 16:48:34 +0100110 if (np) {
111 ret = mop500_of_probe(pdev, np);
112 if (ret)
113 return ret;
114 }
115
Ola Liljae0690382012-06-12 08:50:08 +0200116 dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
117 __func__, mop500_card.name);
118 platform_set_drvdata(pdev, &mop500_card);
119
120 snd_soc_card_set_drvdata(&mop500_card, NULL);
121
122 dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
123 __func__, mop500_card.name, mop500_card.num_links);
124 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
125 __func__, mop500_card.name, mop500_card.dai_link[0].name);
126 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
127 __func__, mop500_card.name,
128 mop500_card.dai_link[0].stream_name);
129
130 ret = snd_soc_register_card(&mop500_card);
131 if (ret)
132 dev_err(&pdev->dev,
Lee Jones2087a692012-08-21 10:06:44 +0100133 "Error: snd_soc_register_card failed (%d)!\n", ret);
Ola Liljae0690382012-06-12 08:50:08 +0200134
135 return ret;
136}
137
Bill Pembertonda794872012-12-07 09:26:35 -0500138static int mop500_remove(struct platform_device *pdev)
Ola Liljae0690382012-06-12 08:50:08 +0200139{
140 struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
141
142 pr_debug("%s: Enter.\n", __func__);
143
144 snd_soc_unregister_card(mop500_card);
145 mop500_ab8500_remove(mop500_card);
Lee Jones39013bd2012-10-15 14:13:25 +0100146 mop500_of_node_put();
Lee Jones2087a692012-08-21 10:06:44 +0100147
Ola Liljae0690382012-06-12 08:50:08 +0200148 return 0;
149}
150
Lee Jones0af541c2012-07-26 16:48:34 +0100151static const struct of_device_id snd_soc_mop500_match[] = {
152 { .compatible = "stericsson,snd-soc-mop500", },
153 {},
154};
155
Ola Liljae0690382012-06-12 08:50:08 +0200156static struct platform_driver snd_soc_mop500_driver = {
157 .driver = {
Ola Liljae0690382012-06-12 08:50:08 +0200158 .name = "snd-soc-mop500",
Lee Jones0af541c2012-07-26 16:48:34 +0100159 .of_match_table = snd_soc_mop500_match,
Ola Liljae0690382012-06-12 08:50:08 +0200160 },
161 .probe = mop500_probe,
Bill Pembertonda794872012-12-07 09:26:35 -0500162 .remove = mop500_remove,
Ola Liljae0690382012-06-12 08:50:08 +0200163};
164
165module_platform_driver(snd_soc_mop500_driver);