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