[ALSA] sound/pci: fix-up sleeping paths

ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:

1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>

authored by Nishanth Aravamudan and committed by Jaroslav Kysela ef21ca24 072c0119

+42 -68
+9 -8
sound/pci/ac97/ac97_codec.c
··· 2227 void snd_ac97_resume(ac97_t *ac97) 2228 { 2229 int i; 2230 2231 if (ac97->bus->ops->reset) { 2232 ac97->bus->ops->reset(ac97); ··· 2245 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]); 2246 if (ac97_is_audio(ac97)) { 2247 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101); 2248 - for (i = HZ/10; i >= 0; i--) { 2249 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2250 break; 2251 set_current_state(TASK_UNINTERRUPTIBLE); 2252 schedule_timeout(1); 2253 - } 2254 /* FIXME: extra delay */ 2255 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2256 - if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000) { 2257 - set_current_state(TASK_UNINTERRUPTIBLE); 2258 - schedule_timeout(HZ/4); 2259 - } 2260 } else { 2261 - for (i = HZ/10; i >= 0; i--) { 2262 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2263 if (val != 0xffff && (val & 1) != 0) 2264 break; 2265 set_current_state(TASK_UNINTERRUPTIBLE); 2266 schedule_timeout(1); 2267 - } 2268 } 2269 __reset_ready: 2270
··· 2227 void snd_ac97_resume(ac97_t *ac97) 2228 { 2229 int i; 2230 + unsigned long end_time; 2231 2232 if (ac97->bus->ops->reset) { 2233 ac97->bus->ops->reset(ac97); ··· 2244 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]); 2245 if (ac97_is_audio(ac97)) { 2246 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101); 2247 + end_time = jiffies + msecs_to_jiffies(100); 2248 + do { 2249 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2250 break; 2251 set_current_state(TASK_UNINTERRUPTIBLE); 2252 schedule_timeout(1); 2253 + } while (time_after_eq(end_time, jiffies)); 2254 /* FIXME: extra delay */ 2255 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2256 + if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000) 2257 + msleep(250); 2258 } else { 2259 + end_time = jiffies + msecs_to_jiffies(100); 2260 + do { 2261 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2262 if (val != 0xffff && (val & 1) != 0) 2263 break; 2264 set_current_state(TASK_UNINTERRUPTIBLE); 2265 schedule_timeout(1); 2266 + } while (time_after_eq(end_time, jiffies)); 2267 } 2268 __reset_ready: 2269
+2 -2
sound/pci/ali5451/ali5451.c
··· 399 unsigned long end_time; 400 unsigned int res; 401 402 - end_time = jiffies + 10 * (HZ >> 2); 403 do { 404 res = snd_ali_5451_peek(codec,port); 405 if (! (res & 0x8000)) ··· 422 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); 423 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 424 425 - end_time = jiffies + 10 * (HZ >> 2); 426 do { 427 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 428 if (dwChk2 != dwChk1)
··· 399 unsigned long end_time; 400 unsigned int res; 401 402 + end_time = jiffies + 10 * msecs_to_jiffies(250); 403 do { 404 res = snd_ali_5451_peek(codec,port); 405 if (! (res & 0x8000)) ··· 422 dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); 423 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 424 425 + end_time = jiffies + 10 * msecs_to_jiffies(250); 426 do { 427 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 428 if (dwChk2 != dwChk1)
+5 -10
sound/pci/cs46xx/cs46xx_lib.c
··· 2400 if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05) 2401 return; 2402 2403 - set_current_state(TASK_UNINTERRUPTIBLE); 2404 - schedule_timeout(HZ/100); 2405 } while (time_after_eq(end_time, jiffies)); 2406 2407 snd_printk("CS46xx secondary codec dont respond!\n"); ··· 2434 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97[codec]); 2435 return err; 2436 } 2437 - set_current_state(TASK_INTERRUPTIBLE); 2438 - schedule_timeout(HZ/100); 2439 } 2440 snd_printdd("snd_cs46xx: codec %d detection timeout\n", codec); 2441 return -ENXIO; ··· 3016 /* 3017 * Wait until the PLL has stabilized. 3018 */ 3019 - set_current_state(TASK_UNINTERRUPTIBLE); 3020 - schedule_timeout(HZ/10); /* 100ms */ 3021 3022 /* 3023 * Turn on clocking of the core so that we can setup the serial ports. ··· 3069 */ 3070 if (snd_cs46xx_peekBA0(chip, BA0_ACSTS) & ACSTS_CRDY) 3071 goto ok1; 3072 - set_current_state(TASK_UNINTERRUPTIBLE); 3073 - schedule_timeout((HZ+99)/100); 3074 } 3075 3076 ··· 3118 */ 3119 if ((snd_cs46xx_peekBA0(chip, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4)) 3120 goto ok2; 3121 - set_current_state(TASK_UNINTERRUPTIBLE); 3122 - schedule_timeout((HZ+99)/100); 3123 } 3124 3125 #ifndef CONFIG_SND_CS46XX_NEW_DSP
··· 2400 if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05) 2401 return; 2402 2403 + msleep(10); 2404 } while (time_after_eq(end_time, jiffies)); 2405 2406 snd_printk("CS46xx secondary codec dont respond!\n"); ··· 2435 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97[codec]); 2436 return err; 2437 } 2438 + msleep(10); 2439 } 2440 snd_printdd("snd_cs46xx: codec %d detection timeout\n", codec); 2441 return -ENXIO; ··· 3018 /* 3019 * Wait until the PLL has stabilized. 3020 */ 3021 + msleep(100); 3022 3023 /* 3024 * Turn on clocking of the core so that we can setup the serial ports. ··· 3072 */ 3073 if (snd_cs46xx_peekBA0(chip, BA0_ACSTS) & ACSTS_CRDY) 3074 goto ok1; 3075 + msleep(10); 3076 } 3077 3078 ··· 3122 */ 3123 if ((snd_cs46xx_peekBA0(chip, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4)) 3124 goto ok2; 3125 + msleep(10); 3126 } 3127 3128 #ifndef CONFIG_SND_CS46XX_NEW_DSP
+1 -11
sound/pci/ens1370.c
··· 2018 if (pci->vendor == es1371_ac97_reset_hack[idx].vid && 2019 pci->device == es1371_ac97_reset_hack[idx].did && 2020 ensoniq->rev == es1371_ac97_reset_hack[idx].rev) { 2021 - unsigned long tmo; 2022 - signed long tmo2; 2023 - 2024 ensoniq->cssr |= ES_1371_ST_AC97_RST; 2025 outl(ensoniq->cssr, ES_REG(ensoniq, STATUS)); 2026 /* need to delay around 20ms(bleech) to give 2027 some CODECs enough time to wakeup */ 2028 - tmo = jiffies + (HZ / 50) + 1; 2029 - while (1) { 2030 - tmo2 = tmo - jiffies; 2031 - if (tmo2 <= 0) 2032 - break; 2033 - set_current_state(TASK_UNINTERRUPTIBLE); 2034 - schedule_timeout(tmo2); 2035 - } 2036 break; 2037 } 2038 /* AC'97 warm reset to start the bitclk */
··· 2018 if (pci->vendor == es1371_ac97_reset_hack[idx].vid && 2019 pci->device == es1371_ac97_reset_hack[idx].did && 2020 ensoniq->rev == es1371_ac97_reset_hack[idx].rev) { 2021 ensoniq->cssr |= ES_1371_ST_AC97_RST; 2022 outl(ensoniq->cssr, ES_REG(ensoniq, STATUS)); 2023 /* need to delay around 20ms(bleech) to give 2024 some CODECs enough time to wakeup */ 2025 + msleep(20); 2026 break; 2027 } 2028 /* AC'97 warm reset to start the bitclk */
+4 -10
sound/pci/es1968.c
··· 664 return result; 665 } 666 667 - #define big_mdelay(msec) do {\ 668 - set_current_state(TASK_UNINTERRUPTIBLE);\ 669 - schedule_timeout(((msec) * HZ + 999) / 1000);\ 670 - } while (0) 671 - 672 /* Wait for the codec bus to be free */ 673 static int snd_es1968_ac97_wait(es1968_t *chip) 674 { ··· 1804 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); 1805 do_gettimeofday(&start_time); 1806 spin_unlock_irq(&chip->reg_lock); 1807 - set_current_state(TASK_UNINTERRUPTIBLE); 1808 - schedule_timeout(HZ / 20); /* 50 msec */ 1809 spin_lock_irq(&chip->reg_lock); 1810 offset = __apu_get_register(chip, apu, 5); 1811 do_gettimeofday(&stop_time); ··· 2087 outw(0x0000, ioaddr + 0x60); /* write 0 to gpio 0 */ 2088 udelay(20); 2089 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio 1 */ 2090 - big_mdelay(20); 2091 2092 outw(save_68 | 0x1, ioaddr + 0x68); /* now restore .. */ 2093 outw((inw(ioaddr + 0x38) & 0xfffc) | 0x1, ioaddr + 0x38); ··· 2103 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio */ 2104 udelay(20); 2105 outw(0x0009, ioaddr + 0x60); /* write 9 to gpio */ 2106 - big_mdelay(500); 2107 //outw(inw(ioaddr + 0x38) & 0xfffc, ioaddr + 0x38); 2108 outw(inw(ioaddr + 0x3a) & 0xfffc, ioaddr + 0x3a); 2109 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c); ··· 2129 2130 if (w > 10000) { 2131 outb(inb(ioaddr + 0x37) | 0x08, ioaddr + 0x37); /* do a software reset */ 2132 - big_mdelay(500); /* oh my.. */ 2133 outb(inb(ioaddr + 0x37) & ~0x08, 2134 ioaddr + 0x37); 2135 udelay(1);
··· 664 return result; 665 } 666 667 /* Wait for the codec bus to be free */ 668 static int snd_es1968_ac97_wait(es1968_t *chip) 669 { ··· 1809 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); 1810 do_gettimeofday(&start_time); 1811 spin_unlock_irq(&chip->reg_lock); 1812 + msleep(50); 1813 spin_lock_irq(&chip->reg_lock); 1814 offset = __apu_get_register(chip, apu, 5); 1815 do_gettimeofday(&stop_time); ··· 2093 outw(0x0000, ioaddr + 0x60); /* write 0 to gpio 0 */ 2094 udelay(20); 2095 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio 1 */ 2096 + msleep(20); 2097 2098 outw(save_68 | 0x1, ioaddr + 0x68); /* now restore .. */ 2099 outw((inw(ioaddr + 0x38) & 0xfffc) | 0x1, ioaddr + 0x38); ··· 2109 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio */ 2110 udelay(20); 2111 outw(0x0009, ioaddr + 0x60); /* write 9 to gpio */ 2112 + msleep(500); 2113 //outw(inw(ioaddr + 0x38) & 0xfffc, ioaddr + 0x38); 2114 outw(inw(ioaddr + 0x3a) & 0xfffc, ioaddr + 0x3a); 2115 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c); ··· 2135 2136 if (w > 10000) { 2137 outb(inb(ioaddr + 0x37) | 0x08, ioaddr + 0x37); /* do a software reset */ 2138 + msleep(500); /* oh my.. */ 2139 outb(inb(ioaddr + 0x37) & ~0x08, 2140 ioaddr + 0x37); 2141 udelay(1);
+1 -2
sound/pci/intel8x0.c
··· 2464 } 2465 do_gettimeofday(&start_time); 2466 spin_unlock_irq(&chip->reg_lock); 2467 - set_current_state(TASK_UNINTERRUPTIBLE); 2468 - schedule_timeout(HZ / 20); 2469 spin_lock_irq(&chip->reg_lock); 2470 /* check the position */ 2471 pos = ichdev->fragsize1;
··· 2464 } 2465 do_gettimeofday(&start_time); 2466 spin_unlock_irq(&chip->reg_lock); 2467 + msleep(50); 2468 spin_lock_irq(&chip->reg_lock); 2469 /* check the position */ 2470 pos = ichdev->fragsize1;
+2 -2
sound/pci/mixart/mixart.c
··· 445 446 static int mixart_sync_nonblock_events(mixart_mgr_t *mgr) 447 { 448 - int timeout = HZ; 449 while (atomic_read(&mgr->msg_processed) > 0) { 450 - if (! timeout--) { 451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n"); 452 return -EBUSY; 453 }
··· 445 446 static int mixart_sync_nonblock_events(mixart_mgr_t *mgr) 447 { 448 + unsigned long timeout = jiffies + HZ; 449 while (atomic_read(&mgr->msg_processed) > 0) { 450 + if (time_after(jiffies, timeout)) { 451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n"); 452 return -EBUSY; 453 }
+2 -4
sound/pci/rme9652/hdsp.c
··· 679 } 680 681 if ((1000 / HZ) < 3000) { 682 - set_current_state(TASK_UNINTERRUPTIBLE); 683 - schedule_timeout((3000 * HZ + 999) / 1000); 684 } else { 685 mdelay(3000); 686 } ··· 5079 if (!is_9652 && !is_9632) { 5080 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 5081 if ((1000 / HZ) < 2000) { 5082 - set_current_state(TASK_UNINTERRUPTIBLE); 5083 - schedule_timeout((2000 * HZ + 999) / 1000); 5084 } else { 5085 mdelay(2000); 5086 }
··· 679 } 680 681 if ((1000 / HZ) < 3000) { 682 + ssleep(3); 683 } else { 684 mdelay(3000); 685 } ··· 5080 if (!is_9652 && !is_9632) { 5081 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 5082 if ((1000 / HZ) < 2000) { 5083 + ssleep(2); 5084 } else { 5085 mdelay(2000); 5086 }
+1 -2
sound/pci/trident/trident_main.c
··· 3153 switch (mode) { 3154 case GAMEPORT_MODE_COOKED: 3155 outb(GAMEPORT_MODE_ADC, TRID_REG(chip, GAMEPORT_GCR)); 3156 - set_current_state(TASK_UNINTERRUPTIBLE); 3157 - schedule_timeout(1 + 20 * HZ / 1000); /* 20msec */ 3158 return 0; 3159 case GAMEPORT_MODE_RAW: 3160 outb(0, TRID_REG(chip, GAMEPORT_GCR));
··· 3153 switch (mode) { 3154 case GAMEPORT_MODE_COOKED: 3155 outb(GAMEPORT_MODE_ADC, TRID_REG(chip, GAMEPORT_GCR)); 3156 + msleep(20); 3157 return 0; 3158 case GAMEPORT_MODE_RAW: 3159 outb(0, TRID_REG(chip, GAMEPORT_GCR));
+6 -7
sound/pci/via82xx.c
··· 547 int err; 548 err = snd_via82xx_codec_ready(chip, ac97->num); 549 /* here we need to wait fairly for long time.. */ 550 - set_current_state(TASK_UNINTERRUPTIBLE); 551 - schedule_timeout(HZ/2); 552 } 553 554 static void snd_via82xx_codec_write(ac97_t *ac97, ··· 1846 static int snd_via82xx_chip_init(via82xx_t *chip) 1847 { 1848 unsigned int val; 1849 - int max_count; 1850 unsigned char pval; 1851 1852 #if 0 /* broken on K7M? */ ··· 1888 } 1889 1890 /* wait until codec ready */ 1891 - max_count = ((3 * HZ) / 4) + 1; 1892 do { 1893 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 1894 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 1895 break; 1896 set_current_state(TASK_UNINTERRUPTIBLE); 1897 schedule_timeout(1); 1898 - } while (--max_count > 0); 1899 1900 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 1901 snd_printk("AC'97 codec is not ready [0x%x]\n", val); ··· 1904 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 1905 VIA_REG_AC97_SECONDARY_VALID | 1906 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 1907 - max_count = ((3 * HZ) / 4) + 1; 1908 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 1909 VIA_REG_AC97_SECONDARY_VALID | 1910 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); ··· 1915 } 1916 set_current_state(TASK_INTERRUPTIBLE); 1917 schedule_timeout(1); 1918 - } while (--max_count > 0); 1919 /* This is ok, the most of motherboards have only one codec */ 1920 1921 __ac97_ok2:
··· 547 int err; 548 err = snd_via82xx_codec_ready(chip, ac97->num); 549 /* here we need to wait fairly for long time.. */ 550 + msleep(500); 551 } 552 553 static void snd_via82xx_codec_write(ac97_t *ac97, ··· 1847 static int snd_via82xx_chip_init(via82xx_t *chip) 1848 { 1849 unsigned int val; 1850 + unsigned long end_time; 1851 unsigned char pval; 1852 1853 #if 0 /* broken on K7M? */ ··· 1889 } 1890 1891 /* wait until codec ready */ 1892 + end_time = jiffies + msecs_to_jiffies(750); 1893 do { 1894 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 1895 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 1896 break; 1897 set_current_state(TASK_UNINTERRUPTIBLE); 1898 schedule_timeout(1); 1899 + } while (time_before(jiffies, end_time)); 1900 1901 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 1902 snd_printk("AC'97 codec is not ready [0x%x]\n", val); ··· 1905 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 1906 VIA_REG_AC97_SECONDARY_VALID | 1907 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 1908 + end_time = jiffies + msecs_to_jiffies(750); 1909 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 1910 VIA_REG_AC97_SECONDARY_VALID | 1911 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); ··· 1916 } 1917 set_current_state(TASK_INTERRUPTIBLE); 1918 schedule_timeout(1); 1919 + } while (time_before(jiffies, end_time)); 1920 /* This is ok, the most of motherboards have only one codec */ 1921 1922 __ac97_ok2:
+6 -7
sound/pci/via82xx_modem.c
··· 408 int err; 409 err = snd_via82xx_codec_ready(chip, ac97->num); 410 /* here we need to wait fairly for long time.. */ 411 - set_current_state(TASK_UNINTERRUPTIBLE); 412 - schedule_timeout(HZ/2); 413 } 414 415 static void snd_via82xx_codec_write(ac97_t *ac97, ··· 922 static int snd_via82xx_chip_init(via82xx_t *chip) 923 { 924 unsigned int val; 925 - int max_count; 926 unsigned char pval; 927 928 pci_read_config_byte(chip->pci, VIA_MC97_CTRL, &pval); ··· 961 } 962 963 /* wait until codec ready */ 964 - max_count = ((3 * HZ) / 4) + 1; 965 do { 966 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 967 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 968 break; 969 set_current_state(TASK_UNINTERRUPTIBLE); 970 schedule_timeout(1); 971 - } while (--max_count > 0); 972 973 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 974 snd_printk("AC'97 codec is not ready [0x%x]\n", val); ··· 976 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 977 VIA_REG_AC97_SECONDARY_VALID | 978 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 979 - max_count = ((3 * HZ) / 4) + 1; 980 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 981 VIA_REG_AC97_SECONDARY_VALID | 982 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); ··· 987 } 988 set_current_state(TASK_INTERRUPTIBLE); 989 schedule_timeout(1); 990 - } while (--max_count > 0); 991 /* This is ok, the most of motherboards have only one codec */ 992 993 __ac97_ok2:
··· 408 int err; 409 err = snd_via82xx_codec_ready(chip, ac97->num); 410 /* here we need to wait fairly for long time.. */ 411 + msleep(500); 412 } 413 414 static void snd_via82xx_codec_write(ac97_t *ac97, ··· 923 static int snd_via82xx_chip_init(via82xx_t *chip) 924 { 925 unsigned int val; 926 + unsigned long end_time; 927 unsigned char pval; 928 929 pci_read_config_byte(chip->pci, VIA_MC97_CTRL, &pval); ··· 962 } 963 964 /* wait until codec ready */ 965 + end_time = jiffies + msecs_to_jiffies(750); 966 do { 967 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 968 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 969 break; 970 set_current_state(TASK_UNINTERRUPTIBLE); 971 schedule_timeout(1); 972 + } while (time_before(jiffies, end_time)); 973 974 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 975 snd_printk("AC'97 codec is not ready [0x%x]\n", val); ··· 977 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 978 VIA_REG_AC97_SECONDARY_VALID | 979 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 980 + end_time = jiffies + msecs_to_jiffies(750); 981 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 982 VIA_REG_AC97_SECONDARY_VALID | 983 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); ··· 988 } 989 set_current_state(TASK_INTERRUPTIBLE); 990 schedule_timeout(1); 991 + } while (time_before(jiffies, end_time)); 992 /* This is ok, the most of motherboards have only one codec */ 993 994 __ac97_ok2:
+3 -3
sound/pci/ymfpci/ymfpci_main.c
··· 84 85 static int snd_ymfpci_codec_ready(ymfpci_t *chip, int secondary) 86 { 87 - signed long end_time; 88 u32 reg = secondary ? YDSXGR_SECSTATUSADR : YDSXGR_PRISTATUSADR; 89 90 - end_time = (jiffies + ((3 * HZ) / 4)) + 1; 91 do { 92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) 93 return 0; 94 set_current_state(TASK_UNINTERRUPTIBLE); 95 schedule_timeout(1); 96 - } while (end_time - (signed long)jiffies >= 0); 97 snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); 98 return -EBUSY; 99 }
··· 84 85 static int snd_ymfpci_codec_ready(ymfpci_t *chip, int secondary) 86 { 87 + unsigned long end_time; 88 u32 reg = secondary ? YDSXGR_SECSTATUSADR : YDSXGR_PRISTATUSADR; 89 90 + end_time = jiffies + msecs_to_jiffies(750); 91 do { 92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) 93 return 0; 94 set_current_state(TASK_UNINTERRUPTIBLE); 95 schedule_timeout(1); 96 + } while (time_before(jiffies, end_time)); 97 snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); 98 return -EBUSY; 99 }