2
* Toshiba TC6393XB I/O Controller.
3
* Found in Sharp Zaurus SL-6000 (tosa) or some
4
* Toshiba e-Series PDAs.
6
* Most features are currently unsupported!!!
8
* This code is licensed under the GNU GPL v2.
15
#include "pixel_ops.h"
17
#define IRQ_TC6393_NAND 0
18
#define IRQ_TC6393_MMC 1
19
#define IRQ_TC6393_OHCI 2
20
#define IRQ_TC6393_SERIAL 3
21
#define IRQ_TC6393_FB 4
23
#define TC6393XB_NR_IRQS 8
25
#define TC6393XB_GPIOS 16
27
#define SCR_REVID 0x08 /* b Revision ID */
28
#define SCR_ISR 0x50 /* b Interrupt Status */
29
#define SCR_IMR 0x52 /* b Interrupt Mask */
30
#define SCR_IRR 0x54 /* b Interrupt Routing */
31
#define SCR_GPER 0x60 /* w GP Enable */
32
#define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
33
#define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
34
#define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
35
#define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
36
#define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
37
#define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
38
#define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
39
#define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
40
#define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
41
#define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
42
#define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
43
#define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
44
#define SCR_CCR 0x98 /* w Clock Control */
45
#define SCR_PLL2CR 0x9a /* w PLL2 Control */
46
#define SCR_PLL1CR 0x9c /* l PLL1 Control */
47
#define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
48
#define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
49
#define SCR_FER 0xe0 /* b Function Enable */
50
#define SCR_MCR 0xe4 /* w Mode Control */
51
#define SCR_CONFIG 0xfc /* b Configuration Control */
52
#define SCR_DEBUG 0xff /* b Debug */
54
#define NAND_CFG_COMMAND 0x04 /* w Command */
55
#define NAND_CFG_BASE 0x10 /* l Control Base Address */
56
#define NAND_CFG_INTP 0x3d /* b Interrupt Pin */
57
#define NAND_CFG_INTE 0x48 /* b Int Enable */
58
#define NAND_CFG_EC 0x4a /* b Event Control */
59
#define NAND_CFG_ICC 0x4c /* b Internal Clock Control */
60
#define NAND_CFG_ECCC 0x5b /* b ECC Control */
61
#define NAND_CFG_NFTC 0x60 /* b NAND Flash Transaction Control */
62
#define NAND_CFG_NFM 0x61 /* b NAND Flash Monitor */
63
#define NAND_CFG_NFPSC 0x62 /* b NAND Flash Power Supply Control */
64
#define NAND_CFG_NFDC 0x63 /* b NAND Flash Detect Control */
66
#define NAND_DATA 0x00 /* l Data */
67
#define NAND_MODE 0x04 /* b Mode */
68
#define NAND_STATUS 0x05 /* b Status */
69
#define NAND_ISR 0x06 /* b Interrupt Status */
70
#define NAND_IMR 0x07 /* b Interrupt Mask */
72
#define NAND_MODE_WP 0x80
73
#define NAND_MODE_CE 0x10
74
#define NAND_MODE_ALE 0x02
75
#define NAND_MODE_CLE 0x01
76
#define NAND_MODE_ECC_MASK 0x60
77
#define NAND_MODE_ECC_EN 0x20
78
#define NAND_MODE_ECC_READ 0x40
79
#define NAND_MODE_ECC_RST 0x60
82
target_phys_addr_t target_base;
112
qemu_irq handler[TC6393XB_GPIOS];
122
struct nand_flash_s *flash;
123
struct ecc_state_s ecc;
126
QEMUConsole *console;
127
ram_addr_t vram_addr;
128
uint32_t scr_width, scr_height; /* in pixels */
134
qemu_irq *tc6393xb_gpio_in_get(struct tc6393xb_s *s)
139
static void tc6393xb_gpio_set(void *opaque, int line, int level)
141
// struct tc6393xb_s *s = opaque;
143
if (line > TC6393XB_GPIOS) {
144
printf("%s: No GPIO pin %i\n", __FUNCTION__, line);
148
// FIXME: how does the chip reflect the GPIO input level change?
151
void tc6393xb_gpio_out_set(struct tc6393xb_s *s, int line,
154
if (line >= TC6393XB_GPIOS) {
155
fprintf(stderr, "TC6393xb: no GPIO pin %d\n", line);
159
s->handler[line] = handler;
162
static void tc6393xb_gpio_handler_update(struct tc6393xb_s *s)
164
uint32_t level, diff;
167
level = s->gpio_level & s->gpio_dir;
169
for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) {
171
qemu_set_irq(s->handler[bit], (level >> bit) & 1);
174
s->prev_level = level;
177
qemu_irq tc6393xb_l3v_get(struct tc6393xb_s *s)
182
static void tc6393xb_l3v(void *opaque, int line, int level)
184
struct tc6393xb_s *s = opaque;
186
fprintf(stderr, "L3V: %d\n", level);
189
static void tc6393xb_sub_irq(void *opaque, int line, int level) {
190
struct tc6393xb_s *s = opaque;
191
uint8_t isr = s->scr.ISR;
197
qemu_set_irq(s->irq, isr & s->scr.IMR);
200
#define SCR_REG_B(N) \
201
case SCR_ ##N: return s->scr.N
202
#define SCR_REG_W(N) \
203
case SCR_ ##N: return s->scr.N; \
204
case SCR_ ##N + 1: return s->scr.N >> 8;
205
#define SCR_REG_L(N) \
206
case SCR_ ##N: return s->scr.N; \
207
case SCR_ ##N + 1: return s->scr.N >> 8; \
208
case SCR_ ##N + 2: return s->scr.N >> 16; \
209
case SCR_ ##N + 3: return s->scr.N >> 24;
210
#define SCR_REG_A(N) \
211
case SCR_ ##N(0): return s->scr.N[0]; \
212
case SCR_ ##N(1): return s->scr.N[1]; \
213
case SCR_ ##N(2): return s->scr.N[2]
215
static uint32_t tc6393xb_scr_readb(struct tc6393xb_s *s, target_phys_addr_t addr)
233
return (s->gpio_level >> ((addr - SCR_GPO_DSR(0)) * 8)) & 0xff;
234
case SCR_GPO_DOECR(0):
235
case SCR_GPO_DOECR(1):
236
case SCR_GPO_DOECR(2):
237
return (s->gpio_dir >> ((addr - SCR_GPO_DOECR(0)) * 8)) & 0xff;
239
SCR_REG_A(GP_IARLCR);
241
SCR_REG_W(GPA_IARCR);
242
SCR_REG_W(GPA_IARLCR);
253
fprintf(stderr, "tc6393xb_scr: unhandled read at %08x\n", (uint32_t) addr);
261
#define SCR_REG_B(N) \
262
case SCR_ ##N: s->scr.N = value; return;
263
#define SCR_REG_W(N) \
264
case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \
265
case SCR_ ##N + 1: s->scr.N = (s->scr.N & 0xff) | (value << 8); return
266
#define SCR_REG_L(N) \
267
case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \
268
case SCR_ ##N + 1: s->scr.N = (s->scr.N & ~(0xff << 8)) | (value & (0xff << 8)); return; \
269
case SCR_ ##N + 2: s->scr.N = (s->scr.N & ~(0xff << 16)) | (value & (0xff << 16)); return; \
270
case SCR_ ##N + 3: s->scr.N = (s->scr.N & ~(0xff << 24)) | (value & (0xff << 24)); return;
271
#define SCR_REG_A(N) \
272
case SCR_ ##N(0): s->scr.N[0] = value; return; \
273
case SCR_ ##N(1): s->scr.N[1] = value; return; \
274
case SCR_ ##N(2): s->scr.N[2] = value; return
276
static void tc6393xb_scr_writeb(struct tc6393xb_s *s, target_phys_addr_t addr, uint32_t value)
290
s->gpio_level = (s->gpio_level & ~(0xff << ((addr - SCR_GPO_DSR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DSR(0))*8));
291
tc6393xb_gpio_handler_update(s);
293
case SCR_GPO_DOECR(0):
294
case SCR_GPO_DOECR(1):
295
case SCR_GPO_DOECR(2):
296
s->gpio_dir = (s->gpio_dir & ~(0xff << ((addr - SCR_GPO_DOECR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DOECR(0))*8));
297
tc6393xb_gpio_handler_update(s);
300
SCR_REG_A(GP_IARLCR);
302
SCR_REG_W(GPA_IARCR);
303
SCR_REG_W(GPA_IARLCR);
314
fprintf(stderr, "tc6393xb_scr: unhandled write at %08x: %02x\n",
315
(uint32_t) addr, value & 0xff);
322
static void tc6393xb_nand_irq(struct tc6393xb_s *s) {
323
qemu_set_irq(s->sub_irqs[IRQ_TC6393_NAND],
324
(s->nand.imr & 0x80) && (s->nand.imr & s->nand.isr));
327
static uint32_t tc6393xb_nand_cfg_readb(struct tc6393xb_s *s, target_phys_addr_t addr) {
329
case NAND_CFG_COMMAND:
330
return s->nand_enable ? 2 : 0;
332
case NAND_CFG_BASE + 1:
333
case NAND_CFG_BASE + 2:
334
case NAND_CFG_BASE + 3:
335
return s->nand_phys >> (addr - NAND_CFG_BASE);
337
fprintf(stderr, "tc6393xb_nand_cfg: unhandled read at %08x\n", (uint32_t) addr);
340
static void tc6393xb_nand_cfg_writeb(struct tc6393xb_s *s, target_phys_addr_t addr, uint32_t value) {
342
case NAND_CFG_COMMAND:
343
s->nand_enable = (value & 0x2);
346
case NAND_CFG_BASE + 1:
347
case NAND_CFG_BASE + 2:
348
case NAND_CFG_BASE + 3:
349
s->nand_phys &= ~(0xff << ((addr - NAND_CFG_BASE) * 8));
350
s->nand_phys |= (value & 0xff) << ((addr - NAND_CFG_BASE) * 8);
353
fprintf(stderr, "tc6393xb_nand_cfg: unhandled write at %08x: %02x\n",
354
(uint32_t) addr, value & 0xff);
357
static uint32_t tc6393xb_nand_readb(struct tc6393xb_s *s, target_phys_addr_t addr) {
363
return nand_getio(s->flash);
373
fprintf(stderr, "tc6393xb_nand: unhandled read at %08x\n", (uint32_t) addr);
376
static void tc6393xb_nand_writeb(struct tc6393xb_s *s, target_phys_addr_t addr, uint32_t value) {
377
// fprintf(stderr, "tc6393xb_nand: write at %08x: %02x\n",
378
// (uint32_t) addr, value & 0xff);
384
nand_setio(s->flash, value);
386
tc6393xb_nand_irq(s);
389
s->nand.mode = value;
390
nand_setpins(s->flash,
391
value & NAND_MODE_CLE,
392
value & NAND_MODE_ALE,
393
!(value & NAND_MODE_CE),
394
value & NAND_MODE_WP,
396
switch (value & NAND_MODE_ECC_MASK) {
397
case NAND_MODE_ECC_RST:
400
case NAND_MODE_ECC_READ:
403
case NAND_MODE_ECC_EN:
409
tc6393xb_nand_irq(s);
413
tc6393xb_nand_irq(s);
416
fprintf(stderr, "tc6393xb_nand: unhandled write at %08x: %02x\n",
417
(uint32_t) addr, value & 0xff);
421
#include "tc6393xb_template.h"
423
#include "tc6393xb_template.h"
425
#include "tc6393xb_template.h"
427
#include "tc6393xb_template.h"
429
#include "tc6393xb_template.h"
431
static void tc6393xb_draw_graphic(struct tc6393xb_s *s, int full_update)
433
switch (s->ds->depth) {
435
tc6393xb_draw_graphic8(s);
438
tc6393xb_draw_graphic15(s);
441
tc6393xb_draw_graphic16(s);
444
tc6393xb_draw_graphic24(s);
447
tc6393xb_draw_graphic32(s);
450
printf("tc6393xb: unknown depth %d\n", s->ds->depth);
454
dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height);
457
static void tc6393xb_draw_blank(struct tc6393xb_s *s, int full_update)
465
w = s->scr_width * ((s->ds->depth + 7) >> 3);
467
for(i = 0; i < s->scr_height; i++) {
469
d += s->ds->linesize;
472
dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height);
475
static void tc6393xb_update_display(void *opaque)
477
struct tc6393xb_s *s = opaque;
480
if (s->scr_width == 0 || s->scr_height == 0)
484
if (s->blanked != s->blank) {
485
s->blanked = s->blank;
488
if (s->scr_width != s->ds->width || s->scr_height != s->ds->height) {
489
qemu_console_resize(s->console, s->scr_width, s->scr_height);
493
tc6393xb_draw_blank(s, full_update);
495
tc6393xb_draw_graphic(s, full_update);
499
static uint32_t tc6393xb_readb(void *opaque, target_phys_addr_t addr) {
500
struct tc6393xb_s *s = opaque;
501
addr -= s->target_base;
505
return tc6393xb_scr_readb(s, addr & 0xff);
507
return tc6393xb_nand_cfg_readb(s, addr & 0xff);
510
if ((addr &~0xff) == s->nand_phys && s->nand_enable) {
511
// return tc6393xb_nand_readb(s, addr & 0xff);
512
uint8_t d = tc6393xb_nand_readb(s, addr & 0xff);
513
// fprintf(stderr, "tc6393xb_nand: read at %08x: %02hhx\n", (uint32_t) addr, d);
517
// fprintf(stderr, "tc6393xb: unhandled read at %08x\n", (uint32_t) addr);
521
static void tc6393xb_writeb(void *opaque, target_phys_addr_t addr, uint32_t value) {
522
struct tc6393xb_s *s = opaque;
523
addr -= s->target_base;
527
tc6393xb_scr_writeb(s, addr & 0xff, value);
530
tc6393xb_nand_cfg_writeb(s, addr & 0xff, value);
534
if ((addr &~0xff) == s->nand_phys && s->nand_enable)
535
tc6393xb_nand_writeb(s, addr & 0xff, value);
537
fprintf(stderr, "tc6393xb: unhandled write at %08x: %02x\n",
538
(uint32_t) addr, value & 0xff);
541
static uint32_t tc6393xb_readw(void *opaque, target_phys_addr_t addr)
543
return (tc6393xb_readb(opaque, addr) & 0xff) |
544
(tc6393xb_readb(opaque, addr + 1) << 8);
547
static uint32_t tc6393xb_readl(void *opaque, target_phys_addr_t addr)
549
return (tc6393xb_readb(opaque, addr) & 0xff) |
550
((tc6393xb_readb(opaque, addr + 1) & 0xff) << 8) |
551
((tc6393xb_readb(opaque, addr + 2) & 0xff) << 16) |
552
((tc6393xb_readb(opaque, addr + 3) & 0xff) << 24);
555
static void tc6393xb_writew(void *opaque, target_phys_addr_t addr, uint32_t value)
557
tc6393xb_writeb(opaque, addr, value);
558
tc6393xb_writeb(opaque, addr + 1, value >> 8);
561
static void tc6393xb_writel(void *opaque, target_phys_addr_t addr, uint32_t value)
563
tc6393xb_writeb(opaque, addr, value);
564
tc6393xb_writeb(opaque, addr + 1, value >> 8);
565
tc6393xb_writeb(opaque, addr + 2, value >> 16);
566
tc6393xb_writeb(opaque, addr + 3, value >> 24);
569
struct tc6393xb_s *tc6393xb_init(uint32_t base, qemu_irq irq, DisplayState *ds)
572
struct tc6393xb_s *s;
573
CPUReadMemoryFunc *tc6393xb_readfn[] = {
578
CPUWriteMemoryFunc *tc6393xb_writefn[] = {
584
s = (struct tc6393xb_s *) qemu_mallocz(sizeof(struct tc6393xb_s));
585
s->target_base = base;
587
s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS);
589
s->l3v = *qemu_allocate_irqs(tc6393xb_l3v, s, 1);
592
s->sub_irqs = qemu_allocate_irqs(tc6393xb_sub_irq, s, TC6393XB_NR_IRQS);
594
s->flash = nand_init(NAND_MFR_TOSHIBA, 0x76);
596
iomemtype = cpu_register_io_memory(0, tc6393xb_readfn,
597
tc6393xb_writefn, s);
598
cpu_register_physical_memory(s->target_base, 0x10000, iomemtype);
602
s->vram_addr = qemu_ram_alloc(0x100000);
603
cpu_register_physical_memory(s->target_base + 0x100000, 0x100000, s->vram_addr);
606
s->console = graphic_console_init(ds,
607
tc6393xb_update_display,
608
NULL, /* invalidate */
609
NULL, /* screen_dump */
610
NULL, /* text_update */