blob: 2b26318bc20097b0c5e369b50f151b7bde511e59 [file] [log] [blame]
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +08001/*
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
22static const struct snd_kcontrol_new brownstone_dapm_control[] = {
23 SOC_DAPM_PIN_SWITCH("Ext Spk"),
24};
25
26static 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
33static 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
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +080048static 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 int sspa_div;
56
57 if (params_rate(params) > 11025) {
58 freq_out = params_rate(params) * 512;
59 sysclk = params_rate(params) * 256;
60 sspa_mclk = params_rate(params) * 64;
61 } else {
62 freq_out = params_rate(params) * 1024;
63 sysclk = params_rate(params) * 512;
64 sspa_mclk = params_rate(params) * 64;
65 }
66 sspa_div = freq_out;
67 do_div(sspa_div, sspa_mclk);
68
69 snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
70 snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
71 snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
72
73 /* set wm8994 sysclk */
74 snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
75
76 return 0;
77}
78
79/* machine stream operations */
80static struct snd_soc_ops brownstone_ops = {
81 .hw_params = brownstone_wm8994_hw_params,
82};
83
84static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
85{
86 .name = "WM8994",
87 .stream_name = "WM8994 HiFi",
88 .cpu_dai_name = "mmp-sspa-dai.0",
89 .codec_dai_name = "wm8994-aif1",
90 .platform_name = "mmp-pcm-audio",
91 .codec_name = "wm8994-codec",
92 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
93 SND_SOC_DAIFMT_CBS_CFS,
94 .ops = &brownstone_ops,
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +080095},
96};
97
98/* audio machine driver */
99static struct snd_soc_card brownstone = {
100 .name = "brownstone",
Wei Yongjun0d617862013-07-02 17:26:21 +0800101 .owner = THIS_MODULE,
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800102 .dai_link = brownstone_wm8994_dai,
103 .num_links = ARRAY_SIZE(brownstone_wm8994_dai),
104
105 .controls = brownstone_dapm_control,
106 .num_controls = ARRAY_SIZE(brownstone_dapm_control),
107 .dapm_widgets = brownstone_dapm_widgets,
108 .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
109 .dapm_routes = brownstone_audio_map,
110 .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
Lars-Peter Clausen6b9aa502015-05-07 21:27:46 +0200111 .fully_routed = true,
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800112};
113
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500114static int brownstone_probe(struct platform_device *pdev)
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800115{
116 int ret;
117
118 brownstone.dev = &pdev->dev;
119 ret = snd_soc_register_card(&brownstone);
120 if (ret)
121 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
122 ret);
123 return ret;
124}
125
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500126static int brownstone_remove(struct platform_device *pdev)
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800127{
128 snd_soc_unregister_card(&brownstone);
129 return 0;
130}
131
132static struct platform_driver mmp_driver = {
133 .driver = {
134 .name = "brownstone-audio",
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +0400135 .pm = &snd_soc_pm_ops,
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800136 },
137 .probe = brownstone_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500138 .remove = brownstone_remove,
Zhangfei Gao5ebf20a2012-06-11 18:04:40 +0800139};
140
141module_platform_driver(mmp_driver);
142
143MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
144MODULE_DESCRIPTION("ALSA SoC Brownstone");
145MODULE_LICENSE("GPL");