Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * neo1973_wm8753.c -- SoC audio for Neo1973 |
| 3 | * |
| 4 | * Copyright 2007 Wolfson Microelectronics PLC. |
| 5 | * Author: Graeme Gregory |
| 6 | * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/timer.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/i2c.h> |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/soc.h> |
Mike Montour | a2e31a5 | 2008-06-11 13:47:14 +0100 | [diff] [blame] | 24 | #include <sound/tlv.h> |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 25 | |
Mark Brown | fb2aa07 | 2008-10-08 13:02:20 +0100 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/regs-clock.h> |
| 28 | #include <mach/regs-gpio.h> |
| 29 | #include <mach/hardware.h> |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 30 | #include <linux/io.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/spi-gpio.h> |
Harald Welte | aa9673c | 2007-12-19 15:37:49 +0100 | [diff] [blame] | 32 | |
Ben Dooks | 8150bc8 | 2009-03-04 00:49:26 +0000 | [diff] [blame] | 33 | #include <plat/regs-iis.h> |
Harald Welte | aa9673c | 2007-12-19 15:37:49 +0100 | [diff] [blame] | 34 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 35 | #include "../codecs/wm8753.h" |
| 36 | #include "lm4857.h" |
Jassi Brar | 4b640cf | 2010-11-22 15:35:57 +0900 | [diff] [blame] | 37 | #include "dma.h" |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 38 | #include "s3c24xx-i2s.h" |
| 39 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 40 | static struct snd_soc_card neo1973; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 41 | static struct i2c_client *i2c; |
| 42 | |
| 43 | static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream, |
| 44 | struct snd_pcm_hw_params *params) |
| 45 | { |
| 46 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 47 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 48 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 49 | unsigned int pll_out = 0, bclk = 0; |
| 50 | int ret = 0; |
| 51 | unsigned long iis_clkrate; |
| 52 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 53 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 54 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 55 | iis_clkrate = s3c24xx_i2s_get_clockrate(); |
| 56 | |
| 57 | switch (params_rate(params)) { |
| 58 | case 8000: |
| 59 | case 16000: |
| 60 | pll_out = 12288000; |
| 61 | break; |
| 62 | case 48000: |
| 63 | bclk = WM8753_BCLK_DIV_4; |
| 64 | pll_out = 12288000; |
| 65 | break; |
| 66 | case 96000: |
| 67 | bclk = WM8753_BCLK_DIV_2; |
| 68 | pll_out = 12288000; |
| 69 | break; |
| 70 | case 11025: |
| 71 | bclk = WM8753_BCLK_DIV_16; |
| 72 | pll_out = 11289600; |
| 73 | break; |
| 74 | case 22050: |
| 75 | bclk = WM8753_BCLK_DIV_8; |
| 76 | pll_out = 11289600; |
| 77 | break; |
| 78 | case 44100: |
| 79 | bclk = WM8753_BCLK_DIV_4; |
| 80 | pll_out = 11289600; |
| 81 | break; |
| 82 | case 88200: |
| 83 | bclk = WM8753_BCLK_DIV_2; |
| 84 | pll_out = 11289600; |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | /* set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 89 | ret = snd_soc_dai_set_fmt(codec_dai, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 90 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 91 | SND_SOC_DAIFMT_CBM_CFM); |
| 92 | if (ret < 0) |
| 93 | return ret; |
| 94 | |
| 95 | /* set cpu DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 96 | ret = snd_soc_dai_set_fmt(cpu_dai, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 97 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 98 | SND_SOC_DAIFMT_CBM_CFM); |
| 99 | if (ret < 0) |
| 100 | return ret; |
| 101 | |
| 102 | /* set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 103 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 104 | SND_SOC_CLOCK_IN); |
| 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
| 108 | /* set MCLK division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 109 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 110 | S3C2410_IISMOD_32FS); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 111 | if (ret < 0) |
| 112 | return ret; |
| 113 | |
| 114 | /* set codec BCLK division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 115 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 116 | if (ret < 0) |
| 117 | return ret; |
| 118 | |
| 119 | /* set prescaler division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 120 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 121 | S3C24XX_PRESCALE(4, 4)); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
| 125 | /* codec PLL input is PCLK/4 */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 126 | ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 127 | iis_clkrate / 4, pll_out); |
| 128 | if (ret < 0) |
| 129 | return ret; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream) |
| 135 | { |
| 136 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 137 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 138 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 139 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 140 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 141 | /* disable the PLL */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 142 | return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
| 146 | * Neo1973 WM8753 HiFi DAI opserations. |
| 147 | */ |
| 148 | static struct snd_soc_ops neo1973_hifi_ops = { |
| 149 | .hw_params = neo1973_hifi_hw_params, |
| 150 | .hw_free = neo1973_hifi_hw_free, |
| 151 | }; |
| 152 | |
| 153 | static int neo1973_voice_hw_params(struct snd_pcm_substream *substream, |
| 154 | struct snd_pcm_hw_params *params) |
| 155 | { |
| 156 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 157 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 158 | unsigned int pcmdiv = 0; |
| 159 | int ret = 0; |
| 160 | unsigned long iis_clkrate; |
| 161 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 162 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 163 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 164 | iis_clkrate = s3c24xx_i2s_get_clockrate(); |
| 165 | |
| 166 | if (params_rate(params) != 8000) |
| 167 | return -EINVAL; |
| 168 | if (params_channels(params) != 1) |
| 169 | return -EINVAL; |
| 170 | |
| 171 | pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */ |
| 172 | |
| 173 | /* todo: gg check mode (DSP_B) against CSR datasheet */ |
| 174 | /* set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 175 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 176 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); |
| 177 | if (ret < 0) |
| 178 | return ret; |
| 179 | |
| 180 | /* set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 181 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 182 | SND_SOC_CLOCK_IN); |
| 183 | if (ret < 0) |
| 184 | return ret; |
| 185 | |
| 186 | /* set codec PCM division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 187 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 188 | if (ret < 0) |
| 189 | return ret; |
| 190 | |
Andrea Gelmini | fa2eb00 | 2010-10-16 15:19:20 +0200 | [diff] [blame] | 191 | /* configure and enable PLL for 12.288MHz output */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 192 | ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 193 | iis_clkrate / 4, 12288000); |
| 194 | if (ret < 0) |
| 195 | return ret; |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int neo1973_voice_hw_free(struct snd_pcm_substream *substream) |
| 201 | { |
| 202 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 203 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 204 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 205 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 206 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 207 | /* disable the PLL */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 208 | return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static struct snd_soc_ops neo1973_voice_ops = { |
| 212 | .hw_params = neo1973_voice_hw_params, |
| 213 | .hw_free = neo1973_voice_hw_free, |
| 214 | }; |
| 215 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 216 | static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0}; |
| 217 | |
| 218 | static void lm4857_write_regs(void) |
| 219 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 220 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 221 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 222 | if (i2c_master_send(i2c, lm4857_regs, 4) != 4) |
| 223 | printk(KERN_ERR "lm4857: i2c write failed\n"); |
| 224 | } |
| 225 | |
| 226 | static int lm4857_get_reg(struct snd_kcontrol *kcontrol, |
| 227 | struct snd_ctl_elem_value *ucontrol) |
| 228 | { |
Mark Brown | 236e672 | 2009-06-10 13:55:34 +0100 | [diff] [blame] | 229 | struct soc_mixer_control *mc = |
| 230 | (struct soc_mixer_control *)kcontrol->private_value; |
| 231 | int reg = mc->reg; |
| 232 | int shift = mc->shift; |
| 233 | int mask = mc->max; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 234 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 235 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 236 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 237 | ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask; |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int lm4857_set_reg(struct snd_kcontrol *kcontrol, |
| 242 | struct snd_ctl_elem_value *ucontrol) |
| 243 | { |
Mark Brown | 236e672 | 2009-06-10 13:55:34 +0100 | [diff] [blame] | 244 | struct soc_mixer_control *mc = |
| 245 | (struct soc_mixer_control *)kcontrol->private_value; |
| 246 | int reg = mc->reg; |
| 247 | int shift = mc->shift; |
| 248 | int mask = mc->max; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 249 | |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 250 | if (((lm4857_regs[reg] >> shift) & mask) == |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 251 | ucontrol->value.integer.value[0]) |
| 252 | return 0; |
| 253 | |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 254 | lm4857_regs[reg] &= ~(mask << shift); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 255 | lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift; |
| 256 | lm4857_write_regs(); |
| 257 | return 1; |
| 258 | } |
| 259 | |
| 260 | static int lm4857_get_mode(struct snd_kcontrol *kcontrol, |
| 261 | struct snd_ctl_elem_value *ucontrol) |
| 262 | { |
| 263 | u8 value = lm4857_regs[LM4857_CTRL] & 0x0F; |
| 264 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 265 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 266 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 267 | if (value) |
| 268 | value -= 5; |
| 269 | |
| 270 | ucontrol->value.integer.value[0] = value; |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static int lm4857_set_mode(struct snd_kcontrol *kcontrol, |
| 275 | struct snd_ctl_elem_value *ucontrol) |
| 276 | { |
| 277 | u8 value = ucontrol->value.integer.value[0]; |
| 278 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 279 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 280 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 281 | if (value) |
| 282 | value += 5; |
| 283 | |
| 284 | if ((lm4857_regs[LM4857_CTRL] & 0x0F) == value) |
| 285 | return 0; |
| 286 | |
| 287 | lm4857_regs[LM4857_CTRL] &= 0xF0; |
| 288 | lm4857_regs[LM4857_CTRL] |= value; |
| 289 | lm4857_write_regs(); |
| 290 | return 1; |
| 291 | } |
| 292 | |
| 293 | static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = { |
| 294 | SND_SOC_DAPM_LINE("Audio Out", NULL), |
| 295 | SND_SOC_DAPM_LINE("GSM Line Out", NULL), |
| 296 | SND_SOC_DAPM_LINE("GSM Line In", NULL), |
| 297 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 298 | SND_SOC_DAPM_MIC("Call Mic", NULL), |
| 299 | }; |
| 300 | |
| 301 | |
Mark Brown | 8f3112d | 2008-05-13 14:58:03 +0200 | [diff] [blame] | 302 | static const struct snd_soc_dapm_route dapm_routes[] = { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 303 | |
| 304 | /* Connections to the lm4857 amp */ |
| 305 | {"Audio Out", NULL, "LOUT1"}, |
| 306 | {"Audio Out", NULL, "ROUT1"}, |
| 307 | |
| 308 | /* Connections to the GSM Module */ |
| 309 | {"GSM Line Out", NULL, "MONO1"}, |
| 310 | {"GSM Line Out", NULL, "MONO2"}, |
| 311 | {"RXP", NULL, "GSM Line In"}, |
| 312 | {"RXN", NULL, "GSM Line In"}, |
| 313 | |
| 314 | /* Connections to Headset */ |
| 315 | {"MIC1", NULL, "Mic Bias"}, |
| 316 | {"Mic Bias", NULL, "Headset Mic"}, |
| 317 | |
| 318 | /* Call Mic */ |
| 319 | {"MIC2", NULL, "Mic Bias"}, |
| 320 | {"MIC2N", NULL, "Mic Bias"}, |
| 321 | {"Mic Bias", NULL, "Call Mic"}, |
| 322 | |
| 323 | /* Connect the ALC pins */ |
| 324 | {"ACIN", NULL, "ACOP"}, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | static const char *lm4857_mode[] = { |
| 328 | "Off", |
| 329 | "Call Speaker", |
| 330 | "Stereo Speakers", |
| 331 | "Stereo Speakers + Headphones", |
| 332 | "Headphones" |
| 333 | }; |
| 334 | |
| 335 | static const struct soc_enum lm4857_mode_enum[] = { |
| 336 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode), |
| 337 | }; |
| 338 | |
Mike Montour | a2e31a5 | 2008-06-11 13:47:14 +0100 | [diff] [blame] | 339 | static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0); |
| 340 | static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0); |
| 341 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 342 | static const struct snd_kcontrol_new wm8753_neo1973_controls[] = { |
Lars-Peter Clausen | 004c52e | 2011-03-07 08:04:54 +0100 | [diff] [blame^] | 343 | SOC_DAPM_PIN_SWITCH("Audio Out"), |
| 344 | SOC_DAPM_PIN_SWITCH("GSM Line Out"), |
| 345 | SOC_DAPM_PIN_SWITCH("GSM Line In"), |
| 346 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 347 | SOC_DAPM_PIN_SWITCH("Call Mic"), |
| 348 | |
Mike Montour | a2e31a5 | 2008-06-11 13:47:14 +0100 | [diff] [blame] | 349 | SOC_SINGLE_EXT_TLV("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0, |
| 350 | lm4857_get_reg, lm4857_set_reg, stereo_tlv), |
| 351 | SOC_SINGLE_EXT_TLV("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0, |
| 352 | lm4857_get_reg, lm4857_set_reg, stereo_tlv), |
| 353 | SOC_SINGLE_EXT_TLV("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0, |
| 354 | lm4857_get_reg, lm4857_set_reg, mono_tlv), |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 355 | SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0], |
| 356 | lm4857_get_mode, lm4857_set_mode), |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 357 | SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0, |
| 358 | lm4857_get_reg, lm4857_set_reg), |
| 359 | SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0, |
| 360 | lm4857_get_reg, lm4857_set_reg), |
| 361 | SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0, |
| 362 | lm4857_get_reg, lm4857_set_reg), |
| 363 | SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0, |
| 364 | lm4857_get_reg, lm4857_set_reg), |
| 365 | }; |
| 366 | |
| 367 | /* |
| 368 | * This is an example machine initialisation for a wm8753 connected to a |
| 369 | * neo1973 II. It is missing logic to detect hp/mic insertions and logic |
| 370 | * to re-route the audio in such an event. |
| 371 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd) |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 373 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 374 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 375 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 376 | int err; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 377 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 378 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 379 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 380 | /* set up NC codec pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 381 | snd_soc_dapm_nc_pin(dapm, "LOUT2"); |
| 382 | snd_soc_dapm_nc_pin(dapm, "ROUT2"); |
| 383 | snd_soc_dapm_nc_pin(dapm, "OUT3"); |
| 384 | snd_soc_dapm_nc_pin(dapm, "OUT4"); |
| 385 | snd_soc_dapm_nc_pin(dapm, "LINE1"); |
| 386 | snd_soc_dapm_nc_pin(dapm, "LINE2"); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 387 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 388 | /* Add neo1973 specific widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 389 | snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets, |
Mark Brown | 8f3112d | 2008-05-13 14:58:03 +0200 | [diff] [blame] | 390 | ARRAY_SIZE(wm8753_dapm_widgets)); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 391 | |
Jonas Bonn | e808994 | 2008-10-01 18:17:12 +0100 | [diff] [blame] | 392 | /* set endpoints to default mode */ |
Lars-Peter Clausen | 004c52e | 2011-03-07 08:04:54 +0100 | [diff] [blame^] | 393 | snd_soc_dapm_disable_pin(dapm, "Audio Out"); |
| 394 | snd_soc_dapm_disable_pin(dapm, "GSM Line Out"); |
| 395 | snd_soc_dapm_disable_pin(dapm, "GSM Line In"); |
| 396 | snd_soc_dapm_disable_pin(dapm, "Headset Mic"); |
| 397 | snd_soc_dapm_disable_pin(dapm, "Call Mic"); |
Jonas Bonn | e808994 | 2008-10-01 18:17:12 +0100 | [diff] [blame] | 398 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 399 | /* add neo1973 specific controls */ |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 400 | err = snd_soc_add_controls(codec, wm8753_neo1973_controls, |
| 401 | ARRAY_SIZE(8753_neo1973_controls)); |
| 402 | if (err < 0) |
| 403 | return err; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 404 | |
Mark Brown | 8f3112d | 2008-05-13 14:58:03 +0200 | [diff] [blame] | 405 | /* set up neo1973 specific audio routes */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 406 | err = snd_soc_dapm_add_routes(dapm, dapm_routes, |
Mark Brown | 8f3112d | 2008-05-13 14:58:03 +0200 | [diff] [blame] | 407 | ARRAY_SIZE(dapm_routes)); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 408 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 409 | snd_soc_dapm_sync(dapm); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * BT Codec DAI |
| 415 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 416 | static struct snd_soc_dai bt_dai = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 417 | .name = "bluetooth-dai", |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 418 | .playback = { |
| 419 | .channels_min = 1, |
| 420 | .channels_max = 1, |
| 421 | .rates = SNDRV_PCM_RATE_8000, |
| 422 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 423 | .capture = { |
| 424 | .channels_min = 1, |
| 425 | .channels_max = 1, |
| 426 | .rates = SNDRV_PCM_RATE_8000, |
| 427 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 428 | }; |
| 429 | |
| 430 | static struct snd_soc_dai_link neo1973_dai[] = { |
| 431 | { /* Hifi Playback - for similatious use with voice below */ |
| 432 | .name = "WM8753", |
| 433 | .stream_name = "WM8753 HiFi", |
Jassi Brar | 58bb407 | 2010-11-22 15:35:50 +0900 | [diff] [blame] | 434 | .platform_name = "samsung-audio", |
Lars-Peter Clausen | 518aa59 | 2011-01-24 22:12:42 +0100 | [diff] [blame] | 435 | .cpu_dai_name = "s3c24xx-iis", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 436 | .codec_dai_name = "wm8753-hifi", |
Lars-Peter Clausen | 81d7da5 | 2011-01-24 22:09:22 +0100 | [diff] [blame] | 437 | .codec_name = "wm8753-codec.0-001a", |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 438 | .init = neo1973_wm8753_init, |
| 439 | .ops = &neo1973_hifi_ops, |
| 440 | }, |
| 441 | { /* Voice via BT */ |
| 442 | .name = "Bluetooth", |
| 443 | .stream_name = "Voice", |
Jassi Brar | 58bb407 | 2010-11-22 15:35:50 +0900 | [diff] [blame] | 444 | .platform_name = "samsung-audio", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 445 | .cpu_dai_name = "bluetooth-dai", |
| 446 | .codec_dai_name = "wm8753-voice", |
Lars-Peter Clausen | 81d7da5 | 2011-01-24 22:09:22 +0100 | [diff] [blame] | 447 | .codec_name = "wm8753-codec.0-001a", |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 448 | .ops = &neo1973_voice_ops, |
| 449 | }, |
| 450 | }; |
| 451 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 452 | static struct snd_soc_card neo1973 = { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 453 | .name = "neo1973", |
| 454 | .dai_link = neo1973_dai, |
| 455 | .num_links = ARRAY_SIZE(neo1973_dai), |
| 456 | }; |
| 457 | |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 458 | static int lm4857_i2c_probe(struct i2c_client *client, |
| 459 | const struct i2c_device_id *id) |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 460 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 461 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 462 | |
Jonas Bonn | f9d1ab3 | 2008-10-01 21:47:19 +0200 | [diff] [blame] | 463 | i2c = client; |
| 464 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 465 | lm4857_write_regs(); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 469 | static int lm4857_i2c_remove(struct i2c_client *client) |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 470 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 471 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 472 | |
Jonas Bonn | f9d1ab3 | 2008-10-01 21:47:19 +0200 | [diff] [blame] | 473 | i2c = NULL; |
| 474 | |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 475 | return 0; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Graeme Gregory | fd403dc | 2008-04-30 20:26:45 +0200 | [diff] [blame] | 478 | static u8 lm4857_state; |
| 479 | |
| 480 | static int lm4857_suspend(struct i2c_client *dev, pm_message_t state) |
| 481 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 482 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 483 | |
Graeme Gregory | fd403dc | 2008-04-30 20:26:45 +0200 | [diff] [blame] | 484 | dev_dbg(&dev->dev, "lm4857_suspend\n"); |
| 485 | lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf; |
| 486 | if (lm4857_state) { |
| 487 | lm4857_regs[LM4857_CTRL] &= 0xf0; |
| 488 | lm4857_write_regs(); |
| 489 | } |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static int lm4857_resume(struct i2c_client *dev) |
| 494 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 495 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 496 | |
Graeme Gregory | fd403dc | 2008-04-30 20:26:45 +0200 | [diff] [blame] | 497 | if (lm4857_state) { |
| 498 | lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f); |
| 499 | lm4857_write_regs(); |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static void lm4857_shutdown(struct i2c_client *dev) |
| 505 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 506 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 507 | |
Graeme Gregory | fd403dc | 2008-04-30 20:26:45 +0200 | [diff] [blame] | 508 | dev_dbg(&dev->dev, "lm4857_shutdown\n"); |
| 509 | lm4857_regs[LM4857_CTRL] &= 0xf0; |
| 510 | lm4857_write_regs(); |
| 511 | } |
| 512 | |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 513 | static const struct i2c_device_id lm4857_i2c_id[] = { |
Mark Brown | df20cf9 | 2008-09-24 11:57:27 +0100 | [diff] [blame] | 514 | { "neo1973_lm4857", 0 }, |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 515 | { } |
| 516 | }; |
| 517 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 518 | static struct i2c_driver lm4857_i2c_driver = { |
| 519 | .driver = { |
| 520 | .name = "LM4857 I2C Amp", |
| 521 | .owner = THIS_MODULE, |
| 522 | }, |
Graeme Gregory | fd403dc | 2008-04-30 20:26:45 +0200 | [diff] [blame] | 523 | .suspend = lm4857_suspend, |
| 524 | .resume = lm4857_resume, |
| 525 | .shutdown = lm4857_shutdown, |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 526 | .probe = lm4857_i2c_probe, |
| 527 | .remove = lm4857_i2c_remove, |
| 528 | .id_table = lm4857_i2c_id, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | static struct platform_device *neo1973_snd_device; |
| 532 | |
| 533 | static int __init neo1973_init(void) |
| 534 | { |
| 535 | int ret; |
| 536 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 537 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 538 | |
Mark Brown | fb2aa07 | 2008-10-08 13:02:20 +0100 | [diff] [blame] | 539 | if (!machine_is_neo1973_gta01()) { |
| 540 | printk(KERN_INFO |
| 541 | "Only GTA01 hardware supported by ASoC driver\n"); |
| 542 | return -ENODEV; |
| 543 | } |
| 544 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 545 | neo1973_snd_device = platform_device_alloc("soc-audio", -1); |
| 546 | if (!neo1973_snd_device) |
| 547 | return -ENOMEM; |
| 548 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 549 | platform_set_drvdata(neo1973_snd_device, &neo1973); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 550 | ret = platform_device_add(neo1973_snd_device); |
| 551 | |
Jean Delvare | d280289 | 2008-09-01 17:44:05 +0200 | [diff] [blame] | 552 | if (ret) { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 553 | platform_device_put(neo1973_snd_device); |
Jean Delvare | d280289 | 2008-09-01 17:44:05 +0200 | [diff] [blame] | 554 | return ret; |
| 555 | } |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 556 | |
Jonas Bonn | f9d1ab3 | 2008-10-01 21:47:19 +0200 | [diff] [blame] | 557 | ret = i2c_add_driver(&lm4857_i2c_driver); |
| 558 | |
Jean Delvare | b647130 | 2008-09-01 17:46:57 +0200 | [diff] [blame] | 559 | if (ret != 0) |
Jean Delvare | d280289 | 2008-09-01 17:44:05 +0200 | [diff] [blame] | 560 | platform_device_unregister(neo1973_snd_device); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 561 | |
| 562 | return ret; |
| 563 | } |
| 564 | |
| 565 | static void __exit neo1973_exit(void) |
| 566 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 567 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 568 | |
Tim Niemeyer | 6b9a9b3 | 2008-04-22 17:10:23 +0200 | [diff] [blame] | 569 | i2c_del_driver(&lm4857_i2c_driver); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 570 | platform_device_unregister(neo1973_snd_device); |
| 571 | } |
| 572 | |
| 573 | module_init(neo1973_init); |
| 574 | module_exit(neo1973_exit); |
| 575 | |
| 576 | /* Module information */ |
Graeme Gregory | 443590e | 2008-04-30 20:25:23 +0200 | [diff] [blame] | 577 | MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org"); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 578 | MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973"); |
| 579 | MODULE_LICENSE("GPL"); |