Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/soc/pxa/z2.c |
| 3 | * |
| 4 | * SoC Audio driver for Aeronix Zipit Z2 |
| 5 | * |
| 6 | * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com> |
| 7 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> |
| 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/gpio.h> |
| 20 | |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/soc.h> |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 24 | #include <sound/jack.h> |
| 25 | |
| 26 | #include <asm/mach-types.h> |
| 27 | #include <mach/hardware.h> |
| 28 | #include <mach/audio.h> |
| 29 | #include <mach/z2.h> |
| 30 | |
| 31 | #include "../codecs/wm8750.h" |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 32 | #include "pxa2xx-i2s.h" |
| 33 | |
| 34 | static struct snd_soc_card snd_soc_z2; |
| 35 | |
| 36 | static int z2_hw_params(struct snd_pcm_substream *substream, |
| 37 | struct snd_pcm_hw_params *params) |
| 38 | { |
| 39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 41 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 42 | unsigned int clk = 0; |
| 43 | int ret = 0; |
| 44 | |
| 45 | switch (params_rate(params)) { |
| 46 | case 8000: |
| 47 | case 16000: |
| 48 | case 48000: |
| 49 | case 96000: |
| 50 | clk = 12288000; |
| 51 | break; |
| 52 | case 11025: |
| 53 | case 22050: |
| 54 | case 44100: |
| 55 | clk = 11289600; |
| 56 | break; |
| 57 | } |
| 58 | |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 59 | /* set the codec system clock for DAC and ADC */ |
| 60 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, |
| 61 | SND_SOC_CLOCK_IN); |
| 62 | if (ret < 0) |
| 63 | return ret; |
| 64 | |
| 65 | /* set the I2S system clock as input (unused) */ |
| 66 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0, |
| 67 | SND_SOC_CLOCK_IN); |
| 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct snd_soc_jack hs_jack; |
| 75 | |
| 76 | /* Headset jack detection DAPM pins */ |
| 77 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 78 | { |
| 79 | .pin = "Mic Jack", |
| 80 | .mask = SND_JACK_MICROPHONE, |
| 81 | }, |
| 82 | { |
| 83 | .pin = "Headphone Jack", |
| 84 | .mask = SND_JACK_HEADPHONE, |
| 85 | }, |
Vasily Khoruzhick | 5f3822c | 2011-03-11 11:05:37 +0200 | [diff] [blame] | 86 | { |
| 87 | .pin = "Ext Spk", |
| 88 | .mask = SND_JACK_HEADPHONE, |
| 89 | .invert = 1 |
| 90 | }, |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /* Headset jack detection gpios */ |
| 94 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { |
| 95 | { |
| 96 | .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT, |
| 97 | .name = "hsdet-gpio", |
| 98 | .report = SND_JACK_HEADSET, |
| 99 | .debounce_time = 200, |
Vasily Khoruzhick | 7cbf7004 | 2011-01-18 16:54:24 +0200 | [diff] [blame] | 100 | .invert = 1, |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 101 | }, |
| 102 | }; |
| 103 | |
| 104 | /* z2 machine dapm widgets */ |
| 105 | static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = { |
| 106 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 107 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 108 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 109 | |
| 110 | /* headset is a mic and mono headphone */ |
| 111 | SND_SOC_DAPM_HP("Headset Jack", NULL), |
| 112 | }; |
| 113 | |
| 114 | /* Z2 machine audio_map */ |
Axel Lin | 3c3f51f | 2011-12-31 08:45:49 +0800 | [diff] [blame] | 115 | static const struct snd_soc_dapm_route z2_audio_map[] = { |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 116 | |
| 117 | /* headphone connected to LOUT1, ROUT1 */ |
| 118 | {"Headphone Jack", NULL, "LOUT1"}, |
| 119 | {"Headphone Jack", NULL, "ROUT1"}, |
| 120 | |
| 121 | /* ext speaker connected to LOUT2, ROUT2 */ |
| 122 | {"Ext Spk", NULL , "ROUT2"}, |
| 123 | {"Ext Spk", NULL , "LOUT2"}, |
| 124 | |
| 125 | /* mic is connected to R input 2 - with bias */ |
| 126 | {"RINPUT2", NULL, "Mic Bias"}, |
| 127 | {"Mic Bias", NULL, "Mic Jack"}, |
| 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Logic for a wm8750 as connected on a Z2 Device |
| 132 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 133 | static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd) |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 134 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 135 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 136 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 137 | int ret; |
| 138 | |
| 139 | /* NC codec pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 140 | snd_soc_dapm_disable_pin(dapm, "LINPUT3"); |
| 141 | snd_soc_dapm_disable_pin(dapm, "RINPUT3"); |
| 142 | snd_soc_dapm_disable_pin(dapm, "OUT3"); |
Vasily Khoruzhick | 64c25a9 | 2011-03-11 11:05:38 +0200 | [diff] [blame] | 143 | snd_soc_dapm_disable_pin(dapm, "MONO1"); |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 144 | |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 145 | /* Jack detection API stuff */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 146 | ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 147 | &hs_jack); |
| 148 | if (ret) |
| 149 | goto err; |
| 150 | |
| 151 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
| 152 | hs_jack_pins); |
| 153 | if (ret) |
| 154 | goto err; |
| 155 | |
| 156 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 157 | hs_jack_gpios); |
| 158 | if (ret) |
| 159 | goto err; |
| 160 | |
| 161 | return 0; |
| 162 | |
| 163 | err: |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | static struct snd_soc_ops z2_ops = { |
| 168 | .hw_params = z2_hw_params, |
| 169 | }; |
| 170 | |
| 171 | /* z2 digital audio interface glue - connects codec <--> CPU */ |
| 172 | static struct snd_soc_dai_link z2_dai = { |
| 173 | .name = "wm8750", |
| 174 | .stream_name = "WM8750", |
Ian Lartey | a2a0086 | 2010-08-20 17:18:43 +0100 | [diff] [blame] | 175 | .cpu_dai_name = "pxa2xx-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 176 | .codec_dai_name = "wm8750-hifi", |
| 177 | .platform_name = "pxa-pcm-audio", |
Mark Brown | dc5de62 | 2011-08-03 18:22:28 +0900 | [diff] [blame] | 178 | .codec_name = "wm8750.0-001b", |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 179 | .init = z2_wm8750_init, |
Axel Lin | 36c1b40 | 2011-12-30 23:44:37 +0800 | [diff] [blame] | 180 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 181 | SND_SOC_DAIFMT_CBS_CFS, |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 182 | .ops = &z2_ops, |
| 183 | }; |
| 184 | |
| 185 | /* z2 audio machine driver */ |
| 186 | static struct snd_soc_card snd_soc_z2 = { |
| 187 | .name = "Z2", |
Axel Lin | 561c6a1 | 2011-12-22 09:44:43 +0800 | [diff] [blame] | 188 | .owner = THIS_MODULE, |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 189 | .dai_link = &z2_dai, |
| 190 | .num_links = 1, |
Axel Lin | 3c3f51f | 2011-12-31 08:45:49 +0800 | [diff] [blame] | 191 | |
| 192 | .dapm_widgets = wm8750_dapm_widgets, |
| 193 | .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets), |
| 194 | .dapm_routes = z2_audio_map, |
| 195 | .num_dapm_routes = ARRAY_SIZE(z2_audio_map), |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 196 | }; |
| 197 | |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 198 | static struct platform_device *z2_snd_device; |
| 199 | |
| 200 | static int __init z2_init(void) |
| 201 | { |
| 202 | int ret; |
| 203 | |
| 204 | if (!machine_is_zipit2()) |
| 205 | return -ENODEV; |
| 206 | |
| 207 | z2_snd_device = platform_device_alloc("soc-audio", -1); |
| 208 | if (!z2_snd_device) |
| 209 | return -ENOMEM; |
| 210 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 211 | platform_set_drvdata(z2_snd_device, &snd_soc_z2); |
Marek Vasut | d21e0f4 | 2010-04-05 06:13:38 +0200 | [diff] [blame] | 212 | ret = platform_device_add(z2_snd_device); |
| 213 | |
| 214 | if (ret) |
| 215 | platform_device_put(z2_snd_device); |
| 216 | |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | static void __exit z2_exit(void) |
| 221 | { |
| 222 | platform_device_unregister(z2_snd_device); |
| 223 | } |
| 224 | |
| 225 | module_init(z2_init); |
| 226 | module_exit(z2_exit); |
| 227 | |
| 228 | MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, " |
| 229 | "Marek Vasut <marek.vasut@gmail.com>"); |
| 230 | MODULE_DESCRIPTION("ALSA SoC ZipitZ2"); |
| 231 | MODULE_LICENSE("GPL"); |