Commit | Line | Data |
---|---|---|
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 | ||
32 | #define DRV_NAME "tegra-snd-wm9712" | |
33 | ||
34 | struct tegra_wm9712 { | |
35 | struct platform_device *codec; | |
36 | }; | |
37 | ||
38 | static const struct snd_soc_dapm_widget tegra_wm9712_dapm_widgets[] = { | |
39 | SND_SOC_DAPM_HP("Headphone", NULL), | |
40 | SND_SOC_DAPM_LINE("LineIn", NULL), | |
41 | SND_SOC_DAPM_MIC("Mic", NULL), | |
42 | }; | |
43 | ||
44 | static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd) | |
45 | { | |
46 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
47 | struct snd_soc_codec *codec = codec_dai->codec; | |
48 | struct snd_soc_dapm_context *dapm = &codec->dapm; | |
49 | ||
50 | snd_soc_dapm_force_enable_pin(dapm, "Mic Bias"); | |
51 | ||
52 | return snd_soc_dapm_sync(dapm); | |
53 | } | |
54 | ||
55 | static struct snd_soc_dai_link tegra_wm9712_dai = { | |
56 | .name = "AC97 HiFi", | |
57 | .stream_name = "AC97 HiFi", | |
58 | .cpu_dai_name = "tegra-ac97-pcm", | |
59 | .codec_dai_name = "wm9712-hifi", | |
60 | .codec_name = "wm9712-codec", | |
61 | .init = tegra_wm9712_init, | |
62 | }; | |
63 | ||
64 | static struct snd_soc_card snd_soc_tegra_wm9712 = { | |
65 | .name = "tegra-wm9712", | |
66 | .owner = THIS_MODULE, | |
67 | .dai_link = &tegra_wm9712_dai, | |
68 | .num_links = 1, | |
69 | ||
70 | .dapm_widgets = tegra_wm9712_dapm_widgets, | |
71 | .num_dapm_widgets = ARRAY_SIZE(tegra_wm9712_dapm_widgets), | |
72 | .fully_routed = true, | |
73 | }; | |
74 | ||
75 | static int tegra_wm9712_driver_probe(struct platform_device *pdev) | |
76 | { | |
77 | struct device_node *np = pdev->dev.of_node; | |
78 | struct snd_soc_card *card = &snd_soc_tegra_wm9712; | |
79 | struct tegra_wm9712 *machine; | |
80 | int ret; | |
81 | ||
82 | if (!pdev->dev.of_node) { | |
83 | dev_err(&pdev->dev, "No platform data supplied\n"); | |
84 | return -EINVAL; | |
85 | } | |
86 | ||
87 | machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm9712), | |
88 | GFP_KERNEL); | |
89 | if (!machine) { | |
90 | dev_err(&pdev->dev, "Can't allocate tegra_wm9712 struct\n"); | |
91 | return -ENOMEM; | |
92 | } | |
93 | ||
94 | card->dev = &pdev->dev; | |
95 | platform_set_drvdata(pdev, card); | |
96 | snd_soc_card_set_drvdata(card, machine); | |
97 | ||
98 | machine->codec = platform_device_alloc("wm9712-codec", -1); | |
99 | if (!machine->codec) { | |
100 | dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n"); | |
101 | return -ENOMEM; | |
102 | } | |
103 | ||
104 | ret = platform_device_add(machine->codec); | |
105 | if (ret) | |
106 | goto codec_put; | |
107 | ||
108 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); | |
109 | if (ret) | |
110 | goto codec_unregister; | |
111 | ||
112 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); | |
113 | if (ret) | |
114 | goto codec_unregister; | |
115 | ||
116 | tegra_wm9712_dai.cpu_of_node = of_parse_phandle(np, | |
117 | "nvidia,ac97-controller", 0); | |
118 | if (!tegra_wm9712_dai.cpu_of_node) { | |
119 | dev_err(&pdev->dev, | |
120 | "Property 'nvidia,ac97-controller' missing or invalid\n"); | |
121 | ret = -EINVAL; | |
122 | goto codec_unregister; | |
123 | } | |
124 | ||
125 | tegra_wm9712_dai.platform_of_node = tegra_wm9712_dai.cpu_of_node; | |
126 | ||
127 | ret = snd_soc_register_card(card); | |
128 | if (ret) { | |
129 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", | |
130 | ret); | |
131 | goto codec_unregister; | |
132 | } | |
133 | ||
134 | return 0; | |
135 | ||
136 | codec_unregister: | |
137 | platform_device_del(machine->codec); | |
138 | codec_put: | |
139 | platform_device_put(machine->codec); | |
140 | return ret; | |
141 | } | |
142 | ||
143 | static int tegra_wm9712_driver_remove(struct platform_device *pdev) | |
144 | { | |
145 | struct snd_soc_card *card = platform_get_drvdata(pdev); | |
146 | struct tegra_wm9712 *machine = snd_soc_card_get_drvdata(card); | |
147 | ||
148 | snd_soc_unregister_card(card); | |
149 | ||
150 | platform_device_unregister(machine->codec); | |
151 | ||
152 | return 0; | |
153 | } | |
154 | ||
155 | static const struct of_device_id tegra_wm9712_of_match[] __devinitconst = { | |
156 | { .compatible = "nvidia,tegra-audio-wm9712", }, | |
157 | {}, | |
158 | }; | |
159 | ||
160 | static struct platform_driver tegra_wm9712_driver = { | |
161 | .driver = { | |
162 | .name = DRV_NAME, | |
163 | .owner = THIS_MODULE, | |
164 | .pm = &snd_soc_pm_ops, | |
165 | .of_match_table = tegra_wm9712_of_match, | |
166 | }, | |
167 | .probe = tegra_wm9712_driver_probe, | |
168 | .remove = tegra_wm9712_driver_remove, | |
169 | }; | |
170 | module_platform_driver(tegra_wm9712_driver); | |
171 | ||
172 | MODULE_AUTHOR("Lucas Stach"); | |
173 | MODULE_DESCRIPTION("Tegra+WM9712 machine ASoC driver"); | |
174 | MODULE_LICENSE("GPL v2"); | |
175 | MODULE_ALIAS("platform:" DRV_NAME); | |
176 | MODULE_DEVICE_TABLE(of, tegra_wm9712_of_match); |