aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/ad1848
diff options
context:
space:
mode:
authorKrzysztof Helt <krzysztof.h1@wp.pl>2007-09-06 09:03:22 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 10:49:09 -0400
commit8e6a2c2ec9e7c99128425e6b73bea8437efd3a93 (patch)
tree8baf0a743f66f83a9b03436f172d5cf89bce01d0 /sound/isa/ad1848
parentef285fe6ef3620fbac5d7fc4c0560e276adb0fc2 (diff)
[ALSA] ad1848_lib: replace common delay loop by function
This patch replaces a common delay loop by a function. It also uses ARRAY_SIZE macro for the rates table. Acked-by: Rene Herman <rene.herman@gmail.com> Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/isa/ad1848')
-rw-r--r--sound/isa/ad1848/ad1848_lib.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/sound/isa/ad1848/ad1848_lib.c b/sound/isa/ad1848/ad1848_lib.c
index 1bc2e3fd5721..f01e564b1238 100644
--- a/sound/isa/ad1848/ad1848_lib.c
+++ b/sound/isa/ad1848/ad1848_lib.c
@@ -70,7 +70,7 @@ static unsigned int rates[14] = {
70}; 70};
71 71
72static struct snd_pcm_hw_constraint_list hw_constraints_rates = { 72static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
73 .count = 14, 73 .count = ARRAY_SIZE(rates),
74 .list = rates, 74 .list = rates,
75 .mask = 0, 75 .mask = 0,
76}; 76};
@@ -99,24 +99,32 @@ static unsigned char snd_ad1848_original_image[16] =
99 * Basic I/O functions 99 * Basic I/O functions
100 */ 100 */
101 101
102void snd_ad1848_out(struct snd_ad1848 *chip, 102static void snd_ad1848_wait(struct snd_ad1848 *chip)
103 unsigned char reg,
104 unsigned char value)
105{ 103{
106 int timeout; 104 int timeout;
107 105
108 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--) 106 for (timeout = 250; timeout > 0; timeout--) {
107 if ((inb(AD1848P(chip, REGSEL)) & AD1848_INIT) == 0)
108 break;
109 udelay(100); 109 udelay(100);
110 }
111}
112
113void snd_ad1848_out(struct snd_ad1848 *chip,
114 unsigned char reg,
115 unsigned char value)
116{
117 snd_ad1848_wait(chip);
110#ifdef CONFIG_SND_DEBUG 118#ifdef CONFIG_SND_DEBUG
111 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 119 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
112 snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); 120 snd_printk(KERN_WARNING "auto calibration time out - "
121 "reg = 0x%x, value = 0x%x\n", reg, value);
113#endif 122#endif
114 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); 123 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
115 outb(chip->image[reg] = value, AD1848P(chip, REG)); 124 outb(chip->image[reg] = value, AD1848P(chip, REG));
116 mb(); 125 mb();
117#if 0 126 snd_printdd("codec out - reg 0x%x = 0x%x\n",
118 printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value); 127 chip->mce_bit | reg, value);
119#endif
120} 128}
121 129
122EXPORT_SYMBOL(snd_ad1848_out); 130EXPORT_SYMBOL(snd_ad1848_out);
@@ -124,10 +132,7 @@ EXPORT_SYMBOL(snd_ad1848_out);
124static void snd_ad1848_dout(struct snd_ad1848 *chip, 132static void snd_ad1848_dout(struct snd_ad1848 *chip,
125 unsigned char reg, unsigned char value) 133 unsigned char reg, unsigned char value)
126{ 134{
127 int timeout; 135 snd_ad1848_wait(chip);
128
129 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
130 udelay(100);
131 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); 136 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
132 outb(value, AD1848P(chip, REG)); 137 outb(value, AD1848P(chip, REG));
133 mb(); 138 mb();
@@ -135,13 +140,11 @@ static void snd_ad1848_dout(struct snd_ad1848 *chip,
135 140
136static unsigned char snd_ad1848_in(struct snd_ad1848 *chip, unsigned char reg) 141static unsigned char snd_ad1848_in(struct snd_ad1848 *chip, unsigned char reg)
137{ 142{
138 int timeout; 143 snd_ad1848_wait(chip);
139
140 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
141 udelay(100);
142#ifdef CONFIG_SND_DEBUG 144#ifdef CONFIG_SND_DEBUG
143 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 145 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
144 snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x\n", reg); 146 snd_printk(KERN_WARNING "auto calibration time out - "
147 "reg = 0x%x\n", reg);
145#endif 148#endif
146 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); 149 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
147 mb(); 150 mb();
@@ -183,8 +186,7 @@ static void snd_ad1848_mce_up(struct snd_ad1848 *chip)
183 unsigned long flags; 186 unsigned long flags;
184 int timeout; 187 int timeout;
185 188
186 for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--) 189 snd_ad1848_wait(chip);
187 udelay(100);
188#ifdef CONFIG_SND_DEBUG 190#ifdef CONFIG_SND_DEBUG
189 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 191 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
190 snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n"); 192 snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n");
@@ -319,11 +321,11 @@ static unsigned char snd_ad1848_get_rate(unsigned int rate)
319{ 321{
320 int i; 322 int i;
321 323
322 for (i = 0; i < 14; i++) 324 for (i = 0; i < ARRAY_SIZE(rates); i++)
323 if (rate == rates[i]) 325 if (rate == rates[i])
324 return freq_bits[i]; 326 return freq_bits[i];
325 snd_BUG(); 327 snd_BUG();
326 return freq_bits[13]; 328 return freq_bits[ARRAY_SIZE(rates) - 1];
327} 329}
328 330
329static int snd_ad1848_ioctl(struct snd_pcm_substream *substream, 331static int snd_ad1848_ioctl(struct snd_pcm_substream *substream,