blob: b1c89ec2d999ce3f410282dfdf1ecfb30b7cfe4e [file] [log] [blame]
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +09001/*
2 * sound/soc/samsung/smdk_wm8994pcm.c
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
Paul Gortmakerda155d52011-07-15 12:38:28 -040012#include <linux/module.h>
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090013#include <sound/soc.h>
14#include <sound/pcm.h>
15#include <sound/pcm_params.h>
16
17#include "../codecs/wm8994.h"
18#include "dma.h"
19#include "pcm.h"
20
21/*
22 * Board Settings:
23 * o '1' means 'ON'
24 * o '0' means 'OFF'
25 * o 'X' means 'Don't care'
26 *
27 * SMDKC210, SMDKV310: CFG3- 1001, CFG5-1000, CFG7-111111
28 */
29
30/*
31 * Configure audio route as :-
32 * $ amixer sset 'DAC1' on,on
33 * $ amixer sset 'Right Headphone Mux' 'DAC'
34 * $ amixer sset 'Left Headphone Mux' 'DAC'
35 * $ amixer sset 'DAC1R Mixer AIF1.1' on
36 * $ amixer sset 'DAC1L Mixer AIF1.1' on
37 * $ amixer sset 'IN2L' on
38 * $ amixer sset 'IN2L PGA IN2LN' on
39 * $ amixer sset 'MIXINL IN2L' on
40 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
41 * $ amixer sset 'IN2R' on
42 * $ amixer sset 'IN2R PGA IN2RN' on
43 * $ amixer sset 'MIXINR IN2R' on
44 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
45 */
46
47/* SMDK has a 16.9344MHZ crystal attached to WM8994 */
48#define SMDK_WM8994_FREQ 16934400
49
50static int smdk_wm8994_pcm_hw_params(struct snd_pcm_substream *substream,
51 struct snd_pcm_hw_params *params)
52{
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_dai *codec_dai = rtd->codec_dai;
55 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
56 unsigned long mclk_freq;
57 int rfs, ret;
58
59 switch(params_rate(params)) {
60 case 8000:
61 rfs = 512;
62 break;
63 default:
64 dev_err(cpu_dai->dev, "%s:%d Sampling Rate %u not supported!\n",
65 __func__, __LINE__, params_rate(params));
66 return -EINVAL;
67 }
68
69 mclk_freq = params_rate(params) * rfs;
70
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090071 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
72 mclk_freq, SND_SOC_CLOCK_IN);
73 if (ret < 0)
74 return ret;
75
76 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
77 SMDK_WM8994_FREQ, mclk_freq);
78 if (ret < 0)
79 return ret;
80
81 /* Set PCM source clock on CPU */
82 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
83 mclk_freq, SND_SOC_CLOCK_IN);
84 if (ret < 0)
85 return ret;
86
87 /* Set SCLK_DIV for making bclk */
88 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
89 if (ret < 0)
90 return ret;
91
92 return 0;
93}
94
95static struct snd_soc_ops smdk_wm8994_pcm_ops = {
96 .hw_params = smdk_wm8994_pcm_hw_params,
97};
98
99static struct snd_soc_dai_link smdk_dai[] = {
100 {
101 .name = "WM8994 PAIF PCM",
102 .stream_name = "Primary PCM",
103 .cpu_dai_name = "samsung-pcm.0",
104 .codec_dai_name = "wm8994-aif1",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530105 .platform_name = "samsung-pcm.0",
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900106 .codec_name = "wm8994-codec",
Lars-Peter Clausenfce20bf2015-01-01 17:16:29 +0100107 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
108 SND_SOC_DAIFMT_CBS_CFS,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900109 .ops = &smdk_wm8994_pcm_ops,
110 },
111};
112
113static struct snd_soc_card smdk_pcm = {
114 .name = "SMDK-PCM",
Axel Lin095d79d2011-12-22 10:53:15 +0800115 .owner = THIS_MODULE,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900116 .dai_link = smdk_dai,
117 .num_links = 1,
118};
119
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500120static int snd_smdk_probe(struct platform_device *pdev)
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900121{
122 int ret = 0;
123
124 smdk_pcm.dev = &pdev->dev;
Tushar Beherac5838832014-05-21 08:52:17 +0530125 ret = devm_snd_soc_register_card(&pdev->dev, &smdk_pcm);
126 if (ret)
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900127 dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900128
Tushar Beherac5838832014-05-21 08:52:17 +0530129 return ret;
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900130}
131
132static struct platform_driver snd_smdk_driver = {
133 .driver = {
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900134 .name = "samsung-smdk-pcm",
135 },
136 .probe = snd_smdk_probe,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900137};
138
Axel Lin1175f712011-11-28 18:53:57 +0800139module_platform_driver(snd_smdk_driver);
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900140
141MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
142MODULE_DESCRIPTION("ALSA SoC SMDK WM8994 for PCM");
143MODULE_LICENSE("GPL");