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