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