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