Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 1 | /* sound/soc/s3c24xx/jive_wm8750.c |
| 2 | * |
| 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 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/timer.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/clk.h> |
| 20 | |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/soc.h> |
| 24 | #include <sound/soc-dapm.h> |
| 25 | |
| 26 | #include <asm/mach-types.h> |
| 27 | |
Jassi Brar | d3ff5a3 | 2009-11-17 16:53:31 +0900 | [diff] [blame] | 28 | #include "s3c-dma.h" |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 29 | #include "s3c2412-i2s.h" |
| 30 | |
| 31 | #include "../codecs/wm8750.h" |
| 32 | |
| 33 | static const struct snd_soc_dapm_route audio_map[] = { |
| 34 | { "Headphone Jack", NULL, "LOUT1" }, |
| 35 | { "Headphone Jack", NULL, "ROUT1" }, |
| 36 | { "Internal Speaker", NULL, "LOUT2" }, |
| 37 | { "Internal Speaker", NULL, "ROUT2" }, |
| 38 | { "LINPUT1", NULL, "Line Input" }, |
| 39 | { "RINPUT1", NULL, "Line Input" }, |
| 40 | }; |
| 41 | |
| 42 | static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = { |
| 43 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 44 | SND_SOC_DAPM_SPK("Internal Speaker", NULL), |
| 45 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 46 | }; |
| 47 | |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 48 | static int jive_hw_params(struct snd_pcm_substream *substream, |
| 49 | struct snd_pcm_hw_params *params) |
| 50 | { |
| 51 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 52 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 53 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 54 | struct s3c_i2sv2_rate_calc div; |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 55 | unsigned int clk = 0; |
| 56 | int ret = 0; |
| 57 | |
| 58 | switch (params_rate(params)) { |
| 59 | case 8000: |
| 60 | case 16000: |
| 61 | case 48000: |
| 62 | case 96000: |
| 63 | clk = 12288000; |
| 64 | break; |
| 65 | case 11025: |
| 66 | case 22050: |
| 67 | case 44100: |
| 68 | clk = 11289600; |
| 69 | break; |
| 70 | } |
| 71 | |
Ben Dooks | 01c4cad | 2009-04-16 10:32:20 +0100 | [diff] [blame] | 72 | s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params), |
Jassi Brar | 5728242 | 2010-04-27 15:56:45 +0900 | [diff] [blame] | 73 | s3c_i2sv2_get_clock(cpu_dai)); |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 74 | |
| 75 | /* set codec DAI configuration */ |
| 76 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 77 | SND_SOC_DAIFMT_NB_NF | |
| 78 | SND_SOC_DAIFMT_CBS_CFS); |
| 79 | if (ret < 0) |
| 80 | return ret; |
| 81 | |
| 82 | /* set cpu DAI configuration */ |
| 83 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
| 84 | SND_SOC_DAIFMT_NB_NF | |
| 85 | SND_SOC_DAIFMT_CBS_CFS); |
| 86 | if (ret < 0) |
| 87 | return ret; |
| 88 | |
| 89 | /* set the codec system clock for DAC and ADC */ |
| 90 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, |
| 91 | SND_SOC_CLOCK_IN); |
| 92 | if (ret < 0) |
| 93 | return ret; |
| 94 | |
| 95 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div); |
| 96 | if (ret < 0) |
| 97 | return ret; |
| 98 | |
| 99 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER, |
| 100 | div.clk_div - 1); |
| 101 | if (ret < 0) |
| 102 | return ret; |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | static struct snd_soc_ops jive_ops = { |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 108 | .hw_params = jive_hw_params, |
| 109 | }; |
| 110 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 111 | static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd) |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 112 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 113 | struct snd_soc_codec *codec = rtd->codec; |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 114 | int err; |
| 115 | |
| 116 | /* These endpoints are not being used. */ |
Mark Brown | a1b3eaeb | 2009-03-04 20:17:48 +0000 | [diff] [blame] | 117 | snd_soc_dapm_nc_pin(codec, "LINPUT2"); |
| 118 | snd_soc_dapm_nc_pin(codec, "RINPUT2"); |
| 119 | snd_soc_dapm_nc_pin(codec, "LINPUT3"); |
| 120 | snd_soc_dapm_nc_pin(codec, "RINPUT3"); |
| 121 | snd_soc_dapm_nc_pin(codec, "OUT3"); |
| 122 | snd_soc_dapm_nc_pin(codec, "MONO"); |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 123 | |
| 124 | /* Add jive specific widgets */ |
| 125 | err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, |
| 126 | ARRAY_SIZE(wm8750_dapm_widgets)); |
| 127 | if (err) { |
| 128 | printk(KERN_ERR "%s: failed to add widgets (%d)\n", |
| 129 | __func__, err); |
| 130 | return err; |
| 131 | } |
| 132 | |
| 133 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 134 | snd_soc_dapm_sync(codec); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static struct snd_soc_dai_link jive_dai = { |
| 140 | .name = "wm8750", |
| 141 | .stream_name = "WM8750", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 142 | .cpu_dai_name = "s3c2412-i2s", |
| 143 | .codec_dai_name = "wm8750-hifi", |
| 144 | .platform_name = "s3c24xx-pcm-audio", |
| 145 | .codec_name = "wm8750-codec.0-0x1a", |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 146 | .init = jive_wm8750_init, |
| 147 | .ops = &jive_ops, |
| 148 | }; |
| 149 | |
| 150 | /* jive audio machine driver */ |
Ben Dooks | 01c4cad | 2009-04-16 10:32:20 +0100 | [diff] [blame] | 151 | static struct snd_soc_card snd_soc_machine_jive = { |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 152 | .name = "Jive", |
| 153 | .dai_link = &jive_dai, |
| 154 | .num_links = 1, |
| 155 | }; |
| 156 | |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 157 | static struct platform_device *jive_snd_device; |
| 158 | |
| 159 | static int __init jive_init(void) |
| 160 | { |
| 161 | int ret; |
| 162 | |
| 163 | if (!machine_is_jive()) |
| 164 | return 0; |
| 165 | |
| 166 | printk("JIVE WM8750 Audio support\n"); |
| 167 | |
| 168 | jive_snd_device = platform_device_alloc("soc-audio", -1); |
| 169 | if (!jive_snd_device) |
| 170 | return -ENOMEM; |
| 171 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 172 | platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive); |
Ben Dooks | 3093e48 | 2009-03-04 00:49:27 +0000 | [diff] [blame] | 173 | ret = platform_device_add(jive_snd_device); |
| 174 | |
| 175 | if (ret) |
| 176 | platform_device_put(jive_snd_device); |
| 177 | |
| 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | static void __exit jive_exit(void) |
| 182 | { |
| 183 | platform_device_unregister(jive_snd_device); |
| 184 | } |
| 185 | |
| 186 | module_init(jive_init); |
| 187 | module_exit(jive_exit); |
| 188 | |
| 189 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 190 | MODULE_DESCRIPTION("ALSA SoC Jive Audio support"); |
| 191 | MODULE_LICENSE("GPL"); |