]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/audioac97mix.c
devkbd: bits bad! revert repeat/delay, better patches welcome
[plan9front.git] / sys / src / 9 / pc / audioac97mix.c
index bb27d38669256fa10a2df8ab73d31893f47bc2b0..5194cccbc70bf48d09de9cb58267d28fae95e010 100644 (file)
@@ -7,8 +7,6 @@
 #include "../port/error.h"
 #include "../port/audioif.h"
 
-enum { Maxbusywait = 500000 };
-
 enum {
        Reset = 0x0,
                Capmic = 0x1,
@@ -114,18 +112,18 @@ enum {
 };
 
 static Volume voltab[] = {
-       [Vmaster] "master", 0x02, 63, Stereo, 0,
-       [Vaudio] "audio", 0x18, 31, Stereo, 0,
-       [Vhead] "head", 0x04, 31, Stereo, Capheadphones,
+       [Vmaster] "master", 0x02, -63, Stereo, 0,
+       [Vaudio] "audio", 0x18, -31, Stereo, 0,
+       [Vhead] "head", 0x04, -31, Stereo, Capheadphones,
        [Vbass] "bass", 0x08, 15, Left, Captonectl,
        [Vtreb] "treb", 0x08, 15, Right, Captonectl,
-       [Vbeep] "beep", 0x0a, 31, Right, 0,
-       [Vphone] "phone", 0x0c, 31, Right, 0,
-       [Vmic] "mic", 0x0e, 31, Right, Capmic,
-       [Vline] "line", 0x10, 31, Stereo, 0,
-       [Vcd] "cd", 0x12, 31, Stereo,   0,
-       [Vvideo] "video", 0x14, 31, Stereo, 0,
-       [Vaux] "aux", 0x16, 63, Stereo, 0,
+       [Vbeep] "beep", 0x0a, -31, Right, 0,
+       [Vphone] "phone", 0x0c, -31, Right, 0,
+       [Vmic] "mic", 0x0e, -31, Right, Capmic,
+       [Vline] "line", 0x10, -31, Stereo, 0,
+       [Vcd] "cd", 0x12, -31, Stereo,  0,
+       [Vvideo] "video", 0x14, -31, Stereo, 0,
+       [Vaux] "aux", 0x16, -63, Stereo, 0,
        [Vrecgain] "recgain", 0x1c, 15, Stereo, 0,
        [Vmicgain] "micgain", 0x1e, 15, Right, Capmic,
        [Vspeed] "speed", 0x2c, 0, Absolute, 0,
@@ -160,11 +158,10 @@ ac97volget(Audio *adev, int x, int a[2])
        default:
                v = m->rr(adev, vol->reg);
                if(v & 0x8000){
-                       a[0] = 0;
-                       a[1] = 0;
+                       a[0] = a[1] = vol->range < 0 ? 0x7f : 0;
                } else {
-                       a[0] = vol->range - ((v>>8) & 0x7f);
-                       a[1] = vol->range - (v & 0x7f);
+                       a[0] = ((v>>8) & 0x7f);
+                       a[1] = (v & 0x7f);
                }
        }
        return 0;
@@ -185,22 +182,24 @@ ac97volset(Audio *adev, int x, int a[2])
                        return 0;
                }
                m->wr(adev, vol->reg, a[0]);            
-               if(x == Vspeed)
+               if(x == Vspeed){
+                       m->wr(adev, 0x32, a[0]);        /* adc rate */
                        adev->speed = m->rr(adev, vol->reg);
+               }
                break;
        case Left:
-               v = (vol->range - a[0]) & 0x7f;
+               v = a[0] & 0x7f;
                w = m->rr(adev, vol->reg) & 0x7f;
                m->wr(adev, vol->reg, (v<<8)|w);
                break;
        case Right:
                v = m->rr(adev, vol->reg) & 0x7f00;
-               w = (vol->range - a[1]) & 0x7f;
+               w = a[1] & 0x7f;
                m->wr(adev, vol->reg, v|w);
                break;
        case Stereo:
-               v = (vol->range - a[0]) & 0x7f;
-               w = (vol->range - a[1]) & 0x7f;
+               v = a[0] & 0x7f;
+               w = a[1] & 0x7f;
                m->wr(adev, vol->reg, (v<<8)|w);
                break;
        }
@@ -235,7 +234,6 @@ ac97mixreset(Audio *adev, void (*wr)(Audio*,int,ushort), ushort (*rr)(Audio*,int
 {
        Mixer *m;
        ushort t;
-       int i;
 
        m = malloc(sizeof(Mixer));
        if(m == nil){
@@ -246,14 +244,9 @@ ac97mixreset(Audio *adev, void (*wr)(Audio*,int,ushort), ushort (*rr)(Audio*,int
        m->rr = rr;
        m->wr(adev, Reset, 0);
        m->wr(adev, Powerdowncsr, 0);
-
+       delay(1000);
        t = (Adcpower | Dacpower | Anlpower | Refpower);
-       for(i = 0; i < Maxbusywait; i++){
-               if((m->rr(adev, Powerdowncsr) & t) == t)
-                       break;
-               microdelay(1);
-       }
-       if(i == Maxbusywait)
+       if((m->rr(adev, Powerdowncsr) & t) != t)
                print("#A%d: ac97 exhausted waiting powerup\n", adev->ctlrno);
 
        t = m->rr(adev, Extid);