blob: 746930dde5d7917587be324de45327520d219236 [file] [log] [blame]
Sylwester Nawrockif9ff3802019-04-19 12:21:57 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (c) 2011 Samsung Electronics Co., Ltd
4// http://www.samsung.com
5
Paul Gortmakerda155d52011-07-15 12:38:28 -04006#include <linux/module.h>
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +09007#include <sound/soc.h>
8#include <sound/pcm.h>
9#include <sound/pcm_params.h>
10
11#include "../codecs/wm8994.h"
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090012#include "pcm.h"
13
14/*
15 * Board Settings:
16 * o '1' means 'ON'
17 * o '0' means 'OFF'
18 * o 'X' means 'Don't care'
19 *
20 * SMDKC210, SMDKV310: CFG3- 1001, CFG5-1000, CFG7-111111
21 */
22
23/*
24 * Configure audio route as :-
25 * $ amixer sset 'DAC1' on,on
26 * $ amixer sset 'Right Headphone Mux' 'DAC'
27 * $ amixer sset 'Left Headphone Mux' 'DAC'
28 * $ amixer sset 'DAC1R Mixer AIF1.1' on
29 * $ amixer sset 'DAC1L Mixer AIF1.1' on
30 * $ amixer sset 'IN2L' on
31 * $ amixer sset 'IN2L PGA IN2LN' on
32 * $ amixer sset 'MIXINL IN2L' on
33 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
34 * $ amixer sset 'IN2R' on
35 * $ amixer sset 'IN2R PGA IN2RN' on
36 * $ amixer sset 'MIXINR IN2R' on
37 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
38 */
39
40/* SMDK has a 16.9344MHZ crystal attached to WM8994 */
41#define SMDK_WM8994_FREQ 16934400
42
43static int smdk_wm8994_pcm_hw_params(struct snd_pcm_substream *substream,
44 struct snd_pcm_hw_params *params)
45{
46 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimoto7de6b6b2020-03-23 14:20:20 +090047 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
48 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090049 unsigned long mclk_freq;
50 int rfs, ret;
51
52 switch(params_rate(params)) {
53 case 8000:
54 rfs = 512;
55 break;
56 default:
57 dev_err(cpu_dai->dev, "%s:%d Sampling Rate %u not supported!\n",
58 __func__, __LINE__, params_rate(params));
59 return -EINVAL;
60 }
61
62 mclk_freq = params_rate(params) * rfs;
63
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090064 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
65 mclk_freq, SND_SOC_CLOCK_IN);
66 if (ret < 0)
67 return ret;
68
69 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
70 SMDK_WM8994_FREQ, mclk_freq);
71 if (ret < 0)
72 return ret;
73
74 /* Set PCM source clock on CPU */
75 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
76 mclk_freq, SND_SOC_CLOCK_IN);
77 if (ret < 0)
78 return ret;
79
80 /* Set SCLK_DIV for making bclk */
81 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
82 if (ret < 0)
83 return ret;
84
85 return 0;
86}
87
88static struct snd_soc_ops smdk_wm8994_pcm_ops = {
89 .hw_params = smdk_wm8994_pcm_hw_params,
90};
91
Kuninori Morimoto245139b2019-06-06 13:09:12 +090092SND_SOC_DAILINK_DEFS(paif_pcm,
93 DAILINK_COMP_ARRAY(COMP_CPU("samsung-pcm.0")),
94 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
95 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-pcm.0")));
96
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +090097static struct snd_soc_dai_link smdk_dai[] = {
98 {
99 .name = "WM8994 PAIF PCM",
100 .stream_name = "Primary PCM",
Lars-Peter Clausenfce20bf2015-01-01 17:16:29 +0100101 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
102 SND_SOC_DAIFMT_CBS_CFS,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900103 .ops = &smdk_wm8994_pcm_ops,
Kuninori Morimoto245139b2019-06-06 13:09:12 +0900104 SND_SOC_DAILINK_REG(paif_pcm),
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900105 },
106};
107
108static struct snd_soc_card smdk_pcm = {
109 .name = "SMDK-PCM",
Axel Lin095d79d2011-12-22 10:53:15 +0800110 .owner = THIS_MODULE,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900111 .dai_link = smdk_dai,
112 .num_links = 1,
113};
114
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500115static int snd_smdk_probe(struct platform_device *pdev)
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900116{
117 int ret = 0;
118
119 smdk_pcm.dev = &pdev->dev;
Tushar Beherac5838832014-05-21 08:52:17 +0530120 ret = devm_snd_soc_register_card(&pdev->dev, &smdk_pcm);
Marek Szyprowski1a1b3742020-02-28 11:11:20 +0100121 if (ret && ret != -EPROBE_DEFER)
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900122 dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900123
Tushar Beherac5838832014-05-21 08:52:17 +0530124 return ret;
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900125}
126
127static struct platform_driver snd_smdk_driver = {
128 .driver = {
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900129 .name = "samsung-smdk-pcm",
130 },
131 .probe = snd_smdk_probe,
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900132};
133
Axel Lin1175f712011-11-28 18:53:57 +0800134module_platform_driver(snd_smdk_driver);
Sangbeom Kimd2ec3ab2011-06-20 17:29:29 +0900135
136MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
137MODULE_DESCRIPTION("ALSA SoC SMDK WM8994 for PCM");
138MODULE_LICENSE("GPL");