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