summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/stmp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/tools/lua/stmp')
-rw-r--r--utils/hwstub/tools/lua/stmp/i2c.lua13
-rw-r--r--utils/hwstub/tools/lua/stmp/pinctrl.lua34
2 files changed, 41 insertions, 6 deletions
diff --git a/utils/hwstub/tools/lua/stmp/i2c.lua b/utils/hwstub/tools/lua/stmp/i2c.lua
index 54d860e0df..209f1df4e2 100644
--- a/utils/hwstub/tools/lua/stmp/i2c.lua
+++ b/utils/hwstub/tools/lua/stmp/i2c.lua
@@ -8,10 +8,7 @@ h:add("The STMP.clkctrl table handles the i2c device for all STMPs.")
8 8
9function STMP.i2c.init() 9function STMP.i2c.init()
10 HW.I2C.CTRL0.SFTRST.set() 10 HW.I2C.CTRL0.SFTRST.set()
11 STMP.pinctrl.pin(0, 30).muxsel("MAIN") 11 STMP.pinctrl.i2c.setup()
12 STMP.pinctrl.pin(0, 30).pull(true)
13 STMP.pinctrl.pin(0, 31).muxsel("MAIN")
14 STMP.pinctrl.pin(0, 31).pull(true)
15 STMP.i2c.reset() 12 STMP.i2c.reset()
16 STMP.i2c.set_speed(true) 13 STMP.i2c.set_speed(true)
17end 14end
@@ -21,7 +18,9 @@ function STMP.i2c.reset()
21 HW.I2C.CTRL0.SFTRST.clr() 18 HW.I2C.CTRL0.SFTRST.clr()
22 HW.I2C.CTRL0.CLKGATE.clr() 19 HW.I2C.CTRL0.CLKGATE.clr()
23 -- errata for IMX233 20 -- errata for IMX233
24 HW.I2C.CTRL1.ACK_MODE.set(); 21 if STMP.is_imx233() then
22 HW.I2C.CTRL1.ACK_MODE.set();
23 end
25end 24end
26 25
27function STMP.i2c.set_speed(fast) 26function STMP.i2c.set_speed(fast)
@@ -63,7 +62,9 @@ function STMP.i2c.transmit(slave_addr, buffer, send_stop)
63 while HW.I2C.CTRL0.RUN.read() == 1 do 62 while HW.I2C.CTRL0.RUN.read() == 1 do
64 end 63 end
65 if HW.I2C.CTRL1.NO_SLAVE_ACK_IRQ.read() == 1 then 64 if HW.I2C.CTRL1.NO_SLAVE_ACK_IRQ.read() == 1 then
66 HW.I2C.CTRL1.CLR_GOT_A_NAK.set() 65 if STMP.is_imx233() then
66 HW.I2C.CTRL1.CLR_GOT_A_NAK.set()
67 end
67 STMP.i2c.reset() 68 STMP.i2c.reset()
68 return false 69 return false
69 end 70 end
diff --git a/utils/hwstub/tools/lua/stmp/pinctrl.lua b/utils/hwstub/tools/lua/stmp/pinctrl.lua
index 5346c75b35..013b29701e 100644
--- a/utils/hwstub/tools/lua/stmp/pinctrl.lua
+++ b/utils/hwstub/tools/lua/stmp/pinctrl.lua
@@ -86,6 +86,7 @@ hh:add("* pin: pin number (mandatory) ")
86hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") 86hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)")
87hh:add("* enable: enable/disable output (optional)") 87hh:add("* enable: enable/disable output (optional)")
88hh:add("* output: set/clear output (optional)") 88hh:add("* output: set/clear output (optional)")
89hh:add("* pull: enable/disable pullup (optional)")
89hh:add("All non-subtable entries are ignored") 90hh:add("All non-subtable entries are ignored")
90hh:add("All unknown parameters in subtablkes are ignored") 91hh:add("All unknown parameters in subtablkes are ignored")
91hh:add("") 92hh:add("")
@@ -112,6 +113,10 @@ function STMP.pinctrl.configure(tbl)
112 if v.output then pin.set() 113 if v.output then pin.set()
113 else pin.clr() end 114 else pin.clr() end
114 end 115 end
116 if v.pull ~= nil then
117 STMP.debug(string.format("cfg B%dP%02d pull %s", v.bank, v.pin, v.pull))
118 pin.pull(v.pull)
119 end
115 end 120 end
116 end 121 end
117 end 122 end
@@ -291,3 +296,32 @@ function STMP.pinctrl.lcdif.setup_system(bus_width, busy)
291 STMP.pinctrl.configure_ex(busy_pin) 296 STMP.pinctrl.configure_ex(busy_pin)
292 end 297 end
293end 298end
299
300STMP.pinctrl.i2c = {}
301
302local hhh = hh:create_topic("setup")
303hhh:add("The STMP.pinctrl.i2c.setup() functions configure the I2C pins.")
304
305function STMP.pinctrl.i2c.setup()
306 local pins =
307 {
308 stmp3700 =
309 {
310 all =
311 {
312 i2c_scl = { bank = 2, pin = 5, muxsel = "MAIN", pull = true},
313 i2c_sda = { bank = 2, pin = 6, muxsel = "MAIN", pull = true}
314 }
315 },
316 imx233 =
317 {
318 all =
319 {
320 i2c_scl = { bank = 0, pin = 30, muxsel = "MAIN", pull = true},
321 i2c_sda = { bank = 0, pin = 31, muxsel = "MAIN", pull = true}
322 }
323 }
324 }
325
326 STMP.pinctrl.configure_ex(pins)
327end