-
Notifications
You must be signed in to change notification settings - Fork 8
/
deviceSonyTG50.c
executable file
·337 lines (295 loc) · 9.46 KB
/
deviceSonyTG50.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//(c) uARM project https://github.com/uARM-Palm/uARM uARM@dmitry.gr
#include "mmiodev_MemoryStickController.h"
#include "i2cdev_AN32502A.h"
#include "mmiodev_TG50uc.h"
#include "sspdev_AD7873.h"
#include "i2sdev_AK4534.h"
#include "SDL2/SDL.h"
#include "device.h"
#include "util.h"
#include "RAM.h"
/*
///palmos irqs from most to least important:
irqno source notes
0 gpio0 pwr btn?
15 DMA
7 LCD
40 IrcExtn interrupt
16 OS timer 0 ?
3 USB
11 BTUART
12 FFUART
21 RTC Alarm
14 SSP
10 STUART
9 ICP ??WHY??
8 I2C
5 I2S
23 gpio5 ??
24 gpio6 ??
27 gpio10 MS ip chip ?
26 gpio9 pen detect ?
22 gpio3 cradle button
29 gpio14 keyboard/hardkey int ???
30 gpio21 ??
35 gpioA.8 change? definitely: Pa1Lib interrupt
34 gpioA.5 change?
39 gpioA.15 change headphone insert/remove (low when inserted)
25 gpio7 ms insert/remove ?
32 gpioA.1 change?
33 gpioA.4 change? thus hold switch?
37 gpioA.11 change?
36 gpioA.10 change?
31 gpioA.4 change? definitely: BtTransportGn interrupt
38 possibly key related (manipulated always near key mask). maybe hold?
41
28 gpio13 seems to be irq for all uC things as per dispatcher
unlisted in prio map but existing:
1 gpio1 (rst)
2 gpio2-84 dispatched separately
4 PMU unused?
6 AC97 unused?
13 MMC unused?
17 OS timer 1 unused?
18 OS timer 2 unused?
19 OS timer 3 unused?
20 RTC HZ unused?
*/
/*
GPIO AFR DIR STATE EDGE NOTES
0 0 0 1 FE palmos irq 0, ????
1 1 0 0 gpio reset
2 0 0 0
3 0 0 0 FE palmos irq 22, active low "hotsync" cradle button detect
4 0 1 0
5 0 1 0 palmos irq 23
6 0 0 0 palmos irq 24
7 0 0 1 RE FE palmos irq 25, likely memory stick detect (active low)
8 0 1 0
9 0 0 1 RE FE palmos irq 26, touch interrupt from AD7873
10 0 0 1 FE palmos irq 27, memorystick IO interrupt ?
11 1 1 0 3.6MHz out
12 0 1 0
13 0 0 1 FE palmos irq 28, related to keys
14 0 0 0 FE palmos irq 29, hard key pressed
15 0 1 1 active low memory stick IP reset?
16 2 1 0 PWM0 out
17 2 1 0 PWM1 out
18 1 0 0 RDY (external bus ready)
19 1 0 0 DREQ[1] (used by memory stick IP chip)
20 1 0 0 DREQ[0] (used by memory stick IP chip)
21 0 0 0 FE palmos irq 30, related to keys. irq when jog clicks up/down
22 0 0 0 IFF irq21 interrupted, this is read to tell which it was. hi = up, lo = down
23 2 1 0 SCLK (SSP)
24 2 1 1 SFRM (SSP) (AD7873 chip select)
25 2 1 0 TXD (SSP)
26 1 0 0 RXD (SSP)
27 0 1 0
28 2 0 0 bit_clk IN (I2S)
29 2 0 0 Sdata_in (I2S)
30 1 1 0 Sdata_out (I2S)
31 1 1 0 sync (I2S)
32 0 1 0 controls memory stick ip somehow (power?)
33 2 1 0 nCS5
34 1 0 0 FFRXD
35 1 0 0 FFCTS
36 0 1 0
37 0 1 0
38 0 1 0
39 2 1 0 FFTXD
40 2 1 0 FFDTR
41 2 1 0 FFRTS
42 0 0 0
43 0 0 0
44 0 0 0
45 0 0 0
46 0 1 0
47 0 1 0
48 0 1 0
49 2 1 0 nPWE (mem ctrlr)
50 0 1 0
51 0 1 0
52 0 1 0
53 0 1 0
54 0 1 0
55 0 1 0
56 0 1 0
57 0 1 0
58 2 1 0 LDD[0] (LCD DATA)
59 2 1 0 LDD[1] (LCD DATA)
60 2 1 0 LDD[2] (LCD DATA)
61 2 1 0 LDD[3] (LCD DATA)
62 2 1 0 LDD[4] (LCD DATA)
63 2 1 0 LDD[5] (LCD DATA)
64 2 1 0 LDD[6] (LCD DATA)
65 2 1 0 LDD[7] (LCD DATA)
66 2 1 0 LDD[8] (LCD DATA)
67 2 1 0 LDD[9] (LCD DATA)
68 2 1 0 LDD[10] (LCD DATA)
69 2 1 0 LDD[11] (LCD DATA)
70 2 1 0 LDD[12] (LCD DATA)
71 2 1 0 LDD[13] (LCD DATA)
72 2 1 0 LDD[14] (LCD DATA)
73 2 1 0 LDD[15] (LCD DATA)
74 2 1 0 FCLK (LCD)
75 2 1 0 LCLK (LCD)
76 2 1 0 PCLK (LCD)
77 0 1 0
78 2 1 0 nCS2
79 2 1 0 nCS3
80 2 1 0 nCS4
UC GPIOS:
GPIO DIR VAL RE/FE EIRQ NOTES
A0 0 1
A1 0 0
A2 0 1
A3 0 1
A4 0 1 rf yes hold slider (active low when in hold mode)
A5 0 1
A6 1 0 possibly bt chip power
A7 0 0
A8 0 1 r yes
A9 1 0
A10 1 0 keyboard backlight (active low)
A11 1 0
A12 1 0
A13 0 1 rf yes cradle detect (low when charging)
A14 0 1 charge detect (low when in cradle)
A15 0 1 rf yes headphone detect (low when inserted)
B0 1 0 touch chip power (audio goes wrong when we toggle this)
B1 1 0 audio chip power (goes wrong when toggled)
B2 1 1
B3 1 1
B4 0 0
B5 1 1
B6 1 1
B7 1 1
B8 1 0
B9 1 1 lcd power
B10 1 0
B11 1 1 backglight power (active high)
B12 1 0 power led (green led in power button) (active low)
B13 0 1 attention LED (red led in power button) (active low)
B14 0 0 BT LED ? (code says yes, but no effect)
B15 1 1 rec led ? (code says yes, but no effect)
C0 x x rf yes keypad colum read
C1 x x rf yes keypad colum read
C2 x x rf yes keypad colum read
C3 x x rf yes keypad colum read
C4 x x rf yes keypad colum read
C5 x x rf yes keypad colum read
C6 x x rf yes keypad colum read
C7 x x rf yes keypad colum read
C8 0 x keypad row drivers
C9 0 x keypad row drivers
C10 0 x keypad row drivers
C11 0 x keypad row drivers
C12 0 x keypad row drivers
C13 0 x keypad row drivers
C14 0 x keypad row drivers
C15 0 x keypad row drivers
D0 0 0 \
D1 0 0 | device revision
D2 0 1 | ID straps here
D3 0 0 /
keyboad matrix is on uc's portC
low 8 bits are row drivers (out). drive low to drive a row
high 8 bits are colomn reads. read low if key is down
//as per american TG50 the map is:
ROW/COL 0 1 2 3 4 5 6 7
0 power hard1 hard2 ? hard3 ? hard4 voice_rec
1 pgUp pgDn home jobBk ? jogSel grafiti ?
2 q caps w e r t h ?
3 y tab u i o p j ?
4 a shift s d f g k ?
5 z ctrl x c v b l ?
6 n blue m comma period up down ?
7 space red _@ left right enter bksp ?
*/
struct Device {
struct MemoryStickController *msc;
struct An32502A *an32502A;
struct Ad7873 *ad7873;
struct AK4534 *ak4534;
struct TG50uc *uc;
};
bool deviceHasGrafArea(void)
{
return false;
}
enum RomChipType deviceGetRomMemType(void)
{
return RomWriteError;
}
uint32_t deviceGetRamSize(void)
{
return 17UL << 20; //it probes over 32M so we say 17M here so that our mirror covers the probe
}
enum RamTermination deviceGetRamTerminationStyle(void)
{
return RamTerminationMirror;
}
uint_fast8_t deviceGetSocRev(void)
{
return 0; //PXA25x
}
struct Device* deviceSetup(struct SocPeriphs *sp, struct Keypad *kp, struct VSD *vsd, FILE* nandFile)
{
static const uint32_t keyMap[] = {
SDLK_ESCAPE, SDLK_F1, SDLK_F2, 0, SDLK_F3, 0, SDLK_F4, SDLK_F5,
SDLK_PAGEUP, SDLK_PAGEDOWN, SDLK_HOME, SDLK_END /* jog back */, 0, SDLK_F11/* jog sel */, SDLK_BACKQUOTE /* grafiti icon */, 0,
SDLK_q, SDLK_CAPSLOCK, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_h, 0,
SDLK_y, SDLK_TAB, SDLK_u, SDLK_i, SDLK_o, SDLK_p, SDLK_j, 0,
SDLK_a, SDLK_LSHIFT, SDLK_s, SDLK_d, SDLK_f, SDLK_g, SDLK_k, 0,
SDLK_z, SDLK_LCTRL, SDLK_x, SDLK_c, SDLK_v, SDLK_b, SDLK_l, 0,
SDLK_n, SDLK_F7 /* blue shift key */, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_UP, SDLK_DOWN, 0,
SDLK_SPACE, SDLK_F9 /* red shift key */, SDLK_UNDERSCORE, SDLK_LEFT, SDLK_RIGHT, SDLK_RETURN, SDLK_BACKSPACE, 0,
};
struct ArmRam *unknownSram;
struct Device *dev;
dev = (struct Device*)malloc(sizeof(*dev));
if (!dev)
ERR("cannot alloc device");
//gpio24 is AD7873 chip select (active low) in gpio mode (or SSPFRM mode)
dev->ad7873 = ad7873Init(sp->ssp, sp->gpio, 9);
if (!dev->ad7873)
ERR("Cannot init AD7873");
dev->ak4534 = ak4534Init(sp->i2c, sp->i2s, sp->gpio);
if (!dev->ak4534)
ERR("Cannot init AK4534");
dev->an32502A = an32502aInit(sp->i2c);
if (!dev->an32502A)
ERR("Cannot init AN32502A");
dev->uc = tg50ucInit(sp->mem, sp->gpio, 14, keyMap);
if (!dev->uc)
ERR("Cannot init TG50's UC");
dev->msc = msCtrlrInit(sp->mem, 0x14000000ul);
if (!dev->msc)
ERR("Cannot init MSC");
unknownSram = ramInit(sp->mem, 0xac000000ul, 1024, (uint32_t*)malloc(1024));
if (!unknownSram)
ERR("Cannot init RAM4");
if (!keypadAddGpioKey(kp, SDLK_ESCAPE, 0, false))
ERR("Cannot init power key\n");
socGpioSetState(sp->gpio, 1, true); //tg50 reset button (active low)
socGpioSetState(sp->gpio, 3, true); //cradle button not pressed
socGpioSetState(sp->gpio, 7, true); //tg50 MS not inserted
socGpioSetState(sp->gpio, 10, true); //tg50 MS IP not interrupting
socGpioSetState(sp->gpio, 13, true); //tg50 UC not interrupting
ad7873setVbatt(dev->ad7873, 4200); //battery is full
sp->dbgUart = sp->uarts[2]; //FFUART
return dev;
}
void devicePeriodic(struct Device *dev, uint32_t cycles)
{
if (!(cycles & 0x00007FFFUL))
ad7873Periodic(dev->ad7873);
}
void deviceTouch(struct Device *dev, int x, int y)
{
ad7873PenInput(dev->ad7873, (x >= 0 && y >= 0) ? 3200 - 10 * x : -1, (x >= 0 && y >= 0) ? 3200 - 10 * y : -1);
}
void deviceKey(struct Device *dev, uint32_t key, bool down)
{
tg50ucSetKeyPressed(dev->uc, key, down);
}