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