Subversion Repositories Kolibri OS

Rev

Rev 6878 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. ;driver sceletone
  9.  
  10. format PE DLL native 0.05
  11. entry START
  12.  
  13.         DEBUG                   = 1
  14.         __DEBUG__               = 1
  15.         __DEBUG_LEVEL__         = 1             ; 1 = verbose, 2 = errors only
  16.  
  17.  
  18.         API_VERSION             = 0  ;debug
  19.  
  20.         STRIDE                  = 4      ;size of row in devices table
  21.  
  22.         SRV_GETVERSION          = 0
  23.  
  24. section '.flat' code readable writable executable
  25.  
  26. include 'proc32.inc'
  27. include 'struct.inc'
  28. include 'macros.inc'
  29. include 'peimport.inc'
  30. include 'fdo.inc'
  31.  
  32. proc START c, state:dword, cmdline:dword
  33.  
  34.         cmp     [state], 1
  35.         jne     .exit
  36. .entry:
  37.  
  38.         push    esi
  39.         DEBUGF  1,"Loading vortex86EX GPIO driver\n"
  40.         call    detect
  41.         pop     esi
  42.         test    eax, eax
  43.         jz      .fail
  44.  
  45. ; Set crossbar base address register in southbridge
  46.         invoke  PciWrite16, [bus], [dev], 64h, 0x0A00 or 1
  47.  
  48. ; Set GPIO base address register in southbridge
  49.         invoke  PciWrite16, [bus], [dev], 62h, 0xF100 or 1
  50.  
  51. ; Enable GPIO0-9
  52.         mov     dx, 0xf100
  53.         mov     eax, 0x000001ff
  54.         out     dx, eax
  55.  
  56.         mov     ecx, 10
  57.         mov     dx, 0xf104
  58.         mov     ax, 0xf200
  59.   .gpio_init:
  60. ; Set GPIO data port base address
  61.         out     dx, ax
  62.         add     ax, 2
  63.         add     dx, 2
  64. ; Set GPIO direction base address
  65.         out     dx, ax
  66.         add     ax, 2
  67.         add     dx, 2
  68. ; loop
  69.         dec     ecx
  70.         jnz     .gpio_init
  71.  
  72. ; Set GPIO0 pin 0 as output
  73.         mov     al, 0x01
  74.         mov     dx, 0xf202
  75.         out     dx, al
  76.  
  77. ; Set GPIO4 pin 0 as output
  78.         mov     al, 0x01
  79.         mov     dx, 0xf212
  80.         out     dx, al
  81.  
  82.         invoke  RegService, my_service, service_proc
  83.         ret
  84. .fail:
  85. .exit:
  86.         xor     eax, eax
  87.         ret
  88. endp
  89.  
  90. proc service_proc stdcall, ioctl:dword
  91.  
  92.         mov     ebx, [ioctl]
  93.         mov     eax, [ebx+IOCTL.io_code]
  94.         cmp     eax, SRV_GETVERSION
  95.         jne     @F
  96.  
  97.         mov     eax, [ebx+IOCTL.output]
  98.         cmp     [ebx+IOCTL.out_size], 4
  99.         jne     .fail
  100.         mov     dword [eax], API_VERSION
  101.         xor     eax, eax
  102.         ret
  103. @@:
  104.         cmp     eax, 1  ; read GPIO P0
  105.         jne     @f
  106.         mov     dx, 0xf200
  107.         in      al, dx
  108.         ret
  109. @@:
  110.         cmp     eax, 2  ; write GPIO P0
  111.         jne     @f
  112.  
  113.         mov     eax, [ebx + IOCTL.input]
  114.         mov     dx, 0xf200
  115.         out     dx, al
  116.         xor     eax, eax
  117.         ret
  118. @@:
  119. .fail:
  120.         or      eax, -1
  121.         ret
  122. endp
  123.  
  124.  
  125. proc detect
  126.         push    ebx
  127.         invoke  GetPCIList
  128.         mov     ebx, eax
  129. .next_dev:
  130.         mov     eax, [eax+PCIDEV.fd]
  131.         cmp     eax, ebx
  132.         jz      .err
  133.         mov     edx, [eax+PCIDEV.vendor_device_id]
  134.  
  135.         mov     esi, devices
  136. @@:
  137.         cmp     dword [esi], 0
  138.         jz      .next_dev
  139.         cmp     edx, [esi]
  140.         jz      .found
  141.  
  142.         add     esi, STRIDE
  143.         jmp     @B
  144.  
  145. .found:
  146.         movzx   ebx, [eax+PCIDEV.devfn]
  147.         mov     [dev], ebx
  148.         movzx   ebx, [eax+PCIDEV.bus]
  149.         mov     [bus], ebx
  150.         xor     eax, eax
  151.         inc     eax
  152.         pop     ebx
  153.         ret
  154. .err:
  155.         DEBUGF  1,"Could not find vortex86EX south bridge!\n"
  156.         xor     eax, eax
  157.         pop     ebx
  158.         ret
  159. endp
  160.  
  161. DEVICE_ID    = 6011h
  162. VENDOR_ID    = 17F3h
  163.  
  164. ;all initialized data place here
  165.  
  166. align 4
  167. devices      dd (DEVICE_ID shl 16)+VENDOR_ID
  168.              dd 0    ;terminator
  169.  
  170. my_service   db '86DUINO-GPIO',0  ;max 16 chars include zero
  171.  
  172. include_debug_strings                           ; All data wich FDO uses will be included here
  173.  
  174. dev     dd ?
  175. bus     dd ?
  176.  
  177. align 4
  178. data fixups
  179. end data
  180.