Commit | Line | Data |
---|---|---|
a40712a3 SN |
1 | /* |
2 | * Copyright (C) 2014 Samsung Electronics Co., Ltd. | |
3 | * | |
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. | |
8 | */ | |
9 | ||
10 | #include <linux/of.h> | |
11 | #include <linux/module.h> | |
12 | #include <sound/soc.h> | |
13 | #include <sound/pcm_params.h> | |
14 | #include "i2s.h" | |
15 | ||
16 | struct odroidx2_drv_data { | |
17 | const struct snd_soc_dapm_widget *dapm_widgets; | |
18 | unsigned int num_dapm_widgets; | |
19 | }; | |
20 | ||
21 | /* The I2S CDCLK output clock frequency for the MAX98090 codec */ | |
22 | #define MAX98090_MCLK 19200000 | |
23 | ||
ecb400ca SN |
24 | static struct snd_soc_dai_link odroidx2_dai[]; |
25 | ||
a40712a3 SN |
26 | static int odroidx2_late_probe(struct snd_soc_card *card) |
27 | { | |
5015920a ML |
28 | struct snd_soc_pcm_runtime *rtd; |
29 | struct snd_soc_dai *codec_dai; | |
30 | struct snd_soc_dai *cpu_dai; | |
a40712a3 SN |
31 | int ret; |
32 | ||
5015920a ML |
33 | rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name); |
34 | codec_dai = rtd->codec_dai; | |
35 | cpu_dai = rtd->cpu_dai; | |
36 | ||
a40712a3 SN |
37 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK, |
38 | SND_SOC_CLOCK_IN); | |
ecb400ca SN |
39 | |
40 | if (ret < 0 || of_find_property(odroidx2_dai[0].codec_of_node, | |
41 | "clocks", NULL)) | |
a40712a3 SN |
42 | return ret; |
43 | ||
44 | /* Set the cpu DAI configuration in order to use CDCLK */ | |
45 | return snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK, | |
46 | 0, SND_SOC_CLOCK_OUT); | |
47 | } | |
48 | ||
49 | static const struct snd_soc_dapm_widget odroidx2_dapm_widgets[] = { | |
50 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
51 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | |
52 | SND_SOC_DAPM_MIC("DMIC", NULL), | |
53 | }; | |
54 | ||
55 | static const struct snd_soc_dapm_widget odroidu3_dapm_widgets[] = { | |
56 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
57 | SND_SOC_DAPM_SPK("Speakers", NULL), | |
58 | }; | |
59 | ||
60 | static struct snd_soc_dai_link odroidx2_dai[] = { | |
61 | { | |
62 | .name = "MAX98090", | |
63 | .stream_name = "MAX98090 PCM", | |
64 | .codec_dai_name = "HiFi", | |
65 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | |
66 | SND_SOC_DAIFMT_CBM_CFM, | |
67 | } | |
68 | }; | |
69 | ||
70 | static struct snd_soc_card odroidx2 = { | |
71 | .owner = THIS_MODULE, | |
72 | .dai_link = odroidx2_dai, | |
73 | .num_links = ARRAY_SIZE(odroidx2_dai), | |
74 | .fully_routed = true, | |
75 | .late_probe = odroidx2_late_probe, | |
76 | }; | |
77 | ||
d80a12f9 | 78 | static const struct odroidx2_drv_data odroidx2_drvdata = { |
a40712a3 SN |
79 | .dapm_widgets = odroidx2_dapm_widgets, |
80 | .num_dapm_widgets = ARRAY_SIZE(odroidx2_dapm_widgets), | |
81 | }; | |
82 | ||
d80a12f9 | 83 | static const struct odroidx2_drv_data odroidu3_drvdata = { |
a40712a3 SN |
84 | .dapm_widgets = odroidu3_dapm_widgets, |
85 | .num_dapm_widgets = ARRAY_SIZE(odroidu3_dapm_widgets), | |
86 | }; | |
87 | ||
88 | static const struct of_device_id odroidx2_audio_of_match[] = { | |
89 | { | |
90 | .compatible = "samsung,odroidx2-audio", | |
91 | .data = &odroidx2_drvdata, | |
92 | }, { | |
93 | .compatible = "samsung,odroidu3-audio", | |
94 | .data = &odroidu3_drvdata, | |
95 | }, | |
96 | { }, | |
97 | }; | |
98 | MODULE_DEVICE_TABLE(of, odroidx2_audio_of_match); | |
99 | ||
100 | static int odroidx2_audio_probe(struct platform_device *pdev) | |
101 | { | |
102 | struct device_node *snd_node = pdev->dev.of_node; | |
103 | struct snd_soc_card *card = &odroidx2; | |
104 | struct device_node *i2s_node, *codec_node; | |
105 | struct odroidx2_drv_data *dd; | |
106 | const struct of_device_id *of_id; | |
107 | int ret; | |
108 | ||
109 | of_id = of_match_node(odroidx2_audio_of_match, snd_node); | |
110 | dd = (struct odroidx2_drv_data *)of_id->data; | |
111 | ||
112 | card->num_dapm_widgets = dd->num_dapm_widgets; | |
113 | card->dapm_widgets = dd->dapm_widgets; | |
114 | ||
115 | card->dev = &pdev->dev; | |
116 | ||
117 | ret = snd_soc_of_parse_card_name(card, "samsung,model"); | |
118 | if (ret < 0) | |
119 | return ret; | |
120 | ||
121 | ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing"); | |
122 | if (ret < 0) | |
123 | return ret; | |
124 | ||
125 | codec_node = of_parse_phandle(snd_node, "samsung,audio-codec", 0); | |
126 | if (!codec_node) { | |
127 | dev_err(&pdev->dev, | |
128 | "Failed parsing samsung,i2s-codec property\n"); | |
129 | return -EINVAL; | |
130 | } | |
131 | ||
132 | i2s_node = of_parse_phandle(snd_node, "samsung,i2s-controller", 0); | |
133 | if (!i2s_node) { | |
134 | dev_err(&pdev->dev, | |
135 | "Failed parsing samsung,i2s-controller property\n"); | |
136 | ret = -EINVAL; | |
137 | goto err_put_codec_n; | |
138 | } | |
139 | ||
140 | odroidx2_dai[0].codec_of_node = codec_node; | |
141 | odroidx2_dai[0].cpu_of_node = i2s_node; | |
142 | odroidx2_dai[0].platform_of_node = i2s_node; | |
143 | ||
144 | ret = snd_soc_register_card(card); | |
145 | if (ret) { | |
146 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", | |
147 | ret); | |
148 | goto err_put_i2s_n; | |
149 | } | |
150 | return 0; | |
151 | ||
152 | err_put_i2s_n: | |
153 | of_node_put(i2s_node); | |
154 | err_put_codec_n: | |
155 | of_node_put(codec_node); | |
156 | return ret; | |
157 | } | |
158 | ||
159 | static int odroidx2_audio_remove(struct platform_device *pdev) | |
160 | { | |
161 | struct snd_soc_card *card = platform_get_drvdata(pdev); | |
162 | ||
163 | snd_soc_unregister_card(card); | |
164 | ||
0099c762 JFM |
165 | of_node_put(odroidx2_dai[0].cpu_of_node); |
166 | of_node_put(odroidx2_dai[0].codec_of_node); | |
a40712a3 SN |
167 | |
168 | return 0; | |
169 | } | |
170 | ||
171 | static struct platform_driver odroidx2_audio_driver = { | |
172 | .driver = { | |
173 | .name = "odroidx2-audio", | |
a40712a3 SN |
174 | .of_match_table = odroidx2_audio_of_match, |
175 | .pm = &snd_soc_pm_ops, | |
176 | }, | |
177 | .probe = odroidx2_audio_probe, | |
178 | .remove = odroidx2_audio_remove, | |
179 | }; | |
180 | module_platform_driver(odroidx2_audio_driver); | |
181 | ||
182 | MODULE_AUTHOR("Chen Zhen <zhen1.chen@samsung.com>"); | |
183 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); | |
184 | MODULE_DESCRIPTION("ALSA SoC Odroid X2/U3 Audio Support"); | |
185 | MODULE_LICENSE("GPL v2"); |