24 #include <linux/module.h>
25 #include <linux/slab.h>
32 #include <linux/i2c.h>
49 #define CS42L51_FORMATS ( \
50 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
51 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
52 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
53 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
65 "I2C read failure, addr=0x%x (ret=%d vs %d)\n",
73 static int cs42l51_get_chan_mix(
struct snd_kcontrol *kcontrol,
82 ucontrol->
value.integer.value[0] = 0;
87 ucontrol->
value.integer.value[0] = 1;
90 ucontrol->
value.integer.value[0] = 2;
97 #define CHAN_MIX_NORMAL 0x00
98 #define CHAN_MIX_BOTH 0x55
99 #define CHAN_MIX_SWAP 0xFF
101 static int cs42l51_set_chan_mix(
struct snd_kcontrol *kcontrol,
107 switch (ucontrol->
value.integer.value[0]) {
132 static const char *chan_mix[] = {
138 static const struct soc_enum cs42l51_chan_mix =
144 6, 0x19, 0x7F, adc_pcm_tlv),
149 0, 0x34, 0xE4, aout_tlv),
152 6, 0x19, 0x7F, adc_pcm_tlv),
165 cs42l51_get_chan_mix, cs42l51_set_chan_mix),
193 static const char *cs42l51_dac_names[] = {
"Direct PCM",
195 static const struct soc_enum cs42l51_dac_mux_enum =
200 static const char *cs42l51_adcl_names[] = {
"AIN1 Left",
"AIN2 Left",
201 "MIC Left",
"MIC+preamp Left"};
202 static const struct soc_enum cs42l51_adcl_mux_enum =
207 static const char *cs42l51_adcr_names[] = {
"AIN1 Right",
"AIN2 Right",
208 "MIC Right",
"MIC+preamp Right"};
209 static const struct soc_enum cs42l51_adcr_mux_enum =
252 &cs42l51_dac_mux_controls),
254 &cs42l51_adcl_mux_controls),
256 &cs42l51_adcr_mux_controls),
260 {
"HPL",
NULL,
"Left DAC"},
261 {
"HPR",
NULL,
"Right DAC"},
263 {
"Left ADC",
NULL,
"Left PGA"},
264 {
"Right ADC",
NULL,
"Right PGA"},
266 {
"Mic Preamp Left",
NULL,
"MICL"},
267 {
"Mic Preamp Right",
NULL,
"MICR"},
269 {
"PGA-ADC Mux Left",
"AIN1 Left",
"AIN1L" },
270 {
"PGA-ADC Mux Left",
"AIN2 Left",
"AIN2L" },
271 {
"PGA-ADC Mux Left",
"MIC Left",
"MICL" },
272 {
"PGA-ADC Mux Left",
"MIC+preamp Left",
"Mic Preamp Left" },
273 {
"PGA-ADC Mux Right",
"AIN1 Right",
"AIN1R" },
274 {
"PGA-ADC Mux Right",
"AIN2 Right",
"AIN2R" },
275 {
"PGA-ADC Mux Right",
"MIC Right",
"MICR" },
276 {
"PGA-ADC Mux Right",
"MIC+preamp Right",
"Mic Preamp Right" },
278 {
"Left PGA",
NULL,
"PGA-ADC Mux Left"},
279 {
"Right PGA",
NULL,
"PGA-ADC Mux Right"},
282 static int cs42l51_set_dai_fmt(
struct snd_soc_dai *codec_dai,
307 dev_err(codec->
dev,
"Unknown master/slave configuration\n");
345 static int cs42l51_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
346 int clk_id,
unsigned int freq,
int dir)
367 int intf_ctl, power_ctl,
fmt;
369 switch (cs42l51->
func) {
373 ratios = slave_ratios;
377 ratios = slave_auto_ratios;
385 for (i = 0; i < nr_ratios; i++) {
386 if (ratios[i].ratio == ratio)
390 if (i == nr_ratios) {
392 dev_err(codec->
dev,
"could not find matching ratio\n");
404 switch (cs42l51->
func) {
485 .hw_params = cs42l51_hw_params,
486 .set_sysclk = cs42l51_set_dai_sysclk,
487 .set_fmt = cs42l51_set_dai_fmt,
488 .digital_mute = cs42l51_dai_mute,
492 .name =
"cs42l51-hifi",
494 .stream_name =
"Playback",
501 .stream_name =
"Capture",
507 .ops = &cs42l51_dai_ops,
515 ret = cs42l51_fill_cache(codec);
517 dev_err(codec->
dev,
"failed to fill register cache\n");
523 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
544 .probe = cs42l51_probe,
546 .reg_word_size =
sizeof(
u8),
550 .dapm_widgets = cs42l51_dapm_widgets,
551 .num_dapm_widgets =
ARRAY_SIZE(cs42l51_dapm_widgets),
552 .dapm_routes = cs42l51_routes,
553 .num_dapm_routes =
ARRAY_SIZE(cs42l51_routes),
565 dev_err(&i2c_client->
dev,
"failed to read I2C\n");
571 dev_err(&i2c_client->
dev,
"Invalid chip id\n");
576 dev_info(&i2c_client->
dev,
"found device cs42l51 rev %d\n",
582 dev_err(&i2c_client->
dev,
"could not allocate codec\n");
586 i2c_set_clientdata(i2c_client, cs42l51);
590 &soc_codec_device_cs42l51, &cs42l51_dai, 1);
595 static int cs42l51_i2c_remove(
struct i2c_client *
client)
607 static struct i2c_driver cs42l51_i2c_driver = {
609 .name =
"cs42l51-codec",
612 .id_table = cs42l51_id,
613 .probe = cs42l51_i2c_probe,
614 .remove = cs42l51_i2c_remove,