summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:24:32 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:34:44 +0200
commit9ed980785429db35f51f8d324cc75c23f2e5fb20 (patch)
treeaa5362c4eea139c22b606b685e2ab29a19908d0d
parentbfb67f41a9e9df3b730d34041be6b4f4a4983c5b (diff)
downloadrockbox-9ed980785429db35f51f8d324cc75c23f2e5fb20.tar.gz
rockbox-9ed980785429db35f51f8d324cc75c23f2e5fb20.zip
hwstub: rework i2c completely
Change-Id: I1e5f87f15f0ca9586d8185316ffcaeef6d9d4d38
-rw-r--r--utils/hwstub/tools/lua/i2c_scan.lua11
-rw-r--r--utils/hwstub/tools/lua/sonynwze360.lua7
-rw-r--r--utils/hwstub/tools/lua/stmp/i2c.lua13
-rw-r--r--utils/hwstub/tools/lua/stmp/pinctrl.lua34
4 files changed, 52 insertions, 13 deletions
diff --git a/utils/hwstub/tools/lua/i2c_scan.lua b/utils/hwstub/tools/lua/i2c_scan.lua
new file mode 100644
index 0000000000..def7b5d84c
--- /dev/null
+++ b/utils/hwstub/tools/lua/i2c_scan.lua
@@ -0,0 +1,11 @@
1I2CSCAN = {}
2
3function I2CSCAN.scan()
4 STMP.i2c.init()
5 STMP.i2c.set_speed(true)
6 for i = 2, 254, 2 do
7 if STMP.i2c.transmit(i, {}, true) then
8 print(string.format("%#x OK", i))
9 end
10 end
11 end \ No newline at end of file
diff --git a/utils/hwstub/tools/lua/sonynwze360.lua b/utils/hwstub/tools/lua/sonynwze360.lua
index 669e899f0d..4fabdfd27c 100644
--- a/utils/hwstub/tools/lua/sonynwze360.lua
+++ b/utils/hwstub/tools/lua/sonynwze360.lua
@@ -150,13 +150,6 @@ end
150function NWZE360.init() 150function NWZE360.init()
151 NWZE360.lcd_init() 151 NWZE360.lcd_init()
152 NWZE360.set_backlight(100) 152 NWZE360.set_backlight(100)
153 STMP.i2c.init()
154 STMP.i2c.set_speed(true)
155 for i = 2, 254, 2 do
156 if STMP.i2c.transmit(i, {}, true) then
157 print(string.format("%#x OK", i))
158 end
159 end
160 --[[ 153 --[[
161 HW.LRADC.CTRL0.SFTRST.clr() 154 HW.LRADC.CTRL0.SFTRST.clr()
162 HW.LRADC.CTRL0.CLKGATE.clr() 155 HW.LRADC.CTRL0.CLKGATE.clr()
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