1
0
Fork 0
forked from len0rd/rockbox

hwstub: rework i2c completely

Change-Id: I1e5f87f15f0ca9586d8185316ffcaeef6d9d4d38
This commit is contained in:
Amaury Pouly 2013-10-22 00:24:32 +02:00
parent bfb67f41a9
commit 9ed9807854
4 changed files with 52 additions and 13 deletions

View file

@ -0,0 +1,11 @@
I2CSCAN = {}
function I2CSCAN.scan()
STMP.i2c.init()
STMP.i2c.set_speed(true)
for i = 2, 254, 2 do
if STMP.i2c.transmit(i, {}, true) then
print(string.format("%#x OK", i))
end
end
end

View file

@ -150,13 +150,6 @@ end
function NWZE360.init() function NWZE360.init()
NWZE360.lcd_init() NWZE360.lcd_init()
NWZE360.set_backlight(100) NWZE360.set_backlight(100)
STMP.i2c.init()
STMP.i2c.set_speed(true)
for i = 2, 254, 2 do
if STMP.i2c.transmit(i, {}, true) then
print(string.format("%#x OK", i))
end
end
--[[ --[[
HW.LRADC.CTRL0.SFTRST.clr() HW.LRADC.CTRL0.SFTRST.clr()
HW.LRADC.CTRL0.CLKGATE.clr() HW.LRADC.CTRL0.CLKGATE.clr()

View file

@ -8,10 +8,7 @@ h:add("The STMP.clkctrl table handles the i2c device for all STMPs.")
function STMP.i2c.init() function STMP.i2c.init()
HW.I2C.CTRL0.SFTRST.set() HW.I2C.CTRL0.SFTRST.set()
STMP.pinctrl.pin(0, 30).muxsel("MAIN") STMP.pinctrl.i2c.setup()
STMP.pinctrl.pin(0, 30).pull(true)
STMP.pinctrl.pin(0, 31).muxsel("MAIN")
STMP.pinctrl.pin(0, 31).pull(true)
STMP.i2c.reset() STMP.i2c.reset()
STMP.i2c.set_speed(true) STMP.i2c.set_speed(true)
end end
@ -21,7 +18,9 @@ function STMP.i2c.reset()
HW.I2C.CTRL0.SFTRST.clr() HW.I2C.CTRL0.SFTRST.clr()
HW.I2C.CTRL0.CLKGATE.clr() HW.I2C.CTRL0.CLKGATE.clr()
-- errata for IMX233 -- errata for IMX233
HW.I2C.CTRL1.ACK_MODE.set(); if STMP.is_imx233() then
HW.I2C.CTRL1.ACK_MODE.set();
end
end end
function STMP.i2c.set_speed(fast) function STMP.i2c.set_speed(fast)
@ -63,7 +62,9 @@ function STMP.i2c.transmit(slave_addr, buffer, send_stop)
while HW.I2C.CTRL0.RUN.read() == 1 do while HW.I2C.CTRL0.RUN.read() == 1 do
end end
if HW.I2C.CTRL1.NO_SLAVE_ACK_IRQ.read() == 1 then if HW.I2C.CTRL1.NO_SLAVE_ACK_IRQ.read() == 1 then
HW.I2C.CTRL1.CLR_GOT_A_NAK.set() if STMP.is_imx233() then
HW.I2C.CTRL1.CLR_GOT_A_NAK.set()
end
STMP.i2c.reset() STMP.i2c.reset()
return false return false
end end

View file

@ -86,6 +86,7 @@ hh:add("* pin: pin number (mandatory) ")
hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)")
hh:add("* enable: enable/disable output (optional)") hh:add("* enable: enable/disable output (optional)")
hh:add("* output: set/clear output (optional)") hh:add("* output: set/clear output (optional)")
hh:add("* pull: enable/disable pullup (optional)")
hh:add("All non-subtable entries are ignored") hh:add("All non-subtable entries are ignored")
hh:add("All unknown parameters in subtablkes are ignored") hh:add("All unknown parameters in subtablkes are ignored")
hh:add("") hh:add("")
@ -112,6 +113,10 @@ function STMP.pinctrl.configure(tbl)
if v.output then pin.set() if v.output then pin.set()
else pin.clr() end else pin.clr() end
end end
if v.pull ~= nil then
STMP.debug(string.format("cfg B%dP%02d pull %s", v.bank, v.pin, v.pull))
pin.pull(v.pull)
end
end end
end end
end end
@ -291,3 +296,32 @@ function STMP.pinctrl.lcdif.setup_system(bus_width, busy)
STMP.pinctrl.configure_ex(busy_pin) STMP.pinctrl.configure_ex(busy_pin)
end end
end end
STMP.pinctrl.i2c = {}
local hhh = hh:create_topic("setup")
hhh:add("The STMP.pinctrl.i2c.setup() functions configure the I2C pins.")
function STMP.pinctrl.i2c.setup()
local pins =
{
stmp3700 =
{
all =
{
i2c_scl = { bank = 2, pin = 5, muxsel = "MAIN", pull = true},
i2c_sda = { bank = 2, pin = 6, muxsel = "MAIN", pull = true}
}
},
imx233 =
{
all =
{
i2c_scl = { bank = 0, pin = 30, muxsel = "MAIN", pull = true},
i2c_sda = { bank = 0, pin = 31, muxsel = "MAIN", pull = true}
}
}
}
STMP.pinctrl.configure_ex(pins)
end