diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-10-22 00:24:32 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-10-22 00:34:44 +0200 |
commit | 9ed980785429db35f51f8d324cc75c23f2e5fb20 (patch) | |
tree | aa5362c4eea139c22b606b685e2ab29a19908d0d | |
parent | bfb67f41a9e9df3b730d34041be6b4f4a4983c5b (diff) | |
download | rockbox-9ed980785429db35f51f8d324cc75c23f2e5fb20.tar.gz rockbox-9ed980785429db35f51f8d324cc75c23f2e5fb20.zip |
hwstub: rework i2c completely
Change-Id: I1e5f87f15f0ca9586d8185316ffcaeef6d9d4d38
-rw-r--r-- | utils/hwstub/tools/lua/i2c_scan.lua | 11 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/sonynwze360.lua | 7 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/i2c.lua | 13 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/stmp/pinctrl.lua | 34 |
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 @@ | |||
1 | I2CSCAN = {} | ||
2 | |||
3 | function 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 | |||
150 | function NWZE360.init() | 150 | function 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 | ||
9 | function STMP.i2c.init() | 9 | function 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) |
17 | end | 14 | end |
@@ -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 | ||
25 | end | 24 | end |
26 | 25 | ||
27 | function STMP.i2c.set_speed(fast) | 26 | function 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) ") | |||
86 | hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") | 86 | hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") |
87 | hh:add("* enable: enable/disable output (optional)") | 87 | hh:add("* enable: enable/disable output (optional)") |
88 | hh:add("* output: set/clear output (optional)") | 88 | hh:add("* output: set/clear output (optional)") |
89 | hh:add("* pull: enable/disable pullup (optional)") | ||
89 | hh:add("All non-subtable entries are ignored") | 90 | hh:add("All non-subtable entries are ignored") |
90 | hh:add("All unknown parameters in subtablkes are ignored") | 91 | hh:add("All unknown parameters in subtablkes are ignored") |
91 | hh:add("") | 92 | hh: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 |
293 | end | 298 | end |
299 | |||
300 | STMP.pinctrl.i2c = {} | ||
301 | |||
302 | local hhh = hh:create_topic("setup") | ||
303 | hhh:add("The STMP.pinctrl.i2c.setup() functions configure the I2C pins.") | ||
304 | |||
305 | function 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) | ||
327 | end | ||