diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2016-03-19 21:57:58 +0000 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-24 15:17:46 +0100 |
commit | 4fd9400458f131e61a18142105c2d2d3a082a057 (patch) | |
tree | 8c2802574edb52423d94a71e6caad6610dd90186 /utils/hwstub/tools/lua/fiiox1.lua | |
parent | 0b6cbd8e49eaf664cd005c6bb63a3111a4f4c308 (diff) | |
download | rockbox-4fd9400458f131e61a18142105c2d2d3a082a057.tar.gz rockbox-4fd9400458f131e61a18142105c2d2d3a082a057.zip |
hwstub/tools/shell: add JZ4760B and Fiio X1 code
The jz code can do several useful things like dumping the IPL and SPL.
The Fiio code can play with backlight and has code do dump the IPL
and SPL with the correct parameters (extracted by reverse engineering).
Change-Id: I317b3174f5db8d38c9a56670c1d45565142ec208
Diffstat (limited to 'utils/hwstub/tools/lua/fiiox1.lua')
-rw-r--r-- | utils/hwstub/tools/lua/fiiox1.lua | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/fiiox1.lua b/utils/hwstub/tools/lua/fiiox1.lua new file mode 100644 index 0000000000..c038f4077b --- /dev/null +++ b/utils/hwstub/tools/lua/fiiox1.lua | |||
@@ -0,0 +1,145 @@ | |||
1 | -- | ||
2 | -- Fiio X1 | ||
3 | -- | ||
4 | FIIOX1 = {} | ||
5 | |||
6 | -- 0 is PF3, 1 is PE1 | ||
7 | function FIIOX1.get_backlight_type() | ||
8 | return FIIOX1.bl_type | ||
9 | end | ||
10 | |||
11 | -- 0 is V2, 1 is V1 | ||
12 | function FIIOX1.get_hw_type() | ||
13 | return FIIOX1.hw_type | ||
14 | end | ||
15 | |||
16 | function FIIOX1.hw_detect() | ||
17 | -- PA12 is used to detect hardware version | ||
18 | JZ.gpio.pin(0, 12).std_gpio_out(1) | ||
19 | FIIOX1.hw_type = JZ.gpio.pin(0, 12).read() | ||
20 | -- PA13 is used to detect backlight type | ||
21 | JZ.gpio.pin(0, 13).std_gpio_out(1) | ||
22 | FIIOX1.bl_type = JZ.gpio.pin(0, 13).read() | ||
23 | |||
24 | if FIIOX1.hw_type == 1 then | ||
25 | print("Fiio X1: hardware version: V01") | ||
26 | else | ||
27 | print("Fiio X1: hardware version: V02") | ||
28 | end | ||
29 | print(string.format("Fiio X1: backlight type: %s", FIIOX1.bl_type)) | ||
30 | end | ||
31 | |||
32 | function FIIOX1.get_backlight_pin() | ||
33 | if FIIOX1.get_backlight_type() == 0 then | ||
34 | -- PF3 | ||
35 | return JZ.gpio.pin(5, 3) | ||
36 | else | ||
37 | -- PE1 | ||
38 | return JZ.gpio.pin(4, 1) | ||
39 | end | ||
40 | end | ||
41 | |||
42 | function FIIOX1.init_backligt() | ||
43 | -- setup as output, high level to make no change | ||
44 | FIIOX1.get_backlight_pin().std_gpio_out(1) | ||
45 | end | ||
46 | |||
47 | function FIIOX1.enable_backlight(en) | ||
48 | local pin = FIIOX1.get_backlight_pin() | ||
49 | pin.clr() | ||
50 | hwstub.mdelay(1) | ||
51 | if en then | ||
52 | pin.set() | ||
53 | end | ||
54 | end | ||
55 | |||
56 | function FIIOX1.test_backlight() | ||
57 | print("backlight test") | ||
58 | print("enable backlight") | ||
59 | FIIOX1.enable_backlight(true) | ||
60 | print("sleep for 1 sec") | ||
61 | hwstub.mdelay(1000) | ||
62 | print("disable backlight") | ||
63 | FIIOX1.enable_backlight(false) | ||
64 | print("sleep for 1 sec") | ||
65 | hwstub.mdelay(1000) | ||
66 | print("enable backlight") | ||
67 | FIIOX1.enable_backlight(true) | ||
68 | end | ||
69 | |||
70 | function FIIOX1.setup_fiio_lcd_pins() | ||
71 | -- PE4: reset pin | ||
72 | JZ.gpio.pin(4, 4).std_gpio_out(1) | ||
73 | -- PC9: unknown | ||
74 | JZ.gpio.pin(2, 9).std_gpio_out(0) | ||
75 | -- PC2: unknown | ||
76 | JZ.gpio.pin(2, 2).std_gpio_out(1) | ||
77 | -- PF0: unknown | ||
78 | JZ.gpio.pin(5, 0).std_gpio_out(1) | ||
79 | end | ||
80 | |||
81 | function FIIOX1.lcd_reset() | ||
82 | local pin = JZ.gpio.pin(4, 4) | ||
83 | pin.set() | ||
84 | hwstub.mdelay(50) | ||
85 | pin.clr() | ||
86 | hwstub.mdelay(50) | ||
87 | pin.set() | ||
88 | hwstub.mdelay(150) | ||
89 | end | ||
90 | |||
91 | function FIIOX1.init_lcd() | ||
92 | -- setup Fiio X1 specific pins | ||
93 | FIIOX1.setup_fiio_lcd_pins() | ||
94 | -- reset lcd | ||
95 | JZ.lcd_reset() | ||
96 | end | ||
97 | |||
98 | -- call with nil to get automatic name | ||
99 | function FIIOX1.dump_ipl(file) | ||
100 | FIIOX1.hw_detect() | ||
101 | if file == nil then | ||
102 | file = "fiiox1_ipl_hw_v" .. FIIOX1.hw_type .. ".bin" | ||
103 | end | ||
104 | print("Dumping IPL to " .. file .." ...") | ||
105 | JZ.nand.rom.init() | ||
106 | JZ.nand.rom.read_flags() | ||
107 | local ipl = JZ.nand.rom.read_bootloader() | ||
108 | JZ.nand.rom.write_to_file(file, ipl) | ||
109 | end | ||
110 | |||
111 | -- call with nil to get automatic name | ||
112 | function FIIOX1.dump_spl(file) | ||
113 | FIIOX1.hw_detect() | ||
114 | if file == nil then | ||
115 | file = "fiiox1_spl_hw_v" .. FIIOX1.hw_type .. ".bin" | ||
116 | end | ||
117 | print("Dumping SPL to " .. file .." ...") | ||
118 | -- hardcoded parameters are specific to the Fiio X1 | ||
119 | local nand_params = { | ||
120 | bus_width = 16, | ||
121 | row_cycle = 2, | ||
122 | col_cycle = 2, | ||
123 | page_size = 2048, | ||
124 | page_per_block = 64, | ||
125 | oob_size = 64, | ||
126 | badblock_pos = 0, | ||
127 | badblock_page = 0, | ||
128 | ecc_pos = 4, | ||
129 | ecc_size = 13, | ||
130 | ecc_level = 8, | ||
131 | addr_setup_time = 4, | ||
132 | addr_hold_time = 4, | ||
133 | write_strobe_time = 4, | ||
134 | read_strobe_time = 4, | ||
135 | recovery_time = 13, | ||
136 | } | ||
137 | local spl = JZ.nand.rom.read_spl(nand_params, 0x400, 0x200) | ||
138 | JZ.nand.rom.write_to_file(file, spl) | ||
139 | end | ||
140 | |||
141 | function FIIOX1.init() | ||
142 | FIIOX1.init_backligt() | ||
143 | FIIOX1.test_backlight() | ||
144 | FIIOX1.init_lcd() | ||
145 | end | ||