aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2007-08-13 11:40:54 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 09:58:54 -0400
commit918f3a0e8cf67b5db966516f255eaf24d814fac0 (patch)
treeae4ac300f4ca93346d4b4ca9a22d760c87ab3072 /sound/pci
parent7653d557606c7cae921557a6a0ebb7c510e458eb (diff)
[ALSA] pcm: add snd_pcm_rate_to_rate_bit() helper
Add a snd_pcm_rate_to_rate_bit() function to factor out common code used by several drivers. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/bt87x.c21
-rw-r--r--sound/pci/rme32.c21
-rw-r--r--sound/pci/rme96.c22
3 files changed, 9 insertions, 55 deletions
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index f0e12985dc29..85d50b64d2ba 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -340,28 +340,9 @@ static struct snd_pcm_hardware snd_bt87x_analog_hw = {
340 340
341static int snd_bt87x_set_digital_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime) 341static int snd_bt87x_set_digital_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime)
342{ 342{
343 static struct {
344 int rate;
345 unsigned int bit;
346 } ratebits[] = {
347 {8000, SNDRV_PCM_RATE_8000},
348 {11025, SNDRV_PCM_RATE_11025},
349 {16000, SNDRV_PCM_RATE_16000},
350 {22050, SNDRV_PCM_RATE_22050},
351 {32000, SNDRV_PCM_RATE_32000},
352 {44100, SNDRV_PCM_RATE_44100},
353 {48000, SNDRV_PCM_RATE_48000}
354 };
355 int i;
356
357 chip->reg_control |= CTL_DA_IOM_DA; 343 chip->reg_control |= CTL_DA_IOM_DA;
358 runtime->hw = snd_bt87x_digital_hw; 344 runtime->hw = snd_bt87x_digital_hw;
359 runtime->hw.rates = SNDRV_PCM_RATE_KNOT; 345 runtime->hw.rates = snd_pcm_rate_to_rate_bit(chip->dig_rate);
360 for (i = 0; i < ARRAY_SIZE(ratebits); ++i)
361 if (chip->dig_rate == ratebits[i].rate) {
362 runtime->hw.rates = ratebits[i].bit;
363 break;
364 }
365 runtime->hw.rate_min = chip->dig_rate; 346 runtime->hw.rate_min = chip->dig_rate;
366 runtime->hw.rate_max = chip->dig_rate; 347 runtime->hw.rate_max = chip->dig_rate;
367 return 0; 348 return 0;
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index ee0189b756d1..1475912588e9 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -258,19 +258,6 @@ static inline unsigned int snd_rme32_pcm_byteptr(struct rme32 * rme32)
258 & RME32_RCR_AUDIO_ADDR_MASK); 258 & RME32_RCR_AUDIO_ADDR_MASK);
259} 259}
260 260
261static int snd_rme32_ratecode(int rate)
262{
263 switch (rate) {
264 case 32000: return SNDRV_PCM_RATE_32000;
265 case 44100: return SNDRV_PCM_RATE_44100;
266 case 48000: return SNDRV_PCM_RATE_48000;
267 case 64000: return SNDRV_PCM_RATE_64000;
268 case 88200: return SNDRV_PCM_RATE_88200;
269 case 96000: return SNDRV_PCM_RATE_96000;
270 }
271 return 0;
272}
273
274/* silence callback for halfduplex mode */ 261/* silence callback for halfduplex mode */
275static int snd_rme32_playback_silence(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ 262static int snd_rme32_playback_silence(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */
276 snd_pcm_uframes_t pos, 263 snd_pcm_uframes_t pos,
@@ -887,7 +874,7 @@ static int snd_rme32_playback_spdif_open(struct snd_pcm_substream *substream)
887 if ((rme32->rcreg & RME32_RCR_KMODE) && 874 if ((rme32->rcreg & RME32_RCR_KMODE) &&
888 (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) { 875 (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) {
889 /* AutoSync */ 876 /* AutoSync */
890 runtime->hw.rates = snd_rme32_ratecode(rate); 877 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
891 runtime->hw.rate_min = rate; 878 runtime->hw.rate_min = rate;
892 runtime->hw.rate_max = rate; 879 runtime->hw.rate_max = rate;
893 } 880 }
@@ -929,7 +916,7 @@ static int snd_rme32_capture_spdif_open(struct snd_pcm_substream *substream)
929 if (isadat) { 916 if (isadat) {
930 return -EIO; 917 return -EIO;
931 } 918 }
932 runtime->hw.rates = snd_rme32_ratecode(rate); 919 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
933 runtime->hw.rate_min = rate; 920 runtime->hw.rate_min = rate;
934 runtime->hw.rate_max = rate; 921 runtime->hw.rate_max = rate;
935 } 922 }
@@ -965,7 +952,7 @@ snd_rme32_playback_adat_open(struct snd_pcm_substream *substream)
965 if ((rme32->rcreg & RME32_RCR_KMODE) && 952 if ((rme32->rcreg & RME32_RCR_KMODE) &&
966 (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) { 953 (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) {
967 /* AutoSync */ 954 /* AutoSync */
968 runtime->hw.rates = snd_rme32_ratecode(rate); 955 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
969 runtime->hw.rate_min = rate; 956 runtime->hw.rate_min = rate;
970 runtime->hw.rate_max = rate; 957 runtime->hw.rate_max = rate;
971 } 958 }
@@ -989,7 +976,7 @@ snd_rme32_capture_adat_open(struct snd_pcm_substream *substream)
989 if (!isadat) { 976 if (!isadat) {
990 return -EIO; 977 return -EIO;
991 } 978 }
992 runtime->hw.rates = snd_rme32_ratecode(rate); 979 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
993 runtime->hw.rate_min = rate; 980 runtime->hw.rate_min = rate;
994 runtime->hw.rate_max = rate; 981 runtime->hw.rate_max = rate;
995 } 982 }
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index ba4a34bae48f..0b3c532c4014 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -301,20 +301,6 @@ snd_rme96_capture_ptr(struct rme96 *rme96)
301} 301}
302 302
303static int 303static int
304snd_rme96_ratecode(int rate)
305{
306 switch (rate) {
307 case 32000: return SNDRV_PCM_RATE_32000;
308 case 44100: return SNDRV_PCM_RATE_44100;
309 case 48000: return SNDRV_PCM_RATE_48000;
310 case 64000: return SNDRV_PCM_RATE_64000;
311 case 88200: return SNDRV_PCM_RATE_88200;
312 case 96000: return SNDRV_PCM_RATE_96000;
313 }
314 return 0;
315}
316
317static int
318snd_rme96_playback_silence(struct snd_pcm_substream *substream, 304snd_rme96_playback_silence(struct snd_pcm_substream *substream,
319 int channel, /* not used (interleaved data) */ 305 int channel, /* not used (interleaved data) */
320 snd_pcm_uframes_t pos, 306 snd_pcm_uframes_t pos,
@@ -1192,7 +1178,7 @@ snd_rme96_playback_spdif_open(struct snd_pcm_substream *substream)
1192 (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0) 1178 (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
1193 { 1179 {
1194 /* slave clock */ 1180 /* slave clock */
1195 runtime->hw.rates = snd_rme96_ratecode(rate); 1181 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
1196 runtime->hw.rate_min = rate; 1182 runtime->hw.rate_min = rate;
1197 runtime->hw.rate_max = rate; 1183 runtime->hw.rate_max = rate;
1198 } 1184 }
@@ -1219,7 +1205,7 @@ snd_rme96_capture_spdif_open(struct snd_pcm_substream *substream)
1219 if (isadat) { 1205 if (isadat) {
1220 return -EIO; 1206 return -EIO;
1221 } 1207 }
1222 runtime->hw.rates = snd_rme96_ratecode(rate); 1208 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
1223 runtime->hw.rate_min = rate; 1209 runtime->hw.rate_min = rate;
1224 runtime->hw.rate_max = rate; 1210 runtime->hw.rate_max = rate;
1225 } 1211 }
@@ -1259,7 +1245,7 @@ snd_rme96_playback_adat_open(struct snd_pcm_substream *substream)
1259 (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0) 1245 (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
1260 { 1246 {
1261 /* slave clock */ 1247 /* slave clock */
1262 runtime->hw.rates = snd_rme96_ratecode(rate); 1248 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
1263 runtime->hw.rate_min = rate; 1249 runtime->hw.rate_min = rate;
1264 runtime->hw.rate_max = rate; 1250 runtime->hw.rate_max = rate;
1265 } 1251 }
@@ -1284,7 +1270,7 @@ snd_rme96_capture_adat_open(struct snd_pcm_substream *substream)
1284 if (!isadat) { 1270 if (!isadat) {
1285 return -EIO; 1271 return -EIO;
1286 } 1272 }
1287 runtime->hw.rates = snd_rme96_ratecode(rate); 1273 runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
1288 runtime->hw.rate_min = rate; 1274 runtime->hw.rate_min = rate;
1289 runtime->hw.rate_max = rate; 1275 runtime->hw.rate_max = rate;
1290 } 1276 }