Version:  2.6.34 2.6.35 2.6.36 2.6.37 2.6.38 2.6.39 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14

Linux/sound/soc/tegra/tegra_wm9712.c

  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         .codec_dai_name = "wm9712-hifi",
 59         .codec_name = "wm9712-codec",
 60         .init = tegra_wm9712_init,
 61 };
 62 
 63 static struct snd_soc_card snd_soc_tegra_wm9712 = {
 64         .name = "tegra-wm9712",
 65         .owner = THIS_MODULE,
 66         .dai_link = &tegra_wm9712_dai,
 67         .num_links = 1,
 68 
 69         .dapm_widgets = tegra_wm9712_dapm_widgets,
 70         .num_dapm_widgets = ARRAY_SIZE(tegra_wm9712_dapm_widgets),
 71         .fully_routed = true,
 72 };
 73 
 74 static int tegra_wm9712_driver_probe(struct platform_device *pdev)
 75 {
 76         struct device_node *np = pdev->dev.of_node;
 77         struct snd_soc_card *card = &snd_soc_tegra_wm9712;
 78         struct tegra_wm9712 *machine;
 79         int ret;
 80 
 81         machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm9712),
 82                                GFP_KERNEL);
 83         if (!machine) {
 84                 dev_err(&pdev->dev, "Can't allocate tegra_wm9712 struct\n");
 85                 return -ENOMEM;
 86         }
 87 
 88         card->dev = &pdev->dev;
 89         platform_set_drvdata(pdev, card);
 90         snd_soc_card_set_drvdata(card, machine);
 91 
 92         machine->codec = platform_device_alloc("wm9712-codec", -1);
 93         if (!machine->codec) {
 94                 dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n");
 95                 return -ENOMEM;
 96         }
 97 
 98         ret = platform_device_add(machine->codec);
 99         if (ret)
100                 goto codec_put;
101 
102         ret = snd_soc_of_parse_card_name(card, "nvidia,model");
103         if (ret)
104                 goto codec_unregister;
105 
106         ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
107         if (ret)
108                 goto codec_unregister;
109 
110         tegra_wm9712_dai.cpu_of_node = of_parse_phandle(np,
111                                        "nvidia,ac97-controller", 0);
112         if (!tegra_wm9712_dai.cpu_of_node) {
113                 dev_err(&pdev->dev,
114                         "Property 'nvidia,ac97-controller' missing or invalid\n");
115                 ret = -EINVAL;
116                 goto codec_unregister;
117         }
118 
119         tegra_wm9712_dai.platform_of_node = tegra_wm9712_dai.cpu_of_node;
120 
121         ret = snd_soc_register_card(card);
122         if (ret) {
123                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
124                         ret);
125                 goto codec_unregister;
126         }
127 
128         return 0;
129 
130 codec_unregister:
131         platform_device_del(machine->codec);
132 codec_put:
133         platform_device_put(machine->codec);
134         return ret;
135 }
136 
137 static int tegra_wm9712_driver_remove(struct platform_device *pdev)
138 {
139         struct snd_soc_card *card = platform_get_drvdata(pdev);
140         struct tegra_wm9712 *machine = snd_soc_card_get_drvdata(card);
141 
142         snd_soc_unregister_card(card);
143 
144         platform_device_unregister(machine->codec);
145 
146         return 0;
147 }
148 
149 static const struct of_device_id tegra_wm9712_of_match[] = {
150         { .compatible = "nvidia,tegra-audio-wm9712", },
151         {},
152 };
153 
154 static struct platform_driver tegra_wm9712_driver = {
155         .driver = {
156                 .name = DRV_NAME,
157                 .owner = THIS_MODULE,
158                 .pm = &snd_soc_pm_ops,
159                 .of_match_table = tegra_wm9712_of_match,
160         },
161         .probe = tegra_wm9712_driver_probe,
162         .remove = tegra_wm9712_driver_remove,
163 };
164 module_platform_driver(tegra_wm9712_driver);
165 
166 MODULE_AUTHOR("Lucas Stach");
167 MODULE_DESCRIPTION("Tegra+WM9712 machine ASoC driver");
168 MODULE_LICENSE("GPL v2");
169 MODULE_ALIAS("platform:" DRV_NAME);
170 MODULE_DEVICE_TABLE(of, tegra_wm9712_of_match);
171 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us