drm/i915: fix port checks for MST support on gen >= 11
[linux/fpc-iii.git] / sound / soc / sh / migor.c
blob8739c9f60672ced9588c05677e9affeb70f38c6b
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // ALSA SoC driver for Migo-R
4 //
5 // Copyright (C) 2009-2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7 #include <linux/clkdev.h>
8 #include <linux/device.h>
9 #include <linux/firmware.h>
10 #include <linux/module.h>
12 #include <asm/clock.h>
14 #include <cpu/sh7722.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
20 #include "../codecs/wm8978.h"
21 #include "siu.h"
23 /* Default 8000Hz sampling frequency */
24 static unsigned long codec_freq = 8000 * 512;
26 static unsigned int use_count;
28 /* External clock, sourced from the codec at the SIUMCKB pin */
29 static unsigned long siumckb_recalc(struct clk *clk)
31 return codec_freq;
34 static struct sh_clk_ops siumckb_clk_ops = {
35 .recalc = siumckb_recalc,
38 static struct clk siumckb_clk = {
39 .ops = &siumckb_clk_ops,
40 .rate = 0, /* initialised at run-time */
43 static struct clk_lookup *siumckb_lookup;
45 static int migor_hw_params(struct snd_pcm_substream *substream,
46 struct snd_pcm_hw_params *params)
48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
49 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 int ret;
51 unsigned int rate = params_rate(params);
53 ret = snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 13000000,
54 SND_SOC_CLOCK_IN);
55 if (ret < 0)
56 return ret;
58 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8978_OPCLKRATE, rate * 512);
59 if (ret < 0)
60 return ret;
62 codec_freq = rate * 512;
64 * This propagates the parent frequency change to children and
65 * recalculates the frequency table
67 clk_set_rate(&siumckb_clk, codec_freq);
68 dev_dbg(codec_dai->dev, "%s: configure %luHz\n", __func__, codec_freq);
70 ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, SIU_CLKB_EXT,
71 codec_freq / 2, SND_SOC_CLOCK_IN);
73 if (!ret)
74 use_count++;
76 return ret;
79 static int migor_hw_free(struct snd_pcm_substream *substream)
81 struct snd_soc_pcm_runtime *rtd = substream->private_data;
82 struct snd_soc_dai *codec_dai = rtd->codec_dai;
84 if (use_count) {
85 use_count--;
87 if (!use_count)
88 snd_soc_dai_set_sysclk(codec_dai, WM8978_PLL, 0,
89 SND_SOC_CLOCK_IN);
90 } else {
91 dev_dbg(codec_dai->dev, "Unbalanced hw_free!\n");
94 return 0;
97 static const struct snd_soc_ops migor_dai_ops = {
98 .hw_params = migor_hw_params,
99 .hw_free = migor_hw_free,
102 static const struct snd_soc_dapm_widget migor_dapm_widgets[] = {
103 SND_SOC_DAPM_HP("Headphone", NULL),
104 SND_SOC_DAPM_MIC("Onboard Microphone", NULL),
105 SND_SOC_DAPM_MIC("External Microphone", NULL),
108 static const struct snd_soc_dapm_route audio_map[] = {
109 /* Headphone output connected to LHP/RHP, enable OUT4 for VMID */
110 { "Headphone", NULL, "OUT4 VMID" },
111 { "OUT4 VMID", NULL, "LHP" },
112 { "OUT4 VMID", NULL, "RHP" },
114 /* On-board microphone */
115 { "RMICN", NULL, "Mic Bias" },
116 { "RMICP", NULL, "Mic Bias" },
117 { "Mic Bias", NULL, "Onboard Microphone" },
119 /* External microphone */
120 { "LMICN", NULL, "Mic Bias" },
121 { "LMICP", NULL, "Mic Bias" },
122 { "Mic Bias", NULL, "External Microphone" },
125 /* migor digital audio interface glue - connects codec <--> CPU */
126 static struct snd_soc_dai_link migor_dai = {
127 .name = "wm8978",
128 .stream_name = "WM8978",
129 .cpu_dai_name = "siu-pcm-audio",
130 .codec_dai_name = "wm8978-hifi",
131 .platform_name = "siu-pcm-audio",
132 .codec_name = "wm8978.0-001a",
133 .dai_fmt = SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_I2S |
134 SND_SOC_DAIFMT_CBS_CFS,
135 .ops = &migor_dai_ops,
138 /* migor audio machine driver */
139 static struct snd_soc_card snd_soc_migor = {
140 .name = "Migo-R",
141 .owner = THIS_MODULE,
142 .dai_link = &migor_dai,
143 .num_links = 1,
145 .dapm_widgets = migor_dapm_widgets,
146 .num_dapm_widgets = ARRAY_SIZE(migor_dapm_widgets),
147 .dapm_routes = audio_map,
148 .num_dapm_routes = ARRAY_SIZE(audio_map),
151 static struct platform_device *migor_snd_device;
153 static int __init migor_init(void)
155 int ret;
157 ret = clk_register(&siumckb_clk);
158 if (ret < 0)
159 return ret;
161 siumckb_lookup = clkdev_create(&siumckb_clk, "siumckb_clk", NULL);
162 if (!siumckb_lookup) {
163 ret = -ENOMEM;
164 goto eclkdevalloc;
167 /* Port number used on this machine: port B */
168 migor_snd_device = platform_device_alloc("soc-audio", 1);
169 if (!migor_snd_device) {
170 ret = -ENOMEM;
171 goto epdevalloc;
174 platform_set_drvdata(migor_snd_device, &snd_soc_migor);
176 ret = platform_device_add(migor_snd_device);
177 if (ret)
178 goto epdevadd;
180 return 0;
182 epdevadd:
183 platform_device_put(migor_snd_device);
184 epdevalloc:
185 clkdev_drop(siumckb_lookup);
186 eclkdevalloc:
187 clk_unregister(&siumckb_clk);
188 return ret;
191 static void __exit migor_exit(void)
193 clkdev_drop(siumckb_lookup);
194 clk_unregister(&siumckb_clk);
195 platform_device_unregister(migor_snd_device);
198 module_init(migor_init);
199 module_exit(migor_exit);
201 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
202 MODULE_DESCRIPTION("ALSA SoC Migor");
203 MODULE_LICENSE("GPL v2");