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