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