2 * Copyright (C) 2014 Samsung Electronics Co., Ltd.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
11 #include <linux/module.h>
12 #include <sound/soc.h>
13 #include <sound/pcm_params.h>
16 struct odroidx2_drv_data {
17 const struct snd_soc_dapm_widget *dapm_widgets;
18 unsigned int num_dapm_widgets;
21 /* The I2S CDCLK output clock frequency for the MAX98090 codec */
22 #define MAX98090_MCLK 19200000
24 static struct snd_soc_dai_link odroidx2_dai[];
26 static int odroidx2_late_probe(struct snd_soc_card *card)
28 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
29 struct snd_soc_dai *cpu_dai = card->rtd[0].cpu_dai;
32 ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK,
35 if (ret < 0 || of_find_property(odroidx2_dai[0].codec_of_node,
39 /* Set the cpu DAI configuration in order to use CDCLK */
40 return snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
41 0, SND_SOC_CLOCK_OUT);
44 static const struct snd_soc_dapm_widget odroidx2_dapm_widgets[] = {
45 SND_SOC_DAPM_HP("Headphone Jack", NULL),
46 SND_SOC_DAPM_MIC("Mic Jack", NULL),
47 SND_SOC_DAPM_MIC("DMIC", NULL),
50 static const struct snd_soc_dapm_widget odroidu3_dapm_widgets[] = {
51 SND_SOC_DAPM_HP("Headphone Jack", NULL),
52 SND_SOC_DAPM_SPK("Speakers", NULL),
55 static struct snd_soc_dai_link odroidx2_dai[] = {
58 .stream_name = "MAX98090 PCM",
59 .codec_dai_name = "HiFi",
60 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
61 SND_SOC_DAIFMT_CBM_CFM,
65 static struct snd_soc_card odroidx2 = {
67 .dai_link = odroidx2_dai,
68 .num_links = ARRAY_SIZE(odroidx2_dai),
70 .late_probe = odroidx2_late_probe,
73 static const struct odroidx2_drv_data odroidx2_drvdata = {
74 .dapm_widgets = odroidx2_dapm_widgets,
75 .num_dapm_widgets = ARRAY_SIZE(odroidx2_dapm_widgets),
78 static const struct odroidx2_drv_data odroidu3_drvdata = {
79 .dapm_widgets = odroidu3_dapm_widgets,
80 .num_dapm_widgets = ARRAY_SIZE(odroidu3_dapm_widgets),
83 static const struct of_device_id odroidx2_audio_of_match[] = {
85 .compatible = "samsung,odroidx2-audio",
86 .data = &odroidx2_drvdata,
88 .compatible = "samsung,odroidu3-audio",
89 .data = &odroidu3_drvdata,
93 MODULE_DEVICE_TABLE(of, odroidx2_audio_of_match);
95 static int odroidx2_audio_probe(struct platform_device *pdev)
97 struct device_node *snd_node = pdev->dev.of_node;
98 struct snd_soc_card *card = &odroidx2;
99 struct device_node *i2s_node, *codec_node;
100 struct odroidx2_drv_data *dd;
101 const struct of_device_id *of_id;
104 of_id = of_match_node(odroidx2_audio_of_match, snd_node);
105 dd = (struct odroidx2_drv_data *)of_id->data;
107 card->num_dapm_widgets = dd->num_dapm_widgets;
108 card->dapm_widgets = dd->dapm_widgets;
110 card->dev = &pdev->dev;
112 ret = snd_soc_of_parse_card_name(card, "samsung,model");
116 ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing");
120 codec_node = of_parse_phandle(snd_node, "samsung,audio-codec", 0);
123 "Failed parsing samsung,i2s-codec property\n");
127 i2s_node = of_parse_phandle(snd_node, "samsung,i2s-controller", 0);
130 "Failed parsing samsung,i2s-controller property\n");
132 goto err_put_codec_n;
135 odroidx2_dai[0].codec_of_node = codec_node;
136 odroidx2_dai[0].cpu_of_node = i2s_node;
137 odroidx2_dai[0].platform_of_node = i2s_node;
139 ret = snd_soc_register_card(card);
141 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
148 of_node_put(i2s_node);
150 of_node_put(codec_node);
154 static int odroidx2_audio_remove(struct platform_device *pdev)
156 struct snd_soc_card *card = platform_get_drvdata(pdev);
158 snd_soc_unregister_card(card);
160 of_node_put(odroidx2_dai[0].cpu_of_node);
161 of_node_put(odroidx2_dai[0].codec_of_node);
166 static struct platform_driver odroidx2_audio_driver = {
168 .name = "odroidx2-audio",
169 .of_match_table = odroidx2_audio_of_match,
170 .pm = &snd_soc_pm_ops,
172 .probe = odroidx2_audio_probe,
173 .remove = odroidx2_audio_remove,
175 module_platform_driver(odroidx2_audio_driver);
177 MODULE_AUTHOR("Chen Zhen <zhen1.chen@samsung.com>");
178 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
179 MODULE_DESCRIPTION("ALSA SoC Odroid X2/U3 Audio Support");
180 MODULE_LICENSE("GPL v2");