17 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/slab.h>
21 #include <linux/errno.h>
24 #include <linux/i2c.h>
47 0x0502, 0x0000, 0x0000, 0x3f3f,
48 0x0202, 0x0000, 0x0000, 0x0000,
49 0x0000, 0x0000, 0x0000, 0x0000,
50 0x0000, 0x0000, 0x0000, 0x0000,
51 0x0000, 0xff00, 0x0000, 0x4800,
52 0x0000, 0x0000, 0x0000, 0x0000,
53 0x0000, 0x0000, 0x0000, 0x0000,
54 0x0000, 0x0000, 0x0000, 0x0000,
55 0x0000, 0x8000, 0x0002, 0x0000,
58 static unsigned long uda1380_cache_dirty;
77 static inline void uda1380_write_reg_cache(
struct snd_soc_codec *codec,
84 if ((reg >= 0x10) && (cache[reg] != value))
85 set_bit(reg - 0x10, &uda1380_cache_dirty);
92 static int uda1380_write(
struct snd_soc_codec *codec,
unsigned int reg,
103 data[1] = (value & 0xff00) >> 8;
104 data[2] = value & 0x00ff;
106 uda1380_write_reg_cache(codec, reg, value);
113 pr_debug(
"uda1380: hw write %x val %x\n", reg, value);
118 val = (data[0]<<8) | data[1];
120 pr_debug(
"uda1380: READ BACK VAL %x\n",
121 (data[0]<<8) | data[1]);
125 clear_bit(reg - 0x10, &uda1380_cache_dirty);
140 data[1] = (cache[
reg] & 0xff00) >> 8;
141 data[2] = cache[
reg] & 0x00ff;
143 dev_err(codec->
dev,
"%s: write to reg 0x%x failed\n",
164 dev_err(codec->
dev,
"%s: failed\n", __func__);
180 pr_debug(
"uda1380: flush reg %x val %x:\n", reg,
181 uda1380_read_reg_cache(uda1380_codec, reg));
182 uda1380_write(uda1380_codec, reg,
183 uda1380_read_reg_cache(uda1380_codec, reg));
190 static const char *uda1380_deemp[] = {
197 static const char *uda1380_input_sel[] = {
203 static const char *uda1380_output_sel[] = {
207 static const char *uda1380_spf_mode[] = {
213 static const char *uda1380_capture_sel[] = {
217 static const char *uda1380_sel_ns[] = {
221 static const char *uda1380_mix_control[] = {
224 "before sound processing",
225 "after sound processing"
227 static const char *uda1380_sdet_setting[] = {
233 static const char *uda1380_os_setting[] = {
235 "double-speed (no mixing)",
236 "quad-speed (no mixing)"
239 static const struct soc_enum uda1380_deemp_enum[] = {
243 static const struct soc_enum uda1380_input_sel_enum =
245 static const struct soc_enum uda1380_output_sel_enum =
247 static const struct soc_enum uda1380_spf_enum =
249 static const struct soc_enum uda1380_capture_sel_enum =
251 static const struct soc_enum uda1380_sel_ns_enum =
253 static const struct soc_enum uda1380_mix_enum =
255 static const struct soc_enum uda1380_sdet_enum =
257 static const struct soc_enum uda1380_os_enum =
270 static const unsigned int mvol_tlv[] = {
283 static const unsigned int vc_tlv[] = {
309 SOC_DOUBLE_TLV(
"Master Playback Volume", UDA1380_MVOL, 0, 8, 252, 1, mvol_tlv),
312 SOC_ENUM(
"Sound Processing Filter", uda1380_spf_enum),
317 SOC_ENUM(
"ADC Playback De-emphasis", uda1380_deemp_enum[0]),
319 SOC_ENUM(
"PCM Playback De-emphasis", uda1380_deemp_enum[1]),
321 SOC_ENUM(
"Noise Shaper", uda1380_sel_ns_enum),
322 SOC_ENUM(
"Digital Mixer Signal Control", uda1380_mix_enum),
324 SOC_ENUM(
"Silence Detector Setting", uda1380_sdet_enum),
325 SOC_ENUM(
"Oversampling Input", uda1380_os_enum),
354 &uda1380_input_mux_control),
356 &uda1380_output_mux_control),
358 &uda1380_capture_mux_control),
379 {
"HeadPhone Driver",
NULL,
"Output Mux"},
380 {
"VOUTR",
NULL,
"Output Mux"},
381 {
"VOUTL",
NULL,
"Output Mux"},
383 {
"Analog Mixer",
NULL,
"VINR"},
384 {
"Analog Mixer",
NULL,
"VINL"},
385 {
"Analog Mixer",
NULL,
"DAC"},
387 {
"Output Mux",
"DAC",
"DAC"},
388 {
"Output Mux",
"Analog Mixer",
"Analog Mixer"},
393 {
"VOUTLHP",
NULL,
"HeadPhone Driver"},
394 {
"VOUTRHP",
NULL,
"HeadPhone Driver"},
397 {
"Left ADC",
NULL,
"Input Mux"},
398 {
"Input Mux",
"Mic",
"Mic LNA"},
399 {
"Input Mux",
"Mic + Line R",
"Mic LNA"},
400 {
"Input Mux",
"Line L",
"Left PGA"},
401 {
"Input Mux",
"Line",
"Left PGA"},
404 {
"Right ADC",
"Mic + Line R",
"Right PGA"},
405 {
"Right ADC",
"Line",
"Right PGA"},
408 {
"Mic LNA",
NULL,
"VINM"},
409 {
"Left PGA",
NULL,
"VINL"},
410 {
"Right PGA",
NULL,
"VINR"},
413 static int uda1380_set_dai_fmt_both(
struct snd_soc_dai *codec_dai,
443 static int uda1380_set_dai_fmt_playback(
struct snd_soc_dai *codec_dai,
453 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
473 static int uda1380_set_dai_fmt_capture(
struct snd_soc_dai *codec_dai,
483 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
506 struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec);
542 case 12501 ... 25000:
545 case 25001 ... 50000:
548 case 50001 ... 100000:
572 if (clk & R00_DAC_CLK) {
585 static int uda1380_set_bias_level(
struct snd_soc_codec *codec,
588 int pm = uda1380_read_reg_cache(codec,
UDA1380_PM);
592 if (codec->
dapm.bias_level == level)
606 uda1380_reset(codec);
609 uda1380_sync_cache(codec);
623 set_bit(reg - 0x10, &uda1380_cache_dirty);
629 #define UDA1380_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
630 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
631 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
634 .hw_params = uda1380_pcm_hw_params,
635 .shutdown = uda1380_pcm_shutdown,
636 .trigger = uda1380_trigger,
637 .set_fmt = uda1380_set_dai_fmt_both,
641 .hw_params = uda1380_pcm_hw_params,
642 .shutdown = uda1380_pcm_shutdown,
643 .trigger = uda1380_trigger,
644 .set_fmt = uda1380_set_dai_fmt_playback,
648 .hw_params = uda1380_pcm_hw_params,
649 .shutdown = uda1380_pcm_shutdown,
650 .trigger = uda1380_trigger,
651 .set_fmt = uda1380_set_dai_fmt_capture,
656 .name =
"uda1380-hifi",
658 .stream_name =
"Playback",
664 .stream_name =
"Capture",
669 .ops = &uda1380_dai_ops,
672 .name =
"uda1380-hifi-playback",
674 .stream_name =
"Playback",
680 .ops = &uda1380_dai_ops_playback,
683 .name =
"uda1380-hifi-capture",
685 .stream_name =
"Capture",
691 .ops = &uda1380_dai_ops_capture,
710 struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec);
734 ret = uda1380_reset(codec);
777 .probe = uda1380_probe,
778 .remove = uda1380_remove,
779 .suspend = uda1380_suspend,
780 .resume = uda1380_resume,
781 .read = uda1380_read_reg_cache,
782 .write = uda1380_write,
783 .set_bias_level = uda1380_set_bias_level,
785 .reg_word_size =
sizeof(
u16),
791 .dapm_widgets = uda1380_dapm_widgets,
792 .num_dapm_widgets =
ARRAY_SIZE(uda1380_dapm_widgets),
793 .dapm_routes = uda1380_dapm_routes,
794 .num_dapm_routes =
ARRAY_SIZE(uda1380_dapm_routes),
797 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
809 i2c_set_clientdata(i2c, uda1380);
813 &soc_codec_dev_uda1380, uda1380_dai,
ARRAY_SIZE(uda1380_dai));
829 static struct i2c_driver uda1380_i2c_driver = {
831 .name =
"uda1380-codec",
834 .probe = uda1380_i2c_probe,
836 .id_table = uda1380_i2c_id,
840 static int __init uda1380_modinit(
void)
843 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
844 ret = i2c_add_driver(&uda1380_i2c_driver);
846 pr_err(
"Failed to register UDA1380 I2C driver: %d\n", ret);
852 static void __exit uda1380_exit(
void)
854 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)