Rev 6878 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5558 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
6878 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2015-2017. All rights reserved. ;; |
5558 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | format PE DLL native 0.05 |
||
9 | entry START |
||
10 | |||
11 | DEBUG = 1 |
||
12 | __DEBUG__ = 1 |
||
13 | __DEBUG_LEVEL__ = 1 ; 1 = verbose, 2 = errors only |
||
14 | |||
15 | |||
16 | API_VERSION = 0 ;debug |
||
17 | |||
18 | STRIDE = 4 ;size of row in devices table |
||
19 | |||
20 | SRV_GETVERSION = 0 |
||
21 | |||
22 | section '.flat' code readable writable executable |
||
23 | |||
6878 | hidnplayr | 24 | include '../proc32.inc' |
25 | include '../struct.inc' |
||
26 | include '../macros.inc' |
||
27 | include '../peimport.inc' |
||
28 | include '../fdo.inc' |
||
5558 | hidnplayr | 29 | |
6878 | hidnplayr | 30 | GPIO_PORT_CONFIG_ADDR = 0xF100 |
31 | GPIO_DATA_ADDR = 0xF200 |
||
32 | ADC_ADDR = 0xFE00 |
||
33 | |||
5558 | hidnplayr | 34 | proc START c, state:dword, cmdline:dword |
35 | |||
36 | cmp [state], 1 |
||
37 | jne .exit |
||
38 | .entry: |
||
39 | |||
40 | push esi |
||
41 | DEBUGF 1,"Loading vortex86EX GPIO driver\n" |
||
42 | call detect |
||
43 | pop esi |
||
44 | test eax, eax |
||
45 | jz .fail |
||
46 | |||
47 | ; Set crossbar base address register in southbridge |
||
6878 | hidnplayr | 48 | invoke PciWrite16, [bus], [dev], 0x64, 0x0A00 or 1 |
5558 | hidnplayr | 49 | |
50 | ; Set GPIO base address register in southbridge |
||
6878 | hidnplayr | 51 | invoke PciWrite16, [bus], [dev], 0x62, GPIO_PORT_CONFIG_ADDR or 1 |
5558 | hidnplayr | 52 | |
6878 | hidnplayr | 53 | DEBUGF 1,"Setting up ADC\n" |
54 | |||
55 | ; Enable ADC |
||
56 | invoke PciRead32, [bus], [dev], 0xBC |
||
57 | and eax, not (1 shl 28) |
||
58 | invoke PciWrite32, [bus], [dev], 0xBC, eax |
||
59 | |||
60 | ; Set ADC base address |
||
61 | mov ebx, [dev] |
||
62 | inc ebx |
||
63 | invoke PciRead16, [bus], ebx, 0xDE |
||
64 | or ax, 0x02 |
||
65 | invoke PciWrite16, [bus], ebx, 0xDE, eax |
||
66 | |||
67 | invoke PciWrite32, [bus], ebx, 0xE0, 0x00500000 or ADC_ADDR |
||
68 | |||
69 | ; set up ADC |
||
70 | mov dx, ADC_ADDR + 1 |
||
71 | xor al, al |
||
72 | out dx, al |
||
73 | |||
74 | ; Empty FIFO |
||
75 | @@: |
||
76 | mov dx, ADC_ADDR + 2 ; Status register |
||
77 | in al, dx |
||
78 | test al, 0x01 ; FIFO ready |
||
79 | jz @f |
||
80 | mov dx, ADC_ADDR + 4 |
||
81 | in ax, dx |
||
82 | jmp @r |
||
83 | @@: |
||
84 | |||
5558 | hidnplayr | 85 | ; Enable GPIO0-9 |
6878 | hidnplayr | 86 | mov dx, GPIO_PORT_CONFIG_ADDR + 0 ; General-Purpose I/O Data & Direction Decode Enable |
5558 | hidnplayr | 87 | mov eax, 0x000001ff |
88 | out dx, eax |
||
89 | |||
6878 | hidnplayr | 90 | mov ecx, 10 ; 10 GPIO ports total |
91 | mov dx, GPIO_PORT_CONFIG_ADDR + 4 ; General-Purpose I/O Port0 Data & Direction Decode Address |
||
92 | mov ax, GPIO_DATA_ADDR |
||
5558 | hidnplayr | 93 | .gpio_init: |
94 | ; Set GPIO data port base address |
||
95 | out dx, ax |
||
96 | add ax, 2 |
||
97 | add dx, 2 |
||
98 | ; Set GPIO direction base address |
||
99 | out dx, ax |
||
100 | add ax, 2 |
||
101 | add dx, 2 |
||
102 | ; loop |
||
103 | dec ecx |
||
104 | jnz .gpio_init |
||
105 | |||
7298 | hidnplayr | 106 | ; Set GPIO0 pin 0-7 as output |
107 | mov al, 0xff |
||
6878 | hidnplayr | 108 | mov dx, GPIO_DATA_ADDR + 0*4 + 2 |
5558 | hidnplayr | 109 | out dx, al |
110 | |||
111 | invoke RegService, my_service, service_proc |
||
112 | ret |
||
6878 | hidnplayr | 113 | .fail: |
114 | .exit: |
||
5558 | hidnplayr | 115 | xor eax, eax |
116 | ret |
||
117 | endp |
||
118 | |||
119 | proc service_proc stdcall, ioctl:dword |
||
120 | |||
121 | mov ebx, [ioctl] |
||
122 | mov eax, [ebx+IOCTL.io_code] |
||
123 | cmp eax, SRV_GETVERSION |
||
124 | jne @F |
||
125 | |||
126 | mov eax, [ebx+IOCTL.output] |
||
127 | cmp [ebx+IOCTL.out_size], 4 |
||
128 | jne .fail |
||
129 | mov dword [eax], API_VERSION |
||
130 | xor eax, eax |
||
131 | ret |
||
6878 | hidnplayr | 132 | @@: |
5558 | hidnplayr | 133 | cmp eax, 1 ; read GPIO P0 |
6878 | hidnplayr | 134 | jne .no_gpioread |
135 | mov dx, GPIO_DATA_ADDR + 0x00 |
||
5558 | hidnplayr | 136 | in al, dx |
137 | ret |
||
6878 | hidnplayr | 138 | .no_gpioread: |
5558 | hidnplayr | 139 | cmp eax, 2 ; write GPIO P0 |
6878 | hidnplayr | 140 | jne .no_gpiowrite |
5558 | hidnplayr | 141 | |
142 | mov eax, [ebx + IOCTL.input] |
||
6878 | hidnplayr | 143 | mov dx, GPIO_DATA_ADDR + 0x00 |
5558 | hidnplayr | 144 | out dx, al |
145 | xor eax, eax |
||
146 | ret |
||
6878 | hidnplayr | 147 | .no_gpiowrite: |
7298 | hidnplayr | 148 | cmp eax, 3 ; read single ADC channel |
6878 | hidnplayr | 149 | jne .no_adcread |
150 | |||
7298 | hidnplayr | 151 | mov ecx, [ebx + IOCTL.input] |
152 | cmp ecx, 8 |
||
153 | jae .fail |
||
154 | |||
6878 | hidnplayr | 155 | mov dx, ADC_ADDR + 1 |
156 | mov al, 1 shl 3 ; Power down ADC |
||
157 | out dx, al |
||
158 | |||
159 | mov dx, ADC_ADDR + 0 ; AUX channel select register |
||
7298 | hidnplayr | 160 | mov al, 1 |
161 | shl ax, cl |
||
6878 | hidnplayr | 162 | out dx, al |
163 | |||
164 | mov dx, ADC_ADDR + 1 |
||
165 | mov al, 1 shl 0 ; Single shot, no interrupts, start |
||
166 | out dx, al |
||
167 | |||
168 | mov dx, ADC_ADDR + 2 |
||
169 | @@: |
||
170 | in al, dx |
||
171 | test al, 1 shl 0 ; data ready? |
||
172 | jz @r |
||
173 | |||
174 | mov dx, ADC_ADDR + 4 |
||
7298 | hidnplayr | 175 | in ax, dx ; read the data from the FIFO and return to user call |
6878 | hidnplayr | 176 | ret |
177 | .no_adcread: |
||
178 | .fail: |
||
5558 | hidnplayr | 179 | or eax, -1 |
180 | ret |
||
181 | endp |
||
182 | |||
183 | |||
184 | proc detect |
||
185 | push ebx |
||
186 | invoke GetPCIList |
||
187 | mov ebx, eax |
||
6878 | hidnplayr | 188 | .next_dev: |
5558 | hidnplayr | 189 | mov eax, [eax+PCIDEV.fd] |
190 | cmp eax, ebx |
||
191 | jz .err |
||
192 | mov edx, [eax+PCIDEV.vendor_device_id] |
||
193 | |||
194 | mov esi, devices |
||
6878 | hidnplayr | 195 | @@: |
5558 | hidnplayr | 196 | cmp dword [esi], 0 |
197 | jz .next_dev |
||
198 | cmp edx, [esi] |
||
199 | jz .found |
||
200 | |||
201 | add esi, STRIDE |
||
202 | jmp @B |
||
203 | |||
6878 | hidnplayr | 204 | .found: |
5558 | hidnplayr | 205 | movzx ebx, [eax+PCIDEV.devfn] |
206 | mov [dev], ebx |
||
207 | movzx ebx, [eax+PCIDEV.bus] |
||
208 | mov [bus], ebx |
||
209 | xor eax, eax |
||
210 | inc eax |
||
211 | pop ebx |
||
212 | ret |
||
6878 | hidnplayr | 213 | .err: |
5558 | hidnplayr | 214 | DEBUGF 1,"Could not find vortex86EX south bridge!\n" |
215 | xor eax, eax |
||
216 | pop ebx |
||
217 | ret |
||
218 | endp |
||
219 | |||
220 | DEVICE_ID = 6011h |
||
221 | VENDOR_ID = 17F3h |
||
222 | |||
223 | ;all initialized data place here |
||
224 | |||
225 | align 4 |
||
226 | devices dd (DEVICE_ID shl 16)+VENDOR_ID |
||
227 | dd 0 ;terminator |
||
228 | |||
229 | my_service db '86DUINO-GPIO',0 ;max 16 chars include zero |
||
230 | |||
231 | include_debug_strings ; All data wich FDO uses will be included here |
||
232 | |||
233 | dev dd ? |
||
234 | bus dd ? |
||
235 | |||
236 | align 4 |
||
237 | data fixups |
||
238 | end data |