diff options
Diffstat (limited to 'sound/soc/codecs/cs4270.c')
-rw-r--r-- | sound/soc/codecs/cs4270.c | 262 |
1 files changed, 128 insertions, 134 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index dab22cc97ead..bf2ab72d49bf 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <sound/driver.h> | ||
32 | #include <sound/core.h> | 31 | #include <sound/core.h> |
33 | #include <sound/soc.h> | 32 | #include <sound/soc.h> |
34 | #include <sound/initval.h> | 33 | #include <sound/initval.h> |
@@ -48,12 +47,130 @@ struct cs4270_private { | |||
48 | unsigned int mode; /* The mode (I2S or left-justified) */ | 47 | unsigned int mode; /* The mode (I2S or left-justified) */ |
49 | }; | 48 | }; |
50 | 49 | ||
51 | /* The number of MCLK/LRCK ratios supported by the CS4270 */ | 50 | /* |
52 | #define NUM_MCLK_RATIOS 9 | 51 | * The codec isn't really big-endian or little-endian, since the I2S |
52 | * interface requires data to be sent serially with the MSbit first. | ||
53 | * However, to support BE and LE I2S devices, we specify both here. That | ||
54 | * way, ALSA will always match the bit patterns. | ||
55 | */ | ||
56 | #define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ | ||
57 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ | ||
58 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \ | ||
59 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ | ||
60 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ | ||
61 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) | ||
62 | |||
63 | #ifdef USE_I2C | ||
64 | |||
65 | /* CS4270 registers addresses */ | ||
66 | #define CS4270_CHIPID 0x01 /* Chip ID */ | ||
67 | #define CS4270_PWRCTL 0x02 /* Power Control */ | ||
68 | #define CS4270_MODE 0x03 /* Mode Control */ | ||
69 | #define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */ | ||
70 | #define CS4270_TRANS 0x05 /* Transition Control */ | ||
71 | #define CS4270_MUTE 0x06 /* Mute Control */ | ||
72 | #define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */ | ||
73 | #define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */ | ||
74 | |||
75 | #define CS4270_FIRSTREG 0x01 | ||
76 | #define CS4270_LASTREG 0x08 | ||
77 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) | ||
53 | 78 | ||
54 | /* The actual MCLK/LRCK ratios, in increasing numerical order */ | 79 | /* Bit masks for the CS4270 registers */ |
55 | static unsigned int mclk_ratios[NUM_MCLK_RATIOS] = | 80 | #define CS4270_CHIPID_ID 0xF0 |
56 | {64, 96, 128, 192, 256, 384, 512, 768, 1024}; | 81 | #define CS4270_CHIPID_REV 0x0F |
82 | #define CS4270_PWRCTL_FREEZE 0x80 | ||
83 | #define CS4270_PWRCTL_PDN_ADC 0x20 | ||
84 | #define CS4270_PWRCTL_PDN_DAC 0x02 | ||
85 | #define CS4270_PWRCTL_PDN 0x01 | ||
86 | #define CS4270_MODE_SPEED_MASK 0x30 | ||
87 | #define CS4270_MODE_1X 0x00 | ||
88 | #define CS4270_MODE_2X 0x10 | ||
89 | #define CS4270_MODE_4X 0x20 | ||
90 | #define CS4270_MODE_SLAVE 0x30 | ||
91 | #define CS4270_MODE_DIV_MASK 0x0E | ||
92 | #define CS4270_MODE_DIV1 0x00 | ||
93 | #define CS4270_MODE_DIV15 0x02 | ||
94 | #define CS4270_MODE_DIV2 0x04 | ||
95 | #define CS4270_MODE_DIV3 0x06 | ||
96 | #define CS4270_MODE_DIV4 0x08 | ||
97 | #define CS4270_MODE_POPGUARD 0x01 | ||
98 | #define CS4270_FORMAT_FREEZE_A 0x80 | ||
99 | #define CS4270_FORMAT_FREEZE_B 0x40 | ||
100 | #define CS4270_FORMAT_LOOPBACK 0x20 | ||
101 | #define CS4270_FORMAT_DAC_MASK 0x18 | ||
102 | #define CS4270_FORMAT_DAC_LJ 0x00 | ||
103 | #define CS4270_FORMAT_DAC_I2S 0x08 | ||
104 | #define CS4270_FORMAT_DAC_RJ16 0x18 | ||
105 | #define CS4270_FORMAT_DAC_RJ24 0x10 | ||
106 | #define CS4270_FORMAT_ADC_MASK 0x01 | ||
107 | #define CS4270_FORMAT_ADC_LJ 0x00 | ||
108 | #define CS4270_FORMAT_ADC_I2S 0x01 | ||
109 | #define CS4270_TRANS_ONE_VOL 0x80 | ||
110 | #define CS4270_TRANS_SOFT 0x40 | ||
111 | #define CS4270_TRANS_ZERO 0x20 | ||
112 | #define CS4270_TRANS_INV_ADC_A 0x08 | ||
113 | #define CS4270_TRANS_INV_ADC_B 0x10 | ||
114 | #define CS4270_TRANS_INV_DAC_A 0x02 | ||
115 | #define CS4270_TRANS_INV_DAC_B 0x04 | ||
116 | #define CS4270_TRANS_DEEMPH 0x01 | ||
117 | #define CS4270_MUTE_AUTO 0x20 | ||
118 | #define CS4270_MUTE_ADC_A 0x08 | ||
119 | #define CS4270_MUTE_ADC_B 0x10 | ||
120 | #define CS4270_MUTE_POLARITY 0x04 | ||
121 | #define CS4270_MUTE_DAC_A 0x01 | ||
122 | #define CS4270_MUTE_DAC_B 0x02 | ||
123 | |||
124 | /* | ||
125 | * Clock Ratio Selection for Master Mode with I2C enabled | ||
126 | * | ||
127 | * The data for this chart is taken from Table 5 of the CS4270 reference | ||
128 | * manual. | ||
129 | * | ||
130 | * This table is used to determine how to program the Mode Control register. | ||
131 | * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling | ||
132 | * rates the CS4270 currently supports. | ||
133 | * | ||
134 | * Each element in this array corresponds to the ratios in mclk_ratios[]. | ||
135 | * These two arrays need to be in sync. | ||
136 | * | ||
137 | * 'speed_mode' is the corresponding bit pattern to be written to the | ||
138 | * MODE bits of the Mode Control Register | ||
139 | * | ||
140 | * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of | ||
141 | * the Mode Control Register. | ||
142 | * | ||
143 | * In situations where a single ratio is represented by multiple speed | ||
144 | * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick | ||
145 | * double-speed instead of quad-speed. However, the CS4270 errata states | ||
146 | * that Divide-By-1.5 can cause failures, so we avoid that mode where | ||
147 | * possible. | ||
148 | * | ||
149 | * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not | ||
150 | * work if VD = 3.3V. If this effects you, select the | ||
151 | * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will | ||
152 | * never select any sample rates that require divide-by-1.5. | ||
153 | */ | ||
154 | static struct { | ||
155 | unsigned int ratio; | ||
156 | u8 speed_mode; | ||
157 | u8 mclk; | ||
158 | } cs4270_mode_ratios[] = { | ||
159 | {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, | ||
160 | #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA | ||
161 | {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, | ||
162 | #endif | ||
163 | {128, CS4270_MODE_2X, CS4270_MODE_DIV1}, | ||
164 | {192, CS4270_MODE_4X, CS4270_MODE_DIV3}, | ||
165 | {256, CS4270_MODE_1X, CS4270_MODE_DIV1}, | ||
166 | {384, CS4270_MODE_2X, CS4270_MODE_DIV3}, | ||
167 | {512, CS4270_MODE_1X, CS4270_MODE_DIV2}, | ||
168 | {768, CS4270_MODE_1X, CS4270_MODE_DIV3}, | ||
169 | {1024, CS4270_MODE_1X, CS4270_MODE_DIV4} | ||
170 | }; | ||
171 | |||
172 | /* The number of MCLK/LRCK ratios supported by the CS4270 */ | ||
173 | #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) | ||
57 | 174 | ||
58 | /* | 175 | /* |
59 | * Determine the CS4270 samples rates. | 176 | * Determine the CS4270 samples rates. |
@@ -97,7 +214,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai, | |||
97 | cs4270->mclk = freq; | 214 | cs4270->mclk = freq; |
98 | 215 | ||
99 | for (i = 0; i < NUM_MCLK_RATIOS; i++) { | 216 | for (i = 0; i < NUM_MCLK_RATIOS; i++) { |
100 | unsigned int rate = freq / mclk_ratios[i]; | 217 | unsigned int rate = freq / cs4270_mode_ratios[i].ratio; |
101 | rates |= snd_pcm_rate_to_rate_bit(rate); | 218 | rates |= snd_pcm_rate_to_rate_bit(rate); |
102 | if (rate < rate_min) | 219 | if (rate < rate_min) |
103 | rate_min = rate; | 220 | rate_min = rate; |
@@ -155,80 +272,6 @@ static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, | |||
155 | } | 272 | } |
156 | 273 | ||
157 | /* | 274 | /* |
158 | * The codec isn't really big-endian or little-endian, since the I2S | ||
159 | * interface requires data to be sent serially with the MSbit first. | ||
160 | * However, to support BE and LE I2S devices, we specify both here. That | ||
161 | * way, ALSA will always match the bit patterns. | ||
162 | */ | ||
163 | #define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ | ||
164 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ | ||
165 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \ | ||
166 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ | ||
167 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ | ||
168 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) | ||
169 | |||
170 | #ifdef USE_I2C | ||
171 | |||
172 | /* CS4270 registers addresses */ | ||
173 | #define CS4270_CHIPID 0x01 /* Chip ID */ | ||
174 | #define CS4270_PWRCTL 0x02 /* Power Control */ | ||
175 | #define CS4270_MODE 0x03 /* Mode Control */ | ||
176 | #define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */ | ||
177 | #define CS4270_TRANS 0x05 /* Transition Control */ | ||
178 | #define CS4270_MUTE 0x06 /* Mute Control */ | ||
179 | #define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */ | ||
180 | #define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */ | ||
181 | |||
182 | #define CS4270_FIRSTREG 0x01 | ||
183 | #define CS4270_LASTREG 0x08 | ||
184 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) | ||
185 | |||
186 | /* Bit masks for the CS4270 registers */ | ||
187 | #define CS4270_CHIPID_ID 0xF0 | ||
188 | #define CS4270_CHIPID_REV 0x0F | ||
189 | #define CS4270_PWRCTL_FREEZE 0x80 | ||
190 | #define CS4270_PWRCTL_PDN_ADC 0x20 | ||
191 | #define CS4270_PWRCTL_PDN_DAC 0x02 | ||
192 | #define CS4270_PWRCTL_PDN 0x01 | ||
193 | #define CS4270_MODE_SPEED_MASK 0x30 | ||
194 | #define CS4270_MODE_1X 0x00 | ||
195 | #define CS4270_MODE_2X 0x10 | ||
196 | #define CS4270_MODE_4X 0x20 | ||
197 | #define CS4270_MODE_SLAVE 0x30 | ||
198 | #define CS4270_MODE_DIV_MASK 0x0E | ||
199 | #define CS4270_MODE_DIV1 0x00 | ||
200 | #define CS4270_MODE_DIV15 0x02 | ||
201 | #define CS4270_MODE_DIV2 0x04 | ||
202 | #define CS4270_MODE_DIV3 0x06 | ||
203 | #define CS4270_MODE_DIV4 0x08 | ||
204 | #define CS4270_MODE_POPGUARD 0x01 | ||
205 | #define CS4270_FORMAT_FREEZE_A 0x80 | ||
206 | #define CS4270_FORMAT_FREEZE_B 0x40 | ||
207 | #define CS4270_FORMAT_LOOPBACK 0x20 | ||
208 | #define CS4270_FORMAT_DAC_MASK 0x18 | ||
209 | #define CS4270_FORMAT_DAC_LJ 0x00 | ||
210 | #define CS4270_FORMAT_DAC_I2S 0x08 | ||
211 | #define CS4270_FORMAT_DAC_RJ16 0x18 | ||
212 | #define CS4270_FORMAT_DAC_RJ24 0x10 | ||
213 | #define CS4270_FORMAT_ADC_MASK 0x01 | ||
214 | #define CS4270_FORMAT_ADC_LJ 0x00 | ||
215 | #define CS4270_FORMAT_ADC_I2S 0x01 | ||
216 | #define CS4270_TRANS_ONE_VOL 0x80 | ||
217 | #define CS4270_TRANS_SOFT 0x40 | ||
218 | #define CS4270_TRANS_ZERO 0x20 | ||
219 | #define CS4270_TRANS_INV_ADC_A 0x08 | ||
220 | #define CS4270_TRANS_INV_ADC_B 0x10 | ||
221 | #define CS4270_TRANS_INV_DAC_A 0x02 | ||
222 | #define CS4270_TRANS_INV_DAC_B 0x04 | ||
223 | #define CS4270_TRANS_DEEMPH 0x01 | ||
224 | #define CS4270_MUTE_AUTO 0x20 | ||
225 | #define CS4270_MUTE_ADC_A 0x08 | ||
226 | #define CS4270_MUTE_ADC_B 0x10 | ||
227 | #define CS4270_MUTE_POLARITY 0x04 | ||
228 | #define CS4270_MUTE_DAC_A 0x01 | ||
229 | #define CS4270_MUTE_DAC_B 0x02 | ||
230 | |||
231 | /* | ||
232 | * A list of addresses on which this CS4270 could use. I2C addresses are | 275 | * A list of addresses on which this CS4270 could use. I2C addresses are |
233 | * 7 bits. For the CS4270, the upper four bits are always 1001, and the | 276 | * 7 bits. For the CS4270, the upper four bits are always 1001, and the |
234 | * lower three bits are determined via the AD2, AD1, and AD0 pins | 277 | * lower three bits are determined via the AD2, AD1, and AD0 pins |
@@ -315,53 +358,6 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, | |||
315 | } | 358 | } |
316 | 359 | ||
317 | /* | 360 | /* |
318 | * Clock Ratio Selection for Master Mode with I2C enabled | ||
319 | * | ||
320 | * The data for this chart is taken from Table 5 of the CS4270 reference | ||
321 | * manual. | ||
322 | * | ||
323 | * This table is used to determine how to program the Mode Control register. | ||
324 | * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling | ||
325 | * rates the CS4270 currently supports. | ||
326 | * | ||
327 | * Each element in this array corresponds to the ratios in mclk_ratios[]. | ||
328 | * These two arrays need to be in sync. | ||
329 | * | ||
330 | * 'speed_mode' is the corresponding bit pattern to be written to the | ||
331 | * MODE bits of the Mode Control Register | ||
332 | * | ||
333 | * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of | ||
334 | * the Mode Control Register. | ||
335 | * | ||
336 | * In situations where a single ratio is represented by multiple speed | ||
337 | * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick | ||
338 | * double-speed instead of quad-speed. However, the CS4270 errata states | ||
339 | * that Divide-By-1.5 can cause failures, so we avoid that mode where | ||
340 | * possible. | ||
341 | * | ||
342 | * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not | ||
343 | * work if VD = 3.3V. If this effects you, select the | ||
344 | * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will | ||
345 | * never select any sample rates that require divide-by-1.5. | ||
346 | */ | ||
347 | static struct { | ||
348 | u8 speed_mode; | ||
349 | u8 mclk; | ||
350 | } cs4270_mode_ratios[NUM_MCLK_RATIOS] = { | ||
351 | {CS4270_MODE_4X, CS4270_MODE_DIV1}, /* 64 */ | ||
352 | #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA | ||
353 | {CS4270_MODE_4X, CS4270_MODE_DIV15}, /* 96 */ | ||
354 | #endif | ||
355 | {CS4270_MODE_2X, CS4270_MODE_DIV1}, /* 128 */ | ||
356 | {CS4270_MODE_4X, CS4270_MODE_DIV3}, /* 192 */ | ||
357 | {CS4270_MODE_1X, CS4270_MODE_DIV1}, /* 256 */ | ||
358 | {CS4270_MODE_2X, CS4270_MODE_DIV3}, /* 384 */ | ||
359 | {CS4270_MODE_1X, CS4270_MODE_DIV2}, /* 512 */ | ||
360 | {CS4270_MODE_1X, CS4270_MODE_DIV3}, /* 768 */ | ||
361 | {CS4270_MODE_1X, CS4270_MODE_DIV4} /* 1024 */ | ||
362 | }; | ||
363 | |||
364 | /* | ||
365 | * Program the CS4270 with the given hardware parameters. | 361 | * Program the CS4270 with the given hardware parameters. |
366 | * | 362 | * |
367 | * The .dai_ops functions are used to provide board-specific data, like | 363 | * The .dai_ops functions are used to provide board-specific data, like |
@@ -388,7 +384,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
388 | ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */ | 384 | ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */ |
389 | 385 | ||
390 | for (i = 0; i < NUM_MCLK_RATIOS; i++) { | 386 | for (i = 0; i < NUM_MCLK_RATIOS; i++) { |
391 | if (mclk_ratios[i] == ratio) | 387 | if (cs4270_mode_ratios[i].ratio == ratio) |
392 | break; | 388 | break; |
393 | } | 389 | } |
394 | 390 | ||
@@ -669,7 +665,7 @@ error: | |||
669 | return ret; | 665 | return ret; |
670 | } | 666 | } |
671 | 667 | ||
672 | #endif | 668 | #endif /* USE_I2C*/ |
673 | 669 | ||
674 | struct snd_soc_codec_dai cs4270_dai = { | 670 | struct snd_soc_codec_dai cs4270_dai = { |
675 | .name = "CS4270", | 671 | .name = "CS4270", |
@@ -687,10 +683,6 @@ struct snd_soc_codec_dai cs4270_dai = { | |||
687 | .rates = 0, | 683 | .rates = 0, |
688 | .formats = CS4270_FORMATS, | 684 | .formats = CS4270_FORMATS, |
689 | }, | 685 | }, |
690 | .dai_ops = { | ||
691 | .set_sysclk = cs4270_set_dai_sysclk, | ||
692 | .set_fmt = cs4270_set_dai_fmt, | ||
693 | } | ||
694 | }; | 686 | }; |
695 | EXPORT_SYMBOL_GPL(cs4270_dai); | 687 | EXPORT_SYMBOL_GPL(cs4270_dai); |
696 | 688 | ||
@@ -752,6 +744,8 @@ static int cs4270_probe(struct platform_device *pdev) | |||
752 | if (codec->control_data) { | 744 | if (codec->control_data) { |
753 | /* Initialize codec ops */ | 745 | /* Initialize codec ops */ |
754 | cs4270_dai.ops.hw_params = cs4270_hw_params; | 746 | cs4270_dai.ops.hw_params = cs4270_hw_params; |
747 | cs4270_dai.dai_ops.set_sysclk = cs4270_set_dai_sysclk; | ||
748 | cs4270_dai.dai_ops.set_fmt = cs4270_set_dai_fmt; | ||
755 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE | 749 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE |
756 | cs4270_dai.dai_ops.digital_mute = cs4270_mute; | 750 | cs4270_dai.dai_ops.digital_mute = cs4270_mute; |
757 | #endif | 751 | #endif |