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