/[openvortex]/alsa/pci/au88x0/au88x0_core.c
ViewVC logotype

Diff of /alsa/pci/au88x0/au88x0_core.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by vizard, Thu Jun 12 23:37:31 2003 UTC revision 1.22 by vizard, Mon Jun 16 01:39:00 2003 UTC
# Line 1880  irqreturn_t vortex_interrupt(int irq, vo Line 1880  irqreturn_t vortex_interrupt(int irq, vo
1880    
1881  /* Codec */  /* Codec */
1882    
1883  #define POLL_COUNT 15  #define POLL_COUNT 1000
1884  void vortex_codec_init(vortex_t *vortex) {  void vortex_codec_init(vortex_t *vortex) {
1885      int i;      int i;
1886    
# Line 1916  void vortex_codec_init(vortex_t *vortex) Line 1916  void vortex_codec_init(vortex_t *vortex)
1916          hwwrite(vortex->mmio,VORTEX_CODEC_EN, hwread(vortex->mmio,VORTEX_CODEC_EN) | 0x300);          hwwrite(vortex->mmio,VORTEX_CODEC_EN, hwread(vortex->mmio,VORTEX_CODEC_EN) | 0x300);
1917  }  }
1918    
1919  void vortex_codec_write(ac97_t *codec, unsigned short addr,unsigned short data){  void vortex_codec_write(ac97_t *codec, unsigned short addr, unsigned short data){
1920    
1921          vortex_t *card = (vortex_t*)codec->private_data;          vortex_t *card = (vortex_t*)codec->private_data;
1922          unsigned long flags;          unsigned long flags;
1923          unsigned int t;          unsigned int lifeboat = 0;
1924    
         //verify that the codec is ready for writing  
         for (t = 0; t < POLL_COUNT; t++){  
                 if((hwread(card->mmio,VORTEX_CODEC_CTRL) & 0x100))  
                         break;  
         udelay(100);  
         }  
1925          spin_lock_irqsave(&card->lock, flags);          spin_lock_irqsave(&card->lock, flags);
1926          //Write register          
1927            /* wait for transactions to clear */
1928            while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) {
1929                    udelay(100);
1930                    if (lifeboat++ > POLL_COUNT) {
1931                            printk(KERN_ERR "vortex: ac97 codec busy\n");
1932                            return;
1933                    }
1934            }
1935            
1936            /* write register */
1937          hwwrite(card->mmio, VORTEX_CODEC_IO, ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |          hwwrite(card->mmio, VORTEX_CODEC_IO, ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |
1938                          ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) |                          ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) |
1939                                          VORTEX_CODEC_WRITE);                                          VORTEX_CODEC_WRITE);
         //FIXME: maybe check to see if the write succeeded??  
1940    
1941          spin_unlock_irqrestore(&card->lock, flags);          spin_unlock_irqrestore(&card->lock, flags);
1942          for (t = 0; t < POLL_COUNT; t++){  
1943                  if((hwread(card->mmio,VORTEX_CODEC_CTRL) & 0x100))          /* verify that the write succeeded */
1944                          break;          if (vortex_codec_read(codec, addr) != data) {
1945          udelay(100);                  printk(KERN_ERR "vortex: ac97 codec write failed\n");
         }  
1946    
1947  }  }
1948    
1949  unsigned short vortex_codec_read(ac97_t *codec, unsigned short addr) {  unsigned short vortex_codec_read(ac97_t *codec, unsigned short addr) {
1950    
1951          unsigned long reader;          u32 read_addr;
1952          vortex_t *card = (vortex_t*)codec->private_data;          vortex_t *card = (vortex_t*)codec->private_data;
1953          unsigned long flags;          unsigned long flags;
1954          unsigned t;          unsigned lifeboat = 0;
1955          u16 x;          u16 x;
1956            
1957          spin_lock_irqsave(&card->lock, flags);          spin_lock_irqsave(&card->lock, flags);
1958    
1959          //poll for codec write          /* wait for transactions to clear */
1960          for (t = 0; t < POLL_COUNT; t++){          while (!(hwread(card->mmio, VORTEX_CODEC_CTRL) & 0x100)) {
1961                  if(!(hwread(card->mmio,VORTEX_CODEC_CTRL) & 0x100))                  udelay(100);
1962                          break;                  if (lifeboat++ > POLL_COUNT) {
1963          udelay(100);                          printk(KERN_ERR "vortex: ac97 codec busy\n");
1964          }                          return 0xffff;
1965          reader = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK);                  }
1966            }
1967            
1968            /* set up read address */
1969            read_addr = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK);
1970          hwwrite(card->mmio, VORTEX_CODEC_IO, reader);          hwwrite(card->mmio, VORTEX_CODEC_IO, reader);
1971    
1972          //FIXME: this could be cleaner, and have a proper fail path          /* wait for address */
1973          for (t = 0; t < POLL_COUNT; t++){          lifeboat = 0;
1974                  if(((hwread(card->mmio,VORTEX_CODEC_IO) & VORTEX_CODEC_ADDMASK)) == (addr << VORTEX_CODEC_ADDSHIFT))          while ((hwread(card->mmio, VORTEX_CODEC_IO) & VORTEX_CODEC_ADDMASK) != (addr << VORTEX_CODEC_ADDSHIFT))
                         break;  
1975                  udelay(100);                  udelay(100);
1976          }                  if (lifeboat++ > POLL_COUNT) {
1977          //FIXME: get rid of this                          printk(KERN_ERR "vortex: ac97 address never arrived\n");
1978          x = hwread(card->mmio,VORTEX_CODEC_IO) & VORTEX_CODEC_DATMASK;                          return 0xffff;
1979                    }
1980            }
1981            
1982            /* read codec */
1983            x = hwread(card->mmio, VORTEX_CODEC_IO) & VORTEX_CODEC_DATMASK;
1984    
1985          spin_unlock_irqrestore(&card->lock, flags);          spin_unlock_irqrestore(&card->lock, flags);
1986          return x;          return x;

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26