2 * linux/sound/soc/pxa/brownstone.c
4 * Copyright (C) 2011 Marvell International Ltd.
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.
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>
19 #include "../codecs/wm8994.h"
22 static const struct snd_kcontrol_new brownstone_dapm_control
[] = {
23 SOC_DAPM_PIN_SWITCH("Ext Spk"),
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
),
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"},
39 {"Headset Stereophone", NULL
, "HPOUT1L"},
40 {"Headset Stereophone", NULL
, "HPOUT1R"},
42 {"IN1RN", NULL
, "Headset Mic"},
44 {"DMIC1DAT", NULL
, "MICBIAS1"},
45 {"MICBIAS1", NULL
, "Main Mic"},
48 static int brownstone_wm8994_init(struct snd_soc_pcm_runtime
*rtd
)
50 struct snd_soc_codec
*codec
= rtd
->codec
;
51 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
53 /* set endpoints to not connected */
54 snd_soc_dapm_nc_pin(dapm
, "HPOUT2P");
55 snd_soc_dapm_nc_pin(dapm
, "HPOUT2N");
56 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1N");
57 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1P");
58 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2N");
59 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2P");
60 snd_soc_dapm_nc_pin(dapm
, "IN1LN");
61 snd_soc_dapm_nc_pin(dapm
, "IN1LP");
62 snd_soc_dapm_nc_pin(dapm
, "IN1RP");
63 snd_soc_dapm_nc_pin(dapm
, "IN2LP:VXRN");
64 snd_soc_dapm_nc_pin(dapm
, "IN2RN");
65 snd_soc_dapm_nc_pin(dapm
, "IN2RP:VXRP");
66 snd_soc_dapm_nc_pin(dapm
, "IN2LN");
71 static int brownstone_wm8994_hw_params(struct snd_pcm_substream
*substream
,
72 struct snd_pcm_hw_params
*params
)
74 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
75 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
76 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
77 int freq_out
, sspa_mclk
, sysclk
;
80 if (params_rate(params
) > 11025) {
81 freq_out
= params_rate(params
) * 512;
82 sysclk
= params_rate(params
) * 256;
83 sspa_mclk
= params_rate(params
) * 64;
85 freq_out
= params_rate(params
) * 1024;
86 sysclk
= params_rate(params
) * 512;
87 sspa_mclk
= params_rate(params
) * 64;
90 do_div(sspa_div
, sspa_mclk
);
92 snd_soc_dai_set_sysclk(cpu_dai
, MMP_SSPA_CLK_AUDIO
, freq_out
, 0);
93 snd_soc_dai_set_pll(cpu_dai
, MMP_SYSCLK
, 0, freq_out
, sysclk
);
94 snd_soc_dai_set_pll(cpu_dai
, MMP_SSPA_CLK
, 0, freq_out
, sspa_mclk
);
96 /* set wm8994 sysclk */
97 snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_MCLK1
, sysclk
, 0);
102 /* machine stream operations */
103 static struct snd_soc_ops brownstone_ops
= {
104 .hw_params
= brownstone_wm8994_hw_params
,
107 static struct snd_soc_dai_link brownstone_wm8994_dai
[] = {
110 .stream_name
= "WM8994 HiFi",
111 .cpu_dai_name
= "mmp-sspa-dai.0",
112 .codec_dai_name
= "wm8994-aif1",
113 .platform_name
= "mmp-pcm-audio",
114 .codec_name
= "wm8994-codec",
115 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
116 SND_SOC_DAIFMT_CBS_CFS
,
117 .ops
= &brownstone_ops
,
118 .init
= brownstone_wm8994_init
,
122 /* audio machine driver */
123 static struct snd_soc_card brownstone
= {
124 .name
= "brownstone",
125 .owner
= THIS_MODULE
,
126 .dai_link
= brownstone_wm8994_dai
,
127 .num_links
= ARRAY_SIZE(brownstone_wm8994_dai
),
129 .controls
= brownstone_dapm_control
,
130 .num_controls
= ARRAY_SIZE(brownstone_dapm_control
),
131 .dapm_widgets
= brownstone_dapm_widgets
,
132 .num_dapm_widgets
= ARRAY_SIZE(brownstone_dapm_widgets
),
133 .dapm_routes
= brownstone_audio_map
,
134 .num_dapm_routes
= ARRAY_SIZE(brownstone_audio_map
),
137 static int brownstone_probe(struct platform_device
*pdev
)
141 brownstone
.dev
= &pdev
->dev
;
142 ret
= snd_soc_register_card(&brownstone
);
144 dev_err(&pdev
->dev
, "snd_soc_register_card() failed: %d\n",
149 static int brownstone_remove(struct platform_device
*pdev
)
151 snd_soc_unregister_card(&brownstone
);
155 static struct platform_driver mmp_driver
= {
157 .name
= "brownstone-audio",
158 .owner
= THIS_MODULE
,
159 .pm
= &snd_soc_pm_ops
,
161 .probe
= brownstone_probe
,
162 .remove
= brownstone_remove
,
165 module_platform_driver(mmp_driver
);
167 MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
168 MODULE_DESCRIPTION("ALSA SoC Brownstone");
169 MODULE_LICENSE("GPL");