summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/atj/gpio.lua
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/tools/lua/atj/gpio.lua')
-rw-r--r--utils/hwstub/tools/lua/atj/gpio.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/atj/gpio.lua b/utils/hwstub/tools/lua/atj/gpio.lua
new file mode 100644
index 0000000000..970d271187
--- /dev/null
+++ b/utils/hwstub/tools/lua/atj/gpio.lua
@@ -0,0 +1,65 @@
1ATJ.gpio = {}
2
3function ATJ.gpio.muxsel(dev)
4 if type(dev) == "string" then
5 if dev == "LCM" then dev = 0
6 elseif dev == "SD" then dev = 1
7 elseif dev == "NAND" then dev = 2
8 else error("Invalid mux string " .. dev)
9 end
10 end
11
12 local mfctl0 = HW.GPIO.MFCTL0.read()
13 if dev == 0 then
14 -- LCM (taken from WELCOME.BIN)
15 mfctl0 = bit32.band(mfctl0, 0xfe3f3f00)
16 mfctl0 = bit32.bor(mfctl0, 0x00808092)
17 elseif dev == 1 then
18 -- SD (taken from CARD.DRV)
19 mfctl0 = bit32.band(mfctl0, 0xff3ffffc)
20 mfctl0 = bit32.bor(mfctl0, 0x01300004)
21 elseif dev == 2 then
22 -- NAND (taken from BROM dump)
23 mfctl0 = bit32.band(mfctl0, 0xfe3ff300)
24 mfctl0 = bit32.bor(mfctl0, 0x00400449)
25 end
26
27 -- enable multifunction mux
28 HW.GPIO.MFCTL1.write(0x80000000)
29
30 -- write multifunction mux selection
31 HW.GPIO.MFCTL0.write(mfctl0)
32end
33
34function ATJ.gpio.outen(port, pin, en)
35 if type(port) == "string" then
36 if port == "PORTA" then
37 HW.GPIO.AOUTEN.write(bit32.replace(HW.GPIO.AOUTEN.read(), en, pin, 1))
38 elseif port == "PORTB" then
39 HW.GPIO.BOUTEN.write(bit32.replace(HW.GPIO.BOUTEN.read(), en, pin, 1))
40 else error("Invalid port string " .. port)
41 end
42 end
43end
44
45function ATJ.gpio.inen(port, pin)
46 if type(port) == "string" then
47 if port == "PORTA" then
48 HW.GPIO.AINEN.write(bit32.replace(HW.GPIO.AINEN.read(), en, pin, 1))
49 elseif port == "PORTB" then
50 HW.GPIO.BINEN.write(bit32.replace(HW.GPIO.BINEN.read(), en, pin, 1))
51 else error("Invalid port string " .. port)
52 end
53 end
54end
55
56function ATJ.gpio.set(port, pin, val)
57 if type(port) == "string" then
58 if port == "PORTA" then
59 HW.GPIO.ADAT.write(bit32.replace(HW.GPIO.ADAT.read(), val, pin, 1))
60 elseif port == "PORTB" then
61 HW.GPIO.BDAT.write(bit32.replace(HW.GPIO.BDAT.read(), val, pin, 1))
62 else error("Invalid port string " .. port)
63 end
64 end
65end