Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
brownstone.c
Go to the documentation of this file.
1 /*
2  * linux/sound/soc/pxa/brownstone.c
3  *
4  * Copyright (C) 2011 Marvell International Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  */
12 
13 #include <linux/module.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/soc.h>
17 #include <sound/jack.h>
18 
19 #include "../codecs/wm8994.h"
20 #include "mmp-sspa.h"
21 
22 static const struct snd_kcontrol_new brownstone_dapm_control[] = {
23  SOC_DAPM_PIN_SWITCH("Ext Spk"),
24 };
25 
26 static const struct snd_soc_dapm_widget brownstone_dapm_widgets[] = {
27  SND_SOC_DAPM_SPK("Ext Spk", NULL),
28  SND_SOC_DAPM_HP("Headset Stereophone", NULL),
29  SND_SOC_DAPM_MIC("Headset Mic", NULL),
30  SND_SOC_DAPM_MIC("Main Mic", NULL),
31 };
32 
33 static const struct snd_soc_dapm_route brownstone_audio_map[] = {
34  {"Ext Spk", NULL, "SPKOUTLP"},
35  {"Ext Spk", NULL, "SPKOUTLN"},
36  {"Ext Spk", NULL, "SPKOUTRP"},
37  {"Ext Spk", NULL, "SPKOUTRN"},
38 
39  {"Headset Stereophone", NULL, "HPOUT1L"},
40  {"Headset Stereophone", NULL, "HPOUT1R"},
41 
42  {"IN1RN", NULL, "Headset Mic"},
43 
44  {"DMIC1DAT", NULL, "MICBIAS1"},
45  {"MICBIAS1", NULL, "Main Mic"},
46 };
47 
48 static int brownstone_wm8994_init(struct snd_soc_pcm_runtime *rtd)
49 {
50  struct snd_soc_codec *codec = rtd->codec;
51  struct snd_soc_dapm_context *dapm = &codec->dapm;
52 
53  snd_soc_dapm_enable_pin(dapm, "Ext Spk");
54  snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
55  snd_soc_dapm_enable_pin(dapm, "Headset Mic");
56  snd_soc_dapm_enable_pin(dapm, "Main Mic");
57 
58  /* set endpoints to not connected */
59  snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
60  snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
61  snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
62  snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
63  snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
64  snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
65  snd_soc_dapm_nc_pin(dapm, "IN1LN");
66  snd_soc_dapm_nc_pin(dapm, "IN1LP");
67  snd_soc_dapm_nc_pin(dapm, "IN1RP");
68  snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
69  snd_soc_dapm_nc_pin(dapm, "IN2RN");
70  snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
71  snd_soc_dapm_nc_pin(dapm, "IN2LN");
72 
73  snd_soc_dapm_sync(dapm);
74 
75  return 0;
76 }
77 
78 static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream,
79  struct snd_pcm_hw_params *params)
80 {
81  struct snd_soc_pcm_runtime *rtd = substream->private_data;
82  struct snd_soc_dai *codec_dai = rtd->codec_dai;
83  struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
84  int freq_out, sspa_mclk, sysclk;
85  int sspa_div;
86 
87  if (params_rate(params) > 11025) {
88  freq_out = params_rate(params) * 512;
89  sysclk = params_rate(params) * 256;
90  sspa_mclk = params_rate(params) * 64;
91  } else {
92  freq_out = params_rate(params) * 1024;
93  sysclk = params_rate(params) * 512;
94  sspa_mclk = params_rate(params) * 64;
95  }
96  sspa_div = freq_out;
97  do_div(sspa_div, sspa_mclk);
98 
99  snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
100  snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
101  snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
102 
103  /* set wm8994 sysclk */
104  snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
105 
106  return 0;
107 }
108 
109 /* machine stream operations */
110 static struct snd_soc_ops brownstone_ops = {
111  .hw_params = brownstone_wm8994_hw_params,
112 };
113 
114 static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
115 {
116  .name = "WM8994",
117  .stream_name = "WM8994 HiFi",
118  .cpu_dai_name = "mmp-sspa-dai.0",
119  .codec_dai_name = "wm8994-aif1",
120  .platform_name = "mmp-pcm-audio",
121  .codec_name = "wm8994-codec",
124  .ops = &brownstone_ops,
125  .init = brownstone_wm8994_init,
126 },
127 };
128 
129 /* audio machine driver */
130 static struct snd_soc_card brownstone = {
131  .name = "brownstone",
132  .dai_link = brownstone_wm8994_dai,
133  .num_links = ARRAY_SIZE(brownstone_wm8994_dai),
134 
135  .controls = brownstone_dapm_control,
136  .num_controls = ARRAY_SIZE(brownstone_dapm_control),
137  .dapm_widgets = brownstone_dapm_widgets,
138  .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
139  .dapm_routes = brownstone_audio_map,
140  .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
141 };
142 
143 static int __devinit brownstone_probe(struct platform_device *pdev)
144 {
145  int ret;
146 
147  brownstone.dev = &pdev->dev;
148  ret = snd_soc_register_card(&brownstone);
149  if (ret)
150  dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
151  ret);
152  return ret;
153 }
154 
155 static int __devexit brownstone_remove(struct platform_device *pdev)
156 {
157  snd_soc_unregister_card(&brownstone);
158  return 0;
159 }
160 
161 static struct platform_driver mmp_driver = {
162  .driver = {
163  .name = "brownstone-audio",
164  .owner = THIS_MODULE,
165  },
166  .probe = brownstone_probe,
167  .remove = __devexit_p(brownstone_remove),
168 };
169 
170 module_platform_driver(mmp_driver);
171 
172 MODULE_AUTHOR("Leo Yan <[email protected]>");
173 MODULE_DESCRIPTION("ALSA SoC Brownstone");
174 MODULE_LICENSE("GPL");