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