summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/stmp
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:12:01 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:25:15 +0200
commitf9cb5de58020936812653c578c79c79a13bc626c (patch)
treed1d6c29207472bea4daa68d2fffd7e8dbfac998b /utils/hwstub/tools/lua/stmp
parentc5357940ab0108b4102442d07825c44d5be0d22f (diff)
downloadrockbox-f9cb5de58020936812653c578c79c79a13bc626c.tar.gz
rockbox-f9cb5de58020936812653c578c79c79a13bc626c.zip
hwstub: introduce lua code for the STMP and Creative ZEN V/Mozaic
Change-Id: Ice5f509a2e0d2114436d4760f338b9203ef96691
Diffstat (limited to 'utils/hwstub/tools/lua/stmp')
-rw-r--r--utils/hwstub/tools/lua/stmp/digctl.lua38
-rw-r--r--utils/hwstub/tools/lua/stmp/lcdif.lua100
-rw-r--r--utils/hwstub/tools/lua/stmp/pinctrl.lua253
-rw-r--r--utils/hwstub/tools/lua/stmp/pwm.lua35
4 files changed, 426 insertions, 0 deletions
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 @@
1---
2--- DIGCTL
3---
4STMP.digctl = {}
5
6local h = HELP:get_topic("STMP"):create_topic("digctl")
7h:add("The STMP.digctl table handles the digctl device for all STMPs.")
8
9local hh = h:create_topic("package")
10hh:add("The STMP.digctl.package() function returns the name of the package.")
11hh:add("The following packages can be returned:")
12hh:add("* bga100")
13hh:add("* bga169")
14hh:add("* tqfp100")
15hh:add("* lqfp100")
16hh:add("* lqfp128")
17
18function STMP.digctl.package()
19 local pack = nil
20 if STMP.is_stmp3600() then
21 HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.set()
22 if HW.DIGCTL.STATUS.PACKAGE_TYPE.read() == 1 then
23 pack = "lqfp100"
24 else
25 pack = "bga169"
26 end
27 HW.DIGCTL.CTRL.PACKAGE_SENSE_ENABLE.clr()
28 elseif STMP.is_stmp3700() or STMP.is_stmp3770() or STMP.is_imx233() then
29 local t = HW.DIGCTL.STATUS.PACKAGE_TYPE.read()
30 if t == 0 then pack = "bga169"
31 elseif t == 1 then pack = "bga100"
32 elseif t == 2 then pack = "tqfp100"
33 elseif t == 3 then pack = "tqfp128"
34 end
35 end
36
37 return pack
38end \ 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 @@
1--
2-- LCDIF
3--
4
5STMP.lcdif = {}
6
7function STMP.lcdif.init()
8 HW.LCDIF.CTRL.SFTRST.set()
9 HW.LCDIF.CTRL.SFTRST.clr()
10 HW.LCDIF.CTRL.CLKGATE.clr()
11end
12
13function STMP.lcdif.set_system_timing(data_setup, data_hold, cmd_setup, cmd_hold)
14 HW.LCDIF.TIMING.CMD_HOLD.write(cmd_hold)
15 HW.LCDIF.TIMING.CMD_SETUP.write(cmd_setup)
16 HW.LCDIF.TIMING.DATA_HOLD.write(data_hold)
17 HW.LCDIF.TIMING.DATA_SETUP.write(data_setup)
18end
19
20function STMP.lcdif.set_byte_packing_format(val)
21 HW.LCDIF.CTRL1.BYTE_PACKING_FORMAT.write(val)
22end
23
24function STMP.lcdif.set_reset(val)
25 if STMP.is_stmp3600() then
26 HW.LCDIF.CTRL.RESET.write(val)
27 else
28 HW.LCDIF.CTRL1.RESET.write(val)
29 end
30end
31
32function STMP.lcdif.set_word_length(bus_width)
33 if STMP.is_stmp3600() or STMP.is_stmp3700() then
34 if bus_width == 8 then
35 HW.LCDIF.CTRL.WORD_LENGTH.set()
36 else
37 HW.LCDIF.CTRL.WORD_LENGTH.clr()
38 end
39 else
40 error("STMP.lcdif.set_word_length: unimplemented")
41 end
42end
43
44function STMP.lcdif.get_word_length()
45 if STMP.is_stmp3600() or STMP.is_stmp3700() then
46 if HW.LCDIF.CTRL.WORD_LENGTH.read() == 1 then
47 return 8
48 else
49 return 16
50 end
51 else
52 error("STMP.lcdif.get_word_length: unimplemented")
53 end
54end
55
56function STMP.lcdif.set_data_swizzle(swizzle)
57 local v = swizzle
58 if type(swizzle) == "string" then
59 if swizzle == "NONE" then
60 v = 0
61 else
62 error("unimplemented")
63 end
64 end
65 HW.LCDIF.CTRL.DATA_SWIZZLE.write(v)
66end
67
68function STMP.lcdif.is_busy()
69 if STMP.is_stmp3600() then
70 return HW.LCDIF.CTRL.FIFO_STATUS.read() == 0
71 else
72 return HW.LCDIF.STAT.TXFIFO_FULL.read() == 1
73 end
74end
75
76function STMP.lcdif.send_pio(data_mode, data)
77 local wl = STMP.lcdif.get_word_length()
78 if data_mode then
79 HW.LCDIF.CTRL.DATA_SELECT.set()
80 else
81 HW.LCDIF.CTRL.DATA_SELECT.clr()
82 end
83 STMP.debug(string.format("lcdif: count = %d", #data))
84 HW.LCDIF.CTRL.RUN.clr()
85 HW.LCDIF.CTRL.COUNT.write(#data)
86 HW.LCDIF.CTRL.RUN.set()
87 local i = 1
88 while i <= #data do
89 local v = 0
90 local v_size = 0
91 while i <= #data and v_size + wl <= 32 do
92 v = bit32.bor(v, bit32.lshift(data[i], v_size))
93 v_size = v_size + wl
94 i = i + 1
95 end
96 STMP.debug(string.format("lcdif: i=%d send 0x%x", i, v))
97 while STMP.lcdif.is_busy() do STMP.debug("lcdif: fifo full") end
98 HW.LCDIF.DATA.write(v)
99 end
100end \ 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 @@
1---
2--- PINCTRL
3---
4STMP.pinctrl = {}
5
6local h = HELP:get_topic("STMP"):create_topic("pinctrl")
7h:add("The STMP.pinctrl table handles the pinctrl device for all STMPs.")
8h:add("It provides a simple abstraction to set individual pins.")
9
10local hh = h:create_topic("pin")
11hh:add("The STMP.pinctrl.pin(x,yy) function returns a table for the pin BxPyy.")
12hh:add("Depending on the STMP family, the following function might be available.")
13hh:add("* read() returns the value of the pin (the pin does not need to be configured as GPIO)")
14hh:add("* write(x) sets the value of the pin (provided it is a GPIO with output enabled)")
15hh:add("* set() is equivalent to write(1)")
16hh:add("* clr() is equivalent to write(0)")
17hh:add("* enable() enables the gpio output (provided it is configured as GPIO).")
18hh:add("* disable() disables the gpio output (provided it is configured as GPIO)")
19hh:add("* muxsel(x) set pin function to x, which can be an integer or one of: MAIN, ALT1, ALT2, GPIO")
20
21function STMP.pinctrl.pin(bank,pin)
22 local t = {
23 read = function()
24 return bit32.extract(HW.PINCTRL.DINn[bank].read(), pin)
25 end,
26
27 write = function(val)
28 if val then t.set() else t.clr() end
29 end,
30
31 set = function()
32 HW.PINCTRL.DOUTn[bank].set(bit32.lshift(1, pin))
33 end,
34
35 clr = function()
36 HW.PINCTRL.DOUTn[bank].clr(bit32.lshift(1, pin))
37 end,
38
39 enable = function()
40 HW.PINCTRL.DOEn[bank].set(bit32.lshift(1, pin))
41 end,
42
43 disable = function()
44 HW.PINCTRL.DOEn[bank].clr(bit32.lshift(1, pin))
45 end,
46
47 muxsel = function(x)
48 if type(x) == "string" then
49 if x == "MAIN" then x = 0
50 elseif x == "ALT1" then x = 1
51 elseif x == "ALT2" then x = 2
52 elseif x == "GPIO" then x = 3
53 else error("Invalid muxsel string " .. x) end
54 end
55 local v = nil
56 if STMP.is_stmp3600() then
57 if pin < 16 then
58 v = HW.PINCTRL.MUXSELLn[bank]
59 else
60 v = HW.PINCTRL.MUXSELHn[bank]
61 end
62 else
63 v = HW.PINCTRL.MUXSELn[2 * bank + math.floor(pin / 16)]
64 end
65 v.write(bit32.replace(v.read(), x, (pin % 16) * 2, 2))
66 end
67 }
68 return t
69end
70
71hh = h:create_topic("configure")
72hh:add("The STMP.pinctrl.configure(tbl) function configures pins according to a table.")
73hh:add("The table must contain a list of subtable, each corresponding to a pin.")
74hh:add("Each subtable can configure one or more aspects of a specific pin.")
75hh:add("The following characteristics are understood:")
76hh:add("* bank: pin bank (mandatory)")
77hh:add("* pin: pin number (mandatory) ")
78hh:add("* muxsel: same values as STMP.pinctrl.pin().muxsel (optional)")
79hh:add("* enable: enable/disable output (optional)")
80hh:add("* output: set/clear output (optional)")
81hh:add("All non-subtable entries are ignored")
82hh:add("All unknown parameters in subtablkes are ignored")
83hh:add("")
84hh:add("Example:")
85hh:add("STMP.pinctrl.configure({{bank=0,pin=1,muxsel=\"GPIO\",enable=false},{bank=0,pin=2,muxsel=\"MAIN\"}})")
86
87function STMP.pinctrl.configure(tbl)
88 if type(tbl) ~= "table" then error("Parameter must be a table") end
89 for i,v in pairs(tbl) do
90 if type(v) == "table" then
91 if v.bank ~= nil and v.pin ~= nil then
92 local pin = STMP.pinctrl.pin(v.bank,v.pin)
93 if v.muxsel ~= nil then
94 STMP.debug(string.format("cfg B%dP%02d muxsel %s", v.bank, v.pin, v.muxsel))
95 pin.muxsel(v.muxsel)
96 end
97 if v.enable ~= nil then
98 STMP.debug(string.format("cfg B%dP%02d enable %s", v.bank, v.pin, v.enable))
99 if v.enable then pin.enable()
100 else pin.disable() end
101 end
102 if v.output ~= nil then
103 STMP.debug(string.format("cfg B%dP%02d output %s", v.bank, v.pin, v.output))
104 if v.output then pin.set()
105 else pin.clr() end
106 end
107 end
108 end
109 end
110end
111
112hh = h:create_topic("configure_ex")
113hh:add("The STMP.pinctrl.configure_ex(tbl) function configures pins according to a table.")
114hh:add("It is an enhanced version of configure which handles the different families and packages.")
115hh:add("The argument must be a table with one entry per STMP family.")
116hh:add("Each entry must a subtable with one subentry per package.")
117hh:add("Each subentry must be a valid argument to STMP.pinctrl.configure().")
118hh:add("The family names are the one returned by STMP.family.")
119hh:add("The table can also contain an entry \"all\" which apply to all families")
120hh:add("The package names are the one returned by STMP.digctl.package().")
121hh:add("The table can also contain an entry \"all\" which apply to all packages.")
122
123function STMP.pinctrl.configure_ex(tbl)
124 if type(tbl) ~= "table" then error("Parameter must be a table") end
125 local pack = STMP.digctl.package()
126 if tbl[STMP.family] ~= nil then
127 if tbl[STMP.family][pack] ~= nil then STMP.pinctrl.configure(tbl[STMP.family][pack]) end
128 if tbl[STMP.family]["all"] ~= nil then STMP.pinctrl.configure(tbl[STMP.family]["all"]) end
129 end
130 if tbl["all"] ~= nil then
131 if tbl["all"][pack] ~= nil then STMP.pinctrl.configure(tbl["all"][pack]) end
132 if tbl["all"]["all"] ~= nil then STMP.pinctrl.configure(tbl["all"]["all"]) end
133 end
134end
135
136hh = h:create_topic("lcdif")
137hh:add("The STMP.pinctrl.lcdif tables provides some high level routines to configure the pins.")
138hh:add("It is specialised to configure the LCDIF pins correctly.")
139hh:add("Some of the modes may not be available on all STMP families.")
140
141STMP.pinctrl.lcdif = {}
142
143local hhh = hh:create_topic("setup_system")
144hhh:add("The STMP.pinctrl.lcdif.setup_system(bus_width,busy) functions configure the LCDIF pins.")
145hhh:add("It only take cares of the pins used in system mode and for a specified bus width.")
146hhh:add("The handled bus widths are 8, 16 and 18")
147hhh:add("The busy pin is configured only if busy is true")
148
149function STMP.pinctrl.lcdif.setup_system(bus_width, busy)
150 local common =
151 {
152 stmp3600 =
153 {
154 all =
155 {
156 lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"},
157 lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"},
158 lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"},
159 lcd_cs = { bank = 1, pin = 19, muxsel = "MAIN"},
160 lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"},
161 lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"},
162 lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"},
163 lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"},
164 lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"},
165 lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"},
166 lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"},
167 lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"}
168 }
169 },
170 stmp3700 =
171 {
172 all =
173 {
174 lcd_reset = { bank = 1, pin = 16, muxsel = "MAIN"},
175 lcd_rs = { bank = 1, pin = 17, muxsel = "MAIN"},
176 lcd_wr = { bank = 1, pin = 18, muxsel = "MAIN"},
177 lcd_rd = { bank = 1, pin = 19, muxsel = "MAIN"},
178 lcd_cs = { bank = 1, pin = 20, muxsel = "MAIN"},
179 lcd_d0 = {bank = 1, pin = 0, muxsel = "MAIN"},
180 lcd_d1 = {bank = 1, pin = 1, muxsel = "MAIN"},
181 lcd_d2 = {bank = 1, pin = 2, muxsel = "MAIN"},
182 lcd_d3 = {bank = 1, pin = 3, muxsel = "MAIN"},
183 lcd_d4 = {bank = 1, pin = 4, muxsel = "MAIN"},
184 lcd_d5 = {bank = 1, pin = 5, muxsel = "MAIN"},
185 lcd_d6 = {bank = 1, pin = 6, muxsel = "MAIN"},
186 lcd_d7 = {bank = 1, pin = 7, muxsel = "MAIN"}
187 }
188 }
189 }
190 local bus8_15 =
191 {
192 stmp3600 =
193 {
194 all =
195 {
196 lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"},
197 lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"},
198 lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"},
199 lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"},
200 lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"},
201 lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"},
202 lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"},
203 lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"}
204 }
205 },
206 stmp3700 =
207 {
208 all =
209 {
210 lcd_d8 = {bank = 1, pin = 8, muxsel = "MAIN"},
211 lcd_d9 = {bank = 1, pin = 9, muxsel = "MAIN"},
212 lcd_d10 = {bank = 1, pin = 10, muxsel = "MAIN"},
213 lcd_d11 = {bank = 1, pin = 11, muxsel = "MAIN"},
214 lcd_d12 = {bank = 1, pin = 12, muxsel = "MAIN"},
215 lcd_d13 = {bank = 1, pin = 13, muxsel = "MAIN"},
216 lcd_d14 = {bank = 1, pin = 14, muxsel = "MAIN"},
217 lcd_d15 = {bank = 1, pin = 15, muxsel = "MAIN"}
218 }
219 }
220 }
221 local bus16_17 =
222 {
223
224 }
225 local busy_pin =
226 {
227 stmp3600 =
228 {
229 all =
230 {
231 lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"},
232 }
233 },
234 stmp3700 =
235 {
236 all =
237 {
238 lcd_busy = { bank = 1, pin = 21, muxsel = "MAIN"},
239 }
240 },
241 }
242
243 STMP.pinctrl.configure_ex(common)
244 if bus_width > 8 then
245 STMP.pinctrl.configure_ex(bus8_15)
246 end
247 if bus_width > 16 then
248 STMP.pinctrl.configure_ex(bus16_17)
249 end
250 if busy then
251 STMP.pinctrl.configure_ex(busy_pin)
252 end
253end
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 @@
1--
2-- LCDIF
3--
4
5STMP.pwm = {}
6
7function STMP.pwm.init()
8 HW.LCDIF.CTRL.SFTRST.clr()
9 HW.LCDIF.CTRL.CLKGATE.clr()
10end
11
12function STMP.pwm.enable(chan, en)
13 if en then
14 HW.PWM.CTRL.set(bit32.lshift(1, chan))
15 else
16 HW.PWM.CTRL.clr(bit32.lshift(1, chan))
17 end
18end
19
20function STMP.pwm.setup(channel, period, cdiv, active, active_state, inactive, inactive_state)
21 -- stop
22 STMP.pwm.enable(channel, false)
23 -- setup pin
24 --FIXME
25 -- watch the order ! active THEN period
26 -- NOTE: the register value is period-1
27 HW.PWM.ACTIVEn[channel].ACTIVE.write(active)
28 HW.PWM.ACTIVEn[channel].INACTIVE.write(inactive)
29 HW.PWM.PERIODn[channel].PERIOD.write(period - 1)
30 HW.PWM.PERIODn[channel].ACTIVE_STATE.write(active_state)
31 HW.PWM.PERIODn[channel].INACTIVE_STATE.write(inactive_state)
32 HW.PWM.PERIODn[channel].CDIV.write(cdiv)
33 -- restore
34 STMP.pwm.enable(channel, true)
35end \ No newline at end of file