iwl3945: do not print RFKILL message
[linux/fpc-iii.git] / sound / soc / atmel / sam9x5_wm8731.c
blob992ae38d5a15afda177080da1032300bcffd18ac
1 /*
2 * sam9x5_wm8731 -- SoC audio for AT91SAM9X5-based boards
3 * that are using WM8731 as codec.
5 * Copyright (C) 2011 Atmel,
6 * Nicolas Ferre <nicolas.ferre@atmel.com>
8 * Copyright (C) 2013 Paratronic,
9 * Richard Genoud <richard.genoud@gmail.com>
11 * Based on sam9g20_wm8731.c by:
12 * Sedji Gaouaou <sedji.gaouaou@atmel.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
20 #include <linux/of.h>
21 #include <linux/export.h>
22 #include <linux/module.h>
23 #include <linux/mod_devicetable.h>
24 #include <linux/platform_device.h>
25 #include <linux/device.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dai.h>
29 #include <sound/soc-dapm.h>
31 #include "../codecs/wm8731.h"
32 #include "atmel_ssc_dai.h"
35 #define MCLK_RATE 12288000
37 #define DRV_NAME "sam9x5-snd-wm8731"
39 struct sam9x5_drvdata {
40 int ssc_id;
44 * Logic for a wm8731 as connected on a at91sam9x5ek based board.
46 static int sam9x5_wm8731_init(struct snd_soc_pcm_runtime *rtd)
48 struct snd_soc_dai *codec_dai = rtd->codec_dai;
49 struct device *dev = rtd->dev;
50 int ret;
52 dev_dbg(dev, "ASoC: %s called\n", __func__);
54 /* set the codec system clock for DAC and ADC */
55 ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
56 MCLK_RATE, SND_SOC_CLOCK_IN);
57 if (ret < 0) {
58 dev_err(dev, "ASoC: Failed to set WM8731 SYSCLK: %d\n", ret);
59 return ret;
62 return 0;
66 * Audio paths on at91sam9x5ek board:
68 * |A| ------------> | | ---R----> Headphone Jack
69 * |T| <----\ | WM | ---L--/
70 * |9| ---> CLK <--> | 8731 | <--R----- Line In Jack
71 * |1| <------------ | | <--L--/
73 static const struct snd_soc_dapm_widget sam9x5_dapm_widgets[] = {
74 SND_SOC_DAPM_HP("Headphone Jack", NULL),
75 SND_SOC_DAPM_LINE("Line In Jack", NULL),
78 static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
80 struct device_node *np = pdev->dev.of_node;
81 struct device_node *codec_np, *cpu_np;
82 struct snd_soc_card *card;
83 struct snd_soc_dai_link *dai;
84 struct sam9x5_drvdata *priv;
85 int ret;
87 if (!np) {
88 dev_err(&pdev->dev, "No device node supplied\n");
89 return -EINVAL;
92 card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL);
93 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
94 dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL);
95 if (!dai || !card || !priv) {
96 ret = -ENOMEM;
97 goto out;
100 card->dev = &pdev->dev;
101 card->owner = THIS_MODULE;
102 card->dai_link = dai;
103 card->num_links = 1;
104 card->dapm_widgets = sam9x5_dapm_widgets;
105 card->num_dapm_widgets = ARRAY_SIZE(sam9x5_dapm_widgets);
106 dai->name = "WM8731";
107 dai->stream_name = "WM8731 PCM";
108 dai->codec_dai_name = "wm8731-hifi";
109 dai->init = sam9x5_wm8731_init;
110 dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
111 | SND_SOC_DAIFMT_CBM_CFM;
113 ret = snd_soc_of_parse_card_name(card, "atmel,model");
114 if (ret) {
115 dev_err(&pdev->dev, "atmel,model node missing\n");
116 goto out;
119 ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing");
120 if (ret) {
121 dev_err(&pdev->dev, "atmel,audio-routing node missing\n");
122 goto out;
125 codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
126 if (!codec_np) {
127 dev_err(&pdev->dev, "atmel,audio-codec node missing\n");
128 ret = -EINVAL;
129 goto out;
132 dai->codec_of_node = codec_np;
134 cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
135 if (!cpu_np) {
136 dev_err(&pdev->dev, "atmel,ssc-controller node missing\n");
137 ret = -EINVAL;
138 goto out;
140 dai->cpu_of_node = cpu_np;
141 dai->platform_of_node = cpu_np;
143 priv->ssc_id = of_alias_get_id(cpu_np, "ssc");
145 ret = atmel_ssc_set_audio(priv->ssc_id);
146 if (ret != 0) {
147 dev_err(&pdev->dev,
148 "ASoC: Failed to set SSC %d for audio: %d\n",
149 ret, priv->ssc_id);
150 goto out;
153 of_node_put(codec_np);
154 of_node_put(cpu_np);
156 platform_set_drvdata(pdev, card);
158 ret = snd_soc_register_card(card);
159 if (ret) {
160 dev_err(&pdev->dev,
161 "ASoC: Platform device allocation failed\n");
162 goto out_put_audio;
165 dev_dbg(&pdev->dev, "ASoC: %s ok\n", __func__);
167 return ret;
169 out_put_audio:
170 atmel_ssc_put_audio(priv->ssc_id);
171 out:
172 return ret;
175 static int sam9x5_wm8731_driver_remove(struct platform_device *pdev)
177 struct snd_soc_card *card = platform_get_drvdata(pdev);
178 struct sam9x5_drvdata *priv = card->drvdata;
180 snd_soc_unregister_card(card);
181 atmel_ssc_put_audio(priv->ssc_id);
183 return 0;
186 static const struct of_device_id sam9x5_wm8731_of_match[] = {
187 { .compatible = "atmel,sam9x5-wm8731-audio", },
190 MODULE_DEVICE_TABLE(of, sam9x5_wm8731_of_match);
192 static struct platform_driver sam9x5_wm8731_driver = {
193 .driver = {
194 .name = DRV_NAME,
195 .owner = THIS_MODULE,
196 .of_match_table = of_match_ptr(sam9x5_wm8731_of_match),
198 .probe = sam9x5_wm8731_driver_probe,
199 .remove = sam9x5_wm8731_driver_remove,
201 module_platform_driver(sam9x5_wm8731_driver);
203 /* Module information */
204 MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>");
205 MODULE_AUTHOR("Richard Genoud <richard.genoud@gmail.com>");
206 MODULE_DESCRIPTION("ALSA SoC machine driver for AT91SAM9x5 - WM8731");
207 MODULE_LICENSE("GPL");
208 MODULE_ALIAS("platform:" DRV_NAME);