From f9cb5de58020936812653c578c79c79a13bc626c Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Thu, 13 Jun 2013 02:12:01 +0200 Subject: hwstub: introduce lua code for the STMP and Creative ZEN V/Mozaic Change-Id: Ice5f509a2e0d2114436d4760f338b9203ef96691 --- utils/hwstub/tools/lua/stmp/digctl.lua | 38 +++++ utils/hwstub/tools/lua/stmp/lcdif.lua | 100 +++++++++++++ utils/hwstub/tools/lua/stmp/pinctrl.lua | 253 ++++++++++++++++++++++++++++++++ utils/hwstub/tools/lua/stmp/pwm.lua | 35 +++++ 4 files changed, 426 insertions(+) create mode 100644 utils/hwstub/tools/lua/stmp/digctl.lua create mode 100644 utils/hwstub/tools/lua/stmp/lcdif.lua create mode 100644 utils/hwstub/tools/lua/stmp/pinctrl.lua create mode 100644 utils/hwstub/tools/lua/stmp/pwm.lua (limited to 'utils/hwstub/tools/lua/stmp') diff --git a/utils/hwstub/tools/lua/stmp/digctl.lua b/utils/hwstub/tools/lua/stmp/digctl.lua new file mode 100644 index 0000000000..8dfc13b7f2 --- /dev/null +++ b/utils/hwstub/tools/lua/stmp/digctl.lua @@ -0,0 +1,38 @@ +--- +--- DIGCTL +--- +STMP.digctl = {} + +local h = HELP:get_topic("STMP"):create_topic("digctl") +h:add("The STMP.digctl table handles the digctl device for all STMPs.") + +local hh = h:create_topic("package") +hh:add("The STMP.digctl.package() function returns the name of the package.") +hh:add("The following packages can be returned:") +hh:add("* bga100") +hh:add("* bga169") +hh:add("* tqfp100") +hh:add("* lqfp100") +hh:add("* lqfp128") + +function STMP.digctl.package() + local pack = nil + if STMP.is_stmp3600() then + HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.set() + if HW.DIGCTL.STATUS.PACKAGE_TYPE.read() == 1 then + pack = "lqfp100" + else + pack = "bga169" + end + HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.clr() + elseif STMP.is_stmp3700() or STMP.is_stmp3770() or STMP.is_imx233() then + local t = HW.DIGCTL.STATUS.PACKAGE_TYPE.read() + if t == 0 then pack = "bga169" + elseif t == 1 then pack = "bga100" + elseif t == 2 then pack = "tqfp100" + elseif t == 3 then pack = "tqfp128" + end + end + + return pack +end \ No newline at end of file diff --git a/utils/hwstub/tools/lua/stmp/lcdif.lua b/utils/hwstub/tools/lua/stmp/lcdif.lua new file mode 100644 index 0000000000..0878cb1139 --- /dev/null +++ b/utils/hwstub/tools/lua/stmp/lcdif.lua @@ -0,0 +1,100 @@ +-- +-- LCDIF +-- + +STMP.lcdif = {} + +function STMP.lcdif.init() + HW.LCDIF.CTRL.SFTRST.set() + HW.LCDIF.CTRL.SFTRST.clr() + HW.LCDIF.CTRL.CLKGATE.clr() +end + +function STMP.lcdif.set_system_timing(data_setup, data_hold, cmd_setup, cmd_hold) + HW.LCDIF.TIMING.CMD_HOLD.write(cmd_hold) + HW.LCDIF.TIMING.CMD_SETUP.write(cmd_setup) + HW.LCDIF.TIMING.DATA_HOLD.write(data_hold) + HW.LCDIF.TIMING.DATA_SETUP.write(data_setup) +end + +function STMP.lcdif.set_byte_packing_format(val) + HW.LCDIF.CTRL1.BYTE_PACKING_FORMAT.write(val) +end + +function STMP.lcdif.set_reset(val) + if STMP.is_stmp3600() then + HW.LCDIF.CTRL.RESET.write(val) + else + HW.LCDIF.CTRL1.RESET.write(val) + end +end + +function STMP.lcdif.set_word_length(bus_width) + if STMP.is_stmp3600() or STMP.is_stmp3700() then + if bus_width == 8 then + HW.LCDIF.CTRL.WORD_LENGTH.set() + else + HW.LCDIF.CTRL.WORD_LENGTH.clr() + end + else + error("STMP.lcdif.set_word_length: unimplemented") + end +end + +function STMP.lcdif.get_word_length() + if STMP.is_stmp3600() or STMP.is_stmp3700() then + if HW.LCDIF.CTRL.WORD_LENGTH.read() == 1 then + return 8 + else + return 16 + end + else + error("STMP.lcdif.get_word_length: unimplemented") + end +end + +function STMP.lcdif.set_data_swizzle(swizzle) + local v = swizzle + if type(swizzle) == "string" then + if swizzle == "NONE" then + v = 0 + else + error("unimplemented") + end + end + HW.LCDIF.CTRL.DATA_SWIZZLE.write(v) +end + +function STMP.lcdif.is_busy() + if STMP.is_stmp3600() then + return HW.LCDIF.CTRL.FIFO_STATUS.read() == 0 + else + return HW.LCDIF.STAT.TXFIFO_FULL.read() == 1 + end +end + +function STMP.lcdif.send_pio(data_mode, data) + local wl = STMP.lcdif.get_word_length() + if data_mode then + HW.LCDIF.CTRL.DATA_SELECT.set() + else + HW.LCDIF.CTRL.DATA_SELECT.clr() + end + STMP.debug(string.format("lcdif: count = %d", #data)) + HW.LCDIF.CTRL.RUN.clr() + HW.LCDIF.CTRL.COUNT.write(#data) + HW.LCDIF.CTRL.RUN.set() + local i = 1 + while i <= #data do + local v = 0 + local v_size = 0 + while i <= #data and v_size + wl <= 32 do + v = bit32.bor(v, bit32.lshift(data[i], v_size)) + v_size = v_size + wl + i = i + 1 + end + STMP.debug(string.format("lcdif: i=%d send 0x%x", i, v)) + while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end + HW.LCDIF.DATA.write(v) + end +end \ No newline at end of file diff --git a/utils/hwstub/tools/lua/stmp/pinctrl.lua b/utils/hwstub/tools/lua/stmp/pinctrl.lua new file mode 100644 index 0000000000..2676f6476b --- /dev/null +++ b/utils/hwstub/tools/lua/stmp/pinctrl.lua @@ -0,0 +1,253 @@ +--- +--- PINCTRL +--- +STMP.pinctrl = {} + +local h = HELP:get_topic("STMP"):create_topic("pinctrl") +h:add("The STMP.pinctrl table handles the pinctrl device for all STMPs.") +h:add("It provides a simple abstraction to set individual pins.") + +local hh = h:create_topic("pin") +hh:add("The STMP.pinctrl.pin(x,yy) function returns a table for the pin BxPyy.") +hh:add("Depending on the STMP family, the following function might be available.") +hh:add("* read() returns the value of the pin (the pin does not need to be configured as GPIO)") +hh:add("* write(x) sets the value of the pin (provided it is a GPIO with output enabled)") +hh:add("* set() is equivalent to write(1)") +hh:add("* clr() is equivalent to write(0)") +hh:add("* enable() enables the gpio output (provided it is configured as GPIO).") +hh:add("* disable() disables the gpio output (provided it is configured as GPIO)") +hh:add("* muxsel(x) set pin function to x, which can be an integer or one of: MAIN, ALT1, ALT2, GPIO") + +function STMP.pinctrl.pin(bank,pin) + local t = { + read = function() + return bit32.extract(HW.PINCTRL.DINn[bank].read(), pin) + end, + + write = function(val) + if val then t.set() else t.clr() end + end, + + set = function() + HW.PINCTRL.DOUTn[bank].set(bit32.lshift(1, pin)) + end, + + clr = function() + HW.PINCTRL.DOUTn[bank].clr(bit32.lshift(1, pin)) + end, + + enable = function() + HW.PINCTRL.DOEn[bank].set(bit32.lshift(1, pin)) + end, + + disable = function() + HW.PINCTRL.DOEn[bank].clr(bit32.lshift(1, pin)) + end, + + muxsel = function(x) + if type(x) == "string" then + if x == "MAIN" then x = 0 + elseif x == "ALT1" then x = 1 + elseif x == "ALT2" then x = 2 + elseif x == "GPIO" then x = 3 + else error("Invalid muxsel string " .. x) end + end + local v = nil + if STMP.is_stmp3600() then + if pin < 16 then + v = HW.PINCTRL.MUXSELLn[bank] + else + v = HW.PINCTRL.MUXSELHn[bank] + end + else + v = HW.PINCTRL.MUXSELn[2 * bank + math.floor(pin / 16)] + end + v.write(bit32.replace(v.read(), x, (pin % 16) * 2, 2)) + end + } + return t +end + +hh = h:create_topic("configure") +hh:add("The STMP.pinctrl.configure(tbl) function configures pins according to a table.") +hh:add("The table must contain a list of subtable, each corresponding to a pin.") +hh:add("Each subtable can configure one or more aspects of a specific pin.") +hh:add("The following characteristics are understood:") +hh:add("* bank: pin bank (mandatory)") +hh:add("* pin: pin number (mandatory) ") +hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)") +hh:add("* enable: enable/disable output (optional)") +hh:add("* output: set/clear output (optional)") +hh:add("All non-subtable entries are ignored") +hh:add("All unknown parameters in subtablkes are ignored") +hh:add("") +hh:add("Example:") +hh:add("STMP.pinctrl.configure({{bank=0,pin=1,muxsel=\"GPIO\",enable=false},{bank=0,pin=2,muxsel=\"MAIN\"}})") + +function STMP.pinctrl.configure(tbl) + if type(tbl) ~= "table" then error("Parameter must be a table") end + for i,v in pairs(tbl) do + if type(v) == "table" then + if v.bank ~= nil and v.pin ~= nil then + local pin = STMP.pinctrl.pin(v.bank,v.pin) + if v.muxsel ~= nil then + STMP.debug(string.format("cfg B%dP%02d muxsel %s", v.bank, v.pin, v.muxsel)) + pin.muxsel(v.muxsel) + end + if v.enable ~= nil then + STMP.debug(string.format("cfg B%dP%02d enable %s", v.bank, v.pin, v.enable)) + if v.enable then pin.enable() + else pin.disable() end + end + if v.output ~= nil then + STMP.debug(string.format("cfg B%dP%02d output %s", v.bank, v.pin, v.output)) + if v.output then pin.set() + else pin.clr() end + end + end + end + end +end + +hh = h:create_topic("configure_ex") +hh:add("The STMP.pinctrl.configure_ex(tbl) function configures pins according to a table.") +hh:add("It is an enhanced version of configure which handles the different families and packages.") +hh:add("The argument must be a table with one entry per STMP family.") +hh:add("Each entry must a subtable with one subentry per package.") +hh:add("Each subentry must be a valid argument to STMP.pinctrl.configure().") +hh:add("The family names are the one returned by STMP.family.") +hh:add("The table can also contain an entry \"all\" which apply to all families") +hh:add("The package names are the one returned by STMP.digctl.package().") +hh:add("The table can also contain an entry \"all\" which apply to all packages.") + +function STMP.pinctrl.configure_ex(tbl) + if type(tbl) ~= "table" then error("Parameter must be a table") end + local pack = STMP.digctl.package() + if tbl[STMP.family] ~= nil then + if tbl[STMP.family][pack] ~= nil then STMP.pinctrl.configure(tbl[STMP.family][pack]) end + if tbl[STMP.family]["all"] ~= nil then STMP.pinctrl.configure(tbl[STMP.family]["all"]) end + end + if tbl["all"] ~= nil then + if tbl["all"][pack] ~= nil then STMP.pinctrl.configure(tbl["all"][pack]) end + if tbl["all"]["all"] ~= nil then STMP.pinctrl.configure(tbl["all"]["all"]) end + end +end + +hh = h:create_topic("lcdif") +hh:add("The STMP.pinctrl.lcdif tables provides some high level routines to configure the pins.") +hh:add("It is specialised to configure the LCDIF pins correctly.") +hh:add("Some of the modes may not be available on all STMP families.") + +STMP.pinctrl.lcdif = {} + +local hhh = hh:create_topic("setup_system") +hhh:add("The STMP.pinctrl.lcdif.setup_system(bus_width,busy) functions configure the LCDIF pins.") +hhh:add("It only take cares of the pins used in system mode and for a specified bus width.") +hhh:add("The handled bus widths are 8, 16 and 18") +hhh:add("The busy pin is configured only if busy is true") + +function STMP.pinctrl.lcdif.setup_system(bus_width, busy) + local common = + { + stmp3600 = + { + all = + { + lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"}, + lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"}, + lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"}, + lcd_cs = { bank = 1, pin = 19, muxsel = "MAIN"}, + lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"}, + lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"}, + lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"}, + lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"}, + lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"}, + lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"}, + lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"}, + lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"} + } + }, + stmp3700 = + { + all = + { + lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"}, + lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"}, + lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"}, + lcd_rd = { bank = 1, pin = 19, muxsel = "MAIN"}, + lcd_cs = { bank = 1, pin = 20, muxsel = "MAIN"}, + lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"}, + lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"}, + lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"}, + lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"}, + lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"}, + lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"}, + lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"}, + lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"} + } + } + } + local bus8_15 = + { + stmp3600 = + { + all = + { + lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"}, + lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"}, + lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"}, + lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"}, + lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"}, + lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"}, + lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"}, + lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"} + } + }, + stmp3700 = + { + all = + { + lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"}, + lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"}, + lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"}, + lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"}, + lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"}, + lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"}, + lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"}, + lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"} + } + } + } + local bus16_17 = + { + + } + local busy_pin = + { + stmp3600 = + { + all = + { + lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"}, + } + }, + stmp3700 = + { + all = + { + lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"}, + } + }, + } + + STMP.pinctrl.configure_ex(common) + if bus_width > 8 then + STMP.pinctrl.configure_ex(bus8_15) + end + if bus_width > 16 then + STMP.pinctrl.configure_ex(bus16_17) + end + if busy then + STMP.pinctrl.configure_ex(busy_pin) + end +end diff --git a/utils/hwstub/tools/lua/stmp/pwm.lua b/utils/hwstub/tools/lua/stmp/pwm.lua new file mode 100644 index 0000000000..8b078af5a7 --- /dev/null +++ b/utils/hwstub/tools/lua/stmp/pwm.lua @@ -0,0 +1,35 @@ +-- +-- LCDIF +-- + +STMP.pwm = {} + +function STMP.pwm.init() + HW.LCDIF.CTRL.SFTRST.clr() + HW.LCDIF.CTRL.CLKGATE.clr() +end + +function STMP.pwm.enable(chan, en) + if en then + HW.PWM.CTRL.set(bit32.lshift(1, chan)) + else + HW.PWM.CTRL.clr(bit32.lshift(1, chan)) + end +end + +function STMP.pwm.setup(channel, period, cdiv, active, active_state, inactive, inactive_state) + -- stop + STMP.pwm.enable(channel, false) + -- setup pin + --FIXME + -- watch the order ! active THEN period + -- NOTE: the register value is period-1 + HW.PWM.ACTIVEn[channel].ACTIVE.write(active) + HW.PWM.ACTIVEn[channel].INACTIVE.write(inactive) + HW.PWM.PERIODn[channel].PERIOD.write(period - 1) + HW.PWM.PERIODn[channel].ACTIVE_STATE.write(active_state) + HW.PWM.PERIODn[channel].INACTIVE_STATE.write(inactive_state) + HW.PWM.PERIODn[channel].CDIV.write(cdiv) + -- restore + STMP.pwm.enable(channel, true) +end \ No newline at end of file -- cgit v1.2.3