f2d056c6c121431ea607c6b0ec01be257bb768b3
[tpg/acess2.git] / Modules / Sound / SoundBlaster16 / main.c
1 /*\r
2  * Acess2 SoundBlaster16 Driver\r
3  */\r
4 #define DEBUG   0\r
5 #include <acess.h>\r
6 #include <errno.h>\r
7 #include <modules.h>\r
8 #include <vfs.h>\r
9 #include <fs_devfs.h>\r
10 #include <drv_pci.h>\r
11 #include <api_drv_sound.h>\r
12 \r
13 #define INT\r
14 \r
15 // === TYPES ===\r
16 typedef struct sSB16\r
17 {\r
18         Uint16  Base;\r
19 }       tSB16;\r
20 \r
21 // === CONSTANTS ===\r
22 enum {\r
23         SB16_PORT_RESET = 0x6,\r
24         SB16_PORT_READ  = 0xA,\r
25         SB16_PORT_WRITE = 0xC,\r
26         SB16_PORT_AVAIL = 0xE\r
27 };\r
28 #define SB16_BASE_PORT  0x200\r
29 enum {\r
30         SB16_CMD_RAW8    = 0x10,        // 8-bit DAC value follows\r
31         SB16_CMD_DMAFREQ = 0x40,        // followed by TIME_CONSTANT = 256 - 1000000 / frequency\r
32         SB16_CMD_DMASTOP = 0xD0,\r
33         SB16_CMD_SPKRON  = 0xD1,\r
34         SB16_CMD_SPKROFF = 0xD3,\r
35         SB16_CMD_DMACONT = 0xD4,\r
36         \r
37         // DMA Types (uses channel 1)\r
38         // - Followed by 16-bit length (well, length - 1)\r
39         SB16_CMD_DMA_8BIT = 0x14,\r
40 };\r
41 \r
42 \r
43 // === PROTOTYPES ===\r
44 // Driver\r
45  int    SB16_Install(char **Arguments);\r
46 void    SB16_Uninstall();\r
47 // Filesystem\r
48 Uint64  SB16_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);\r
49  int    SB16_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
50 \r
51 // === GLOBALS ===\r
52 MODULE_DEFINE(0, 0x0032, SoundBlaster16, SB16_Install, SB16_Uninstall, "PCI", NULL);\r
53 tDevFS_Driver   gBGA_DriverStruct = {\r
54         NULL, "SoundBlaster16",\r
55         {\r
56         .Write = SB16_Write,\r
57         .IOCtl = SB16_IOCtl\r
58         }\r
59 };\r
60 \r
61 // === CODE ===\r
62 int SB16_Install(char **Arguments)\r
63 {\r
64          int    jumper_port_setting = 1;        // 1-6 incl\r
65         \r
66         // Reset\r
67         outb(card->Base+SB16_PORT_RESET, 1);\r
68         // - Wait 3us\r
69         outb(card->Base+SB16_PORT_RESET, 0);\r
70         \r
71         SB16_ReadDSP(card);\r
72         \r
73         return MODULE_ERR_OK;\r
74 }\r
75 \r
76 void SB16_Uninstall()\r
77 {\r
78 }\r
79 \r
80 /**\r
81  * \fn Uint64 SB16_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)\r
82  * \brief Write to the framebuffer\r
83  */\r
84 Uint64 SB16_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)\r
85 {       \r
86         return 0;\r
87 }\r
88 \r
89 /**\r
90  * \fn int SB16_IOCtl(tVFS_Node *Node, int ID, void *Data)\r
91  * \brief Handle messages to the device\r
92  */\r
93 int SB16_IOCtl(tVFS_Node *Node, int ID, void *Data)\r
94 {\r
95         return -1;\r
96 }\r
97 \r
98 //\r
99 int SB16_WriteDSP(tSB16 *Card, Uint8 Value)\r
100 {\r
101         // Wait for the card to be ready\r
102         while( inb(Card->Base+SB16_PORT_WRITE) & 0x80 )\r
103                 ;\r
104         \r
105         outb(Card->Base+SB16_PORT_WRITE, Value);\r
106         \r
107         return 0;\r
108 }\r
109 \r
110 Uint8 SB16_ReadDSP(tSB16 *Card)\r
111 {\r
112         // Wait for bit 7 of AVAIL\r
113         while( !(inb(card->Base+SB16_PORT_AVAIL) & 0x80) )\r
114                 ;\r
115         return inb(card->Base+SB16_PORT_READ);\r
116 }\r

UCC git Repository :: git.ucc.asn.au