Subversion Repositories Kolibri OS

Rev

Rev 6878 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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