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/ 13 14 #include <linux/delay.h> 15 #include <linux/module.h> 16 #include <linux/regmap.h> 17 #include <linux/slab.h> 18 19 #include <sound/pcm.h> 20 #include <sound/pcm_params.h> 21 #include <sound/soc.h> 22 #include <sound/tlv.h> 23 24 #include "ssm2602.h" 25 26 /* codec private data */ 27 struct ssm2602_priv { 28 unsigned int sysclk; 29 const struct snd_pcm_hw_constraint_list *sysclk_constraints; 30 31 struct regmap *regmap; 32 33 enum ssm2602_type type; 34 unsigned int clk_out_pwr; 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 */ 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 } 54 }; 55 56 57 /*Appending several "None"s just for OSS mixer use*/ 58 static const char *ssm2602_input_select[] = { 59 "Line", "Mic", 60 }; 61 62 static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; 63 64 static const struct soc_enum ssm2602_enum[] = { 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), 69 }; 70 71 static const DECLARE_TLV_DB_RANGE(ssm260x_outmix_tlv, 72 0, 47, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0), 73 48, 127, TLV_DB_SCALE_ITEM(-7400, 100, 0) 74 ); 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 79 static const struct snd_kcontrol_new ssm260x_snd_controls[] = { 80 SOC_DOUBLE_R_TLV("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 45, 0, 81 ssm260x_inpga_tlv), 82 SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1), 83 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 87 SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), 88 }; 89 90 static const struct snd_kcontrol_new ssm2602_snd_controls[] = { 91 SOC_DOUBLE_R_TLV("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V, 92 0, 127, 0, ssm260x_outmix_tlv), 93 SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V, 94 7, 1, 0), 95 SOC_SINGLE_TLV("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1, 96 ssm260x_sidetone_tlv), 97 98 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0), 99 SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0), 100 }; 101 102 /* Output Mixer */ 103 static const struct snd_kcontrol_new ssm260x_output_mixer_controls[] = { 104 SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), 105 SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0), 106 SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0), 107 }; 108 109 static const struct snd_kcontrol_new mic_ctl = 110 SOC_DAPM_SINGLE("Switch", SSM2602_APANA, 1, 1, 1); 111 112 /* Input mux */ 113 static const struct snd_kcontrol_new ssm2602_input_mux_controls = 114 SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]); 115 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 134 static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = { 135 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1), 136 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1), 137 SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0), 138 139 SND_SOC_DAPM_SUPPLY("Digital Core Power", SSM2602_ACTIVE, 0, 0, NULL, 0), 140 141 SND_SOC_DAPM_OUTPUT("LOUT"), 142 SND_SOC_DAPM_OUTPUT("ROUT"), 143 SND_SOC_DAPM_INPUT("RLINEIN"), 144 SND_SOC_DAPM_INPUT("LLINEIN"), 145 }; 146 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 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 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[] = { 170 {"DAC", NULL, "Digital Core Power"}, 171 {"ADC", NULL, "Digital Core Power"}, 172 173 {"Output Mixer", "Line Bypass Switch", "Line Input"}, 174 {"Output Mixer", "HiFi Playback Switch", "DAC"}, 175 176 {"ROUT", NULL, "Output Mixer"}, 177 {"LOUT", NULL, "Output Mixer"}, 178 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 189 {"Input Mux", "Line", "Line Input"}, 190 {"Input Mux", "Mic", "Mic Switch"}, 191 {"ADC", NULL, "Input Mux"}, 192 193 {"Mic Switch", NULL, "Mic Bias"}, 194 195 {"Mic Bias", NULL, "MICIN"}, 196 }; 197 198 static const struct snd_soc_dapm_route ssm2604_routes[] = { 199 {"ADC", NULL, "Line Input"}, 200 }; 201 202 static const unsigned int ssm2602_rates_12288000[] = { 203 8000, 16000, 32000, 48000, 96000, 204 }; 205 206 static const struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = { 207 .list = ssm2602_rates_12288000, 208 .count = ARRAY_SIZE(ssm2602_rates_12288000), 209 }; 210 211 static const unsigned int ssm2602_rates_11289600[] = { 212 8000, 11025, 22050, 44100, 88200, 213 }; 214 215 static const struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = { 216 .list = ssm2602_rates_11289600, 217 .count = ARRAY_SIZE(ssm2602_rates_11289600), 218 }; 219 220 struct ssm2602_coeff { 221 u32 mclk; 222 u32 rate; 223 u8 srate; 224 }; 225 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[] = { 230 /* 48k */ 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)}, 234 235 /* 32k */ 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)}, 239 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 245 /* 8k */ 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)}, 251 252 /* 96k */ 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)}, 256 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 267 /* 44.1k */ 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)}, 271 272 /* 88.2k */ 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)}, 276 }; 277 278 static inline int ssm2602_get_coeff(int mclk, int rate) 279 { 280 int i; 281 282 for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) { 283 if (ssm2602_coeff_table[i].rate == rate) { 284 if (ssm2602_coeff_table[i].mclk == mclk) 285 return ssm2602_coeff_table[i].srate; 286 if (ssm2602_coeff_table[i].mclk == mclk / 2) 287 return ssm2602_coeff_table[i].srate | SRATE_CORECLK_DIV2; 288 } 289 } 290 return -EINVAL; 291 } 292 293 static int ssm2602_hw_params(struct snd_pcm_substream *substream, 294 struct snd_pcm_hw_params *params, 295 struct snd_soc_dai *dai) 296 { 297 struct snd_soc_component *component = dai->component; 298 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 299 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); 300 unsigned int iface; 301 302 if (srate < 0) 303 return srate; 304 305 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate); 306 307 /* bit size */ 308 switch (params_width(params)) { 309 case 16: 310 iface = 0x0; 311 break; 312 case 20: 313 iface = 0x4; 314 break; 315 case 24: 316 iface = 0x8; 317 break; 318 case 32: 319 iface = 0xc; 320 break; 321 default: 322 return -EINVAL; 323 } 324 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE, 325 IFACE_AUDIO_DATA_LEN, iface); 326 return 0; 327 } 328 329 static int ssm2602_startup(struct snd_pcm_substream *substream, 330 struct snd_soc_dai *dai) 331 { 332 struct snd_soc_component *component = dai->component; 333 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 334 335 if (ssm2602->sysclk_constraints) { 336 snd_pcm_hw_constraint_list(substream->runtime, 0, 337 SNDRV_PCM_HW_PARAM_RATE, 338 ssm2602->sysclk_constraints); 339 } 340 341 return 0; 342 } 343 344 static int ssm2602_mute(struct snd_soc_dai *dai, int mute, int direction) 345 { 346 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(dai->component); 347 348 if (mute) 349 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, 350 APDIGI_ENABLE_DAC_MUTE, 351 APDIGI_ENABLE_DAC_MUTE); 352 else 353 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, 354 APDIGI_ENABLE_DAC_MUTE, 0); 355 return 0; 356 } 357 358 static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, 359 int clk_id, unsigned int freq, int dir) 360 { 361 struct snd_soc_component *component = codec_dai->component; 362 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 363 364 if (dir == SND_SOC_CLOCK_IN) { 365 if (clk_id != SSM2602_SYSCLK) 366 return -EINVAL; 367 368 switch (freq) { 369 case 12288000: 370 case 18432000: 371 case 24576000: 372 case 36864000: 373 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000; 374 break; 375 case 11289600: 376 case 16934400: 377 case 22579200: 378 case 33868800: 379 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600; 380 break; 381 case 12000000: 382 case 24000000: 383 ssm2602->sysclk_constraints = NULL; 384 break; 385 default: 386 return -EINVAL; 387 } 388 389 ssm2602->sysclk = freq; 390 } else { 391 unsigned int mask; 392 393 switch (clk_id) { 394 case SSM2602_CLK_CLKOUT: 395 mask = PWR_CLK_OUT_PDN; 396 break; 397 case SSM2602_CLK_XTO: 398 mask = PWR_OSC_PDN; 399 break; 400 default: 401 return -EINVAL; 402 } 403 404 if (freq == 0) 405 ssm2602->clk_out_pwr |= mask; 406 else 407 ssm2602->clk_out_pwr &= ~mask; 408 409 regmap_update_bits(ssm2602->regmap, SSM2602_PWR, 410 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); 411 } 412 413 return 0; 414 } 415 416 static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, 417 unsigned int fmt) 418 { 419 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(codec_dai->component); 420 unsigned int iface = 0; 421 422 /* set master/slave audio interface */ 423 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { 424 case SND_SOC_DAIFMT_CBP_CFP: 425 iface |= 0x0040; 426 break; 427 case SND_SOC_DAIFMT_CBC_CFC: 428 break; 429 default: 430 return -EINVAL; 431 } 432 433 /* interface format */ 434 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 435 case SND_SOC_DAIFMT_I2S: 436 iface |= 0x0002; 437 break; 438 case SND_SOC_DAIFMT_RIGHT_J: 439 break; 440 case SND_SOC_DAIFMT_LEFT_J: 441 iface |= 0x0001; 442 break; 443 case SND_SOC_DAIFMT_DSP_A: 444 iface |= 0x0013; 445 break; 446 case SND_SOC_DAIFMT_DSP_B: 447 iface |= 0x0003; 448 break; 449 default: 450 return -EINVAL; 451 } 452 453 /* clock inversion */ 454 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 455 case SND_SOC_DAIFMT_NB_NF: 456 break; 457 case SND_SOC_DAIFMT_IB_IF: 458 iface |= 0x0090; 459 break; 460 case SND_SOC_DAIFMT_IB_NF: 461 iface |= 0x0080; 462 break; 463 case SND_SOC_DAIFMT_NB_IF: 464 iface |= 0x0010; 465 break; 466 default: 467 return -EINVAL; 468 } 469 470 /* set iface */ 471 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface); 472 return 0; 473 } 474 475 static int ssm2602_set_bias_level(struct snd_soc_component *component, 476 enum snd_soc_bias_level level) 477 { 478 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 479 480 switch (level) { 481 case SND_SOC_BIAS_ON: 482 /* vref/mid on, osc and clkout on if enabled */ 483 regmap_update_bits(ssm2602->regmap, SSM2602_PWR, 484 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, 485 ssm2602->clk_out_pwr); 486 break; 487 case SND_SOC_BIAS_PREPARE: 488 break; 489 case SND_SOC_BIAS_STANDBY: 490 /* everything off except vref/vmid, */ 491 regmap_update_bits(ssm2602->regmap, SSM2602_PWR, 492 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, 493 PWR_CLK_OUT_PDN | PWR_OSC_PDN); 494 break; 495 case SND_SOC_BIAS_OFF: 496 /* everything off */ 497 regmap_update_bits(ssm2602->regmap, SSM2602_PWR, 498 PWR_POWER_OFF, PWR_POWER_OFF); 499 break; 500 501 } 502 return 0; 503 } 504 505 #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 506 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ 507 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ 508 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ 509 SNDRV_PCM_RATE_96000) 510 511 #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 512 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 513 514 static const struct snd_soc_dai_ops ssm2602_dai_ops = { 515 .startup = ssm2602_startup, 516 .hw_params = ssm2602_hw_params, 517 .mute_stream = ssm2602_mute, 518 .set_sysclk = ssm2602_set_dai_sysclk, 519 .set_fmt = ssm2602_set_dai_fmt, 520 .no_capture_mute = 1, 521 }; 522 523 static struct snd_soc_dai_driver ssm2602_dai = { 524 .name = "ssm2602-hifi", 525 .playback = { 526 .stream_name = "Playback", 527 .channels_min = 2, 528 .channels_max = 2, 529 .rates = SSM2602_RATES, 530 .formats = SSM2602_FORMATS,}, 531 .capture = { 532 .stream_name = "Capture", 533 .channels_min = 2, 534 .channels_max = 2, 535 .rates = SSM2602_RATES, 536 .formats = SSM2602_FORMATS,}, 537 .ops = &ssm2602_dai_ops, 538 .symmetric_rate = 1, 539 .symmetric_sample_bits = 1, 540 }; 541 542 static int ssm2602_resume(struct snd_soc_component *component) 543 { 544 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 545 546 regcache_sync(ssm2602->regmap); 547 548 return 0; 549 } 550 551 static int ssm2602_component_probe(struct snd_soc_component *component) 552 { 553 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 554 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 555 int ret; 556 557 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V, 558 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); 559 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V, 560 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); 561 562 ret = snd_soc_add_component_controls(component, ssm2602_snd_controls, 563 ARRAY_SIZE(ssm2602_snd_controls)); 564 if (ret) 565 return ret; 566 567 ret = snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets, 568 ARRAY_SIZE(ssm2602_dapm_widgets)); 569 if (ret) 570 return ret; 571 572 return snd_soc_dapm_add_routes(dapm, ssm2602_routes, 573 ARRAY_SIZE(ssm2602_routes)); 574 } 575 576 static int ssm2604_component_probe(struct snd_soc_component *component) 577 { 578 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 579 int ret; 580 581 ret = snd_soc_dapm_new_controls(dapm, ssm2604_dapm_widgets, 582 ARRAY_SIZE(ssm2604_dapm_widgets)); 583 if (ret) 584 return ret; 585 586 return snd_soc_dapm_add_routes(dapm, ssm2604_routes, 587 ARRAY_SIZE(ssm2604_routes)); 588 } 589 590 static int ssm260x_component_probe(struct snd_soc_component *component) 591 { 592 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(component); 593 int ret; 594 595 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0); 596 if (ret < 0) { 597 dev_err(component->dev, "Failed to issue reset: %d\n", ret); 598 return ret; 599 } 600 601 /* set the update bits */ 602 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL, 603 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); 604 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL, 605 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); 606 /*select Line in as default input*/ 607 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC | 608 APANA_ENABLE_MIC_BOOST); 609 610 switch (ssm2602->type) { 611 case SSM2602: 612 ret = ssm2602_component_probe(component); 613 break; 614 case SSM2604: 615 ret = ssm2604_component_probe(component); 616 break; 617 } 618 619 return ret; 620 } 621 622 static const struct snd_soc_component_driver soc_component_dev_ssm2602 = { 623 .probe = ssm260x_component_probe, 624 .resume = ssm2602_resume, 625 .set_bias_level = ssm2602_set_bias_level, 626 .controls = ssm260x_snd_controls, 627 .num_controls = ARRAY_SIZE(ssm260x_snd_controls), 628 .dapm_widgets = ssm260x_dapm_widgets, 629 .num_dapm_widgets = ARRAY_SIZE(ssm260x_dapm_widgets), 630 .dapm_routes = ssm260x_routes, 631 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), 632 .suspend_bias_off = 1, 633 .idle_bias_on = 1, 634 .use_pmdown_time = 1, 635 .endianness = 1, 636 }; 637 638 static bool ssm2602_register_volatile(struct device *dev, unsigned int reg) 639 { 640 return reg == SSM2602_RESET; 641 } 642 643 const struct regmap_config ssm2602_regmap_config = { 644 .val_bits = 9, 645 .reg_bits = 7, 646 647 .max_register = SSM2602_RESET, 648 .volatile_reg = ssm2602_register_volatile, 649 650 .cache_type = REGCACHE_RBTREE, 651 .reg_defaults = ssm2602_reg, 652 .num_reg_defaults = ARRAY_SIZE(ssm2602_reg), 653 }; 654 EXPORT_SYMBOL_GPL(ssm2602_regmap_config); 655 656 int ssm2602_probe(struct device *dev, enum ssm2602_type type, 657 struct regmap *regmap) 658 { 659 struct ssm2602_priv *ssm2602; 660 661 if (IS_ERR(regmap)) 662 return PTR_ERR(regmap); 663 664 ssm2602 = devm_kzalloc(dev, sizeof(*ssm2602), GFP_KERNEL); 665 if (ssm2602 == NULL) 666 return -ENOMEM; 667 668 dev_set_drvdata(dev, ssm2602); 669 ssm2602->type = type; 670 ssm2602->regmap = regmap; 671 672 return devm_snd_soc_register_component(dev, &soc_component_dev_ssm2602, 673 &ssm2602_dai, 1); 674 } 675 EXPORT_SYMBOL_GPL(ssm2602_probe); 676 677 MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver"); 678 MODULE_AUTHOR("Cliff Cai"); 679 MODULE_LICENSE("GPL"); 680