0001
0002
0003 #include "../codecs/wm8994.h"
0004 #include <sound/pcm_params.h>
0005 #include <sound/soc.h>
0006 #include <linux/module.h>
0007 #include <linux/of.h>
0008 #include <linux/of_device.h>
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #define SMDK_WM8994_FREQ 16934000
0034
0035 struct smdk_wm8994_data {
0036 int mclk1_rate;
0037 };
0038
0039
0040 static struct smdk_wm8994_data smdk_board_data = {
0041 .mclk1_rate = SMDK_WM8994_FREQ,
0042 };
0043
0044 static int smdk_hw_params(struct snd_pcm_substream *substream,
0045 struct snd_pcm_hw_params *params)
0046 {
0047 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0048 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0049 unsigned int pll_out;
0050 int ret;
0051
0052
0053 if (params_width(params) == 24)
0054 pll_out = params_rate(params) * 384;
0055 else if (params_rate(params) == 8000 || params_rate(params) == 11025)
0056 pll_out = params_rate(params) * 512;
0057 else
0058 pll_out = params_rate(params) * 256;
0059
0060 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
0061 SMDK_WM8994_FREQ, pll_out);
0062 if (ret < 0)
0063 return ret;
0064
0065 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
0066 pll_out, SND_SOC_CLOCK_IN);
0067 if (ret < 0)
0068 return ret;
0069
0070 return 0;
0071 }
0072
0073
0074
0075
0076 static const struct snd_soc_ops smdk_ops = {
0077 .hw_params = smdk_hw_params,
0078 };
0079
0080 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
0081 {
0082 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
0083
0084
0085 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
0086 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
0087 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
0088 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
0089 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
0090 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
0091 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
0092 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
0093 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
0094 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
0095 snd_soc_dapm_nc_pin(dapm, "IN1LP");
0096 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
0097 snd_soc_dapm_nc_pin(dapm, "IN1RP");
0098 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
0099
0100 return 0;
0101 }
0102
0103 SND_SOC_DAILINK_DEFS(aif1,
0104 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
0105 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
0106 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
0107
0108 SND_SOC_DAILINK_DEFS(fifo_tx,
0109 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s-sec")),
0110 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
0111 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s-sec")));
0112
0113 static struct snd_soc_dai_link smdk_dai[] = {
0114 {
0115 .name = "WM8994 AIF1",
0116 .stream_name = "Pri_Dai",
0117 .init = smdk_wm8994_init_paiftx,
0118 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0119 SND_SOC_DAIFMT_CBM_CFM,
0120 .ops = &smdk_ops,
0121 SND_SOC_DAILINK_REG(aif1),
0122 }, {
0123 .name = "Sec_FIFO TX",
0124 .stream_name = "Sec_Dai",
0125 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0126 SND_SOC_DAIFMT_CBM_CFM,
0127 .ops = &smdk_ops,
0128 SND_SOC_DAILINK_REG(fifo_tx),
0129 },
0130 };
0131
0132 static struct snd_soc_card smdk = {
0133 .name = "SMDK-I2S",
0134 .owner = THIS_MODULE,
0135 .dai_link = smdk_dai,
0136 .num_links = ARRAY_SIZE(smdk_dai),
0137 };
0138
0139 static const struct of_device_id samsung_wm8994_of_match[] __maybe_unused = {
0140 { .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data },
0141 {},
0142 };
0143 MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
0144
0145 static int smdk_audio_probe(struct platform_device *pdev)
0146 {
0147 int ret;
0148 struct device_node *np = pdev->dev.of_node;
0149 struct snd_soc_card *card = &smdk;
0150 struct smdk_wm8994_data *board;
0151 const struct of_device_id *id;
0152
0153 card->dev = &pdev->dev;
0154
0155 board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL);
0156 if (!board)
0157 return -ENOMEM;
0158
0159 if (np) {
0160 smdk_dai[0].cpus->dai_name = NULL;
0161 smdk_dai[0].cpus->of_node = of_parse_phandle(np,
0162 "samsung,i2s-controller", 0);
0163 if (!smdk_dai[0].cpus->of_node) {
0164 dev_err(&pdev->dev,
0165 "Property 'samsung,i2s-controller' missing or invalid\n");
0166 ret = -EINVAL;
0167 return ret;
0168 }
0169
0170 smdk_dai[0].platforms->name = NULL;
0171 smdk_dai[0].platforms->of_node = smdk_dai[0].cpus->of_node;
0172 }
0173
0174 id = of_match_device(samsung_wm8994_of_match, &pdev->dev);
0175 if (id)
0176 *board = *((struct smdk_wm8994_data *)id->data);
0177
0178 platform_set_drvdata(pdev, board);
0179
0180 ret = devm_snd_soc_register_card(&pdev->dev, card);
0181
0182 if (ret)
0183 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
0184
0185 return ret;
0186 }
0187
0188 static struct platform_driver smdk_audio_driver = {
0189 .driver = {
0190 .name = "smdk-audio-wm8994",
0191 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
0192 .pm = &snd_soc_pm_ops,
0193 },
0194 .probe = smdk_audio_probe,
0195 };
0196
0197 module_platform_driver(smdk_audio_driver);
0198
0199 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
0200 MODULE_LICENSE("GPL");
0201 MODULE_ALIAS("platform:smdk-audio-wm8994");