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