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