Linux 3.15-rc1
[deliverable/linux.git] / sound / soc / tegra / tegra_wm9712.c
CommitLineData
6995b8cb
LS
1/*
2 * tegra20_wm9712.c - Tegra machine ASoC driver for boards using WM9712 codec.
3 *
4 * Copyright 2012 Lucas Stach <dev@lynxeye.de>
5 *
6 * Partly based on code copyright/by:
7 * Copyright 2011,2012 Toradex Inc.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/gpio.h>
24#include <linux/of_gpio.h>
25
26#include <sound/core.h>
27#include <sound/jack.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31
1ca2e847
LS
32#include "tegra_asoc_utils.h"
33
6995b8cb
LS
34#define DRV_NAME "tegra-snd-wm9712"
35
36struct tegra_wm9712 {
37 struct platform_device *codec;
1ca2e847 38 struct tegra_asoc_utils_data util_data;
6995b8cb
LS
39};
40
41static const struct snd_soc_dapm_widget tegra_wm9712_dapm_widgets[] = {
42 SND_SOC_DAPM_HP("Headphone", NULL),
43 SND_SOC_DAPM_LINE("LineIn", NULL),
44 SND_SOC_DAPM_MIC("Mic", NULL),
45};
46
47static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd)
48{
49 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 struct snd_soc_codec *codec = codec_dai->codec;
51 struct snd_soc_dapm_context *dapm = &codec->dapm;
52
53 snd_soc_dapm_force_enable_pin(dapm, "Mic Bias");
54
55 return snd_soc_dapm_sync(dapm);
56}
57
58static struct snd_soc_dai_link tegra_wm9712_dai = {
59 .name = "AC97 HiFi",
60 .stream_name = "AC97 HiFi",
6995b8cb
LS
61 .codec_dai_name = "wm9712-hifi",
62 .codec_name = "wm9712-codec",
63 .init = tegra_wm9712_init,
64};
65
66static struct snd_soc_card snd_soc_tegra_wm9712 = {
67 .name = "tegra-wm9712",
68 .owner = THIS_MODULE,
69 .dai_link = &tegra_wm9712_dai,
70 .num_links = 1,
71
72 .dapm_widgets = tegra_wm9712_dapm_widgets,
73 .num_dapm_widgets = ARRAY_SIZE(tegra_wm9712_dapm_widgets),
74 .fully_routed = true,
75};
76
77static int tegra_wm9712_driver_probe(struct platform_device *pdev)
78{
79 struct device_node *np = pdev->dev.of_node;
80 struct snd_soc_card *card = &snd_soc_tegra_wm9712;
81 struct tegra_wm9712 *machine;
82 int ret;
83
6995b8cb
LS
84 machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm9712),
85 GFP_KERNEL);
86 if (!machine) {
87 dev_err(&pdev->dev, "Can't allocate tegra_wm9712 struct\n");
88 return -ENOMEM;
89 }
90
91 card->dev = &pdev->dev;
92 platform_set_drvdata(pdev, card);
93 snd_soc_card_set_drvdata(card, machine);
94
95 machine->codec = platform_device_alloc("wm9712-codec", -1);
96 if (!machine->codec) {
97 dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n");
98 return -ENOMEM;
99 }
100
101 ret = platform_device_add(machine->codec);
102 if (ret)
103 goto codec_put;
104
105 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
106 if (ret)
107 goto codec_unregister;
108
109 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
110 if (ret)
111 goto codec_unregister;
112
113 tegra_wm9712_dai.cpu_of_node = of_parse_phandle(np,
114 "nvidia,ac97-controller", 0);
115 if (!tegra_wm9712_dai.cpu_of_node) {
116 dev_err(&pdev->dev,
117 "Property 'nvidia,ac97-controller' missing or invalid\n");
118 ret = -EINVAL;
119 goto codec_unregister;
120 }
121
122 tegra_wm9712_dai.platform_of_node = tegra_wm9712_dai.cpu_of_node;
123
1ca2e847
LS
124 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
125 if (ret)
126 goto codec_unregister;
127
128 ret = tegra_asoc_utils_set_ac97_rate(&machine->util_data);
129 if (ret)
130 goto asoc_utils_fini;
131
6995b8cb
LS
132 ret = snd_soc_register_card(card);
133 if (ret) {
134 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
135 ret);
1ca2e847 136 goto asoc_utils_fini;
6995b8cb
LS
137 }
138
139 return 0;
140
1ca2e847
LS
141asoc_utils_fini:
142 tegra_asoc_utils_fini(&machine->util_data);
6995b8cb
LS
143codec_unregister:
144 platform_device_del(machine->codec);
145codec_put:
146 platform_device_put(machine->codec);
147 return ret;
148}
149
150static int tegra_wm9712_driver_remove(struct platform_device *pdev)
151{
152 struct snd_soc_card *card = platform_get_drvdata(pdev);
153 struct tegra_wm9712 *machine = snd_soc_card_get_drvdata(card);
154
155 snd_soc_unregister_card(card);
156
1ca2e847
LS
157 tegra_asoc_utils_fini(&machine->util_data);
158
6995b8cb
LS
159 platform_device_unregister(machine->codec);
160
161 return 0;
162}
163
b10fedf8 164static const struct of_device_id tegra_wm9712_of_match[] = {
6995b8cb
LS
165 { .compatible = "nvidia,tegra-audio-wm9712", },
166 {},
167};
168
169static struct platform_driver tegra_wm9712_driver = {
170 .driver = {
171 .name = DRV_NAME,
172 .owner = THIS_MODULE,
173 .pm = &snd_soc_pm_ops,
174 .of_match_table = tegra_wm9712_of_match,
175 },
176 .probe = tegra_wm9712_driver_probe,
177 .remove = tegra_wm9712_driver_remove,
178};
179module_platform_driver(tegra_wm9712_driver);
180
181MODULE_AUTHOR("Lucas Stach");
182MODULE_DESCRIPTION("Tegra+WM9712 machine ASoC driver");
183MODULE_LICENSE("GPL v2");
184MODULE_ALIAS("platform:" DRV_NAME);
185MODULE_DEVICE_TABLE(of, tegra_wm9712_of_match);
This page took 0.085249 seconds and 5 git commands to generate.