blob: 7fcb51faa2a0e98803cbc8ac67cd370b7f2fd02b [file] [log] [blame]
Jassi Brar5033f432010-11-22 15:37:25 +09001/* sound/soc/samsung/jive_wm8750.c
Ben Dooks3093e482009-03-04 00:49:27 +00002 *
3 * Copyright 2007,2008 Simtec Electronics
4 *
5 * Based on sound/soc/pxa/spitz.c
6 * Copyright 2005 Wolfson Microelectronics PLC.
7 * Copyright 2005 Openedhand Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
Paul Gortmakerda155d52011-07-15 12:38:28 -040014#include <linux/module.h>
Ben Dooks3093e482009-03-04 00:49:27 +000015#include <sound/soc.h>
Ben Dooks3093e482009-03-04 00:49:27 +000016
17#include <asm/mach-types.h>
18
Ben Dooks3093e482009-03-04 00:49:27 +000019#include "s3c2412-i2s.h"
Ben Dooks3093e482009-03-04 00:49:27 +000020#include "../codecs/wm8750.h"
21
22static const struct snd_soc_dapm_route audio_map[] = {
23 { "Headphone Jack", NULL, "LOUT1" },
24 { "Headphone Jack", NULL, "ROUT1" },
25 { "Internal Speaker", NULL, "LOUT2" },
26 { "Internal Speaker", NULL, "ROUT2" },
27 { "LINPUT1", NULL, "Line Input" },
28 { "RINPUT1", NULL, "Line Input" },
29};
30
31static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
32 SND_SOC_DAPM_HP("Headphone Jack", NULL),
33 SND_SOC_DAPM_SPK("Internal Speaker", NULL),
34 SND_SOC_DAPM_LINE("Line In", NULL),
35};
36
Ben Dooks3093e482009-03-04 00:49:27 +000037static int jive_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000041 struct snd_soc_dai *codec_dai = rtd->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Ben Dooksdc854472009-03-04 00:49:30 +000043 struct s3c_i2sv2_rate_calc div;
Ben Dooks3093e482009-03-04 00:49:27 +000044 unsigned int clk = 0;
45 int ret = 0;
46
47 switch (params_rate(params)) {
48 case 8000:
49 case 16000:
50 case 48000:
51 case 96000:
52 clk = 12288000;
53 break;
54 case 11025:
55 case 22050:
56 case 44100:
57 clk = 11289600;
58 break;
59 }
60
Ben Dooks01c4cad2009-04-16 10:32:20 +010061 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
Jassi Brar57282422010-04-27 15:56:45 +090062 s3c_i2sv2_get_clock(cpu_dai));
Ben Dooks3093e482009-03-04 00:49:27 +000063
Ben Dooks3093e482009-03-04 00:49:27 +000064 /* set the codec system clock for DAC and ADC */
65 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
66 SND_SOC_CLOCK_IN);
67 if (ret < 0)
68 return ret;
69
70 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
71 if (ret < 0)
72 return ret;
73
74 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
75 div.clk_div - 1);
76 if (ret < 0)
77 return ret;
78
79 return 0;
80}
81
82static struct snd_soc_ops jive_ops = {
Ben Dooks3093e482009-03-04 00:49:27 +000083 .hw_params = jive_hw_params,
84};
85
Ben Dooks3093e482009-03-04 00:49:27 +000086static struct snd_soc_dai_link jive_dai = {
87 .name = "wm8750",
88 .stream_name = "WM8750",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000089 .cpu_dai_name = "s3c2412-i2s",
90 .codec_dai_name = "wm8750-hifi",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +053091 .platform_name = "s3c2412-i2s",
Mark Browndc5de622011-08-03 18:22:28 +090092 .codec_name = "wm8750.0-001a",
Lars-Peter Clausen72303ca2015-01-01 17:16:21 +010093 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
94 SND_SOC_DAIFMT_CBS_CFS,
Ben Dooks3093e482009-03-04 00:49:27 +000095 .ops = &jive_ops,
96};
97
98/* jive audio machine driver */
Ben Dooks01c4cad2009-04-16 10:32:20 +010099static struct snd_soc_card snd_soc_machine_jive = {
Ben Dooks3093e482009-03-04 00:49:27 +0000100 .name = "Jive",
Axel Lin095d79d2011-12-22 10:53:15 +0800101 .owner = THIS_MODULE,
Ben Dooks3093e482009-03-04 00:49:27 +0000102 .dai_link = &jive_dai,
103 .num_links = 1,
Mark Brown03b53622011-10-08 13:30:17 +0100104
Axel Lin68264d22011-12-07 17:44:47 +0800105 .dapm_widgets = wm8750_dapm_widgets,
Mark Brown03b53622011-10-08 13:30:17 +0100106 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
107 .dapm_routes = audio_map,
108 .num_dapm_routes = ARRAY_SIZE(audio_map),
Lars-Peter Clausen3a41e0f2015-01-16 14:34:52 +0100109 .fully_routed = true,
Ben Dooks3093e482009-03-04 00:49:27 +0000110};
111
Ben Dooks3093e482009-03-04 00:49:27 +0000112static struct platform_device *jive_snd_device;
113
114static int __init jive_init(void)
115{
116 int ret;
117
118 if (!machine_is_jive())
119 return 0;
120
121 printk("JIVE WM8750 Audio support\n");
122
123 jive_snd_device = platform_device_alloc("soc-audio", -1);
124 if (!jive_snd_device)
125 return -ENOMEM;
126
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000127 platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
Ben Dooks3093e482009-03-04 00:49:27 +0000128 ret = platform_device_add(jive_snd_device);
129
130 if (ret)
131 platform_device_put(jive_snd_device);
132
133 return ret;
134}
135
136static void __exit jive_exit(void)
137{
138 platform_device_unregister(jive_snd_device);
139}
140
141module_init(jive_init);
142module_exit(jive_exit);
143
144MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
145MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
146MODULE_LICENSE("GPL");