• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
brownstone_wm8994_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)48 static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream,
49 				       struct snd_pcm_hw_params *params)
50 {
51 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
52 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
53 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
54 	int freq_out, sspa_mclk, sysclk;
55 
56 	if (params_rate(params) > 11025) {
57 		freq_out  = params_rate(params) * 512;
58 		sysclk    = params_rate(params) * 256;
59 		sspa_mclk = params_rate(params) * 64;
60 	} else {
61 		freq_out  = params_rate(params) * 1024;
62 		sysclk    = params_rate(params) * 512;
63 		sspa_mclk = params_rate(params) * 64;
64 	}
65 
66 	snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
67 	snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
68 	snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
69 
70 	/* set wm8994 sysclk */
71 	snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
72 
73 	return 0;
74 }
75 
76 /* machine stream operations */
77 static struct snd_soc_ops brownstone_ops = {
78 	.hw_params = brownstone_wm8994_hw_params,
79 };
80 
81 static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
82 {
83 	.name		= "WM8994",
84 	.stream_name	= "WM8994 HiFi",
85 	.cpu_dai_name	= "mmp-sspa-dai.0",
86 	.codec_dai_name	= "wm8994-aif1",
87 	.platform_name	= "mmp-pcm-audio",
88 	.codec_name	= "wm8994-codec",
89 	.dai_fmt	= SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
90 				SND_SOC_DAIFMT_CBS_CFS,
91 	.ops		= &brownstone_ops,
92 },
93 };
94 
95 /* audio machine driver */
96 static struct snd_soc_card brownstone = {
97 	.name         = "brownstone",
98 	.owner        = THIS_MODULE,
99 	.dai_link     = brownstone_wm8994_dai,
100 	.num_links    = ARRAY_SIZE(brownstone_wm8994_dai),
101 
102 	.controls = brownstone_dapm_control,
103 	.num_controls = ARRAY_SIZE(brownstone_dapm_control),
104 	.dapm_widgets = brownstone_dapm_widgets,
105 	.num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
106 	.dapm_routes = brownstone_audio_map,
107 	.num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
108 	.fully_routed = true,
109 };
110 
brownstone_probe(struct platform_device * pdev)111 static int brownstone_probe(struct platform_device *pdev)
112 {
113 	int ret;
114 
115 	brownstone.dev = &pdev->dev;
116 	ret = devm_snd_soc_register_card(&pdev->dev, &brownstone);
117 	if (ret)
118 		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
119 				ret);
120 	return ret;
121 }
122 
123 static struct platform_driver mmp_driver = {
124 	.driver		= {
125 		.name	= "brownstone-audio",
126 		.pm     = &snd_soc_pm_ops,
127 	},
128 	.probe		= brownstone_probe,
129 };
130 
131 module_platform_driver(mmp_driver);
132 
133 MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
134 MODULE_DESCRIPTION("ALSA SoC Brownstone");
135 MODULE_LICENSE("GPL");
136 MODULE_ALIAS("platform:brownstone-audio");
137