11 #include <linux/module.h>
13 #include <linux/i2c.h>
15 #include <linux/slab.h>
24 #define ADAU1701_DSPCTRL 0x1c
25 #define ADAU1701_SEROCTL 0x1e
26 #define ADAU1701_SERICTL 0x1f
28 #define ADAU1701_AUXNPOW 0x22
30 #define ADAU1701_OSCIPOW 0x26
31 #define ADAU1701_DACSET 0x27
33 #define ADAU1701_NUM_REGS 0x28
35 #define ADAU1701_DSPCTRL_CR (1 << 2)
36 #define ADAU1701_DSPCTRL_DAM (1 << 3)
37 #define ADAU1701_DSPCTRL_ADM (1 << 4)
38 #define ADAU1701_DSPCTRL_SR_48 0x00
39 #define ADAU1701_DSPCTRL_SR_96 0x01
40 #define ADAU1701_DSPCTRL_SR_192 0x02
41 #define ADAU1701_DSPCTRL_SR_MASK 0x03
43 #define ADAU1701_SEROCTL_INV_LRCLK 0x2000
44 #define ADAU1701_SEROCTL_INV_BCLK 0x1000
45 #define ADAU1701_SEROCTL_MASTER 0x0800
47 #define ADAU1701_SEROCTL_OBF16 0x0000
48 #define ADAU1701_SEROCTL_OBF8 0x0200
49 #define ADAU1701_SEROCTL_OBF4 0x0400
50 #define ADAU1701_SEROCTL_OBF2 0x0600
51 #define ADAU1701_SEROCTL_OBF_MASK 0x0600
53 #define ADAU1701_SEROCTL_OLF1024 0x0000
54 #define ADAU1701_SEROCTL_OLF512 0x0080
55 #define ADAU1701_SEROCTL_OLF256 0x0100
56 #define ADAU1701_SEROCTL_OLF_MASK 0x0180
58 #define ADAU1701_SEROCTL_MSB_DEALY1 0x0000
59 #define ADAU1701_SEROCTL_MSB_DEALY0 0x0004
60 #define ADAU1701_SEROCTL_MSB_DEALY8 0x0008
61 #define ADAU1701_SEROCTL_MSB_DEALY12 0x000c
62 #define ADAU1701_SEROCTL_MSB_DEALY16 0x0010
63 #define ADAU1701_SEROCTL_MSB_DEALY_MASK 0x001c
65 #define ADAU1701_SEROCTL_WORD_LEN_24 0x0000
66 #define ADAU1701_SEROCTL_WORD_LEN_20 0x0001
67 #define ADAU1701_SEROCTL_WORD_LEN_16 0x0010
68 #define ADAU1701_SEROCTL_WORD_LEN_MASK 0x0003
70 #define ADAU1701_AUXNPOW_VBPD 0x40
71 #define ADAU1701_AUXNPOW_VRPD 0x20
73 #define ADAU1701_SERICTL_I2S 0
74 #define ADAU1701_SERICTL_LEFTJ 1
75 #define ADAU1701_SERICTL_TDM 2
76 #define ADAU1701_SERICTL_RIGHTJ_24 3
77 #define ADAU1701_SERICTL_RIGHTJ_20 4
78 #define ADAU1701_SERICTL_RIGHTJ_18 5
79 #define ADAU1701_SERICTL_RIGHTJ_16 6
80 #define ADAU1701_SERICTL_MODE_MASK 7
81 #define ADAU1701_SERICTL_INV_BCLK BIT(3)
82 #define ADAU1701_SERICTL_INV_LRCLK BIT(4)
84 #define ADAU1701_OSCIPOW_OPD 0x04
85 #define ADAU1701_DACSET_DACINIT 1
87 #define ADAU1701_FIRMWARE "adau1701.bin"
113 {
"OUT0",
NULL,
"DAC0" },
114 {
"OUT1",
NULL,
"DAC1" },
115 {
"OUT2",
NULL,
"DAC2" },
116 {
"OUT3",
NULL,
"DAC3" },
118 {
"ADC",
NULL,
"IN0" },
119 {
"ADC",
NULL,
"IN1" },
136 dev_err(codec->
dev,
"Unsupported register address: %d\n", reg);
140 static int adau1701_write(
struct snd_soc_codec *codec,
unsigned int reg,
148 size = adau1701_register_size(codec, reg);
157 for (i = size + 1; i >= 2; --
i) {
171 static unsigned int adau1701_read(
struct snd_soc_codec *codec,
unsigned int reg)
183 static int adau1701_load_firmware(
struct snd_soc_codec *codec)
188 static int adau1701_set_capture_pcm_format(
struct snd_soc_codec *codec,
229 static int adau1701_set_playback_pcm_format(
struct snd_soc_codec *codec,
232 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
284 return adau1701_set_playback_pcm_format(codec, format);
286 return adau1701_set_capture_pcm_format(codec, format);
289 static int adau1701_set_dai_fmt(
struct snd_soc_dai *codec_dai,
293 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
294 unsigned int serictl = 0x00, seroctl = 0x00;
312 invert_lrclk =
false;
318 invert_lrclk =
false;
337 invert_lrclk = !invert_lrclk;
342 invert_lrclk = !invert_lrclk;
362 static int adau1701_set_bias_level(
struct snd_soc_codec *codec,
402 static int adau1701_set_sysclk(
struct snd_soc_codec *codec,
int clk_id,
423 #define ADAU1701_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \
424 SNDRV_PCM_RATE_192000)
426 #define ADAU1701_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
427 SNDRV_PCM_FMTBIT_S24_LE)
430 .set_fmt = adau1701_set_dai_fmt,
431 .hw_params = adau1701_hw_params,
432 .digital_mute = adau1701_digital_mute,
438 .stream_name =
"Playback",
445 .stream_name =
"Capture",
451 .ops = &adau1701_dai_ops,
452 .symmetric_rates = 1,
461 ret = adau1701_load_firmware(codec);
472 .probe = adau1701_probe,
473 .set_bias_level = adau1701_set_bias_level,
474 .idle_bias_off =
true,
477 .reg_word_size =
sizeof(
u16),
481 .dapm_widgets = adau1701_dapm_widgets,
482 .num_dapm_widgets =
ARRAY_SIZE(adau1701_dapm_widgets),
483 .dapm_routes = adau1701_dapm_routes,
484 .num_dapm_routes =
ARRAY_SIZE(adau1701_dapm_routes),
486 .write = adau1701_write,
487 .read = adau1701_read,
489 .set_sysclk = adau1701_set_sysclk,
495 struct adau1701 *adau1701;
502 i2c_set_clientdata(client, adau1701);
520 static struct i2c_driver adau1701_i2c_driver = {
525 .probe = adau1701_i2c_probe,
527 .id_table = adau1701_i2c_id,