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