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