GPIO 4.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
;
; Copyright (c) 2012, RISC OS Open Ltd
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;     * Redistributions of source code must retain the above copyright
;       notice, this list of conditions and the following disclaimer.
;     * Redistributions in binary form must reproduce the above copyright
;       notice, this list of conditions and the following disclaimer in the
;       documentation and/or other materials provided with the distribution.
;     * Neither the name of RISC OS Open Ltd nor the names of its contributors
;       may be used to endorse or promote products derived from this software
;       without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
;

        AREA    |ARM$$code|, CODE, READONLY, PIC

        GET     Hdr:ListOpts
        GET     Hdr:Macros
        GET     Hdr:Proc
        GET     hdr.BCM2835
        GET     hdr.StaticWS

        EXPORT  GPIO_InitDevices
38
        IMPORT  memcpy
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

        MACRO
$class  HALDeviceField $field, $value
        LCLS    myvalue
      [ "$value" = ""
myvalue SETS    "$field"
      |
myvalue SETS    "$value"
      ]
        ASSERT  . - %A0 = HALDevice_$class$field
     [ ?HALDevice_$class$field = 2
        DCW     $myvalue
   ELIF ?HALDevice_$class$field = 4
        DCD     $myvalue
      |
        %       ?HALDevice_$class$field
      ]
        MEND


; Template for GPIO interface

GPIO_Dev
0
        HALDeviceField Type,               HALDeviceType_Comms + HALDeviceComms_GPIO
        HALDeviceField ID,                 HALDeviceID_GPIO_BCM2835
        HALDeviceField Location,           HALDeviceBus_Sys + HALDeviceSysBus_AHB ; Guess
        HALDeviceField Version,            0
        HALDeviceField Description,        GPIO_Description
        HALDeviceField Address,            0
        HALDeviceField Reserved1,          0
        HALDeviceField Activate,           GPIO_Activate
        HALDeviceField Deactivate,         GPIO_Deactivate
        HALDeviceField Reset,              GPIO_Reset
        HALDeviceField Sleep,              GPIO_Sleep
        HALDeviceField Device,             -1
        HALDeviceField TestIRQ,            0
        HALDeviceField ClearIRQ,           0
        HALDeviceField Reserved2,          0
GPIO    HALDeviceField Type,               GPIOType_BCM2835_RaspberryPi
79
GPIO    HALDeviceField Revision,           0 ; Filled in at runtime
80 81 82 83 84 85 86
        ASSERT  . - %A0 = HALDevice_GPIO_Size

GPIO_Description
        = "BCM2835 GPIO interface", 0

        ALIGN

87 88 89 90 91 92 93 94 95 96
; Lookup table to determine board type
        MACRO
        BoardType $model, $minrev, $maxrev, $type
        DCD $model
        DCD $minrev
        DCD $maxrev
        DCD GPIORevision_RaspberryPi_$type
        MEND

GPIO_BoardTypes
Ben Avison's avatar
Ben Avison committed
97 98 99 100
        BoardType 0, &02, &03, B_1
        BoardType 0, &04, &06, B_2
        BoardType 0, &07, &09, A_2
        BoardType 0, &0d, &0f, B_2
101 102
        BoardType 0, &10, &10, BPlus
        BoardType 0, &11, &ffffffff, C_1
103 104
GPIO_BoardTypes_End

105 106
        ; Initialise our HAL devices
GPIO_InitDevices ROUT
107 108
        Entry   "v1-v3"
        ADRL    a1, GPIODevice
109
        ADR     a2, GPIO_Dev
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        MOV     a3, #HALDevice_GPIO_Size
        BL      memcpy
        ADR     v1, GPIO_BoardTypes
        LDR     v2, Board_Model
        LDR     v3, Board_Revision
        ADR     ip, GPIO_BoardTypes_End
10
        CMP     v1, ip
        EXIT    EQ ; Unknown model, give up
        LDMIA   v1!, {a1-a4}
        CMP     a1, v2
        BNE     %BT10
        CMP     a2, v3
        CMPLS   v3, a3
        BHI     %BT10
        ; Found a match
        ADRL    a2, GPIODevice
        STR     a4, [a2, #HALDevice_GPIORevision]
        MOV     a1, #0
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        MOV     lr, pc
        LDR     pc, OSentries+4*OS_AddDevice
        EXIT

GPIO_Activate
        MOV     a1, #1
GPIO_Deactivate
GPIO_Reset
        MOV     pc, lr

GPIO_Sleep
        MOV     a1, #0
        MOV     pc, lr

        END