Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / i386 / isa / sound / mad16.h
1
2 /*
3  *      Initialization code for OPTI MAD16 interface chip by
4  *      Davor Jadrijevic <davor@emard.pub.hr>
5  *      (Included by ad1848.c when MAD16 support is enabled)
6  *
7  * It looks like MAD16 is similar than the Mozart chip (OAK OTI-601).
8  * It could be even possible that these chips are exactly the same. Can
9  * anybody confirm this?
10  */
11
12 static void wr_a_mad16(int base, int v, int a)
13 {
14  OUTB(a, base + 0xf);
15  OUTB(v, base + 0x11);
16 }
17
18 static void wr_b_mad16(int base, int v, int a)
19 {
20  OUTB(a, base + 0xf);
21  OUTB(v, base + 0xd);
22 }
23
24 /*
25 static int rd_a_mad16(int base, int a)
26 {
27  OUTB(a, base + 0xf);
28  return INB(base + 0x11);
29 }
30 */
31
32 static int rd_b_mad16(int base, int a)
33 {
34  OUTB(a, base + 0xf);
35  return INB(base + 0xd);
36 }
37
38 /*
39 static int rd_0_mad16(int base, int a)
40 {
41  OUTB(a, base + 0xf);
42  return INB(base + 0xf);
43 }
44
45 static void wr_ad(int base, int v, int a)
46 {
47  OUTB(a, base + 4);
48  OUTB(v, base + 5);
49 }
50
51 static int rd_ad(int base, int a)
52 {
53  OUTB(a, base + 4);
54  return INB(base + 5);
55 }
56 */
57
58 static int mad16init(int adr)
59 {
60  int j;
61  long i;
62
63  static int ad1848_bases[] = 
64 { 0x220, -1, -1, 0x240, -1, -1, -1, -1, 0x530, 0xE80, 0xF40, 0x604, 0 };
65
66  int mad16_base = 0xf80, ad1848_base;
67
68
69  for(j = 0; (j < 16) && (ad1848_bases[j] != 0); j++)
70   if(adr == ad1848_bases[j])
71    break;
72
73  if( (ad1848_base = ad1848_bases[j]) < 0x530)
74  {
75   printk("Unknown MAD16 setting 0x%3X\n", adr);
76   return -1;
77  }
78
79  /* printk("OPTi MAD16 WSS at 0x%3X\n", ad1848_base); */
80
81  rd_b_mad16(mad16_base, 0xe2);
82  wr_a_mad16(mad16_base, 0x1a, 0xe2);
83  wr_b_mad16(mad16_base, j * 16 + 1, 0xe2);
84  wr_a_mad16(mad16_base, 0x1a, 0xe2);
85  for( i = 0; i < 10000; i++)
86   if( (INB(ad1848_base+4) & 0x80) == 0 )
87    break;
88
89  return 0;
90 };
91