Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bfin-eval-adau1373.c
Go to the documentation of this file.
1 /*
2  * Machine driver for EVAL-ADAU1373 on Analog Devices bfin
3  * evaluation boards.
4  *
5  * Copyright 2011 Analog Devices Inc.
6  * Author: Lars-Peter Clausen <[email protected]>
7  *
8  * Licensed under the GPL-2 or later.
9  */
10 
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/soc.h>
16 #include <sound/pcm_params.h>
17 
18 #include "../codecs/adau1373.h"
19 
20 static const struct snd_soc_dapm_widget bfin_eval_adau1373_dapm_widgets[] = {
21  SND_SOC_DAPM_LINE("Line In1", NULL),
22  SND_SOC_DAPM_LINE("Line In2", NULL),
23  SND_SOC_DAPM_LINE("Line In3", NULL),
24  SND_SOC_DAPM_LINE("Line In4", NULL),
25 
26  SND_SOC_DAPM_LINE("Line Out1", NULL),
27  SND_SOC_DAPM_LINE("Line Out2", NULL),
28  SND_SOC_DAPM_LINE("Stereo Out", NULL),
29  SND_SOC_DAPM_HP("Headphone", NULL),
30  SND_SOC_DAPM_HP("Earpiece", NULL),
31  SND_SOC_DAPM_SPK("Speaker", NULL),
32 };
33 
34 static const struct snd_soc_dapm_route bfin_eval_adau1373_dapm_routes[] = {
35  { "AIN1L", NULL, "Line In1" },
36  { "AIN1R", NULL, "Line In1" },
37  { "AIN2L", NULL, "Line In2" },
38  { "AIN2R", NULL, "Line In2" },
39  { "AIN3L", NULL, "Line In3" },
40  { "AIN3R", NULL, "Line In3" },
41  { "AIN4L", NULL, "Line In4" },
42  { "AIN4R", NULL, "Line In4" },
43 
44  /* MICBIAS can be connected via a jumper to the line-in jack, since w
45  don't know which one is going to be used, just power both. */
46  { "Line In1", NULL, "MICBIAS1" },
47  { "Line In2", NULL, "MICBIAS1" },
48  { "Line In3", NULL, "MICBIAS1" },
49  { "Line In4", NULL, "MICBIAS1" },
50  { "Line In1", NULL, "MICBIAS2" },
51  { "Line In2", NULL, "MICBIAS2" },
52  { "Line In3", NULL, "MICBIAS2" },
53  { "Line In4", NULL, "MICBIAS2" },
54 
55  { "Line Out1", NULL, "LOUT1L" },
56  { "Line Out1", NULL, "LOUT1R" },
57  { "Line Out2", NULL, "LOUT2L" },
58  { "Line Out2", NULL, "LOUT2R" },
59  { "Headphone", NULL, "HPL" },
60  { "Headphone", NULL, "HPR" },
61  { "Earpiece", NULL, "EP" },
62  { "Speaker", NULL, "SPKL" },
63  { "Stereo Out", NULL, "SPKR" },
64 };
65 
66 static int bfin_eval_adau1373_hw_params(struct snd_pcm_substream *substream,
67  struct snd_pcm_hw_params *params)
68 {
69  struct snd_soc_pcm_runtime *rtd = substream->private_data;
70  struct snd_soc_dai *codec_dai = rtd->codec_dai;
71  int ret;
72  int pll_rate;
73 
74  switch (params_rate(params)) {
75  case 48000:
76  case 8000:
77  case 12000:
78  case 16000:
79  case 24000:
80  case 32000:
81  pll_rate = 48000 * 1024;
82  break;
83  case 44100:
84  case 7350:
85  case 11025:
86  case 14700:
87  case 22050:
88  case 29400:
89  pll_rate = 44100 * 1024;
90  break;
91  default:
92  return -EINVAL;
93  }
94 
95  ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
96  ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
97  if (ret)
98  return ret;
99 
100  ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
102 
103  return ret;
104 }
105 
106 static int bfin_eval_adau1373_codec_init(struct snd_soc_pcm_runtime *rtd)
107 {
108  struct snd_soc_dai *codec_dai = rtd->codec_dai;
109  unsigned int pll_rate = 48000 * 1024;
110  int ret;
111 
112  ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
113  ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
114  if (ret)
115  return ret;
116 
117  ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
119 
120  return ret;
121 }
122 static struct snd_soc_ops bfin_eval_adau1373_ops = {
123  .hw_params = bfin_eval_adau1373_hw_params,
124 };
125 
126 static struct snd_soc_dai_link bfin_eval_adau1373_dai = {
127  .name = "adau1373",
128  .stream_name = "adau1373",
129  .cpu_dai_name = "bfin-i2s.0",
130  .codec_dai_name = "adau1373-aif1",
131  .platform_name = "bfin-i2s-pcm-audio",
132  .codec_name = "adau1373.0-001a",
133  .ops = &bfin_eval_adau1373_ops,
134  .init = bfin_eval_adau1373_codec_init,
137 };
138 
139 static struct snd_soc_card bfin_eval_adau1373 = {
140  .name = "bfin-eval-adau1373",
141  .owner = THIS_MODULE,
142  .dai_link = &bfin_eval_adau1373_dai,
143  .num_links = 1,
144 
145  .dapm_widgets = bfin_eval_adau1373_dapm_widgets,
146  .num_dapm_widgets = ARRAY_SIZE(bfin_eval_adau1373_dapm_widgets),
147  .dapm_routes = bfin_eval_adau1373_dapm_routes,
148  .num_dapm_routes = ARRAY_SIZE(bfin_eval_adau1373_dapm_routes),
149 };
150 
151 static int bfin_eval_adau1373_probe(struct platform_device *pdev)
152 {
153  struct snd_soc_card *card = &bfin_eval_adau1373;
154 
155  card->dev = &pdev->dev;
156 
157  return snd_soc_register_card(&bfin_eval_adau1373);
158 }
159 
160 static int __devexit bfin_eval_adau1373_remove(struct platform_device *pdev)
161 {
162  struct snd_soc_card *card = platform_get_drvdata(pdev);
163 
165 
166  return 0;
167 }
168 
169 static struct platform_driver bfin_eval_adau1373_driver = {
170  .driver = {
171  .name = "bfin-eval-adau1373",
172  .owner = THIS_MODULE,
173  .pm = &snd_soc_pm_ops,
174  },
175  .probe = bfin_eval_adau1373_probe,
176  .remove = __devexit_p(bfin_eval_adau1373_remove),
177 };
178 
179 module_platform_driver(bfin_eval_adau1373_driver);
180 
181 MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
182 MODULE_DESCRIPTION("ALSA SoC bfin adau1373 driver");
183 MODULE_LICENSE("GPL");
184 MODULE_ALIAS("platform:bfin-eval-adau1373");