Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * File: sound/soc/codecs/ssm2602.c |
| 3 | * Author: Cliff Cai <Cliff.Cai@analog.com> |
| 4 | * |
| 5 | * Created: Tue June 06 2008 |
| 6 | * Description: Driver for ssm2602 sound chip |
| 7 | * |
| 8 | * Modified: |
| 9 | * Copyright 2008 Analog Devices Inc. |
| 10 | * |
| 11 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, see the file COPYING, or write |
| 25 | * to the Free Software Foundation, Inc., |
| 26 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | */ |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/moduleparam.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/pm.h> |
| 34 | #include <linux/i2c.h> |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 35 | #include <linux/spi/spi.h> |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 38 | #include <sound/core.h> |
| 39 | #include <sound/pcm.h> |
| 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 42 | #include <sound/initval.h> |
| 43 | |
| 44 | #include "ssm2602.h" |
| 45 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 46 | #define SSM2602_VERSION "0.1" |
| 47 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 48 | /* codec private data */ |
| 49 | struct ssm2602_priv { |
| 50 | unsigned int sysclk; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 51 | enum snd_soc_control_type control_type; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 52 | struct snd_pcm_substream *master_substream; |
| 53 | struct snd_pcm_substream *slave_substream; |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * ssm2602 register cache |
| 58 | * We can't read the ssm2602 register space when we are |
| 59 | * using 2 wire for device control, so we cache them instead. |
| 60 | * There is no point in caching the reset register |
| 61 | */ |
| 62 | static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = { |
| 63 | 0x0017, 0x0017, 0x0079, 0x0079, |
| 64 | 0x0000, 0x0000, 0x0000, 0x000a, |
| 65 | 0x0000, 0x0000 |
| 66 | }; |
| 67 | |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 68 | #define ssm2602_reset(c) snd_soc_write(c, SSM2602_RESET, 0) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 69 | |
| 70 | /*Appending several "None"s just for OSS mixer use*/ |
| 71 | static const char *ssm2602_input_select[] = { |
| 72 | "Line", "Mic", "None", "None", "None", |
| 73 | "None", "None", "None", |
| 74 | }; |
| 75 | |
| 76 | static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; |
| 77 | |
| 78 | static const struct soc_enum ssm2602_enum[] = { |
| 79 | SOC_ENUM_SINGLE(SSM2602_APANA, 2, 2, ssm2602_input_select), |
| 80 | SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, 4, ssm2602_deemph), |
| 81 | }; |
| 82 | |
| 83 | static const struct snd_kcontrol_new ssm2602_snd_controls[] = { |
| 84 | |
| 85 | SOC_DOUBLE_R("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V, |
| 86 | 0, 127, 0), |
| 87 | SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V, |
| 88 | 7, 1, 0), |
| 89 | |
| 90 | SOC_DOUBLE_R("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 31, 0), |
| 91 | SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1), |
| 92 | |
| 93 | SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0), |
Lars-Peter Clausen | 36c90ab | 2011-05-05 16:59:16 +0200 | [diff] [blame] | 94 | SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0), |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 95 | SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1), |
| 96 | |
| 97 | SOC_SINGLE("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1), |
| 98 | |
| 99 | SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1), |
| 100 | SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0), |
| 101 | |
| 102 | SOC_ENUM("Capture Source", ssm2602_enum[0]), |
| 103 | |
| 104 | SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), |
| 105 | }; |
| 106 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 107 | /* Output Mixer */ |
| 108 | static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = { |
| 109 | SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), |
| 110 | SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0), |
| 111 | SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0), |
| 112 | }; |
| 113 | |
| 114 | /* Input mux */ |
| 115 | static const struct snd_kcontrol_new ssm2602_input_mux_controls = |
| 116 | SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]); |
| 117 | |
| 118 | static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = { |
| 119 | SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1, |
| 120 | &ssm2602_output_mixer_controls[0], |
| 121 | ARRAY_SIZE(ssm2602_output_mixer_controls)), |
| 122 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1), |
| 123 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 124 | SND_SOC_DAPM_OUTPUT("LHPOUT"), |
| 125 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| 126 | SND_SOC_DAPM_OUTPUT("RHPOUT"), |
| 127 | SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1), |
| 128 | SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls), |
| 129 | SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0), |
| 130 | SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1), |
| 131 | SND_SOC_DAPM_INPUT("MICIN"), |
| 132 | SND_SOC_DAPM_INPUT("RLINEIN"), |
| 133 | SND_SOC_DAPM_INPUT("LLINEIN"), |
| 134 | }; |
| 135 | |
| 136 | static const struct snd_soc_dapm_route audio_conn[] = { |
| 137 | /* output mixer */ |
| 138 | {"Output Mixer", "Line Bypass Switch", "Line Input"}, |
| 139 | {"Output Mixer", "HiFi Playback Switch", "DAC"}, |
| 140 | {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"}, |
| 141 | |
| 142 | /* outputs */ |
| 143 | {"RHPOUT", NULL, "Output Mixer"}, |
| 144 | {"ROUT", NULL, "Output Mixer"}, |
| 145 | {"LHPOUT", NULL, "Output Mixer"}, |
| 146 | {"LOUT", NULL, "Output Mixer"}, |
| 147 | |
| 148 | /* input mux */ |
| 149 | {"Input Mux", "Line", "Line Input"}, |
| 150 | {"Input Mux", "Mic", "Mic Bias"}, |
| 151 | {"ADC", NULL, "Input Mux"}, |
| 152 | |
| 153 | /* inputs */ |
| 154 | {"Line Input", NULL, "LLINEIN"}, |
| 155 | {"Line Input", NULL, "RLINEIN"}, |
| 156 | {"Mic Bias", NULL, "MICIN"}, |
| 157 | }; |
| 158 | |
| 159 | static int ssm2602_add_widgets(struct snd_soc_codec *codec) |
| 160 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 161 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 162 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 163 | snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets, |
| 164 | ARRAY_SIZE(ssm2602_dapm_widgets)); |
| 165 | snd_soc_dapm_add_routes(dapm, audio_conn, ARRAY_SIZE(audio_conn)); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 166 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 170 | struct ssm2602_coeff { |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 171 | u32 mclk; |
| 172 | u32 rate; |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 173 | u8 srate; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 174 | }; |
| 175 | |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 176 | #define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb)) |
| 177 | |
| 178 | /* codec mclk clock coefficients */ |
| 179 | static const struct ssm2602_coeff ssm2602_coeff_table[] = { |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 180 | /* 48k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 181 | {12288000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x0)}, |
| 182 | {18432000, 48000, SSM2602_COEFF_SRATE(0x0, 0x1, 0x0)}, |
| 183 | {12000000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 184 | |
| 185 | /* 32k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 186 | {12288000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x0)}, |
| 187 | {18432000, 32000, SSM2602_COEFF_SRATE(0x6, 0x1, 0x0)}, |
| 188 | {12000000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 189 | |
| 190 | /* 8k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 191 | {12288000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x0)}, |
| 192 | {18432000, 8000, SSM2602_COEFF_SRATE(0x3, 0x1, 0x0)}, |
| 193 | {11289600, 8000, SSM2602_COEFF_SRATE(0xb, 0x0, 0x0)}, |
| 194 | {16934400, 8000, SSM2602_COEFF_SRATE(0xb, 0x1, 0x0)}, |
| 195 | {12000000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 196 | |
| 197 | /* 96k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 198 | {12288000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x0)}, |
| 199 | {18432000, 96000, SSM2602_COEFF_SRATE(0x7, 0x1, 0x0)}, |
| 200 | {12000000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 201 | |
| 202 | /* 44.1k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 203 | {11289600, 44100, SSM2602_COEFF_SRATE(0x8, 0x0, 0x0)}, |
| 204 | {16934400, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x0)}, |
| 205 | {12000000, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 206 | |
| 207 | /* 88.2k */ |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 208 | {11289600, 88200, SSM2602_COEFF_SRATE(0xf, 0x0, 0x0)}, |
| 209 | {16934400, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x0)}, |
| 210 | {12000000, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x1)}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 211 | }; |
| 212 | |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 213 | static inline int ssm2602_get_coeff(int mclk, int rate) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 214 | { |
| 215 | int i; |
| 216 | |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 217 | for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) { |
| 218 | if (ssm2602_coeff_table[i].rate == rate && |
| 219 | ssm2602_coeff_table[i].mclk == mclk) |
| 220 | return ssm2602_coeff_table[i].srate; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 221 | } |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 222 | return -EINVAL; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static int ssm2602_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 226 | struct snd_pcm_hw_params *params, |
| 227 | struct snd_soc_dai *dai) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 228 | { |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 229 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 230 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 231 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 232 | u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3; |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 233 | int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 234 | |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 235 | if (substream == ssm2602->slave_substream) { |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 236 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
Lars-Peter Clausen | 0b4cd2e | 2011-05-05 16:59:10 +0200 | [diff] [blame^] | 240 | if (srate < 0) |
| 241 | return srate; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 242 | |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 243 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
| 244 | snd_soc_write(codec, SSM2602_SRATE, srate); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 245 | |
| 246 | /* bit size */ |
| 247 | switch (params_format(params)) { |
| 248 | case SNDRV_PCM_FORMAT_S16_LE: |
| 249 | break; |
| 250 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 251 | iface |= 0x0004; |
| 252 | break; |
| 253 | case SNDRV_PCM_FORMAT_S24_LE: |
| 254 | iface |= 0x0008; |
| 255 | break; |
| 256 | case SNDRV_PCM_FORMAT_S32_LE: |
| 257 | iface |= 0x000c; |
| 258 | break; |
| 259 | } |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 260 | snd_soc_write(codec, SSM2602_IFACE, iface); |
| 261 | snd_soc_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 265 | static int ssm2602_startup(struct snd_pcm_substream *substream, |
| 266 | struct snd_soc_dai *dai) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 267 | { |
| 268 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 269 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 270 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 271 | struct i2c_client *i2c = codec->control_data; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 272 | struct snd_pcm_runtime *master_runtime; |
| 273 | |
| 274 | /* The DAI has shared clocks so if we already have a playback or |
| 275 | * capture going then constrain this substream to match it. |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 276 | * TODO: the ssm2602 allows pairs of non-matching PB/REC rates |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 277 | */ |
| 278 | if (ssm2602->master_substream) { |
| 279 | master_runtime = ssm2602->master_substream->runtime; |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 280 | dev_dbg(&i2c->dev, "Constraining to %d bits at %dHz\n", |
| 281 | master_runtime->sample_bits, |
| 282 | master_runtime->rate); |
| 283 | |
Cliff Cai | f692fce | 2009-06-02 00:18:54 -0400 | [diff] [blame] | 284 | if (master_runtime->rate != 0) |
| 285 | snd_pcm_hw_constraint_minmax(substream->runtime, |
| 286 | SNDRV_PCM_HW_PARAM_RATE, |
| 287 | master_runtime->rate, |
| 288 | master_runtime->rate); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 289 | |
Cliff Cai | f692fce | 2009-06-02 00:18:54 -0400 | [diff] [blame] | 290 | if (master_runtime->sample_bits != 0) |
| 291 | snd_pcm_hw_constraint_minmax(substream->runtime, |
| 292 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, |
| 293 | master_runtime->sample_bits, |
| 294 | master_runtime->sample_bits); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 295 | |
| 296 | ssm2602->slave_substream = substream; |
| 297 | } else |
| 298 | ssm2602->master_substream = substream; |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 303 | static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream, |
| 304 | struct snd_soc_dai *dai) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 305 | { |
| 306 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 307 | struct snd_soc_codec *codec = rtd->codec; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 308 | /* set active */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 309 | snd_soc_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 314 | static void ssm2602_shutdown(struct snd_pcm_substream *substream, |
| 315 | struct snd_soc_dai *dai) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 316 | { |
| 317 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 318 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 319 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
Cliff Cai | f692fce | 2009-06-02 00:18:54 -0400 | [diff] [blame] | 320 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 321 | /* deactivate */ |
| 322 | if (!codec->active) |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 323 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
Karl Beldan | faab5a3 | 2008-11-20 15:39:27 +0100 | [diff] [blame] | 324 | |
| 325 | if (ssm2602->master_substream == substream) |
| 326 | ssm2602->master_substream = ssm2602->slave_substream; |
| 327 | |
| 328 | ssm2602->slave_substream = NULL; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) |
| 332 | { |
| 333 | struct snd_soc_codec *codec = dai->codec; |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 334 | u16 mute_reg = snd_soc_read(codec, SSM2602_APDIGI) & ~APDIGI_ENABLE_DAC_MUTE; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 335 | if (mute) |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 336 | snd_soc_write(codec, SSM2602_APDIGI, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 337 | mute_reg | APDIGI_ENABLE_DAC_MUTE); |
| 338 | else |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 339 | snd_soc_write(codec, SSM2602_APDIGI, mute_reg); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 344 | int clk_id, unsigned int freq, int dir) |
| 345 | { |
| 346 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 347 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 348 | switch (freq) { |
| 349 | case 11289600: |
| 350 | case 12000000: |
| 351 | case 12288000: |
| 352 | case 16934400: |
| 353 | case 18432000: |
| 354 | ssm2602->sysclk = freq; |
| 355 | return 0; |
| 356 | } |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | |
| 360 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 361 | unsigned int fmt) |
| 362 | { |
| 363 | struct snd_soc_codec *codec = codec_dai->codec; |
| 364 | u16 iface = 0; |
| 365 | |
| 366 | /* set master/slave audio interface */ |
| 367 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 368 | case SND_SOC_DAIFMT_CBM_CFM: |
| 369 | iface |= 0x0040; |
| 370 | break; |
| 371 | case SND_SOC_DAIFMT_CBS_CFS: |
| 372 | break; |
| 373 | default: |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | /* interface format */ |
| 378 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 379 | case SND_SOC_DAIFMT_I2S: |
| 380 | iface |= 0x0002; |
| 381 | break; |
| 382 | case SND_SOC_DAIFMT_RIGHT_J: |
| 383 | break; |
| 384 | case SND_SOC_DAIFMT_LEFT_J: |
| 385 | iface |= 0x0001; |
| 386 | break; |
| 387 | case SND_SOC_DAIFMT_DSP_A: |
Jarkko Nikula | c691348 | 2008-12-22 10:57:33 +0200 | [diff] [blame] | 388 | iface |= 0x0013; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 389 | break; |
| 390 | case SND_SOC_DAIFMT_DSP_B: |
Jarkko Nikula | c691348 | 2008-12-22 10:57:33 +0200 | [diff] [blame] | 391 | iface |= 0x0003; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 392 | break; |
| 393 | default: |
| 394 | return -EINVAL; |
| 395 | } |
| 396 | |
| 397 | /* clock inversion */ |
| 398 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 399 | case SND_SOC_DAIFMT_NB_NF: |
| 400 | break; |
| 401 | case SND_SOC_DAIFMT_IB_IF: |
| 402 | iface |= 0x0090; |
| 403 | break; |
| 404 | case SND_SOC_DAIFMT_IB_NF: |
| 405 | iface |= 0x0080; |
| 406 | break; |
| 407 | case SND_SOC_DAIFMT_NB_IF: |
| 408 | iface |= 0x0010; |
| 409 | break; |
| 410 | default: |
| 411 | return -EINVAL; |
| 412 | } |
| 413 | |
| 414 | /* set iface */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 415 | snd_soc_write(codec, SSM2602_IFACE, iface); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static int ssm2602_set_bias_level(struct snd_soc_codec *codec, |
| 420 | enum snd_soc_bias_level level) |
| 421 | { |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 422 | u16 reg = snd_soc_read(codec, SSM2602_PWR) & 0xff7f; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 423 | |
| 424 | switch (level) { |
| 425 | case SND_SOC_BIAS_ON: |
| 426 | /* vref/mid, osc on, dac unmute */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 427 | snd_soc_write(codec, SSM2602_PWR, reg); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 428 | break; |
| 429 | case SND_SOC_BIAS_PREPARE: |
| 430 | break; |
| 431 | case SND_SOC_BIAS_STANDBY: |
| 432 | /* everything off except vref/vmid, */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 433 | snd_soc_write(codec, SSM2602_PWR, reg | PWR_CLK_OUT_PDN); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 434 | break; |
| 435 | case SND_SOC_BIAS_OFF: |
| 436 | /* everything off, dac mute, inactive */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 437 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
| 438 | snd_soc_write(codec, SSM2602_PWR, 0xffff); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 439 | break; |
| 440 | |
| 441 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 442 | codec->dapm.bias_level = level; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
Cliff Cai | 2552a71 | 2009-06-02 00:18:53 -0400 | [diff] [blame] | 446 | #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_32000 |\ |
| 447 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ |
| 448 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 449 | |
Karl Beldan | 5de27b6 | 2008-11-20 15:39:31 +0100 | [diff] [blame] | 450 | #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 451 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 452 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 453 | static struct snd_soc_dai_ops ssm2602_dai_ops = { |
| 454 | .startup = ssm2602_startup, |
| 455 | .prepare = ssm2602_pcm_prepare, |
| 456 | .hw_params = ssm2602_hw_params, |
| 457 | .shutdown = ssm2602_shutdown, |
| 458 | .digital_mute = ssm2602_mute, |
| 459 | .set_sysclk = ssm2602_set_dai_sysclk, |
| 460 | .set_fmt = ssm2602_set_dai_fmt, |
| 461 | }; |
| 462 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 463 | static struct snd_soc_dai_driver ssm2602_dai = { |
| 464 | .name = "ssm2602-hifi", |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 465 | .playback = { |
| 466 | .stream_name = "Playback", |
| 467 | .channels_min = 2, |
| 468 | .channels_max = 2, |
| 469 | .rates = SSM2602_RATES, |
Karl Beldan | 5de27b6 | 2008-11-20 15:39:31 +0100 | [diff] [blame] | 470 | .formats = SSM2602_FORMATS,}, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 471 | .capture = { |
| 472 | .stream_name = "Capture", |
| 473 | .channels_min = 2, |
| 474 | .channels_max = 2, |
| 475 | .rates = SSM2602_RATES, |
Karl Beldan | 5de27b6 | 2008-11-20 15:39:31 +0100 | [diff] [blame] | 476 | .formats = SSM2602_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 477 | .ops = &ssm2602_dai_ops, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 478 | }; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 479 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 480 | static int ssm2602_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 481 | { |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 482 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 483 | return 0; |
| 484 | } |
| 485 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 486 | static int ssm2602_resume(struct snd_soc_codec *codec) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 487 | { |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 488 | snd_soc_cache_sync(codec); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 489 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 490 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 491 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 495 | static int ssm2602_probe(struct snd_soc_codec *codec) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 496 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 497 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
| 498 | int ret = 0, reg; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 499 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 500 | pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); |
| 501 | |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 502 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, ssm2602->control_type); |
| 503 | if (ret < 0) { |
| 504 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 505 | return ret; |
| 506 | } |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 507 | |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 508 | ret = ssm2602_reset(codec); |
| 509 | if (ret < 0) { |
| 510 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
| 511 | return ret; |
| 512 | } |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 513 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 514 | /*power on device*/ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 515 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 516 | /* set the update bits */ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 517 | reg = snd_soc_read(codec, SSM2602_LINVOL); |
| 518 | snd_soc_write(codec, SSM2602_LINVOL, reg | LINVOL_LRIN_BOTH); |
| 519 | reg = snd_soc_read(codec, SSM2602_RINVOL); |
| 520 | snd_soc_write(codec, SSM2602_RINVOL, reg | RINVOL_RLIN_BOTH); |
| 521 | reg = snd_soc_read(codec, SSM2602_LOUT1V); |
| 522 | snd_soc_write(codec, SSM2602_LOUT1V, reg | LOUT1V_LRHP_BOTH); |
| 523 | reg = snd_soc_read(codec, SSM2602_ROUT1V); |
| 524 | snd_soc_write(codec, SSM2602_ROUT1V, reg | ROUT1V_RLHP_BOTH); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 525 | /*select Line in as default input*/ |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 526 | snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 527 | APANA_ENABLE_MIC_BOOST); |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 528 | snd_soc_write(codec, SSM2602_PWR, 0); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 529 | |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 530 | snd_soc_add_controls(codec, ssm2602_snd_controls, |
| 531 | ARRAY_SIZE(ssm2602_snd_controls)); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 532 | ssm2602_add_widgets(codec); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 533 | |
Cliff Cai | 93547e8 | 2011-03-27 17:22:57 -0400 | [diff] [blame] | 534 | return 0; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 535 | } |
| 536 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 537 | /* remove everything here */ |
| 538 | static int ssm2602_remove(struct snd_soc_codec *codec) |
| 539 | { |
| 540 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { |
| 545 | .probe = ssm2602_probe, |
| 546 | .remove = ssm2602_remove, |
| 547 | .suspend = ssm2602_suspend, |
| 548 | .resume = ssm2602_resume, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 549 | .set_bias_level = ssm2602_set_bias_level, |
Lars-Peter Clausen | 8fc63fe | 2011-05-05 16:59:14 +0200 | [diff] [blame] | 550 | .reg_cache_size = ARRAY_SIZE(ssm2602_reg), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 551 | .reg_word_size = sizeof(u16), |
| 552 | .reg_cache_default = ssm2602_reg, |
| 553 | }; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 554 | |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 555 | #if defined(CONFIG_SPI_MASTER) |
| 556 | static int __devinit ssm2602_spi_probe(struct spi_device *spi) |
| 557 | { |
| 558 | struct ssm2602_priv *ssm2602; |
| 559 | int ret; |
| 560 | |
| 561 | ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL); |
| 562 | if (ssm2602 == NULL) |
| 563 | return -ENOMEM; |
| 564 | |
| 565 | spi_set_drvdata(spi, ssm2602); |
| 566 | ssm2602->control_type = SND_SOC_SPI; |
| 567 | |
| 568 | ret = snd_soc_register_codec(&spi->dev, |
| 569 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
| 570 | if (ret < 0) |
| 571 | kfree(ssm2602); |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | static int __devexit ssm2602_spi_remove(struct spi_device *spi) |
| 576 | { |
| 577 | snd_soc_unregister_codec(&spi->dev); |
| 578 | kfree(spi_get_drvdata(spi)); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | static struct spi_driver ssm2602_spi_driver = { |
| 583 | .driver = { |
| 584 | .name = "ssm2602", |
| 585 | .owner = THIS_MODULE, |
| 586 | }, |
| 587 | .probe = ssm2602_spi_probe, |
| 588 | .remove = __devexit_p(ssm2602_spi_remove), |
| 589 | }; |
| 590 | #endif |
| 591 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 592 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 593 | /* |
| 594 | * ssm2602 2 wire address is determined by GPIO5 |
| 595 | * state during powerup. |
| 596 | * low = 0x1a |
| 597 | * high = 0x1b |
| 598 | */ |
Lars-Peter Clausen | 04b8945 | 2011-05-05 16:59:12 +0200 | [diff] [blame] | 599 | static int __devinit ssm2602_i2c_probe(struct i2c_client *i2c, |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 600 | const struct i2c_device_id *id) |
| 601 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 602 | struct ssm2602_priv *ssm2602; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 603 | int ret; |
| 604 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 605 | ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL); |
| 606 | if (ssm2602 == NULL) |
| 607 | return -ENOMEM; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 608 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 609 | i2c_set_clientdata(i2c, ssm2602); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 610 | ssm2602->control_type = SND_SOC_I2C; |
| 611 | |
| 612 | ret = snd_soc_register_codec(&i2c->dev, |
| 613 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 614 | if (ret < 0) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 615 | kfree(ssm2602); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 616 | return ret; |
| 617 | } |
| 618 | |
Lars-Peter Clausen | 04b8945 | 2011-05-05 16:59:12 +0200 | [diff] [blame] | 619 | static int __devexit ssm2602_i2c_remove(struct i2c_client *client) |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 620 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | snd_soc_unregister_codec(&client->dev); |
| 622 | kfree(i2c_get_clientdata(client)); |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | static const struct i2c_device_id ssm2602_i2c_id[] = { |
| 627 | { "ssm2602", 0 }, |
| 628 | { } |
| 629 | }; |
| 630 | MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 631 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 632 | /* corgi i2c codec control layer */ |
| 633 | static struct i2c_driver ssm2602_i2c_driver = { |
| 634 | .driver = { |
Mike Frysinger | 2a16101 | 2011-03-27 00:44:10 -0400 | [diff] [blame] | 635 | .name = "ssm2602", |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 636 | .owner = THIS_MODULE, |
| 637 | }, |
| 638 | .probe = ssm2602_i2c_probe, |
Lars-Peter Clausen | 04b8945 | 2011-05-05 16:59:12 +0200 | [diff] [blame] | 639 | .remove = __devexit_p(ssm2602_i2c_remove), |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 640 | .id_table = ssm2602_i2c_id, |
| 641 | }; |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 642 | #endif |
| 643 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 644 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 645 | static int __init ssm2602_modinit(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 646 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 647 | int ret = 0; |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 648 | |
| 649 | #if defined(CONFIG_SPI_MASTER) |
| 650 | ret = spi_register_driver(&ssm2602_spi_driver); |
| 651 | if (ret) |
| 652 | return ret; |
| 653 | #endif |
| 654 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 655 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 656 | ret = i2c_add_driver(&ssm2602_i2c_driver); |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 657 | if (ret) |
| 658 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 659 | #endif |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 660 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 661 | return ret; |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 662 | } |
| 663 | module_init(ssm2602_modinit); |
| 664 | |
| 665 | static void __exit ssm2602_exit(void) |
| 666 | { |
Mike Frysinger | b39e285 | 2011-04-07 02:05:11 -0400 | [diff] [blame] | 667 | #if defined(CONFIG_SPI_MASTER) |
| 668 | spi_unregister_driver(&ssm2602_spi_driver); |
| 669 | #endif |
| 670 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 671 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 672 | i2c_del_driver(&ssm2602_i2c_driver); |
| 673 | #endif |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 674 | } |
| 675 | module_exit(ssm2602_exit); |
| 676 | |
Cliff Cai | b713821 | 2008-09-05 18:09:57 +0800 | [diff] [blame] | 677 | MODULE_DESCRIPTION("ASoC ssm2602 driver"); |
| 678 | MODULE_AUTHOR("Cliff Cai"); |
| 679 | MODULE_LICENSE("GPL"); |