16 #include <linux/i2c.h>
18 #include <linux/module.h>
22 #include <linux/slab.h>
33 #define STA529_FFXCFG0 0x00
34 #define STA529_FFXCFG1 0x01
35 #define STA529_MVOL 0x02
36 #define STA529_LVOL 0x03
37 #define STA529_RVOL 0x04
38 #define STA529_TTF0 0x05
39 #define STA529_TTF1 0x06
40 #define STA529_TTP0 0x07
41 #define STA529_TTP1 0x08
42 #define STA529_S2PCFG0 0x0A
43 #define STA529_S2PCFG1 0x0B
44 #define STA529_P2SCFG0 0x0C
45 #define STA529_P2SCFG1 0x0D
46 #define STA529_PLLCFG0 0x14
47 #define STA529_PLLCFG1 0x15
48 #define STA529_PLLCFG2 0x16
49 #define STA529_PLLCFG3 0x17
50 #define STA529_PLLPFE 0x18
51 #define STA529_PLLST 0x19
52 #define STA529_ADCCFG 0x1E
53 #define STA529_CKOCFG 0x1F
54 #define STA529_MISC 0x20
55 #define STA529_PADST0 0x21
56 #define STA529_PADST1 0x22
57 #define STA529_FFXST 0x23
58 #define STA529_PWMIN1 0x2D
59 #define STA529_PWMIN2 0x2E
60 #define STA529_POWST 0x32
62 #define STA529_MAX_REGISTER 0x32
64 #define STA529_RATES (SNDRV_PCM_RATE_8000 | \
65 SNDRV_PCM_RATE_11025 | \
66 SNDRV_PCM_RATE_16000 | \
67 SNDRV_PCM_RATE_22050 | \
68 SNDRV_PCM_RATE_32000 | \
69 SNDRV_PCM_RATE_44100 | \
72 #define STA529_FORMAT (SNDRV_PCM_FMTBIT_S16_LE | \
73 SNDRV_PCM_FMTBIT_S24_LE | \
74 SNDRV_PCM_FMTBIT_S32_LE)
75 #define S2PC_VALUE 0x98
76 #define CLOCK_OUT 0x60
77 #define LEFT_J_DATA_FORMAT 0x10
78 #define I2S_DATA_FORMAT 0x12
79 #define RIGHT_J_DATA_FORMAT 0x14
80 #define CODEC_MUTE_VAL 0x80
82 #define POWER_CNTLMSAK 0x40
83 #define POWER_STDBY 0x40
87 #define FFX_CLK_ENB 0x01
88 #define FFX_CLK_DIS 0x00
89 #define FFX_CLK_MSK 0x01
90 #define PLAY_FREQ_RANGE_MSK 0x70
91 #define CAP_FREQ_RANGE_MSK 0x0C
92 #define PDATA_LEN_MSK 0xC0
93 #define BCLK_TO_FS_MSK 0x30
94 #define AUDIO_MUTE_MSK 0x80
96 static const struct reg_default sta529_reg_defaults[] = {
115 static bool sta529_readable(
struct device *
dev,
unsigned int reg)
138 static const char *pwm_mode_text[] = {
"Binary",
"Headphone",
"Ternary",
147 127, 0, out_gain_tlv),
156 struct sta529 *
sta529 = snd_soc_codec_get_drvdata(codec);
197 int pdata, play_freq_val, record_freq_val;
198 int bclk_to_fs_ratio;
203 bclk_to_fs_ratio = 0;
207 bclk_to_fs_ratio = 1;
211 bclk_to_fs_ratio = 2;
245 bclk_to_fs_ratio << 4);
252 bclk_to_fs_ratio << 4);
254 record_freq_val << 2);
298 .hw_params = sta529_hw_params,
299 .set_fmt = sta529_set_dai_fmt,
300 .digital_mute = sta529_mute,
304 .name =
"sta529-audio",
306 .stream_name =
"Playback",
313 .stream_name =
"Capture",
319 .ops = &sta529_dai_ops,
324 struct sta529 *sta529 = snd_soc_codec_get_drvdata(codec);
331 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
362 .probe = sta529_probe,
363 .remove = sta529_remove,
364 .set_bias_level = sta529_set_bias_level,
365 .suspend = sta529_suspend,
366 .resume = sta529_resume,
367 .controls = sta529_snd_controls,
368 .num_controls =
ARRAY_SIZE(sta529_snd_controls),
371 static const struct regmap_config sta529_regmap = {
376 .readable_reg = sta529_readable,
379 .reg_defaults = sta529_reg_defaults,
380 .num_reg_defaults =
ARRAY_SIZE(sta529_reg_defaults),
386 struct sta529 *sta529;
393 if (sta529 ==
NULL) {
394 dev_err(&i2c->
dev,
"Can not allocate memory\n");
399 if (IS_ERR(sta529->
regmap)) {
400 ret = PTR_ERR(sta529->
regmap);
401 dev_err(&i2c->
dev,
"Failed to allocate regmap: %d\n", ret);
405 i2c_set_clientdata(i2c, sta529);
408 &sta529_codec_driver, &sta529_dai, 1);
410 dev_err(&i2c->
dev,
"Failed to register CODEC: %d\n", ret);
428 static struct i2c_driver sta529_i2c_driver = {
433 .probe = sta529_i2c_probe,
435 .id_table = sta529_i2c_id,